Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dagcircuit mypy errors #11469

Merged
merged 4 commits into from Mar 24, 2024
Merged

Fix dagcircuit mypy errors #11469

merged 4 commits into from Mar 24, 2024

Conversation

Randl
Copy link
Contributor

@Randl Randl commented Dec 31, 2023

Summary

Fixing mypy errors for dagcircuit module. Followup to #8252
See also #6905

Details and comments

diff of mypy output before and after PR
695d694
< qiskit/dagcircuit/dagnode.py:232: error: Incompatible types in assignment (expression has type "set[Any]", variable has type "list[Any]")  [assignment]
698a698,699
> qiskit/dagcircuit/dagnode.py:236: error: Incompatible types in assignment (expression has type "set[Any]", variable has type "list[Any]")  [assignment]
> qiskit/dagcircuit/dagnode.py:285: error: Property "name" defined in "Operation" is read-only  [misc]
1071,1076c1072,1076
< qiskit/dagcircuit/dagcircuit.py:111: error: Need type annotation for "_calibrations"  [var-annotated]
< qiskit/dagcircuit/dagcircuit.py:143: error: Incompatible types in assignment (expression has type "ParameterExpression", variable has type "int")  [assignment]
< qiskit/dagcircuit/dagcircuit.py:666: error: Incompatible types in assignment (expression has type "tuple[Any, ...]", variable has type "set[Any]")  [assignment]
< qiskit/dagcircuit/dagcircuit.py:711: error: Incompatible types in assignment (expression has type "tuple[Any, ...]", variable has type "set[Any]")  [assignment]
< qiskit/dagcircuit/dagcircuit.py:826: error: "DAGInNode" has no attribute "register"  [attr-defined]
< qiskit/dagcircuit/dagcircuit.py:1032: error: Unsupported operand types for + ("list[Qubit]" and "list[Clbit]")  [operator]
---
> qiskit/dagcircuit/dagcircuit.py:677: error: Incompatible types in assignment (expression has type "tuple[Clbit, ...]", variable has type "set[Any | Clbit]")  [assignment]
> qiskit/dagcircuit/dagcircuit.py:729: error: Incompatible types in assignment (expression has type "tuple[Clbit, ...]", variable has type "set[Any | Clbit]")  [assignment]
> qiskit/dagcircuit/dagcircuit.py:844: error: "DAGInNode" has no attribute "register"  [attr-defined]
> qiskit/dagcircuit/dagcircuit.py:852: error: "Operation" has no attribute "copy"  [attr-defined]
> qiskit/dagcircuit/dagcircuit.py:1050: error: Unsupported operand types for + ("list[Qubit]" and "list[Clbit]")  [operator]
1101,1102c1101,1110
< qiskit/dagcircuit/collect_blocks.py:297: error: Need type annotation for "bit_depths" (hint: "bit_depths: Dict[<type>, <type>] = ...")  [var-annotated]
< qiskit/dagcircuit/collect_blocks.py:298: error: Need type annotation for "layers" (hint: "layers: List[<type>] = ...")  [var-annotated]
---
> qiskit/dagcircuit/collect_blocks.py:90: error: Item "DAGDependency" of "DAGCircuit | DAGDependency" has no attribute "op_nodes"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:92: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "get_nodes"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:107: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "get_node"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:108: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "direct_successors"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:112: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "get_node"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:113: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "direct_predecessors"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:129: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "get_node"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:130: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "direct_predecessors"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:134: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "get_node"  [union-attr]
> qiskit/dagcircuit/collect_blocks.py:135: error: Item "DAGCircuit" of "DAGCircuit | DAGDependency" has no attribute "direct_successors"  [union-attr]
1199a1208,1209
> qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py:37: error: "Operation" has no attribute "is_parameterized"  [attr-defined]
> qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py:74: error: "Operation" has no attribute "inverse"  [attr-defined]
1220a1231,1232
> qiskit/transpiler/passes/scheduling/base_scheduler.py:267: error: "Operation" has no attribute "params"  [attr-defined]
> qiskit/transpiler/passes/scheduling/base_scheduler.py:270: error: "Operation" has no attribute "duration"  [attr-defined]
1221a1234,1237
> qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py:69: error: "Operation" has no attribute "params"  [attr-defined]
> qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py:73: error: "Operation" has no attribute "to_mutable"  [attr-defined]
> qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py:74: error: "Operation" has no attribute "duration"  [attr-defined]
> qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py:76: error: "Operation" has no attribute "duration"  [attr-defined]
1222a1239
> qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py:313: error: Argument 2 to "_make_op_layers" of "Commuting2qGateRouter" has incompatible type "Operation"; expected "Commuting2qBlock"  [arg-type]
1223a1241,1242
> qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py:362: error: Incompatible types in assignment (expression has type "Operation", target has type "Gate")  [assignment]
> qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py:379: error: "Operation" has no attribute "__iter__" (not iterable)  [attr-defined]
1259a1279
> qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py:246: error: Incompatible types in assignment (expression has type "float", variable has type "int")  [assignment]
1708,1709c1728,1729
< qiskit/dagcircuit/dagdependency.py:110: error: Need type annotation for "_calibrations"  [var-annotated]
< qiskit/dagcircuit/dagdependency.py:132: error: Incompatible types in assignment (expression has type "ParameterExpression", variable has type "int")  [assignment]
---
> qiskit/dagcircuit/dagdependency.py:467: error: Argument 3 to "commute" of "CommutationChecker" has incompatible type "tuple[Any, ...]"; expected "list[Any]"  [arg-type]
> qiskit/dagcircuit/dagdependency.py:470: error: Argument 6 to "commute" of "CommutationChecker" has incompatible type "tuple[Any, ...]"; expected "list[Any]"  [arg-type]
1778a1799,1800
> qiskit/transpiler/passes/optimization/optimize_1q_commutation.py:135: error: "Operation" has no attribute "base_class"  [attr-defined]
> qiskit/transpiler/passes/optimization/optimize_1q_commutation.py:137: error: "Operation" has no attribute "base_class"  [attr-defined]
1790a1813,1822
> qiskit/transpiler/passes/scheduling/alignments/align_measures.py:173: error: "Operation" has no attribute "condition_bits"  [attr-defined]
> qiskit/transpiler/passes/scheduling/alignments/align_measures.py:186: error: "Operation" has no attribute "duration"  [attr-defined]
> qiskit/transpiler/passes/scheduling/alignments/align_measures.py:194: error: "Operation" has no attribute "condition_bits"  [attr-defined]
> qiskit/transpiler/passes/scheduling/alignments/reschedule.py:136: error: "Operation" has no attribute "duration"  [attr-defined]
> qiskit/transpiler/passes/scheduling/alignments/reschedule.py:143: error: "Operation" has no attribute "condition_bits"  [attr-defined]
> qiskit/transpiler/passes/scheduling/alignments/reschedule.py:146: error: "Operation" has no attribute "condition_bits"  [attr-defined]
> qiskit/transpiler/passes/scheduling/alignments/reschedule.py:161: error: "Operation" has no attribute "condition_bits"  [attr-defined]
> qiskit/transpiler/passes/scheduling/alignments/reschedule.py:164: error: "Operation" has no attribute "condition_bits"  [attr-defined]
> qiskit/transpiler/passes/scheduling/padding/base_padding.py:115: error: "Operation" has no attribute "duration"  [attr-defined]
> qiskit/transpiler/passes/scheduling/padding/base_padding.py:141: error: Argument 3 to "_apply_scheduled_op" of "BasePadding" has incompatible type "Operation"; expected "Instruction"  [arg-type]
1792c1824
< Found 1491 errors in 284 files (checked 950 source files)
---
> Found 1523 errors in 287 files (checked 950 source files)

Note that some errors appeared due to added types mypy couldn't derive previously.

@Randl Randl requested a review from a team as a code owner December 31, 2023 14:30
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Dec 31, 2023
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Dec 31, 2023

Pull Request Test Coverage Report for Build 8387768993

Details

  • 66 of 68 (97.06%) changed or added relevant lines in 5 files are covered.
  • 16 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.004%) to 89.327%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/dagcircuit/dagdependency.py 17 18 94.44%
qiskit/dagcircuit/dagnode.py 7 8 87.5%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 93.13%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 8376619819: 0.004%
Covered Lines: 59808
Relevant Lines: 66954

💛 - Coveralls

Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

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

Thanks a lot !

@1ucian0 1ucian0 added this pull request to the merge queue Mar 24, 2024
Merged via the queue into Qiskit:main with commit b14f3b5 Mar 24, 2024
12 checks passed
@sbrandhsn sbrandhsn added the Changelog: None Do not include in changelog label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants