dialects
auxiliary
stmts
const
ConstBool
Bases: Statement
IR Statement representing a constant boolean value.
result
class-attribute
instance-attribute
result: ResultValue = result(Bool)
result (Float): The result value.
value
class-attribute
instance-attribute
value: bool = attribute(Bool)
value (float): The constant float value.
ConstFloat
Bases: Statement
IR Statement representing a constant float value.
result
class-attribute
instance-attribute
result: ResultValue = result(Float)
result (Float): The result value.
value
class-attribute
instance-attribute
value: float = attribute(Float)
value (float): The constant float value.
ConstInt
Bases: Statement
IR Statement representing a constant integer value.
result
class-attribute
instance-attribute
result: ResultValue = result(Int)
result (Int): The result value.
value
class-attribute
instance-attribute
value: int = attribute(Int)
value (int): The constant integer value.
ConstStr
Bases: Statement
IR Statement representing a constant str value.
result
class-attribute
instance-attribute
result: ResultValue = result(String)
result (str): The result value.
value
class-attribute
instance-attribute
value: str = attribute(String)
value (str): The constant str value.
Neg
Bases: Statement
IR Statement representing a negation operation.
collapse
stmts
measure
Measurement
Bases: Statement
p
class-attribute
instance-attribute
p: SSAValue = argument(Float)
probability of noise introduced by measurement. For example 0.01 means 1% the measurement will be flipped
pp_measure
PPMeasurement
Bases: Statement
p
class-attribute
instance-attribute
p: SSAValue = argument(Float)
probability of noise introduced by measurement. For example 0.01 means 1% the measurement will be flipped
parse
lowering
One-to-one lowering routine from stim circuit to a stim-dialect kirin kernel.
loads
loads(
stim_str: str,
*,
kernel_name: str = "main",
ignore_unknown_stim: bool = False,
error_unknown_nonstim: bool = False,
nonstim_noise_ops: dict[str, type[Statement]] = {},
dialects: DialectGroup | None = None,
globals: dict[str, Any] | None = None,
file: str | None = None,
lineno_offset: int = 0,
col_offset: int = 0,
compactify: bool = True
) -> ir.Method[[], None]
Loads a STIM string and returns the corresponding kernel object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stim_str
|
str
|
The string representation of a STIM circuit to load. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
kernel_name |
str
|
The name of the kernel to load. Defaults to "main". |
ignore_unknown_stim |
bool
|
If True, don't throw a build error on an unimplemented stim instruction. |
error_unknown_nonstim |
bool
|
If True, throw a build error if an unknown tag is
used on the |
nonstim_noise_ops |
dict[str, Statement]
|
Additional statements to
represent non-standard stim operations. The dictionary key should match the
tag used to identify it in stim (stim format
|
dialects |
DialectGroup | None
|
The dialects to use. Defaults to |
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. |
Example:
from bloqade.stim.lowering import loads
method = loads('''
X 0 2 4
DEPOLARIZE1(0.01) 0
I_ERROR[CUSTOM_ERROR](0.02) 2 4
M 0 2 4
DETECTOR rec[-1] rec[-2]
''')
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/parse/lowering.py
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 |
|
rewrite
ifs_to_stim
IfElseSimplification
dataclass
IfElseSimplification()
contains_ifelse
contains_ifelse(stmt: IfElse) -> bool
Check if the IfElse statement contains another IfElse statement.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/ifs_to_stim.py
35 36 37 38 39 40 |
|
has_else_body
has_else_body(stmt: IfElse) -> bool
Check if the IfElse statement has an else body.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/ifs_to_stim.py
57 58 59 60 61 62 63 64 65 66 |
|
is_nested_ifelse
is_nested_ifelse(stmt: IfElse) -> bool
Check if the IfElse statement is nested.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/ifs_to_stim.py
45 46 47 48 49 50 51 52 53 54 55 |
|
IfToStim
dataclass
IfToStim(
measure_analysis: dict[SSAValue, MeasureId],
measure_count: int,
)
StimSplitIfStmts
dataclass
StimSplitIfStmts()
Bases: IfElseSimplification
, SplitIfStmts
Splits the then body of an if-else statement into multiple if statements
Given an IfElse with multiple valid statements in the then-body:
if measure_result
squin.qubit.apply(op.X, q0) squin.qubit.apply(op.Y, q1)
this should be rewritten to:
if measure_result
squin.qubit.apply(op.X, q0)
if measure_result
squin.qubit.apply(op.Y, q1)
qubit_to_stim
SquinQubitToStim
Bases: RewriteRule
NOTE this require address analysis result to be wrapped before using this rule.
rewrite_Apply_and_Broadcast
rewrite_Apply_and_Broadcast(
stmt: Apply | Broadcast,
) -> RewriteResult
Rewrite Apply and Broadcast nodes to their stim equivalent statements.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/qubit_to_stim.py
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 |
|
squin_measure
SquinMeasureToStim
dataclass
SquinMeasureToStim(
measure_id_result: dict[SSAValue, MeasureId],
total_measure_count: int,
)
Bases: RewriteRule
Rewrite squin measure-related statements to stim statements.
get_qubit_idx_ssas
get_qubit_idx_ssas(
measure_stmt: MeasureQubit | MeasureQubitList | Measure,
) -> tuple[ir.SSAValue, ...] | None
Extract the address attribute and insert qubit indices for the given measure statement.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_measure.py
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 |
|
insert_get_record_list
insert_get_record_list(
node: Statement,
measure_id_tuple: MeasureIdTuple,
meas_count: int,
)
Insert GetRecord statements before the given node
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_measure.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
squin_noise
SquinNoiseToStim
dataclass
SquinNoiseToStim()
Bases: RewriteRule
rewrite_Apply_and_Broadcast
rewrite_Apply_and_Broadcast(
stmt: Apply | Broadcast,
) -> RewriteResult
Rewrite Apply and Broadcast to their stim statements.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_noise.py
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 |
|
rewrite_Depolarize
rewrite_Depolarize(
stmt: Apply | Broadcast | Broadcast | Apply,
qubit_idx_ssas: Tuple[SSAValue],
) -> Statement
Rewrite squin.noise.Depolarize to stim.Depolarize1.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_noise.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
rewrite_Depolarize2
rewrite_Depolarize2(
stmt: Apply | Broadcast | Broadcast | Apply,
qubit_idx_ssas: Tuple[SSAValue],
) -> Statement
Rewrite squin.noise.Depolarize2 to stim.Depolarize2.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_noise.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
rewrite_PauliError
rewrite_PauliError(
stmt: Apply | Broadcast | Broadcast | Apply,
qubit_idx_ssas: Tuple[SSAValue],
) -> Statement
Rewrite squin.noise.PauliError to XError, YError, ZError.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_noise.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
rewrite_SingleQubitPauliChannel
rewrite_SingleQubitPauliChannel(
stmt: Apply | Broadcast | Broadcast | Apply,
qubit_idx_ssas: Tuple[SSAValue],
) -> Statement
Rewrite squin.noise.SingleQubitPauliChannel to stim.PauliChannel1.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_noise.py
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 |
|
rewrite_TwoQubitPauliChannel
rewrite_TwoQubitPauliChannel(
stmt: Apply | Broadcast | Broadcast | Apply,
qubit_idx_ssas: Tuple[SSAValue],
) -> Statement
Rewrite squin.noise.SingleQubitPauliChannel to stim.PauliChannel1.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/squin_noise.py
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 |
|
util
insert_qubit_idx_after_apply
insert_qubit_idx_after_apply(
stmt: Apply | Apply | Broadcast | Broadcast,
) -> tuple[ir.SSAValue, ...] | None
Extract qubit indices from Apply or Broadcast statements.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/util.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
insert_qubit_idx_from_address
insert_qubit_idx_from_address(
address: AddressAttribute,
stmt_to_insert_before: Statement,
) -> tuple[ir.SSAValue, ...] | None
Extract qubit indices from an AddressAttribute and insert them into the SSA form.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/util.py
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 |
|
insert_qubit_idx_from_wire_ssa
insert_qubit_idx_from_wire_ssa(
wire_ssas: tuple[SSAValue, ...],
stmt_to_insert_before: Statement,
) -> tuple[ir.SSAValue, ...] | None
Extract qubit indices from wire SSA values and insert them into the SSA form.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/util.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
is_measure_result_used
is_measure_result_used(
stmt: MeasureQubit | MeasureQubitList | Measure,
) -> bool
Check if the result of a measure statement is used in the program.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/util.py
200 201 202 203 204 205 206 |
|
rewrite_Control
rewrite_Control(
stmt_with_ctrl: Apply | Apply | Broadcast | Broadcast,
) -> RewriteResult
Handle control gates for Apply and Broadcast statements.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/util.py
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 159 160 161 162 |
|
rewrite_QubitLoss
rewrite_QubitLoss(
stmt: Apply | Broadcast | Broadcast | Apply,
) -> RewriteResult
Rewrite QubitLoss statements to Stim's TrivialError.
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/util.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
wire_identity_elimination
SquinWireIdentityElimination
Bases: RewriteRule
rewrite_Statement
rewrite_Statement(node: Statement) -> RewriteResult
Handle the case where an unwrap feeds a wire directly into a wrap, equivalent to nothing happening/identity operation
w = unwrap(qubit) wrap(qubit, w)
Source code in .venv/lib/python3.12/site-packages/bloqade/stim/rewrite/wire_identity_elimination.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|