diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aad2bcd..d565b625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Fixed +- control_panel - Fix rounding error in `ManualOutputControl` that caused voltage drifts. - octave_tools - Fix bug when setting calibrate to False in ``get_correction_for_each_LO_and_IF()``. - unit - ``to_clock_cycles()`` now always returns an integer. + ### Added - octave_tools - Added the possibility to pass the AutoCalibrationParams to ``get_correction_for_each_LO_and_IF()`` to customize the calibration parameters (IF_amplitude for instance). diff --git a/qualang_tools/control_panel/manual_output_control.py b/qualang_tools/control_panel/manual_output_control.py index 29d158a8..da9d2151 100644 --- a/qualang_tools/control_panel/manual_output_control.py +++ b/qualang_tools/control_panel/manual_output_control.py @@ -1,6 +1,7 @@ """calling function libraries""" import copy +import math from time import sleep import numpy as np @@ -11,7 +12,11 @@ def _round_to_fixed_point_accuracy(x, accuracy=2**-16): - return np.round(x / accuracy) * accuracy + return round(x / accuracy) * accuracy + + +def _floor_to_fixed_point_accuracy(x, accuracy=2**-16): + return math.floor(x / accuracy) * accuracy class ManualOutputControl: @@ -242,19 +247,23 @@ def set_amplitude(self, element, value, ignore_missing_elements=False): raise Exception(f"The absolute value of the amplitude must smaller than 0.5, {value} was given") prev_value = self.analog_data[element]["amplitude"] - self.analog_data[element]["amplitude"] = value if value != 0: - value = (value - prev_value) * (1 / self.ANALOG_WAVEFORM_AMPLITUDE) - value = _round_to_fixed_point_accuracy(value) - if value == 0: + delta_value = (value - prev_value) * (1 / self.ANALOG_WAVEFORM_AMPLITUDE) + delta_value = _round_to_fixed_point_accuracy(delta_value) + if delta_value == 0: return + else: + delta_value = value + self.analog_data[element]["amplitude"] = _floor_to_fixed_point_accuracy( + prev_value + delta_value * self.ANALOG_WAVEFORM_AMPLITUDE + ) while not self.analog_job.is_paused(): sleep(0.01) self.analog_qm.set_io_values( int(self.analog_elements.index(element)) + len(self.analog_elements), - float(value), + float(delta_value), ) self.analog_job.resume()