Skip to content

Commit

Permalink
format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FarLab committed Aug 1, 2024
1 parent 16585d1 commit 67e0abc
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions mitiq/zne/tests/test_zne.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
from mitiq import QPROGRAM, SUPPORTED_PROGRAM_TYPES
from mitiq.benchmarks.randomized_benchmarking import generate_rb_circuits
from mitiq.interface import accept_any_qprogram_as_input, convert_from_mitiq
from mitiq.interface.mitiq_braket import to_braket
from mitiq.interface.mitiq_cirq import (
compute_density_matrix,
sample_bitstrings,
)
from mitiq.interface.mitiq_pennylane import to_pennylane
from mitiq.interface.mitiq_pyquil import to_pyquil
from mitiq.interface.mitiq_qibo import to_qibo
from mitiq.interface.mitiq_qiskit import (
execute_with_shots_and_noise,
initialized_depolarizing_noise,
to_qiskit,
)
from mitiq.observable import Observable, PauliString
from mitiq.zne import (
Expand All @@ -54,14 +59,6 @@
)
from mitiq.zne.zne import combine_results, scaled_circuits

from mitiq.interface.mitiq_qiskit import to_qiskit
from mitiq.interface.mitiq_braket import to_braket
from mitiq.interface.mitiq_pennylane import to_pennylane
from mitiq.interface.mitiq_pyquil import to_pyquil
from mitiq.interface.mitiq_qibo import to_qibo



BASE_NOISE = 0.007
TEST_DEPTH = 30
ONE_QUBIT_GS_PROJECTOR = np.array([[1, 0], [0, 0]])
Expand Down Expand Up @@ -577,6 +574,7 @@ def qs_noisy_simulation(
mitigated = execute_with_zne(circuit, qs_noisy_simulation)
assert abs(mitigated) < 1000


@pytest.mark.parametrize(
"noise_scaling_method",
[fold_gates_at_random, insert_id_layers, fold_global, fold_all],
Expand All @@ -585,40 +583,45 @@ def qs_noisy_simulation(
"extrapolation_factory", [RichardsonFactory, LinearFactory]
)
@pytest.mark.parametrize(
"to_frontend", [None, to_qiskit, to_braket, to_pennylane, to_pyquil, to_qibo]
"to_frontend",
[None, to_qiskit, to_braket, to_pennylane, to_pyquil, to_qibo],
)
def test_two_stage_zne(noise_scaling_method, extrapolation_factory, to_frontend):
def test_two_stage_zne(
noise_scaling_method, extrapolation_factory, to_frontend
):
qreg = cirq.LineQubit.range(2)
cirq_circuit = cirq.Circuit(
cirq.H.on_each(qreg),
cirq.CNOT(*qreg),
cirq.CNOT(*qreg),
cirq.H.on_each(qreg),
)
if to_frontend != None:
)
if to_frontend is not None:
frontend_circuit = to_frontend(cirq_circuit)
else:
frontend_circuit = cirq_circuit

scale_factors = [1, 3, 5]
frontend_circuits = scaled_circuits(
circs = scaled_circuits(
frontend_circuit, scale_factors, noise_scaling_method
)

assert len(frontend_circuits) == len(scale_factors)
assert len(circs) == len(scale_factors)

if to_frontend == to_braket:
assert all(isinstance(circ, braket.circuits.Circuit) for circ in frontend_circuits)
assert all(isinstance(circ, braket.circuits.Circuit) for circ in circs)
elif to_frontend == to_qiskit:
assert all(isinstance(circ, qiskit.QuantumCircuit) for circ in frontend_circuits)
assert all(isinstance(circ, qiskit.QuantumCircuit) for circ in circs)
elif to_frontend == to_pennylane:
assert all(isinstance(circ, pennylane.tape.QuantumTape) for circ in frontend_circuits)
assert all(
isinstance(circ, pennylane.tape.QuantumTape) for circ in circs
)
elif to_frontend == to_pyquil:
assert all(isinstance(circ, pyquil.quil.Program) for circ in frontend_circuits)
assert all(isinstance(circ, pyquil.quil.Program) for circ in circs)
elif to_frontend == to_qibo:
assert all(isinstance(circ, qibo.Circuit) for circ in frontend_circuits)
assert all(isinstance(circ, qibo.Circuit) for circ in circs)
else:
assert all(isinstance(circ, cirq.Circuit) for circ in frontend_circuits)
assert all(isinstance(circ, cirq.Circuit) for circ in circs)

np.random.seed(42)

Expand Down

0 comments on commit 67e0abc

Please sign in to comment.