Ejemplo n.º 1
0
def test_gate():
    tg = Gate("TEST", qubits=[Qubit(1), Qubit(2)], params=[])
    assert tg.out() == "TEST 1 2"
Ejemplo n.º 2
0
def test_defgate_param():
    dgp = DefGate("TEST", [[1., 0.], [0., 1.]])
    assert dgp.out() == "DEFGATE TEST:\n    1.0, 0\n    0, 1.0\n"
    test = dgp.get_constructor()
    tg = test(Qubit(1))
    assert tg.out() == "TEST 1"
Ejemplo n.º 3
0
def test_get_qubits_not_as_indices():
    pq = Program(X(0), CNOT(0, 4), MEASURE(5, 5))
    assert pq.get_qubits(indices=False) == {Qubit(i) for i in [0, 4, 5]}
Ejemplo n.º 4
0
def _qubit(qubit):
    # type: (QuilParser.QubitContext) -> Qubit
    return Qubit(int(qubit.getText()))
Ejemplo n.º 5
0
def test_simple_gate():
    parse_equals("A 0", Gate("A", [], [Qubit(0)]))
    parse_equals("A 1 10 100",
                 Gate("A", [],
                      [Qubit(1), Qubit(10), Qubit(100)]))
Ejemplo n.º 6
0
def test_parameters():
    parse_equals("RX(123) 0", RX(123, 0))
    parse_equals("CPHASE00(0) 0 1", CPHASE00(0, 0, 1))
    parse_equals("A(8,9) 0", Gate("A", [8, 9], [Qubit(0)]))
    parse_equals("A(8, 9) 0", Gate("A", [8, 9], [Qubit(0)]))
Ejemplo n.º 7
0
def test_program_calibrate_cyclic_error(program_text):
    prog = Program(program_text)
    with pytest.raises(CalibrationError):
        prog.calibrate(Gate("RZ", [np.pi], [Qubit(0)]))
Ejemplo n.º 8
0
def test_program_match_last():
    first = DefCalibration("X", [], [Qubit(0)], ["foo"])
    second = DefCalibration("X", [], [Qubit(0)], ["bar"])
    prog = Program(first, second)
    match = prog.match_calibrations(Gate("X", [], [Qubit(0)]))
    assert match == CalibrationMatch(cal=second, settings={})
Ejemplo n.º 9
0
    prog = Program(first, second)
    match = prog.match_calibrations(Gate("X", [], [Qubit(0)]))
    assert match == CalibrationMatch(cal=second, settings={})


@pytest.mark.parametrize(
    "program_input,gate,program_output",
    [
        (
            Program(
                """
DEFCAL RZ(%theta) q:
    SHIFT-PHASE q "rf" -%theta
"""
            ),
            Gate("RZ", [np.pi], [Qubit(0)]),
            Program('SHIFT-PHASE 0 "rf" -pi'),
        ),
        (
            Program(
                """
DEFCAL A(%theta) q:
    SHIFT-PHASE q "rf" -%theta

DEFCAL RZ(%theta) q:
    SHIFT-PHASE q "rf" -%theta
    A(%theta) q
"""
            ),
            Gate("RZ", [np.pi], [Qubit(0)]),
            Program('SHIFT-PHASE 0 "rf" -pi', 'SHIFT-PHASE 0 "rf" -pi'),
Ejemplo n.º 10
0
def test_parameters():
    _test("RX(123) 0", RX(123)(0))
    _test("CPHASE00(0) 0 1", CPHASE00(0)(0, 1))
    _test("A(8,9) 0", Gate("A", [8, 9], [Qubit(0)]))
    _test("A(8, 9) 0", Gate("A", [8, 9], [Qubit(0)]))
Ejemplo n.º 11
0
def test_simple_gate():
    _test("A 0", Gate("A", [], [Qubit(0)]))
    _test("A 1 10 100", Gate("A", [], [Qubit(1), Qubit(10), Qubit(100)]))