AI-assisted docs. Parts of this page were drafted or edited with AI assistance. The project creator reviews and maintains the final text; see the AI notice.
Syntax
.qtr files are Python source plus a small operator overlay. Quantar supplies
the runtime, CLI, and simulator; the overlay adds binary and unary operators and
built-in gate symbols. If your editor understands Python, it already understands
the shape of a Quantar program.
Python first
def prepare(n: int) -> list[int]:
return [i * i for i in range(n)]
values = prepare(4)
if values and values[-1] > 3:
print("plain Python, no quantum paperwork")
Imports work normally, and .qtr modules can import other .qtr modules. The
runner installs an import hook, so sibling files are found without extra
configuration.
Gates are Python calls or built-in operators
Quantum gates are matrix factories and methods, and the common ones also have built-in symbolic forms:
from quantum import QuantumComputer, h_MAT, swap_MAT
qc = QuantumComputer(2)
qc[0].apply_gate(h_MAT())
qc.apply_gate(swap_MAT(), [0, 1])
# Equivalent built-in operator forms
h qc[0]
qc[0] <-> qc[1]
qc[0] <-s-> qc[1]
qc[1] <-i-> qc[0]
print(qc.state_vector)
h_MAT() is a matrix factory. apply_gate() applies it to one or more qubits.
Controlled gates accept an optional control_qubits argument.
Built-in gate operators are:
- Binary:
<->,<-s->,<-i-> - Unary prefix:
h,~[x],~[y],~[z],idm,s,sdg,t,tdg
The bracketed ~[x], ~[y], and ~[z] names are built-in gate operators, not
user-defined bracket patterns.
User-defined operators
Math-style notation can be registered with @operator.binary,
@operator.unary_pre, and @operator.unary_post:
from lang_systems.operators import operator
@operator.binary("<~>")
def combine(left, right):
return left + right
@operator.unary_pre("~flip~")
def flip(value):
return -value
@operator.unary_post("†")
def adjoint(value):
return value
x = 1 <~> 2
y = ~flip~ x
z = x†
Bracket-style user operators such as |x> and <a|b> are not supported.
Checking without running
qtr check parses, compiles, and type-checks the entry file and reachable local
modules without executing them:
Errors use cargo-style output, for example:
Next steps
- Quickstart — create and run a project.
- Standard Library — gates, algorithms, and physics helpers.