Skip to content

Commit

Permalink
feat(folding_amplifier): add multi-qubit amplifier facade
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorrivero committed Feb 5, 2024
1 parent 6ca8866 commit c154596
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from zne.noise_amplification import (
CxAmplifier,
LocalFoldingAmplifier,
MultiQubitAmplifier,
TwoQubitAmplifier,
)

Expand Down Expand Up @@ -460,8 +461,27 @@ class TestFacades:
(TwoQubitAmplifier, {"gates_to_fold": 2}),
],
)
def test_two_qubit_amplifier(self, cls, configs):
def test_amplifier_facade(self, cls, configs):
amplifier = cls()
assert isinstance(amplifier, LocalFoldingAmplifier)
for key, value in configs.items():
assert getattr(amplifier, key) == frozenset([value])

def test_multi_qubit_amplifier(self):
amplifier = MultiQubitAmplifier()
assert isinstance(amplifier, LocalFoldingAmplifier)
assert amplifier.gates_to_fold is None
circuit = QuantumCircuit(4)
circuit.h(0)
circuit.z(3)
circuit.cx(0, 1)
circuit.x(1)
circuit.ccx(0, 1, 2)
circuit.y(2)
circuit.ecr(2, 3)
circuit.measure_all()
for operation in circuit.data:
instruction = operation[0]
skipped_instructions = {"barrier", "measure"}
expected = instruction.num_qubits > 1 and instruction.name not in skipped_instructions
assert amplifier._check_gate_folds(operation) == expected
2 changes: 2 additions & 0 deletions zne/noise_amplification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CxAmplifier,
GlobalFoldingAmplifier,
LocalFoldingAmplifier,
MultiQubitAmplifier,
TwoQubitAmplifier,
)
from .noise_amplifier import CircuitNoiseAmplifier, DAGNoiseAmplifier, NoiseAmplifier
Expand All @@ -27,6 +28,7 @@
LocalFoldingAmplifier,
CxAmplifier,
TwoQubitAmplifier,
MultiQubitAmplifier,
)
}

Expand Down
2 changes: 2 additions & 0 deletions zne/noise_amplification/folding_amplifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .local_folding_amplifier import (
CxAmplifier,
LocalFoldingAmplifier,
MultiQubitAmplifier,
TwoQubitAmplifier,
)

Expand All @@ -24,4 +25,5 @@
"LocalFoldingAmplifier",
"CxAmplifier",
"TwoQubitAmplifier",
"MultiQubitAmplifier",
]
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,35 @@ def __init__( # pylint: disable=too-many-arguments,duplicate-code
noise_factor_relative_tolerance=noise_factor_relative_tolerance,
warn_user=warn_user,
)


class MultiQubitAmplifier(LocalFoldingAmplifier):
"""
Digital noise amplifier acting on multi-qubit gates exclusively.
Replaces each multi-qubit gate locally with as many gates as indicated by the noise_factor.
"""

def __init__( # pylint: disable=too-many-arguments,duplicate-code
self,
sub_folding_option: str = "from_first",
barriers: bool = True,
random_seed: int | None = None,
noise_factor_relative_tolerance: float = 1e-2,
warn_user: bool = True,
) -> None:
super().__init__(
gates_to_fold=None,
sub_folding_option=sub_folding_option,
barriers=barriers,
random_seed=random_seed,
noise_factor_relative_tolerance=noise_factor_relative_tolerance,
warn_user=warn_user,
)

def _check_gate_folds(self, operation: CircuitInstruction) -> bool:
instruction, qargs, _ = operation
if instruction.name in {"barrier", "measure"}:
return False
num_qubits = len(qargs)
return num_qubits > 1

0 comments on commit c154596

Please sign in to comment.