Exemple #1
0
def mgp_model(gp_model):
    """
    test the init function
    """

    grid_params = {}
    if 'twobody' in gp_model.kernels:
        grid_params['twobody'] = {'grid_num': [64], 'lower_bound': [0.1]}
    if 'threebody' in gp_model.kernels:
        grid_params['threebody'] = {
            'grid_num': [16] * 3,
            'lower_bound': [0.1] * 3
        }
    species_list = [1, 2, 3]
    lammps_location = f'tmp_lmp'
    mapped_model = MappedGaussianProcess(grid_params=grid_params,
                                         unique_species=species_list,
                                         n_cpus=1,
                                         lmp_file_name=lammps_location,
                                         var_map='simple')

    # import flare.mgp.mapxb
    # flare.mgp.mapxb.global_use_grid_kern = False

    mapped_model.build_map(gp_model)

    yield mapped_model
    del mapped_model
Exemple #2
0
def test_mgp_gpfa(all_mgp, all_gp):
    """
    Ensure that passing in an MGP also works for the trajectory trainer
    :param all_mgp:
    :param all_gp:
    :return:
    """

    np.random.seed(10)
    gp_model = get_gp("3", "mc", False)
    gp_model.set_L_alpha()

    grid_num_3 = 3
    lower_cut = 0.01
    grid_params_3b = {
        "lower_bound": [lower_cut] * 3,
        "grid_num": [grid_num_3] * 3,
        "svd_rank": "auto",
    }
    grid_params = {"load_grid": None, "update": False}
    grid_params["threebody"] = grid_params_3b
    unique_species = gp_model.training_statistics["species"]

    mgp_model = MappedGaussianProcess(grid_params=grid_params,
                                      unique_species=unique_species,
                                      n_cpus=1)

    mgp_model.build_map(gp_model)

    nenv = 10
    cell = np.eye(3)
    struc, f = get_random_structure(cell, unique_species, nenv)

    struc.forces = np.array(f)

    frames = [struc]

    tt = TrajectoryTrainer(
        frames,
        mgp_model,
        rel_std_tolerance=0,
        abs_std_tolerance=0,
        abs_force_tolerance=1e-8,
        print_training_plan=True,
    )
    assert tt.gp_is_mapped is True
    tt.run()

    # Test that training plan is properly written
    with open("gp_from_aimd_training_plan.json", "r") as f:
        plan = json.loads(f.readline())
    assert isinstance(plan["0"], list)
    assert len(plan["0"]) == len(struc)
    assert [p[0] for p in plan["0"]] == list(range(len(struc)))

    for f in glob(f"gp_from_aimd*"):
        remove(f)