-
Notifications
You must be signed in to change notification settings - Fork 8
fix(twpa): scope TWPA init dedup to active QUA program #137
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """Tests for ``TWPA.initialize`` program scoping.""" | ||
|
|
||
| import pytest | ||
| from qm.qua import program | ||
|
|
||
| from quam.config.models.quam import QuamConfig | ||
| from quam.config.resolvers import get_quam_config | ||
| from quam.config.vars import CONFIG_PATH_ENV_NAME | ||
| from quam.components.ports import FEMPortsContainer | ||
|
|
||
| from quam_builder.architecture.superconducting.qpu import FixedFrequencyQuam | ||
| from quam_builder.builder.superconducting.modify_quam import add_qubit | ||
| from quam_builder.architecture.superconducting.components.twpa import TWPA | ||
| from quam_builder.architecture.superconducting.components.xy_drive import XYDriveMW | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def compatible_quam_config(tmp_path, monkeypatch): | ||
| """Use a qualibrate config that matches the installed quam package version.""" | ||
| config_file = tmp_path / "config.toml" | ||
| config_file.write_text(f"[quam]\nversion = {QuamConfig.version}\n") | ||
| monkeypatch.setenv(CONFIG_PATH_ENV_NAME, str(config_file)) | ||
| if hasattr(get_quam_config, "cache_clear"): | ||
| get_quam_config.cache_clear() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def machine() -> FixedFrequencyQuam: | ||
| """A machine with one TWPA configured for pump initialization.""" | ||
| machine = FixedFrequencyQuam(ports=FEMPortsContainer()) | ||
| add_qubit( | ||
| machine, | ||
| "q0", | ||
| { | ||
| "xy": {"opx_output": "#/ports/mw_outputs/con1/1/1"}, | ||
| "rr": { | ||
| "opx_output": "#/ports/mw_outputs/con1/2/1", | ||
| "opx_input": "#/ports/mw_inputs/con1/2/1", | ||
| }, | ||
| }, | ||
| ) | ||
| machine.active_qubit_names = ["q0"] | ||
| machine.twpas["twpa1"] = TWPA( | ||
| id="twpa1", | ||
| pump=XYDriveMW(opx_output="#/ports/mw_outputs/con1/7/1"), | ||
| pump_amplitude=0.5, | ||
| ) | ||
| return machine | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def record_pump_play(machine, monkeypatch): | ||
| """Record every call to the TWPA pump ``play`` method.""" | ||
| plays = [] | ||
|
|
||
| def record_play(*args, **kwargs): | ||
| plays.append(1) | ||
|
|
||
| monkeypatch.setattr(machine.twpas["twpa1"].pump, "play", record_play) | ||
| return plays | ||
|
|
||
|
|
||
| def test_twpa_initialize_once_per_program(machine, record_pump_play): | ||
| """Two initialize_qpu calls in one program block emit TWPA init only once.""" | ||
| with program(): | ||
| machine.initialize_qpu() | ||
| machine.initialize_qpu() | ||
|
|
||
| assert len(record_pump_play) == 1 | ||
|
|
||
|
|
||
| def test_twpa_initialize_in_each_program(machine, record_pump_play): | ||
| """Each new program block re-initializes the TWPA pump.""" | ||
| with program(): | ||
| machine.initialize_qpu() | ||
| assert len(record_pump_play) == 1 | ||
|
|
||
| with program(): | ||
| machine.initialize_qpu() | ||
| assert len(record_pump_play) == 2 |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.