Skip to content

Commit

Permalink
🚨 small ruff updates (#329)
Browse files Browse the repository at this point in the history
## Description

A couple of small updates and new rules for ruff

## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.

---------

Signed-off-by: burgholzer <[email protected]>
  • Loading branch information
burgholzer authored Nov 9, 2023
1 parent 68539e4 commit 3b083a3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
class CDAStyle(UnsrtStyle):
"""Custom style for including PDF links."""

def format_url(self, _e: Entry) -> HRef:
def format_url(self, _e: Entry) -> HRef: # noqa: PLR6301
"""Format URL field as a link to the PDF."""
url = field("url", raw=True)
return href()[url, "[PDF]"]
Expand Down
20 changes: 18 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ extend-select = [
"EXE", # flake8-executable
"FA", # flake8-future-annotations
"FLY", # flynt
"FURB", # refurb
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging-format
"N", # flake8-naming
"NPY", # numpy
"PERF", # perflint
Expand All @@ -202,23 +204,37 @@ extend-select = [
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # Ruff-specific
"S", # flake8-bandit
"SLF", # flake8-self
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"T20", # flake8-print
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"YTT", # flake8-2020
]
extend-ignore = [
"ANN101", # Missing type annotation for self in method
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in classmethod
"ISC001", # Conflicts with formatter
"PLR", # Design related pylint codes
"PLR0904", # Too many public methods
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments
"PLR0915", # Too many local statements
"PLR2004", # Magic value used in comparison
"PLC0415", # Import should be at top of file
"PT004", # Incorrect, just usefixtures instead.
"S101", # Use of assert detected
]
isort.required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"test/python/**" = ["T20", "ANN"]
"docs/**" = ["T20"]
"noxfile.py" = ["T20", "TID251"]
"*.pyi" = ["D"] # pydocstyle
"*.ipynb" = [
"D", # pydocstyle
Expand Down
1 change: 0 additions & 1 deletion src/mqt/qcec/compilation_flow_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,3 @@ def generate_profile(
filename = generate_profile_name(optimization_level=optimization_level, mode=mode)
filepath = filepath.joinpath(filename)
write_profile_data_to_file(profile, filepath)
print(f"Wrote profile data to {filepath}")
4 changes: 2 additions & 2 deletions test/python/test_compilation_flow_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@


@pytest.fixture(params=[0, 1, 2, 3])
def optimization_level(request: Any) -> int: # noqa: ANN401
def optimization_level(request: Any) -> int:
"""Fixture for optimization levels."""
return cast(int, request.param)


@pytest.fixture(params=[qcec.AncillaMode.NO_ANCILLA, qcec.AncillaMode.RECURSION, qcec.AncillaMode.V_CHAIN])
def ancilla_mode(request: Any) -> qcec.AncillaMode: # noqa: ANN401
def ancilla_mode(request: Any) -> qcec.AncillaMode:
"""Fixture for ancilla modes."""
return cast(qcec.AncillaMode, request.param)

Expand Down
16 changes: 8 additions & 8 deletions test/python/test_symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ def test_verify_compilation_on_optimization_levels(original_circuit: QuantumCirc
"""Test the verification of the compilation of a circuit to the 5-qubit IBMQ Athens architecture with various optimization levels."""
compiled_circuit = transpile(original_circuit, backend=FakeAthens(), optimization_level=optimization_level)
result = qcec.verify_compilation(original_circuit, compiled_circuit, optimization_level, timeout=3600)
assert (
result.equivalence == qcec.EquivalenceCriterion.equivalent
or result.equivalence == qcec.EquivalenceCriterion.equivalent_up_to_global_phase
)
assert result.equivalence in {
qcec.EquivalenceCriterion.equivalent,
qcec.EquivalenceCriterion.equivalent_up_to_global_phase,
}


@pytest.mark.parametrize("optimization_level", [0, 1, 2, 3])
Expand All @@ -205,10 +205,10 @@ def test_verify_compilation_on_optimization_levels_config(
result = qcec.verify_compilation(
original_circuit, compiled_circuit, optimization_level, AncillaMode.NO_ANCILLA, config
)
assert (
result.equivalence == qcec.EquivalenceCriterion.equivalent
or result.equivalence == qcec.EquivalenceCriterion.equivalent_up_to_global_phase
)
assert result.equivalence in {
qcec.EquivalenceCriterion.equivalent,
qcec.EquivalenceCriterion.equivalent_up_to_global_phase,
}


def test_performed_instantiations(rz_commute_lhs: QuantumCircuit, rz_commute_rhs_incorrect: QuantumCircuit) -> None:
Expand Down
8 changes: 4 additions & 4 deletions test/python/test_verify_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def test_verify_compilation_on_optimization_levels(original_circuit: QuantumCirc
"""Test the verification of the compilation of a circuit to the 5-qubit IBMQ Athens architecture with various optimization levels."""
compiled_circuit = transpile(original_circuit, backend=FakeAthens(), optimization_level=optimization_level)
result = qcec.verify_compilation(original_circuit, compiled_circuit, optimization_level=optimization_level)
assert (
result.equivalence == qcec.EquivalenceCriterion.equivalent
or result.equivalence == qcec.EquivalenceCriterion.equivalent_up_to_global_phase
)
assert result.equivalence in {
qcec.EquivalenceCriterion.equivalent,
qcec.EquivalenceCriterion.equivalent_up_to_global_phase,
}


def test_warning_on_missing_measurements() -> None:
Expand Down

0 comments on commit 3b083a3

Please sign in to comment.