Skip to content

Commit

Permalink
Merge branch 'master' into feat/time_dependent_transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Dec 5, 2022
2 parents b93c1a6 + 63f1231 commit 775d459
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions changes.d/707.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed that single segment tables where always interpreted to be constant.
2 changes: 1 addition & 1 deletion qupulse/_program/waveforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _validate_input(input_waveform_table: Sequence[EntryInInit]) -> Union[Tuple[
raise ValueError('Negative time values are not allowed.')

# constant_v is None <=> the waveform is constant until up to the current entry
constant_v = first_interp.constant_value((previous_t, previous_v), (t, v))
constant_v = interp.constant_value((previous_t, previous_v), (t, v))

for next_t, next_v, next_interp in input_iter:
if next_t < t:
Expand Down
14 changes: 8 additions & 6 deletions qupulse/pulses/repetition_pulse_template.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This module defines RepetitionPulseTemplate, a higher-order hierarchical pulse template that
represents the n-times repetition of another PulseTemplate."""

from typing import Dict, List, Set, Optional, Union, Any, Mapping, cast
from typing import Dict, List, AbstractSet, Optional, Union, Any, Mapping, cast
from numbers import Real
from warnings import warn

Expand Down Expand Up @@ -87,12 +87,14 @@ def __str__(self) -> str:
.format(self._repetition_count, self.body)

@property
def parameter_names(self) -> Set[str]:
return set.union(self.body.parameter_names, self.repetition_count.variables, self.constrained_parameters,
self.measurement_parameters)
def parameter_names(self) -> AbstractSet[str]:
return set().union(self.body.parameter_names,
self.constrained_parameters,
self.measurement_parameters,
self.repetition_count.variables)

@property
def measurement_names(self) -> Set[str]:
def measurement_names(self) -> AbstractSet[str]:
return self.body.measurement_names | MeasurementDefiner.measurement_names.fget(self)

@property
Expand All @@ -104,7 +106,7 @@ def _internal_create_program(self, *,
measurement_mapping: Dict[str, Optional[str]],
channel_mapping: Dict[ChannelID, Optional[ChannelID]],
global_transformation: Optional['Transformation'],
to_single_waveform: Set[Union[str, 'PulseTemplate']],
to_single_waveform: AbstractSet[Union[str, 'PulseTemplate']],
parent_loop: Loop) -> None:
self.validate_scope(scope)

Expand Down
25 changes: 25 additions & 0 deletions tests/_program/waveforms_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,31 @@ def test_validate_input_errors(self):
TableWaveformEntry(-0.2, 0.2, HoldInterpolationStrategy()),
TableWaveformEntry(0.1, 0.2, HoldInterpolationStrategy())])

def test_validate_input_const_detection(self):
constant_table = [TableWaveformEntry(0.0, 2.5, HoldInterpolationStrategy()),
(1.4, 2.5, LinearInterpolationStrategy())]
linear_table = [TableWaveformEntry(0.0, 0.0, HoldInterpolationStrategy()),
TableWaveformEntry(1.4, 2.5, LinearInterpolationStrategy())]

self.assertEqual((1.4, 2.5), TableWaveform._validate_input(constant_table))
self.assertEqual(linear_table,
TableWaveform._validate_input(linear_table))

def test_const_detection_regression(self):
# regression test 707
from qupulse.pulses import PointPT
second_point_pt = PointPT([(0, 'v_0+v_1'),
('t_2', 'v_0', 'linear')],
channel_names=('A',),
measurements=[('M', 0, 1)])
parameters = dict(t=3,
t_2=2,
v_0=1,
v_1=1.4)
channel_mapping = {'A': 'A'}
wf = second_point_pt.build_waveform(parameters=parameters, channel_mapping=channel_mapping)
self.assertIsInstance(wf, TableWaveform)

def test_validate_input_duplicate_removal(self):
validated = TableWaveform._validate_input([TableWaveformEntry(0.0, 0.2, HoldInterpolationStrategy()),
TableWaveformEntry(0.1, 0.2, LinearInterpolationStrategy()),
Expand Down
8 changes: 4 additions & 4 deletions tests/pulses/repetition_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from qupulse._program._loop import Loop
from qupulse.expressions import Expression, ExpressionScalar
from qupulse.pulses import ConstantPT
from qupulse.pulses.repetition_pulse_template import RepetitionPulseTemplate,ParameterNotIntegerException
from qupulse.pulses.parameters import ParameterNotProvidedException, ParameterConstraintViolation, ConstantParameter, \
ParameterConstraint
Expand Down Expand Up @@ -48,10 +49,9 @@ def test_parameter_names_and_declarations(self) -> None:
self.assertEqual(body.parameter_names, t.parameter_names)

def test_parameter_names(self) -> None:
body = DummyPulseTemplate(parameter_names={'foo', 'bar'})
t = RepetitionPulseTemplate(body, 5, parameter_constraints={'foo > hugo'}, measurements=[('meas', 'd', 0)])

self.assertEqual({'foo', 'bar', 'hugo', 'd'}, t.parameter_names)
for body in [DummyPulseTemplate(parameter_names={'foo', 'bar'}), ConstantPT(1.4, {'A': 'foo', 'B': 'bar'})]:
t = RepetitionPulseTemplate(body, 5, parameter_constraints={'foo > hugo'}, measurements=[('meas', 'd', 0)])
self.assertEqual({'foo', 'bar', 'hugo', 'd'}, t.parameter_names)

def test_str(self) -> None:
body = DummyPulseTemplate()
Expand Down

0 comments on commit 775d459

Please sign in to comment.