# Generated from the package source. Do not edit. """OpenQASM 2.0, read into the gate lists the `quantum` module runs. A compiler hands over its output as OpenQASM 2.0 text, and this reads it without importing any compiler. `read(text)` gives a `Circuit`: its qubit count and its gates in order, each on qubit indices counted across the registers in the order they are declared. `write(circuit)` writes one back. WHAT IT KEEPS EXACT. An angle is a float, computed as the text writes it, and also, when the text makes it one, an exact rational multiple of pi plus an exact rational: `pi/2` is exactly a half of pi, `0.3` exactly three tenths. A function (`sin`, `cos`, `tan`, `exp`, `ln`, `sqrt`) or a power leaves only the float. So a reader can tell `rz(pi/2)` — a quarter turn, a Clifford gate — from `rz(1.5707963267948966)`, which is not one exactly. WHAT A GATE IS. A gate the module runs keeps its name: `h x y z s t sx rx ry rz`, `cnot` (written `cx` or `CX`), `cz`, `ecr` and `swap`, and `id`, which a device may name. A gate the file defines with `gate` is replaced by its body, its parameters substituted, since that is what the definition says it is. A gate the module runs keeps its name even when the file also defines it — Qiskit's exporter defines `ecr`, which `qelib1.inc` lacks — and the definition is kept in `Circuit.defined`, so a test can hold the module's matrix to it. Any other name is refused. `measure` and `reset` are kept as gates of those names, so a file with them reads, and a comparison of two circuits can refuse them. `barrier` is dropped. `opaque`, `if` and `U` are refused. Usage: python -m dke.quantum.qasm print the circuit, one gate a line""" import math import re import sys from dataclasses import dataclass, field from fractions import Fraction NATIVE: ... RENAMED: ... ARITY: ... ANGLES: ... FUNCTIONS: ... class QasmError(ValueError): ... @dataclass(frozen=True) class Angle: """An angle in radians: `value` as the text computes it in floating point, and `exact`, the pair (a, b) for a·pi + b with a and b rational, when the text makes it exactly that.""" value: float exact: tuple[Fraction, Fraction] | None = None def pi_multiple(self) -> Fraction | None: """a, when the angle is exactly a·pi.""" ... @dataclass(frozen=True) class Gate: name: str qubits: tuple[int, ...] angles: tuple[Angle, ...] = () @dataclass class Definition: params: list[str] args: list[str] body: list[tuple[str, list[str], list[str]]] @dataclass class Circuit: qubits: int gates: list[Gate] defined: dict[str, Definition] = field(default_factory=dict) def angle(text: str, env: dict[str, Angle] | None=None) -> Angle: ... def read(text: str) -> Circuit: ... def write(circuit: Circuit) -> str: """The circuit as OpenQASM 2.0 on one register `q`, with `cnot` written `cx`. `ecr`, which `qelib1.inc` lacks, comes with the definition Qiskit's exporter writes for it, which equals the module's `ecr` up to a global phase. A circuit holding `measure` or `reset` is refused: there is no classical register to write it to.""" ... def main(argv: list[str] | None=None) -> int: ...