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 mypy errors (quantum_info) #8257

Merged
merged 2 commits into from
Feb 7, 2023
Merged

Fix mypy errors (quantum_info) #8257

merged 2 commits into from
Feb 7, 2023

Conversation

Randl
Copy link
Contributor

@Randl Randl commented Jun 28, 2022

Summary

Following discussion, I'm splitting #8187 by module.

Details and comments

There are 8 errors left:

qiskit/quantum_info/synthesis/two_qubit_decompose.py:580: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
qiskit/quantum_info/synthesis/two_qubit_decompose.py:580: error: Argument 1 to "Gate" has incompatible type "float"; expected "str"  [arg-type]
qiskit/quantum_info/synthesis/two_qubit_decompose.py:583: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
qiskit/quantum_info/synthesis/two_qubit_decompose.py:583: error: Argument 1 to "Gate" has incompatible type "float"; expected "str"  [arg-type]
qiskit/quantum_info/synthesis/two_qubit_decompose.py:590: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
qiskit/quantum_info/synthesis/two_qubit_decompose.py:590: error: Argument 1 to "Gate" has incompatible type "float"; expected "str"  [arg-type]
qiskit/quantum_info/synthesis/two_qubit_decompose.py:665: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
qiskit/quantum_info/synthesis/two_qubit_decompose.py:665: error: Argument 1 to "Gate" has incompatible type "float"; expected "str"  [arg-type]

All are related to the fact that gates, even though inheriting from Gate have different constructor signature. Not sure what the proper fix is.
The ignores are related to python/mypy#1362

@Randl Randl requested review from a team and ikkoham as code owners June 28, 2022 14:07
@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:

@javabster javabster added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jun 28, 2022
@kevinsung
Copy link
Contributor

The ignores are related to python/mypy#1362

That issue is closed. Do you still get an error if you run with the latest version of mypy?

@coveralls
Copy link

coveralls commented Feb 7, 2023

Pull Request Test Coverage Report for Build 4117876587

  • 5 of 5 (100.0%) changed or added relevant lines in 2 files are covered.
  • 5 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.002%) to 85.277%

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 93.97%
qiskit/pulse/library/waveform.py 3 91.67%
Totals Coverage Status
Change from base Build 4114140947: -0.002%
Covered Lines: 67251
Relevant Lines: 78862

💛 - Coveralls

@Randl
Copy link
Contributor Author

Randl commented Feb 7, 2023

The code related to this issue is removed anyway. I've rebased on current master and updated correspondingly

Copy link
Contributor

@kevinsung kevinsung left a comment

Choose a reason for hiding this comment

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

Thanks! Are there any more mypy issues in this module? If so, could you report the output?

@Randl
Copy link
Contributor Author

Randl commented Feb 7, 2023

There are a few left:

out.txt:qiskit/quantum_info/synthesis/two_qubit_decompose.py:585: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
out.txt:qiskit/quantum_info/synthesis/two_qubit_decompose.py:588: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
out.txt:qiskit/quantum_info/synthesis/two_qubit_decompose.py:595: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
out.txt:qiskit/quantum_info/synthesis/two_qubit_decompose.py:670: error: Missing positional arguments "num_qubits", "params" in call to "Gate"  [call-arg]
out.txt:qiskit/quantum_info/synthesis/two_qubit_decompose.py:670: error: Argument 1 to "Gate" has incompatible type "float"; expected "str"  [arg-type]
out.txt:qiskit/quantum_info/synthesis/xx_decompose/decomposer.py:99: error: Item "QuantumCircuit" of "Union[List[Any], QuantumCircuit]" has no attribute "__iter__" (not iterable)  [union-attr]

All except one are since Gate overloads have different constructor parameters. The last one I'm unsure about.

@kevinsung
Copy link
Contributor

The last one seems like it's related to one of your changes, right? Could you please post the mypy outputs both before and after the changes you made?

@Randl
Copy link
Contributor Author

Randl commented Feb 7, 2023

Ok, this is a consequence of the fact that QuantumCircuit implements getitem but not iter: python/mypy#9737

Not sure what is the appropriate fix? Maybe just adding iter function

@@ -93,7 +93,9 @@ def __init__(
self.basis_fidelity = basis_fidelity

# expose one of the basis gates so others can know what this decomposer targets
embodiment_circuit = next(iter(self.embodiments.items()), ([], []))[1]
embodiment_circuit: list | QuantumCircuit = next(iter(self.embodiments.items()), ([], []))[
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be CircuitInstruction instead of QuantumCircuit?

Copy link
Contributor Author

@Randl Randl Feb 7, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the code, it seems that

next(iter(self.embodiments.items()), ([], []))

should be a QuantumCircuit. But then embodiment_circuit is actually obtained by indexing into this object:

next(iter(self.embodiments.items()), ([], []))[1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

self.embodiments is a dictionary, so self.embodiments.items() contains tuples, and thus indexing will return the second element of first tuple, i.e., circuit

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok. It seems this line can be significantly simplified by calling self.embodiments.values() instead of items. You can go ahead and make that change if you like, but it's not necessary.

Copy link
Contributor

@kevinsung kevinsung left a comment

Choose a reason for hiding this comment

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

Thanks! If you decide to update your other mypy PRs, please include the mypy output both before and after your changes. That would make the review easier.

@kdk kdk added automerge Changelog: None Do not include in changelog labels Feb 7, 2023
@kdk kdk added this to the 0.24.0 milestone Feb 7, 2023
@mergify mergify bot merged commit 202ec09 into Qiskit:main Feb 7, 2023
@Randl
Copy link
Contributor Author

Randl commented Feb 8, 2023

@kevinsung Thanks! I've added the mypy output after changes, but keeping PRs up-to-date is a bit annoying, so I'm waiting for some of the maintainers to engage on specific PR before updating it. Feel free to ping me if you want me to update some specific ones.

pranay1990 pushed a commit to pranay1990/qiskit-terra that referenced this pull request Feb 9, 2023
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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

6 participants