def test_run_sx_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.25 amp_cal = FineSXAmplitudeCal(0, self.cals, "sx") circs = transpile(amp_cal.circuits(), self.backend, inst_map=self.cals.default_inst_map) 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["sx"][((0,), ())], expected_sx) # run the calibration experiment. This should update the amp parameter of x which we test. exp_data = amp_cal.run(MockIQBackend(FineAmpHelper(-np.pi * 0.07, np.pi / 2, "sx"))) self.assertExperimentDone(exp_data) d_theta = exp_data.analysis_results(1).value.n new_amp = init_amp * (np.pi / 2) / (np.pi / 2 + d_theta) circs = transpile(amp_cal.circuits(), self.backend, inst_map=self.cals.default_inst_map) sx_cal = circs[5].calibrations["sx"][((0,), ())] # Requires allclose due to numerical precision. self.assertTrue(np.allclose(sx_cal.blocks[0].pulse.amp, new_amp)) self.assertFalse(np.allclose(sx_cal.blocks[0].pulse.amp, init_amp))
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_roundtrip_serializable(self): """Test round trip JSON serialization""" exp = FineSXAmplitudeCal(0, self.cals, "sx") self.assertRoundTripSerializable(exp, self.json_equiv)
def test_experiment_config(self): """Test converting to and from config works""" exp = FineSXAmplitudeCal(0, self.cals, "sx") loaded_exp = FineSXAmplitudeCal.from_config(exp.config()) self.assertNotEqual(exp, loaded_exp) self.assertTrue(self.json_equiv(exp, loaded_exp))