Exemple #1
0
def test_delay():
    seq = Sequence(reg, device)
    seq.declare_channel('ch0', 'raman_local')
    with pytest.raises(ValueError, match='Use the name of a declared channel'):
        seq.delay(1e3, 'ch01')
    with pytest.raises(ValueError, match='channel has no target'):
        seq.delay(100, 'ch0')
    seq.target('q19', 'ch0')
    seq.delay(388, 'ch0')
    assert seq._last('ch0') == _TimeSlot('delay', 0, 388, {'q19'})
Exemple #2
0
def test_delay():
    seq = Sequence(reg, device)
    seq.declare_channel("ch0", "raman_local")
    with pytest.raises(ValueError, match="Use the name of a declared channel"):
        seq.delay(1e3, "ch01")
    with pytest.raises(ValueError, match="channel has no target"):
        seq.delay(100, "ch0")
    seq.target("q19", "ch0")
    seq.delay(388, "ch0")
    assert seq._last("ch0") == _TimeSlot("delay", 0, 388, {"q19"})
Exemple #3
0
def test_delay_min_duration():
    # Check that a delay shorter than a channel's minimal duration
    # is automatically extended to that minimal duration
    seq = Sequence(reg, device)
    seq.declare_channel("ch0", "rydberg_global")
    seq.declare_channel("ch1", "rydberg_local")
    seq.target("q0", "ch1")
    pulse0 = Pulse.ConstantPulse(52, 1, 1, 0)
    pulse1 = Pulse.ConstantPulse(180, 1, 1, 0)
    seq.add(pulse1, "ch1")
    seq.add(pulse0, "ch0")
    seq.target("q1", "ch1")
    seq.add(pulse1, "ch1")
    min_duration = seq._channels["ch1"].min_duration
    assert seq._schedule["ch1"][3] == _TimeSlot("delay", 220,
                                                220 + min_duration, {"q1"})
Exemple #4
0
def test_target():
    seq = Sequence(reg, device)
    seq.declare_channel('ch0', 'raman_local', initial_target='q1')
    seq.declare_channel('ch1', 'rydberg_global')

    with pytest.raises(ValueError, match='name of a declared channel'):
        seq.target('q0', 'ch2')
    with pytest.raises(ValueError, match='qubits have to belong'):
        seq.target(0, 'ch0')
        seq.target('0', 'ch1')
    with pytest.raises(ValueError, match="Can only choose target of 'Local'"):
        seq.target('q3', 'ch1')
    with pytest.raises(ValueError, match="can target at most 1 qubits"):
        seq.target(['q1', 'q5'], 'ch0')

    assert seq._schedule['ch0'][-1] == _TimeSlot('target', -1, 0, {'q1'})
    seq.target('q4', 'ch0')
    retarget_t = seq.declared_channels['ch0'].retarget_time
    assert seq._schedule['ch0'][-1] == _TimeSlot('target', 0, retarget_t,
                                                 {'q4'})
    with pytest.warns(UserWarning):
        seq.target('q4', 'ch0')
    seq.target('q20', 'ch0')
    assert seq._schedule['ch0'][-1] == _TimeSlot('target', retarget_t,
                                                 2 * retarget_t, {'q20'})
    seq.delay(216, 'ch0')
    seq.target('q2', 'ch0')
    ti = 2 * retarget_t + 216
    tf = ti + 16
    assert seq._schedule['ch0'][-1] == _TimeSlot('target', ti, tf, {'q2'})

    seq.delay(220, 'ch0')
    seq.target('q1', 'ch0')
    ti = tf + 220
    tf = ti
    assert seq._schedule['ch0'][-1] == _TimeSlot('target', ti, tf, {'q1'})

    seq.delay(100, 'ch0')
    seq.target('q10', 'ch0')
    ti = tf + 100
    tf = ti + 120
    assert seq._schedule['ch0'][-1] == _TimeSlot('target', ti, tf, {'q10'})

    seq2 = Sequence(reg, MockDevice)
    seq2.declare_channel('ch0', 'raman_local', initial_target={'q1', 'q10'})
    seq2.phase_shift(1, 'q2')
    with pytest.raises(ValueError, match="qubits with different phase"):
        seq2.target({'q3', 'q1', 'q2'}, 'ch0')
Exemple #5
0
def test_target():
    seq = Sequence(reg, device)
    seq.declare_channel("ch0", "raman_local", initial_target="q1")
    seq.declare_channel("ch1", "rydberg_global")

    with pytest.raises(ValueError, match="name of a declared channel"):
        seq.target("q0", "ch2")
    with pytest.raises(ValueError, match="ids have to be qubit ids"):
        seq.target(0, "ch0")
    with pytest.raises(ValueError, match="ids have to be qubit ids"):
        seq.target("0", "ch0")
    with pytest.raises(ValueError, match="Can only choose target of 'Local'"):
        seq.target("q3", "ch1")
    with pytest.raises(ValueError, match="can target at most 1 qubits"):
        seq.target(["q1", "q5"], "ch0")

    assert seq._schedule["ch0"][-1] == _TimeSlot("target", -1, 0, {"q1"})
    seq.target("q4", "ch0")
    retarget_t = seq.declared_channels["ch0"].min_retarget_interval
    assert seq._schedule["ch0"][-1] == _TimeSlot("target", 0, retarget_t,
                                                 {"q4"})
    seq.target("q4", "ch0")  # targets the same qubit
    seq.target("q20", "ch0")
    assert seq._schedule["ch0"][-1] == _TimeSlot("target", retarget_t,
                                                 2 * retarget_t, {"q20"})
    seq.delay(216, "ch0")
    seq.target("q2", "ch0")
    ti = 2 * retarget_t + 216
    tf = ti + 16
    assert seq._schedule["ch0"][-1] == _TimeSlot("target", ti, tf, {"q2"})

    seq.delay(220, "ch0")
    seq.target("q1", "ch0")
    ti = tf + 220
    tf = ti
    assert seq._schedule["ch0"][-1] == _TimeSlot("target", ti, tf, {"q1"})

    seq.delay(100, "ch0")
    seq.target("q10", "ch0")
    ti = tf + 100
    tf = ti + 120
    assert seq._schedule["ch0"][-1] == _TimeSlot("target", ti, tf, {"q10"})

    seq2 = Sequence(reg, MockDevice)
    seq2.declare_channel("ch0", "raman_local", initial_target={"q1", "q10"})
    seq2.phase_shift(1, "q2")
    with pytest.raises(ValueError, match="qubits with different phase"):
        seq2.target({"q3", "q1", "q2"}, "ch0")
Exemple #6
0
def test_channel_declaration():
    seq = Sequence(reg, device)
    available_channels = set(seq.available_channels)
    seq.declare_channel("ch0", "rydberg_global")
    seq.declare_channel("ch1", "raman_local")
    with pytest.raises(ValueError, match="No channel"):
        seq.declare_channel("ch2", "raman")
    with pytest.raises(ValueError, match="not available"):
        seq.declare_channel("ch2", "rydberg_global")
    with pytest.raises(ValueError, match="name is already in use"):
        seq.declare_channel("ch0", "raman_local")

    chs = {"rydberg_global", "raman_local"}
    assert seq._schedule["ch0"][-1] == _TimeSlot("target", -1, 0,
                                                 set(seq.qubit_info.keys()))
    assert set(seq.available_channels) == available_channels - chs

    seq2 = Sequence(reg, MockDevice)
    available_channels = set(seq2.available_channels)
    seq2.declare_channel("ch0", "raman_local", initial_target="q1")
    seq2.declare_channel("ch1", "rydberg_global")
    seq2.declare_channel("ch2", "rydberg_global")
    assert set(seq2.available_channels) == (available_channels - {"mw_global"})
    assert seq2._taken_channels == {
        "ch0": "raman_local",
        "ch1": "rydberg_global",
        "ch2": "rydberg_global",
    }
    assert seq2._taken_channels.keys() == seq2._channels.keys()
    with pytest.raises(ValueError, match="type 'Microwave' cannot work "):
        seq2.declare_channel("ch3", "mw_global")

    seq2 = Sequence(reg, MockDevice)
    seq2.declare_channel("ch0", "mw_global")
    assert set(seq2.available_channels) == {"mw_global"}
    with pytest.raises(
            ValueError,
            match="cannot work simultaneously with the declared 'Microwave'",
    ):
        seq2.declare_channel("ch3", "rydberg_global")
Exemple #7
0
def test_channel_declaration():
    seq = Sequence(reg, device)
    available_channels = set(seq.available_channels)
    seq.declare_channel('ch0', 'rydberg_global')
    seq.declare_channel('ch1', 'raman_local')
    with pytest.raises(ValueError, match="No channel"):
        seq.declare_channel('ch2', 'raman')
    with pytest.raises(ValueError, match="not available"):
        seq.declare_channel('ch2', 'rydberg_global')
    with pytest.raises(ValueError, match="name is already in use"):
        seq.declare_channel('ch0', 'raman_local')

    chs = {'rydberg_global', 'raman_local'}
    assert seq._schedule['ch0'][-1] == _TimeSlot('target', -1, 0,
                                                 set(seq.qubit_info.keys()))
    assert set(seq.available_channels) == available_channels - chs

    seq2 = Sequence(reg, MockDevice)
    available_channels = set(seq2.available_channels)
    seq2.declare_channel('ch0', 'raman_local', initial_target='q1')
    seq2.declare_channel('ch1', 'rydberg_global')
    assert set(seq2.available_channels) == available_channels