예제 #1
0
def main():
    """
    Main Learning network using dynamic graph
    :return: Plot or No return
    """

    # Read data from built-in function or xyz file depending on OS
    sysStr = platform.system()
    if sysStr == 'Windows':
        #  Windows does not support SCF, using H2_generator instead
        print('Molecule data will be read from built-in function')
        _H, _, N = H2_generator()
        print('Read Process Finished')

    elif sysStr in ('Linux', 'Darwin'):
        # for linux only
        from paddle_quantum.VQE.chemistrygen import read_calc_H
        # Harmiltonian and cnot module preparing, must be executed under Linux
        # Read the H2 molecule data
        print('Molecule data will be read from h2.xyz')
        _H, _, N = read_calc_H(geo_fn='h2.xyz')
        print('Read Process Finished')

    else:
        print("Don't support this OS.")

    Paddle_VQE(_H, N)
    benchmark_result()
예제 #2
0
def benchmark_result():
    """
    benchmark using numpy
    """

    # Read H and calc using numpy
    sysStr = platform.system()
    if sysStr == 'Windows':
        #  Windows does not support SCF, using H2_generator instead
        print('Molecule data will be read from built-in function')
        _H, _, _ = H2_generator()
        print('Read Process Finished')
    elif sysStr == 'Linux' or sysStr == 'Darwin':
        # for linux only
        from paddle_quantum.VQE.chemistrygen import read_calc_H
        # Harmiltonian and cnot module preparing, must be executed under Linux
        # Read the H2 molecule data
        print('Molecule data will be read from h2.xyz')
        _H, _, _ = read_calc_H(geo_fn='h2.xyz')
        print('Read Process Finished')
    else:
        print("Don't support this os.")

    # plot
    x1 = numpy.load('./output/summary_data.npz')

    eig_val, eig_state = numpy.linalg.eig(_H)
    min_eig_H = numpy.min(eig_val)
    min_loss = numpy.ones([len(x1['iter'])]) * min_eig_H

    plt.figure(1)
    func1, = plt.plot(x1['iter'],
                      x1['energy'],
                      alpha=0.7,
                      marker='',
                      linestyle="--",
                      color='m')
    func_min, = plt.plot(x1['iter'],
                         min_loss,
                         alpha=0.7,
                         marker='',
                         linestyle=":",
                         color='b')
    plt.xlabel('Number of iteration')
    plt.ylabel('Energy (Ha)')

    plt.legend(
        handles=[func1, func_min],
        labels=[
            r'$\left\langle {\psi \left( {\bf{\theta }} \right)} '
            r'\right|H\left| {\psi \left( {\bf{\theta }} \right)} \right\rangle $',
            'Minimum energy',
        ],
        loc='best')

    # output the picture
    plt.show()