Skip to content

Commit

Permalink
Merge pull request #788 from qutech/issues/692_pow
Browse files Browse the repository at this point in the history
Add __pow__ convenience repetition operation.
  • Loading branch information
terrorfisch authored Aug 25, 2023
2 parents e36e4cc + 1b0c991 commit 86205e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes.d/692.feature
Original file line number Diff line number Diff line change
@@ -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'`.
4 changes: 4 additions & 0 deletions qupulse/pulses/pulse_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
5 changes: 5 additions & 0 deletions tests/pulses/pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 86205e6

Please sign in to comment.