Skip to content

Commit a2af2f3

Browse files
committed
Fix commutativity of join operation
1 parent 2bf369e commit a2af2f3

File tree

1 file changed

+13
-17
lines changed
  • src/bloqade/analysis/validation/nocloning

1 file changed

+13
-17
lines changed

src/bloqade/analysis/validation/nocloning/lattice.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def is_subseteq(self, other: QubitValidation) -> bool:
4343
return True
4444

4545
def join(self, other: QubitValidation) -> QubitValidation:
46+
match other:
47+
case Bottom():
48+
return self
49+
case Must(violations=v):
50+
return May(violations=v)
51+
case May() | Top():
52+
return other
4653
return other
4754

4855
def meet(self, other: QubitValidation) -> QubitValidation:
@@ -87,25 +94,14 @@ def is_subseteq(self, other: QubitValidation) -> bool:
8794
return False
8895

8996
def join(self, other: QubitValidation) -> QubitValidation:
90-
"""Join with another validation state.
91-
92-
Key insight: Must ⊔ Bottom = May (error on one path, not all)
93-
"""
9497
match other:
9598
case Bottom():
96-
# Error in one branch, safe in other = May (conditional error)
97-
result = May(violations=self.violations)
98-
return result
99+
return May(violations=self.violations)
99100
case Must(violations=ov):
100-
# Errors in both branches
101-
common = self.violations & ov
102-
all_violations = self.violations | ov
103-
if common == all_violations:
104-
# Same errors on all paths = Must
105-
return Must(violations=all_violations)
101+
if self.violations == ov:
102+
return Must(violations=self.violations)
106103
else:
107-
# Different errors on different paths = May
108-
return May(violations=all_violations)
104+
return May(violations=self.violations | ov)
109105
case May(violations=ov):
110106
return May(violations=self.violations | ov)
111107
case Top():
@@ -120,7 +116,7 @@ def meet(self, other: QubitValidation) -> QubitValidation:
120116
inter = self.violations & ov
121117
return Must(violations=inter) if inter else Bottom()
122118
case May(violations=ov):
123-
inter = self.violations & ov if ov else self.violations
119+
inter = self.violations & ov
124120
return Must(violations=inter) if inter else Bottom()
125121
case Top():
126122
return self
@@ -166,7 +162,7 @@ def meet(self, other: QubitValidation) -> QubitValidation:
166162
case Bottom():
167163
return Bottom()
168164
case Must(violations=ov):
169-
inter = self.violations & ov if ov else ov or self.violations
165+
inter = self.violations & ov
170166
return Must(violations=inter) if inter else Bottom()
171167
case May(violations=ov):
172168
inter = self.violations & ov

0 commit comments

Comments
 (0)