Repository navigation
Raise at compile time for a gain outside [-1, 1], and warn when a gain rounds to 0 - #443
Merged
Merged
Conversation
… to 0 In asm_v2, the gain of a pulse is a fraction of full scale. A value past +/-1 does not fit in the gain register. Before this change, the register kept the low 16 bits, and the output wrapped with no error. The gain of tProc v1 code is in DAC units, for example gain=16000. In asm_v2, such a value gave an inverted output that wrapped. params2pulse now raises a RuntimeError if the gain, or the range of a gain sweep, is outside [-1, 1]. calc_muxgen_regs does the same check for mux_gains. A gain of exactly +/-1 still compiles. A nonzero gain that rounds to 0 now gives a warning. Fixes openquantumhardware#326. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks for this, and I am happy to accept the unit tests (for this PR, and also for #444 if you think any of the tests you ran for that PR are useful as unit tests) as a separate PR. If you include a Actions workflow to run the tests, that will be helpful. But whatever you have is appreciated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #326.
In asm_v2, gain is a fraction of full scale. A gain past ±1 goes into the gain register with no check, and the firmware keeps the low 16 bits, so the output wraps. Nothing fails.
We hit this on a ZCU111 with code that kept the tProc v1 habit of DAC units (
gain=2000..32766). On the DAC output, the amplitude rose to about 0.43 Vpp atgain=16000, then folded back to about 0 atgain=32766. It was also inverted.Changes:
params2pulseraises aRuntimeErrorif the gain of a pulse, or any value of a gain sweep, is outside [-1, 1]. This coversconst,arbandflat_top.calc_muxgen_regsraises if amux_gainsentry is outside [-1, 1], the range that thedeclare_gendocstring gives.Gains of exactly ±1, and sweeps that end at ±1, still compile.
Testing is compile only (no board), against
firmware/testbench/qick_testbench/soccfg.json(ZCU216,axis_signal_gen_v6, tProc v2). The cases:mux_gainsof 1.0, -1.0 and 0.3 give the expected rounded gain, while 1.5 and -2.0 raise.On this branch:
41 passed. On main, the same file gives23 failed, 18 passed. The 23 failures are exactly the new raise and warn cases.The test file is not in this PR because the repo has no unit-test folder. I can add it if you want one.