Skip to content

Commit

Permalink
Faster TestEPGAnalysis (#1276)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
itoko authored Sep 29, 2023
1 parent f33bed7 commit f32e985
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions test/library/randomized_benchmarking/test_rb_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ class TestEPGAnalysis(QiskitExperimentsTestCase):
by comparing the value with the depolarizing probability.
"""

def setUp(self):
"""Setup the tests."""
super().setUp()
@classmethod
def setUpClass(cls):
"""Run experiments without analysis for test data preparation."""
super().setUpClass()

# Setup noise model, including more gate for complicated EPG computation
# Note that 1Q channel error is amplified to check 1q channel correction mechanism
self.p_x = 0.04
self.p_h = 0.02
self.p_s = 0.0
self.p_cx = 0.09
x_error = depolarizing_error(self.p_x, 1)
h_error = depolarizing_error(self.p_h, 1)
s_error = depolarizing_error(self.p_s, 1)
cx_error = depolarizing_error(self.p_cx, 2)
cls.p_x = 0.04
cls.p_h = 0.02
cls.p_s = 0.0
cls.p_cx = 0.09
x_error = depolarizing_error(cls.p_x, 1)
h_error = depolarizing_error(cls.p_h, 1)
s_error = depolarizing_error(cls.p_s, 1)
cx_error = depolarizing_error(cls.p_cx, 2)

noise_model = NoiseModel()
noise_model.add_all_qubit_quantum_error(x_error, "x")
Expand All @@ -70,8 +71,7 @@ def setUp(self):
backend=backend,
)
exp_1qrb_q0.set_transpile_options(**transpiler_options)
expdata_1qrb_q0 = exp_1qrb_q0.run(analysis=None)
self.assertExperimentDone(expdata_1qrb_q0, timeout=300)
expdata_1qrb_q0 = exp_1qrb_q0.run(analysis=None).block_for_results()

exp_1qrb_q1 = rb.StandardRB(
physical_qubits=(1,),
Expand All @@ -80,8 +80,7 @@ def setUp(self):
backend=backend,
)
exp_1qrb_q1.set_transpile_options(**transpiler_options)
expdata_1qrb_q1 = exp_1qrb_q1.run(analysis=None)
self.assertExperimentDone(expdata_1qrb_q1, timeout=300)
expdata_1qrb_q1 = exp_1qrb_q1.run(analysis=None).block_for_results()

exp_2qrb = rb.StandardRB(
physical_qubits=(0, 1),
Expand All @@ -90,12 +89,18 @@ def setUp(self):
backend=backend,
)
exp_2qrb.set_transpile_options(**transpiler_options)
expdata_2qrb = exp_2qrb.run(analysis=None)
self.assertExperimentDone(expdata_2qrb, timeout=300)
expdata_2qrb = exp_2qrb.run(analysis=None).block_for_results()

cls.expdata_1qrb_q0 = expdata_1qrb_q0
cls.expdata_1qrb_q1 = expdata_1qrb_q1
cls.expdata_2qrb = expdata_2qrb

self.expdata_1qrb_q0 = expdata_1qrb_q0
self.expdata_1qrb_q1 = expdata_1qrb_q1
self.expdata_2qrb = expdata_2qrb
def setUp(self):
"""Setup the tests."""
super().setUp()
self.assertExperimentDone(self.expdata_1qrb_q0)
self.assertExperimentDone(self.expdata_1qrb_q1)
self.assertExperimentDone(self.expdata_2qrb)

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

0 comments on commit f32e985

Please sign in to comment.