def test_rabi_end_to_end(self): """Test the Rabi experiment end to end.""" test_tol = 0.01 backend = RabiBackend() rabi = Rabi(self.qubit, self.sched) rabi.set_experiment_options(amplitudes=np.linspace(-0.95, 0.95, 21)) expdata = rabi.run(backend) result = expdata.analysis_results(0) self.assertEqual(result.quality, "good") self.assertTrue( abs(result.value.value[1] - backend.rabi_rate) < test_tol) backend = RabiBackend(amplitude_to_angle=np.pi / 2) rabi = Rabi(self.qubit, self.sched) rabi.set_experiment_options(amplitudes=np.linspace(-0.95, 0.95, 21)) expdata = rabi.run(backend) result = expdata.analysis_results(0) self.assertEqual(result.quality, "good") self.assertTrue( abs(result.value.value[1] - backend.rabi_rate) < test_tol) backend = RabiBackend(amplitude_to_angle=2.5 * np.pi) rabi = Rabi(self.qubit, self.sched) rabi.set_experiment_options(amplitudes=np.linspace(-0.95, 0.95, 101)) expdata = rabi.run(backend) result = expdata.analysis_results(0) self.assertEqual(result.quality, "good") self.assertTrue( abs(result.value.value[1] - backend.rabi_rate) < test_tol)
def test_update(self): """Test that the calibrations update properly.""" self.assertTrue(np.allclose(self.cals.get_parameter_value("amp", 0, "x"), 0.5)) self.assertTrue(np.allclose(self.cals.get_parameter_value("amp", 0, "sx"), 0.25)) rabi_ef = RoughXSXAmplitudeCal(0, self.cals) expdata = rabi_ef.run(RabiBackend(amplitude_to_angle=np.pi * 1.5)) self.assertExperimentDone(expdata) tol = 0.002 self.assertTrue(abs(self.cals.get_parameter_value("amp", 0, "x") - 0.333) < tol) self.assertTrue(abs(self.cals.get_parameter_value("amp", 0, "sx") - 0.333 / 2) < tol)
def test_ef_update(self): """Tes that we properly update the pulses on the 1<->2 transition.""" self.assertTrue(np.allclose(self.cals.get_parameter_value("amp", 0, "x12"), 0.4)) self.assertTrue(np.allclose(self.cals.get_parameter_value("amp", 0, "sx12"), 0.2)) rabi_ef = EFRoughXSXAmplitudeCal(0, self.cals) expdata = rabi_ef.run(RabiBackend(amplitude_to_angle=np.pi * 1.5)) self.assertExperimentDone(expdata) tol = 0.002 self.assertTrue(abs(self.cals.get_parameter_value("amp", 0, "x12") - 0.333) < tol) self.assertTrue(abs(self.cals.get_parameter_value("amp", 0, "sx12") - 0.333 / 2) < tol)
def test_default_schedule(self): """Test the default schedule.""" rabi = Rabi(2, self.sched) rabi.set_experiment_options(amplitudes=[0.5]) rabi.backend = RabiBackend() circs = rabi.circuits() with pulse.build() as expected: pulse.play(pulse.Gaussian(160, 0.5, 40), pulse.DriveChannel(2)) self.assertEqual(circs[0].calibrations["Rabi"][((2, ), (0.5, ))], expected) self.assertEqual(len(circs), 1)
def test_wrong_processor(self): """Test that we can override the data processing by giving a faulty data processor.""" backend = RabiBackend() rabi = Rabi(self.qubit, self.sched) fail_key = "fail_key" rabi.analysis.set_options(data_processor=DataProcessor(fail_key, [])) rabi.set_run_options(shots=2) data = rabi.run(backend) result = data.analysis_results() self.assertEqual(len(result), 0)
def test_ef_rabi_end_to_end(self): """Test the EFRabi experiment end to end.""" test_tol = 0.01 backend = RabiBackend() # Note that the backend is not sophisticated enough to simulate an e-f # transition so we run the test with a tiny frequency shift, still driving the e-g transition. rabi = EFRabi(self.qubit, self.sched) rabi.set_experiment_options(amplitudes=np.linspace(-0.95, 0.95, 21)) expdata = rabi.run(backend) result = expdata.analysis_results(1) self.assertEqual(result.quality, "good") self.assertTrue(abs(result.value.value - backend.rabi_rate) < test_tol)
def test_user_schedule(self): """Test the user given schedule.""" amp = Parameter("my_double_amp") with pulse.build() as my_schedule: pulse.play(pulse.Drag(160, amp, 40, 10), pulse.DriveChannel(2)) pulse.play(pulse.Drag(160, amp, 40, 10), pulse.DriveChannel(2)) rabi = Rabi(2, self.sched) rabi.set_experiment_options(schedule=my_schedule, amplitudes=[0.5]) rabi.backend = RabiBackend() circs = rabi.circuits() assigned_sched = my_schedule.assign_parameters({amp: 0.5}, inplace=False) self.assertEqual(circs[0].calibrations["Rabi"][((2, ), (0.5, ))], assigned_sched)