Skip to content

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.

Quickstart

Quantar files end in .qtr. They are Python files that went to quantum camp and came back with opinions—and a small collection of very dramatic brackets.

You do not need to throw away your Python habits. Functions, loops, imports, classes, and questionable variable names all still work.

1. Install Quantar

pip install quantar

# Or, if you prefer uv:
uv add quantar

Optional extras:

pip install quantar[backends]      # alternative quantum backends
pip install quantar[optimization]  # SciPy-powered COBYLA optimization
pip install quantar[lsp]           # VS Code language-server support

The Python simulator works without Rust. Rust is only needed if you want to build the compiled quantum.quantar_kernels extension from source, which is the fast path for larger circuits.

2. Create a project

qtr new quantum-demo
cd quantum-demo

That gives you something like:

quantum-demo/
├── pyproject.toml
├── README.md
├── .gitignore
├── src/
│   └── main.qtr
└── tests/
    └── test_quantum_demo.qtr

Already have a directory? Run qtr init there instead. Scaffolding never overwrites files you already own, because silently replacing someone's work is not a feature.

The generated pyproject.toml includes a [tool.quantar] table:

[tool.quantar]
entry = "src/main.qtr"
output = "src/main.py"
compile-to = "py"
mode = "standalone"
rust = false
jobs = 2

With that in place, the CLI commands can infer your entry point. Command-line options still win if you pass them explicitly.

3. Write a first program

Replace src/main.qtr with this:

# src/main.qtr
import quantum
from quantum import QuantumComputer, h_MAT, set_seed, swap_MAT

set_seed(7)  # randomness, but with a save file


def circuit(qc):
    qc[0].apply_gate(h_MAT())          # superposition: the classic "maybe"
    qc.apply_gate(swap_MAT(), [0, 1])  # SWAP: two qubits trading seats


qc = QuantumComputer(2)
circuit(qc)

print(qc.state_vector)
print(qc.to_openqasm3())

# sample() resets the register, reruns the circuit, and returns bitstring counts.
print(qc.sample(circuit, 1000))

qc.apply_gate(swap_MAT(), [0, 1]) applies a SWAP to qubits 0 and 1. Gates are regular Python functions and methods, and the common ones also have built-in operators such as h qc[0], qc[0] <-> qc[1], qc[0] <-s-> qc[1], and qc[1] <-i-> qc[0].

4. Run, check, and compile

qtr run                         # run the configured entry point
qtr run src/main.qtr            # run a specific file
qtr src/main.qtr                # shorthand for `qtr run`

qtr check                       # validate without executing
qtr check src/main.qtr

qtr compile                     # lower to Python (default target, but it can use pyinstaller and make a binary)
qtr compile src/main.qtr out.py

qtr check walks the entry file and reachable local .qtr/.py modules, resolves local imports from source text, parses and compiles everything, then runs a mypy-backed type pass over Python mirrors of those sources. It reports cargo-style errors for syntax and other compile-time problems, bad imports/exports, undefined names, and common type mistakes. It does not execute your program or your local modules. Your debug print("did the thing") statements remain mysteriously silent.

To build a standalone executable instead of Python source:

qtr compile --compile-to binary --mode onefile

5. Opt into Rust explicitly

The Python backend is the default. When you want the compiled backend, ask for it:

qtr run --rust
qtr compile --rust --compile-to binary

If the Rust extension is missing, stale, or incompatible, these commands fail loudly. They do not quietly pretend NumPy was the plan all along. If Rust is available locally, the loader can build the extension for you first.

Where to go next

  • Syntax — how .qtr files use Python plus binary/unary and gate operators.
  • Standard Library — what lives in quantum, stl, and quantar.
  • Releases — version policy and what changed when.