Skip to content

Commit

Permalink
Fix import of deprecated gates from qiskit.extensions (#4366)
Browse files Browse the repository at this point in the history
The monkeypatching PR didn't allow to import the deprecated gate names (such as Cu1Gate) to be imported from qiskit.extensions. This is fixed and a test added.

(cherry picked from commit 61b5e24)
  • Loading branch information
Cryoris authored and mergify-bot committed Apr 30, 2020
1 parent afe78a9 commit fcd0145
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion qiskit/circuit/library/standard_gates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,17 @@
from .y import YGate, CYGate
from .z import ZGate, CZGate

from .boolean_logical_gates import logical_and, logical_or
from .multi_control_rotation_gates import mcrx, mcry, mcrz

# deprecated gates
from .boolean_logical_gates import logical_and, logical_or
from .u1 import Cu1Gate
from .u3 import Cu3Gate
from .x import CnotGate, ToffoliGate
from .swap import FredkinGate
from .i import IdGate
from .rx import CrxGate
from .ry import CryGate
from .rz import CrzGate
from .y import CyGate
from .z import CzGate
15 changes: 14 additions & 1 deletion test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,8 @@ def test_controlled_standard_gates(self, num_ctrl_qubits, gate_class):
class TestDeprecatedGates(QiskitTestCase):
"""Test controlled of deprecated gates."""

import qiskit.extensions as ext

import qiskit.extensions.standard.i as i
import qiskit.extensions.standard.rx as rx
import qiskit.extensions.standard.ry as ry
Expand Down Expand Up @@ -938,7 +940,18 @@ class TestDeprecatedGates(QiskitTestCase):
(x.CXGate, x.CnotGate, []),
(x.CCXGate, x.ToffoliGate, []),
(y.CYGate, y.CyGate, []),
(z.CZGate, z.CzGate, []))
(z.CZGate, z.CzGate, []),
(i.IGate, ext.IdGate, []),
(rx.CRXGate, ext.CrxGate, [0.1]),
(ry.CRYGate, ext.CryGate, [0.1]),
(rz.CRZGate, ext.CrzGate, [0.1]),
(swap.CSwapGate, ext.FredkinGate, []),
(u1.CU1Gate, ext.Cu1Gate, [0.1]),
(u3.CU3Gate, ext.Cu3Gate, [0.1, 0.2, 0.3]),
(x.CXGate, ext.CnotGate, []),
(x.CCXGate, ext.ToffoliGate, []),
(y.CYGate, ext.CyGate, []),
(z.CZGate, ext.CzGate, []))
@unpack
def test_deprecated_gates(self, new, old, params):
"""Test types of the deprecated gate classes."""
Expand Down

0 comments on commit fcd0145

Please sign in to comment.