Skip to content

bloqade.cirq_utils.emit.base.emit_circuit

← Module overview

functionemit_circuitsource

bloqade.cirq_utils.emit.base.emit_circuit

Signature
def emit_circuit(mt: ir.Method, qubits: Sequence[cirq.Qid] | None = None, circuit_qubits: Sequence[cirq.Qid] | None = None, args: tuple = (), ignore_returns: bool = False) -> cirq.Circuit

Converts a squin.kernel method to a cirq.Circuit object.

Here’s a very basic example:

from bloqade import squin
from bloqade.cirq_utils import emit_circuit
@squin.kernel
def main():
q = squin.qalloc(2)
squin.h(q[0])
squin.cx(q[0], q[1])
circuit = emit_circuit(main)
print(circuit)

You can also compose multiple kernels. Those are emitted as subcircuits within the “main” circuit. Subkernels can accept arguments and return a value.

from bloqade import squin
from bloqade.cirq_utils import emit_circuit
from kirin.dialects import ilist
from typing import Literal
import cirq
@squin.kernel
def entangle(q: ilist.IList[squin.qubit.Qubit, Literal[2]]):
squin.h(q[0])
squin.cx(q[0], q[1])
@squin.kernel
def main():
q = squin.qalloc(2)
q2 = squin.qalloc(3)
squin.cx(q[1], q2[2])
# custom list of qubits on grid
qubits = [cirq.GridQubit(i, i+1) for i in range(5)]
circuit = emit_circuit(main, circuit_qubits=qubits)
print(circuit)

We also passed in a custom list of qubits above. This allows you to provide a custom geometry and manipulate the qubits in other circuits directly written in cirq as well.

Parameters

NameTypeDefaultDescription
mtir.MethodrequiredThe kernel method from which to construct the circuit.
qubitsSequence[cirq.Qid] | NoneNone
circuit_qubitsSequence[cirq.Qid] | NoneNone
argstuple()
ignore_returnsboolFalse

Other Parameters

NameTypeDescription
circuit_qubitsSequence[cirq.Qid] | NoneA list of qubits to use as the qubits in the circuit. Defaults to None. If this is None, then `cirq.LineQubit`s are inserted for every `squin.qalloc` statement in the order they appear inside the kernel. **Note**: If a list of qubits is provided, make sure that there is a sufficient number of qubits for the resulting circuit.
argstupleThe arguments of the kernel function from which to emit a circuit.
ignore_returnsboolIf `False`, emitting a circuit from a kernel that returns a value will error. Set it to `True` in order to ignore the return value(s). Defaults to `False`.

Returns

cirq.Circuit

source