Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️🪝 update pre-commit hooks #226

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:

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

# Clang-format the C++ part of the code base automatically
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.4
rev: v18.1.5
hooks:
- id: clang-format
types_or: [c++, c, cuda]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
import locale
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -304,7 +305,7 @@ def save_results(self, x_success_cnt: int, z_success_cnt: int, runs: int) -> dic
}

output.update(self.input_values)
with Path(self.outfile).open(mode="w") as f:
with Path(self.outfile).open(mode="w", encoding=locale.getpreferredencoding(False)) as f:
json.dump(output, f, ensure_ascii=False, indent=4, default=lambda o: o.__dict__)
return output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
import locale
from pathlib import Path
from timeit import default_timer as timer
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -699,7 +700,7 @@ def save_results(
output.update(self.input_values)
output["bias"] = replace_inf(output["bias"]) # type: ignore[assignment, arg-type]

with Path(self.outfile).open() as f:
with Path(self.outfile).open(encoding=locale.getpreferredencoding(False)) as f:
f.write(
json.dumps(
output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
import locale
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -274,6 +275,6 @@ def save_results(

output.update(input_vals)
output["bias"] = replace_inf(output["bias"])
with Path(outfile).open(mode="w") as out:
with Path(outfile).open(mode="w", encoding=locale.getpreferredencoding(False)) as out:
json.dump(output, out, ensure_ascii=False, indent=4, default=lambda o: o.__dict__)
return output
5 changes: 4 additions & 1 deletion src/mqt/qecc/cc_decoder/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import datetime
import json
import locale
import subprocess # noqa: S404
from dataclasses import dataclass, field
from pathlib import Path
Expand Down Expand Up @@ -122,7 +123,9 @@ def solve(
wcnf = str(self.optimizer)
# Note: This merely calls the solver. It does not interpret the output.
# This is just to measure the time it takes to solve the problem.
with Path("./solver-out_" + solver_path.split("/")[-1] + ".txt").open("a+") as out:
with Path("./solver-out_" + solver_path.split("/")[-1] + ".txt").open(
"a+", encoding=locale.getpreferredencoding(False)
) as out:
start = datetime.datetime.now()
subprocess.run([solver_path, wcnf], stdout=out, check=False) # noqa: S603
solve_time = datetime.datetime.now() - start
Expand Down
3 changes: 2 additions & 1 deletion src/mqt/qecc/ecc_qiskit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import argparse
import locale
import pathlib
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -179,7 +180,7 @@ def main() -> None:

if ecc_export_filename is not None:
print("Exporting circuit to: " + str(ecc_export_filename)) # noqa: T201
with pathlib.Path(ecc_export_filename).open("w") as f:
with pathlib.Path(ecc_export_filename).open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
return

Expand Down
18 changes: 10 additions & 8 deletions test/python/ecc_fw/test_ecc_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
if TYPE_CHECKING:
from pytest_console_scripts import ScriptRunner

import locale

from qiskit import QuantumCircuit


Expand All @@ -34,7 +36,7 @@ def test_with_stab_simulator(
circ: QuantumCircuit, simulator: str, noise_models: str, script_runner: ScriptRunner
) -> None:
"""Testing the script with different parameters."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
ret = script_runner.run([
"ecc_qiskit_wrapper",
Expand All @@ -56,7 +58,7 @@ def test_with_stab_simulator(

def test_failing_simulators(circ: QuantumCircuit, script_runner: ScriptRunner) -> None:
"""Testing the script with unsupported ecc."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
ret = script_runner.run([
"ecc_qiskit_wrapper",
Expand All @@ -83,7 +85,7 @@ def test_failing_simulators(circ: QuantumCircuit, script_runner: ScriptRunner) -

def test_unavailable_backend(circ: QuantumCircuit, script_runner: ScriptRunner) -> None:
"""Testing the script with unsupported backend."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
ret = script_runner.run(["ecc_qiskit_wrapper", "-fs", "dummyBackedn", "-f", "dummyCircuit.qasm"])
file_to_remove = pathlib.Path("dummyCircuit.qasm")
Expand All @@ -94,7 +96,7 @@ def test_unavailable_backend(circ: QuantumCircuit, script_runner: ScriptRunner)

def test_unavailable_error_type(circ: QuantumCircuit, script_runner: ScriptRunner) -> None:
"""Testing the script with unsupported ecc."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
ret = script_runner.run(["ecc_qiskit_wrapper", "-m", "K", "-f", "dummyCircuit.qasm"])
file_to_remove = pathlib.Path("dummyCircuit.qasm")
Expand All @@ -105,7 +107,7 @@ def test_unavailable_error_type(circ: QuantumCircuit, script_runner: ScriptRunne

def test_statevector_simulators(circ: QuantumCircuit, script_runner: ScriptRunner) -> None:
"""Testing the simulator with a different simulator."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
ret = script_runner.run([
"ecc_qiskit_wrapper",
Expand All @@ -131,7 +133,7 @@ def test_statevector_simulators(circ: QuantumCircuit, script_runner: ScriptRunne

def test_save_circuit(circ: QuantumCircuit, script_runner: ScriptRunner) -> None:
"""Saving a circuit after applying an ECC."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
ret = script_runner.run([
"ecc_qiskit_wrapper",
Expand All @@ -148,7 +150,7 @@ def test_save_circuit(circ: QuantumCircuit, script_runner: ScriptRunner) -> None

def test_circuit_without_measurements(circ_no_measure: QuantumCircuit, script_runner: ScriptRunner) -> None:
"""Testing circuit without ecc."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ_no_measure, f)
ret = script_runner.run(["ecc_qiskit_wrapper", "-f", "dummyCircuit.qasm"])
file_to_remove = pathlib.Path("dummyCircuit.qasm")
Expand All @@ -158,7 +160,7 @@ def test_circuit_without_measurements(circ_no_measure: QuantumCircuit, script_ru

def test_trying_to_use_stabilizer_simulator(circ: QuantumCircuit, script_runner: ScriptRunner) -> None:
"""Testing circuit without ecc."""
with pathlib.Path("dummyCircuit.qasm").open("w") as f:
with pathlib.Path("dummyCircuit.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
ret = script_runner.run(["ecc_qiskit_wrapper", "-f", "dummyCircuit.qasm", "-m", "A"])
file_to_remove = pathlib.Path("dummyCircuit.qasm")
Expand Down
Loading