OpenQASM Compiler

Translating quantum circuits

myQLM provides a script to translate a QASM file into a myQLM circuit file. For instance, the following bash command generate a file bell.circ containing a myQLM circuit from a text file bell.qasm

# Bash command
oqasm2circ bell.qasm bell.cirq

The Python code corresponding to this translate uses the class OqasmParser

from qat.interop.openqasm import OqasmParser

# Define a bell pair QASM circuit
bell_data = """
OPENQASM 2.0;

// Allocate qubits and cbits
qreg q[2];
creg c[2];

// Define the circuit
h q[0];
cx q[0],q[1];

// Measure
measure q[0] -> c[0];
measure q[1] -> c[1];
"""

# Translate into a myQLM circuit
parser = OqasmParser()
circuit = parser.compile(bell_data)
print("The circuit is composed of gates",
      list(circuit.iterate_simple()))
The circuit is composed of gates [('H', [], [0]), ('CNOT', [], [0, 1]), ('MEASURE', [0], [0]), ('MEASURE', [1], [1])]
/var/lib/jenkins/workspace/orial-doc_release_myqlm-1.12.0_2/runtime_linux-x86_64_cpython_python312/usr/local/lib64/python3/qaptiva-packages/qat/interop/__init__.py:31: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import parse_version

Note

The 2.0 version of OPENQASM is the only one fully supported, other versions might work flawlessly, but they haven’t been tested.