Skip to content

Commit

Permalink
⬆️🪝 Update pre-commit hook astral-sh/ruff-pre-commit to v0.8.1 (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored Nov 29, 2024
1 parent 13a3482 commit a996b1d
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 25 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repos:

# Python linting and formatting using ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.1
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -72,7 +72,7 @@ repos:

# Format configuration files with prettier
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.3
rev: v3.4.1
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
Expand All @@ -98,7 +98,7 @@ repos:

# Check for spelling
- repo: https://github.com/crate-ci/typos
rev: v1.27.3
rev: v1.28.1
hooks:
- id: typos
exclude: legal.html
Expand Down Expand Up @@ -129,6 +129,6 @@ repos:

# Check the pyproject.toml file
- repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2024.11.11
rev: 2024.11.25
hooks:
- id: validate-pyproject
6 changes: 3 additions & 3 deletions frontend/src/mqt/bench/viewer/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def filter_database(self, benchmark_config: BenchmarkConfiguration) -> list[str]
]
db_filtered = pd.concat([db_filtered, db_tmp6])

return cast(list[str], db_filtered["filename"].to_list())
return cast("list[str]", db_filtered["filename"].to_list())

def generate_zip_ephemeral_chunks(
self,
Expand Down Expand Up @@ -567,7 +567,7 @@ def get_opt_level(filename: str) -> int:
pat = re.compile(r"opt\d")
m = pat.search(filename)
num = m.group()[-1:] if m else -1
return int(cast(str, num))
return int(cast("str", num))


def get_num_qubits(filename: str) -> int:
Expand All @@ -582,7 +582,7 @@ def get_num_qubits(filename: str) -> int:
pat = re.compile(r"(\d+)\.")
m = pat.search(filename)
num = m.group()[0:-1] if m else -1
return int(cast(str, num))
return int(cast("str", num))


def get_tket_settings(filename: str) -> str | None:
Expand Down
15 changes: 12 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ filterwarnings = [
'ignore:.*invalid value encountered in det.*:RuntimeWarning:',
'ignore::DeprecationWarning:.*(docplex).*',
'ignore::SyntaxWarning:.*(docplex).*',
# Qiskit 1.2 deprecations
'ignore:.*The abstract Provider and ProviderV1 classes are deprecated.*:DeprecationWarning:qiskit.*',
'ignore:.*qiskit.providers.models is deprecated since Qiskit 1.2*:DeprecationWarning:',
'ignore:.*Treating CircuitInstruction as an iterable is deprecated legacy behavior since Qiskit 1.2*:DeprecationWarning:pytket.*',
Expand All @@ -110,7 +111,17 @@ filterwarnings = [
'ignore:.*The class ``qiskit.qobj.pulse_qobj.Pulse.*`` is deprecated as of qiskit 1.2.*:DeprecationWarning:qiskit.*',
'ignore:.*The class ``qiskit.primitives.sampler.Sampler`` is deprecated as of qiskit 1.2*:DeprecationWarning:mqt.*',
'ignore:.*The class ``qiskit.primitives.estimator.Estimator`` is deprecated as of qiskit 1.2*:DeprecationWarning:mqt.*',
# TKET Warnings
'ignore:.*The pytket Circuit contains implicit qubit permutations*.:UserWarning:pytket.extensions.qiskit.qiskit_convert',
# Qiskit 1.3 deprecations
'ignore:.*The property ``qiskit.dagcircuit.dagcircuit.DAGCircuit.*`` is deprecated as of qiskit 1.3.0.*:DeprecationWarning:qiskit.*',
'ignore:.*The class ``qiskit.pulse.*`` is deprecated as of Qiskit 1.3.*:DeprecationWarning:qiskit.*',
'ignore:.*The class ``qiskit.qobj.*`` is deprecated as of Qiskit 1.3.*:DeprecationWarning:qiskit.*',
'ignore:.*The property ``qiskit.transpiler.target.*`` is deprecated as of Qiskit 1.3.*:DeprecationWarning:qiskit.*',
'ignore:.*The property ``qiskit.circuit.instruction.Instruction.condition`` is deprecated as of qiskit 1.3.0.*:DeprecationWarning:',
# Warnings that should be fixed by us in a subsequent PR. Most likely as part of https://github.com/cda-tum/mqt-bench/pull/429
'ignore:.*Providing non-standard gates.*is deprecated for both ``transpile`` and ``generate_preset_pass_manager`` as of Qiskit 1.3.0.*:DeprecationWarning:qiskit.*',
'ignore:.*is pending deprecation as of qiskit 1.3..*:PendingDeprecationWarning:',
]

[tool.coverage]
Expand Down Expand Up @@ -184,15 +195,13 @@ extend-select = [
"SLF", # flake8-self
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"TC", # flake8-type-checking
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"YTT", # flake8-2020
]
ignore = [
"ANN101", # Missing type annotation for self in method
"ANN102", # Missing type annotation for cls in classmethod
"ISC001", # Conflicts with formatter
"E501", # Line too long (Black is enough)
"PLR", # Design related pylint codes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import SLSQP
from qiskit_optimization import QuadraticProgram
from qiskit_optimization.problems import LinearExpression, QuadraticExpression

if TYPE_CHECKING: # pragma: no cover
from numpy.typing import NDArray
from qiskit import QuantumCircuit
from qiskit_optimization.problems import LinearExpression, QuadraticExpression


class Initializer:
Expand Down Expand Up @@ -106,15 +106,15 @@ def binary_representation(
# Evaluates the cost distance from a binary representation of a path
def fun(x: NDArray[np.float64]) -> float:
return cast(
float,
"float",
np.dot(np.around(x), np.dot(q, np.around(x))) + np.dot(g, np.around(x)) + c,
)

cost = fun(x_sol)
except Exception:
cost = 0

return q, g, cast(float, c), cost
return q, g, cast("float", c), cost

def construct_problem(self, q: QuadraticExpression, g: LinearExpression, c: float) -> QuadraticProgram:
"""Constructs the problem."""
Expand Down Expand Up @@ -155,8 +155,8 @@ def create_circuit(num_nodes: int = 3, num_vehs: int = 2) -> QuantumCircuit:

quantum_optimizer = QuantumOptimizer(instance, n, k)
q, g, c, _binary_cost = quantum_optimizer.binary_representation(x_sol=np.array(0.0, dtype=float))
q_casted = cast(QuadraticExpression, q)
g_casted = cast(LinearExpression, g)
q_casted = cast("QuadraticExpression", q)
g_casted = cast("LinearExpression", g)
qp = quantum_optimizer.construct_problem(q_casted, g_casted, c)
# Instantiate the quantum optimizer class with parameters:
qc = quantum_optimizer.solve_problem(qp)
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ def parse_benchmark_name_and_instance(algorithm: str) -> tuple[str, str | None]:
if algorithm.startswith(("shor_", "groundstate_")):
as_list = algorithm.split("_", 2)
assert len(as_list) == 2
return cast(tuple[str, str], tuple(as_list))
return cast("tuple[str, str]", tuple(as_list))

return algorithm, None
6 changes: 3 additions & 3 deletions src/mqt/bench/devices/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def import_backend(cls, path: Path) -> Device:
Returns: the Device object
"""
with path.open() as json_file:
ibm_calibration = cast(IBMCalibration, json.load(json_file))
ibm_calibration = cast("IBMCalibration", json.load(json_file))

device = Device()
device.name = ibm_calibration["name"]
Expand Down Expand Up @@ -116,8 +116,8 @@ def __import_target(cls, target: Target) -> DeviceCalibration:

for qubit in range(num_qubits):
qubit_props = target.qubit_properties[qubit]
calibration.t1[qubit] = cast(float, qubit_props.t1)
calibration.t2[qubit] = cast(float, qubit_props.t2)
calibration.t1[qubit] = cast("float", qubit_props.t1)
calibration.t2[qubit] = cast("float", qubit_props.t2)

calibration.single_qubit_gate_fidelity = {qubit: {} for qubit in range(num_qubits)}
calibration.single_qubit_gate_duration = {qubit: {} for qubit in range(num_qubits)}
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/devices/ionq.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def import_backend(cls, path: Path) -> Device:
the Device object
"""
with path.open() as json_file:
ionq_calibration = cast(IonQCalibration, json.load(json_file))
ionq_calibration = cast("IonQCalibration", json.load(json_file))

device = Device()
device.name = ionq_calibration["name"]
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/devices/iqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def import_backend(cls, path: Path) -> Device:
Returns: the Device object
"""
with path.open() as json_file:
iqm_calibration = cast(IQMCalibration, json.load(json_file))
iqm_calibration = cast("IQMCalibration", json.load(json_file))

device = Device()
device.name = iqm_calibration["name"]
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/devices/oqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def import_backend(cls, path: Path) -> Device:
the Device object
"""
with path.open() as json_file:
oqc_calibration = cast(OQCCalibration, json.load(json_file))
oqc_calibration = cast("OQCCalibration", json.load(json_file))

device = Device()
device.name = oqc_calibration["name"]
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/devices/quantinuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def import_backend(cls, path: Path) -> Device:
the Device object
"""
with path.open() as json_file:
quantinuum_calibration = cast(QuantinuumCalibration, json.load(json_file))
quantinuum_calibration = cast("QuantinuumCalibration", json.load(json_file))

device = Device()
device.name = quantinuum_calibration["name"]
Expand Down
2 changes: 1 addition & 1 deletion src/mqt/bench/devices/rigetti.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def import_backend(cls, path: Path) -> Device:
the Device object
"""
with path.open() as json_file:
rigetti_calibration = cast(RigettiCalibration, json.load(json_file))
rigetti_calibration = cast("RigettiCalibration", json.load(json_file))

device = Device()
device.name = rigetti_calibration["name"]
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@pytest.mark.parametrize(
"device", get_available_devices(sanitize_device=True), ids=lambda device: cast(str, device.name)
"device", get_available_devices(sanitize_device=True), ids=lambda device: cast("str", device.name)
)
def test_sanitized_devices(device: Device) -> None:
"""Test that all devices can be sanitized and provide complete fidelity data."""
Expand Down

0 comments on commit a996b1d

Please sign in to comment.