Skip to content

Commit f32e985

Browse files
authored
Faster TestEPGAnalysis (#1276)
### Summary Made `TestEPGAnalysis` faster so that they can run within the 60 second limit. ### Details and comments The heavy part in the analysis tests is in running experiments before the analyses to be tested. So common experiments are run in advance and used for analyses in `TestEPGAnalysis`. However, all the common experiments were run before every test because they were run in `setUp`. This commit moves them to `setUpClass` so that they are run once as expected. By the change, the total execution time is reduced from 34 sec to 7 sec in my local environment.
1 parent f33bed7 commit f32e985

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

test/library/randomized_benchmarking/test_rb_analysis.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ class TestEPGAnalysis(QiskitExperimentsTestCase):
3232
by comparing the value with the depolarizing probability.
3333
"""
3434

35-
def setUp(self):
36-
"""Setup the tests."""
37-
super().setUp()
35+
@classmethod
36+
def setUpClass(cls):
37+
"""Run experiments without analysis for test data preparation."""
38+
super().setUpClass()
3839

3940
# Setup noise model, including more gate for complicated EPG computation
4041
# Note that 1Q channel error is amplified to check 1q channel correction mechanism
41-
self.p_x = 0.04
42-
self.p_h = 0.02
43-
self.p_s = 0.0
44-
self.p_cx = 0.09
45-
x_error = depolarizing_error(self.p_x, 1)
46-
h_error = depolarizing_error(self.p_h, 1)
47-
s_error = depolarizing_error(self.p_s, 1)
48-
cx_error = depolarizing_error(self.p_cx, 2)
42+
cls.p_x = 0.04
43+
cls.p_h = 0.02
44+
cls.p_s = 0.0
45+
cls.p_cx = 0.09
46+
x_error = depolarizing_error(cls.p_x, 1)
47+
h_error = depolarizing_error(cls.p_h, 1)
48+
s_error = depolarizing_error(cls.p_s, 1)
49+
cx_error = depolarizing_error(cls.p_cx, 2)
4950

5051
noise_model = NoiseModel()
5152
noise_model.add_all_qubit_quantum_error(x_error, "x")
@@ -70,8 +71,7 @@ def setUp(self):
7071
backend=backend,
7172
)
7273
exp_1qrb_q0.set_transpile_options(**transpiler_options)
73-
expdata_1qrb_q0 = exp_1qrb_q0.run(analysis=None)
74-
self.assertExperimentDone(expdata_1qrb_q0, timeout=300)
74+
expdata_1qrb_q0 = exp_1qrb_q0.run(analysis=None).block_for_results()
7575

7676
exp_1qrb_q1 = rb.StandardRB(
7777
physical_qubits=(1,),
@@ -80,8 +80,7 @@ def setUp(self):
8080
backend=backend,
8181
)
8282
exp_1qrb_q1.set_transpile_options(**transpiler_options)
83-
expdata_1qrb_q1 = exp_1qrb_q1.run(analysis=None)
84-
self.assertExperimentDone(expdata_1qrb_q1, timeout=300)
83+
expdata_1qrb_q1 = exp_1qrb_q1.run(analysis=None).block_for_results()
8584

8685
exp_2qrb = rb.StandardRB(
8786
physical_qubits=(0, 1),
@@ -90,12 +89,18 @@ def setUp(self):
9089
backend=backend,
9190
)
9291
exp_2qrb.set_transpile_options(**transpiler_options)
93-
expdata_2qrb = exp_2qrb.run(analysis=None)
94-
self.assertExperimentDone(expdata_2qrb, timeout=300)
92+
expdata_2qrb = exp_2qrb.run(analysis=None).block_for_results()
93+
94+
cls.expdata_1qrb_q0 = expdata_1qrb_q0
95+
cls.expdata_1qrb_q1 = expdata_1qrb_q1
96+
cls.expdata_2qrb = expdata_2qrb
9597

96-
self.expdata_1qrb_q0 = expdata_1qrb_q0
97-
self.expdata_1qrb_q1 = expdata_1qrb_q1
98-
self.expdata_2qrb = expdata_2qrb
98+
def setUp(self):
99+
"""Setup the tests."""
100+
super().setUp()
101+
self.assertExperimentDone(self.expdata_1qrb_q0)
102+
self.assertExperimentDone(self.expdata_1qrb_q1)
103+
self.assertExperimentDone(self.expdata_2qrb)
99104

100105
def test_default_epg_ratio(self):
101106
"""Calculate EPG with default ratio dictionary. H and X have the same ratio."""

0 commit comments

Comments
 (0)