Skip to content

Commit feafac0

Browse files
committed
revert option to split pad_to to more waveforms
1 parent de1295a commit feafac0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

qupulse/pulses/pulse_template.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ def with_appended(self, *appended: 'PulseTemplate'):
376376
return self
377377

378378
def pad_to(self, to_new_duration: Union[ExpressionLike, Callable[[Expression], ExpressionLike]],
379+
as_single_wf: bool = True,
379380
pt_kwargs: Mapping[str, Any] = {}) -> 'PulseTemplate':
380381
"""Pad this pulse template to the given duration.
381382
The target duration can be numeric, symbolic or a callable that returns a new duration from the current
@@ -395,12 +396,18 @@ def pad_to(self, to_new_duration: Union[ExpressionLike, Callable[[Expression], E
395396
>>> padded_4 = my_pt.pad_to(to_next_multiple(1, 16))
396397
Args:
397398
to_new_duration: Duration or callable that maps the current duration to the new duration
399+
as_single_wf:
400+
- if PT is supposed ot be single element in memory, e.g.
401+
to conform to waveform-granularities, select True.
402+
(for nested PTs, pad_to on sub-PTs or pad_all_atomic recommened)
403+
- if used just as a mean to elongate last value, select False.
398404
pt_kwargs: Keyword arguments for the newly created sequence pulse template.
399405
400406
Returns:
401407
A pulse template that has the duration given by ``to_new_duration``.
402408
self if ConstantPT,
403-
SingleWFTimeExtensionPulseTemplate otherwise.
409+
else SingleWFTimeExtensionPulseTemplate if as_single_wf,
410+
else SequencePT
404411
"""
405412
from qupulse.pulses import ConstantPT, SequencePT
406413
from qupulse.pulses.time_extension_pulse_template import SingleWFTimeExtensionPulseTemplate
@@ -411,26 +418,24 @@ def pad_to(self, to_new_duration: Union[ExpressionLike, Callable[[Expression], E
411418
new_duration = ExpressionScalar(to_new_duration)
412419
pad_duration = new_duration - current_duration
413420

414-
# if not pt_kwargs and pad_duration == 0:
415-
# return self
416-
417421
#shortcut
418422
if isinstance(self,ConstantPT):
419423
if pt_kwargs:
420424
raise NotImplementedError()
421425
self._duration = new_duration
422426
return self
423427

424-
return SingleWFTimeExtensionPulseTemplate(self, new_duration, **pt_kwargs)
428+
if as_single_wf:
429+
return SingleWFTimeExtensionPulseTemplate(self, new_duration, **pt_kwargs)
425430

426-
# pad_duration = new_duration - current_duration
427-
# if not pt_kwargs and pad_duration == 0:
428-
# return self
429-
# pad_pt = ConstantPT(pad_duration, self.final_values)
430-
# if pt_kwargs:
431-
# return SequencePT(self, pad_pt, **pt_kwargs)
432-
# else:
433-
# return self @ pad_pt
431+
else:
432+
if not pt_kwargs and pad_duration == 0:
433+
return self
434+
pad_pt = ConstantPT(pad_duration, self.final_values)
435+
if pt_kwargs:
436+
return SequencePT(self, pad_pt, **pt_kwargs)
437+
else:
438+
return self @ pad_pt
434439

435440
def __format__(self, format_spec: str):
436441
if format_spec == '':

0 commit comments

Comments
 (0)