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

Added U1, U2 and U3 deprecation warnings into Circuit Library #8391

Merged

Conversation

Guillermo-Mijares-Vilarino
Copy link
Contributor

Summary

Added a deprecation warning in the circuit library pages of U1Gate, U2Gate and U3Gate.

Details and comments

Along with the warning, I also included some equivalences, most of which are taken from the Summary of Quantum Operators tutorial from Qiskit-tutorials with some corrections.

@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:

@coveralls
Copy link

coveralls commented Jul 22, 2022

Pull Request Test Coverage Report for Build 2745528462

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.991%

Totals Coverage Status
Change from base Build 2743676755: 0.0%
Covered Lines: 55896
Relevant Lines: 66550

💛 - Coveralls

@Guillermo-Mijares-Vilarino Guillermo-Mijares-Vilarino marked this pull request as ready for review July 22, 2022 18:33
@Guillermo-Mijares-Vilarino Guillermo-Mijares-Vilarino requested a review from a team as a code owner July 22, 2022 18:33
@Guillermo-Mijares-Vilarino
Copy link
Contributor Author

I don't quite understand what's happening with doc generation. Now, when running tox -edocs, I get some errors that are not even related to what I'm changing like

Failed to import qiskit.tools.jupyter.
Possible hints:
* AttributeError: module 'qiskit._accelerate' has no attribute 'sabre_swap'
* KeyError: 'qiskit'
* AttributeError: partially initialized module 'qiskit' has no attribute '_accelerate' (most likely due to a circular import)
Failed to import qiskit.opflow.
Possible hints:
* KeyError: 'qiskit'
* AttributeError: partially initialized module 'qiskit' has no attribute '_accelerate' (most likely due to a circular import)

Maybe it has something to do with a new version of sphinx or something like that?

@Cryoris
Copy link
Contributor

Cryoris commented Jul 25, 2022

I believe that problem is fixed in #8392 and is not due to your changes 🙂

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.

The overall changes LGTM. I think it would be very nice if the warning directly shows how to replace the gate usage -- at least that's what I would be most interested in! The other relations with more gates might be better kept in the Examples section?

So it could look something like

.. warning:: 

    ... what you have ...

    .. code-block:: python

        circuit = QuantumCircuit(1)
        circuit.p(lambda, 0)  # or circuit.u(0, 0, lambda)

and then in the Examples section add the formulas you added?

@Guillermo-Mijares-Vilarino
Copy link
Contributor Author

While I was moving the formulas to Examples for the U2Gate I noticed that all the examples were just next to the other in the same line. There wasn't even a space between any of them. I cleaned that up.

Co-authored-by: Julien Gacon <gaconju@gmail.com>
@@ -49,11 +61,24 @@ class U2Gate(Gate):

**Examples:**

.. math::

U2(\phi,\lambda) = RZ(\phi) RY\left(\frac{\pi}{2}\right) RZ(\lambda)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this first equivalence with RZ RY RZ misses a global phase, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hadn't actually checked that one (trusted it to be correct but seems that was an error on my part 🤦‍♂️) but you are correct. $U2(\phi, \lambda) = e^{i\frac{\phi+\lambda}{2}}RZ(\phi)RY(\pi/2)RZ(\lambda)$

Comment on lines 70 to 71
U3(\theta, \phi, \lambda) = e^{i \frac{\pi + \theta}{2}} P(\phi + \pi) \sqrt{X}
P(\theta + \pi) \sqrt{X} P(\lambda)
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here the global phase doesn't seem to match (or maybe I have a typo!)

>>> decomp = np.exp(0.5j * (np.pi + th)) * np.dot(PhaseGate(phi + np.pi), np.dot(SXGate(), np.dot(PhaseGate(th + np.pi), np.dot(SXGate(), PhaseGate(lam)))))
>>> decomp
array([[-0.53350621-0.71685923j,  0.22160969+0.39034999j],
       [ 0.23851082-0.38025854j,  0.56442266-0.69277925j]])
>>> u3 = U3Gate(th, phi, lam).to_matrix()
>>> u3  # matrix doesn't match decomp
array([[ 0.89359724+0.j        , -0.44545363-0.05527232j],
       [ 0.1626514 +0.41836406j,  0.21878112+0.86640109j]])
>>> Operator(u3).equiv(decomp)  # but it is equivalent -- hence a global phase difference exists
True

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's because I forgot to add a minus sign to the global phase 😅. The correct phase is $e^{-i \frac{\theta + \pi}{2}}$ so the typo was mine!

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.

Thank you for fixing the relations!

@Cryoris Cryoris added the Changelog: None Do not include in changelog label Jul 26, 2022
@mergify mergify bot merged commit f8f638a into Qiskit:main Jul 27, 2022
@Guillermo-Mijares-Vilarino Guillermo-Mijares-Vilarino deleted the add-u1-u2-u3-deprecation branch July 27, 2022 10:46
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants