Skip to content

Commit

Permalink
⬆️🪝 update pre-commit hooks (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] authored Jun 18, 2024
1 parent a26491e commit 95160ac
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:

# Clean jupyter notebooks
- repo: https://github.com/srstevenson/nb-clean
rev: 3.2.0
rev: 3.3.0
hooks:
- id: nb-clean
args:
Expand All @@ -58,7 +58,7 @@ repos:

# Python linting using ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
rev: v0.4.9
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down
72 changes: 36 additions & 36 deletions src/mqt/qao/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ def _not_constraint_check(self, constraint: str, variables: Variables, solution:
expr1_to_sub = bool(not str(expr1).replace(".", "").isnumeric())
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub:
for var in solution:
for var, values in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(values, float):
expr1, expr2 = self._constraint_check_sub_single_var(
expr1_to_sub, expr2_to_sub, expr1, expr2, solution[var], variables.variables_dict[var]
expr1_to_sub, expr2_to_sub, expr1, expr2, values, variables.variables_dict[var]
)
elif isinstance(solution[var], list):
elif isinstance(values, list):
expr1, expr2 = self._constraint_check_sub_list_var(
solution,
variables,
Expand Down Expand Up @@ -380,20 +380,20 @@ def _and_constraint_check(self, constraint: str, variables: Variables, solution:
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
expr3_to_sub = bool(not str(expr3).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub or expr3_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2, expr3 = self._constraint_check_three_sub_single_var(
expr1_to_sub,
expr2_to_sub,
expr3_to_sub,
expr1,
expr2,
expr3,
solution[var],
value,
variables.variables_dict[var],
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2, expr3 = self._constraint_check_three_sub_list_var(
solution, variables, expr1, expr2, expr3, var, expr1_to_sub, expr2_to_sub, expr3_to_sub
)
Expand Down Expand Up @@ -535,20 +535,20 @@ def _or_constraint_check(self, constraint: str, variables: Variables, solution:
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
expr3_to_sub = bool(not str(expr3).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub or expr3_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2, expr3 = self._constraint_check_three_sub_single_var(
expr1_to_sub,
expr2_to_sub,
expr3_to_sub,
expr1,
expr2,
expr3,
solution[var],
value,
variables.variables_dict[var],
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2, expr3 = self._constraint_check_three_sub_list_var(
solution, variables, expr1, expr2, expr3, var, expr1_to_sub, expr2_to_sub, expr3_to_sub
)
Expand Down Expand Up @@ -765,20 +765,20 @@ def _xor_constraint_check(self, constraint: str, variables: Variables, solution:
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
expr3_to_sub = bool(not str(expr3).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub or expr3_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2, expr3 = self._constraint_check_three_sub_single_var(
expr1_to_sub,
expr2_to_sub,
expr3_to_sub,
expr1,
expr2,
expr3,
solution[var],
value,
variables.variables_dict[var],
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2, expr3 = self._constraint_check_three_sub_list_var(
solution, variables, expr1, expr2, expr3, var, expr1_to_sub, expr2_to_sub, expr3_to_sub
)
Expand Down Expand Up @@ -1008,13 +1008,13 @@ def _greq_constraint_check(self, constraint: str, variables: Variables, solution
expr1_to_sub = bool(not str(expr1).replace(".", "").isnumeric())
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2 = self._constraint_check_sub_single_var(
expr1_to_sub, expr2_to_sub, expr1, expr2, solution[var], variables.variables_dict[var]
expr1_to_sub, expr2_to_sub, expr1, expr2, value, variables.variables_dict[var]
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2 = self._constraint_check_sub_list_var(
solution, variables, expr1, expr2, var, expr1_to_sub, expr2_to_sub
)
Expand Down Expand Up @@ -1175,13 +1175,13 @@ def _lteq_constraint_check(self, constraint: str, variables: Variables, solution
expr1_to_sub = bool(not str(expr1).replace(".", "").isnumeric())
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2 = self._constraint_check_sub_single_var(
expr1_to_sub, expr2_to_sub, expr1, expr2, solution[var], variables.variables_dict[var]
expr1_to_sub, expr2_to_sub, expr1, expr2, value, variables.variables_dict[var]
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2 = self._constraint_check_sub_list_var(
solution, variables, expr1, expr2, var, expr1_to_sub, expr2_to_sub
)
Expand Down Expand Up @@ -1352,13 +1352,13 @@ def _grt_constraint_check(self, constraint: str, variables: Variables, solution:
expr1_to_sub = bool(not str(expr1).replace(".", "").isnumeric())
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2 = self._constraint_check_sub_single_var(
expr1_to_sub, expr2_to_sub, expr1, expr2, solution[var], variables.variables_dict[var]
expr1_to_sub, expr2_to_sub, expr1, expr2, value, variables.variables_dict[var]
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2 = self._constraint_check_sub_list_var(
solution, variables, expr1, expr2, var, expr1_to_sub, expr2_to_sub
)
Expand Down Expand Up @@ -1532,13 +1532,13 @@ def _lt_constraint_check(self, constraint: str, variables: Variables, solution:
expr1_to_sub = bool(not str(expr1).replace(".", "").isnumeric())
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2 = self._constraint_check_sub_single_var(
expr1_to_sub, expr2_to_sub, expr1, expr2, solution[var], variables.variables_dict[var]
expr1_to_sub, expr2_to_sub, expr1, expr2, value, variables.variables_dict[var]
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2 = self._constraint_check_sub_list_var(
solution, variables, expr1, expr2, var, expr1_to_sub, expr2_to_sub
)
Expand Down Expand Up @@ -1635,13 +1635,13 @@ def _eq_constraint_check(self, constraint: str, variables: Variables, solution:
expr1_to_sub = bool(not str(expr1).replace(".", "").isnumeric())
expr2_to_sub = bool(not str(expr2).replace(".", "").isnumeric())
if expr2_to_sub or expr1_to_sub:
for var in solution:
for var, value in solution.items():
if var in variables.variables_dict:
if isinstance(solution[var], float):
if isinstance(value, float):
expr1, expr2 = self._constraint_check_sub_single_var(
expr1_to_sub, expr2_to_sub, expr1, expr2, solution[var], variables.variables_dict[var]
expr1_to_sub, expr2_to_sub, expr1, expr2, value, variables.variables_dict[var]
)
elif isinstance(solution[var], list):
elif isinstance(value, list):
expr1, expr2 = self._constraint_check_sub_list_var(
solution, variables, expr1, expr2, var, expr1_to_sub, expr2_to_sub
)
Expand Down
10 changes: 5 additions & 5 deletions src/mqt/qao/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ def _moc(cost_function: PUBO, constraint_function: PUBO) -> float:

val = 0.0
first = True
for key in p_sum:
for key, value in p_sum.items():
if key in p_sum_constrained and p_sum_constrained[key] != 0:
v = p_sum[key] / p_sum_constrained[key]
v = value / p_sum_constrained[key]
if v != 0 and first:
val = v
first = False
Expand Down Expand Up @@ -394,9 +394,9 @@ def upper_lower_bound_posiform_and_negaform_method(cost_function: PUBO) -> float
n_sum[elem] += cost_function[key] / len(key)
lowerbound = 0.0
upperbound = 0.0
for key in p_sum:
if p_sum[key] < 0:
lowerbound += p_sum[key]
for key, value in p_sum.items():
if value < 0:
lowerbound += value
if n_sum[key] > 0:
upperbound += n_sum[key]
return upperbound - lowerbound
Expand Down
6 changes: 3 additions & 3 deletions src/mqt/qao/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,9 @@ def wring_json_reports(
elems_v = {}
coeff_m = sum(coeff) / len(coeff)
coeff_v = np.var(coeff)
for key in elems:
elems_m[key] = sum(elems[key]) / len(elems[key])
elems_v[key] = np.var(elems[key])
for key, value in elems.items():
elems_m[key] = sum(value) / len(value)
elems_v[key] = np.var(value)
data["qubo contributions"] = num_elm
data["qubo contributions average"] = elems_m
data["qubo contributions variance"] = elems_v
Expand Down
28 changes: 14 additions & 14 deletions tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def test_cost_function() -> None:
for key in qubo:
qubo_re[tuple(sorted(key))] = qubo[key]
reference_qubo_dict_re = {}
for key in reference_qubo_dict:
reference_qubo_dict_re[tuple(sorted(key))] = reference_qubo_dict[key]
for key, value in reference_qubo_dict.items():
reference_qubo_dict_re[tuple(sorted(key))] = value
assert dict(sorted(qubo_re.items())) == dict(sorted(reference_qubo_dict_re.items()))


Expand Down Expand Up @@ -392,8 +392,8 @@ def test_cost_function_matrix() -> None:
for key in qubo:
qubo_re[tuple(sorted(key))] = qubo[key]
reference_qubo_dict_re = {}
for key in reference_qubo_dict:
reference_qubo_dict_re[tuple(sorted(key))] = reference_qubo_dict[key]
for key, value in reference_qubo_dict.items():
reference_qubo_dict_re[tuple(sorted(key))] = value
assert dict(sorted(qubo_re.items())) == dict(sorted(reference_qubo_dict_re.items()))


Expand Down Expand Up @@ -449,13 +449,13 @@ def test_constraint(expression: str, var_precision: bool) -> None:
for key in qubo_second:
qubo_second_re[tuple(sorted(key))] = qubo_second[key]
dictionary_constraints_qubo_re = {}
for key in dictionary_constraints_qubo:
dictionary_constraints_qubo_re[tuple(sorted(key))] = dictionary_constraints_qubo[key]
for key, value in dictionary_constraints_qubo.items():
dictionary_constraints_qubo_re[tuple(sorted(key))] = value
if expression == "~a = b":
dictionary_constraints_qubo_2 = {("b0",): -1.0, ("b1",): -1.0, ("b0", "b1"): 2.0, (): 1.0}
dictionary_constraints_qubo_2_re = {}
for key in dictionary_constraints_qubo_2:
dictionary_constraints_qubo_2_re[tuple(sorted(key))] = dictionary_constraints_qubo_2[key]
for key, value in dictionary_constraints_qubo_2.items():
dictionary_constraints_qubo_2_re[tuple(sorted(key))] = value
assert dict(sorted(qubo_second_re.items())) == dict(sorted(dictionary_constraints_qubo_2_re.items()))
assert dict(sorted(qubo_first_re.items())) == dict(sorted(dictionary_constraints_qubo_re.items()))
elif expression == "a & b = c":
Expand Down Expand Up @@ -855,13 +855,13 @@ def test_constraint_no_sub(expression: str) -> None:
for key in qubo_second:
qubo_second_re[tuple(sorted(key))] = qubo_second[key]
dictionary_constraints_qubo_re = {}
for key in dictionary_constraints_qubo:
dictionary_constraints_qubo_re[tuple(sorted(key))] = dictionary_constraints_qubo[key]
for key, value in dictionary_constraints_qubo.items():
dictionary_constraints_qubo_re[tuple(sorted(key))] = value
if expression == "~b0 = b1":
dictionary_constraints_qubo_2 = {("b0",): -1, ("b1",): -1, ("b0", "b1"): 2, (): 1}
dictionary_constraints_qubo_2_re = {}
for key in dictionary_constraints_qubo_2:
dictionary_constraints_qubo_2_re[tuple(sorted(key))] = dictionary_constraints_qubo_2[key]
for key, value in dictionary_constraints_qubo_2.items():
dictionary_constraints_qubo_2_re[tuple(sorted(key))] = value
assert dict(sorted(qubo_second_re.items())) == dict(sorted(dictionary_constraints_qubo_2_re.items()))
assert dict(sorted(qubo_first_re.items())) == dict(sorted(dictionary_constraints_qubo_re.items()))

Expand Down Expand Up @@ -945,8 +945,8 @@ def test_problem(lambda_strategy: str) -> None:
for key in qubo:
qubo_re[tuple(sorted(key))] = qubo[key]
reference_qubo_dict_re = {}
for key in reference_qubo_dict:
reference_qubo_dict_re[tuple(sorted(key))] = reference_qubo_dict[key]
for key, value in reference_qubo_dict.items():
reference_qubo_dict_re[tuple(sorted(key))] = value
if lambda_strategy in {"upper_bound_only_positive", "upper lower bound naive"}:
assert lambdas == [52.25 * 1.1] * 2
assert dict(sorted(qubo_re.items())) == dict(sorted(reference_qubo_dict_re.items()))
Expand Down

0 comments on commit 95160ac

Please sign in to comment.