Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/missing measurement parameter inclusion #328

Merged
merged 3 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion qctoolkit/pulses/loop_pulse_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def duration(self) -> ExpressionScalar:
def parameter_names(self) -> Set[str]:
parameter_names = self.body.parameter_names.copy()
parameter_names.remove(self._loop_index)
return parameter_names | self._loop_range.parameter_names | self.constrained_parameters
return parameter_names | self._loop_range.parameter_names | self.constrained_parameters | self.measurement_parameters

def _body_parameter_generator(self, parameters: Dict[str, Parameter], forward=True) -> Generator:
loop_range_parameters = dict((parameter_name, parameters[parameter_name].get_value())
Expand Down
2 changes: 1 addition & 1 deletion qctoolkit/pulses/sequence_pulse_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self,

@property
def parameter_names(self) -> Set[str]:
return self.constrained_parameters.union(*(st.parameter_names for st in self.__subtemplates))
return self.constrained_parameters.union(self.measurement_parameters, *(st.parameter_names for st in self.__subtemplates))

@property
def subtemplates(self) -> List[MappingPulseTemplate]:
Expand Down
2 changes: 1 addition & 1 deletion qctoolkit/pulses/table_pulse_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def table_parameters(self) -> Set[str]:

@property
def parameter_names(self) -> Set[str]:
return self.table_parameters | self.measurement_parameters
return self.table_parameters | self.measurement_parameters | self.constrained_parameters

@property
def is_interruptable(self) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion tests/pulses/function_pulse_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def test_defined_channels(self) -> None:
self.assertEqual({'A'}, self.fpt.defined_channels)

def test_parameter_names(self):
self.assertEqual(self.fpt.parameter_names, {'a', 'b', 'c', 'd', 'x', 'z', 'j', 'u'})
fpt = FunctionPulseTemplate('k*r*sin(x)', '1.14*d', parameter_constraints={'x < hugo'}, measurements=[('meas', 'f', 1)])
self.assertEqual(fpt.parameter_names, {'k', 'r', 'x', 'd', 'hugo', 'f'})

def test_duration(self):
self.assertEqual(self.fpt.duration, self.s2)
Expand Down
6 changes: 3 additions & 3 deletions tests/pulses/loop_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def test_duration(self):

def test_parameter_names(self):
dt = DummyPulseTemplate(parameter_names={'i', 'k'})
flt = ForLoopPulseTemplate(body=dt, loop_index='i', loop_range=('a', 'b', 'c'))

self.assertEqual(flt.parameter_names, {'k', 'a', 'b', 'c'})
flt = ForLoopPulseTemplate(body=dt, loop_index='i', loop_range=('a', 'b', 'c'),
parameter_constraints={'c > hugo'}, measurements=[('meas', 'd', 1)])
self.assertEqual({'k', 'a', 'b', 'c', 'd', 'hugo'}, flt.parameter_names)

def test_parameter_names_param_only_in_constraint(self) -> None:
flt = ForLoopPulseTemplate(body=DummyPulseTemplate(parameter_names={'k', 'i'}), loop_index='i',
Expand Down
6 changes: 6 additions & 0 deletions tests/pulses/mapping_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def test_nested_mapping_avoidance(self):
self.assertIs(st_4.template, st_3)
self.assertEqual(st_4.parameter_mapping, {'t': 't', 'k': 'k', 'bar': 't*l'})

def test_parameter_names(self) -> None:
template = DummyPulseTemplate(parameter_names={'foo'}, measurement_names={'meas1'})
mt = MappingPulseTemplate(template, parameter_mapping={'foo': 't*k'}, parameter_constraints={'t >= m'},
measurement_mapping={'meas1': 'meas2'})
self.assertEqual({'t', 'k', 'm'}, mt.parameter_names)

def test_get_updated_channel_mapping(self):
template = DummyPulseTemplate(defined_channels={'foo', 'bar'})
st = MappingPulseTemplate(template, channel_mapping={'bar': 'kneipe'})
Expand Down
5 changes: 5 additions & 0 deletions tests/pulses/multi_channel_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def test_duration(self):

self.assertEqual(template.duration, 't1')

def test_parameter_names(self) -> None:
template = AtomicMultiChannelPulseTemplate(*zip(self.subtemplates, self.param_maps, self.chan_maps),
parameter_constraints={'pp1 > hugo'}, measurements={('meas', 'd', 1)})
self.assertEqual({'pp1', 'pp2', 'pp3', 'hugo', 'd'}, template.parameter_names)

def test_mapping_template_pure_conversion(self):
template = AtomicMultiChannelPulseTemplate(*zip(self.subtemplates, self.param_maps, self.chan_maps))

Expand Down
6 changes: 3 additions & 3 deletions tests/pulses/point_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def test_point_parameters(self):
{'A', 'B', 't', 'C'})

def test_parameter_names(self):
self.assertEqual(PointPulseTemplate([(1, 'A'), ('t+6', 'B+C')],
self.assertEqual({'a', 'b', 'n', 'A', 'B', 't', 'C'},
PointPulseTemplate([(1, 'A'), ('t+6', 'B+C')],
[0, 'asd'],
measurements=[('M', 'n', 1)],
parameter_constraints=['a < b']).parameter_names,
{'a', 'b', 'n', 'A', 'B', 't', 'C'})
parameter_constraints=['a < b']).parameter_names)

def test_integral(self) -> None:
pulse = PointPulseTemplate(
Expand Down
6 changes: 6 additions & 0 deletions tests/pulses/repetition_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def test_parameter_names_and_declarations(self) -> None:
body.parameter_names_ = {'foo', 't', 'bar'}
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)

@unittest.skip('is interruptable not implemented for loops')
def test_is_interruptable(self) -> None:
body = DummyPulseTemplate(is_interruptable=False)
Expand Down
7 changes: 4 additions & 3 deletions tests/pulses/sequence_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ def test_duration(self):
DummyPulseTemplate(duration='b'))
self.assertEqual(pt.duration, Expression('a+a+b'))

def test_parameter_names_param_only_in_constraint(self) -> None:
pt = SequencePulseTemplate(DummyPulseTemplate(parameter_names={'a'}), DummyPulseTemplate(parameter_names={'b'}), parameter_constraints=['a==b', 'a<c'])
self.assertEqual(pt.parameter_names, {'a','b','c'})
def test_parameter_names(self) -> None:
pt = SequencePulseTemplate(DummyPulseTemplate(parameter_names={'a'}), DummyPulseTemplate(parameter_names={'b'}),
parameter_constraints=['a==b', 'a<c'], measurements=[('meas', 'd', 1)])
self.assertEqual({'a', 'b', 'c', 'd'}, pt.parameter_names, )

def test_build_waveform(self):
wfs = [DummyWaveform(), DummyWaveform()]
Expand Down
4 changes: 4 additions & 0 deletions tests/pulses/table_pulse_template_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def test_time_not_increasing_hard(self):
('b', 1),
('c*a', 'k')]}, parameter_constraints=['a*c < b'])

def test_parameter_names(self) -> None:
table = TablePulseTemplate({'a': [('foo', 'bar')]}, parameter_constraints=['foo < hugo'], measurements=[('meas', 'd', 2)])
self.assertEqual({'foo', 'bar', 'hugo', 'd'}, table.parameter_names)

def test_time_is_0_on_construction(self) -> None:
with self.assertWarns(ZeroDurationTablePulseTemplate):
warnings.simplefilter('default', ZeroDurationTablePulseTemplate)
Expand Down