Skip to content

Commit

Permalink
Renaming MCR to MPR
Browse files Browse the repository at this point in the history
  • Loading branch information
jkalloor3 committed Sep 27, 2024
1 parent f61b081 commit 779c8ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
16 changes: 8 additions & 8 deletions bqskit/passes/synthesis/bzxz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from bqskit.ir.gates.constant import HGate
from bqskit.ir.gates.constant import IdentityGate
from bqskit.ir.gates.constant import ZGate
from bqskit.ir.gates.parameterized.mcrz import MCRZGate
from bqskit.ir.gates.parameterized.mprz import MPRZGate
from bqskit.ir.location import CircuitLocation
from bqskit.ir.operation import Operation
from bqskit.passes.processing.extract_diagonal import ExtractDiagonalPass
Expand Down Expand Up @@ -232,7 +232,7 @@ def demultiplex(
most significant qubit.
We return the Unitary Matrices V and W and the parameters for the
corresponding MCRZ gate.
corresponding MPRZ gate.
"""
# U can be decomposed into U = (I otimes V )(D otimes D†)(I otimes W )

Expand All @@ -245,7 +245,7 @@ def demultiplex(
# We can then multiply to solve for W
W = D @ V.conj().T @ U_2

# We can use d to find the parameters for the MCRZ gate.
# We can use d to find the parameters for the MPRZ gate.
# Note than because and Rz does exp(-i * theta / 2), we must
# multiply by -2.
d_params: list[float] = list(np.angle(d) * -2)
Expand Down Expand Up @@ -291,8 +291,8 @@ def zxz(orig_u: UnitaryMatrix) -> Circuit:
wc_gate, wc_params = QSDPass.create_unitary_gate(WC)
circ.append_gate(wc_gate, CircuitLocation(select_qubits), wc_params)

# Add decomposed MCRZ gate circuit.
# Since the MCRZ gate circuit sets the target qubit as qubit
# Add decomposed MPRZ gate circuit.
# Since the MPRZ gate circuit sets the target qubit as qubit
# num_qudits - 1, we must shift the qubits to the left
shifted_qubits = all_qubits[1:] + all_qubits[0:1]
circ.append_circuit(
Expand All @@ -313,9 +313,9 @@ def zxz(orig_u: UnitaryMatrix) -> Circuit:
)
circ.append_gate(HGate(), CircuitLocation((controlled_qubit,)))

# The central MCRZ_gate. We set the target to the controlled qubit,
# The central MPRZ_gate. We set the target to the controlled qubit,
# so there is no need to shift
z_gate = MCRZGate(len(all_qubits), 0)
z_gate = MPRZGate(len(all_qubits), 0)
circ.append_gate(z_gate, CircuitLocation(all_qubits), BZ_params)

# Now add the decomposed B-tilde gates VB and a Hadamard
Expand All @@ -326,7 +326,7 @@ def zxz(orig_u: UnitaryMatrix) -> Circuit:
)
circ.append_gate(HGate(), CircuitLocation((controlled_qubit,)))

# Add the decomposed MCRZ gate circuit again on shifted qubits
# Add the decomposed MPRZ gate circuit again on shifted qubits
circ.append_circuit(
MGDPass.decompose_mpx_two_levels(
decompose_ry=False,
Expand Down
54 changes: 27 additions & 27 deletions bqskit/passes/synthesis/qsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from bqskit.ir.gates.parameterized import RYGate
from bqskit.ir.gates.parameterized import RZGate
from bqskit.ir.gates.parameterized import VariableUnitaryGate
from bqskit.ir.gates.parameterized.mcry import MCRYGate
from bqskit.ir.gates.parameterized.mcrz import MCRZGate
from bqskit.ir.gates.parameterized.mpry import MPRYGate
from bqskit.ir.gates.parameterized.mprz import MPRZGate
from bqskit.ir.operation import Operation
from bqskit.passes.processing import ScanningGateRemovalPass
from bqskit.passes.processing import TreeScanningGateRemovalPass
Expand Down Expand Up @@ -116,7 +116,7 @@ async def run(self, circuit: Circuit, data: PassData) -> None:

class MGDPass(BasePass):
"""
A pass performing one round of decomposition of the MCRY and MCRZ gates in a
A pass performing one round of decomposition of the MPRY and MPRZ gates in a
circuit.
References:
Expand All @@ -132,10 +132,10 @@ class MGDPass(BasePass):

def __init__(self, decompose_twice: bool = True) -> None:
"""
The MGDPass decomposes all MCRY and MCRZ gates in a circuit.
The MGDPass decomposes all MPRY and MPRZ gates in a circuit.
Args:
decompose_twice (bool): Whether to decompose the MCRZ gate twice.
decompose_twice (bool): Whether to decompose the MPRZ gate twice.
This will save 2 CNOT gates in the decomposition. If false,
the pass will only decompose one level. (Default: True)
"""
Expand All @@ -153,30 +153,30 @@ def decompose_mpx_one_level(
Decompose Multiplexed Gate one level.
Args:
params (RealVector): The parameters for the original MCRZ gate
num_qudits (int): The number of qudits in the MCRZ gate
params (RealVector): The parameters for the original MPRZ gate
num_qudits (int): The number of qudits in the MPRZ gate
reverse (bool): Whether to reverse the order of the gates (you can
decompose the gates in either order to get the same result)
drop_last_cnot (bool): Whether to drop the last CNOT gate. This
should be set if you are doing a 2 level decomposition to save 2
CNOT gates.
Returns:
Circuit: The circuit that decomposes the MCRZ gate
Circuit: The circuit that decomposes the MPRZ gate
"""

new_gate: MCRZGate | MCRYGate | RZGate | RYGate = RZGate()
new_gate: MPRZGate | MPRYGate | RZGate | RYGate = RZGate()
if decompose_ry:
new_gate = RYGate()

if (num_qudits >= 3):
if decompose_ry:
new_gate = MCRYGate(num_qudits - 1, num_qudits - 2)
new_gate = MPRYGate(num_qudits - 1, num_qudits - 2)
else:
# Remove 1 qubit, last qubit is controlled
new_gate = MCRZGate(num_qudits - 1, num_qudits - 2)
new_gate = MPRZGate(num_qudits - 1, num_qudits - 2)

left_params, right_params = MCRYGate.get_decomposition(params)
left_params, right_params = MPRYGate.get_decomposition(params)
circ = Circuit(num_qudits)
new_gate_location = list(range(1, num_qudits))
cx_location = (0, num_qudits - 1)
Expand Down Expand Up @@ -218,16 +218,16 @@ def decompose_mpx_two_levels(
https://arxiv.org/pdf/2403.13692v1.pdf.
Args:
decompose_ry (bool): Whether to decompose the MCRY gate
params (RealVector): The parameters for the original MCR gate
num_qudits (int): The number of qudits in the MCR gate
decompose_ry (bool): Whether to decompose the MPRY gate
params (RealVector): The parameters for the original MPR gate
num_qudits (int): The number of qudits in the MPR gate
reverse (bool): Whether to reverse the order of the gates (you can
decompose the gates in either order to get the same result)
drop_last_cnot (bool): Whether to drop the last CNOT gate (only
should be set to True if you are doing section 5.2 optimization)
Returns:
Circuit: The circuit that decomposes the MCR gate
Circuit: The circuit that decomposes the MPR gate
"""

if num_qudits <= 2:
Expand All @@ -239,10 +239,10 @@ def decompose_mpx_two_levels(
reverse,
)

# Get params for first decomposition of the MCRZ gate
left_params, right_params = MCRYGate.get_decomposition(params)
# Get params for first decomposition of the MPRZ gate
left_params, right_params = MPRYGate.get_decomposition(params)

# Decompose the MCRZ gate into 2 MCRZ gates, dropping the last CNOT
# Decompose the MPRZ gate into 2 MPRZ gates, dropping the last CNOT
# Also Reverse the circuit for the right side in order to do the
# optimization in section 5.2
circ_left = MGDPass.decompose_mpx_one_level(
Expand All @@ -262,7 +262,7 @@ def decompose_mpx_two_levels(
)

# Now, construct the circuit.
# This will generate the original MCRZ gate with the target qubit
# This will generate the original MPRZ gate with the target qubit
# set as qubit num_qudits - 1
circ = Circuit(num_qudits)
cx_location_big = (0, num_qudits - 1)
Expand Down Expand Up @@ -290,15 +290,15 @@ def decompose_mpx_two_levels(
return circ

async def run(self, circuit: Circuit, data: PassData) -> None:
"""Decompose all MCRY and MCRZ gates in the circuit one level."""
"""Decompose all MPRY and MPRZ gates in the circuit one level."""
ops: list[Operation] = []
pts: list[CircuitPoint] = []
locations: list[CircuitLocation] = []
all_ops = list(circuit.operations_with_cycles(reverse=True))

# Gather all of the multiplexed operations
for cyc, op in all_ops:
if isinstance(op.gate, MCRYGate) or isinstance(op.gate, MCRZGate):
if isinstance(op.gate, MPRYGate) or isinstance(op.gate, MPRZGate):
ops.append(op)
pts.append(CircuitPoint((cyc, op.location[0])))
# Adjust location based on current target, move target to last
Expand All @@ -316,15 +316,15 @@ async def run(self, circuit: Circuit, data: PassData) -> None:
if self.decompose_twice:
circs = [
MGDPass.decompose_mpx_two_levels(
isinstance(op.gate, MCRYGate),
isinstance(op.gate, MPRYGate),
op.params,
op.num_qudits,
) for op in ops
]
else:
circs = [
MGDPass.decompose_mpx_one_level(
isinstance(op.gate, MCRYGate),
isinstance(op.gate, MPRYGate),
op.params,
op.num_qudits,
) for op in ops
Expand Down Expand Up @@ -438,7 +438,7 @@ def create_multiplexed_circ(

# Create Multi Controlled Z Gate
z_params: RealVector = np.array(-2 * np.angle(np.diag(D)).flatten())
z_gate = MCRZGate(len(all_qubits), u1.num_qudits)
z_gate = MPRZGate(len(all_qubits), u1.num_qudits)

# Create right gate
right_gate, right_params = QSDPass.create_unitary_gate(UnitaryMatrix(V))
Expand Down Expand Up @@ -482,7 +482,7 @@ def qsd(orig_u: UnitaryMatrix) -> Circuit:
assert (len(theta_y) == u.shape[0] / 2)

# Create the multiplexed circuit
# This generates 2 circuits that multipex U,V with an MCRY gate
# This generates 2 circuits that multipex U,V with an MPRY gate
controlled_qubit = u.num_qudits - 1
select_qubits = list(range(0, u.num_qudits - 1))
all_qubits = list(range(u.num_qudits))
Expand All @@ -498,7 +498,7 @@ def qsd(orig_u: UnitaryMatrix) -> Circuit:
],
select_qubits,
)
gate_2 = MCRYGate(u.num_qudits, controlled_qubit)
gate_2 = MPRYGate(u.num_qudits, controlled_qubit)

circ_1.append_gate(gate_2, CircuitLocation(all_qubits), 2 * theta_y)
circ_1.append_circuit(
Expand Down

0 comments on commit 779c8ab

Please sign in to comment.