def sequence_from_description(cls, seq_dict: dict) -> 'Sequence': """ Returns a sequence from a description given as a dict Args: seq_dict: a dict in the same form as returned by Sequence.description """ awgspecs = seq_dict['awgspecs'] SR = awgspecs['SR'] elem_list = list(seq_dict.keys()) new_instance = cls() for ele in elem_list[:-1]: channels_list = list(seq_dict[ele]['channels'].keys()) elem = Element() for chan in channels_list: bp_sum = BluePrint.blueprint_from_description(seq_dict[ele]['channels'][chan]) bp_sum.setSR(SR) elem.addBluePrint(int(chan), bp_sum) ChannelAmplitude = awgspecs['channel{}_amplitude'.format(chan)] new_instance.setChannelAmplitude(int(chan), ChannelAmplitude) # Call signature: channel, amplitude (peak-to-peak) ChannelOffset = awgspecs['channel{}_offset'.format(chan)] new_instance.setChannelOffset(int(chan), ChannelOffset) new_instance.addElement(int(ele), elem) sequencedict = seq_dict[ele]['sequencing'] new_instance.setSequencingTriggerWait(int(ele), sequencedict['Wait trigger']) new_instance.setSequencingNumberOfRepetitions(int(ele), sequencedict['Repeat']) new_instance.setSequencingEventInput(int(ele), sequencedict['jump_input']) new_instance.setSequencingEventJumpTarget(int(ele), sequencedict['jump_target']) new_instance.setSequencingGoto(int(ele), sequencedict['Go to']) new_instance.setSR(SR) return new_instance
def test_equality_false(blueprint_tophat): elem1 = Element() elem2 = Element() elem1.addBluePrint(1, blueprint_tophat) elem2.addBluePrint(1, blueprint_tophat) elem1.changeArg(1, 'ramp', 'start', 2) assert elem1 != elem2
def test_points(SR, N): elem = Element() with pytest.raises(KeyError): elem.points bp = bb.BluePrint() bp.insertSegment(0, ramp, (0, 0), dur=N / SR) bp.setSR(SR) wfm = np.linspace(-1, 1, N) elem.addArray(1, wfm, SR) elem.addBluePrint(2, bp) assert elem.points == N elem = Element() bp = bb.BluePrint() bp.insertSegment(0, ramp, (0, 0), dur=N / SR) bp.setSR(SR) wfm = np.linspace(-1, 1, N) elem.addArray(2, wfm, SR) elem.addBluePrint(1, bp) assert elem.points == N
def test_write_read_element(blueprint_tophat, tmp_path): elem = Element() elem.addBluePrint(1, blueprint_tophat) d = tmp_path / "Element" d.mkdir() elem.write_to_json(os.path.join(d, "ele.json")) readback_elem = Element.init_from_json(os.path.join(d, "ele.json")) assert elem.description == readback_elem.description
def mixed_element(blueprint_tophat): """ An element with blueprints and arrays """ noise = np.random.randn(blueprint_tophat.points) wiggle = bb.BluePrint() wiggle.insertSegment(0, sine, args=(1, 10, 0, 0), dur=2.5) wiggle.setSR(blueprint_tophat.SR) elem = Element() elem.addBluePrint(1, blueprint_tophat) elem.addArray(2, noise, blueprint_tophat.SR) elem.addBluePrint(3, wiggle) return elem
def test_invalid_durations(SR1, SR2, N, M): """ There are soooo many ways to have invalid durations, here we hit a couple of them """ # differing sample rates elem = Element() bp = bb.BluePrint() bp.insertSegment(0, ramp, (0, 0), dur=N / SR2) bp.setSR(SR2) wfm = np.linspace(-1, 1, N) elem.addArray(1, wfm, SR1) elem.addBluePrint(2, bp) if SR1 == SR2: elem.validateDurations() else: with pytest.raises(ElementDurationError): elem.validateDurations() # differing durations bp1 = bb.BluePrint() bp1.insertSegment(0, ramp, (0, 1), dur=N / SR1) bp1.setSR(SR1) bp2 = bb.BluePrint() bp2.insertSegment(0, ramp, (0, 2), dur=M / SR1) bp2.setSR(SR1) elem = Element() elem.addBluePrint(1, bp1) elem.addBluePrint(2, bp2) if N == M: elem.validateDurations() else: with pytest.raises(ElementDurationError): elem.validateDurations()
def test_copy(blueprint_tophat): elem1 = Element() elem1.addBluePrint(1, blueprint_tophat) elem2 = elem1.copy() assert elem1 == elem2
def test_equality_true(blueprint_tophat): elem1 = Element() elem2 = Element() elem1.addBluePrint(1, blueprint_tophat) elem2.addBluePrint(1, blueprint_tophat) assert elem1 == elem2
def test_bare_init(blueprint_tophat): elem = Element() elem.addBluePrint(1, blueprint_tophat) assert list(elem._data.keys()) == [1]
def test_input_fail1(improper_bp): elem = Element() with pytest.raises(ValueError): elem.addBluePrint(1, improper_bp)