forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type hints to gates and QuantumCircuit (Qiskit#6831)
* Move QuantumCircuit.measure into QuantumCircuit * Add type hints to QuantumCircuit This adds full type hints to all public function entry points in QuantumCircuit. This will not cause quantumcircuit.py to pass a mypy check yet; there are various idioms used within the file which are not statically type-safe (nor, in some cases, dynamically type safe in the sense that we sometimes rely on mismatched types to throw exceptions). These include anything which takes the `inplace` argument, since `inplace=True` versions do not return, which influences the out types to Optional["QuantumCircuit"] This then means that methods using these functions (e.g. `QuantumCircuit.__add__`) become unsafe; even though they use the default `inplace=False`, subclasses could override this while still maintaining type safety, and so the operation is not safe. This patch makes no attempt to modify the behaviour of these non-type-safe functions, only to classify what the current types are. * Add type hints and label to all standard gates This completes the standard-library gate documentation overhaul tracked by Qiskit#3705, and mostly done in Qiskit#4017, by adding type hints to the initializers. It also adds the missing `label` option to the iSWAP, R, RXX, RYY, RZX and RZZ gates, to bring them up to parity with the other gates, tracked in Qiskit#6780. * Add parameters to QuantumCircuit gate docstrings This only adds short documentation to the docstrings of the gate methods (for example `QuantumCircuit.x`) about the parameters and the return values. It does not currently import the matrix representations into the docstrings themselves, because the gate classes include those. The expectation is that you would see the docstring when running interactively, and even in Jupyter, this typically does not include displaying maths. The matrix form is more useful when looking at the online Sphinx documentation, where the cross-reference gate link will work more easily. * Add release note * Document type aliases in comments, not __doc__ Python 3.6 doesn't allow assigning to the __doc__ field of the `typing` types, so as long as we support it, we can't do that. * Include reset in QuantumCircuit The previous commit stopped `QuantumCircuit.measure` from being monkey-patched in by `qiskit/circuit/measure.py`, but the similar `QuantumCircuit.reset` operation was overlooked. This adds it in for consistency.
- Loading branch information
1 parent
23774bc
commit 2cd42b4
Showing
31 changed files
with
1,662 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.