Example #1
0
def test_parsing_delay():
    parse_equals("DELAY 0 1.0", DelayQubits([Qubit(0)], 1.0))
    parse_equals("DELAY 0 1", DelayQubits([Qubit(0)], 1))
    parse_equals("DELAY 0 1 1e-6", DelayQubits([Qubit(0), Qubit(1)], 1e-6))
    parse_equals('DELAY 0 "rf" 1.0', DelayFrames([Frame([Qubit(0)], "rf")], 1.0))
    parse_equals(
        'DELAY 0 "ro_tx" "ro_rx"  1.0',
        DelayFrames([Frame([Qubit(0)], "ro_tx"), Frame([Qubit(0)], "ro_rx")], 1.0),
    )
Example #2
0
def test_apply_match_delay_qubits():
    settings = {FormalArgument("q"): Qubit(0), Parameter("foo"): 1.0}

    instr = DelayQubits([Qubit(1), FormalArgument("q")], duration=Parameter("foo"))

    actual = fill_placeholders(instr, settings)

    expected = DelayQubits([Qubit(1), Qubit(0)], 1.0)

    assert actual == expected
Example #3
0
def DELAY(*args) -> Union[DelayFrames, DelayQubits]:
    """
    Produce a DELAY instruction.

    Note: There are two variants of DELAY. One applies to specific frames on some
    qubit, e.g. `DELAY 0 "rf" "ff" 1.0` delays the `"rf"` and `"ff"` frames on 0.
    It is also possible to delay all frames on some qubits, e.g. `DELAY 0 1 2 1.0`.

    :param args: A list of delay targets, ending with a duration.
    :returns: A DelayFrames or DelayQubits instance.
    """
    if len(args) < 2:
        raise ValueError(
            "Expected DELAY(t1,...,tn, duration). In particular, there "
            "must be at least one target, as well as a duration."
        )
    targets, duration = args[:-1], args[-1]
    if not isinstance(duration, (Expression, Real)):
        raise TypeError("The last argument of DELAY must be a real or parametric duration.")

    if all(isinstance(t, Frame) for t in targets):
        return DelayFrames(targets, duration)
    elif all(isinstance(t, (int, Qubit, FormalArgument)) for t in targets):
        targets = [Qubit(t) if isinstance(t, int) else t for t in targets]
        return DelayQubits(targets, duration)
    else:
        raise TypeError(
            "DELAY targets must be either (i) a list of frames, or "
            "(ii) a list of qubits / formal arguments. "
            f"Got {args}."
        )