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

Filter calculation tools #176

merged 31 commits into from
Apr 18, 2024

Conversation

yomach
Copy link
Collaborator

@yomach yomach commented Nov 28, 2023

Hi, take a look at this and please review it :)

It's without any tests and without the changelog/readme changes.

It's also mostly without any hardware limitations (besides the highpass), we need to decide if we want to include them or not. And if so, how to deal with changing limitations.

Copy link

github-actions bot commented Nov 28, 2023

Unit Test Results

382 tests   379 ✔️  44s ⏱️
    1 suites      3 💤
    1 files        0

Results for commit 62c87a7.

♻️ This comment has been updated with latest results.

@TheoLaudatQM
Copy link
Contributor

I like the idea of finally putting all of these calculations on the Github very much! 💯
I looked at the highpass_correction and exponential_correction which I know and it looks good. Do you know the maximum high pass time constant that we can correct based on the resolution of the FIR taps? Is it on 17 or 21 bits?
I am not familiar with the bounce_and_delay_correction and the filters concatenation, but I trust you :)

@yomach
Copy link
Collaborator Author

yomach commented Dec 10, 2023

I like the idea of finally putting all of these calculations on the Github very much! 💯 I looked at the highpass_correction and exponential_correction which I know and it looks good. Do you know the maximum high pass time constant that we can correct based on the resolution of the FIR taps? Is it on 17 or 21 bits? I am not familiar with the bounce_and_delay_correction and the filters concatenation, but I trust you :)

Thx!
It was actually planned for a long time...

I want to remove the HW limit from the main function (maybe add it as another function) because:

  1. We're not even sure what it is (see my slack message)
  2. This will change between versions...

@TheoLaudatQM
Copy link
Contributor

I see, regarding the HW limitation I think it is now clear that currently the FIR taps are on 25bits and the IIR on 17bits. Maybe we can add flag to discriminate between the QOP (or qm-qua) versions and make these limitations explicit so that the users will know what is going on and if the given taps are accurate or not, what do you think?

@TheoLaudatQM
Copy link
Contributor

Hey @yomach, I like this one a lot and many customers are actually asking for such a tool.
What is preventing us from pushing it forward?

@yomach
Copy link
Collaborator Author

yomach commented Mar 19, 2024

Not much actually. I guess that we need to:

  1. Remove the hardware limitations from highpass_correction - make all functions return the ideal ones by default, and then have a separate function that can accept filters and change them according to the hardware limitations (and, it will accept an enum with a version in the future). That's at least the method I had in mind, Open to suggestions*.
  2. Add some tests
  3. Add to changelog & readme. Go over docstrings (I think I wrote them alright).

Do you have time to do it?

  • Maybe we can also have the main function accept an optional qop_version enum that will apply the hardware constrains if given, and return ideal ones if not.

@TheoLaudatQM
Copy link
Contributor

Cool!
Yes I can definitely give it a shot :)

@TheoLaudatQM TheoLaudatQM requested a review from KevinAVR March 27, 2024 08:56
@TheoLaudatQM TheoLaudatQM force-pushed the feature/filter_tools branch from 94a9d6b to decb673 Compare April 3, 2024 06:54
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@TheoLaudatQM TheoLaudatQM force-pushed the feature/filter_tools branch from 72f9593 to e96db1d Compare April 3, 2024 15:33
Copy link
Collaborator Author

@yomach yomach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far!

qualang_tools/digital_filters/README.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@TheoLaudatQM
Copy link
Contributor

TheoLaudatQM commented Apr 4, 2024

I fixed the function as we discussed and added some tests.
I have a question regarding the delay: you said:

if delay is not a multiple of the sampling rate, multiple FIR taps will be created.

But even with delay=11 and Ts=2, I get 111 taps resulting in an error so I wanted to raise an error if delay is not a multiple of the sampling time, what do you think?

@yomach
Copy link
Collaborator Author

yomach commented Apr 4, 2024

I fixed the function as we discussed and added some tests. I have a question regarding the delay: you said:

if delay is not a multiple of the sampling rate, multiple FIR taps will be created.

But even with delay=11 and Ts=2, I get 111 taps resulting in an error so I wanted to raise an error if delay is not a multiple of the sampling time, what do you think?

Ts = 2 is not a real scenario 😅 (Should be Ts = 0.5 for the OPX1000, in the future).
The relevant usecase, right now, is Ts=1 and delay=10.25.
We shouldn't raise an error, but we should allow trimming the number of taps (as part of applying the hardware limitation).
Something such as:

max_fir_taps = 44 - 7*len(feedback_taps)
if len(feedforward_taps)>max_fir_taps :
    feedforward_taps = feedforward_taps[:max_fir_taps ]

We can also add a message about it. I'm thinking something such as: summing the abs of the discarded FIR taps. If it's more than 0.01 (1%), give a warning, otherwise, just a debug message.
This is relevant because doing delay=1.5 would not really work (discarded taps will be >1%, probably ~10%), but delay=10.5 should be ok.

@TheoLaudatQM
Copy link
Contributor

Good point!
Although it is the same with Ts=1 and delay=10.5ns. It works more or less okay if no other fir and iir taps are needed, otherwise the outputted signal is crap because we don't have enough taps available I guess.
On the other hand, I never used it and I don't know how many customers do...

I also initiated the hardware limitation function, but I am not sure about the best implementation and about the correct values...

@yomach
Copy link
Collaborator Author

yomach commented Apr 8, 2024

I think that the errors/warning I suggested above would cover this "crap signal" scenario, WDYT?
We can discuss the hardware limitation.

qualang_tools/digital_filters/filters.py Show resolved Hide resolved
qualang_tools/digital_filters/filters.py Outdated Show resolved Hide resolved
qualang_tools/digital_filters/filters.py Outdated Show resolved Hide resolved
qualang_tools/digital_filters/filters.py Outdated Show resolved Hide resolved
qualang_tools/digital_filters/filters.py Outdated Show resolved Hide resolved
qualang_tools/digital_filters/filters.py Outdated Show resolved Hide resolved
@TheoLaudatQM TheoLaudatQM force-pushed the feature/filter_tools branch from 5d9ee58 to 1ae64d4 Compare April 9, 2024 06:55
@TheoLaudatQM
Copy link
Contributor

If we raise an error, then it will be solved, but if we only raise a warning, then the user will be notified about it but the OPX will still output something that can be harmful for the device...
Maybe I can add a safety option set to True by default that will raise an error and the user can set it to False if he still wants to output the signal. WDYT?

@yomach
Copy link
Collaborator Author

yomach commented Apr 9, 2024

If we raise an error, then it will be solved, but if we only raise a warning, then the user will be notified about it but the OPX will still output something that can be harmful for the device... Maybe I can add a safety option set to True by default that will raise an error and the user can set it to False if he still wants to output the signal. WDYT?

I don't think it can harm the device. Removing taps makes the OPX send smaller signals.
But I'm ok with the default being sending an error.

@TheoLaudatQM TheoLaudatQM force-pushed the feature/filter_tools branch from 3701ec1 to dcba422 Compare April 16, 2024 06:40
@TheoLaudatQM TheoLaudatQM marked this pull request as ready for review April 16, 2024 06:51
@TheoLaudatQM TheoLaudatQM force-pushed the feature/filter_tools branch 2 times, most recently from da6d4c8 to 86a5254 Compare April 18, 2024 13:29
@TheoLaudatQM TheoLaudatQM force-pushed the feature/filter_tools branch from 86a5254 to 61955b5 Compare April 18, 2024 13:32
@TheoLaudatQM TheoLaudatQM merged commit 0dc2c43 into main Apr 18, 2024
2 checks passed
@TheoLaudatQM TheoLaudatQM deleted the feature/filter_tools branch April 18, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants