def test_internal_create_program_both_children_no_duration(self) -> None: sub1 = DummyPulseTemplate(duration=0, waveform=None, measurements=[('b', 1, 2)], defined_channels={'A'}) sub2 = DummyPulseTemplate(duration=0, waveform=None, parameter_names={'foo'}, defined_channels={'A'}) scope = DictScope.from_kwargs() measurement_mapping = {'a': 'a', 'b': 'b'} channel_mapping = dict() seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)]) loop = Loop(measurements=None) seq._internal_create_program(scope=scope, measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, global_transformation=None, to_single_waveform=set(), parent_loop=loop) self.assertEqual(1, loop.repetition_count) self.assertIsNone(loop.waveform) self.assertEqual([], list(loop.children)) self.assertIsNone(loop._measurements)
def test_internal_create_program_both_children_no_duration(self) -> None: sub1 = DummyPulseTemplate(duration=0, waveform=None, measurements=[('b', 1, 2)], defined_channels={'A'}) sub2 = DummyPulseTemplate(duration=0, waveform=None, parameter_names={'foo'}, defined_channels={'A'}) parameters = {'foo': DummyNoValueParameter()} measurement_mapping = {'a': 'a', 'b': 'b'} channel_mapping = dict() seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)]) loop = Loop(measurements=None) seq._internal_create_program(parameters=parameters, measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, global_transformation=None, to_single_waveform=set(), parent_loop=loop) self.assertEqual(1, loop.repetition_count) self.assertIsNone(loop.waveform) self.assertEqual([], loop.children) self.assertIsNone(loop._measurements) # ensure same result as from Sequencer sequencer = Sequencer() sequencer.push(seq, parameters=parameters, conditions={}, window_mapping=measurement_mapping, channel_mapping=channel_mapping) block = sequencer.build() old_program = MultiChannelProgram(block, channels={'A'}) old_loop = old_program.programs[frozenset({'A'})] self.assertEqual(old_loop.waveform, loop.waveform) self.assertEqual(old_loop.children, loop.children)
def test_multiple_channels_mismatch(self) -> None: with self.assertRaises(ValueError): SequencePulseTemplate(DummyPulseTemplate(defined_channels={'A'}), DummyPulseTemplate(defined_channels={'B'})) with self.assertRaises(ValueError): SequencePulseTemplate( DummyPulseTemplate(defined_channels={'A'}), DummyPulseTemplate(defined_channels={'A', 'B'}))
def test_is_interruptable(self): self.assertTrue( SequencePulseTemplate(DummyPulseTemplate(is_interruptable=True), DummyPulseTemplate(is_interruptable=True)).is_interruptable) self.assertTrue( SequencePulseTemplate(DummyPulseTemplate(is_interruptable=True), DummyPulseTemplate(is_interruptable=False)).is_interruptable) self.assertFalse( SequencePulseTemplate(DummyPulseTemplate(is_interruptable=False), DummyPulseTemplate(is_interruptable=False)).is_interruptable)
def test_zero_duration(self): p1 = ConstantPulseTemplate(10, {'P1': 1.}) p2 = ConstantPulseTemplate(0, {'P1': 1.}) p3 = ConstantPulseTemplate(2, {'P1': 1.}) _ = qupulse.pulses.plotting.render(p1.create_program()) pulse = SequencePulseTemplate(p1, p2, p3) prog = pulse.create_program() _ = qupulse.pulses.plotting.render(prog) self.assertEqual(pulse.duration, 12)
def test_internal_create_program_parameter_constraint_violations(self) -> None: sub1 = DummyPulseTemplate(duration=3, waveform=DummyWaveform(duration=3), measurements=[('b', 1, 2)]) sub2 = DummyPulseTemplate(duration=2, waveform=DummyWaveform(duration=2), parameter_names={'foo'}) parameters = {'foo': ConstantParameter(7)} seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)], parameter_constraints={'foo < 2'}) loop = Loop() with self.assertRaises(ParameterConstraintViolation): seq._internal_create_program(parameters=parameters, measurement_mapping={'a': 'a', 'b': 'b'}, channel_mapping=dict(), global_transformation=None, to_single_waveform=set(), parent_loop=loop)
def test_internal_create_program_parameter_missing(self) -> None: sub1 = DummyPulseTemplate(duration=3, waveform=DummyWaveform(duration=3), measurements=[('b', 1, 2)]) sub2 = DummyPulseTemplate(duration='d', waveform=DummyWaveform(duration=2), parameter_names={'foo'}) seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 'bar', 1)], parameter_constraints={'foo < 2'}) loop = Loop() # test parameter from constraints parameters = {} with self.assertRaises(ParameterNotProvidedException): seq._internal_create_program(parameters=parameters, measurement_mapping={'a': 'a', 'b': 'b'}, channel_mapping=dict(), global_transformation=None, to_single_waveform=set(), parent_loop=loop) # test parameter from measurements parameters = {'foo': ConstantParameter(1)} with self.assertRaises(ParameterNotProvidedException): seq._internal_create_program(parameters=parameters, measurement_mapping={'a': 'a', 'b': 'b'}, channel_mapping=dict(), global_transformation=None, to_single_waveform=set(), parent_loop=loop) # test parameter from duration parameters = {'foo': ConstantParameter(1), 'bar': ConstantParameter(0)} with self.assertRaises(ParameterNotProvidedException): seq._internal_create_program(parameters=parameters, measurement_mapping={'a': 'a', 'b': 'b'}, channel_mapping=dict(), global_transformation=None, to_single_waveform=set(), parent_loop=loop)
def test_deserialize_old(self) -> None: # test for deprecated version during transition period, remove after final switch with self.assertWarnsRegex( DeprecationWarning, "deprecated", msg= "SequencePT does not issue warning for old serialization routines." ): dummy1 = DummyPulseTemplate() dummy2 = DummyPulseTemplate() serializer = DummySerializer( serialize_callback=lambda x: str(id(x))) data = dict(subtemplates=[ serializer.dictify(dummy1), serializer.dictify(dummy2) ], identifier='foo', parameter_constraints=['a < b'], measurements=[('m', 0, 1)]) template = SequencePulseTemplate.deserialize(serializer, **data) self.assertEqual(template.subtemplates, [dummy1, dummy2]) self.assertEqual(template.parameter_constraints, [ParameterConstraint('a<b')]) self.assertEqual(template.measurement_declarations, [('m', 0, 1)])
def test_measurement_names(self): d1 = DummyPulseTemplate(measurement_names={'a'}) d2 = DummyPulseTemplate(measurement_names={'b'}) spt = SequencePulseTemplate(d1, d2, measurements=[('c', 0, 1)]) self.assertEqual(spt.measurement_names, {'a', 'b', 'c'})
def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) # Setup test data self.square = TablePulseTemplate( { 'default': [(0, 0), ('up', 'v', 'hold'), ('down', 0, 'hold'), ('length', 0)] }, measurements=[('mw1', 'up', 'length-up')]) self.mapping1 = { 'up': 'uptime', 'down': 'uptime + length', 'v': 'voltage', 'length': '0.5 * pulse_length' } self.window_name_mapping = {'mw1': 'test_window'} self.outer_parameters = {'uptime', 'length', 'pulse_length', 'voltage'} self.parameters = dict() self.parameters['uptime'] = ConstantParameter(5) self.parameters['length'] = ConstantParameter(10) self.parameters['pulse_length'] = ConstantParameter(100) self.parameters['voltage'] = ConstantParameter(10) self.sequence = SequencePulseTemplate( MappingPulseTemplate(self.square, parameter_mapping=self.mapping1, measurement_mapping=self.window_name_mapping))
def test_internal_create_program(self): sub_templates = PulseTemplateStub(defined_channels={'a'}, duration=ExpressionScalar('t1')),\ PulseTemplateStub(defined_channels={'a'}, duration=ExpressionScalar('t2')) wfs = DummyWaveform(duration=1), DummyWaveform(duration=2) spt = SequencePulseTemplate(*sub_templates, measurements=[('m', 'a', 'b')]) kwargs = dict(scope=DictScope.from_kwargs(t1=.4, t2=.5, a=.1, b=.2, irrelevant=42), measurement_mapping={'m': 'l'}, channel_mapping={'g': 'h'}, global_transformation=TransformationStub(), to_single_waveform={'to', 'single', 'waveform'}) program = Loop() expected_program = Loop( children=[Loop(waveform=wfs[0]), Loop(waveform=wfs[1])], measurements=[('l', .1, .2)]) with mock.patch.object(spt, 'validate_scope') as validate_scope: with mock.patch.object(spt, 'get_measurement_windows', return_value=[('l', .1, .2) ]) as get_measurement_windows: with mock.patch.object(sub_templates[0], '_create_program', wraps=get_appending_internal_create_program(wfs[0], True)) as create_0,\ mock.patch.object(sub_templates[1], '_create_program', wraps=get_appending_internal_create_program(wfs[1], True)) as create_1: spt._internal_create_program(**kwargs, parent_loop=program) self.assertEqual(expected_program, program) validate_scope.assert_called_once_with(kwargs['scope']) get_measurement_windows.assert_called_once_with( kwargs['scope'], kwargs['measurement_mapping']) create_0.assert_called_once_with(**kwargs, parent_loop=program) create_1.assert_called_once_with(**kwargs, parent_loop=program)
def __matmul__( self, other: Union['PulseTemplate', MappingTuple]) -> 'SequencePulseTemplate': """This method enables using the @-operator (intended for matrix multiplication) for concatenating pulses. If one of the pulses is a SequencePulseTemplate the other pulse gets merged into it""" from qupulse.pulses.sequence_pulse_template import SequencePulseTemplate return SequencePulseTemplate.concatenate(self, other)
def test_regression_sequencept_with_mappingpt(self): t1 = TablePT({'C1': [(0, 0), (100, 0)], 'C2': [(0, 1), (100, 1)]}) t2 = ConstantPulseTemplate(200, {'C1': 2, 'C2': 3}) qupulse_template = SequencePulseTemplate(t1, t2) channel_mapping = {'C1': None, 'C2': 'C2'} p = MappingPT(qupulse_template, channel_mapping=channel_mapping) plot(p) self.assertEqual(p.defined_channels, {'C2'})
def test_integral(self) -> None: dummy1 = DummyPulseTemplate(defined_channels={'A', 'B'}, integrals={'A': ExpressionScalar('k+2*b'), 'B': ExpressionScalar('3')}) dummy2 = DummyPulseTemplate(defined_channels={'A', 'B'}, integrals={'A': ExpressionScalar('7*(b-f)'), 'B': ExpressionScalar('0.24*f-3.0')}) pulse = SequencePulseTemplate(dummy1, dummy2) self.assertEqual({'A': ExpressionScalar('k+2*b+7*(b-f)'), 'B': ExpressionScalar('0.24*f')}, pulse.integral)
def test_external_parameters_warning(self): dummy = DummyPulseTemplate() with self.assertWarnsRegex( DeprecationWarning, "external_parameters", msg= "SequencePT did not issue a warning for argument external_parameters" ): SequencePulseTemplate(dummy, external_parameters={'a'})
def test_get_serialization_data_old(self) -> None: # test for deprecated version during transition period, remove after final switch with self.assertWarnsRegex(DeprecationWarning, "deprecated", msg="SequencePT does not issue warning for old serialization routines."): dummy1 = DummyPulseTemplate() dummy2 = DummyPulseTemplate() sequence = SequencePulseTemplate(dummy1, dummy2, parameter_constraints=['a<b'], measurements=[('m', 0, 1)], registry=dict()) serializer = DummySerializer(serialize_callback=lambda x: str(x)) expected_data = dict( subtemplates=[str(dummy1), str(dummy2)], parameter_constraints=['a < b'], measurements=[('m', 0, 1)] ) data = sequence.get_serialization_data(serializer) self.assertEqual(expected_data, data)
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_crash(self) -> None: table = TablePulseTemplate({'default': [('ta', 'va', 'hold'), ('tb', 'vb', 'linear'), ('tend', 0, 'jump')]}, identifier='foo') expected_parameters = {'ta', 'tb', 'tc', 'td', 'va', 'vb', 'tend'} first_mapping = { 'ta': 'ta', 'tb': 'tb', 'va': 'va', 'vb': 'vb', 'tend': 'tend' } second_mapping = { 'ta': 'tc', 'tb': 'td', 'va': 'vb', 'vb': 'va + vb', 'tend': '2 * tend' } sequence = SequencePulseTemplate((table, first_mapping, {}), (table, second_mapping, {})) self.assertEqual(expected_parameters, sequence.parameter_names) parameters = { 'ta': ConstantParameter(2), 'va': ConstantParameter(2), 'tb': ConstantParameter(4), 'vb': ConstantParameter(3), 'tc': ConstantParameter(5), 'td': ConstantParameter(11), 'tend': ConstantParameter(6)} sequencer = DummySequencer() block = DummyInstructionBlock() self.assertFalse(sequence.requires_stop(parameters, {})) sequence.build_sequence(sequencer, parameters=parameters, conditions={}, measurement_mapping={}, channel_mapping={'default': 'default'}, instruction_block=block) from qupulse.pulses.sequencing import Sequencer s = Sequencer() s.push(sequence, parameters, channel_mapping={'default': 'EXAMPLE_A'})
def test_build_waveform(self): wfs = [DummyWaveform(), DummyWaveform()] pts = [DummyPulseTemplate(waveform=wf) for wf in wfs] spt = SequencePulseTemplate(*pts, parameter_constraints=['a < 3']) with self.assertRaises(ParameterConstraintViolation): spt.build_waveform(dict(a=4), dict()) parameters = dict(a=2) channel_mapping = dict() wf = spt.build_waveform(parameters, channel_mapping=channel_mapping) for wfi, pt in zip(wfs, pts): self.assertEqual(pt.build_waveform_calls, [(parameters, dict())]) self.assertIs(pt.build_waveform_calls[0][0], parameters) self.assertIsInstance(wf, SequenceWaveform) for wfa, wfb in zip(wf.compare_key, wfs): self.assertIs(wfa, wfb)
def test_internal_create_program_one_child_no_duration(self) -> None: sub1 = DummyPulseTemplate(duration=0, waveform=None, measurements=[('b', 1, 2)], defined_channels={'A'}) sub2 = DummyPulseTemplate(duration=2, waveform=DummyWaveform(duration=2), parameter_names={'foo'}, defined_channels={'A'}) scope = DictScope.from_kwargs() measurement_mapping = {'a': 'a', 'b': 'b'} channel_mapping = dict() seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)]) loop = Loop() seq._internal_create_program(scope=scope, measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, global_transformation=None, to_single_waveform=set(), parent_loop=loop) self.assertEqual(1, loop.repetition_count) self.assertIsNone(loop.waveform) self.assertEqual([Loop(repetition_count=1, waveform=sub2.waveform)], list(loop.children)) self.assert_measurement_windows_equal({'a': ([0], [1])}, loop.get_measurement_windows()) # MultiChannelProgram calls cleanup loop.cleanup() self.assert_measurement_windows_equal({'a': ([0], [1])}, loop.get_measurement_windows()) ### test again with inverted sequence seq = SequencePulseTemplate(sub2, sub1, measurements=[('a', 0, 1)]) loop = Loop() seq._internal_create_program(scope=scope, measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, global_transformation=None, to_single_waveform=set(), parent_loop=loop) self.assertEqual(1, loop.repetition_count) self.assertIsNone(loop.waveform) self.assertEqual([Loop(repetition_count=1, waveform=sub2.waveform)], list(loop.children)) self.assert_measurement_windows_equal({'a': ([0], [1])}, loop.get_measurement_windows()) # MultiChannelProgram calls cleanup loop.cleanup() self.assert_measurement_windows_equal({'a': ([0], [1])}, loop.get_measurement_windows())
def test_multiple_channels(self) -> None: dummy = DummyPulseTemplate(parameter_names={'hugo'}, defined_channels={'A', 'B'}) subtemplates = [(dummy, { 'hugo': 'foo' }, {}), (dummy, { 'hugo': '3' }, {})] sequence = SequencePulseTemplate(*subtemplates) self.assertEqual({'A', 'B'}, sequence.defined_channels) self.assertEqual({'foo'}, sequence.parameter_names)
def test_create_program_internal(self) -> None: sub1 = DummyPulseTemplate(duration=3, waveform=DummyWaveform(duration=3), measurements=[('b', 1, 2)], defined_channels={'A'}) sub2 = DummyPulseTemplate(duration=2, waveform=DummyWaveform(duration=2), parameter_names={'foo'}, defined_channels={'A'}) parameters = {'foo': DummyNoValueParameter()} measurement_mapping = {'a': 'a', 'b': 'b'} channel_mapping = dict() seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)]) loop = Loop() seq._internal_create_program(parameters=parameters, measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, global_transformation=None, to_single_waveform=set(), parent_loop=loop) self.assertEqual(1, loop.repetition_count) self.assertIsNone(loop.waveform) self.assertEqual([Loop(repetition_count=1, waveform=sub1.waveform), Loop(repetition_count=1, waveform=sub2.waveform)], loop.children) self.assert_measurement_windows_equal({'a': ([0], [1]), 'b': ([1], [2])}, loop.get_measurement_windows()) # ensure same result as from Sequencer sequencer = Sequencer() sequencer.push(seq, parameters=parameters, conditions={}, window_mapping=measurement_mapping, channel_mapping=channel_mapping) block = sequencer.build() old_program = MultiChannelProgram(block, channels={'A'}) self.assertEqual(old_program.programs[frozenset({'A'})], loop) ### test again with inverted sequence seq = SequencePulseTemplate(sub2, sub1, measurements=[('a', 0, 1)]) loop = Loop() seq._internal_create_program(parameters=parameters, measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, global_transformation=None, to_single_waveform=set(), parent_loop=loop) self.assertEqual(1, loop.repetition_count) self.assertIsNone(loop.waveform) self.assertEqual([Loop(repetition_count=1, waveform=sub2.waveform), Loop(repetition_count=1, waveform=sub1.waveform)], loop.children) self.assert_measurement_windows_equal({'a': ([0], [1]), 'b': ([3], [2])}, loop.get_measurement_windows()) # ensure same result as from Sequencer sequencer = Sequencer() sequencer.push(seq, parameters=parameters, conditions={}, window_mapping=measurement_mapping, channel_mapping=channel_mapping) block = sequencer.build() old_program = MultiChannelProgram(block, channels={'A'}) self.assertEqual(old_program.programs[frozenset({'A'})], loop)
def test_internal_create_program_no_measurement_mapping(self) -> None: sub1 = DummyPulseTemplate(duration=3, waveform=DummyWaveform(duration=3), measurements=[('b', 1, 2)]) sub2 = DummyPulseTemplate(duration=2, waveform=DummyWaveform(duration=2), parameter_names={'foo'}) parameters = {'foo': DummyNoValueParameter()} seq = SequencePulseTemplate(sub1, sub2, measurements=[('a', 0, 1)]) children = [Loop(waveform=DummyWaveform())] loop = Loop(measurements=[], children=children) with self.assertRaises(KeyError): seq._internal_create_program(parameters=parameters, measurement_mapping=dict(), channel_mapping=dict(), global_transformation=None, to_single_waveform=set(), parent_loop=loop) self.assertFalse(sub1.create_program_calls) self.assertFalse(sub2.create_program_calls) self.assertEqual(children, loop.children) self.assertEqual(1, loop.repetition_count) self.assertIsNone(loop.waveform) self.assert_measurement_windows_equal({}, loop.get_measurement_windows()) # test for child level measurements (does not guarantee to leave parent_loop unchanged in this case) with self.assertRaises(KeyError): seq._internal_create_program(parameters=parameters, measurement_mapping=dict(a='a'), channel_mapping=dict(), global_transformation=None, to_single_waveform=set(), parent_loop=loop)
def test_plotting_two_channel_function_pulse_after_two_channel_table_pulse_crash( self) -> None: """ successful if no crash -> no asserts """ template = TablePulseTemplate(entries={ 'A': [(0, 0), ('ta', 'va', 'hold'), ('tb', 'vb', 'linear'), ('tend', 0, 'jump')], 'B': [(0, 0), ('ta', '-va', 'hold'), ('tb', '-vb', 'linear'), ('tend', 0, 'jump')] }, measurements=[('m', 0, 'ta'), ('n', 'tb', 'tend-tb')]) parameters = { 'ta': 2, 'va': 2, 'tb': 4, 'vb': 3, 'tc': 5, 'td': 11, 'tend': 6 } _ = plot(template, parameters, sample_rate=100, show=False, plot_measurements={'m', 'n'}) repeated_template = RepetitionPulseTemplate(template, 'n_rep') sine_template = FunctionPulseTemplate('sin_a*sin(t)', '2*3.1415') two_channel_sine_template = AtomicMultiChannelPulseTemplate( (sine_template, { 'default': 'A' }), (sine_template, { 'default': 'B' }, { 'sin_a': 'sin_b' })) sequence_template = SequencePulseTemplate(repeated_template, two_channel_sine_template) #sequence_template = SequencePulseTemplate(two_channel_sine_template, repeated_template) # this was working fine sequence_parameters = dict( parameters) # we just copy our parameter dict from before sequence_parameters[ 'n_rep'] = 4 # and add a few new values for the new params from the sine wave sequence_parameters['sin_a'] = 1 sequence_parameters['sin_b'] = 2 _ = plot(sequence_template, parameters=sequence_parameters, sample_rate=100, show=False)
def integrated_test_with_sequencer_and_pulse_templates(self) -> None: # Setup test data square = TablePulseTemplate() square.add_entry('up', 'v', 'hold') square.add_entry('down', 0, 'hold') square.add_entry('length', 0) mapping1 = { 'up': 'uptime', 'down': 'uptime + length', 'v': 'voltage', 'length': '0.5 * pulse_length' } outer_parameters = ['uptime', 'length', 'pulse_length', 'voltage'] parameters = {} parameters['uptime'] = 5 parameters['length'] = 10 parameters['pulse_length'] = 100 parameters['voltage'] = 10 sequence = SequencePulseTemplate([(square, mapping1), (square, mapping1)], outer_parameters) # render the plot sample_rate = 20 program = sequence.create_program(parameters=parameters) times, voltages = render(program, sample_rate=sample_rate) # compute expected values expected_times = numpy.linspace(0, 100, sample_rate) expected_voltages = numpy.zeros_like(expected_times) expected_voltages[100:300] = numpy.ones(200) * parameters['voltage'] # compare self.assertEqual(expected_times, times) self.assertEqual(expected_voltages, voltages)
def test_concatenate(self): a = DummyPulseTemplate(parameter_names={'foo'}, defined_channels={'A'}) b = DummyPulseTemplate(parameter_names={'bar'}, defined_channels={'A'}) spt_anon = SequencePulseTemplate(a, b) spt_id = SequencePulseTemplate(a, b, identifier='id') spt_meas = SequencePulseTemplate(a, b, measurements=[('m', 0, 'd')]) spt_constr = SequencePulseTemplate(a, b, parameter_constraints=['a < b']) merged = SequencePulseTemplate.concatenate(a, spt_anon, b) self.assertEqual(merged.subtemplates, [a, a, b, b]) result = SequencePulseTemplate.concatenate(a, spt_id, b) self.assertEqual(result.subtemplates, [a, spt_id, b]) result = SequencePulseTemplate.concatenate(a, spt_meas, b) self.assertEqual(result.subtemplates, [a, spt_meas, b]) result = SequencePulseTemplate.concatenate(a, spt_constr, b) self.assertEqual(result.subtemplates, [a, spt_constr, b])
def test_build_sequence(self) -> None: sub1 = DummyPulseTemplate(requires_stop=False) sub2 = DummyPulseTemplate(requires_stop=True, parameter_names={'foo'}) parameters = {'foo': DummyNoValueParameter()} sequencer = DummySequencer() block = DummyInstructionBlock() seq = SequencePulseTemplate(sub1, (sub2, {'foo': 'foo'}), measurements=[('a', 0, 1)]) seq.build_sequence(sequencer, parameters, conditions=dict(), channel_mapping={'default': 'a'}, measurement_mapping={'a': 'b'}, instruction_block=block) self.assertEqual(2, len(sequencer.sequencing_stacks[block])) self.assertEqual(block.instructions[0], MEASInstruction([('b', 0, 1)])) sequencer = DummySequencer() block = DummyInstructionBlock() seq = SequencePulseTemplate((sub2, {'foo': 'foo'}), sub1) seq.build_sequence(sequencer, parameters, {}, {}, {}, block) self.assertEqual(2, len(sequencer.sequencing_stacks[block]))
def __rmatmul__(self, other: MappingTuple) -> 'SequencePulseTemplate': from qupulse.pulses.sequence_pulse_template import SequencePulseTemplate return SequencePulseTemplate.concatenate(other, self)
def test_table_sequence_sequencer_integration(self) -> None: t1 = TablePulseTemplate(entries={'default': [(2, 'foo'), (5, 0)]}, measurements=[('foo', 2, 2)]) t2 = TablePulseTemplate( entries={'default': [(4, 0), (4.5, 'bar', 'linear'), (5, 0)]}, measurements=[('foo', 4, 1)]) seqt = SequencePulseTemplate( MappingPulseTemplate(t1, measurement_mapping={'foo': 'bar'}), MappingPulseTemplate(t2, parameter_mapping={'bar': '2 * hugo'})) with self.assertRaises(ParameterNotProvidedException): t1.requires_stop(dict(), dict()) with self.assertRaises(ParameterNotProvidedException): t2.requires_stop(dict(), dict()) self.assertFalse( seqt.requires_stop( { 'foo': DummyParameter(), 'hugo': DummyParameter() }, {})) foo = DummyNoValueParameter() bar = DummyNoValueParameter() sequencer = Sequencer() sequencer.push(seqt, { 'foo': foo, 'hugo': bar }, window_mapping=dict(bar='my', foo='thy'), channel_mapping={'default': 'A'}) instructions = sequencer.build() self.assertFalse(sequencer.has_finished()) self.assertEqual(1, len(instructions)) # stop after first TablePT foo = DummyParameter(value=1.1) bar = DummyNoValueParameter() sequencer = Sequencer() sequencer.push(seqt, { 'foo': foo, 'hugo': bar }, window_mapping=dict(bar='my', foo='thy'), channel_mapping={'default': 'A'}) block = sequencer.build() instructions = block.instructions self.assertFalse(sequencer.has_finished()) self.assertIsInstance(block, AbstractInstructionBlock) self.assertEqual(2, len(instructions)) self.assertEqual(instructions[0], MEASInstruction([('my', 2, 2)])) self.assertIsInstance(instructions[1], EXECInstruction) # stop before first TablePT foo = DummyParameter(value=1.1) bar = DummyNoValueParameter() sequencer = Sequencer() sequencer.push(seqt, { 'foo': bar, 'hugo': foo }, window_mapping=dict(bar='my', foo='thy'), channel_mapping={'default': 'A'}) instructions = sequencer.build() self.assertFalse(sequencer.has_finished()) self.assertEqual(1, len(instructions)) foo = DummyParameter(value=1.1) bar = DummyParameter(value=-0.2) sequencer = Sequencer() sequencer.push(seqt, { 'foo': foo, 'hugo': bar }, window_mapping=dict(bar='my', foo='thy'), channel_mapping={'default': 'A'}) instructions = sequencer.build() self.assertTrue(sequencer.has_finished()) self.assertEqual(4, len(instructions.instructions)) self.assertEqual(instructions[0], MEASInstruction([('my', 2, 2)])) self.assertIsInstance(instructions[1], EXECInstruction) self.assertEqual(instructions[2], MEASInstruction([('thy', 4, 1)])) self.assertIsInstance(instructions[3], EXECInstruction)
def test_identifier(self) -> None: identifier = 'some name' pulse = SequencePulseTemplate(DummyPulseTemplate(), identifier=identifier) self.assertEqual(identifier, pulse.identifier)