@@ -70,34 +70,39 @@ def is_subseteq(self, other: Address) -> bool:
7070@final
7171@dataclass
7272class UnknownQubit (Address , metaclass = SingletonMeta ):
73+ """A lattice element representing a single qubit with an unknown address."""
74+
7375 def is_subseteq (self , other : Address ) -> bool :
7476 return isinstance (other , UnknownQubit )
7577
7678
7779@final
7880@dataclass
7981class UnknownReg (Address , metaclass = SingletonMeta ):
82+ """A lattice element representing a container of qubits with unknown indices."""
83+
8084 def is_subseteq (self , other : Address ) -> bool :
8185 return isinstance (other , UnknownReg )
8286
8387
8488@final
8589@dataclass
8690class AddressQubit (Address ):
91+ """A lattice element representing a single qubit with a known address."""
92+
8793 data : int
8894
8995 def is_subseteq (self , other : Address ) -> bool :
9096 if isinstance (other , AddressQubit ):
9197 return self .data == other .data
9298 return False
9399
94- def __hash__ (self ):
95- return hash (AddressQubit ) ^ hash (self .data )
96-
97100
98101@final
99102@dataclass
100103class AddressReg (Address ):
104+ """A lattice element representing a container of qubits with known indices."""
105+
101106 data : Sequence [int ]
102107
103108 def is_subseteq (self , other : Address ) -> bool :
@@ -107,13 +112,12 @@ def is_subseteq(self, other: Address) -> bool:
107112 def qubits (self ) -> tuple [AddressQubit , ...]:
108113 return tuple (AddressQubit (i ) for i in self .data )
109114
110- def __hash__ (self ):
111- return hash (AddressReg ) ^ hash (tuple (self .data ))
112-
113115
114116@final
115117@dataclass
116118class PartialLambda (Address ):
119+ """Represents a partially known lambda function"""
120+
117121 argnames : list [str ]
118122 code : ir .Statement
119123 captured : tuple [Address , ...]
@@ -177,7 +181,7 @@ def new(cls, data: tuple[Address, ...]):
177181 return cls (data )
178182
179183 def join (self , other : "Address" ) -> "Address" :
180- if isinstance (other , StaticContainer ) and len (self .data ) == len (other .data ):
184+ if isinstance (other , type ( self ) ) and len (self .data ) == len (other .data ):
181185 return self .new (tuple (x .join (y ) for x , y in zip (self .data , other .data )))
182186 return self .top ()
183187
@@ -195,6 +199,11 @@ def is_subseteq(self, other: "Address") -> bool:
195199
196200
197201class PartialIListMeta (LatticeAttributeMeta ):
202+ """This metaclass assures that PartialILists of ConstResults or AddressQubits are canonicalized
203+ to a single ConstResult or AddressReg respectively.
204+
205+ """
206+
198207 def __call__ (cls , data : tuple [Address , ...]):
199208 # TODO: when constant prop has PartialIList, make sure to canonicalize here.
200209 if types .is_tuple_of (data , ConstResult ) and types .is_tuple_of (
@@ -213,10 +222,12 @@ def __call__(cls, data: tuple[Address, ...]):
213222
214223@final
215224class PartialIList (StaticContainer , metaclass = PartialIListMeta ):
216- pass
225+ """A lattice element representing a partially known ilist."""
217226
218227
219228class PartialTupleMeta (LatticeAttributeMeta ):
229+ """This metaclass assures that PartialTuples of ConstResults are canonicalized to a single ConstResult."""
230+
220231 def __call__ (cls , data : tuple [Address , ...]):
221232 if not types .is_tuple_of (data , ConstResult ):
222233 return super ().__call__ (data )
@@ -226,4 +237,4 @@ def __call__(cls, data: tuple[Address, ...]):
226237
227238@final
228239class PartialTuple (StaticContainer , metaclass = PartialTupleMeta ):
229- pass
240+ """A lattice element representing a partially known tuple."""
0 commit comments