Skip to content

Commit

Permalink
tox
Browse files Browse the repository at this point in the history
  • Loading branch information
jkalloor3 committed Sep 27, 2024
1 parent 313d5ae commit f844bcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
11 changes: 4 additions & 7 deletions bqskit/passes/synthesis/bzxz.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
from bqskit.compiler.workflow import Workflow
from bqskit.ir.circuit import Circuit
from bqskit.ir.gates import CircuitGate
from bqskit.ir.gates.constant import CNOTGate
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 import RZGate
from bqskit.ir.gates.parameterized.mcry import MCRYGate
from bqskit.ir.gates.parameterized.mcrz import MCRZGate
from bqskit.ir.location import CircuitLocation
from bqskit.ir.operation import Operation
Expand Down Expand Up @@ -301,10 +298,10 @@ def zxz(orig_u: UnitaryMatrix) -> Circuit:
circ.append_circuit(
MGDPass.decompose_mpx_two_levels(
decompose_ry=False,
params=CZ_params,
params=CZ_params,
num_qudits=orig_u.num_qudits,
drop_last_cnot=True
),
drop_last_cnot=True,
),
shifted_qubits,
)

Expand Down Expand Up @@ -336,7 +333,7 @@ def zxz(orig_u: UnitaryMatrix) -> Circuit:
params=AZ_params,
num_qudits=orig_u.num_qudits,
reverse=True,
drop_last_cnot=True
drop_last_cnot=True,
),
shifted_qubits,
)
Expand Down
37 changes: 20 additions & 17 deletions bqskit/passes/synthesis/qsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def decompose_mpx_one_level(
decompose_ry: bool,
params: RealVector,
num_qudits: int,
reverse: bool =False,
drop_last_cnot: bool =False,
reverse: bool = False,
drop_last_cnot: bool = False,
) -> Circuit:
"""
Decompose Multiplexed Gate one level.
Expand Down Expand Up @@ -204,15 +204,15 @@ def decompose_mpx_two_levels(
decompose_ry: bool,
params: RealVector,
num_qudits: int,
reverse: bool =False,
reverse: bool = False,
drop_last_cnot: bool = False,
) -> Circuit:
"""
We decompose a multiplexed RZ gate 2 levels deep. This allows you to
remove 2 CNOTs as per Figure 2 in
We decompose a multiplexed RZ gate 2 levels deep. This allows you to
remove 2 CNOTs as per Figure 2 in
https://arxiv.org/pdf/quant-ph/0406176.pdf.
Furthermore, in the context of the Block ZXZ decomposition, you can
Furthermore, in the context of the Block ZXZ decomposition, you can
set `drop_last_cnot` to True. This CNOT gets merged into a central gate,
which saves another 2 CNOTs. This is shown in section 5.2 of
https://arxiv.org/pdf/2403.13692v1.pdf.
Expand All @@ -232,10 +232,12 @@ def decompose_mpx_two_levels(

if num_qudits <= 2:
# If you have less than 3 qubits, just decompose one level
return MGDPass.decompose_mpx_one_level(decompose_ry,
params,
num_qudits,
reverse)
return MGDPass.decompose_mpx_one_level(
decompose_ry,
params,
num_qudits,
reverse,
)

# Get params for first decomposition of the MCRZ gate
left_params, right_params = MCRYGate.get_decomposition(params)
Expand Down Expand Up @@ -292,7 +294,6 @@ async def run(self, circuit: Circuit, data: PassData) -> None:
ops: list[Operation] = []
pts: list[CircuitPoint] = []
locations: list[CircuitLocation] = []
num_ops = 0
all_ops = list(circuit.operations_with_cycles(reverse=True))

# Gather all of the multiplexed operations
Expand All @@ -308,7 +309,7 @@ async def run(self, circuit: Circuit, data: PassData) -> None:
+ loc[(op.gate.target_qubit + 1):]
+ [loc[op.gate.target_qubit]]
)
locations.append(loc)
locations.append(CircuitLocation(loc))

if len(ops) > 0:
# Do a bulk QSDs -> circs
Expand All @@ -317,15 +318,17 @@ async def run(self, circuit: Circuit, data: PassData) -> None:
MGDPass.decompose_mpx_two_levels(
isinstance(op.gate, MCRYGate),
op.params,
op.num_qudits) for op in ops
]
op.num_qudits,
) for op in ops
]
else:
circs = [
MGDPass.decompose_mpx_one_level(
isinstance(op.gate, MCRYGate),
op.params,
op.num_qudits) for op in ops
]
op.num_qudits,
) for op in ops
]
circ_gates = [CircuitGate(x) for x in circs]
circ_ops = [
Operation(x, locations[i], x._circuit.params)
Expand Down

0 comments on commit f844bcf

Please sign in to comment.