Skip to content

Commit 5520ce1

Browse files
committed
Fix merge errors
1 parent bce9e79 commit 5520ce1

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

inflation/lp/InflationLP.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ def __init__(self,
159159
# them to inequalities when the LHS is non_CG but childless-only.
160160
if np.any(self.does_not_have_children):
161161
bad_boolvecs_for_ineqs = [bool_array[-1] for bool_array in self._CG_adjusting_ortho_groups_as_boolarrays]
162-
self._boolvec_for_not_being_in_CG_notation = np.bitwise_or.reduce(bad_boolvecs_for_ineqs, axis=0)
162+
self._boolvec_for_CG_ineqs = np.bitwise_or.reduce(bad_boolvecs_for_ineqs, axis=0)
163163
else:
164-
self._boolvec_for_not_being_in_CG_notation = self.blank_bool_vec
164+
self._boolvec_for_CG_ineqs = self.blank_bool_vec
165165
if np.any(self.has_children):
166-
bad_boolvecs_for_eqs = [bool_array[-1] for bool_array in self._CG_nonadjusting_ortho_groups_as_boolarrays]
167-
self._boolvec_to_trigger_equality_generation = np.bitwise_or.reduce(bad_boolvecs_for_eqs, axis=0)
166+
bad_boolvecs_for_eqs = [bool_array[0] for bool_array in self._CG_nonadjusting_ortho_groups_as_boolarrays]
167+
self._boolvec_for_FR_eqs = np.bitwise_or.reduce(bad_boolvecs_for_eqs, axis=0)
168168
else:
169-
self._boolvec_to_trigger_equality_generation = self.blank_bool_vec
169+
self._boolvec_for_FR_eqs = self.blank_bool_vec
170170

171171
if self.verbose > 1:
172172
print("Number of single operator measurements per party:", end="")
@@ -1294,7 +1294,7 @@ def _generate_lp(self) -> None:
12941294
self.monomial_from_name[self.constant_term_name] = self.Constant_Term
12951295

12961296
self.raw_n_columns = len(self._raw_monomials_as_lexboolvecs)
1297-
self.n_maximal_events = len(self._maximal_event_as_lexboolvecs)
1297+
self.raw_n_columns_non_CG = len(self._raw_monomials_as_lexboolvecs_non_CG)
12981298

12991299
self._raw_lookup_dict = {bitvec.tobytes(): i for i, bitvec in
13001300
enumerate(self._raw_monomials_as_lexboolvecs)}
@@ -1315,26 +1315,26 @@ def _generate_lp(self) -> None:
13151315
self.num_CG = len(old_reps_CG)
13161316

13171317
orbits_non_CG = self._discover_inflation_orbits(
1318-
self._maximal_event_as_lexboolvecs)
1318+
self._raw_monomials_as_lexboolvecs_non_CG)
13191319
old_reps_non_CG, unique_indices_non_CG, inverse_non_CG = np.unique(
13201320
orbits_non_CG, return_index=True, return_inverse=True)
1321-
self.n_representative_maximal_events = len(old_reps_non_CG)
1321+
self.num_non_CG = len(old_reps_non_CG)
13221322
if self.verbose > 1:
13231323
print(f"Orbits discovered! {self.num_CG} unique monomials.")
13241324
# Obtain the real generating monomials after accounting for symmetry
13251325
else:
13261326
self.num_CG = self.raw_n_columns
13271327
unique_indices_CG = np.arange(self.num_CG)
13281328
inverse_CG = unique_indices_CG
1329-
self.n_representative_maximal_events = self.n_maximal_events
1330-
unique_indices_non_CG = np.arange(self.n_representative_maximal_events)
1329+
self.num_non_CG = self.raw_n_columns_non_CG
1330+
unique_indices_non_CG = np.arange(self.num_non_CG)
13311331
self.inverse = inverse_CG
13321332

13331333
self._monomials_as_lexboolvecs = self._raw_monomials_as_lexboolvecs[unique_indices_CG]
1334-
self._representative_maximal_events_as_lexboolvecs = self._maximal_event_as_lexboolvecs[unique_indices_non_CG]
1334+
self._monomials_as_lexboolvecs_non_CG = self._raw_monomials_as_lexboolvecs_non_CG[unique_indices_non_CG]
13351335
self.n_columns = len(self._monomials_as_lexboolvecs)
13361336

1337-
self.nof_collins_gisin_inequalities = self.n_representative_maximal_events
1337+
self.nof_collins_gisin_inequalities = self.num_non_CG
13381338

13391339
if self.verbose > 0:
13401340
eprint("Number of variables in the LP:",
@@ -1343,11 +1343,9 @@ def _generate_lp(self) -> None:
13431343
self.nof_collins_gisin_inequalities)
13441344

13451345
# Associate Monomials to the remaining entries.
1346-
_monomials = []
1347-
_monomial_names = []
1348-
_compmonomial_from_idx = {}
1349-
_compmonomial_to_idx = {}
1350-
boolvec2mon = {}
1346+
_compmonomial_to_idx = dict()
1347+
self.extra_inverse = np.arange(self.n_columns, dtype=int)
1348+
first_free_index = 0
13511349
for idx, mon_as_lexboolvec in tqdm(enumerate(self._monomials_as_lexboolvecs),
13521350
disable=not self.verbose,
13531351
desc="Initializing monomials ",
@@ -1437,9 +1435,9 @@ def _raw_monomials_as_lexboolvecs(self) -> np.ndarray:
14371435
])
14381436

14391437
@cached_property
1440-
def _maximal_event_as_lexboolvecs(self) -> np.ndarray:
1438+
def _raw_monomials_as_lexboolvecs_non_CG(self) -> np.ndarray:
14411439
r"""Creates the generating set of monomials (as boolvecs),
1442-
of MAXIMAL lengths, NOT limited to Collins-Gisin notation.
1440+
of ALL lengths, limited to Collins-Gisin notation.
14431441
"""
14441442
return np.vstack([
14451443
self._template_to_event_boolarray(clique, self._all_ortho_groups_as_boolarrays)
@@ -1452,10 +1450,10 @@ def minimal_sparse_equalities(self) -> coo_array:
14521450
notation."""
14531451
eq_row, eq_col, eq_data = [], [], []
14541452
nof_equalities = 0
1455-
if np.any(self._boolvec_to_trigger_equality_generation):
1456-
alternatives_as_boolarrays = {v: np.pad(r[:-1], ((1, 0), (0, 0)))
1453+
if np.any(self._boolvec_for_FR_eqs):
1454+
alternatives_as_boolarrays = {v: np.pad(r[1:], ((1, 0), (0, 0)))
14571455
for v, r in zip(
1458-
np.flatnonzero(self._boolvec_to_trigger_equality_generation).flat,
1456+
np.flatnonzero(self._boolvec_for_FR_eqs).flat,
14591457
self._CG_nonadjusting_ortho_groups_as_boolarrays)}
14601458
alternatives_as_signs = {
14611459
i: np.count_nonzero(bool_array, axis=1).astype(bool)
@@ -1464,7 +1462,7 @@ def minimal_sparse_equalities(self) -> coo_array:
14641462
for bool_vec in tqdm(self._monomials_as_lexboolvecs,
14651463
disable=not self.verbose,
14661464
desc="Discovering equalities "):
1467-
critical_boolvec_intersection = np.bitwise_and(bool_vec, self._boolvec_to_trigger_equality_generation)
1465+
critical_boolvec_intersection = np.bitwise_and(bool_vec, self._boolvec_for_FR_eqs)
14681466
if np.any(critical_boolvec_intersection):
14691467

14701468
absent_c_boolvec = bool_vec.copy()
@@ -1525,16 +1523,16 @@ def minimal_sparse_inequalities(self) -> coo_array:
15251523
nof_inequalities = 0
15261524
alternatives_as_boolarrays = {v: np.pad(r[:-1], ((1, 0), (0, 0)))
15271525
for v, r in zip(
1528-
np.flatnonzero(self._boolvec_for_not_being_in_CG_notation).flat,
1526+
np.flatnonzero(self._boolvec_for_CG_ineqs).flat,
15291527
self._CG_adjusting_ortho_groups_as_boolarrays)}
15301528
alternatives_as_signs = {
15311529
i: np.count_nonzero(bool_array, axis=1).astype(bool)
15321530
for i, bool_array in alternatives_as_boolarrays.items()}
1533-
for bool_vec in tqdm(self._representative_maximal_events_as_lexboolvecs,
1531+
for bool_vec in tqdm(self._monomials_as_lexboolvecs_non_CG,
15341532
disable=not self.verbose,
15351533
desc="Discovering inequalities "):
15361534
critical_boolvec_intersection = np.bitwise_and(bool_vec,
1537-
self._boolvec_for_not_being_in_CG_notation)
1535+
self._boolvec_for_CG_ineqs)
15381536
if critical_boolvec_intersection.any():
15391537
absent_c_boolvec = bool_vec.copy()
15401538
absent_c_boolvec[critical_boolvec_intersection] = False
@@ -2102,4 +2100,4 @@ def mon_to_boolvec(self, mon: np.ndarray) -> np.ndarray:
21022100
"""
21032101
boolvec = self.blank_bool_vec.copy()
21042102
boolvec[self.mon_to_lexrepr(mon)] = True
2105-
return boolvec
2103+
return boolvec

0 commit comments

Comments
 (0)