Exemple #1
0
def count_state_averge(val):
    val = np.abs(val)
    print(val)
    values = tools.all_binary_combs(size=3)
    s = (8, 8)
    init_data = np.zeros(s)
    df = pd.DataFrame(data=val, index=values[::-1], columns=values)
    sns.heatmap(df, cmap='RdYlGn_r', linewidths=0.5, annot=True).set_title(
        "Šredingerio lygties perėjimo matricos reikšmių moduliai")
    plt.show()
def test_oracul_values():
    test_case = [test_oracle_1, test_oracle_2]

    for test in range(0, len(test_case)):

        values = tools.all_binary_combs(size=4)
        s = (16, 16)
        init_data = np.zeros(s)
        df = pd.DataFrame(data=init_data, index=values[::-1], columns=values)
        # print(df)

        for b in values:

            qr = QuantumRegister(5, "qr")
            cr = ClassicalRegister(5, "cr")
            qc = QuantumCircuit(qr, cr)

            for i in range(0, len(b)):
                if b[i] == '1':
                    qc.x(qr[3 - i])

            apply_test = test_case[test]
            apply_test(qr, cr, qc)
            # test_oracle_1(qr,cr,qc)
            # test_oracle_2(qr, cr, qc)

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

            # tools.simulate_and_show_result(qc, str(b))
            result = tools.simulate_and_return_result(qc)

            keys = list(result.keys())
            val = list(result.values())

            for i in range(0, len(keys)):
                value_cubits = keys[i][1:5]
                control_cubit = keys[i][0]
                if control_cubit == "1":
                    df[str(b)][value_cubits] = val[i] / 1024

        sns.heatmap(df, cmap='RdYlGn_r', linewidths=0.5,
                    annot=True).set_title("Tikimybė, kad $ q_{n+1} = 1 $"
                                          " pritaikius $U_{f_" +
                                          str(test + 1) + "}$")
        plt.xlabel('Kubitų $ q_0, q_1, ..., q_{n}$ įvestis',
                   fontsize=10)  # x-axis label with fontsize 15
        plt.ylabel('Galimos $ q_0, q_1, ..., q_{n}$ reikšmės',
                   fontsize=10)  # y-axis label with fontsize 15
        plt.show()
def test_all_grover_values_bell():
    values = tools.all_binary_combs(size=4)
    s = (16, 16)
    init_data = np.zeros(s)
    df = pd.DataFrame(data=init_data, index=values[::-1], columns=values)

    for j in range(0, 16):
        result = grover_with_bell_state(j)
        keys = list(result.keys())
        val = list(result.values())

        for i in range(0, len(keys)):
            df[values[j]][keys[i]] = val[i] / 1024

    sns.heatmap(df, cmap='RdYlGn_r', linewidths=0.5, annot=True).set_title(
        "Groverio paieškos tikimybės Bello būsenoje su skirtingais $U_{f}$ ")
    plt.xlabel('Orakulo $U_{f}$ reikšmės', fontsize=10)  # x-axis label with fontsize 15
    plt.ylabel('Galimos būsenos atlikus matavimą', fontsize=10)  # y-axis label with fontsize 15
    plt.show()