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

Allow mcrx, mcry and mcrz gate methods to accept angles of ParameterValueType #13507

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 17 additions & 21 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
Any,
DefaultDict,
Literal,
List,
overload,
)
from math import pi
Expand Down Expand Up @@ -4688,19 +4687,18 @@ def mcp(
def mcrx(
self,
theta: ParameterValueType,
q_controls: Union[QuantumRegister, List[Qubit]],
q_controls: QuantumRegister | list[Qubit],
q_target: Qubit,
use_basis_gates: bool = False,
):
"""
Apply Multiple-Controlled X rotation gate

Args:
self (QuantumCircuit): The QuantumCircuit object to apply the mcrx gate on.
theta (float): angle theta
q_controls (QuantumRegister or list(Qubit)): The list of control qubits
q_target (Qubit): The target qubit
use_basis_gates (bool): use p, u, cx
theta: angle theta
q_controls: The list of control qubits
q_target: The target qubit
use_basis_gates: use p, u, cx
"""
# pylint: disable=cyclic-import
from .library.standard_gates.rx import RXGate
Expand Down Expand Up @@ -4751,7 +4749,7 @@ def mcrx(
def mcry(
self,
theta: ParameterValueType,
q_controls: Union[QuantumRegister, List[Qubit]],
q_controls: QuantumRegister | list[Qubit],
q_target: Qubit,
q_ancillae: Optional[Union[QuantumRegister, Tuple[QuantumRegister, int]]] = None,
mode: Optional[str] = None,
ShellyGarion marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -4761,13 +4759,12 @@ def mcry(
Apply Multiple-Controlled Y rotation gate

Args:
self (QuantumCircuit): The QuantumCircuit object to apply the mcry gate on.
theta (float): angle theta
q_controls (list(Qubit)): The list of control qubits
q_target (Qubit): The target qubit
q_ancillae (QuantumRegister or tuple(QuantumRegister, int)): The list of ancillary qubits.
mode (string): The implementation mode to use
use_basis_gates (bool): use p, u, cx
theta: angle theta
q_controls: The list of control qubits
q_target: The target qubit
q_ancillae: The list of ancillary qubits.
mode: The implementation mode to use
use_basis_gates: use p, u, cx

"""
# pylint: disable=cyclic-import
Expand Down Expand Up @@ -4838,19 +4835,18 @@ def mcry(
def mcrz(
self,
lam: ParameterValueType,
q_controls: Union[QuantumRegister, List[Qubit]],
q_controls: QuantumRegister | list[Qubit],
q_target: Qubit,
use_basis_gates: bool = False,
):
"""
Apply Multiple-Controlled Z rotation gate

Args:
self (QuantumCircuit): The QuantumCircuit object to apply the mcrz gate on.
lam (float): angle lambda
q_controls (list(Qubit)): The list of control qubits
q_target (Qubit): The target qubit
use_basis_gates (bool): use p, u, cx
lam: angle lambda
q_controls: The list of control qubits
q_target: The target qubit
use_basis_gates: use p, u, cx
"""
# pylint: disable=cyclic-import
from .library.standard_gates.rz import CRZGate, RZGate
Expand Down
3 changes: 2 additions & 1 deletion qiskit/synthesis/multi_controlled/mcx_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def synth_mcx_n_dirty_i15(
`arXiv:1501.06911 <http://arxiv.org/abs/1501.06911>`_
"""

num_qubits = 2 * num_ctrl_qubits - 1
if num_ctrl_qubits == 1:
num_qubits = 2
else:
num_qubits = 2 * num_ctrl_qubits - 1
q = QuantumRegister(num_qubits, name="q")
qc = QuantumCircuit(q, name="mcx_vchain")
q_controls = q[:num_ctrl_qubits]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,23 @@ def _mcsu2_real_diagonal(
if not is_secondary_diag_real:
circuit.h(target)

mcx_1 = synth_mcx_n_dirty_i15(num_ctrl_qubits=k_1).to_gate()
circuit.append(mcx_1, controls[:k_1] + [target] + controls[k_1 : 2 * k_1 - 2])
mcx_1 = synth_mcx_n_dirty_i15(num_ctrl_qubits=k_1)
circuit.compose(mcx_1, controls[:k_1] + [target] + controls[k_1 : 2 * k_1 - 2], inplace=True)
circuit.append(s_gate, [target])

# TODO: improve CX count by using action_only=True (based on #9687)
mcx_2 = synth_mcx_n_dirty_i15(num_ctrl_qubits=k_2).to_gate()
circuit.append(mcx_2.inverse(), controls[k_1:] + [target] + controls[k_1 - k_2 + 2 : k_1])
circuit.compose(
mcx_2.inverse(), controls[k_1:] + [target] + controls[k_1 - k_2 + 2 : k_1], inplace=True
)
circuit.append(s_gate.inverse(), [target])

mcx_3 = synth_mcx_n_dirty_i15(num_ctrl_qubits=k_1).to_gate()
circuit.append(mcx_3, controls[:k_1] + [target] + controls[k_1 : 2 * k_1 - 2])
circuit.compose(mcx_3, controls[:k_1] + [target] + controls[k_1 : 2 * k_1 - 2], inplace=True)
circuit.append(s_gate, [target])

mcx_4 = synth_mcx_n_dirty_i15(num_ctrl_qubits=k_2).to_gate()
circuit.append(mcx_4, controls[k_1:] + [target] + controls[k_1 - k_2 + 2 : k_1])
circuit.compose(mcx_4, controls[k_1:] + [target] + controls[k_1 - k_2 + 2 : k_1], inplace=True)
circuit.append(s_gate.inverse(), [target])

if not is_secondary_diag_real:
Expand Down
Loading