10
10
11
11
from mitiq import SUPPORTED_PROGRAM_TYPES , benchmarks
12
12
from mitiq .lre import execute_with_lre , lre_decorator , mitigate_executor
13
+ from mitiq .lre .multivariate_scaling .layerwise_folding import _get_chunks
13
14
from mitiq .zne .scaling import fold_all , fold_global
14
15
15
16
# default circuit for all unit tests
@@ -111,19 +112,6 @@ def execute(circuit, noise_level=0.025):
111
112
)
112
113
113
114
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
-
127
115
@pytest .mark .parametrize ("input_method" , [(fold_global ), (fold_all )])
128
116
def test_lre_executor_with_different_folding_methods (input_method ):
129
117
"""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):
136
124
folding_method = input_method ,
137
125
)
138
126
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