Skip to content

Commit

Permalink
⬆️🪝 update pre-commit config (#434)
Browse files Browse the repository at this point in the history
## Description

This PR adds schema validation to the pre-commit hooks. In addition, it
also replaces codespell with `crates-ci/typos` and fix all newly brought
up typos.
Finally, the PR runs `pre-commit autoupdate`.

## 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 <burgholzer@me.com>
  • Loading branch information
burgholzer authored Aug 9, 2024
1 parent a6c6469 commit 4fd973c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
23 changes: 18 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ repos:

# Python linting and formatting using ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.6
rev: v0.5.7
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down Expand Up @@ -107,11 +107,10 @@ repos:
- pytest

# Check for spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
- repo: https://github.com/crate-ci/typos
rev: v1.23.6
hooks:
- id: codespell
args: ["-L", "wille,linz", "--skip", "*.ipynb"]
- id: typos

# Catch common capitalization mistakes
- repo: local
Expand All @@ -128,3 +127,17 @@ repos:
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]

# Check JSON schemata
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.1
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs

# Check the pyproject.toml file
- repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2024.08.08
hooks:
- id: validate-pyproject
2 changes: 1 addition & 1 deletion docs/source/ParameterizedCircuits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"\n",
"Variational quantum algorithms are a family of mixed quantum-classical algorithms that try to achieve a quantum advantage via low-depth circuits. This is achieved by offloading a substantial amount of computational work to a classical processor. The quantum circuits employed by variational quantum algorithms involve *parameterized gates* which depend on some a-priori uninstantiated variable.\n",
"\n",
"Variational quantum algorithms try to optimize the circuit's parameters in each iteration with the classical post-processor while the quantum circuit is used to compute the cost function that is being optimized. Because recompiling the quantum circuit in each of these iterations is a costly procedure, the circuit is usually compiled in *paramterized* form in which the parameters tuned by the classical optimization routine are not bound to specific values.\n",
"Variational quantum algorithms try to optimize the circuit's parameters in each iteration with the classical post-processor while the quantum circuit is used to compute the cost function that is being optimized. Because recompiling the quantum circuit in each of these iterations is a costly procedure, the circuit is usually compiled in *parameterized* form in which the parameters tuned by the classical optimization routine are not bound to specific values.\n",
"\n",
"As is the case with parameter-free circuits, errors can be made during the compilation process. Therefore, verifying the correctness of compilations of parameterized quantum circuits is an important task for near-term quantum computing.\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/PartialEquivalence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"id": "10fff8c7-f36c-422e-8deb-796cc7637e45",
"metadata": {},
"source": [
"Aditionally, consider the following circuit, which only acts on two qubits."
"Additionally, consider the following circuit, which only acts on two qubits."
]
},
{
Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,21 @@ isort.required-imports = ["from __future__ import annotations"]
convention = "google"


[tool.typos]
default.extend-ignore-re = [
'"id": ".*",',
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$", # ignore line
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on" # ignore block
]
[tool.typos.default.extend-words]
wille = "wille"
anc = "anc"
aer = "aer"


[tool.repo-review]
ignore = [
"PC160", # "Uses codespell" -> switched to https://github.com/crate-ci/typos
"PC180", # "Uses prettier" -> switched to different prettier-mirror that is not recognized by the check
]

Expand Down
2 changes: 1 addition & 1 deletion src/checker/EquivalenceChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <nlohmann/json.hpp>

// this function is mainly placed here in order to have an out-of-line
// virtual method definition which avoids emitting the classe's vtable in
// virtual method definition which avoids emitting the classes' vtable in
// every translation unit.
void ec::EquivalenceChecker::json(nlohmann::basic_json<>& j) const noexcept {
j["equivalence"] = toString(equivalence);
Expand Down
4 changes: 2 additions & 2 deletions src/mqt/qcec/compilation_flow_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def create_gate_profile_data(
cost = compute_cost(qc, basis_gates, optimization_level)

# add the cost to the profile data
profile_data[(gate, control)] = cost
profile_data[gate, control] = cost
return profile_data


Expand Down Expand Up @@ -360,7 +360,7 @@ def find_continuation(
if next_term >= prediction_cutoff:
break
sequence.append(next_term)
profile_data[(gate, max_control + i + 1)] = next_term
profile_data[gate, max_control + i + 1] = next_term


gate_collection_for_mode = {
Expand Down
4 changes: 2 additions & 2 deletions test/python/test_symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ def test_non_equivalent_phase_rz_commute(
assert result.equivalence == qcec.EquivalenceCriterion.not_equivalent


def test_equivalent_roation_gate_fuse(
def test_equivalent_rotation_gate_fuse(
rotation_gate_fuse_lhs: QuantumCircuit, rotation_gate_fuse_rhs_correct: QuantumCircuit
) -> None:
"""Test a rotation gate fusion rule."""
result = qcec.verify(rotation_gate_fuse_lhs, rotation_gate_fuse_rhs_correct)
assert result.equivalence == qcec.EquivalenceCriterion.equivalent


def test_non_equivalent_roation_gate_fuse(
def test_non_equivalent_rotation_gate_fuse(
rotation_gate_fuse_lhs: QuantumCircuit, rotation_gate_fuse_rhs_incorrect: QuantumCircuit
) -> None:
"""Test an invalid rotation gate fusion rule."""
Expand Down
6 changes: 3 additions & 3 deletions test/test_partial_equivalence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void addStandardOperationToCircuit(QuantumComputation& circuit,
}

std::vector<qc::Qubit>
fiveDiffferentRandomNumbers(const qc::Qubit min, const qc::Qubit max,
std::mt19937_64& randomGenerator) {
fiveDifferentRandomNumbers(const qc::Qubit min, const qc::Qubit max,
std::mt19937_64& randomGenerator) {
std::vector<qc::Qubit> numbers;

for (qc::Qubit i = min; i < max; i++) {
Expand Down Expand Up @@ -202,7 +202,7 @@ StandardOperation
makeRandomStandardOperation(const qc::Qubit nrQubits, const qc::Qubit min,
std::mt19937_64& randomGenerator) {
const auto randomNumbers =
fiveDiffferentRandomNumbers(min, min + nrQubits, randomGenerator);
fiveDifferentRandomNumbers(min, min + nrQubits, randomGenerator);

// choose one of the non-compound operations, but not "None", and also
// not GPhase or I or Barrier
Expand Down

0 comments on commit 4fd973c

Please sign in to comment.