Skip to main content

Quantar

Quantar is a strict superset of Python for quantum computing and physics simulations. It keeps Python syntax and adds custom infix operators such as a <-> b, plus a library of quantum gates, circuits, algorithms, and physics helpers.

Requirements

  • Python 3.12 or newer
  • NumPy, Numba, and openqasm3[parser] (installed automatically)

Installation

pip install quantar

# or with uv
uv pip install quantar

Optional extras:

# alternative quantum backends
pip install quantar[backends]

# SciPy-powered COBYLA optimization
pip install quantar[optimization]

# LSP support
pip install quantar[lsp]

Running Quantar

qtr path/to/program.qtr

Compile a file to ordinary Python instead of executing it:

qtr path/to/program.qtr --compile path/to/program.py

During development, the same runner is available as a module:

python -m lang_systems.runner path/to/program.qtr

Small registers use vectorized NumPy so short programs skip Numba's startup and compilation cost. Registers with at least 1,048,576 amplitudes use the JIT. Set QUANTAR_NUMBA_MIN_AMPLITUDES to change that cutoff, or QUANTAR_NUMBA=0 to disable Numba entirely.

VS Code extension

The extension lives in editors/vscode. It provides .qtr syntax highlighting, parser diagnostics, and registry-driven operator highlighting through a pygls language server.

pip install -e ".[lsp]"
cd editors/vscode
npm install
npm run compile

Open editors/vscode in VS Code and run the Run Quantar Extension launch configuration. The extension also adds Quantar: Run File and Quantar: Compile File to Python commands.

Parsing Quantar

lang_systems.parse() returns pegen's raw parse tree. This is the low-level form used by tooling and tests:

from lang_systems import parse

tree = parse("a <-> b\nx = 1 + 2\n")

lang_systems.parse_ast() returns a normal Python AST with custom QuantumOp nodes:

import ast

from lang_systems import OperatorCollector, parse_ast

module = parse_ast("x = a <-> b\n")
print(ast.dump(module, indent=2))

collector = OperatorCollector()
collector.visit(module)
print(collector.operators)  # [("<->", "binary")]

Custom operators are registered with lang_systems.operators.operator:

from lang_systems.operators import operator

@operator.binary("><")
def reverse(left, right):
    return right, left

If the operators live in another module, import that module before parsing:

from lang_systems import load_operators, parse

load_operators("my_package.quantar_ops")
tree = parse("a >< b\n")

Quantar as a library

quantar is the umbrella package. It loads the language, quantum, and physics packages lazily, so importing it stays lightweight:

import quantar

q = quantar.QuantumComputer(2)
tree = quantar.parse_ast("a <-> b\n")
print(quantar.__version__)

quantar.lang_systems
quantar.quantum
quantar.stl

The underlying packages can still be imported directly:

import quantum
from stl.quantum_algs.shors_alg import shors_alg
from stl.physics_algs.units import Quantity, Unit

See the modules under src/quantum/ and src/stl/ for the available gates, circuits, algorithms, and physics helpers.

Development

The Python packages live under src/. Install the project in editable mode before running the CLI or LSP from a checkout:

pip install -e ".[lsp]"

Regenerate the parser after changing src/lang_systems/quantar.gram:

python -m lang_systems.pegen_gram_gen

Build the wheel and source distribution:

uv build

The generated parser is src/lang_systems/quantar_parser.py; the build hook in hatch_build.py regenerates it automatically. The parser is generated from CPython's Grammar/python.gram plus the operator overlay in src/lang_systems/quantar.gram.

Status

Quantar currently provides the parser, AST, quantum library, physics library, a CLI runner/compiler, and a VS Code extension scaffold. A bytecode interpreter and debugger are not implemented yet.

Feedback

Feedback and bug reports are welcome through GitHub issues or by contacting the maintainer. The main contributor is Gautham_rgb.

Notes on AI

Most of the code was written by people. Some AI assistance was used for boilerplate and for explaining the mathematics behind topics such as Kronecker products and gate matrices.

Metadata

Release files for Quantar 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Quantar 0.1.1
File Size Uploaded Provenance
quantar-0.1.1.tar.gz 121.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for Quantar 0.1.1
File Interpreter ABI Platform
quantar-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 233.5 kB

Release files / quantar-0.1.1.tar.gz

Download URL quantar-0.1.1.tar.gz
Size 121.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a370315b6cc5dad35700f255b00456d69f54c23c69619d5aefbe8b8103cdd654
BLAKE2b-256 checksum
How to use checksums
9762e40aed0014d1bde64c3eaa474ace120c4097346fe58ca7dfc6b7d47ae499
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / quantar-0.1.1-py3-none-any.whl

Download URL quantar-0.1.1-py3-none-any.whl
Size 111.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95c7eb533df2750214814cc8e6088606c1dd6e8ffb393b0fb9e50776aeac9d10
BLAKE2b-256 checksum
How to use checksums
5dede61a65b9ce9de27695d1adf7889e0130af5c8c7c10e9cb51b789be44deef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Security for Quantar 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page