Skip to content

Commit

Permalink
🎨 pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed May 13, 2024
1 parent 8ccab96 commit e45e30f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
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

0 comments on commit e45e30f

Please sign in to comment.