Skip to content

Commit

Permalink
🚨 relax linter exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
burgholzer committed Sep 9, 2024
1 parent ab1ef78 commit 30ee669
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 118 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ repos:
hooks:
- id: mypy
files: ^(src/mqt|test/python)
exclude: "code_construction* | ^data_utils\\.py$"
args: []
additional_dependencies:
- numpy
Expand Down
9 changes: 2 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,6 @@ preview = true
unsafe-fixes = true

[tool.ruff.lint]
exclude = [
"scripts/*",
"*/cc_decoder/plots.py",
"*/analog_information_decoding/code_construction/*",
"*/analog_information_decoding/utils/data_utils.py",

]
extend-select = [
"A", # flake8-builtins
"ANN", # flake8-annotations
Expand Down Expand Up @@ -272,6 +265,8 @@ isort.required-imports = ["from __future__ import annotations"]
"E402", # Allow imports to appear anywhere in Jupyter notebooks
"I002", # Allow missing `from __future__ import annotations` import
]
"*/cc_decoder/plots.py" = ["T201"]
"scripts/*" = ["T201"]

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand Down
6 changes: 4 additions & 2 deletions scripts/examples/atd_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""example simulation script"""
"""example simulation script."""

from __future__ import annotations

import numpy as np
import scipy
Expand All @@ -20,7 +22,7 @@
lers = []
ebs = []
for sigma in s:
print(sigma) # noqa: T201
print(sigma)
sim = AtdSimulator(
hx=Hx,
lx=Lx,
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/decoding-performance-simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
nr_failed_runs = 0
code_k = code.K

with Path(outpath).open("w") as outfile:
with Path(outpath).open("w", encoding="utf-8") as outfile:
while curr_p < max_per:
nr_failed_runs = 0
for _ in range(runs_per_p):
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/runtime-simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
nr_runs: int = 1
per: float = 0.01

with Path(outpath).open("w") as outfile:
with Path(outpath).open("w", encoding="utf-8") as outfile:
for code_path in codes:
sample_sum = 0.0
for _ in range(nr_samples):
Expand Down
26 changes: 13 additions & 13 deletions scripts/numerics/visualize/visualizeDecodingRuntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def runtime() -> None:
colors = mcolors.BASE_COLORS

for i in range(len(x_data)):
col, val = colors.popitem()
col, _val = colors.popitem()
if col in {"w", "k"}:
col, val = colors.popitem()
col, _val = colors.popitem()
if col in {"w", "k"}:
col, val = colors.popitem()
col, _val = colors.popitem()
cols.append(col)
label = "% 6.3f" % pers[i]
label = f"{pers[i]: 6.3f}"
orders.append(np.argsort(x_data[i]))
xfinal.append(np.array(x_data[i])[orders[i]])
yfinal.append(np.array(y_data[i])[orders[i]])
Expand All @@ -98,9 +98,9 @@ def runtime_comparison() -> None:
pers2 = 0.0
orders = []

with Path(input_filen).open() as data_file:
with Path(input_filen).open(encoding="utf-8") as data_file:
data = json.load(data_file)
with Path(input_filen2).open() as data_file2:
with Path(input_filen2).open(encoding="utf-8") as data_file2:
data2 = json.load(data_file2)

for per in data:
Expand All @@ -126,19 +126,19 @@ def runtime_comparison() -> None:
colors = mcolors.BASE_COLORS

for i in range(len(x_data)):
col, val = colors.popitem()
col, _val = colors.popitem()
if col in {"w", "k"}:
col, val = colors.popitem()
col, _val = colors.popitem()
if col in {"w", "k"}:
col, val = colors.popitem()
col, _val = colors.popitem()
cols.append(col)
label = "%2.2f" % pers[i]
label = f"{pers[i]:2.2f}"
orders.append(np.argsort(x_data[i]))
xfinal.append(np.array(x_data[i])[orders[i]])
yfinal.append(np.array(y_data[i])[orders[i]])
plt.plot(xfinal[i], yfinal[i], "o", label="UFH, p=" + label, color=col)
start = 0
optimized_parameters, pcov = opt.curve_fit(lin_fun, xfinal[i][start:], yfinal[i][start:])
optimized_parameters, _pcov = opt.curve_fit(lin_fun, xfinal[i][start:], yfinal[i][start:])
plt.plot(
xfinal[i][start:],
lin_fun(xfinal[i][start:], *optimized_parameters),
Expand All @@ -148,13 +148,13 @@ def runtime_comparison() -> None:
)

# general qlpd decoder data
label = "%2.2f" % pers2
label = f"{pers2:2.2f}"
orders2 = np.argsort(x_data2)
xfinal2 = np.array(x_data2)[orders2]
yfinal2 = np.array(y_data2)[orders2]
plt.plot(xfinal2, yfinal2, "d", label="GD, p=" + label, color="green")
start = 0
optimized_parameters2, pcov = opt.curve_fit(quad_fun, xfinal2[start:], yfinal2[start:])
optimized_parameters2, _pcov = opt.curve_fit(quad_fun, xfinal2[start:], yfinal2[start:])
plt.plot(
xfinal2[start:],
quad_fun(xfinal2[start:], *optimized_parameters2),
Expand Down
14 changes: 7 additions & 7 deletions scripts/numerics/visualize/visualizeWordErrRate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def wer() -> None:
input_filename = ""
input_filename2 = ""
input_filename3 = ""
fig, ax = plt.subplots(1)
_fig, ax = plt.subplots(1)

with Path(input_filename).open() as f:
with Path(input_filename).open(encoding="utf-8") as f:
data = json.load(f)
x_data = []
y_data = []
Expand All @@ -29,7 +29,7 @@ def wer() -> None:
x_dataf = np.array(x_data)[order]
y_dataf = np.array(y_data)[order]

with Path(input_filename2).open() as f:
with Path(input_filename2).open(encoding="utf-8") as f:
data2 = json.load(f)
x_data2 = []
y_data2 = []
Expand All @@ -41,7 +41,7 @@ def wer() -> None:
x_data2f = np.array(x_data2)[order2]
y_data2f = np.array(y_data2)[order2]

with Path(input_filename3).open() as f:
with Path(input_filename3).open(encoding="utf-8") as f:
data3 = json.load(f)
x_data3 = []
y_data3 = []
Expand Down Expand Up @@ -77,17 +77,17 @@ def wer_comp() -> None:
plt.rcParams.update({"font.size": 15})
input_filename = ""
input_filename2 = ""
fig, ax = plt.subplots(1)
_fig, ax = plt.subplots(1)

with Path(input_filename).open() as f:
with Path(input_filename).open(encoding="utf-8") as f:
data = json.load(f)
x_data = []
y_data = []
for key in data:
x_data.append(float(key))
y_data.append(data[key])

with Path(input_filename2).open() as f:
with Path(input_filename2).open(encoding="utf-8") as f:
data2 = json.load(f)
x_data2 = []
y_data2 = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import json
import subprocess
import subprocess # noqa: S404
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -145,7 +145,7 @@ def _compute_distances(hx: NDArray[np.int32], hz: NDArray[np.int32], codename: s
code_dict: Any = {}
_m, n = hx.shape
code_k = n - mod2.rank(hx) - mod2.rank(hz)
with Path(f"generated_codes/{codename}/info.txt").open() as f:
with Path(f"generated_codes/{codename}/info.txt").open(encoding="utf-8") as f:
code_dict = dict(
line[: line.rfind("#")].split(" = ") for line in f if not line.startswith("#") and line.strip()
)
Expand All @@ -157,7 +157,7 @@ def _compute_distances(hx: NDArray[np.int32], hz: NDArray[np.int32], codename: s
code_dict["dMX"] = int(code_dict["dMX"])
code_dict["dMZ"] = int(code_dict["dMZ"])

with Path(f"generated_codes/{codename}/code_params.txt").open("w") as file:
with Path(f"generated_codes/{codename}/code_params.txt").open("w", encoding="utf-8") as file:
file.write(json.dumps(code_dict))


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

import json
import subprocess
import subprocess # noqa: S404
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -153,7 +153,7 @@ def _compute_distances(hx: NDArray[np.int32], hz: NDArray[np.int32], codename: s
run_compute_distances(codename)
_, n = hx.shape
code_k = n - mod2.rank(hx) - mod2.rank(hz)
with Path(f"/codes/generated_codes/{codename}/info.txt").open() as f:
with Path(f"/codes/generated_codes/{codename}/info.txt").open(encoding="utf-8") as f:
code_dict: dict[str, Any] = dict(
line[: line.rfind("#")].split(" = ") for line in f if not line.startswith("#") and line.strip()
)
Expand All @@ -163,7 +163,7 @@ def _compute_distances(hx: NDArray[np.int32], hz: NDArray[np.int32], codename: s
code_dict["dX"] = int(code_dict["dX"])
code_dict["dZ"] = int(code_dict["dZ"])

with Path(f"/codes/generated_codes/{codename}/code_params.txt").open("w") as file:
with Path(f"/codes/generated_codes/{codename}/code_params.txt").open("w", encoding="utf-8") as file:
file.write(json.dumps(code_dict))


Expand All @@ -175,7 +175,7 @@ def _store_code_params(hx: csr_matrix, hz: csr_matrix, codename: str) -> None:
code_k = n - mod2.rank(hx) - mod2.rank(hz)
code_dict["n"] = n
code_dict["k"] = code_k
with Path(f"/codes/generated_codes/{codename}/code_params.txt").open("w") as file:
with Path(f"/codes/generated_codes/{codename}/code_params.txt").open("w", encoding="utf-8") as file:
file.write(json.dumps(code_dict))


Expand Down
Loading

0 comments on commit 30ee669

Please sign in to comment.