Skip to content

fix(twpa): scope TWPA init dedup to active QUA program#137

Merged
arthurostrauss merged 2 commits into
mainfrom
fix/122-twpa-init-per-program
Jul 2, 2026
Merged

fix(twpa): scope TWPA init dedup to active QUA program#137
arthurostrauss merged 2 commits into
mainfrom
fix/122-twpa-init-per-program

Conversation

@arthurostrauss

Copy link
Copy Markdown
Contributor

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 from initialize_qpu() still appeared.

Root cause: TWPA.initialize() tracked initialization in a class-level _initialized_ids set keyed by id(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 to scopes_manager.program_scope on each TWPA instance (_initialized_prog_scope). Initialization runs when the current scope object differs from the stored one, and is skipped when initialize_qpu() is called again inside the same block.

This follows the same intent as VoltageSequence._prog_id, but uses object identity (is) rather than id() because Python may reuse integer ids after garbage collection of prior _ProgramScope instances, which would incorrectly suppress initialization in a new program.

Behavior after fix

  • Each new with program() block emits TWPA pump initialization QUA again.
  • Multiple initialize_qpu() calls within the same program still deduplicate (unchanged intent).
  • No API changes for downstream consumers (e.g. qiskit-qm-provider, notebooks).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Test addition/update

Test plan

  • pytest tests/test_twpa_initialize.py
  • pytest tests/test_twpa_keepalive.py (no regression)
  • pre-commit run --all-files

Checklist

  • CHANGELOG.md updated under [Unreleased] > Fixed
  • Commits follow Conventional Commits (commitizen)
  • Pre-commit hooks pass (black, pylint)

Closes #122

Made with Cursor

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>
Comment thread quam_builder/architecture/superconducting/components/twpa.py
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>
@JacobFastQM

Copy link
Copy Markdown
Contributor

LGTM!

@JacobFastQM JacobFastQM marked this pull request as ready for review July 1, 2026 15:35
@arthurostrauss arthurostrauss merged commit b2056cd into main Jul 2, 2026
5 checks passed
@arthurostrauss arthurostrauss deleted the fix/122-twpa-init-per-program branch July 2, 2026 02:42
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.

[Bug]: TWPA.initialize() uses process-global _initialized_ids, causing TWPA QUA to be omitted from subsequent programs

2 participants