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
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
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
|
bool | list[bool]: The result of the measurement. If a single qubit is measured, a single boolean is returned. If a list of qubits is measured, a list of booleans is returned. |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
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
83 84 85 86 87 88 89 90 91 92 93 |
|