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/thierry-martinez/graphix-qasm-parser.git
from 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]
.
OpenQASM gate | Graphix instruction |
---|---|
ccx | CCX |
crz | RZZ |
cx | CX |
swap | SWAP |
h | H |
s | S |
x | X |
y | Y |
z | Z |
rx | RX |
ry | RY |
rz | RZ |
Expressions with arithmetic operators (+
, -
, *
, /
, %
) are supported.
The constant pi
(or π
) is defined.
Compile-time constants can be defined and used in expressions.