analysis
schedule
StmtDag
dataclass
StmtDag(
id_table: IdTable[
Statement
] = lambda: idtable.IdTable()(),
stmts: Dict[str, Statement] = OrderedDict(),
out_edges: Dict[str, Set[str]] = OrderedDict(),
inc_edges: Dict[str, Set[str]] = OrderedDict(),
stmt_index: Dict[Statement, int] = OrderedDict(),
)
Bases: Graph[Statement]
topological_groups
topological_groups()
Split the dag into topological groups where each group contains nodes that have no dependencies on each other, but have dependencies on nodes in one or more previous groups.
Yields:
Type | Description |
---|---|
List[str]: A list of node ids in a topological group |
Raises:
Type | Description |
---|---|
ValueError
|
If a cyclic dependency is detected |
The idea is to yield all nodes with no dependencies, then remove those nodes from the graph repeating until no nodes are left or we reach some upper limit. Worse case is a linear dag, so we can use len(dag.stmts) as the upper limit
If we reach the limit and there are still nodes left, then we have a cyclic dependency.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/analysis/schedule.py
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 |
|
noise
stmts
Depolarize
Bases: NoiseChannel
Apply n-qubit depolaize error to qubits NOTE For Stim, this can only accept 1 or 2 qubits
PPError
Bases: NoiseChannel
Pauli Product Error
op
ch
ch() -> types.Op
Control H gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
153 154 155 156 |
|
control
control(op: Op, *, n_controls: int) -> types.Op
Create a controlled operator.
Note, that when considering atom loss, the operator will not be applied if any of the controls has been lost.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
The operator to apply under the control. |
required | |
n_controls
|
int
|
The number qubits to be used as control. |
required |
Returns:
Type | Description |
---|---|
Op
|
Operator |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
cphase
cphase(theta: float) -> types.Op
Control Phase gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
159 160 161 162 |
|
cx
cx() -> types.Op
Controlled X gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
135 136 137 138 |
|
cy
cy() -> types.Op
Controlled Y gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
141 142 143 144 |
|
cz
cz() -> types.Op
Control Z gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
147 148 149 150 |
|
rx
rx(theta: float) -> types.Op
Rotation X gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
117 118 119 120 |
|
ry
ry(theta: float) -> types.Op
Rotation Y gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
123 124 125 126 |
|
rz
rz(theta: float) -> types.Op
Rotation Z gate.
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/op/__init__.py
129 130 131 132 |
|
rewrite
Rewrite py.binop.mult to Mult stmt
stmts
P0
Bases: ConstantOp
The \(P_0\) projection operator.
P1
Bases: ConstantOp
The \(P_1\) projection operator.
PhaseOp
Bases: PrimitiveOp
A phase operator.
ShiftOp
Bases: PrimitiveOp
A phase shift operator.
Sn
Bases: ConstantOp
\(S_{-}\) operator.
Sp
Bases: ConstantOp
\(S_{+}\) operator.
traits
HasSites
dataclass
HasSites()
Bases: StmtTrait
An operator with a sites
attribute.
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: IList[Qubit, Any] | list[Qubit]
) -> None
Apply an operator to a list of qubits.
Note, that when considering atom loss, lost qubits will be skipped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
Op
|
The operator to apply. |
required |
qubits
|
IList[Qubit, Any] | list[Qubit]
|
The list of qubits to apply the operator to. The size of the list must be inferable and match the number of qubits expected by the operator. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
broadcast
broadcast(
operator: Op, qubits: IList[Qubit, Any] | list[Qubit]
) -> None
Broadcast and apply an operator to a list of qubits. For example, an operator that expects 2 qubits can be applied to a list of 2n qubits, where n is an integer > 0.
For controlled operators, the list of qubits is interpreted as sets of (controls, targets). For example
apply(CX, [q0, q1, q2, q3])
is equivalent to
apply(CX, [q0, q1])
apply(CX, [q2, q3])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
Op
|
The operator to broadcast and apply. |
required |
qubits
|
IList[Qubit, Any] | 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. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
measure
measure(input: Qubit) -> bool
measure(
input: IList[Qubit, Any] | list[Qubit],
) -> ilist.IList[bool, 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
121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
measure_and_reset
measure_and_reset(
qubits: IList[Qubit, Any],
) -> ilist.IList[bool, Any]
Measure the qubits in the list and reset them."
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qubits
|
IList[Qubit, Any]
|
The list of qubits to measure and reset. |
required |
Returns:
Type | Description |
---|---|
IList[bool, Any]
|
list[bool]: The result of the measurement. |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
166 167 168 169 170 171 172 173 174 175 176 |
|
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
85 86 87 88 89 90 91 92 93 94 95 |
|
reset
reset(qubits: IList[Qubit, Any]) -> None
Reset the qubits in the list."
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qubits
|
IList[Qubit, Any]
|
The list of qubits to reset. |
required |
Source code in .venv/lib/python3.12/site-packages/bloqade/squin/qubit.py
179 180 181 182 183 184 185 186 |
|
rewrite
measure_desugar
MeasureDesugarRule
Bases: RewriteRule
Desugar measure operations in the circuit.
wire
A NVIDIA QUAKE-like wire dialect.
This dialect is expected to be used in combination with the operator dialect as an intermediate representation for analysis and optimization of quantum circuits. Thus we do not define wrapping functions for the statements in this dialect.