Skip to content

Commit dd157a7

Browse files
committed
1 parent 02c925f commit dd157a7

File tree

7 files changed

+61
-61
lines changed

7 files changed

+61
-61
lines changed

inflation/InflationProblem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def __init__(self,
188188
self._classical_sources[ii] = 1
189189
self._nonclassical_sources = np.logical_not(self._classical_sources).astype(np.uint8)
190190

191-
self._partial_inverse_dag = dict()
191+
self._partial_inverse_dag = {}
192192
for il in self.intermediate_latents:
193193
this_ils_parents = set(v for (v, kids) in self.dag.items() if il in kids)
194194
self._partial_inverse_dag[il] = this_ils_parents
@@ -625,7 +625,7 @@ def names_to_ints(self) -> dict:
625625
# FUNCTIONS PERTAINING TO KNOWABILITY #
626626
###########################################################################
627627
def _interpret_operator(self, op: np.ndarray) -> dict:
628-
interpretation = dict()
628+
interpretation = {}
629629
party_int = op[0] -1
630630
interpretation["Party as Integer"] = party_int
631631
interpretation["Party"] = self.names[party_int]

inflation/lp/InflationLP.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self,
9999
self.names_to_ints = inflationproblem.names_to_ints
100100
self._lexrepr_to_names = inflationproblem._lexrepr_to_names
101101
self._lexrepr_to_copy_index_free_names = inflationproblem._lexrepr_to_copy_index_free_names
102-
self.op_from_name = dict()
102+
self.op_from_name = {}
103103
for i, op_names in enumerate(inflationproblem._lexrepr_to_all_names.tolist()):
104104
for op_name in op_names:
105105
self.op_from_name.setdefault(op_name, i)
@@ -187,10 +187,10 @@ def __init__(self,
187187
# init so as to be able to test the Monomial constructor function
188188
# without generate_lp.
189189

190-
self._atomic_monomial_from_hash = dict()
191-
self.monomial_from_atoms = dict()
192-
self.monomial_from_name = dict()
193-
self.monomial_from_symbol = dict()
190+
self._atomic_monomial_from_hash = {}
191+
self.monomial_from_atoms = {}
192+
self.monomial_from_name = {}
193+
self.monomial_from_symbol = {}
194194
self.One = self.Monomial(self.identity_operator, idx=1)
195195
self._generate_lp()
196196

@@ -250,7 +250,7 @@ def atomic_monomials(self):
250250
@cached_property
251251
def atom_from_name(self):
252252
"""Returns the atomic monomials."""
253-
lookup_dict = dict()
253+
lookup_dict = {}
254254
for atom in self.atomic_factors:
255255
lookup_dict[atom.name] = atom
256256
lookup_dict[atom.legacy_name] = atom
@@ -270,7 +270,7 @@ def do_conditional_atoms(self):
270270
@cached_property
271271
def factorization_conditions(self):
272272
"""Returns the factorization conditions."""
273-
conds = dict()
273+
conds = {}
274274
for mon in self.monomials:
275275
if mon.n_factors > 1:
276276
conds[mon] = tuple(self.monomial_from_atoms[(fac,)]
@@ -280,7 +280,7 @@ def factorization_conditions(self):
280280
@cached_property
281281
def quadratic_factorization_conditions(self):
282282
"""Returns the quadratic factorization conditions."""
283-
conds = dict()
283+
conds = {}
284284
for mon in self.monomials:
285285
if mon.n_factors > 1:
286286
conds[mon] = (self.monomial_from_atoms[mon.factors[:1]],
@@ -322,7 +322,7 @@ def set_distribution(self,
322322
knowable_values = {atom: atom.compute_marginal(prob_array)
323323
for atom in self.knowable_atoms}
324324
else:
325-
knowable_values = dict()
325+
knowable_values = {}
326326

327327
self.set_values(knowable_values,
328328
use_lpi_constraints=use_lpi_constraints,
@@ -671,7 +671,7 @@ def certificate_as_dict(self,
671671
"polynomial constraints, the certificate is not guaranteed " +
672672
"to apply to other distributions.")
673673
if np.allclose(list(dual.values()), 0.):
674-
return dict()
674+
return {}
675675
if clean:
676676
dual = clean_coefficients(dual, chop_tol, round_decimals)
677677
return {self.monomial_from_name[k]: v for k, v in dual.items()
@@ -1126,7 +1126,7 @@ def _sanitise_dict(self, input_dict: Any) -> Dict:
11261126
if input_dict.free_symbols:
11271127
input_dict_copy = {k: float(v) for k, v in sp.expand(input_dict).as_coefficients_dict().items()}
11281128
else:
1129-
input_dict_copy = dict()
1129+
input_dict_copy = {}
11301130
else:
11311131
input_dict_copy = input_dict
11321132
output_dict = defaultdict(int)
@@ -1244,8 +1244,8 @@ def _generate_lp(self) -> None:
12441244
if self.generate_lp_has_been_called:
12451245
return None
12461246

1247-
self._atomic_monomial_from_hash = dict()
1248-
self.monomial_from_atoms = dict()
1247+
self._atomic_monomial_from_hash = {}
1248+
self.monomial_from_atoms = {}
12491249
self.Constant_Term = self.One.__copy__()
12501250
self.Constant_Term.name = self.constant_term_name
12511251
self.monomial_from_name[self.constant_term_name] = self.Constant_Term
@@ -1302,9 +1302,9 @@ def _generate_lp(self) -> None:
13021302
# Associate Monomials to the remaining entries.
13031303
_monomials = []
13041304
_monomial_names = []
1305-
_compmonomial_from_idx = dict()
1306-
_compmonomial_to_idx = dict()
1307-
boolvec2mon = dict()
1305+
_compmonomial_from_idx = {}
1306+
_compmonomial_to_idx = {}
1307+
boolvec2mon = {}
13081308
for idx, mon_as_lexboolvec in tqdm(enumerate(self._monomials_as_lexboolvecs),
13091309
disable=not self.verbose,
13101310
desc="Initializing monomials ",
@@ -1673,7 +1673,7 @@ def _cleanup_after_set_values(self) -> None:
16731673
for mon in nonzero_known_monomials:
16741674
self.moment_lowerbounds[mon] = 1.
16751675
del self.known_moments[mon]
1676-
self.semiknown_moments = dict()
1676+
self.semiknown_moments = {}
16771677
num_nontrivial_known = len(self.known_moments)
16781678
if self.verbose > 1 and num_nontrivial_known > 1:
16791679
eprint("Number of variables with fixed numeric value:",
@@ -1694,12 +1694,12 @@ def _reset_bounds(self) -> None:
16941694
def _reset_lowerbounds(self) -> None:
16951695
"""Reset the list of lower bounds."""
16961696
self._reset_solution()
1697-
self.moment_lowerbounds = dict()
1697+
self.moment_lowerbounds = {}
16981698

16991699
def _reset_upperbounds(self) -> None:
17001700
"""Reset the list of upper bounds."""
17011701
self._reset_solution()
1702-
self.moment_upperbounds = dict()
1702+
self.moment_upperbounds = {}
17031703

17041704
def _reset_objective(self) -> None:
17051705
"""Reset the objective function."""
@@ -1710,8 +1710,8 @@ def _reset_objective(self) -> None:
17101710
def _reset_values(self) -> None:
17111711
"""Reset the known values."""
17121712
self._reset_solution()
1713-
self.known_moments = dict()
1714-
self.semiknown_moments = dict()
1713+
self.known_moments = {}
1714+
self.semiknown_moments = {}
17151715
self.known_moments[self.One] = 1.
17161716
self.extra_equalities = []
17171717
self.extra_inequalities = []
@@ -1996,7 +1996,7 @@ def _set_upperbounds(self, upperbounds: Union[dict, None]) -> None:
19961996
self._reset_upperbounds()
19971997
if upperbounds is None:
19981998
return
1999-
sanitized_upperbounds = dict()
1999+
sanitized_upperbounds = {}
20002000
for mon, upperbound in upperbounds.items():
20012001
mon = self._sanitise_monomial(mon)
20022002
if mon not in sanitized_upperbounds.keys():
@@ -2022,7 +2022,7 @@ def _set_lowerbounds(self, lowerbounds: Union[dict, None]) -> None:
20222022
self._reset_lowerbounds()
20232023
if lowerbounds is None:
20242024
return
2025-
sanitized_lowerbounds = dict()
2025+
sanitized_lowerbounds = {}
20262026
for mon, lowerbound in lowerbounds.items():
20272027
mon = self._sanitise_monomial(mon)
20282028
if mon not in sanitized_lowerbounds.keys():

inflation/sdp/InflationSDP.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ def __init__(self,
204204
self.all_commuting_q_2d = \
205205
lambda mon: self.all_commuting_q_1d(self.mon_to_lexrepr(mon))
206206

207-
self.canon_lexmon_from_hash = dict()
208-
self.canonsym_lexmon_from_hash = dict()
207+
self.canon_lexmon_from_hash = {}
208+
self.canonsym_lexmon_from_hash = {}
209209
# These next properties are reset during generate_relaxation, but
210210
# are needed in init so as to be able to test the Monomial constructor
211211
# function without generate_relaxation.
212-
self.atomic_monomial_from_hash = dict()
213-
self.monomial_from_atoms = dict()
214-
self.monomial_from_name = dict()
215-
self.monomial_from_symbol = dict()
212+
self.atomic_monomial_from_hash = {}
213+
self.monomial_from_atoms = {}
214+
self.monomial_from_name = {}
215+
self.monomial_from_symbol = {}
216216
self.Zero = self.Moment_2d(self.zero_operator, idx=0)
217217
self.One = self.Moment_2d(self.identity_operator, idx=1)
218218
self._relaxation_has_been_generated = False
@@ -298,10 +298,10 @@ def generate_relaxation(self,
298298
Additional arguments that will be passed to
299299
``InflationSDP.build_columns``.
300300
"""
301-
self.atomic_monomial_from_hash = dict()
302-
self.monomial_from_atoms = dict()
303-
self.monomial_from_name = dict()
304-
self.monomial_from_symbol = dict()
301+
self.atomic_monomial_from_hash = {}
302+
self.monomial_from_atoms = {}
303+
self.monomial_from_name = {}
304+
self.monomial_from_symbol = {}
305305
self.Zero = self.Moment_2d(self.zero_operator, idx=0)
306306
self.One = self.Moment_2d(self.identity_operator, idx=1)
307307
self.Constant_Term = self.One.__copy__()
@@ -351,7 +351,7 @@ def generate_relaxation(self,
351351

352352
# Associate Monomials to the remaining entries. The zero monomial is
353353
# not stored during calculate_momentmatrix
354-
self.compmoment_from_idx = dict()
354+
self.compmoment_from_idx = {}
355355
if self.momentmatrix_has_a_zero:
356356
self.compmoment_from_idx[0] = self.Zero
357357
for (idx, lexmon) in tqdm(self.symmetrized_corresp.items(),
@@ -409,13 +409,13 @@ def generate_relaxation(self,
409409
self.minimal_equalities.append(eq_dict)
410410

411411
self.minimal_inequalities = []
412-
self.moment_upperbounds = dict()
412+
self.moment_upperbounds = {}
413413
self.moment_lowerbounds = {m: 0. for m in self.hermitian_moments}
414414

415415
self.set_objective(None)
416416
self.set_values(None)
417417

418-
self.maskmatrices = dict()
418+
self.maskmatrices = {}
419419
self._relaxation_has_been_generated = True
420420

421421
def set_extra_equalities(self,
@@ -492,7 +492,7 @@ def set_bounds(self,
492492
if bounds is None:
493493
return
494494
# Sanitize list of bounds
495-
sanitized_bounds = dict()
495+
sanitized_bounds = {}
496496
for mon, bound in bounds.items():
497497
mon = self._sanitise_moment(mon)
498498
if mon not in sanitized_bounds.keys():
@@ -525,7 +525,7 @@ def atomic_monomials(self):
525525
@cached_property
526526
def atom_from_name(self):
527527
"""Returns the atomic monomials."""
528-
lookup_dict = dict()
528+
lookup_dict = {}
529529
for atom in self.atomic_factors:
530530
lookup_dict[atom.name] = atom
531531
lookup_dict[atom.legacy_name] = atom
@@ -583,7 +583,7 @@ def set_distribution(self,
583583
knowable_values = {atom: atom.compute_marginal(prob_array)
584584
for atom in self.knowable_atoms}
585585
else:
586-
knowable_values = dict()
586+
knowable_values = {}
587587

588588
self.set_values(knowable_values,
589589
use_lpi_constraints=use_lpi_constraints,
@@ -882,7 +882,7 @@ def certificate_as_dict(self,
882882
"polynomial constraints, the certificate is not guaranteed " +
883883
"to apply to other distributions.")
884884
if np.allclose(list(dual.values()), 0.):
885-
return dict()
885+
return {}
886886
if clean:
887887
dual = clean_coefficients(dual, chop_tol, round_decimals)
888888
return {self.monomial_from_name[k]: v for k, v in dual.items()
@@ -1586,7 +1586,7 @@ def _sanitise_dict(self, input_dict: Any) -> Dict:
15861586
input_dict_copy = {k: float(v) for k, v in sp.expand(
15871587
input_dict).as_coefficients_dict().items()}
15881588
else:
1589-
input_dict_copy = dict()
1589+
input_dict_copy = {}
15901590
else:
15911591
input_dict_copy = input_dict
15921592
output_dict = defaultdict(int)
@@ -1835,7 +1835,7 @@ def _discover_normalization_eqns(self) -> List[Tuple[int, List[int]]]:
18351835

18361836
# This will allow for easy substitution of operators with the last
18371837
# outcome with the rest of the operators orthogonal to it
1838-
lexmon_to_orthogroup = dict()
1838+
lexmon_to_orthogroup = {}
18391839
for group in self.InflationProblem._ortho_groups:
18401840
last_outcome_op = \
18411841
self.mon_to_lexrepr(np.expand_dims(group[-1], axis=0))[0]
@@ -1970,7 +1970,7 @@ def _cleanup_after_set_values(self) -> None:
19701970
for mon in nonzero_known_monomials:
19711971
self.moment_lowerbounds[mon] = 1.
19721972
del self.known_moments[mon]
1973-
self.semiknown_moments = dict()
1973+
self.semiknown_moments = {}
19741974

19751975
self._update_bounds("lo")
19761976
self._update_bounds("up")
@@ -1999,7 +1999,7 @@ def _reset_lowerbounds(self) -> None:
19991999
def _reset_upperbounds(self) -> None:
20002000
"""Reset the list of upper bounds."""
20012001
self._reset_solution()
2002-
self.moment_upperbounds = dict()
2002+
self.moment_upperbounds = {}
20032003

20042004
def _reset_objective(self) -> None:
20052005
"""Reset the objective function."""
@@ -2011,8 +2011,8 @@ def _reset_objective(self) -> None:
20112011
def _reset_values(self) -> None:
20122012
"""Reset the known values."""
20132013
self._reset_solution()
2014-
self.known_moments = dict()
2015-
self.semiknown_moments = dict()
2014+
self.known_moments = {}
2015+
self.semiknown_moments = {}
20162016
if self.momentmatrix_has_a_zero:
20172017
self.known_moments[self.Zero] = 0.
20182018
self.known_moments[self.One] = 1.

inflation/sdp/quantum_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def calculate_momentmatrix_1d_internal(cols: List,
117117
string representation to integer representation.
118118
"""
119119
nrcols = len(cols)
120-
canonical_mon_to_idx = dict()
120+
canonical_mon_to_idx = {}
121121
momentmatrix = np.zeros((nrcols, nrcols), dtype=np.uint32)
122122
varidx = 1 # We start from 1 because 0 is reserved for 0
123123
for (i, mon1), (j, mon2) in tqdm(

inflation/sdp/writer_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def convert_to_human_readable(problem):
3333
constants = {moment.idx: str(value)
3434
for moment, value in problem.known_moments.items()}
3535
# Replacer for semiknowns
36-
semiknowns = dict()
36+
semiknowns = {}
3737
for key, val in problem.semiknown_moments.items():
3838
val_str = val[1].name.replace(", ", ";")
3939
semiknowns[key.idx] = f"{val[0]}*{val_str}"
4040
semiknown_replacer = np.vectorize(lambda x: semiknowns.get(x, str(x)))
4141
# Replacer for remaining symbols
42-
monomials = dict()
42+
monomials = {}
4343
for mon in problem.moments:
4444
monomials[mon.idx] = mon.name.replace(", ", ";")
4545

inflation/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def make_numerical(symbolic_expressions: Dict[Any, sympy.core.expr.Expr],
238238
Dict[Any, float]
239239
The dictionary with same keys and evaluated expressions as values.
240240
"""
241-
numeric_values = dict()
241+
numeric_values = {}
242242
for k, v in symbolic_expressions.items():
243243
try:
244244
numeric_values[k] = float(v.evalf(subs=symbols_to_values))

0 commit comments

Comments
 (0)