Skip to content

Commit 165c4a8

Browse files
committed
update comments, use latest and greatest methods from kirin
1 parent 78a1a37 commit 165c4a8

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

src/bloqade/analysis/measure_id/analysis.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from typing import TypeVar
21
from dataclasses import field, dataclass
32

43
from kirin import ir
5-
from kirin.analysis import ForwardExtra, const
4+
from kirin.analysis import ForwardExtra
65
from kirin.analysis.forward import ForwardFrame
76

87
from .lattice import MeasureId, NotMeasureId
@@ -33,22 +32,5 @@ def eval_fallback(
3332
) -> tuple[MeasureId, ...]:
3433
return tuple(NotMeasureId() for _ in node.results)
3534

36-
# Xiu-zhe (Roger) Luo came up with this in the address analysis,
37-
# reused here for convenience (now modified to be a bit more graceful)
38-
# TODO: Remove this function once upgrade to kirin 0.18 happens,
39-
# method is built-in to interpreter then
40-
41-
T = TypeVar("T")
42-
43-
def get_const_value(
44-
self, input_type: type[T] | tuple[type[T], ...], value: ir.SSAValue
45-
) -> type[T] | None:
46-
if isinstance(hint := value.hints.get("const"), const.Value):
47-
data = hint.data
48-
if isinstance(data, input_type):
49-
return hint.data
50-
51-
return None
52-
5335
def method_self(self, method: ir.Method) -> MeasureId:
5436
return self.lattice.bottom()

src/bloqade/analysis/measure_id/impls.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
)
1616
from .analysis import MeasureIDFrame, MeasurementIDAnalysis
1717

18-
## Can't do wire right now because of
19-
## unresolved RFC on return type
20-
# from bloqade.squin import wire
21-
2218

2319
@qubit.dialect.register(key="measure_id")
2420
class SquinQubit(interp.MethodTable):
@@ -32,7 +28,6 @@ def measure_qubit_list(
3228
):
3329

3430
# try to get the length of the list
35-
## "...safely assume the type inference will give you what you need"
3631
qubits_type = stmt.qubits.type
3732
# vars[0] is just the type of the elements in the ilist,
3833
# vars[1] can contain a literal with length information
@@ -57,15 +52,12 @@ def measurement_predicate(
5752
stmt: qubit.stmts.IsLost | qubit.stmts.IsOne | qubit.stmts.IsZero,
5853
):
5954
original_measure_id_tuple = frame.get(stmt.measurements)
60-
# all members should be RawMeasureId, if it's anything else
61-
# it's Invalid.
6255
if not all(
6356
isinstance(measure_id, RawMeasureId)
6457
for measure_id in original_measure_id_tuple.data
6558
):
6659
return (InvalidMeasureId(),)
6760

68-
# get the proper predicate type
6961
if isinstance(stmt, qubit.stmts.IsLost):
7062
predicate = Predicate.IS_LOST
7163
elif isinstance(stmt, qubit.stmts.IsOne):
@@ -75,7 +67,6 @@ def measurement_predicate(
7567
else:
7668
return (InvalidMeasureId(),)
7769

78-
# Create new MeasureIdBools with proper predicate type
7970
predicate_measure_ids = [
8071
MeasureIdBool(measure_id.idx, predicate)
8172
for measure_id in original_measure_id_tuple.data
@@ -131,14 +122,10 @@ def getitem(
131122
self, interp: MeasurementIDAnalysis, frame: interp.Frame, stmt: py.GetItem
132123
):
133124

134-
idx_or_slice = interp.get_const_value((int, slice), stmt.index)
125+
idx_or_slice = interp.maybe_const(stmt.index, (int, slice))
135126
if idx_or_slice is None:
136127
return (InvalidMeasureId(),)
137128

138-
# hint = stmt.index.hints.get("const")
139-
# if hint is None or not isinstance(hint, const.Value):
140-
# return (InvalidMeasureId(),)
141-
142129
obj = frame.get(stmt.obj)
143130
if isinstance(obj, MeasureIdTuple):
144131
if isinstance(idx_or_slice, slice):

0 commit comments

Comments
 (0)