Skip to content

Commit 4f18bc1

Browse files
committed
Add caching in getitem for an edge case
1 parent f4ca471 commit 4f18bc1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

filter_functions/pulse_sequence.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ def __getitem__(self, key) -> 'PulseSequence':
407407
d=self.d,
408408
basis=self.basis
409409
)
410+
411+
# An edge use case: key is a slice of the form slice(n), e.g.,
412+
# pulse[:n], in which case the control matrix might already have
413+
# been cached in the form of an intermediate
414+
is_valid_slice = (
415+
isinstance(key, slice)
416+
and key.start in (None, 0)
417+
and key.step in (None, 1)
418+
)
419+
if is_valid_slice and 'control_matrix_step_cumulative' in self._intermediates:
420+
new.cache_control_matrix(
421+
self.omega,
422+
self._intermediates['control_matrix_step_cumulative'][key.stop]
423+
)
424+
410425
return new
411426

412427
def __copy__(self) -> 'PulseSequence':

0 commit comments

Comments
 (0)