Skip to content

Commit a0a61e2

Browse files
⬆️🪝 update pre-commit hooks (#448)
<!--pre-commit.ci start--> updates: - [github.com/sirosen/texthooks: 0.6.6 → 0.6.7](sirosen/texthooks@0.6.6...0.6.7) - [github.com/astral-sh/ruff-pre-commit: v0.5.7 → v0.6.1](astral-sh/ruff-pre-commit@v0.5.7...v0.6.1) <!--pre-commit.ci end--> --------- Signed-off-by: burgholzer <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: burgholzer <[email protected]>
1 parent 3d75d0a commit a0a61e2

17 files changed

+9892
-9458
lines changed

.pre-commit-config.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repos:
4141

4242
# Handling unwanted unicode characters
4343
- repo: https://github.com/sirosen/texthooks
44-
rev: 0.6.6
44+
rev: 0.6.7
4545
hooks:
4646
- id: fix-ligatures
4747
- id: fix-smartquotes
@@ -56,7 +56,7 @@ repos:
5656

5757
# Python linting and formatting using ruff
5858
- repo: https://github.com/astral-sh/ruff-pre-commit
59-
rev: v0.5.7
59+
rev: v0.6.3
6060
hooks:
6161
- id: ruff
6262
args: ["--fix", "--show-fixes"]
@@ -96,7 +96,7 @@ repos:
9696

9797
# Check static types with mypy
9898
- repo: https://github.com/pre-commit/mirrors-mypy
99-
rev: v1.11.1
99+
rev: v1.11.2
100100
hooks:
101101
- id: mypy
102102
files: ^(src/mqt|test/python)
@@ -108,7 +108,7 @@ repos:
108108

109109
# Check for spelling
110110
- repo: https://github.com/crate-ci/typos
111-
rev: v1.23.6
111+
rev: v1.24.1
112112
hooks:
113113
- id: typos
114114

@@ -123,21 +123,21 @@ repos:
123123

124124
# Check best practices for scientific Python code
125125
- repo: https://github.com/scientific-python/cookie
126-
rev: 2024.04.23
126+
rev: 2024.08.19
127127
hooks:
128128
- id: sp-repo-review
129129
additional_dependencies: ["repo-review[cli]"]
130130

131131
# Check JSON schemata
132132
- repo: https://github.com/python-jsonschema/check-jsonschema
133-
rev: 0.29.1
133+
rev: 0.29.2
134134
hooks:
135135
- id: check-dependabot
136136
- id: check-github-workflows
137137
- id: check-readthedocs
138138

139139
# Check the pyproject.toml file
140140
- repo: https://github.com/henryiii/validate-pyproject-schema-store
141-
rev: 2024.08.08
141+
rev: 2024.08.26
142142
hooks:
143143
- id: validate-pyproject

cmake/ExternalDependencies.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endif()
2222
# cmake-format: off
2323
set(MQT_CORE_VERSION 2.6.1
2424
CACHE STRING "MQT Core version")
25-
set(MQT_CORE_REV "89f18fb322ff2ce86e33558e3a2b42a08e655174"
25+
set(MQT_CORE_REV "41eea72cdbefbd86ba06f76dc41a911950dd3081"
2626
CACHE STRING "MQT Core identifier (tag, branch or commit hash)")
2727
set(MQT_CORE_REPO_OWNER "cda-tum"
2828
CACHE STRING "MQT Core repository owner (change when using a fork)")

pyproject.toml

-8
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ ignore = ["W002"] # Triggers on __init__.py's
169169

170170
[tool.ruff]
171171
line-length = 120
172-
src = ["src"]
173172
namespace-packages = ["mqt"]
174173
preview = true
175174
unsafe-fixes = true
@@ -269,13 +268,6 @@ anc = "anc"
269268
aer = "aer"
270269

271270

272-
[tool.repo-review]
273-
ignore = [
274-
"PC160", # "Uses codespell" -> switched to https://github.com/crate-ci/typos
275-
"PC180", # "Uses prettier" -> switched to different prettier-mirror that is not recognized by the check
276-
]
277-
278-
279271
[tool.cibuildwheel]
280272
build = "cp3*"
281273
skip = "*-musllinux_*"

src/mqt/qcec/compilation_flow_profiles.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
from enum import Enum, unique
66
from pathlib import Path
7-
from typing import Any
7+
from typing import TYPE_CHECKING, Any
88

99
import numpy as np
1010
from qiskit import QuantumCircuit, transpile
1111
from qiskit import __version__ as qiskit_version
1212

13+
if TYPE_CHECKING:
14+
from numpy.typing import NDArray
15+
1316

1417
@unique
1518
class AncillaMode(Enum):
@@ -307,22 +310,20 @@ def check_recurrence(seq: list[int], order: int = 2) -> list[int] | None:
307310
if len(seq) < (2 * order + 1):
308311
return None
309312

310-
mat, f = [], []
311-
for i in range(order):
312-
mat.append(seq[i : i + order])
313-
f.append(seq[i + order])
313+
mat = np.array([seq[i : i + order] for i in range(order)], dtype=int)
314+
f = np.array([seq[i + order] for i in range(order)], dtype=int)
314315

315316
if np.linalg.det(mat) == 0:
316317
return None
317318

318-
coeffs = np.linalg.inv(mat).dot(f)
319+
coefficients: NDArray[np.float64] = np.linalg.inv(mat).dot(f)
319320

320321
for i in range(2 * order, len(seq)):
321-
predict = np.sum(coeffs * np.array(seq[i - order : i]))
322+
predict: float = np.sum(coefficients * np.array(seq[i - order : i], dtype=float))
322323
if abs(predict - seq[i]) > 10 ** (-2):
323324
return None
324325

325-
return list(coeffs)
326+
return list(coefficients)
326327

327328

328329
def find_continuation(

src/mqt/qcec/parameterized.py

+27-26
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def extract_params(
5252
p = p1.union(p2)
5353

5454
n_params = len(p)
55-
exprs = list(chain(*[instr[0].params for instr in circ1.data + circ2.data if instr[0].params != []]))
55+
exprs = list(chain(*[instr.operation.params for instr in circ1.data + circ2.data if instr.operation.params != []]))
5656

5757
def is_expr(x: float | Parameter | ParameterExpression) -> bool:
5858
return isinstance(x, (Parameter, ParameterExpression))
@@ -115,14 +115,14 @@ def check_parameterized(
115115
total_simulations_started = 0
116116
total_simulations_finished = 0
117117

118-
def update_stats(res: EquivalenceCheckingManager.Results) -> None:
118+
def _update_stats(res: EquivalenceCheckingManager.Results) -> None:
119119
nonlocal total_preprocessing_time, total_runtime, total_simulations_started, total_simulations_finished
120120
total_preprocessing_time += res.preprocessing_time
121121
total_runtime += res.check_time
122122
total_simulations_started += res.started_simulations
123123
total_simulations_finished += res.performed_simulations
124124

125-
def write_stats(i: int, res: EquivalenceCheckingManager.Results) -> None:
125+
def _write_stats(i: int, res: EquivalenceCheckingManager.Results) -> None:
126126
nonlocal total_preprocessing_time, total_runtime, total_simulations_started, total_simulations_finished
127127
res.check_time = total_runtime
128128
res.preprocessing_time = total_preprocessing_time
@@ -135,15 +135,15 @@ def write_stats(i: int, res: EquivalenceCheckingManager.Results) -> None:
135135
if res.considered_equivalent():
136136
return res
137137

138-
update_stats(res)
138+
_update_stats(res)
139139

140140
timeout = __adjust_timeout(configuration.execution.timeout, res)
141141
n_checks = configuration.parameterized.additional_instantiations
142142
tol = configuration.parameterized.parameterized_tolerance
143143

144144
parameters, mat, offsets = extract_params(circ1, circ2)
145145

146-
def instantiate_params(
146+
def _instantiate_params(
147147
qc1: QuantumCircuit, qc2: QuantumCircuit, b: NDArray[np.float64]
148148
) -> tuple[QuantumCircuit, QuantumCircuit, float]:
149149
start_time = time.time()
@@ -153,67 +153,68 @@ def instantiate_params(
153153
qc1_bound = qc1.assign_parameters(param_map)
154154
qc2_bound = qc2.assign_parameters(param_map)
155155

156-
def round_zero_params(qc: QuantumCircuit) -> QuantumCircuit:
156+
def _round_zero_params(qc: QuantumCircuit) -> QuantumCircuit:
157157
for instr in qc.data:
158-
if not hasattr(instr[0], "mutable") or instr[0].mutable:
159-
params = instr[0].params
160-
instr[0].params = [float(x) for x in params]
161-
instr[0].params = [0 if np.abs(x) < tol else x for x in instr[0].params]
158+
operation = instr.operation
159+
if not hasattr(operation, "mutable") or operation.mutable:
160+
params = operation.params
161+
operation.params = [float(x) for x in params]
162+
operation.params = [0 if np.abs(x) < tol else x for x in operation.params]
162163
return qc
163164

164-
qc1_bound = round_zero_params(qc1_bound)
165-
qc2_bound = round_zero_params(qc2_bound)
165+
qc1_bound = _round_zero_params(qc1_bound)
166+
qc2_bound = _round_zero_params(qc2_bound)
166167
return qc1_bound, qc2_bound, time.time() - start_time
167168

168-
def instantiate_params_zero(
169+
def _instantiate_params_zero(
169170
qc1: QuantumCircuit, qc2: QuantumCircuit
170171
) -> tuple[QuantumCircuit, QuantumCircuit, float]:
171-
return instantiate_params(qc1, qc2, offsets)
172+
return _instantiate_params(qc1, qc2, offsets)
172173

173-
def instantiate_params_phases(
174+
def _instantiate_params_phases(
174175
qc1: QuantumCircuit, qc2: QuantumCircuit
175176
) -> tuple[QuantumCircuit, QuantumCircuit, float]:
176177
phases = [0, np.pi, np.pi / 2, -np.pi / 2, np.pi / 4, -np.pi / 4]
177178
rng = np.random.default_rng()
178179
b = rng.choice(phases, size=len(offsets)) + offsets
179-
return instantiate_params(qc1, qc2, b)
180+
return _instantiate_params(qc1, qc2, b)
180181

181-
circ1_inst, circ2_inst, runtime = instantiate_params_zero(circ1, circ2)
182+
circ1_inst, circ2_inst, runtime = _instantiate_params_zero(circ1, circ2)
182183
timeout = __adjust_timeout(timeout, runtime)
183184

184185
if timeout < 0:
185-
write_stats(1, res)
186+
_write_stats(1, res)
186187
res.equivalence = EquivalenceCriterion.no_information
187188
return res
188189

189190
res = check_instantiated(circ1_inst, circ2_inst, configuration)
190-
update_stats(res)
191+
_update_stats(res)
191192
if res.equivalence == EquivalenceCriterion.not_equivalent:
192-
write_stats(1, res)
193+
_write_stats(1, res)
193194
return res
194195

195196
for i in range(n_checks):
196-
circ1_inst, circ2_inst, runtime = instantiate_params_phases(circ1, circ2)
197+
circ1_inst, circ2_inst, runtime = _instantiate_params_phases(circ1, circ2)
197198
timeout = __adjust_timeout(timeout, runtime)
198199
res = check_instantiated(circ1_inst, circ2_inst, configuration)
199200
timeout = __adjust_timeout(timeout, res)
200201

201202
if timeout < 0:
202-
write_stats(i + 2, res)
203+
_write_stats(i + 2, res)
203204
res.equivalence = EquivalenceCriterion.no_information
204205
return res
205206

206-
update_stats(res)
207+
_update_stats(res)
207208

208209
if res.equivalence == EquivalenceCriterion.not_equivalent:
209-
write_stats(i + 2, res)
210+
_write_stats(i + 2, res)
210211
return res
211212

212213
res = check_instantiated_random(circ1, circ2, parameters, configuration)
213214
timeout = __adjust_timeout(timeout, runtime)
214215
if timeout < 0:
215216
res.equivalence = EquivalenceCriterion.no_information
216217

217-
update_stats(res)
218-
write_stats(n_checks + 2, res)
218+
_update_stats(res)
219+
_write_stats(n_checks + 2, res)
219220
return res

0 commit comments

Comments
 (0)