Skip to content

Commit

Permalink
Update PhaseGate.control(n) to return MCPhaseGate (#4994)
Browse files Browse the repository at this point in the history
* Fix PhaseGate.control to return an MCPhaseGate if multiple controls.

* Update test/python/circuit/test_controlled_gate.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>
(cherry picked from commit 81e73da)
  • Loading branch information
kdk authored and mergify-bot committed Aug 31, 2020
1 parent bfd757c commit 084d4f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions qiskit/circuit/library/standard_gates/p.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ def control(self, num_ctrl_qubits=1, label=None, ctrl_state=None):
if num_ctrl_qubits == 1:
gate = CPhaseGate(self.params[0], label=label, ctrl_state=ctrl_state)
elif ctrl_state is None and num_ctrl_qubits > 1:
from .u1 import MCU1Gate
gate = MCU1Gate(self.params[0], num_ctrl_qubits, label=label)
gate = MCPhaseGate(self.params[0], num_ctrl_qubits, label=label)
else:
return super().control(num_ctrl_qubits=num_ctrl_qubits, label=label,
ctrl_state=ctrl_state)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
fixes:
- |
Previously, when creating a multiply controlled phase gate via
``PhaseGate.control``, an ``MCU1Gate`` gate had been returned. This has been
had corrected so that an ``MCPhaseGate`` is returned.
- |
Previously, attempting to decompose a circuit containing an
``MCPhaseGate`` would raise an error due to an inconsistency in the
definition of the ``MCPhaseGate``. This has been corrected.
5 changes: 5 additions & 0 deletions test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def test_controlled_phase(self):
theta = 0.5
self.assertEqual(PhaseGate(theta).control(), CPhaseGate(theta))

def test_double_controlled_phase(self):
"""Test the creation of a controlled phase gate."""
theta = 0.5
self.assertEqual(PhaseGate(theta).control(2), MCPhaseGate(theta, 2))

def test_controlled_u1(self):
"""Test the creation of a controlled U1 gate."""
theta = 0.5
Expand Down

0 comments on commit 084d4f4

Please sign in to comment.