Skip to content

Conversation

@denialhaag
Copy link
Member

@denialhaag denialhaag commented Jan 20, 2026

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 self-assigned this Jan 20, 2026
@denialhaag denialhaag added dependencies Pull requests that update a dependency file python Pull requests that update Python code code quality Improvements to code quality labels Jan 20, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

Migrate static typing from mypy to Ty: enable Ty in CI, replace pre-commit mypy hook with a local ty-check hook, add Ty config and dependency, and update code/tests with type-import adjustments, signature changes, and type-ignore annotations to satisfy Ty.

Changes

Cohort / File(s) Summary
CI & Tooling
\.github/workflows/ci.yml, \.pre-commit-config.yaml, pyproject.toml, CHANGELOG.md
Enable ty in CI (enable-ty: true, disable mypy), add ty dev dependency and [tool.ty.*] config, replace pre-commit mypy hook with local ty-check (uv run ty check), and record changelog entry.
Typing imports & small annotations
src/mqt/predictor/hellinger/utils.py, src/mqt/predictor/reward.py, src/mqt/predictor/ml/helper.py, src/mqt/predictor/utils.py
Adjust TYPE_CHECKING import origins, small type annotation refinements, and add targeted # type: ignore[...] to silence Ty where needed (no runtime changes).
RL parsing / signatures
src/mqt/predictor/rl/parsing.py, src/mqt/predictor/rl/predictor.py, src/mqt/predictor/rl/predictorenv.py
Change return/type annotations and signatures: Gate and Target typing moves to TYPE_CHECKING; postprocess_vf2postlayout now returns ApplyLayout; compile_as_predicted accepts `QuantumCircuit
Predictor ML typing & error handling
src/mqt/predictor/ml/predictor.py, src/mqt/predictor/ml/helper.py
Add type: ignore annotations on QuantumCircuit.from_qasm_file calls, replace assertion-based unreachable with NotImplementedError, and silence specific type warnings.
Runtime pass handling & guards
src/mqt/predictor/rl/helper.py, src/mqt/predictor/rl/predictorenv.py, tests/compilation/test_helper_rl.py
Remove unnecessary str() for path args, add runtime assertions/casts for transpile passes, ensure layout existence before post-processing, and construct PassManager from pass lists.
Tests — typing and data shapes
tests/compilation/test_integration_further_SDKs.py, tests/compilation/test_reward.py, tests/hellinger_distance/test_estimated_hellinger_distance.py
Update test signatures/fixtures to new typed shapes (e.g., dict[PassType, list[Action]]), add runtime isinstance checks for passes/actions, convert list-based data to NumPy arrays, and add targeted ty: ignore where necessary.

Sequence Diagram(s)

(Skipped — changes are tooling migration and scattered typing/signature updates, not a new multi-component runtime control flow.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

documentation

Poem

🐇
I hopped through types and CI light,
swapped mypy cape for Ty tonight.
Imports nudged and tests made new,
linting tuned — a tidy view.
Carrots for builds that pass just right! 🍃

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: replacing mypy with ty as the type checker.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request provides a brief description of replacing mypy with ty, includes a comprehensive checklist with most items checked, but lacks detailed context about motivation, rationale, or dependencies.

✏️ 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.

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: 4

🤖 Fix all issues with AI agents
In `@src/mqt/predictor/ml/helper.py`:
- Around line 121-123: The call site uses qc.count_ops() (returns a
Counter/Mapping-like object) and currently silences the type mismatch with a
ty-ignore; update the signature of dict_to_featurevector to accept a
Mapping[str, int] (or collections.abc.Mapping) instead of a concrete dict so it
directly accepts ops_list without casting, remove the ty: ignore in the call,
and add any needed typing import (Mapping) and adjust internal code in
dict_to_featurevector to treat the input as a mapping of str->int.

In `@src/mqt/predictor/rl/predictorenv.py`:
- Around line 17-18: Remove the unused noqa marker on the import of TketBasePass
in predictorenv.py: delete the trailing "# noqa: PLC2701" from the line
importing pytket._tket.passes.BasePass (aliased as TketBasePass) so the import
is a plain statement alongside the QiskitBasePass import; ensure no other noqa
markers are added for TketBasePass or QiskitBasePass.

In `@tests/compilation/test_integration_further_SDKs.py`:
- Line 42: The parameter annotation for available_actions_dict is wrong: replace
dict[str, list[Action]] with dict[PassType, list[Action]] wherever used (e.g.,
in test_bqskit_o2_action and the other test functions that accept
available_actions_dict) so the type matches the fixture returning keys of type
PassType; update the function signatures (and any related type hints) to use
PassType as the dict key type and ensure PassType is imported where needed.

In `@tests/hellinger_distance/test_estimated_hellinger_distance.py`:
- Around line 254-258: The test uses rng.integers(0, 10) which can produce 0 and
generates 1‑D feature arrays; change to a deterministic positive sample count
(e.g. set random_int = 5) and construct X_train as a 2‑D array (e.g.
rng.random((random_int, n_features))) while keeping y_train as a 1‑D array of
length random_int so TrainingData(X_train=..., y_train=...) provides a non-empty
2‑D feature matrix compatible with RandomForestRegressor and avoids spurious
failures when checking device count.

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 `@src/mqt/predictor/rl/predictorenv.py`:
- Around line 19-20: Remove the no-op conditional that checks "if
sys.version_info >= (3, 11) and TYPE_CHECKING:  # pragma: no cover" in
predictorenv.py; delete that entire empty block (the conditional and its "pass")
so there is no dead code left behind, keeping imports and other logic intact.

In `@tests/compilation/test_integration_further_SDKs.py`:
- Line 20: The import line "from pytket._tket.passes import BasePass as
TketBasePass" contains an unnecessary "# noqa: PLC2701" directive; remove that
trailing noqa comment so the import is clean and linter warnings about unused
noqa are resolved—edit the import statement that defines TketBasePass to drop
the "# noqa: PLC2701" suffix.
♻️ Duplicate comments (1)
src/mqt/predictor/rl/predictorenv.py (1)

17-17: Remove unused noqa directive.

Static analysis flags # noqa: PLC2701 as unused on this import.

🧹 Proposed fix
-from pytket._tket.passes import BasePass as TketBasePass  # noqa: PLC2701
+from pytket._tket.passes import BasePass as TketBasePass

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mqt/predictor/ml/predictor.py 60.0% 2 Missing ⚠️
src/mqt/predictor/rl/predictorenv.py 88.8% 2 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: 1

🤖 Fix all issues with AI agents
In `@src/mqt/predictor/ml/predictor.py`:
- Line 179: The call to QuantumCircuit.from_qasm_file(filename) uses a
type-check suppression; instead normalize the argument by converting filename to
a string (e.g., use str(filename) or filename.as_posix()) before passing it and
remove the "# ty: ignore" comment; update the call site where
QuantumCircuit.from_qasm_file is invoked so it passes str(filename) (or
filename.as_posix()) to satisfy the type checker and keep the call readable.
♻️ Duplicate comments (2)
src/mqt/predictor/ml/predictor.py (2)

356-356: Same type-ignore concern as above.
Consider converting the Path to str here as well to avoid suppression.


466-468: Same type-ignore concern as above.
Converting the Path to str avoids the ignore and keeps the call type-safe.

@denialhaag denialhaag requested a review from burgholzer January 21, 2026 01:09
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.

This looks reasonable 👍🏻 thanks 🙏

@denialhaag denialhaag merged commit 7d25da8 into main Jan 25, 2026
13 of 14 checks passed
@denialhaag denialhaag deleted the ty branch January 25, 2026 09:48
@denialhaag denialhaag mentioned this pull request Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Improvements to code quality 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