Skip to content

Raise at compile time for a gain outside [-1, 1], and warn when a gain rounds to 0 - #443

Merged
meeg merged 4 commits into
openquantumhardware:mainfrom
jinchen-zhao:gain-range-check
Nov 6, 2026
Merged

meeg merged 4 commits into
openquantumhardware:mainfrom
jinchen-zhao:gain-range-check

Conversation

@jinchen-zhao

Copy link
Copy Markdown
Contributor

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 at gain=16000, then folded back to about 0 at gain=32766. It was also inverted.

Changes:

  1. params2pulse raises a RuntimeError if the gain of a pulse, or any value of a gain sweep, is outside [-1, 1]. This covers const, arb and flat_top.
  2. calc_muxgen_regs raises if a mux_gains entry is outside [-1, 1], the range that the declare_gen docstring gives.
  3. Both give a warning if a nonzero gain rounds to 0, which is the other half of Minimum/Maximum gain value warnings #326.

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:

  • gains ±1, 0.5 and 0 compile for each style;
  • gains 1.5, -1.01, 2000, 16000 and 32766 raise for each style;
  • a sweep 0 → 1 compiles, while 0 → 1.5 and -1.5 → 0 raise;
  • a gain of 1e-5 warns, and gains of 0 and 0.01 do not;
  • mux_gains of 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 gives 23 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.

jinchen-zhao and others added 4 commits November 3, 2026 17:07
… 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>
@meeg
meeg merged commit 08a1a69 into openquantumhardware:main Nov 6, 2026
3 checks passed
@meeg

meeg commented Nov 6, 2026

Copy link
Copy Markdown
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.

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.

Minimum/Maximum gain value warnings

3 participants