def test_collect_dependencies(self): # Test collecting build dependencies. self.workbench.register(PulsesManagerManifest()) from hqc_meas.pulses.base_sequences import RootSequence, Sequence from hqc_meas.pulses.pulse import Pulse from hqc_meas.pulses.shapes.base_shapes import SquareShape from hqc_meas.pulses.contexts.awg_context import AWGContext root = RootSequence(context=AWGContext()) pulse1 = Pulse(def_1='1.0', def_2='{7_start} - 1.0') pulse2 = Pulse(def_1='{a} + 1.0', def_2='{6_start} + 1.0') pulse3 = Pulse(def_1='{3_stop} + 0.5', def_2='10.0') pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration') pulse5 = Pulse(def_1='{1_stop}', def_2='0.5', def_mode='Start/Duration') pulse5.shape = SquareShape(amplitude='0.5') pulse5.kind = 'Analogical' pulse5.modulation.frequency = '1.0**' pulse5.modulation.phase = '1.0' pulse5.modulation.activated = True sequence2 = Sequence(items=[pulse3]) sequence1 = Sequence(items=[pulse2, sequence2, pulse4]) root.items = [pulse1, sequence1, pulse5] core = self.workbench.get_plugin(u'enaml.workbench.core') com = u'hqc_meas.dependencies.collect_dependencies' res, build, run = core.invoke_command(com, {'obj': root}, core) assert_true(res) assert_in('pulses', build) assert_items_equal(['Sequence', 'Pulse', 'RootSequence', 'shapes', 'contexts', 'templates', 'sequences'], build['pulses'].keys()) assert_equal(['SquareShape'], build['pulses']['shapes'].keys()) assert_equal(['AWGContext'], build['pulses']['contexts'].keys()) assert_false(run)
def setup(self): self.pulse = Pulse(root=RootSequence(context=TestContext()))
def test_sequence_indexing2(): # Test adding, moving, deleting a sequence in a sequence. root = RootSequence() context = TestContext() root.context = context pulse1 = Pulse() pulse2 = Pulse() pulse3 = Pulse() pulse4 = Pulse() sequence1 = Sequence() sequence2 = Sequence() root.items.append(pulse1) root.items.append(sequence1) root.items.append(pulse2) assert_is(sequence1.parent, root) assert_is(sequence1.root, root) sequence1.items.append(sequence2) assert_is(sequence2.parent, sequence1) assert_is(sequence2.root, root) assert_equal(pulse1.index, 1) assert_equal(pulse2.index, 4) assert_items_equal(root.linkable_vars, ['1_start', '1_stop', '1_duration', '4_start', '4_stop', '4_duration']) pulse1.index = 200 sequence2.items.append(pulse3) assert_is(pulse3.parent, sequence2) assert_is(pulse3.root, root) assert_equal(pulse2.index, 5) assert_equal(pulse3.index, 4) assert_items_equal(root.linkable_vars, ['1_start', '1_stop', '1_duration', '4_start', '4_stop', '4_duration', '5_start', '5_stop', '5_duration']) # Check that only the pulse below the modified sequence are updated. assert_equal(pulse1.index, 200) pulse1.index = 1 sequence1.items.insert(0, pulse4) assert_equal(pulse4.index, 3) assert_equal(sequence2.index, 4) assert_equal(pulse3.index, 5) assert_equal(pulse2.index, 6) assert_items_equal(root.linkable_vars, ['1_start', '1_stop', '1_duration', '3_start', '3_stop', '3_duration', '5_start', '5_stop', '5_duration', '6_start', '6_stop', '6_duration']) sequence1.items = [pulse4] assert_is(sequence2.parent, None) assert_equal(sequence2.index, 0) assert_equal(pulse2.index, 4) assert_items_equal(root.linkable_vars, ['1_start', '1_stop', '1_duration', '3_start', '3_stop', '3_duration', '4_start', '4_stop', '4_duration']) sequence1.index = 200 root2 = RootSequence() sequence2.root = root2 sequence2.items = [] # Check the observer was properly removed assert_equal(sequence1.index, 200)
class TestPulse(object): def setup(self): self.pulse = Pulse(root=RootSequence(context=TestContext())) def test_eval_pulse1(self): # Test evaluating the entries of a pulse when everything is ok. # Start/Stop mode, meaningful values. self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 2.0, 'b': 5.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_true(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_equal(errors, {}) assert_equal(root_vars['0_start'], 2.0) assert_equal(root_vars['0_stop'], 3.0) assert_equal(root_vars['0_duration'], 1.0) assert_equal(seq_locals['0_start'], 2.0) assert_equal(seq_locals['0_stop'], 3.0) assert_equal(seq_locals['0_duration'], 1.0) assert_equal(self.pulse.start, 2.0) assert_equal(self.pulse.stop, 3.0) assert_equal(self.pulse.duration, 1.0) assert_array_equal(self.pulse.waveform, np.ones(1)) def test_eval_pulse2(self): # Test evaluating the entries of a pulse when everything is ok. # Start/Stop mode, meaningless start. self.pulse.def_1 = '-1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 2.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_start', errors) assert_not_in('0_start', root_vars) assert_not_in('0_duration', root_vars) assert_not_in('0_start', seq_locals) assert_not_in('0_duration', seq_locals) def test_eval_pulse3(self): # Test evaluating the entries of a pulse when everything is ok. # Start/Stop mode, meaningless stop (0). self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 0.0, 'b': 10.0, 'c': 0.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_stop', errors) assert_not_in('0_stop', root_vars) assert_not_in('0_duration', root_vars) assert_not_in('0_stop', seq_locals) assert_not_in('0_duration', seq_locals) def test_eval_pulse4(self): # Test evaluating the entries of a pulse when everything is ok. # Start/Stop mode, meaningless stop < start. self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 0.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_stop', errors) assert_not_in('0_stop', root_vars) assert_not_in('0_duration', root_vars) assert_not_in('0_stop', seq_locals) assert_not_in('0_duration', seq_locals) def test_eval_pulse5(self): # Test evaluating the entries of a pulse when everything is ok. # Start/Duration mode, meaningful values. self.pulse.def_mode = 'Start/Duration' self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 2.0, 'b': 5.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_true(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_equal(errors, {}) assert_equal(root_vars['0_start'], 2.0) assert_equal(root_vars['0_stop'], 5.0) assert_equal(root_vars['0_duration'], 3.0) assert_equal(seq_locals['0_start'], 2.0) assert_equal(seq_locals['0_stop'], 5.0) assert_equal(seq_locals['0_duration'], 3.0) assert_equal(self.pulse.start, 2.0) assert_equal(self.pulse.stop, 5.0) assert_equal(self.pulse.duration, 3.0) assert_array_equal(self.pulse.waveform, np.ones(3)) def test_eval_pulse6(self): # Test evaluating the entries of a pulse when everything is ok. # Start/Duration mode, meaningless start. self.pulse.def_mode = 'Start/Duration' self.pulse.def_1 = '-1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 0.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_start', errors) assert_not_in('0_start', root_vars) assert_not_in('0_stop', root_vars) assert_not_in('0_start', seq_locals) assert_not_in('0_stop', seq_locals) def test_eval_pulse7(self): # Test evaluating the entries of a pulse when everything is ok. # Start/Duration mode, meaningless duration. self.pulse.def_mode = 'Start/Duration' self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 0.0, 'b': 10.0, 'c': 0.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_duration', errors) assert_not_in('0_duration', root_vars) assert_not_in('0_stop', root_vars) assert_not_in('0_duration', seq_locals) assert_not_in('0_stop', seq_locals) def test_eval_pulse8(self): # Test evaluating the entries of a pulse when everything is ok. # Duration/Stop mode, meaningful values. self.pulse.def_mode = 'Duration/Stop' self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 2.0, 'b': 5.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_true(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_equal(errors, {}) assert_equal(root_vars['0_start'], 1.0) assert_equal(root_vars['0_stop'], 3.0) assert_equal(root_vars['0_duration'], 2.0) assert_equal(seq_locals['0_start'], 1.0) assert_equal(seq_locals['0_stop'], 3.0) assert_equal(seq_locals['0_duration'], 2.0) assert_equal(self.pulse.start, 1.0) assert_equal(self.pulse.stop, 3.0) assert_equal(self.pulse.duration, 2.0) assert_array_equal(self.pulse.waveform, np.ones(2)) def test_eval_pulse9(self): # Test evaluating the entries of a pulse Duration/Stop mode, # meaningless duration. self.pulse.def_mode = 'Duration/Stop' self.pulse.def_1 = '-1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 0.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_duration', errors) assert_not_in('0_duration', root_vars) assert_not_in('0_start', root_vars) assert_not_in('0_duration', seq_locals) assert_not_in('0_start', seq_locals) def test_eval_pulse10(self): # Test evaluating the entries of a pulse Duration/Stop mode, # meaningless stop. self.pulse.def_mode = 'Duration/Stop' self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 0.0, 'b': 10.0, 'c': 0.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_stop', errors) assert_not_in('0_stop', root_vars) assert_not_in('0_start', root_vars) assert_not_in('0_stop', seq_locals) assert_not_in('0_start', seq_locals) def test_eval_pulse11(self): # Test evaluating the entries of a pulse Duration/Stop mode, duration # larger than stop. self.pulse.def_mode = 'Duration/Stop' self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 0.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_stop', errors) assert_not_in('0_start', root_vars) assert_not_in('0_start', seq_locals) def test_eval_pulse12(self): # Test evaluating the entries of a pulse when some vars are missing. # Issue in def_1 self.pulse.def_1 = '1.0*2.0*{d}' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 2.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set('d')) assert_not_in('0_start', errors) assert_not_in('0_start', root_vars) assert_in('0_stop', root_vars) assert_not_in('0_start', seq_locals) assert_in('0_stop', seq_locals) def test_eval_pulse13(self): # Test evaluating the entries of a pulse when some vars are missing. # Issue in def_2 self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 2.0, 'b': 10.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set('c')) assert_not_in('0_stop', errors) assert_not_in('0_stop', root_vars) assert_in('0_start', root_vars) assert_not_in('0_stop', seq_locals) assert_in('0_start', seq_locals) def test_eval_pulse14(self): # Test evaluating the entries of a pulse when some entries are # incorrect. # Issue def_1 self.pulse.def_1 = '1.0*2.0*zeffer' self.pulse.def_2 = '5.0*{a}/{b} + {c}' root_vars = {'a': 2.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_start', errors) assert_not_in('0_start', root_vars) assert_in('0_stop', root_vars) assert_not_in('0_start', seq_locals) assert_in('0_stop', seq_locals) def test_eval_pulse15(self): # Test evaluating the entries of a pulse when some entries are # incorrect. # Issue in def_2 self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c} + zeffer' root_vars = {'a': 2.0, 'b': 10.0, 'c': 1.0} missing = set() errors = {} seq_locals = root_vars.copy() assert_false(self.pulse.eval_entries(root_vars, seq_locals, missing, errors)) assert_equal(missing, set()) assert_in('0_stop', errors) assert_not_in('0_stop', root_vars) assert_in('0_start', root_vars) assert_not_in('0_stop', seq_locals) assert_in('0_start', seq_locals) def test_eval_pulse16(self): # Test evaluating the entries of an analogical pulse. self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' self.pulse.shape = SquareShape(amplitude='0.5') self.pulse.kind = 'Analogical' root_vars = {'a': 2.0, 'b': 5.0, 'c': 1.0} missing = set() errors = {} assert_true(self.pulse.eval_entries(root_vars, root_vars, missing, errors)) assert_equal(missing, set()) assert_equal(errors, {}) assert_array_equal(self.pulse.waveform, 0.5*np.ones(1)) def test_eval_pulse17(self): # Test evaluating the entries of an analogical pulse whose modulation # evaluation fails. self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' self.pulse.shape = SquareShape(amplitude='0.5') self.pulse.kind = 'Analogical' self.pulse.modulation.frequency = '1.0**' self.pulse.modulation.phase = '1.0' self.pulse.modulation.activated = True root_vars = {'a': 2.0, 'b': 5.0, 'c': 1.0} missing = set() errors = {} assert_false(self.pulse.eval_entries(root_vars, root_vars, missing, errors)) assert_equal(missing, set()) assert_in('0_mod_frequency', errors) def test_eval_pulse18(self): # Test evaluating the entries of an analogical pulse whose shape # evaluation fails. self.pulse.def_1 = '1.0*2.0' self.pulse.def_2 = '5.0*{a}/{b} + {c}' self.pulse.shape = SquareShape(amplitude='0.5*') self.pulse.kind = 'Analogical' self.pulse.modulation.frequency = '1.0' self.pulse.modulation.phase = '1.0' self.pulse.modulation.activated = True root_vars = {'a': 2.0, 'b': 5.0, 'c': 1.0} missing = set() errors = {} assert_false(self.pulse.eval_entries(root_vars, root_vars, missing, errors)) assert_equal(missing, set()) assert_in('0_shape_amplitude', errors)