Skip to content

Conversation

@kartikeyg0104
Copy link

@kartikeyg0104 kartikeyg0104 commented Nov 25, 2025

Overview

This PR adds comprehensive type annotations to all three backend modules, improving IDE support and enabling static type checking.
closes #643

What's Changed

  • Added type annotations to all functions in qumat/qiskit_backend.py
  • Added type annotations to all functions in qumat/cirq_backend.py
  • Added type annotations to all functions in qumat/amazon_braket_backend.py
  • Added necessary imports (typing.Any, numpy)
  • Used modern union syntax for flexible types (e.g., LocalSimulator | AwsDevice)

Why This Change

The backend modules lacked type hints, making it harder for developers to:

  • Get proper IDE autocomplete and IntelliSense
  • Catch type-related bugs during development
  • Understand function signatures at a glance

This change improves developer experience without altering any functionality.

Benefits

  • ✅ Better IDE autocomplete and IntelliSense support
  • ✅ Enable static type checking with mypy
  • ✅ Improved code documentation through types
  • ✅ Easier to catch type-related bugs early

Testing

  • ✅ All existing tests pass (no functionality changes)
  • ✅ Type annotations are consistent across all backends
  • ✅ No runtime behavior changes

- Add type annotations to all functions in qiskit_backend.py
- Add type annotations to all functions in cirq_backend.py
- Add type annotations to all functions in amazon_braket_backend.py
- Import typing.Any and numpy for proper type definitions
- Use union types for flexible return types (e.g., LocalSimulator | AwsDevice)
- Improve IDE support and enable static type checking

This change is purely additive - no functionality is altered, only type information is added to improve code maintainability and developer experience.

Closes #[issue-number]
Copy link
Member

@guan404ming guan404ming left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, overall looks nice. Could you also add some tests for type check?

@kartikeyg0104
Copy link
Author

kartikeyg0104 commented Nov 25, 2025

Thanks for your contribution, overall looks nice. Could you also add some tests for type check?

Yaa sure sir I had worked on it just pushing the changes. Thanks! for you suggestion.

- Add mypy as dev dependency with strict configuration
- Create test_type_checking.py with 6 comprehensive tests
  - Validates type hints in all backend modules
  - Ensures modern union syntax (int | None) works
  - Verifies no type errors are suppressed
- Fix type checking issues in qiskit_backend.py and amazon_braket_backend.py
  - Add explicit type casts for library return values
- Add dedicated type checking step to CI workflow
- All 297 tests pass (291 existing + 6 new)
- mypy validation: Success on all 5 source files
"cirq>=1.5.0,<1.6.0",
"amazon-braket-sdk>=1.102.6,<2.0",
"sympy>=1.14.0,<2.0",
"flask (>=3.1.2,<4.0.0)",
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this?

python_functions = "test_*"
addopts = ["-v", "--tb=short"]

[tool.mypy]
Copy link
Member

@guan404ming guan404ming Nov 26, 2025

Choose a reason for hiding this comment

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

Could you help explain why for these changes, thanks!

@guan404ming guan404ming added this to QDP Nov 28, 2025
@github-project-automation github-project-automation bot moved this to Backlog in QDP Nov 28, 2025
@guan404ming guan404ming removed this from QDP Nov 28, 2025
Copy link
Contributor

@ryankert01 ryankert01 left a comment

Choose a reason for hiding this comment

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

please make sure it pass the pre commit test!

@rawkintrevo
Copy link
Contributor

Sorry I'm late to the party - same comment as @guan404ming and @ryankert01


def execute_circuit(circuit, backend, backend_config):
def execute_circuit(
circuit: qiskit.QuantumCircuit, backend: Any, backend_config: dict[str, Any]

Choose a reason for hiding this comment

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

Suggested change
circuit: qiskit.QuantumCircuit, backend: Any, backend_config: dict[str, Any]
circuit: qiskit.QuantumCircuit, backend: qiskit.providers.backend.Backend, backend_config: dict[str, Any]

Not quite sure what exact type should be here, but better to avoid Any. WDYT?

no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
strict_equality = true

Choose a reason for hiding this comment

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

While we are here, maybe we can also add things like

warn_unreachable = true
strict_optional = true

to detect dead code and check if we miss Optional for args that can take None

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Backend modules lack type hints affecting IDE support and type safety

5 participants