Skip to content

Commit

Permalink
Add caching in getitem for an edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
thangleiter committed Oct 23, 2024
1 parent f4ca471 commit 4f18bc1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions filter_functions/pulse_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,21 @@ def __getitem__(self, key) -> 'PulseSequence':
d=self.d,
basis=self.basis
)

# An edge use case: key is a slice of the form slice(n), e.g.,
# pulse[:n], in which case the control matrix might already have
# been cached in the form of an intermediate
is_valid_slice = (
isinstance(key, slice)
and key.start in (None, 0)
and key.step in (None, 1)
)
if is_valid_slice and 'control_matrix_step_cumulative' in self._intermediates:
new.cache_control_matrix(
self.omega,
self._intermediates['control_matrix_step_cumulative'][key.stop]
)

return new

def __copy__(self) -> 'PulseSequence':
Expand Down

0 comments on commit 4f18bc1

Please sign in to comment.