MQ-17 Strict Mypy Conformance Report¶
Overview¶
MQ-17 tightened [tool.mypy] to strict mode across the entire public SDK.
All per-module error-code overrides have been removed. The remaining in-source
# type: ignore comments were eliminated by fixing the underlying types, so
mypy --strict now passes with zero errors and zero suppressions.
Scope¶
All source files under
src/microquantum/(127 files).Removed
[[tool.mypy.overrides]]formicroquantum.core.circuitandmicroquantum.core.gradientwhich previously suppressedassignment,arg-type,misc,union-attrandindexerror codes.Removed global
ignore_missing_imports = true.Added
strict = truein[tool.mypy].Added scoped overrides only for genuinely-optional external packages (
cupy,scipy).Removed all 46 remaining
# type: ignorecomments inside the SDK by fixing the underlying strict-mode issues (narrowing helpers, asserted invariants, generic key typings and explicitcastat validated API boundaries). The conformance suite permanently asserts this invariant.
Changes¶
- pyproject.toml:
[tool.mypy]: enabledstrict = true, removedignore_missing_imports.Removed module overrides for
microquantum.core.circuitandmicroquantum.core.gradient.Added
[[tool.mypy.overrides]]forcupyandscipymodules.
- core/circuit.py:
Added
_narrow_parameterized()and_narrow_concrete()helper functions for safe type narrowing of_GateInstructionunion.Updated all 9 gate-instruction loop sites to use the new narrowing helpers.
Changed
from_ir()signature fromobjecttoIRCircuit.Added explicit
complexangle rejection (Type-safe path).
- core/gradient.py:
Updated
_find_occurrences()and_build_shifted_circuit()to use_narrow_parameterized().
- core/dynamic.py:
Widened
_opstype from baretupletotuple[Any, ...].Added explicit
complexangle rejection inrx/ry/rz.
- ir/builder.py:
Typed
_OP_FACTORIESasdict[str, Callable[..., Operator]]instead ofdict[str, object].
- backends/executor.py:
Used
_narrow_concrete()for loop narrowing.Added
assert self._noise_model is not Noneguard.
- Type-ignore elimination (18 files):
Reused the
_narrow_concrete()helper at every remaining gate loop:mitigation/zne.py,qml/kernels.py,qml/classifier.py,algorithms/amplitude_estimation.py.Bound
dict[Parameter, float]mappings explicitly viacastat the validatedbind_parameters/gradientboundaries:algorithms/vqe.py,algorithms/vqd.py,algorithms/adapt_vqe.py.algorithms/qaoa.py: narrowed the cost Hamiltonian withisinstancebefore dispatching to the generic/legacy ansatz builders.algorithms/base.py:castfor thejson_safereturn.algorithms/quantum_walk.py,core/measurement.py: useddict.__getitem__as the deterministicmaxkey.core/tensor.py: filtered the homogenous argument tuple byisinstancebefore dispatch.core/visualization.py: unpacked the optional column entry behind an explicitis not Nonecheck.analysis/state.py:assertthe density/statevector invariant that the constructor already enforces.backends/array_backend.py:castthe decomposed-tuple returns.backends/tensor_network.py:assertthe non-leaf children invariant in_lca/_contract/_leaf_order.Added missing generic type arguments and return annotations as required.
Verification¶
uv run mypy src/microquantum/: Success: no issues found (127 files)uv run ruff check src/microquantum/: All checks passeduv run pytest tests/ -q: 2514 passed (2511 prior + 3 new conformance tests)