diff --git a/changes.d/692.feature b/changes.d/692.feature new file mode 100644 index 00000000..7cbdb46c --- /dev/null +++ b/changes.d/692.feature @@ -0,0 +1 @@ +Add `__pow__` as a repetition shortcut. This means you can do `my_pulse_template ** 5` or `my_pulse_template ** 'my_repetition_count'`. \ No newline at end of file diff --git a/qupulse/pulses/pulse_template.py b/qupulse/pulses/pulse_template.py index 57f756e2..f685bd08 100644 --- a/qupulse/pulses/pulse_template.py +++ b/qupulse/pulses/pulse_template.py @@ -96,6 +96,10 @@ def __rmatmul__(self, other: MappingTuple) -> 'SequencePulseTemplate': return SequencePulseTemplate.concatenate(other, self) + def __pow__(self, power: ExpressionLike): + """This is a convenience wrapper for :func:`.with_repetition`.""" + return self.with_repetition(power) + @property @abstractmethod def integral(self) -> Dict[ChannelID, ExpressionScalar]: diff --git a/tests/pulses/pulse_template_tests.py b/tests/pulses/pulse_template_tests.py index f8c0e241..8d4a5871 100644 --- a/tests/pulses/pulse_template_tests.py +++ b/tests/pulses/pulse_template_tests.py @@ -376,6 +376,11 @@ def test_matmul(self): self.assertEqual(a @ b, 'concat') mock_concatenate.assert_called_once_with(a, b) + def test_pow(self): + pt = PulseTemplateStub() + pow_pt = pt ** 5 + self.assertEqual(pow_pt, pt.with_repetition(5)) + def test_rmatmul(self): a = PulseTemplateStub() b = (1, 2, 3)