Lowering
Squin
dataclass
Squin(circuit: Circuit)
Bases: LoweringABC[Circuit]
Lower a cirq.Circuit object to a squin kernel
load_circuit
load_circuit(
circuit: Circuit,
kernel_name: str = "main",
dialects: 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit
|
Circuit
|
The circuit to load. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
kernel_name |
str
|
The name of the kernel to load. Defaults to "main". |
dialects |
DialectGroup | None
|
The dialects to use. Defaults to |
register_as_argument |
bool
|
Determine whether the resulting kernel function should accept
a single |
return_register |
bool
|
Determine whether the resulting kernel functionr returns a
single value of type |
register_argument_name |
str
|
The name of the argument that represents the qubit register.
Only used when |
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. |
Usage Examples:
# 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)
Source code in .venv/lib/python3.12/site-packages/bloqade/cirq_utils/lowering.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |