Skip to content

Commit

Permalink
delete_Op now also deletes attached baked digital_waveform (#20)
Browse files Browse the repository at this point in the history
* delete_Op now also deletes attached baked digital_waveform

* Reformat
  • Loading branch information
arthurostrauss authored Aug 16, 2021
1 parent e79d3b8 commit 84abc1e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
29 changes: 21 additions & 8 deletions qualang_tools/bakery/bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,28 @@ def delete_baked_Op(self, *qe_set: str):
def remove_Op(q):
if self.length_constraint is None:
if self._out:
del self.config["elements"][q]["operations"][
if (
f"baked_Op_{self._ctr}"
]
del self.config["pulses"][f"{q}_baked_pulse_{self._ctr}"]
if "mixInputs" in self.config["elements"][q]:
del self.config["waveforms"][f"{q}_baked_wf_I_{self._ctr}"]
del self.config["waveforms"][f"{q}_baked_wf_Q_{self._ctr}"]
elif "singleInput" in self.config["elements"][q]:
del self.config["waveforms"][f"{q}_baked_wf_{self._ctr}"]
in self.config["elements"][q]["operations"]
):
del self.config["elements"][q]["operations"][
f"baked_Op_{self._ctr}"
]
del self.config["pulses"][f"{q}_baked_pulse_{self._ctr}"]
if "mixInputs" in self.config["elements"][q]:
del self.config["waveforms"][f"{q}_baked_wf_I_{self._ctr}"]
del self.config["waveforms"][f"{q}_baked_wf_Q_{self._ctr}"]
elif "singleInput" in self.config["elements"][q]:
del self.config["waveforms"][f"{q}_baked_wf_{self._ctr}"]
if "digital_waveforms" in self._config:
if (
f"{q}_baked_digital_wf_{self._ctr}"
in self._config["digital_waveforms"]
):
del self.config["digital_waveforms"][
f"{q}_baked_digital_wf_{self._ctr}"
]

else:
raise KeyError(
"delete_baked_Op only available outside of the context manager "
Expand Down
9 changes: 9 additions & 0 deletions qualang_tools/tests/test_bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ def test_delete_Op(config):
assert "baked_Op_0" not in cfg["elements"]["qe1"]["operations"]
assert "baked_Op_0" not in cfg["elements"]["qe2"]["operations"]

with baking(cfg) as b:
b.add_digital_waveform("dig_wf", [(1, 0)])
b.add_Op("new_Op", "qe1", [0.3] * 100, "dig_wf")
b.play("new_Op", "qe1")

assert "qe1_baked_digital_wf_0" in cfg["digital_waveforms"]
b.delete_baked_Op()
assert "qe1_baked_digital_wf_0" not in cfg["digital_waveforms"]


def test_indices_behavior(config):
cfg = deepcopy(config)
Expand Down

0 comments on commit 84abc1e

Please sign in to comment.