Пример #1
0
def inner_product_array(
    num_states, num_rows, num_cols, max_vecs_per_node, verbosity=1):
    """
    Computes inner products from known vecs.

    Remember that rows correspond to adjoint modes and cols to direct modes
    """
    col_vec_handles = [mr.VecHandlePickle(join(data_dir, col_vec_name%col_num))
        for col_num in mr.range(num_cols)]
    row_vec_handles = [mr.VecHandlePickle(join(data_dir, row_vec_name%row_num))
        for row_num in mr.range(num_rows)]

    generate_vecs(data_dir, num_states, row_vec_handles+col_vec_handles)

    my_VS = mr.VectorSpaceHandles(
        inner_product=np.vdot, max_vecs_per_node=max_vecs_per_node,
        verbosity=verbosity)

    prof = cProfile.Profile()
    start_time = time.time()
    prof.runcall(
        my_VS.compute_inner_product_array, *(col_vec_handles, row_vec_handles))
    total_time = time.time() - start_time
    prof.dump_stats('IP_array_r%d.prof'%mr.parallel.get_rank())

    return total_time
Пример #2
0
def symmetric_inner_product_mat(num_states,
                                num_vecs,
                                max_vecs_per_node,
                                verbosity=1):
    """
    Computes symmetric inner product matrix from known vecs (as in POD).
    """
    vec_handles = [
        MR.VecHandlePickle(join(data_dir, row_vec_name % row_num))
        for row_num in range(num_vecs)
    ]

    generate_vecs(data_dir, num_states, vec_handles)

    my_VS = MR.VectorSpaceHandles(N.vdot,
                                  max_vecs_per_node=max_vecs_per_node,
                                  verbosity=verbosity)

    prof = cProfile.Profile()
    start_time = T.time()
    prof.runcall(my_VS.compute_symmetric_inner_product_mat, vec_handles)
    total_time = T.time() - start_time
    prof.dump_stats('IP_symmetric_mat_r%d.prof' % _parallel.get_rank())

    return total_time
Пример #3
0
def lin_combine(
    num_states, num_bases, num_products, max_vecs_per_node, verbosity=1):
    """
    Computes linear combination of vecs from saved vecs and random coeffs

    num_bases is number of vecs to be linearly combined
    num_products is the resulting number of vecs
    """

    basis_handles = [mr.VecHandlePickle(join(data_dir, basis_name%basis_num))
        for basis_num in mr.range(num_bases)]
    product_handles = [mr.VecHandlePickle(join(data_dir,
        product_name%product_num))
        for product_num in mr.range(num_products)]

    generate_vecs(data_dir, num_states, basis_handles)
    my_VS = mr.VectorSpaceHandles(
        inner_product=np.vdot, max_vecs_per_node=max_vecs_per_node,
        verbosity=verbosity)
    coeff_array = np.random.random((num_bases, num_products))
    mr.parallel.barrier()

    prof = cProfile.Profile()
    start_time = time.time()
    prof.runcall(my_VS.lin_combine, *(product_handles, basis_handles,
        coeff_array))
    total_time = time.time() - start_time
    prof.dump_stats('lincomb_r%d.prof'%mr.parallel.get_rank())
    return total_time
Пример #4
0
base_vec_handle = mr.VecHandlePickle('base_vec.pkl')
snapshots = [
    mr.VecHandlePickle('vec%d.pkl' % i,
                       base_vec_handle=base_vec_handle,
                       scale=quad_weights[i]) for i in range(num_vecs)
]

# Save arbitrary data, normally unnecessary.
num_elements = 2000
parallel = mr.parallel_default_instance
if parallel.is_rank_zero():
    for snap in snapshots + [base_vec_handle]:
        snap.put(np.random.random(num_elements))
parallel.barrier()

# Compute and save POD modes.
my_POD = mr.PODHandles(np.vdot)
my_POD.compute_decomp(snapshots)
my_POD.put_decomp('sing_vals.txt', 'sing_vecs.txt')
my_POD.put_correlation_mat('correlation_mat.txt')
mode_indices = [1, 4, 5, 0, 10]
modes = [mr.VecHandleArrayText('mode%d.txt' % i) for i in mode_indices]
my_POD.compute_modes(mode_indices, modes)

# Check that modes are orthonormal
vec_space = mr.VectorSpaceHandles(inner_product=np.vdot)
IP_mat = vec_space.compute_symmetric_inner_product_mat(modes)
if not np.allclose(IP_mat, np.eye(len(mode_indices))):
    print('Warning: modes are not orthonormal', IP_mat)