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

Update PhaseGate.control(n) to return MCPhaseGate #4994

Merged
merged 3 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -96,8 +96,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 @@ -72,6 +72,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 U1 gate."""
Cryoris marked this conversation as resolved.
Show resolved Hide resolved
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