Beispiel #1
0
def test__send_results_to_the_qoi_manager():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()
    engine.task_manager.evaluate_tasks(
        parameters=parameters, potential=engine.configuration.potential)
    engine.qoi_manager.calculate_qois(task_results=engine.task_manager.results)
Beispiel #2
0
def test__read_configuration_file():
    engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                            filename_out='pyposmat.config.out')
    engine.read_configuration_file()

    assert isinstance(engine.configuration, PyposmatConfigurationFile)
    assert engine.configuration.qois is not None
Beispiel #3
0
    def read_configuration_file(self, filename=None):
        PyposmatEngine.read_configuration_file(self, filename=filename)
        # self.structure_directory = self.configuration.structures['structure_directory']
        self.n_iterations = self.configuration.sampling_type['n_iterations']
        self.parameter_names = [
            p for p in self.configuration.sampling_distribution
        ]
        self.qoi_names = [k for k in self.configuration.qois]
        self.error_names = ['{}.err'.format(k) for k in self.qoi_names]
        self.parameter_distribution_definition =\
                self.configuration.sampling_distribution

        try:
            self.free_parameter_names = [
                k for k, v in self.parameter_distribution_definition.items()
                if v[0] != 'equals'
            ]
        except KeyError as e:
            print(self.parameter_distribution_definition.items())
            raise
        if self.configuration.sampling_constraints is not None:
            self.parameter_constraints = copy.deepcopy(
                self.configuration.sampling_constraints)
        else:
            self.parameter_constraints = OrderedDict()

        self.constrained_parameter_names = []
        for p in self.parameter_names:
            if p not in self.free_parameter_names:
                self.constrained_parameter_names.append(p)
Beispiel #4
0
def test__create_base_directories():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.create_base_directories()

    assert all([os.path.isdir(d) for d in simulation_directories])

    cleanup_simulation_directories()
Beispiel #5
0
def test__configure():
    # this test are the submethods in the configure() method
    engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                            filename_out='pyposmat.config.out')
    engine.create_base_directories()
    engine.read_configuration_file()
    engine.configure_qoi_manager()
    engine.configure_task_manager()
Beispiel #6
0
    def __init__(self,
                 filename_in='pyposmat.config.in',
                 filename_out='pyposmat.results.out',
                 o_log=None,
                 mpi_rank=None,
                 mpi_size=None,
                 base_directory=None):
        """Additional attributes are set by the base class :obj:PyposmatEngine

        Args:
            filename_in (str) - path of the configuration file
            filename_out (str) - path of the output file
            o_log (PyposmatLogFile) - if type(o_log) is a string, then the string is treated as a path in which to log information to.  If type(o_log) is PyposmatLogFile then it is set as an attribute for the refernce.
            mpi_rank (int)
            mpi_size (int)
            base_directory (str,optional): Either the relative or full path which provides a
        unique drive addressing space for simultaneously running simulations.
        Attributes:
            mpi_rank (int) - this is passed in
            mpi_size (int) - this is passed in
            pyposmat_data_in_filename (str) - the path of the datafile to read in
            pyposmat_data_out_filename (str) - the path of the datafile to write simulation results to
        """
        assert isinstance(filename_in, str)
        assert isinstance(filename_out, str)
        assert type(base_directory) in [str, type(None)]

        PyposmatEngine.__init__(self,
                                filename_in=filename_in,
                                filename_out=filename_out,
                                base_directory=base_directory,
                                fullauto=False)

        if mpi_rank is None:
            self.mpi_rank = 0
        else:
            self.mpi_rank = mpi_rank

        if mpi_size is None:
            self.mpi_size = 1
        else:
            self.mpi_size = mpi_size

        assert self.mpi_rank < self.mpi_size

        self.mpi_rank = mpi_rank
        self.mpi_size = mpi_size
        self.pyposmat_data_in_filename = None
        self.pyposmat_data_out_filename = filename_out
        self.pyposmat_badparameters_filename = 'pyposmat.badparameters.out'

        try:
            self.configure_logger(o_log)
        except TypeError as e:
            m = "Unable to to configure obj_log based on attribute log:{}".format(
                str(o_log))
            raise TypeError(m)
Beispiel #7
0
def test__initialize_w_filenames():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()

    for d in simulation_directories:
        assert os.path.isdir(d)

    cleanup_simulation_directories()
Beispiel #8
0
    def __init__(self,
            config_fn='pyposmat.config.in',
            data_in_fn='pyposmat.results.in',
            data_out_fn='pyposmat.results.out',
            mpi_rank = None,
            mpi_size=None,
            o_log = None,
            log_to_stdout=True,
            base_directory = None,
            fullauto=True):

        self.DEBUG = False
        self.configuration = None
        self.datafile_in = None
        self.datafile_out = None

        self.mpi_rank = None
        self.mpi_size = None

        self.qoi_mananger = None
        self.task_manager = None

        PyposmatEngine.__init__(self,
                filename_in=config_fn,
                filename_out=data_out_fn,
                base_directory=base_directory,
                fullauto=fullauto)

        self.configuration_fn = config_fn
        self.datafile_in_fn = data_in_fn
        self.datafile_out_fn = data_out_fn
        self.pyposmat_badparameters_filename = 'pyposmat.badparameters.out'

        self.configuration = None
        self.datafile = None
        self.subselect_df = None
        self.reference_potentials = None

        self.qoi_validation_names = None
        self.error_validation_names = None
        self.normed_error_validation_names = None

        self.qoi_validation_target = None
        self.obj_log = None
        self.log_to_stdout = None

        self.initialize_mpi_information(mpi_rank=mpi_rank,
                                        mpi_size=mpi_size)
        self.configure_logger(o_log=o_log,
                              log_to_stdout=log_to_stdout)
        if fullauto is True:
            self.read_configuration_file(filename=self.configuration_fn)
            self.read_datafile_in(filename=data_in_fn)
            self.configure_datafile_out(filename=data_out_fn)
Beispiel #9
0
def test__evaluate_tasks_through_the_task_mananager():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()

    assert type(parameters) is OrderedDict
    assert type(engine.configuration.potential) is OrderedDict

    engine.task_manager.evaluate_tasks(
        parameters=parameters, potential=engine.configuration.potential)

    assert type(engine.task_manager.results) is OrderedDict
Beispiel #10
0
def test__configure_task_manager():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.create_base_directories()
    engine.read_configuration_file()
    engine.configure_qoi_manager()
    engine.configure_task_manager()

    from pypospack.task import TaskManager
    assert type(engine.task_manager) is TaskManager

    cleanup_simulation_directories()
Beispiel #11
0
def test__evaluate_parameter_set():

    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()
    results = engine.evaluate_parameter_set(parameters=parameters)

    assert 'parameters' in results
    assert 'qois' in results
    assert type(results['parameters']) is OrderedDict
    assert type(results['qois']) is OrderedDict
    assert all([v is not None for k, v in results['parameters'].items()])
    assert all([v is not None for k, v in results['qois'].items()])
Beispiel #12
0
    def configure_qoi_manager(self,qois=None,use_fitting_qois=True,use_testing_qois=False):

        if qois is not None:
            _qois = copy.deepcopy(qois)
        else:
            _qois = OrderedDict()

            if use_fitting_qois:
                for k,v in self.configuration.qois.items():
                    _qois[k]=v

            if use_testing_qois:
                for k,v in self.configuration.qois_validation.items():
                    _qois[k]=v
        PyposmatEngine.configure_qoi_manager(self,_qois)
Beispiel #13
0
    def read_configuration_file(self,filename=None):
        PyposmatEngine.read_configuration_file(self,filename=filename)

        # does this have to be removed?
        # self.structure_directory = self.configuration.structures['structure_directory']
        if self.DEBUG:
            if os.path.isdir(self.structure_directory):
                msg = "[OK] structure_directory:".format(self.structure_directory)
                self.__log(msg)
            else:
                msg = "[FAIL] structure_directory:".format(self.structure_directory)
                raise PyposmatEngineError(msg)
        

        # set name arrays for validation qois
        self.qoi_validation_names = self.configuration.qoi_validation_names
        self.error_validation_names = self.configuration.error_validation_names
        self.normed_error_validation_names = self.configuration.normed_error_validation_names

        # set dictionaries for qoi targets
        self.qoi_validation_targets = self.configuration.qoi_validation_targets
    
        # set dictionary for reference potentials
        self.reference_potentials = self.configuration.reference_potentials
Beispiel #14
0
def test__read_configuration_file():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.create_base_directories()
    engine.read_configuration_file()

    from pypospack.pyposmat.data import PyposmatConfigurationFile
    assert type(engine.configuration) is PyposmatConfigurationFile

    cleanup_simulation_directories()
Beispiel #15
0
    from pypospack.pyposmat.engines import PyposmatEngine
    from pypospack.pyposmat.data import PyposmatDataFile
    from pypospack.pyposmat.data import PyposmatConfigurationFile
    # from pypospack.qoi import QoiManager
    # from pypospack.task import TaskManager

    filename_config = 'pypospack.config.in'

    write_configuration_file(
            filename=filename_config,
            qois=qoi_db.qois,
            potential_definition=potential_definition,
            structures=structures)

    #Ni_configuration = PyposmatConfigurationFile()
    #Ni_configuration.qois = Ni_qoi_db.qois
    #Ni_configuration.potential = potential_definition
    #Ni_configuration.structures = Ni_structures
    #Ni_configuration.write(filename='pypospack.config.in')
    #Ni_configuration.read(filename='pypospack.config.in')

    engine = PyposmatEngine(
            filename_in = 'pypospack.config.in',
            filename_out = 'pypospack.config.out')
    engine.configure()

    _parameters = potential_parameters
    results = engine.evaluate_parameter_set(parameters=_parameters)

    print(results)
                                         ('SiSiSi_a', 1.927303534824485),
                                         ('SiSiSi_lambda', 12.109230909182934),
                                         ('SiSiSi_gamma', 2.242334213331301),
                                         ('SiSiSi_costheta0',
                                          -0.3333333333333333),
                                         ('SiSiSi_A', 19.19755654803364),
                                         ('SiSiSi_B', 0.16452955359488666),
                                         ('SiSiSi_p', 4.313046208558489),
                                         ('SiSiSi_q', 0.7433313641477534),
                                         ('SiSiSi_tol', 0.0)])


def cleanup(testing_set):
    import shutil

    if os.path.exists(testing_set['base_directory']):
        if os.path.isdir(testing_set['base_directory']):
            shutil.rmtree(testing_set['base_directory'])
        elif os.path.isfile(testing_set['base_directory']):
            os.remove(testing_set['base_directory'])
        else:
            raise ValueError('path:{}'.format(testing_set['base_directory']))


if __name__ == "__main__":
    cleanup(testing_set)
    o = PyposmatEngine(filename_in=testing_set['config_fn'],
                       base_directory=testing_set['base_directory'])
    o.configure()
    o.evaluate_parameter_set(parameters=testing_set['parameters'])
Beispiel #17
0
    engine.read_configuration_file()
    engine.configure_qoi_manager()


def test__configure():
    # this test are the submethods in the configure() method
    engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                            filename_out='pyposmat.config.out')
    engine.create_base_directories()
    engine.read_configuration_file()
    engine.configure_qoi_manager()
    engine.configure_task_manager()


if __name__ == "__main__":
    engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                            filename_out='pyposmat.config.out')
    engine.read_configuration_file()
    #print(engine.configuration)
    #print(engine.configuration.read(filename=_pyposmat_config_fn))
    print(engine.configuration.configuration)

    if False:
        print("structure_directory:{}".format(engine.structure_directory))
        print("structures")
        for k, v in engine.structures['structures'].items():
            print(k, v)

        from pypospack.potentials.MgO import MgO_LewisCatlow
        _parameters = MgO_LewisCatlow['parameters']
        _results = engine.evaluate_parameter_set(parameters=_parameters)
Beispiel #18
0
def test__configure():
    engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()
Beispiel #19
0
        parameters=parameters, potential=engine.configuration.potential)

    assert type(engine.task_manager.results) is OrderedDict


def test__send_results_to_the_qoi_manager():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()
    engine.task_manager.evaluate_tasks(
        parameters=parameters, potential=engine.configuration.potential)
    engine.qoi_manager.calculate_qois(task_results=engine.task_manager.results)


if __name__ == "__main__":
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()
    results = engine.evaluate_parameter_set(parameters=parameters)
    print(results)
    if False:
        #print_parameters(parameters=parameters)
        m = [80 * '=', '{:^80}'.format('Potential Description'), 80 * '=']
        m += ['potential_description']
        for k, v in engine.configuration.potential.items():
            m += ['\t{} = {}'.format(k, v)]
        m += ['parameters']
        m += ['\t{} = {}'.format(k, v) for k, v in parameters.items()]
        m += [80 * '=', '{:80}'.format('Evaluate Parameter Set'), 80 * '=']
        engine.task_manager.evaluate_tasks(
            parameters=parameters, potential=engine.configuration.potential)
        m += ['engine.task_manager.results:']
Beispiel #20
0
def test__create_base_directories():
    engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                            filename_out='pyposmat.config.out')
    engine.create_base_directories()
Beispiel #21
0
 def configure_task_manager(self):
     PyposmatEngine.configure_task_manager(self)
from pypospack.exceptions import LammpsSimulationError

filename_in = "pypospack.config.in"
filename_out = "pypospack.results.out"

a0 = 3.52
r0 = 1 / (2**0.5) * a0
parameters = OrderedDict()
parameters['p_NiNi_phi0'] = 1.0
parameters['p_NiNi_gamma'] = 2.0
parameters['p_NiNi_r0'] = r0
parameters['d_Ni_rho0'] = 1.0
parameters['d_Ni_beta'] = 4.0
parameters['d_Ni_r0'] = r0
parameters['e_Ni_latticetype'] = 'fcc'
parameters['e_Ni_ecoh'] = -4.45
parameters['e_Ni_B'] = 188.
parameters['e_Ni_a0'] = a0

if __name__ == "__main__":
    engine = PyposmatEngine(filename_in=filename_in, filename_out=filename_out)
    engine.read_configuration_file(
        filename=os.path.join('data', 'pyposmat.config.in'))
    engine.configure_qoi_manager()
    engine.configure_task_manager()
    try:
        engine.evaluate_parameter_set(parameters=parameters)
    except LammpsSimulationError as e:
        print('lammps_simulation_error')
Beispiel #23
0
Ni_eam_parameters = OrderedDict()
Ni_eam_parameters['p_NiNi_D0'] = 0.001114
Ni_eam_parameters['p_NiNi_a'] = 3.429506
Ni_eam_parameters['p_NiNi_r0'] = 2.6813
Ni_eam_parameters['d_Ni_rho0'] = 10.0
Ni_eam_parameters['d_Ni_beta'] = 5.0
Ni_eam_parameters['d_Ni_r0'] = 2.0
Ni_eam_parameters['e_Ni_F0'] = 4.10341782e-3
Ni_eam_parameters['e_Ni_p'] = 8.96274624
Ni_eam_parameters['e_Ni_q'] = 8.95940869
Ni_eam_parameters['e_Ni_F1'] = -3.09

_structure_directory = 'test_PypospackEngine'
Ni_structures = OrderedDict()
Ni_structures['Ni_fcc_unit'] = os.path.join(
        _structure_directory,
        'Ni_fcc_unit.gga.relax.vasp')

Ni_pypospack_config = OrderedDict()
Ni_pypospack_config['qoi_info'] = Ni_qoi
Ni_pypospack_config['structures'] = Ni_structures

_pypospack_root_directory = pypospack.utils.get_pypospack_root_directory()
_pyposmat_config_fn = os.path.join(_pypospack_root_directory,'data','MgO_pareto_data','pyposmat.config.in')

engine = PyposmatEngine(
        filename_in = _pyposmat_config_fn,
        filename_out = 'pypospack.config.out')
engine.configure()

Beispiel #24
0
def test__configure():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()
    cleanup_simulation_directories()
Beispiel #25
0
def test__configure_qoi_manager():
    engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                            filename_out='pyposmat.config.out')
    engine.read_configuration_file()
    engine.configure_qoi_manager()
Beispiel #26
0
def test__evaluate_parameter_set():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
    engine.configure()
    results = engine.evaluate_parameter_set(parameters=parameters)
    cleanup_simulation_directories()
Beispiel #27
0
def test__init__():
    engine = PyposmatEngine(filename_in=config_fn,
                            filename_out='pyposmat.config.out')
import os
from collections import OrderedDict
import pypospack.utils
from pypospack.pyposmat.engines import PyposmatEngine
from pypospack.pyposmat.data import PyposmatDataFile

_pypospack_root_directory = pypospack.utils.get_pypospack_root_directory()
_pyposmat_config_fn = os.path.join(_pypospack_root_directory, 'data',
                                   'MgO_pareto_data', 'pyposmat.config.in')

engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                        filename_out='pyposmat.config.out')
engine.configure()

# this test are the submethods in the configure() method
engine = PyposmatEngine(filename_in=_pyposmat_config_fn,
                        filename_out='pyposmat.config.out')
engine.create_base_directories()
engine.read_configuration_file()
engine.configure_qoi_manager()
engine.configure_task_manager()

print("structure_directory:{}".format(engine.structure_directory))
print("structures")
for k, v in engine.structures['structures'].items():
    print(k, v)

from pypospack.potentials.MgO import MgO_LewisCatlow
_parameters = MgO_LewisCatlow['parameters']
_results = engine.evaluate_parameter_set(parameters=_parameters)