コード例 #1
0
    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
コード例 #2
0
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
コード例 #3
0
    def addElement(self, position: int, element: Element) -> None:
        """
        Add an element to the sequence. Overwrites previous values.

        Args:
            position (int): The sequence position of the element (lowest: 1)
            element (Element): An element instance

        Raises:
            ValueError: If the element has inconsistent durations
        """

        # Validation
        element.validateDurations()

        # make a new copy of the element
        newelement = element.copy()

        # Data mutation
        self._data.update({position: newelement})

        # insert default sequencing settings
        self._sequencing[position] = {'twait': 0, 'nrep': 1,
                                      'jump_input': 0, 'jump_target': 0,
                                      'goto': 0}
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
def test_addArray():

    SR = 1e9
    N = 2500

    wfm = np.linspace(0, N / SR, N)
    m1 = np.zeros(N)
    m2 = np.ones(N)

    elem = Element()
    elem.addArray(1, wfm, SR, m1=m1, m2=m2)
    elem.addArray('2', wfm, SR, m1=m1)
    elem.addArray('readout_channel', wfm, SR, m2=m2)

    elem.validateDurations()

    M = 2400
    wfm2 = np.linspace(0, M / SR, M)
    elem.addArray(3, wfm2, SR)

    with pytest.raises(ElementDurationError):
        elem.validateDurations()

    with pytest.raises(ValueError):
        elem.addArray(1, wfm, SR, m1=m1[:-1])

    with pytest.raises(ValueError):
        elem.addArray(2, wfm, SR, m2=m2[3:])
コード例 #7
0
def test_copy(blueprint_tophat):
    elem1 = Element()
    elem1.addBluePrint(1, blueprint_tophat)
    elem2 = elem1.copy()
    assert elem1 == elem2
コード例 #8
0
def test_equality_true(blueprint_tophat):
    elem1 = Element()
    elem2 = Element()
    elem1.addBluePrint(1, blueprint_tophat)
    elem2.addBluePrint(1, blueprint_tophat)
    assert elem1 == elem2
コード例 #9
0
def test_bare_init(blueprint_tophat):
    elem = Element()
    elem.addBluePrint(1, blueprint_tophat)
    assert list(elem._data.keys()) == [1]
コード例 #10
0
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
コード例 #11
0
def test_input_fail1(improper_bp):
    elem = Element()
    with pytest.raises(ValueError):
        elem.addBluePrint(1, improper_bp)
コード例 #12
0
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()