bloqade.cirq_utils.emit.base.emit_circuit
← Module overview
function
source
functionemit_circuit¶source
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.CircuitConverts a squin.kernel method to a cirq.Circuit object.
Examples:
Section titled “Examples:”Here’s a very basic example:
from bloqade import squinfrom bloqade.cirq_utils import emit_circuit
@squin.kerneldef 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 squinfrom bloqade.cirq_utils import emit_circuitfrom kirin.dialects import ilistfrom typing import Literalimport cirq
@squin.kerneldef entangle(q: ilist.IList[squin.qubit.Qubit, Literal[2]]): squin.h(q[0]) squin.cx(q[0], q[1])
@squin.kerneldef main(): q = squin.qalloc(2) q2 = squin.qalloc(3) squin.cx(q[1], q2[2])
# custom list of qubits on gridqubits = [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
| Name | Type | Default | Description |
|---|---|---|---|
mt | ir.Method | required | The kernel method from which to construct the circuit. |
qubits | Sequence[cirq.Qid] | None | None | |
circuit_qubits | Sequence[cirq.Qid] | None | None | |
args | tuple | () | |
ignore_returns | bool | False |
Other Parameters
| Name | Type | Description |
|---|---|---|
circuit_qubits | Sequence[cirq.Qid] | None | A 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. |
args | tuple | The arguments of the kernel function from which to emit a circuit. |
ignore_returns | bool | If `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