def test__read_configuration_file():
    pyposmat_app = PyposmatIterativeSampler(configuration_filename=config_fn)
    pyposmat_app.read_configuration_file()

    assert type(pyposmat_app.configuration_filename) is str
    assert type(pyposmat_app.configuration) is PyposmatConfigurationFile
    assert os.path.isabs(pyposmat_app.configuration_filename)
    assert pyposmat_app.configuration_filename == os.path.abspath(config_fn)
예제 #2
0
def test__initialize_data_directory__with_relative_path_arg():
    test_data_dir_path = 'test_dir'

    pyposmat_app = PyposmatIterativeSampler(configuration_filename = config_fn)
    pyposmat_app.read_configuration_file()
    is_created,s = pyposmat_app.initialize_data_directory(data_directory=test_data_dir_path)

    assert s == os.path.join(os.getcwd(),test_data_dir_path)
    assert pyposmat_app.data_directory == os.path.join(os.getcwd(),test_data_dir_path)
    shutil.rmtree(test_data_dir_path)
def test__determine_rv_seeds__seeds_do_not_change_when_run_again():
    pyposmat_app = PyposmatIterativeSampler(configuration_filename=config_fn)
    pyposmat_app.read_configuration_file()
    pyposmat_app.setup_mpi_environment()
    pyposmat_app.determine_rv_seeds()

    # make sure the seed doesn't change when it's run again
    old_seed = pyposmat_app.rv_seed
    old_seeds = pyposmat_app.rv_seeds
    pyposmat_app.determine_rv_seeds()

    assert pyposmat_app.rv_seed == old_seed
    assert np.array_equal(pyposmat_app.rv_seeds, old_seeds)
def dev__determine_rv_seeds():
    pyposmat_app = PyposmatIterativeSampler(configuration_filename=config_fn)
    pyposmat_app.read_configuration_file()
    pyposmat_app.setup_mpi_environment()
    pyposmat_app.determine_rv_seeds()

    print('pyposmat_app.rv_seed:')
    print('\ttype:{}.'.format(str(type(pyposmat_app.rv_seed))))
    print('pyposmat_app.rv_seeds:')
    print(pyposmat_app.rv_seeds.shape)
def test__initialize_rank_directory():
    pyposmat_app = PyposmatIterativeSampler(configuration_filename = config_fn)
    pyposmat_app.setup_mpi_environment()
    pyposmat_app.initialize_rank_directory()

    assert os.path.isabs(pyposmat_app.rank_directory)
    assert pyposmat_app.rank_directory == os.path.abspath('rank_{}'.format(pyposmat_app.mpi_rank))
def dev__setup_mpi_environment():
    pyposmat_app = PyposmatIterativeSampler(configuration_filename=config_fn)
    pyposmat_app.read_configuration_file()
    pyposmat_app.setup_mpi_environment()

    print('pyposmat_app.mpi_rank:{}'.format(str(pyposmat_app.mpi_rank)))
    print('pyposmat_app.mpi_size:{}'.format(str(pyposmat_app.mpi_size)))
def test__determine_rv_seeds__no_args__attribute_not_none():
    pyposmat_app = PyposmatIterativeSampler(configuration_filename=config_fn)
    pyposmat_app.read_configuration_file()
    pyposmat_app.setup_mpi_environment()

    pyposmat_app.rv_seed = 1

    assert type(pyposmat_app.rv_seed) is int
    assert type(pyposmat_app.rv_seeds) is type(None)
    assert pyposmat_app.rv_seed == 1

    pyposmat_app.determine_rv_seeds()

    assert type(pyposmat_app.rv_seed) is int
    assert type(pyposmat_app.rv_seeds) is np.ndarray
    assert pyposmat_app.rv_seed == 1
    assert pyposmat_app.rv_seeds.shape[0] == pyposmat_app.mpi_size
    assert pyposmat_app.rv_seeds.shape[1] == pyposmat_app.n_iterations
def test__setup_mpi_environment():
    pyposmat_app = PyposmatIterativeSampler(configuration_filename=config_fn)
    pyposmat_app.read_configuration_file()
    pyposmat_app.setup_mpi_environment()

    assert type(pyposmat_app.mpi_comm) is MPI.Intracomm
    assert type(pyposmat_app.mpi_rank) is int
    assert type(pyposmat_app.mpi_size) is int
예제 #9
0
import os,shutil,sys
import numpy as np
from mpi4py import MPI
from pypospack.pyposmat.data import PyposmatConfigurationFile
from pypospack.pyposmat.engines import PyposmatIterativeSampler

# set to true, if you want to restart the simulation, and recover from the last iteration
# which was completed.  
is_restart = False

if __name__ == "__main__":
    pyposmat_data_dir = 'data' 
    pyposmat_filename_in = os.path.join(
            pyposmat_data_dir,'pyposmat.config.in')
    #------------------------------------------------------------------------------
    # RUN PYPOSMAT 
    #------------------------------------------------------------------------------
    pyposmat_app = PyposmatIterativeSampler(
        configuration_filename = pyposmat_filename_in,
        is_restart=is_restart
    )
    pyposmat_app.data_dir = pyposmat_data_dir
    pyposmat_app.read_configuration_file()
    pyposmat_app.run_all()
예제 #10
0
import os,shutil,sys
import numpy as np
from mpi4py import MPI
from pypospack.pyposmat.data import PyposmatConfigurationFile
from pypospack.pyposmat.engines import PyposmatIterativeSampler

from pypospack.pyposmat.data import PyposmatDataFile
import pandas as pd
class Dev__PyposmatIterativeSampler(PyposmatIterativeSampler):
    pass 

    
if __name__ == "__main__":
    pyposmat_data_dir = 'data__Ni__eam__born_exp_fs_00'
    pyposmat_filename_in = os.path.join(
            'data__Ni__eam__born_exp_fs_00',
            'pyposmat.config.in')
    #------------------------------------------------------------------------------
    # RUN PYPOSMAT 
    #------------------------------------------------------------------------------
    pyposmat_app = PyposmatIterativeSampler(
        configuration_filename = pyposmat_filename_in)
    pyposmat_app.data_directory = 'data__Ni__eam__born_exp_fs_00'
    pyposmat_app.read_configuration_file()
    #pyposmat_app.run_restart()
    #exit()
    pyposmat_app.run_all()
예제 #11
0
import os,shutil,sys
import numpy as np
from mpi4py import MPI
from pypospack.pyposmat.data import PyposmatConfigurationFile
from pypospack.pyposmat.engines import PyposmatIterativeSampler

if __name__ == "__main__":
    import Ni__eam__born_exp_fs_0 as config

    pyposmat_filename_in = 'pyposmat.config.in'
 
    #------------------------------------------------------------------------------
    # RUN PYPOSMAT 
    #------------------------------------------------------------------------------
    pyposmat_app = PyposmatIterativeSampler(
        configuration_filename = pyposmat_filename_in)
    pyposmat_app.read_configuration_file()
    #pyposmat_app.read_configuration_file(filename=pyposmat_configuration_filename)
    pyposmat_app.run_all()
예제 #12
0
from pypospack.pyposmat.data import PyposmatConfigurationFile
from pypospack.pyposmat.data import PyposmatDataFile

import os
import pypospack.utils

_pypospack_root = pypospack.utils.get_pypospack_root_directory()
_simulation_root =  os.path.join(
    _pypospack_root,
    'examples','Ni__eam__born_exp_rose','01_preconditioning_3.5NN')

_pyposmat_configuration_fn = os.path.join(_simulation_root,'data','pyposmat.config.in')
_pyosmat_log_fn = 'pyposmat.log'
_i_iteration = 0
_last_datafile_fn = os.path.join(_simulation_root,'data','pyposmat.kde.1.out')
_new_datafile_fn = 'pyposmat.results.1.out'


engine = PyposmatIterativeSampler(
        configuration_filename=_pyposmat_configuration_fn,
        log_fn='pyposmat.log')
engine.read_configuration_file(
        filename=_pyposmat_configuration_fn)

_data_fn = os.path.join(_simulation_root,'data','pyposmat.results.0.out')
engine.analyze_results(
        i_iteration=0,
        data_fn=_data_fn,
        config_fn=_pyposmat_configuration_fn,
        kde_fn='pyposmat.kde.1.out')
예제 #13
0
def dev__run_parametric_sampling():
    o = PyposmatIterativeSampler(configuration_filename=config_fn)
    o.data_dir = pyposmat_data_dir
    o.read_configuration_file()

    # ensure that the configuration is actually setup as parametric
    assert o.configuration.sampling_type[i_iteration]['type'] == 'parametric'

    #this setup happens in run_all()
    o.setup_mpi_environment()
    o.initialize_data_directory()
    o.i_iteration = i_iteration
    o.log_iteration_information(i_iteration=o.i_iteration)

    #this setup happens in run_simulations()
    o.initialize_rank_directory()

    # ensure that the paths are absolute paths
    assert os.path.isabs(o.rank_directory)
    assert os.path.isabs(o.configuration_filename)
    config_filename = o.configuration_filename
    results_filename = os.path.join(o.rank_directory,
                                    'pyposmat.results.{}.out')
    bad_parameters_filename = os.path.join(o.rank_directory,
                                           'pyposmat.bad_parameters.{}.out')

    os.chdir(o.rank_directory)

    o.determine_rv_seeds()

    o.initialize_sampler(config_fn=config_filename,
                         results_fn=results_filename,
                         mpi_rank=o.mpi_rank,
                         mpi_size=o.mpi_size,
                         o_log=o.o_log)

    o.run_parametric_sampling(i_iteration=i_iteration)
예제 #14
0
def test__read_configuration_files__no_args():
    engine = PyposmatIterativeSampler(
        configuration_filename=_pyposmat_configuration_fn,
        log_fn='pyposmat.log')
    engine.read_configuration_file()
    assert type(engine.configuration) is PyposmatConfigurationFile
예제 #15
0
def test____init__():
    engine = PyposmatIterativeSampler(
        configuration_filename=_pyposmat_configuration_fn,
        log_fn='pyposmat.log')