bloqade.cirq_utils.lowering.load_circuit
← Module overview
function
source
functionload_circuit¶source
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.
Usage Examples:
Section titled “Usage Examples:”# from cirq's "hello qubit" exampleimport cirqfrom 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 squinmain = load_circuit(circuit)
# print the resulting IRmain.print()You can also compose kernel functions generated from circuits by passing in and / or returning the respective quantum registers:
import cirqfrom bloqade.cirq_utils import load_circuitfrom 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.kerneldef main(): qreg = get_entangled_qubits() qreg2 = squin.qalloc(1) entangle_qubits([qreg[1], qreg2[0]]) return squin.qubit.measure(qreg2)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
circuit | cirq.Circuit | required | The circuit to load. |
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 |
Other Parameters
| Name | Type | Description |
|---|---|---|
kernel_name | str | The name of the kernel to load. Defaults to "main". |
dialects | ir.DialectGroup | None | The dialects to use. Defaults to `squin.kernel`. |
register_as_argument | bool | Determine 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_register | bool | Determine 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_name | str | The name of the argument that represents the qubit register. Only used when `register_as_argument=True`. Defaults to "q". |
globals | dict[str, Any] | None | The global variables to use. Defaults to None. |
file | str | None | The file name for error reporting. Defaults to None. |
lineno_offset | int | The line number offset for error reporting. Defaults to 0. |
col_offset | int | The column number offset for error reporting. Defaults to 0. |
compactify | bool | Whether to compactify the output. Defaults to True. |