fix(twpa): scope TWPA init dedup to active QUA program#137
Merged
Conversation
Replace process-global _initialized_ids with per-program scope tracking via scopes_manager.program_scope object identity, matching the intent of VoltageSequence while avoiding Python id() reuse across program blocks. Closes #122 Co-authored-by: Cursor <cursoragent@cursor.com>
JacobFastQM
reviewed
Jun 30, 2026
Mark _initialized_prog_scope as a skipped attribute so machine.save does not attempt to serialize the active QUA program scope object. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
|
LGTM! |
JacobFastQM
approved these changes
Jul 1, 2026
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.
Summary
Fixes #122: TWPA pump QUA was omitted from the second and later
with program()blocks in the same Python session, while flux DC offsets frominitialize_qpu()still appeared.Root cause:
TWPA.initialize()tracked initialization in a class-level_initialized_idsset keyed byid(self). That set lived for the entire Python process, so once a TWPA instance was initialized during any program compilation, all future compilations skipped it.Strategy: Scope deduplication to the active QUA
program()block by storing a reference toscopes_manager.program_scopeon each TWPA instance (_initialized_prog_scope). Initialization runs when the current scope object differs from the stored one, and is skipped wheninitialize_qpu()is called again inside the same block.This follows the same intent as
VoltageSequence._prog_id, but uses object identity (is) rather thanid()because Python may reuse integer ids after garbage collection of prior_ProgramScopeinstances, which would incorrectly suppress initialization in a new program.Behavior after fix
with program()block emits TWPA pump initialization QUA again.initialize_qpu()calls within the same program still deduplicate (unchanged intent).Type of Change
Test plan
pytest tests/test_twpa_initialize.pypytest tests/test_twpa_keepalive.py(no regression)pre-commit run --all-filesChecklist
[Unreleased] > FixedCloses #122
Made with Cursor