Ejemplo n.º 1
0
def main2():
    y0 = 3.2
    yT = 110.5
    T = 100
    a = -0.097
    problem, pproblem = generate_problem(y0, yT, T, a)
    try:
        N = int(sys.argv[1])
    except:
        N = 1000

    comm = pproblem.comm
    m = comm.Get_size()
    rank = comm.Get_rank()
    if sys.argv[3] == '0':
        if m == 1:
            seq = True
        else:
            seq = False
        read_temp_time('outputDir/solveSpeed/sSpeed_' + str(N) + '.txt',
                       m,
                       seq,
                       rank,
                       N,
                       solve=True)
        return
    elif sys.argv[3] == '2':
        if rank == 0:
            read_vector(N, m, problem)
        return
    test_solve(N, problem, pproblem, name='solveSpeed')
def taylor_test_mpi():
    y0 = 3.2
    yT = 1.5
    T = 1
    a = 0.9
    p = 2
    c = 0.5

    non_mpi, mpi_problem = generate_problem(y0, yT, T, a)

    comm = mpi_problem.comm
    rank = comm.Get_rank()
    m = comm.Get_size()
    N = 100
    mu = 1
    dt = float(T) / (N)

    h = MPIVector(100 * np.random.random(local_u_size(N + 1, m, rank)), comm)

    J = lambda x: mpi_problem.parallel_penalty_functional(x, N, mu)
    u = MPIVector(np.zeros(local_u_size(N + 1, m, rank)), comm)
    for i in range(8):
        eps = 1. / (10**i)
        #print J(u+h*eps)-J(u),rank

    def grad_J(x):
        l = mpi_problem.parallel_adjoint_penalty_solver(x, N, m, mu)
        return mpi_problem.penalty_grad(x, N, m, mu)

    table = {
        'J(u+v)-J(u)': [],
        'J(u+v)-J(u)-dJ(u)v': [],
        'rate1': ['--'],
        'rate2': ['--'],
        'e v': []
    }
    eps_list = []
    for i in range(9):
        eps = 1. / (10**i)
        grad_val = abs(J(u + h * eps) - J(u) - eps * h.dot(grad_J(u)))
        func_val = J(u + h * (eps)) - J(u)
        eps_list.append(eps)
        table['J(u+v)-J(u)'].append(func_val)
        table['J(u+v)-J(u)-dJ(u)v'].append(grad_val)
        table['e v'].append(eps * max(h))
        if i != 0:
            table['rate1'].append(
                np.log(
                    abs(table['J(u+v)-J(u)'][i - 1] / table['J(u+v)-J(u)'][i]))
                / np.log(10))
            table['rate2'].append(
                np.log(
                    abs(table['J(u+v)-J(u)-dJ(u)v'][i - 1] /
                        table['J(u+v)-J(u)-dJ(u)v'][i])) / np.log(10))

    data = pd.DataFrame(table, index=eps_list)
    if rank == 0:
        print data
def main():
    y0 = 3.2
    yT = 1.5
    T = 1
    a = 0.9
    p = 2
    c = 0.5
    _, problem = generate_problem(y0, yT, T, a)
    N = 50000

    rank = problem.comm.Get_rank()
    comm = problem.comm
    m = comm.Get_size()
    opt = {'jtol': 0, 'maxiter': 5, 'ignore xtol': True}
    #problem.parallel_penalty_solve(N,m,[1],Lbfgs_options=opt)
    res = problem.parallel_PPCLBFGSsolve(N, m, [1], options=opt)
    print res[-1].niter
def main():
    y0 = 3.2
    yT = 1.5
    T = 1
    a = 0.9
    p = 2
    c = 0
    problem = generate_problem(y0, yT, T, a)[1]
    N = 125000
    m = 1
    opt = {'jtol': 0, 'maxiter': 5, 'ignore xtol': True}
    u = np.zeros(N + m) + 1
    #problem.Penalty_Gradient(u,N,m,1)
    #problem.Gradient(u,N)
    #problem.Functional(u,N)
    #problem.Penalty_Functional(u,N,m,1)
    #problem.PPCLBFGSsolve(N,m,[N,N**2])
    problem.solve(N, Lbfgs_options=opt)
Ejemplo n.º 5
0
def main():

    y0 = 1
    yT = 1
    T = 1
    a = 1

    eval_type = sys.argv[4]
    if eval_type == '0':
        name = 'gradientSpeed/gradSpeed'
    else:
        name = 'functionalSpeed/funcSpeed'

    problem, pproblem = generate_problem(y0, yT, T, a)

    comm = pproblem.comm
    m = comm.Get_size()
    rank = comm.Get_rank()
    try:
        N = int(sys.argv[1])
    except:
        N = 1000
    try:
        K = int(sys.argv[2])
    except:
        K = 10
    if sys.argv[3] == '0':
        if m == 1:
            seq = True
        else:
            seq = False
        name = 'outputDir/' + name + '_' + str(N) + '.txt'
        read_temp_time(name, m, seq, rank, N)
        return
    if eval_type == '0':
        #test_func(N,K,problem,pproblem)
        test_grad(N, K, problem, pproblem)
    else:
        test_func(N, K, problem, pproblem)