Skip to content

Commit

Permalink
🚨 update pre-commit, lockfile, and workflows (#106)
Browse files Browse the repository at this point in the history
## Description

This PR combines a couple of updates for the project configuration that
are long overdue.
This should resolve almost all outstanding pull requests.

## 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 Dec 11, 2024
1 parent aa8d335 commit 9316263
Show file tree
Hide file tree
Showing 43 changed files with 476 additions and 453 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# whether the workflow is triggered from a PR, a push to main, or a release, respectively.
python-packaging:
name: 🐍 Packaging
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-packaging.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-packaging.yml@v1.5
with:
# Do not include local version information on pushes to main to facilitate TestPyPI uploads.
no-local-version: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
path: dist
merge-multiple: true
- name: Generate artifact attestation for sdist and wheel(s)
uses: actions/attest-build-provenance@v1.4.4
uses: actions/attest-build-provenance@v2
with:
subject-path: "dist/*"
- uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ concurrency:
jobs:
change-detection:
name: 🔍 Change
uses: cda-tum/mqt-workflows/.github/workflows/reusable-change-detection.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-change-detection.yml@v1.5

cpp-tests:
name: 🇨‌ Test
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-cpp-tests)
uses: cda-tum/mqt-workflows/.github/workflows/reusable-cpp-ci.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-cpp-ci.yml@v1.5
with:
cmake-args: ""
cmake-args-ubuntu: -G Ninja
Expand All @@ -31,25 +31,25 @@ jobs:
name: 🇨‌ Lint
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-cpp-linter)
uses: cda-tum/mqt-workflows/.github/workflows/reusable-cpp-linter.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-cpp-linter.yml@v1.5

python-tests:
name: 🐍 Test
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-python-tests)
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-ci.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-ci.yml@v1.5

code-ql:
name: 📝 CodeQL
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-code-ql)
uses: cda-tum/mqt-workflows/.github/workflows/reusable-code-ql.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-code-ql.yml@v1.5

cd:
name: 🚀 CD
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-cd)
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-packaging.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-packaging.yml@v1.5

required-checks-pass: # This job does nothing and is only used for branch protection
name: 🚦 Check
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-mqt-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ concurrency:
jobs:
update-mqt-core:
name: ⬆️ Update MQT Core
uses: cda-tum/mqt-workflows/.github/workflows/reusable-mqt-core-update.yml@v1.4
uses: cda-tum/mqt-workflows/.github/workflows/reusable-mqt-core-update.yml@v1.5
with:
update-to-head: ${{ github.event.inputs.update-to-head == 'true' }}
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ repos:

# Python linting using ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.2
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -85,7 +85,7 @@ repos:

# Clang-format the C++ part of the code base automatically
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.4
rev: v19.1.5
hooks:
- id: clang-format
types_or: [c++, c, cuda]
Expand All @@ -101,14 +101,14 @@ repos:

# Format configuration files with prettier
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.3
rev: v3.4.2
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]

# Check for spelling
- repo: https://github.com/crate-ci/typos
rev: v1.27.3
rev: typos-dict-v0.11.37
hooks:
- id: typos

Expand All @@ -130,14 +130,14 @@ repos:

# Check JSON schemata
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.4
rev: 0.30.0
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.11.11
rev: 2024.11.25
hooks:
- id: validate-pyproject
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def _run_tests(
if shutil.which("ninja") is None:
session.install("ninja")

_extras = ["test", *extras]
extras_ = ["test", *extras]
if "--cov" in posargs:
_extras.append("coverage")
extras_.append("coverage")
posargs.append("--cov-config=pyproject.toml")

session.install(*BUILD_REQUIREMENTS, *install_args, env=env)
install_arg = f"-ve.[{','.join(_extras)}]"
install_arg = f"-ve.[{','.join(extras_)}]"
session.install("--no-build-isolation", install_arg, *install_args, env=env)
session.run("pytest", *run_args, *posargs, env=env)

Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,17 @@ extend-select = [
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"T20", # flake8-print
"TCH", # flake8-type-checking
"TC", # flake8-type-checking
"TID251", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"YTT", # flake8-2020
]
ignore = [
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in classmethod
"ISC001", # Conflicts with formatter
"PLR09", # Too many <...>
"PLR2004", # Magic value used in comparison
"PLC0415", # Import should be at top of file
"PT004", # Incorrect, just usefixtures instead.
"S101", # Use of assert detected
"S404", # `subprocess` module is possibly insecure
"D10", # Missing docstrings
Expand Down Expand Up @@ -282,7 +279,7 @@ archs = "auto64"
test-command = "python -c \"from mqt import qudits\""
test-skip = ["cp313*"] # skip testing on Python 3.13 until our dependencies are ready
build-frontend = "build[uv]"
free-threaded-support = true
enable = ["cpython-freethreading"]
manylinux-x86_64-image = "manylinux_2_28"
manylinux-aarch64-image = "manylinux_2_28"
manylinux-ppc64le-image = "manylinux_2_28"
Expand Down
4 changes: 2 additions & 2 deletions src/mqt/qudits/compiler/dit_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ..core.lanes import Lanes
from ..quantum_circuit.components.extensions.gate_types import GateTypes
from . import CompilerPass
from .naive_local_resynth import NaiveLocResynthOptPass
from .onedit import LogLocQRPass, PhyLocAdaPass, PhyLocQRPass, ZPropagationOptPass, ZRemovalOptPass
from .twodit import LogEntQRCEXPass
Expand All @@ -15,6 +14,7 @@
from ..quantum_circuit import QuantumCircuit
from ..quantum_circuit.gate import Gate
from ..simulation.backends.backendv2 import Backend
from . import CompilerPass


class QuditCompiler:
Expand Down Expand Up @@ -48,7 +48,7 @@ def compile(self, backend: Backend, circuit: QuantumCircuit, passes_names: list[
elif "Multi" in str(compiler_pass):
passes_dict[GateTypes.MULTI] = decomposition
for gate in circuit.instructions:
decomposer = typing.cast(Optional[CompilerPass], passes_dict.get(gate.gate_type))
decomposer = typing.cast("Optional[CompilerPass]", passes_dict.get(gate.gate_type))
if decomposer is not None:
new_instructions = decomposer.transpile_gate(gate)
new_instr.extend(new_instructions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def graph_rule_ongate(gate: gates.R, graph: LevelGraph) -> gates.R:
return gates.R(
gate.parent_circuit,
"R",
cast(int, gate.target_qudits),
cast("int", gate.target_qudits),
[g_lev_a, g_lev_b, gate.theta, new_g_phi],
gate.dimensions,
)
Expand Down Expand Up @@ -117,7 +117,7 @@ def gate_chain_condition(previous_gates: list[R], current: R) -> R:
return gates.R(
current.parent_circuit,
"R",
cast(int, current.target_qudits),
cast("int", current.target_qudits),
[current.lev_a, current.lev_b, theta, phi],
current.dimensions,
) # R(theta, phi, current.lev_a, current.lev_b, current.dimension)
Expand All @@ -142,7 +142,11 @@ def route_states2rotate_basic(gate: R, orig_placement: LevelGraph) -> tuple[floa
phy_n_ip1 = placement.nodes[path[i + 1]]["lpmap"]

pi_gate_phy = gates.R(
gate.parent_circuit, "R", cast(int, gate.target_qudits), [phy_n_i, phy_n_ip1, np.pi, -np.pi / 2], dimension
gate.parent_circuit,
"R",
cast("int", gate.target_qudits),
[phy_n_i, phy_n_ip1, np.pi, -np.pi / 2],
dimension,
) # R(np.pi, -np.pi / 2, phy_n_i, phy_n_ip1, dimension)

pi_gate_phy = gate_chain_condition(pi_pulses_routing, pi_gate_phy)
Expand All @@ -152,7 +156,7 @@ def route_states2rotate_basic(gate: R, orig_placement: LevelGraph) -> tuple[floa
pi_gate_logic = gates.R(
gate.parent_circuit,
"R",
cast(int, gate.target_qudits),
cast("int", gate.target_qudits),
[path[i], path[i + 1], pi_gate_phy.theta, pi_gate_phy.phi / 2],
dimension,
) # R(pi_gate_phy.theta, pi_gate_phy.phi, path[i], path[i + 1], dimension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def transpile(self, circuit: QuantumCircuit) -> QuantumCircuit:
def propagate_z(circuit: QuantumCircuit, line: list[R | VirtRz], back: bool) -> tuple[list[R], list[VirtRz]]:
z_angles: dict[int, float] = {}
list_of_x_yrots: list[R] = []
qudit_index = cast(int, line[0].target_qudits)
qudit_index = cast("int", line[0].target_qudits)
dimension = line[0].dimensions

for i in range(dimension):
Expand Down Expand Up @@ -111,9 +111,7 @@ def remove_z(self, original_circuit: QuantumCircuit, back: bool = True) -> Quant

for interval in intervals:
if len(interval) > 1:
from ....quantum_circuit.gates import R, VirtRz

sequence = cast(list[Union[R, VirtRz]], circuit.instructions[interval[0] : interval[-1] + 1])
sequence = cast("list[Union[R, VirtRz]]", circuit.instructions[interval[0] : interval[-1] + 1])
fixed_seq: list[R] = []
z_tail: list[VirtRz] = []
fixed_seq, z_tail = self.propagate_z(circuit, sequence, back)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ def __init__(self, backend: Backend, vrz_prop: bool = False) -> None:
self.vrz_prop = vrz_prop

def transpile_gate(self, gate: Gate) -> list[Gate]:
energy_graph_i = self.backend.energy_level_graphs[cast(int, gate.target_qudits)]
energy_graph_i = self.backend.energy_level_graphs[cast("int", gate.target_qudits)]

qr = PhyQrDecomp(gate, energy_graph_i)

_decomp, algorithmic_cost, total_cost = qr.execute()

adaptive = PhyAdaptiveDecomposition(
gate, energy_graph_i, (algorithmic_cost, total_cost), cast(int, gate.dimensions), z_prop=self.vrz_prop
gate, energy_graph_i, (algorithmic_cost, total_cost), cast("int", gate.dimensions), z_prop=self.vrz_prop
)
(matrices_decomposed, _best_cost, new_energy_level_graph) = adaptive.execute()

self.backend.energy_level_graphs[cast(int, gate.target_qudits)] = new_energy_level_graph
self.backend.energy_level_graphs[cast("int", gate.target_qudits)] = new_energy_level_graph
return [op.dag() for op in reversed(matrices_decomposed)]

def transpile(self, circuit: QuantumCircuit) -> QuantumCircuit:
Expand Down Expand Up @@ -80,12 +80,12 @@ def __init__(
) -> None:
self.circuit: QuantumCircuit = gate.parent_circuit
self.U: NDArray = gate.to_matrix(identities=0)
self.qudit_index: int = cast(int, gate.target_qudits)
self.qudit_index: int = cast("int", gate.target_qudits)
self.graph: LevelGraph = graph_orig
self.graph.phase_storing_setup()
self.cost_limit: tuple[float, float] = cast(tuple[float, float], cost_limit)
self.dimension: int = cast(int, dimension)
self.phase_propagation: bool = cast(bool, z_prop)
self.cost_limit: tuple[float, float] = cast("tuple[float, float]", cost_limit)
self.dimension: int = cast("int", dimension)
self.phase_propagation: bool = cast("bool", z_prop)
self.TREE: NAryTree = NAryTree()

def execute(self) -> tuple[list[Gate], tuple[float, float], LevelGraph]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, backend: Backend) -> None:
super().__init__(backend)

def transpile_gate(self, gate: Gate) -> list[Gate]:
energy_graph_i = self.backend.energy_level_graphs[cast(int, gate.target_qudits)]
energy_graph_i = self.backend.energy_level_graphs[cast("int", gate.target_qudits)]
qr = PhyQrDecomp(gate, energy_graph_i, not_stand_alone=False)
decomp, _algorithmic_cost, _total_cost = qr.execute()
return [op.dag() for op in reversed(decomp)]
Expand All @@ -51,8 +51,8 @@ class PhyQrDecomp:
def __init__(self, gate: Gate, graph_orig: LevelGraph, z_prop: bool = False, not_stand_alone: bool = True) -> None:
self.gate: Gate = gate
self.circuit: QuantumCircuit = gate.parent_circuit
self.dimension: int = cast(int, gate.dimensions)
self.qudit_index: int = cast(int, gate.target_qudits)
self.dimension: int = cast("int", gate.dimensions)
self.qudit_index: int = cast("int", gate.target_qudits)
self.U: NDArray = gate.to_matrix(identities=0)
self.graph: LevelGraph = graph_orig
self.phase_propagation: bool = z_prop
Expand All @@ -77,9 +77,9 @@ def execute(self) -> tuple[list[Gate], float, float]:
phase_gate = gates.VirtRz(
self.gate.parent_circuit,
"VRz",
cast(int, self.gate.target_qudits),
cast("int", self.gate.target_qudits),
[self.graph.nodes[i]["lpmap"], theta_z],
cast(int, self.gate.dimensions),
cast("int", self.gate.dimensions),
) # (thetaZ, self.graph.nodes[i]['lpmap'], dimension)
decomp.append(phase_gate)
recover_dict[i] = theta_z
Expand Down Expand Up @@ -151,9 +151,9 @@ def execute(self) -> tuple[list[Gate], float, float]:
phase_gate = gates.VirtRz(
self.gate.parent_circuit,
"VRz",
cast(int, self.gate.target_qudits),
cast("int", self.gate.target_qudits),
[phy_n_i, np.angle(diag_u[i])],
cast(int, self.gate.dimensions),
cast("int", self.gate.dimensions),
) # Rz(np.angle(diag_U[i]), phy_n_i, dimension)

decomp.append(phase_gate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ def __init__(self, backend: Backend) -> None:
super().__init__(backend)

def transpile_gate(self, gate: Gate) -> list[Gate]:
energy_graph_i = self.backend.energy_level_graphs[cast(int, gate.target_qudits)]
energy_graph_i = self.backend.energy_level_graphs[cast("int", gate.target_qudits)]

qr = QrDecomp(gate, energy_graph_i)

_decomp, algorithmic_cost, total_cost = qr.execute()

adaptive = LogAdaptiveDecomposition(
gate, energy_graph_i, (algorithmic_cost, total_cost), cast(int, gate.dimensions)
gate, energy_graph_i, (algorithmic_cost, total_cost), cast("int", gate.dimensions)
)

(
matrices_decomposed,
_best_cost,
self.backend.energy_level_graphs[cast(int, gate.target_qudits)],
self.backend.energy_level_graphs[cast("int", gate.target_qudits)],
) = adaptive.execute()

return matrices_decomposed
Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(
) -> None:
self.circuit: QuantumCircuit = gate.parent_circuit
self.U: NDArray = gate.to_matrix(identities=0)
self.qudit_index: int = cast(int, gate.target_qudits)
self.qudit_index: int = cast("int", gate.target_qudits)
self.graph: LevelGraph = graph_orig
self.graph.phase_storing_setup()
self.cost_limit: tuple[float, float] = cost_limit
Expand Down
Loading

0 comments on commit 9316263

Please sign in to comment.