Skip to content

Conversation

@denialhaag
Copy link
Member

Description

This PR replaces mypy with ty.

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

@denialhaag denialhaag requested a review from burgholzer January 19, 2026 16:08
@denialhaag denialhaag self-assigned this Jan 19, 2026
@denialhaag denialhaag added dependencies Pull requests that update a dependency file python Pull requests that update Python code code quality Anything related to code quality and code style. labels Jan 19, 2026
@github-project-automation github-project-automation bot moved this to In Progress in MQT Simulation Jan 19, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Changed

    • Migrated static type checking from mypy to ty with stricter error-on-warning handling.
    • Cleaned up inline type-ignore annotations and improved typing across multiple backends and helpers.
  • Tests

    • Updated tests to pass parameter values as explicit dict mappings instead of nested lists.
    • Removed an outdated simulator test script.
  • Chores

    • Updated CI and pre-commit configs to run the new ty-based checks and hooks.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Replaces mypy with the "ty" type checker across CI, pre-commit, and pyproject; converts several simulator backend _run_experiment methods to instance methods; tightens some backend/provider type annotations; updates qasm backend run signature to accept run_input and options-based parameter_values; converts tests to pass parameter mappings as dicts; deletes a Grover test script.

Changes

Cohort / File(s) Summary
Type checker migration (mypy → ty)
​.github/workflows/ci.yml, .pre-commit-config.yaml, pyproject.toml, CHANGELOG.md
Replace mypy with ty: enable-ty flag in CI, add local ty-check pre-commit hook, add [tool.ty] config and ty==0.0.12 dev-dependency, update changelog and pre-commit skip list.
Backend method binding changes
python/mqt/ddsim/deterministic_noise_simulator_backend.py, python/mqt/ddsim/stochastic_noise_simulator_backend.py, python/mqt/ddsim/unitary_simulator_backend.py
Convert _run_experiment from static/class methods to instance methods (remove decorators, add self) and relax options typing to Any (add noqa where present).
Backend API & runtime flow adjustments
python/mqt/ddsim/qasm_simulator_backend.py, python/mqt/ddsim/job.py, python/mqt/ddsim/provider.py
qasm backend run() now accepts run_input and reads parameter_values from **options; DDSIMJob.backend() return type tightened via cast to BackendV2; provider.backends() filter typing changed to accept `Callable[[Backend], bool]
Type annotation / import cleanups
python/mqt/ddsim/experiment_header.py, python/mqt/ddsim/primitives/estimator.py, python/mqt/ddsim/primitives/sampler.py
Remove inline type: ignore annotations, adjust import path for ObservablesArray, clean return annotations, and add defensive defaulting of shots in sampler when pub.shots is None.
Tests: parameter input format changes
test/python/primitives/test_estimator.py, test/python/primitives/test_sampler.py, test/python/simulator/test_qasm_simulator.py
Update tests to supply parameter values as dict mappings (Parameter → value) and use parameter_values= keyword where appropriate; adapt helpers and assertions accordingly.
Deleted test script
test/python/simulator/grover.py
Removed Grover simulation test script.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

documentation

Poem

🐇 I hopped through CI and pre‑commit land,

Swapped mypy for ty with a nimble hand.
Methods found self, tests map their keys,
Gone a Grover script, but types hum with ease.
🥕 Hooray — a tidy, hoppity refactor!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: replacing mypy with ty as the static type checker.
Description check ✅ Passed The description provides a clear summary of the change and includes a completed checklist. Most critical items are checked, though some optional items are marked as not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
python/mqt/ddsim/job.py 75.0% 1 Missing ⚠️
python/mqt/ddsim/primitives/sampler.py 66.6% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/python/primitives/test_sampler.py (1)

173-179: Prefer strict=True here to catch parameter-length mismatches.
strict=False weakens test validation; if parameter counts are known, strict=True is safer. If you must support Python <3.10, drop strict and add explicit length checks instead.

♻️ Proposed change
-    parameters_1_a = dict(zip(qc_1.parameters, [0, 1, 1, 2, 3, 5], strict=False))
-    parameters_1_b = dict(zip(qc_1.parameters, [1, 2, 3, 4, 5, 6], strict=False))
-    parameters_2 = dict(zip(qc_2.parameters, [0, 1, 2, 3, 4, 5, 6, 7], strict=False))
+    parameters_1_a = dict(zip(qc_1.parameters, [0, 1, 1, 2, 3, 5], strict=True))
+    parameters_1_b = dict(zip(qc_1.parameters, [1, 2, 3, 4, 5, 6], strict=True))
+    parameters_2 = dict(zip(qc_2.parameters, [0, 1, 2, 3, 4, 5, 6, 7], strict=True))
🤖 Fix all issues with AI agents
In `@pyproject.toml`:
- Line 367: Remove the unnecessary test dependency "qiskit-algorithms>=0.4.0"
from pyproject.toml: locate the entry that exactly matches
"qiskit-algorithms>=0.4.0" (the string from the diff) and delete that line from
the test/dev dependencies section so it is no longer declared in the project's
dependency list.

In `@python/mqt/ddsim/qasm_simulator_backend.py`:
- Around line 134-159: Update the run() method docstring to reflect that
parameter_values is no longer a separate argument but an optional key inside
**options; mention that run_input accepts a QuantumCircuit or
Sequence[QuantumCircuit], that parameter_values (Sequence[Parameters] | None)
can be provided via options with that type, and that other run options may be
passed through; keep the Returns description for DDSIMJob unchanged and
reference the method name run and the parameter_values option for clarity.
♻️ Duplicate comments (1)
test/python/primitives/test_estimator.py (1)

145-148: Same Python-version constraint applies to zip(..., strict=True) here.
Please ensure the project’s minimum Python version is 3.10+ (or remove strict= and add explicit length checks for older versions).

Also applies to: 198-200, 214-223, 245-277

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
python/mqt/ddsim/qasm_simulator_backend.py (1)

190-190: Type annotation inconsistency in _run_experiment method.

The **options parameter is annotated as dict[str, Any] but should be Any to match the unpacking semantics. When using **kwargs, the annotation should be the value type, not a dict type.

🔧 Proposed fix
-    def _run_experiment(self, qc: QuantumCircuit, **options: dict[str, Any]) -> ExperimentResult:
+    def _run_experiment(self, qc: QuantumCircuit, **options: Any) -> ExperimentResult:

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@python/mqt/ddsim/deterministic_noise_simulator_backend.py`:
- Line 52: The _run_experiment signature currently uses **options: Any and a
redundant noqa; replace that by defining a TypedDict (e.g., ExperimentOptions)
listing the accepted option keys and types, then change the signature to accept
**options: Unpack[ExperimentOptions] (importing TypedDict and Unpack from
typing/typing_extensions as needed) so ANN401 is resolved, and remove the "#
noqa: PLR6301" token from the _run_experiment definition; update any internal
references to options to match the new typed keys if necessary.

In `@python/mqt/ddsim/stochastic_noise_simulator_backend.py`:
- Line 55: Replace the loose **options: Any in _run_experiment with a concrete
TypedDict and Unpack to tighten typing: create an ExperimentOptions TypedDict
containing the exact keys and value types that _run_experiment expects, import
TypedDict and Unpack from typing, change the signature to def
_run_experiment(self, qc: QuantumCircuit, **options: Unpack[ExperimentOptions])
-> ExperimentResult, and remove the unused "# noqa: PLR6301" comment; also
update any local references or callers to match the new option key names/types
if necessary.

Copy link
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Anything related to code quality and code style. dependencies Pull requests that update a dependency file python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants