Skip to content

bloqade.cirq_utils.lowering.load_circuit

← Module overview

functionload_circuitsource

bloqade.cirq_utils.lowering.load_circuit

Signature
def load_circuit(circuit: cirq.Circuit, kernel_name: str = 'main', dialects: ir.DialectGroup = kernel, register_as_argument: bool = False, return_register: bool = False, register_argument_name: str = 'q', globals: dict[str, Any] | None = None, file: str | None = None, lineno_offset: int = 0, col_offset: int = 0, compactify: bool = True)

Converts a cirq.Circuit object into a squin kernel.

# from cirq's "hello qubit" example
import cirq
from bloqade.cirq_utils import load_circuit
# Pick a qubit.
qubit = cirq.GridQubit(0, 0)
# Create a circuit.
circuit = cirq.Circuit(
cirq.X(qubit)**0.5, # Square root of NOT.
cirq.measure(qubit, key='m') # Measurement.
)
# load the circuit as squin
main = load_circuit(circuit)
# print the resulting IR
main.print()

You can also compose kernel functions generated from circuits by passing in and / or returning the respective quantum registers:

import cirq
from bloqade.cirq_utils import load_circuit
from bloqade import squin
q = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q[0]), cirq.CX(*q))
get_entangled_qubits = load_circuit(
circuit, return_register=True, kernel_name="get_entangled_qubits"
)
get_entangled_qubits.print()
entangle_qubits = load_circuit(
circuit, register_as_argument=True, kernel_name="entangle_qubits"
)
@squin.kernel
def main():
qreg = get_entangled_qubits()
qreg2 = squin.qalloc(1)
entangle_qubits([qreg[1], qreg2[0]])
return squin.qubit.measure(qreg2)

Parameters

NameTypeDefaultDescription
circuitcirq.CircuitrequiredThe circuit to load.
kernel_namestr'main'
dialectsir.DialectGroupkernel
register_as_argumentboolFalse
return_registerboolFalse
register_argument_namestr'q'
globalsdict[str, Any] | NoneNone
filestr | NoneNone
lineno_offsetint0
col_offsetint0
compactifyboolTrue

Other Parameters

NameTypeDescription
kernel_namestrThe name of the kernel to load. Defaults to "main".
dialectsir.DialectGroup | NoneThe dialects to use. Defaults to `squin.kernel`.
register_as_argumentboolDetermine whether the resulting kernel function should accept a single `ilist.IList[Qubit, Any]` argument that is a list of qubits used within the function. This allows you to compose kernel functions generated from circuits. Defaults to `False`.
return_registerboolDetermine whether the resulting kernel functionr returns a single value of type `ilist.IList[Qubit, Any]` that is the list of qubits used in the kernel function. Useful when you want to compose multiple kernel functions generated from circuits. Defaults to `False`.
register_argument_namestrThe name of the argument that represents the qubit register. Only used when `register_as_argument=True`. Defaults to "q".
globalsdict[str, Any] | NoneThe global variables to use. Defaults to None.
filestr | NoneThe file name for error reporting. Defaults to None.
lineno_offsetintThe line number offset for error reporting. Defaults to 0.
col_offsetintThe column number offset for error reporting. Defaults to 0.
compactifyboolWhether to compactify the output. Defaults to True.
source