Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

control_panel - Fix rounding error that caused voltage drifts #211

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
21 changes: 15 additions & 6 deletions qualang_tools/control_panel/manual_output_control.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""calling function libraries"""

import copy
import math
from time import sleep

import numpy as np
Expand All @@ -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:
Expand Down Expand Up @@ -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()

Expand Down
Loading