Beispiel #1
0
def grover_unitary(position, retrun_result=False):
    qr = QuantumRegister(4, "qr")
    cr = ClassicalRegister(4, "cr")
    qc = QuantumCircuit(qr, cr)
    state = None

    init_gates(qc)
    create_oracle(qr, cr, qc, position)

    def get_state(qr, cr, qc):
        apply_h(qr, cr, qc)
        # qc.barrier()
        # oracle(qr, cr, qc)

    state = simulate_unitary(get_state)
    diff_state = count_s_state(state)
    create_diff(qr, cr, qc, diff_state)

    create_oracle(qr, cr, qc, position)
    create_diff(qr, cr, qc, diff_state)

    qc.measure(qr[0], cr[0])
    qc.measure(qr[1], cr[1])
    qc.measure(qr[2], cr[2])
    qc.measure(qr[3], cr[3])

    if retrun_result:
        result = tools.simulate_and_return_result(qc)
        return result
    else:
        title = 'Groverio paieškos tikimybės, kai $U_{f = %s}$' % (str(position))
        circle_title = 'Groverio paieškos schema, kai $U_{f = %s}$' % (str(position))
        tools.simulate_and_show_result(qc, title=title, circle_title=circle_title)
Beispiel #2
0
def grover():
    (qr, cr, qc) = get_registers()

    apply_h(qr, cr, qc)
    qc.barrier()

    create_oracle(qr, cr, qc)
    # oracle(qr,cr,qc)
    amplification(qr, cr, qc)

    apply_m(qr, cr, qc)
    tools.simulate_and_show_result(qc, "labas")
def show_oracul_schemes():
    qr = QuantumRegister(5, "qr")
    cr = ClassicalRegister(1, "cr")
    qc = QuantumCircuit(qr, cr)

    # oracule U 1
    # test_oracle_1(qr,cr,qc)

    # oracule U 2
    test_oracle_2(qr, cr, qc)

    qc.measure(qr[4], cr[0])

    tools.simulate_and_show_result(qc, title="$ U_{f_1} $")
def quiskit_simuliation():
    qr = QuantumRegister(2, "qr")
    cr = ClassicalRegister(2, "cr")
    qc = QuantumCircuit(qr, cr)

    qc.h(qr[0])
    qc.cx(qr[0], qr[1])

    # qc.x(qr[0])
    # qc.x(qr[1])

    qc.barrier()

    qc.measure(qr[0], cr[0])  # measure q[1] -> c[0];
    qc.measure(qr[1], cr[1])  # measure q[2] -> c[1];

    tools.simulate_and_show_result(qc)
def test_deutsch_jozsa():
    def test_oracle_1_full(qr, cr, qc):
        test_oracle_1(qr, cr, qc)
        test_oracle_1_return(qr, cr, qc)

    def test_oracle_2_full(qr, cr, qc):
        test_oracle_2(qr, cr, qc)
        test_oracle_2_return(qr, cr, qc)

    # test_oracle_1(qr,cr,qc)
    test_case = [test_oracle_1_full, test_oracle_2_full]
    for test in range(0, len(test_case)):
        qr = QuantumRegister(5, "qr")
        cr = ClassicalRegister(4, "cr")
        qc = QuantumCircuit(qr, cr)

        qc.h(qr[0])
        qc.h(qr[1])
        qc.h(qr[2])
        qc.h(qr[3])
        qc.x(qr[4])
        qc.barrier()

        qc.h(qr[4])
        qc.barrier()

        current_test = test_case[test]
        current_test(qr, cr, qc)

        qc.h(qr[0])
        qc.h(qr[1])
        qc.h(qr[2])
        qc.h(qr[3])

        qc.measure(qr[0], cr[0])
        qc.measure(qr[1], cr[1])
        qc.measure(qr[2], cr[2])
        qc.measure(qr[3], cr[3])

        tools.simulate_and_show_result(
            qc,
            title=
            "Deutsch-Jozsos reikšminių kubitų pasiskirstymo tikimybės, kai $ U_{f_"
            + str(test + 1) + "} $",
            circle_title="Deutsch-Jozsos schema kai $ U_{f_" + str(test + 1) +
            "} $")