Skip to main content

Example Usage

Convert a Cirq circuit to QIR code:
import cirq
from qbraid_qir import dumps
from qbraid_qir.cirq import cirq_to_qir

# create a test circuit

q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1))

# convert to QIR

module = cirq_to_qir(circuit, name="bell")

# saves to .ll and .bc files in working directory

dumps(module)

print(module)

Note

Circuits constructed using qubits of type cirq.NameQubit or cirq.GridQubit will be transformed to type cirq.LineQubit before conversion to QIR. Execute the QIR program using the qir-runner command line tool:
$ qir-runner -f bell.bc
https://github.com/qBraid/qbraid-qir/tree/main/test-containers