Skip to content

Commit b218ee7

Browse files
LRE failure for chunking (#2608)
* change what's being asserted * change assert, update docstring * validate failure * nate's mock test * rename test; cleanup docstring --------- Co-authored-by: nate stemen <nate@unitary.foundation>
1 parent 7b5f549 commit b218ee7

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

mitiq/lre/tests/test_lre.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from mitiq import SUPPORTED_PROGRAM_TYPES, benchmarks
1212
from mitiq.lre import execute_with_lre, lre_decorator, mitigate_executor
13+
from mitiq.lre.multivariate_scaling.layerwise_folding import _get_chunks
1314
from mitiq.zne.scaling import fold_all, fold_global
1415

1516
# default circuit for all unit tests
@@ -111,19 +112,6 @@ def execute(circuit, noise_level=0.025):
111112
)
112113

113114

114-
def test_lre_executor_with_chunking():
115-
"""Verify the executor works as expected for chunking a large circuit into
116-
a smaller circuit."""
117-
# define a larger circuit
118-
test_cirq = benchmarks.generate_rb_circuits(n_qubits=1, num_cliffords=12)[
119-
0
120-
]
121-
lre_exp_val = execute_with_lre(
122-
test_cirq, execute, degree=2, fold_multiplier=2, num_chunks=14
123-
)
124-
assert abs(lre_exp_val - ideal_val) <= abs(noisy_val - ideal_val)
125-
126-
127115
@pytest.mark.parametrize("input_method", [(fold_global), (fold_all)])
128116
def test_lre_executor_with_different_folding_methods(input_method):
129117
"""Verify the executor works as expected for using non-default unitary
@@ -136,3 +124,30 @@ def test_lre_executor_with_different_folding_methods(input_method):
136124
folding_method=input_method,
137125
)
138126
assert abs(lre_exp_val - ideal_val) <= abs(noisy_val - ideal_val)
127+
128+
129+
def test_lre_runs_correct_number_of_circuits_when_chunking():
130+
"""Verify execute_with_lre works as expected when chunking is used.
131+
Note that this does not validate performance of chunking."""
132+
133+
mock_executor = Mock(side_effect=lambda _: random.random())
134+
135+
test_cirq = benchmarks.generate_rb_circuits(n_qubits=1, num_cliffords=12)[
136+
0
137+
]
138+
139+
degree, fold_multiplier, num_chunks = 2, 2, 10
140+
141+
lre_exp_val_chunking = execute_with_lre(
142+
test_cirq,
143+
mock_executor,
144+
degree=degree,
145+
fold_multiplier=fold_multiplier,
146+
num_chunks=num_chunks,
147+
)
148+
149+
chunked_circ = _get_chunks(test_cirq, num_chunks=num_chunks)
150+
assert isinstance(lre_exp_val_chunking, float)
151+
assert mock_executor.call_count == math.comb(
152+
degree + len(chunked_circ), degree
153+
)

0 commit comments

Comments
 (0)