|
5 | 5 | from bloqade.analysis.measure_id import MeasurementIDAnalysis |
6 | 6 | from bloqade.stim.passes.flatten import Flatten |
7 | 7 | from bloqade.analysis.measure_id.lattice import ( |
8 | | - AnyMeasureId, |
9 | 8 | NotMeasureId, |
10 | 9 | MeasureIdBool, |
11 | 10 | MeasureIdTuple, |
@@ -185,14 +184,21 @@ def test(cond: bool): |
185 | 184 |
|
186 | 185 | return ms |
187 | 186 |
|
188 | | - InlinePass(test.dialects).fixpoint(test) |
| 187 | + # We can use Flatten here because the variable condition for the scf.IfElse |
| 188 | + # means it cannot be simplified. |
| 189 | + Flatten(test.dialects).fixpoint(test) |
189 | 190 | frame, _ = MeasurementIDAnalysis(test.dialects).run_analysis(test) |
190 | | - # the result of the analysis on this Scf.IfElse should be two AnyMeasureIds. |
191 | | - # One AnyMeasureId is from resolving the boolean type, which does not change |
192 | | - # during any of the branches. The other is from the fact that broadcast.measure gives |
193 | | - # an AnyMeasureId because it cannot figure out the concrete number of measurements, which has to be |
194 | | - # joined against the MeasureIdBool from the other branch. |
195 | | - assert list(frame.entries.values())[-2:] == [AnyMeasureId(), AnyMeasureId()] |
| 191 | + analysis_results = [ |
| 192 | + val for val in frame.entries.values() if isinstance(val, MeasureIdTuple) |
| 193 | + ] |
| 194 | + # Both branches of the scf.IfElse should be properly traversed and contain the following |
| 195 | + # analysis results. |
| 196 | + expected_full_register_measurement = MeasureIdTuple( |
| 197 | + data=tuple([MeasureIdBool(idx=i) for i in range(1, 6)]) |
| 198 | + ) |
| 199 | + expected_else_measurement = MeasureIdTuple(data=(MeasureIdBool(idx=6),)) |
| 200 | + assert expected_full_register_measurement in analysis_results |
| 201 | + assert expected_else_measurement in analysis_results |
196 | 202 |
|
197 | 203 |
|
198 | 204 | def test_slice(): |
|
0 commit comments