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

Gate documentation overhaul #4017

Merged
merged 40 commits into from
Mar 26, 2020
Merged

Conversation

ajavadia
Copy link
Member

@ajavadia ajavadia commented Mar 25, 2020

As part of making the gates into a circuit library...

Adding docstrings for the standard gates including matrix definition, some explanation of what they are, and what they look like in a circuit.

With this I remove the jupyter execute blocks in the documentation that were slowing things down (fixes #3906 )

I also added a RZX gate.

I mostly just changed docstrings so hopefully it won't clash with #3947 or what @Cryoris is doing with gates location.

I did have to change the matrix definition of RYY because the phase factor should not be part of the canonical matrix. For consistency all Pauli rotations are exp(-i.(\theta/2).pauli). And the decomposition is phase correct as well, so no extra phase is required. Only problem is our RZ to U1 unrolling loses the phase, which is something we should fix separately.

@ajavadia ajavadia added the documentation Something is not clear or an error documentation label Mar 25, 2020
@@ -0,0 +1,7 @@
---
prelude: >
Copy link
Member

Choose a reason for hiding this comment

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

This should be a new feature section or we should save it for the release. The prelude section is special in that we can only have one for a release since it doesn't really combine multiple elements well since it's a free form paragraph section and not a list. Typically before a release I've been writing a small blurb summarizing the big changes for the release. This release is turning out to be quite large (not by patch count but because of several substantial changes) so we'll probably have to collaborate on a good prelude for the release.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah i put it at the top here so we don't forget to write a prelude about documentation that came out of the docathon. i figured we can tweak it towards the release. but documentation doesn't quite fit a "feature" in my mind

@ajavadia ajavadia force-pushed the gate-documentation branch 3 times, most recently from da5478e to 0ea86c1 Compare March 26, 2020 03:30
@ajavadia ajavadia force-pushed the gate-documentation branch from 0ea86c1 to b05187d Compare March 26, 2020 05:59
@Cryoris
Copy link
Contributor

Cryoris commented Mar 26, 2020

This creates merge conflicts in all the standard gate files in qiskit/extensions/standard since I'm working on a PR to move them to qiskit/circuit/gates. But since you only changes the docstrings this is fixable 👍

Cryoris and others added 17 commits March 26, 2020 18:18
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

That's a very much needed upgrade of the documentation and probably helps many people that are confused with different bit orderings! Also we don't have to go look for the gate definitions elsewhere anymore if we need a reminder on the matrix repr 👍

Some brackets might not be perfect, since fractions are enclosed without \left \right but we can do a second run of small improvements on the docs later.

@kdk kdk added the automerge label Mar 26, 2020
@mergify mergify bot merged commit 691ffdf into Qiskit:master Mar 26, 2020
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* docs for x.py

* update rzz docstring

* dcx docs

* add RZXGate

* polish doc for x,y,z,rzz,rzx,iswap,dcx

* i gate

* u1 and rz docs

* u2 and u3

* rx,ry,rz

* fix typos

* cswap

* s and t

* tweak

* lint

* release notes

* iswap def in terms of xx+yy

* lint

* correct phase in RY definition and add reference implementation for iswap

* change u1->rz in RZZ definition

* Update qiskit/extensions/standard/rzx.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/rz.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update rz.py

* Update qiskit/extensions/standard/rxx.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/iswap.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/ry.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/rzx.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/rzx.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/u1.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/u3.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/x.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/x.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/x.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/rzz.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/x.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/y.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/y.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/z.py

Co-Authored-By: Julien Gacon <[email protected]>

* Update qiskit/extensions/standard/y.py

Co-Authored-By: Julien Gacon <[email protected]>

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Jul 29, 2021
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.
mergify bot pushed a commit that referenced this pull request Aug 13, 2021
* 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 #3705, and mostly done in #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 #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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Something is not clear or an error documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chained execution of circuit methods in circuit library objects
4 participants