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
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions qiskit/circuit/library/standard_gates/u1.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ class U1Gate(Gate):
This is a diagonal gate. It can be implemented virtually in hardware
via framechanges (i.e. at zero error and duration).

.. warning::

This gate is deprecated. Instead, the following replacements should be used

.. math::

U1(\lambda) = P(\lambda)= U(0,0,\lambda)

.. code-block:: python

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




**Circuit symbol:**

.. parsed-literal::
Expand Down
29 changes: 27 additions & 2 deletions qiskit/circuit/library/standard_gates/u2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ class U2Gate(Gate):

Implemented using one X90 pulse on IBM Quantum systems:

.. math::
U2(\phi, \lambda) = RZ(\phi).RY(\frac{\pi}{2}).RZ(\lambda)
.. warning::

This gate is deprecated. Instead, the following replacements should be used

.. math::

U2(\phi, \lambda) = U\left(\frac{\pi}{2}, \phi, \lambda\right)

.. code-block:: python

circuit = QuantumCircuit(1)
circuit.u(pi/2, phi, lambda)



**Circuit symbol:**

Expand All @@ -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)$

= e^{- i\frac{\pi}{4}} P\left(\frac{\pi}{2} + \phi\right)
\sqrt{X} P\left(\lambda- \frac{\pi}{2}\right)

.. math::

U2(0, \pi) = H

.. math::

U2(0, 0) = RY(\pi/2)

.. math::

U2(-\pi/2, \pi/2) = RX(\pi/2)

.. seealso::

:class:`~qiskit.circuit.library.standard_gates.U3Gate`:
Expand Down
18 changes: 18 additions & 0 deletions qiskit/circuit/library/standard_gates/u3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
class U3Gate(Gate):
r"""Generic single-qubit rotation gate with 3 Euler angles.

.. warning::

This gate is deprecated. Instead, the following replacements should be used

.. math::

U3(\theta, \phi, \lambda) = U(\theta, \phi, \lambda)

.. codeblock:: python
Cryoris marked this conversation as resolved.
Show resolved Hide resolved

circuit = QuantumCircuit(1)
circuit.u(theta, phi, lambda)

**Circuit symbol:**

.. parsed-literal::
Expand Down Expand Up @@ -52,6 +65,11 @@ class U3Gate(Gate):

**Examples:**

.. math::

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!


.. math::

U3\left(\theta, -\frac{\pi}{2}, \frac{\pi}{2}\right) = RX(\theta)
Expand Down