Beispiel #1
0
def test_control_function_invalid_function():
    main_engine = MainEngine(backend=DummyEngine(),
                             engine_list=[DummyEngine()])

    qureg = main_engine.allocate_qureg(3)

    with pytest.raises(AttributeError):
        ControlFunctionOracle(-42) | qureg

    with pytest.raises(AttributeError):
        ControlFunctionOracle(0x8e) | qureg

    with pytest.raises(RuntimeError):
        ControlFunctionOracle(0x8, synth=revkit.esopps) | qureg
Beispiel #2
0
def test_control_function_majority():
    saving_backend = DummyEngine(save_commands=True)
    main_engine = MainEngine(backend=saving_backend,
                             engine_list=[DummyEngine()])

    qubit0 = main_engine.allocate_qubit()
    qubit1 = main_engine.allocate_qubit()
    qubit2 = main_engine.allocate_qubit()
    qubit3 = main_engine.allocate_qubit()

    ControlFunctionOracle(0xe8) | (qubit0, qubit1, qubit2, qubit3)

    assert len(saving_backend.received_commands) == 7
Beispiel #3
0
def test_control_function_majority_from_python():
    dormouse = pytest.importorskip('dormouse')

    def maj(a, b, c):
        return (a and b) or (a and c) or (b and c)  # pragma: no cover

    saving_backend = DummyEngine(save_commands=True)
    main_engine = MainEngine(backend=saving_backend,
                             engine_list=[DummyEngine()])

    qubit0 = main_engine.allocate_qubit()
    qubit1 = main_engine.allocate_qubit()
    qubit2 = main_engine.allocate_qubit()
    qubit3 = main_engine.allocate_qubit()

    ControlFunctionOracle(maj) | (qubit0, qubit1, qubit2, qubit3)