def test_cal_options(self): """Test that the options are properly propagated.""" # Test the X gate cal amp_cal = FineXAmplitudeCal(0, self.cals, "x") exp_opt = amp_cal.experiment_options self.assertEqual(exp_opt.gate.name, "x") self.assertTrue(exp_opt.add_sx) self.assertTrue(exp_opt.add_xp_circuit) self.assertEqual(exp_opt.result_index, -1) self.assertEqual(exp_opt.group, "default") self.assertTrue(np.allclose(exp_opt.target_angle, np.pi)) # Test the SX gate cal amp_cal = FineSXAmplitudeCal(0, self.cals, "sx") exp_opt = amp_cal.experiment_options self.assertEqual(exp_opt.gate.name, "sx") self.assertFalse(exp_opt.add_sx) self.assertFalse(exp_opt.add_xp_circuit) self.assertEqual(exp_opt.result_index, -1) self.assertEqual(exp_opt.group, "default") self.assertTrue(np.allclose(exp_opt.target_angle, np.pi / 2))
def test_run_x_cal(self): """Test that we can transpile in the calibrations before and after update. If this test passes then we were successful in running a calibration experiment, updating a pulse parameter, having this parameter propagated to the schedules for use the next time the experiment is run. """ # Initial pulse amplitude init_amp = 0.5 amp_cal = FineXAmplitudeCal(0, self.cals, "x") circs = transpile( amp_cal.circuits(), self.backend, inst_map=amp_cal.transpile_options.inst_map ) with pulse.build(name="x") as expected_x: pulse.play(pulse.Drag(160, 0.5, 40, 0), pulse.DriveChannel(0)) with pulse.build(name="sx") as expected_sx: pulse.play(pulse.Drag(160, 0.25, 40, 0), pulse.DriveChannel(0)) self.assertEqual(circs[5].calibrations["x"][((0,), ())], expected_x) self.assertEqual(circs[5].calibrations["sx"][((0,), ())], expected_sx) # run the calibration experiment. This should update the amp parameter of x which we test. exp_data = amp_cal.run(self.backend) self.assertExperimentDone(exp_data) d_theta = exp_data.analysis_results(1).value.n new_amp = init_amp * np.pi / (np.pi + d_theta) circs = transpile( amp_cal.circuits(), self.backend, inst_map=amp_cal.transpile_options.inst_map ) x_cal = circs[5].calibrations["x"][((0,), ())] # Requires allclose due to numerical precision. self.assertTrue(np.allclose(x_cal.blocks[0].pulse.amp, new_amp)) self.assertFalse(np.allclose(x_cal.blocks[0].pulse.amp, init_amp)) self.assertEqual(circs[5].calibrations["sx"][((0,), ())], expected_sx)