Skip to content

Commit

Permalink
chunking failures
Browse files Browse the repository at this point in the history
  • Loading branch information
purva-thakre committed Sep 25, 2024
1 parent 595360a commit 41d08f5
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions mitiq/lre/tests/test_lre.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,31 @@ def execute(circuit, noise_level=0.025):


noisy_val = execute(test_cirq)
ideal_val = execute(test_cirq, noise_level=0)


@pytest.mark.parametrize(
"input_degree, input_fold_multiplier", [(2, 2), (2, 3), (3, 4)]
)
def test_lre_exp_value(input_degree, input_fold_multiplier):
"""Verify LRE executors work as expected."""
ideal_val = execute(test_cirq, noise_level=0)
assert abs(ideal_val - noisy_val) > 0
lre_exp_val = execute_with_lre(
test_cirq,
execute,
degree=input_degree,
fold_multiplier=input_fold_multiplier,
)
assert lre_exp_val > noisy_val
assert abs(lre_exp_val - ideal_val) <= abs(noisy_val - ideal_val)

# verify the mitigated decorator work as expected
mitigated_executor = mitigate_executor(
execute, degree=2, fold_multiplier=2
)
exp_val_from_mitigate_executor = mitigated_executor(test_cirq)
assert exp_val_from_mitigate_executor > noisy_val
assert abs(exp_val_from_mitigate_executor - ideal_val) <= abs(
noisy_val - ideal_val
)


def test_lre_decorator():
Expand All @@ -63,12 +65,12 @@ def execute(circuit, noise_level=0.025):
)
return rho[0, 0].real

assert noisy_val < execute(test_cirq)
assert abs(execute(test_cirq) - ideal_val) <= abs(noisy_val - ideal_val)


def test_lre_decorator_raised_error():
"""Verify error is raised when the defualt parameters for the decorator are
not specified."""
"""Verify an error is raised when the required parameters for the decorator
are not specified."""
with pytest.raises(TypeError, match=re.escape("lre_decorator() missing")):

@lre_decorator()
Expand All @@ -82,18 +84,43 @@ def execute(circuit, noise_level=0.025):
)
return rho[0, 0].real

assert noisy_val < execute(test_cirq)
assert abs(execute(test_cirq) - ideal_val) <= abs(
noisy_val - ideal_val
)


def test_lre_executor_with_chunking():
"""Verify the executor works as expected for chunking a large circuit into
a smaller circuit."""
ideal_val = execute(test_cirq * 4, noise_level=0)
# define a larger circuit
test_cirq = benchmarks.generate_rb_circuits(n_qubits=1, num_cliffords=12)[
0
]
ideal_val = execute(test_cirq, noise_level=0)
assert abs(ideal_val - noisy_val) > 0
lre_exp_val = execute_with_lre(
test_cirq, execute, degree=2, fold_multiplier=2, num_chunks=10
)
assert abs(lre_exp_val - ideal_val) <= abs(noisy_val - ideal_val)


@pytest.mark.parametrize(
"test_input", [(1), (2), (3), (4), (5), (6), (7), (8), (9)]
)
@pytest.mark.xfail
def test_lre_executor_with_chunking_failures(test_input):
"""Verify chunking fails when a large number of layers are chunked into a
smaller number of circuit layers."""
# define a larger circuit
test_cirq = benchmarks.generate_rb_circuits(n_qubits=1, num_cliffords=15)[
0
]
ideal_val = execute(test_cirq, noise_level=0)
assert abs(ideal_val - noisy_val) > 0
lre_exp_val = execute_with_lre(
test_cirq * 4, execute, degree=2, fold_multiplier=2, num_chunks=5
test_cirq, execute, degree=2, fold_multiplier=2, num_chunks=test_input
)
assert lre_exp_val > noisy_val
assert abs(lre_exp_val - ideal_val) <= abs(noisy_val - ideal_val)


@pytest.mark.parametrize("input_method", [(fold_global), (fold_all)])
Expand All @@ -109,4 +136,4 @@ def test_lre_executor_with_different_folding_methods(input_method):
fold_multiplier=2,
folding_method=input_method,
)
assert lre_exp_val > noisy_val
assert abs(lre_exp_val - ideal_val) <= abs(noisy_val - ideal_val)

0 comments on commit 41d08f5

Please sign in to comment.