Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8cc90c4
bring record analysis work over
johnzl-777 Nov 9, 2025
4e56293
save wip test_record_analysis
johnzl-777 Nov 10, 2025
7c1c306
Merge branch 'main' into john/repeat-support
johnzl-777 Nov 10, 2025
8115bf4
Merge branch 'main' into john/repeat-support
johnzl-777 Nov 11, 2025
eee712d
update to new kirin
johnzl-777 Nov 11, 2025
4e1da7b
almost there, still a problem with invariance checking
johnzl-777 Nov 17, 2025
09130c6
loop invariance support complete
johnzl-777 Nov 18, 2025
cf5cb1f
add a set observable just to really make sure things work properly
johnzl-777 Nov 18, 2025
43675fd
fix variable names in test
johnzl-777 Nov 20, 2025
d19f3ef
move record analysis prototype into measure id analysis
johnzl-777 Nov 21, 2025
6bbf11f
add REPEAT statement in stim
johnzl-777 Nov 21, 2025
ca354af
save work before trying to hammer down obnoxious ownership issues
johnzl-777 Nov 23, 2025
3f7ad41
corrected logic in record analysis prototype with Kai's advice, can s…
johnzl-777 Nov 24, 2025
d4113e6
get rid of a bunch of debug print statements
johnzl-777 Nov 24, 2025
4920273
remove more record analysis debug prints and move everything into mea…
johnzl-777 Nov 24, 2025
a8da761
try to merge in latest work
johnzl-777 Dec 4, 2025
79880d4
Merge branch 'main' into john/repeat-support
johnzl-777 Dec 7, 2025
a39a126
latest attempt to try to reconcile type lattices
johnzl-777 Dec 8, 2025
8c5f453
Merge branch 'main' into john/repeat-support
johnzl-777 Dec 8, 2025
b4c4559
still need to find a solution to proper IfElse handling
johnzl-777 Dec 9, 2025
5aa3bfc
Merge branch 'main' into john/repeat-support
johnzl-777 Dec 9, 2025
927fcd8
figured out way to handle scf.IfElse with new lattice
johnzl-777 Dec 9, 2025
4d62a47
get decent portion of qubit and annotate to stim tests fully working,…
johnzl-777 Dec 10, 2025
5013602
delay CSE due to getitem uniqueness issues
johnzl-777 Dec 10, 2025
4da0eed
Merge branch 'main' into john/repeat-support
johnzl-777 Dec 10, 2025
9be26cd
fix coordinate conversion with ilist as the new type for set_detector
johnzl-777 Dec 11, 2025
782ca80
caught some problems with coordinate rewrite as well as address analy…
johnzl-777 Dec 12, 2025
356dcfd
need to remove dead measures, confirm full repetition code works
johnzl-777 Dec 12, 2025
d4858d3
remove debug print statement
johnzl-777 Dec 12, 2025
1b4fbd4
fix test failures with coordinates
johnzl-777 Dec 15, 2025
32a6582
restore test functionality, missed the measurement inbetween to get t…
johnzl-777 Dec 15, 2025
0fec8ba
finish turning development examples into proper tests
johnzl-777 Dec 16, 2025
9ec62d4
finally let go of the original record analysis. Farewell old friend
johnzl-777 Dec 16, 2025
d4f2bb3
Merge branch 'main' into john/repeat-support
weinbe58 Dec 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ mch = "mch"
IY = "IY"
ket = "ket"
typ = "typ"
anc_qs = "anc_qs" # "ancilla qubits" variable abbreivation - used to be autocorrected to AND_QS! :sigh:
75 changes: 70 additions & 5 deletions src/bloqade/analysis/measure_id/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,86 @@
from kirin.analysis import ForwardExtra
from kirin.analysis.forward import ForwardFrame

from .lattice import MeasureId, NotMeasureId
from .lattice import (
MeasureId,
NotMeasureId,
RawMeasureId,
MeasureIdTuple,
PredicatedMeasureId,
)


@dataclass
class GlobalRecordState:
# every time a cond value is encountered inside scf
# detach and save it here because I need to let it update
# if it gets used again somewhere else
type_for_scf_conds: dict[ir.Statement, MeasureId] = field(default_factory=dict)
buffer: list[RawMeasureId | PredicatedMeasureId] = field(default_factory=list)

def add_record_idxs(self, num_new_records: int) -> MeasureIdTuple:
# adjust all previous indices
for record_idx in self.buffer:
record_idx.idx -= num_new_records

# generate new indices and add them to the buffer
new_record_idxs = [RawMeasureId(-i) for i in range(num_new_records, 0, -1)]
self.buffer += new_record_idxs
# Return for usage, idxs linked to the global state
return MeasureIdTuple(data=tuple(new_record_idxs))

# Need for loop invariance, especially when you
# run the loop twice "behind the scenes". Then
# it isn't sufficient to just have two
# copies of a lattice element point to one entry on the
# buffer

def clone_measure_id_tuple(
self, measure_id_tuple: MeasureIdTuple
) -> MeasureIdTuple:
cloned_members = []
for measure_id in measure_id_tuple.data:
cloned_measure_id = self.clone_measure_ids(measure_id)
cloned_members.append(cloned_measure_id)
return MeasureIdTuple(data=tuple(cloned_members))

def clone_raw_measure_id(self, raw_measure_id: RawMeasureId) -> RawMeasureId:
cloned_raw_measure_id = RawMeasureId(raw_measure_id.idx)
self.buffer.append(cloned_raw_measure_id)
return cloned_raw_measure_id

def clone_measure_ids(self, measure_id_type: MeasureId) -> MeasureId:

if isinstance(measure_id_type, RawMeasureId):
return self.clone_raw_measure_id(measure_id_type)
elif isinstance(measure_id_type, PredicatedMeasureId):
return self.clone_predicated_measure_id(measure_id_type)
elif isinstance(measure_id_type, MeasureIdTuple):
cloned_members = []
for member in measure_id_type.data:
cloned_member = self.clone_measure_ids(member)
cloned_members.append(cloned_member)
return MeasureIdTuple(data=tuple(cloned_members))

def offset_existing_records(self, offset: int):
for record_idx in self.buffer:
record_idx.idx -= offset


@dataclass
class MeasureIDFrame(ForwardFrame[MeasureId]):
num_measures_at_stmt: dict[ir.Statement, int] = field(default_factory=dict)
global_record_state: GlobalRecordState = field(default_factory=GlobalRecordState)
# every time a cond value is encountered inside scf
# detach and save it here because I need to let it update
# if it gets used again somewhere else
type_for_scf_conds: dict[ir.Statement, MeasureId] = field(default_factory=dict)
measure_count_offset: int = 0


class MeasurementIDAnalysis(ForwardExtra[MeasureIDFrame, MeasureId]):

keys = ["measure_id"]
lattice = MeasureId
# for every kind of measurement encountered, increment this
# then use this to generate the negative values for target rec indices
measure_count = 0

def initialize_frame(
self, node: ir.Statement, *, has_parent_access: bool = False
Expand Down
Loading
Loading