Qubit
qubit dialect for squin language.
This dialect defines the operations that can be performed on qubits.
Depends on:
- bloqade.squin.op
: provides the OpType
type and semantics for operators applied to qubits.
- kirin.dialects.ilist
: provides the ilist.IListType
type for lists of qubits.
apply
apply(operator: Op, *qubits: Qubit) -> None
Apply an operator to qubits. The number of qubit arguments must match the size of the operator.
Note, that when considering atom loss, lost qubits will be skipped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
Op
|
The operator to apply. |
required |
*qubits
|
Qubit
|
The qubits to apply the operator to. The number of qubits must match the size of the operator. |
()
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
broadcast
broadcast(
operator: Op,
*qubits: IList[Qubit, OpSize] | list[Qubit]
) -> None
Broadcast and apply an operator to lists of qubits. The number of qubit lists must match the size of the operator and the lists must be of same length. The operator is then applied to the list elements similar to what python's map function does.
Usage examples
from bloqade import squin
@squin.kernel
def ghz():
controls = squin.qubit.new(4)
targets = squin.qubit.new(4)
h = squin.op.h()
squin.qubit.broadcast(h, controls)
cx = squin.op.cx()
squin.qubit.broadcast(cx, controls, targets)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
Op
|
The operator to broadcast and apply. |
required |
qubits
|
IList[Qubit, OpSize] | list[Qubit]
|
The list of qubits to broadcast and apply the operator to. The size of the list must be inferable and match the number of qubits expected by the operator. |
()
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
measure
measure(input: Qubit) -> MeasurementResult
measure(
input: IList[Qubit, Any] | list[Qubit],
) -> ilist.IList[MeasurementResult, Any]
measure(input: Any) -> Any
Measure a qubit or qubits in the list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Any
|
A qubit or a list of qubits to measure. |
required |
Returns:
Type | Description |
---|---|
Any
|
MeasurementResult | list[MeasurementResult]: The result of the measurement. If a single qubit is measured, a single result is returned. If a list of qubits is measured, a list of results is returned. A MeasurementResult can represent both 0 and 1, but also atoms that are lost. |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
new
new(n_qubits: int) -> ilist.IList[Qubit, Any]
Create a new list of qubits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_qubits
|
int
|
The number of qubits to create. |
required |
Returns:
Type | Description |
---|---|
IList[Qubit, Any]
|
(ilist.IList[Qubit, n_qubits]) A list of qubits. |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
97 98 99 100 101 102 103 104 105 106 107 |
|