graphix-qasm-parser is a plugin for the
Graphix library that parses
OpenQASM circuit specifications into
graphix.transpiler.Circuit objects, which can then be transpiled
into MBQC patterns.
It is distributed as a separate plugin because it depends on
openqasm-parser.
pip install https://github.com/TeamGraphix/graphix-qasm-parser.gitfrom graphix_qasm_parser import OpenQASMParser
s = """
include "qelib1.inc";
qubit q;
rz(5*pi/4) q;
"""
parser = OpenQASMParser()
circuit = parser.parse_str(s)
pattern = circuit.transpile().pattern
print(pattern)circuit = parser.parse_file("my_circuit.qasm")-
Single-qubit registers:
qubit q, or the old syntaxqreg q. -
Qubit register arrays:
qubit[n] q, or the old syntaxqreg q[n].
-
Single-bit registers:
bit b, or the old syntaxcreg b. -
Bit register arrays:
bit[n] b, or the old syntaxcreg q[n].
| OpenQASM gate | Graphix instruction |
|---|---|
| h | H |
| s | S |
| sdg | SDG |
| t | T |
| tdg | TDG |
| sx | SX |
| sxdg | SXDG |
| id | I |
| x | X |
| y | Y |
| z | Z |
| U | U |
| p | P |
| rx | RX |
| ry | RY |
| rz | RZ |
| swap | SWAP |
| cx | CNOT |
| cy | CY |
| cz | CZ |
| cu | CU |
| cp | CP |
| crx | CRX |
| cry | CRY |
| crz | CRZ |
| cswap | CSWAP |
| ccx | CCX |
| gphase | GPHASE |
Expressions with arithmetic operators (+, -, *, /, %) are supported.
The constant pi (or π) is defined.
Compile-time constants can be defined and used in expressions.
User gates can be defined with gate name(parameters) qubits { ... }.
Measurements of the form bit = measure qubit;, or the old syntax
measure qubit -> bit, are supported.
Both arguments must be registers of the same size, or both must be bit/qubit types.