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

Filter calculation tools #176

Merged
merged 31 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1c07589
initial commit
yomach Nov 27, 2023
50adadd
with working bounce + delay
yomach Nov 28, 2023
34fb101
with docstrings and working sampling rate
yomach Nov 28, 2023
b0d152a
amplitude for reflection is minus the reflection
yomach Nov 28, 2023
106a4ac
format
yomach Nov 28, 2023
1b9276a
Folder + init + readme
TheoLaudatQM Mar 19, 2024
07eae8e
fix warnings
TheoLaudatQM Mar 20, 2024
1cdb6b4
exponential decay + readme
TheoLaudatQM Mar 20, 2024
605268c
multi-exponential trial
TheoLaudatQM Mar 20, 2024
da95381
fix and exp functions
TheoLaudatQM Apr 3, 2024
a5d1885
fixes + test
TheoLaudatQM Apr 3, 2024
b70b8e6
fix unused import
TheoLaudatQM Apr 3, 2024
54139cf
fix after test on server
TheoLaudatQM Apr 3, 2024
422ecb0
fix names and tests
TheoLaudatQM Apr 3, 2024
b90131a
fix LPF to undershoot and overshoot
TheoLaudatQM Apr 3, 2024
12c7100
test on server
TheoLaudatQM Apr 3, 2024
0401549
update changelog
TheoLaudatQM Apr 3, 2024
1cb81f8
correct syntax
TheoLaudatQM Apr 4, 2024
6389129
Increase max tap value and warn the user
TheoLaudatQM Apr 4, 2024
8357e00
small readme fix
TheoLaudatQM Apr 4, 2024
ad53725
Add tests
TheoLaudatQM Apr 4, 2024
1b466b7
hardware limitation implementation in progress
TheoLaudatQM Apr 5, 2024
1f22a70
black
TheoLaudatQM Apr 5, 2024
1ac1c57
hardware check
TheoLaudatQM Apr 9, 2024
d4f3437
QOP_VERSION
TheoLaudatQM Apr 9, 2024
6c3a860
black
TheoLaudatQM Apr 9, 2024
690cce3
update test
TheoLaudatQM Apr 9, 2024
7280f7e
a bit of cleaning + warnings for removed taps
yomach Apr 15, 2024
96c11ec
remove unused line
TheoLaudatQM Apr 15, 2024
61955b5
Add error
TheoLaudatQM Apr 15, 2024
62c87a7
Update readme
TheoLaudatQM Apr 18, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- octave_tools - Added `get_calibration_parameters_from_db` get the most up-to-date correction parameters in the calibration database for the specified values of the Octave LO frequency, intermediate frequency and Octave gain.
- octave_tools - Added `set_correction_parameters_to_opx` set the most up-to-date correction parameters from the calibration database for the specified values of the Octave LO frequency, intermediate frequency and Octave gain.
- octave_tools - Added `get_correction_for_each_LO_and_IF` get the correction matrix elements for a set of intermediate frequencies picked equally spaced in a given list in order to update the correction matrix while performing the IF sweep in QUA.
- digital_filters - Added library of functions allowing the derivation of the digital filter taps to correct distortions.
- macros - Added `long_wait` convenience macro to simplify waiting for longer than the maximum wait time.

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ storing them in the usual configuration file. It allows defining waveforms in a
* [ManualOutputControl](qualang_tools/control_panel/README_manual_output_control.md) - This module allows controlling the outputs from the OPX in CW mode. Once created, it has an API for defining which channels are on. Analog channels also have an API for defining their amplitude and frequency.
* [VNA](qualang_tools/control_panel/README_vna.md) - This module allows to configure the OPX as a VNA for a given element (readout resonator for instance) and operation (readout pulse for instance) already defined in the configuration. Once created, it has an API for defining which measurements are to be run depending on the down-conversion solution used (ED: envelope detector, IR: image rejection mixer, IQ: IQ mixer).
* [Macros](qualang_tools/macros/README.md) - This module includes convenience functions for encapsulating common QUA code.
* [Digital filters](qualang_tools/digital_filters/README.md) - Library of functions allowing the derivation of the digital filter taps to correct distortions.


## Installation
Expand Down
95 changes: 95 additions & 0 deletions qualang_tools/digital_filters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Digital filter tools
This library includes tools for deriving the taps of the OPX digital filters (IIR and FIR).

Such filters are generally used to correct for the high-pass filtering occurring on the fast line of a bias-tee,
or to correct flux pulses for possible distortions happening on the flux lines of superconducting qubit chips.

More details about these types of filter and how they are implemented on the OPX can be found [here](https://docs.quantum-machines.co/1.1.7/qm-qua-sdk/docs/Guides/output_filter/?h=iir#output-filter)

The goal of the following functions is to allow users to easily implement such filters by deriving the IIR and FIR taps
from the measured distortions:
* [Single exponential correction](#singleexponentialcorrection): correct for a low-pass exponential decay `1 + A * exp(-t/tau)`.
* [Highpass correction](#highpasscorrection): correct for a high pass exponential decay `exp(-t/tau)`.
* [Bounce and delay correction](#bounceanddelaycorrection): correct for reflections and delays.
* [Calc filter taps](#calcfiltertaps): correct for any combination of the aforementioned compensations.

## Usage examples

### single_exponential_correction
Calculate the best FIR and IIR filter taps to correct for an exponential decay (undershoot or overshoot) of the shape
`1 + A * exp(-t/tau)`. You can use the `exponential_decay` function for fitting your data as shown below.

####
```python
from scipy import optimize
from qualang_tools.digital_filters import exponential_decay, single_exponential_correction

# Fit your data with the exponential_decay function
[A_lpf, tau_lpf_ns], _ = optimize.curve_fit(
exponential_decay,
x_data,
y_data,
)
# Derive the corresponding taps
feedforward_taps, feedback_tap = single_exponential_correction(A_lpf, tau_lpf_ns)
# Update the config with the digital filter parameters
config["controllers"]["con1"]["analog_outputs"][port_number] = {
"offset": 0.0,
"filter": {"feedforward": feedforward_taps, "feedback": feedback_tap}}
```

### highpass_correction
Calculate the best FIR and IIR filter taps to correct for a highpass decay (high-pass filter) of the shape `exp(-t/tau)`.
You can use the `high_pass_exponential` function for fitting your data as shown below.

####
```python
from scipy import optimize
from qualang_tools.digital_filters import high_pass_exponential, highpass_correction

# Fit your data with the exponential_decay function
[tau_hpf_ns], _ = optimize.curve_fit(
high_pass_exponential,
x_data,
y_data,
)
# Derive the taps from the time constant of the exponential highpass decay tau
feedforward_taps, feedback_tap = highpass_correction(tau_hpf_ns)
# Update the config with the digital filter parameters
config["controllers"]["con1"]["analog_outputs"][port_number] = {
"offset": 0.0,
"filter": {"feedforward": feedforward_taps, "feedback": feedback_tap}}
```

### bounce_and_delay_correction
Calculate the FIR filter taps to correct for reflections (bounce corrections) and to add a delay.

####
```python
from qualang_tools.digital_filters import bounce_and_delay_correction



```

### calc_filter_taps
Calculate the best FIR and IIR filter taps for a system with any combination of FIR corrections, exponential
corrections (undershoot or overshoot), high pass compensation, reflections (bounce corrections) and a needed delay on the line.

####
```python
from qualang_tools.digital_filters import calc_filter_taps

# Derive the taps for correction all the identified distortions (high-pass, low-pass, reflection and delay)
feedforward_taps, feedback_tap = calc_filter_taps(
fir=None,
exponential=list(zip([A_lpf_1, A_lpf_2,...], [tau_lpf_ns_1, tau_lpf_ns_2,...])),
highpass=[tau_hpf_ns],
bounce=[(a_bounce, tau_bounce),],
delay=20,
)
# Update the config with the digital filter parameters
config["controllers"]["con1"]["analog_outputs"][port_number] = {
"offset": 0.0,
"filter": {"feedforward": feedforward_taps, "feedback": feedback_tap}}
```
19 changes: 19 additions & 0 deletions qualang_tools/digital_filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from qualang_tools.digital_filters.filters import (
QOPVersion,
calc_filter_taps,
exponential_decay,
high_pass_exponential,
single_exponential_correction,
highpass_correction,
bounce_and_delay_correction,
)

__all__ = [
"QOPVersion",
"calc_filter_taps",
"exponential_decay",
"high_pass_exponential",
"single_exponential_correction",
"highpass_correction",
"bounce_and_delay_correction",
]
Loading
Loading