Beispiel #1
0
def test_basic_permutation():
    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()

    PermutationOracle([0, 2, 1, 3]) | (qubit0, qubit1)

    assert len(saving_backend.received_commands) == 5
Beispiel #2
0
def test_invalid_permutation():
    main_engine = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])

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

    with pytest.raises(AttributeError):
        PermutationOracle([1, 2, 3, 4]) | (qubit0, qubit1)

    with pytest.raises(AttributeError):
        PermutationOracle([0, 2, 3, 4]) | (qubit0, qubit1)

    with pytest.raises(AttributeError):
        PermutationOracle([0, 1, 1, 2]) | (qubit0, qubit1)

    with pytest.raises(AttributeError):
        PermutationOracle([0, 1, 2]) | (qubit0, qubit1)

    with pytest.raises(AttributeError):
        PermutationOracle([0, 1, 2, 3, 4]) | (qubit0, qubit1)
Beispiel #3
0
def test_synthesis_with_adjusted_tbs():
    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()

    import revkit
    synth = lambda: revkit.tbs()

    PermutationOracle([0, 2, 1, 3], synth=synth) | (qubit0, qubit1)

    assert len(saving_backend.received_commands) == 5
Beispiel #4
0
    return (a and b) ^ (c and d) ^ (e and f)


# permutation
pi = [0, 2, 3, 5, 7, 1, 4, 6]

eng = MainEngine()
qubits = eng.allocate_qureg(6)
x = qubits[::2]  # qubits on odd lines
y = qubits[1::2]  # qubits on even lines

# circuit
with Compute(eng):
    All(H) | qubits
    All(X) | [x[0], x[1]]
    PermutationOracle(pi) | y
PhaseOracle(f) | qubits
Uncompute(eng)

with Compute(eng):
    with Dagger(eng):
        PermutationOracle(pi, synth=revkit.dbs) | x
PhaseOracle(f) | qubits
Uncompute(eng)

All(H) | qubits

All(Measure) | qubits

# measurement result
print("Shift is {}".format(sum(int(q) << i for i, q in enumerate(qubits))))