class TestAmplitudeUpdate(QiskitExperimentsTestCase): """Test the update functions in the update library.""" def setUp(self): """Setup amplitude values.""" super().setUp() self.cals = Calibrations() self.qubit = 1 axp = Parameter("amp") chan = Parameter("ch0") with pulse.build(name="xp") as xp: pulse.play(pulse.Gaussian(duration=160, amp=axp, sigma=40), pulse.DriveChannel(chan)) ax90p = Parameter("amp") with pulse.build(name="x90p") as x90p: pulse.play(pulse.Gaussian(duration=160, amp=ax90p, sigma=40), pulse.DriveChannel(chan)) self.x90p = x90p self.cals.add_schedule(xp, num_qubits=1) self.cals.add_schedule(x90p, num_qubits=1) self.cals.add_parameter_value(0.2, "amp", self.qubit, "xp") self.cals.add_parameter_value(0.1, "amp", self.qubit, "x90p")
def add_parameter_value( cls, cal: Calibrations, exp_data: ExperimentData, value: ParameterValueType, param: Union[Parameter, str], schedule: Union[ScheduleBlock, str] = None, group: str = "default", ): """Update the calibrations with the given value. Args: cal: The Calibrations instance to update. exp_data: The ExperimentData instance that contains the result and the experiment data. value: The value extracted by the subclasses in the :meth:`update` method. param: The name of the parameter, or the parameter instance, which will receive an updated value. schedule: The ScheduleBlock instance or the name of the instance to which the parameter is attached. group: The calibrations group to update. """ qubits = exp_data.metadata["physical_qubits"] param_value = ParameterValue( value=value, date_time=cls._time_stamp(exp_data), group=group, exp_id=exp_data.experiment_id, ) cal.add_parameter_value(param_value, param, qubits, schedule)
class TestAmplitudeUpdate(QiskitTestCase): """Test the update functions in the update library.""" def setUp(self): """Setup amplitude values.""" super().setUp() self.cals = Calibrations() self.qubit = 1 axp = Parameter("amp") chan = Parameter("ch0") with pulse.build(name="xp") as xp: pulse.play(pulse.Gaussian(duration=160, amp=axp, sigma=40), pulse.DriveChannel(chan)) ax90p = Parameter("amp") with pulse.build(name="x90p") as x90p: pulse.play(pulse.Gaussian(duration=160, amp=ax90p, sigma=40), pulse.DriveChannel(chan)) self.x90p = x90p self.cals.add_schedule(xp, num_qubits=1) self.cals.add_schedule(x90p, num_qubits=1) self.cals.add_parameter_value(0.2, "amp", self.qubit, "xp") self.cals.add_parameter_value(0.1, "amp", self.qubit, "x90p") def test_amplitude(self): """Test amplitude update from Rabi.""" rabi = Rabi(self.qubit) rabi.set_experiment_options(amplitudes=np.linspace(-0.95, 0.95, 21)) exp_data = rabi.run(RabiBackend()) exp_data.block_for_results() with self.assertRaises(CalibrationError): self.cals.get_schedule("xp", qubits=0) to_update = [(np.pi, "amp", "xp"), (np.pi / 2, "amp", self.x90p)] self.assertEqual(len(self.cals.parameters_table()), 2) Amplitude.update(self.cals, exp_data, angles_schedules=to_update) with self.assertRaises(CalibrationError): self.cals.get_schedule("xp", qubits=0) self.assertEqual(len(self.cals.parameters_table()["data"]), 4) # Now check the corresponding schedules result = exp_data.analysis_results(1) rate = 2 * np.pi * result.value.value amp = np.round(np.pi / rate, decimals=8) with pulse.build(name="xp") as expected: pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(self.qubit)) self.assertEqual(self.cals.get_schedule("xp", qubits=self.qubit), expected) amp = np.round(0.5 * np.pi / rate, decimals=8) with pulse.build(name="xp") as expected: pulse.play(pulse.Gaussian(160, amp, 40), pulse.DriveChannel(self.qubit)) self.assertEqual(self.cals.get_schedule("x90p", qubits=self.qubit), expected)