mirror of https://github.com/phonopy/phono3py.git
Add pypolymlp CLI test
This commit is contained in:
parent
591c8224f3
commit
a178e369fb
|
@ -2209,7 +2209,11 @@ class Phono3py:
|
|||
else:
|
||||
_params = params
|
||||
|
||||
if _params.ntrain is not None and _params.ntest is not None:
|
||||
if (
|
||||
_params is not None
|
||||
and _params.ntrain is not None
|
||||
and _params.ntest is not None
|
||||
):
|
||||
ntrain = _params.ntrain
|
||||
ntest = _params.ntest
|
||||
disps = self._mlp_dataset["displacements"]
|
||||
|
|
|
@ -514,7 +514,7 @@ def run_pypolymlp_to_compute_forces(
|
|||
displacement_distance: Optional[float] = None,
|
||||
number_of_snapshots: Optional[int] = None,
|
||||
random_seed: Optional[int] = None,
|
||||
mlp_filename: str = "pypolymlp.mlp",
|
||||
mlp_filename: str = "phono3py.pmlp",
|
||||
log_level: int = 0,
|
||||
):
|
||||
"""Run pypolymlp to compute forces."""
|
||||
|
@ -533,6 +533,9 @@ def run_pypolymlp_to_compute_forces(
|
|||
if log_level:
|
||||
print("Developing MLPs by pypolymlp...", flush=True)
|
||||
ph3py.develop_mlp(params=mlp_params)
|
||||
ph3py.mlp.save_mlp(filename=mlp_filename)
|
||||
if log_level:
|
||||
print(f'MLPs were written into "{mlp_filename}"', flush=True)
|
||||
else:
|
||||
if pathlib.Path(mlp_filename).exists():
|
||||
if log_level:
|
||||
|
@ -581,7 +584,6 @@ def run_pypolymlp_to_compute_forces(
|
|||
raise RuntimeError("Displacements are not set. Run generate_displacements.")
|
||||
|
||||
ph3py.evaluate_mlp()
|
||||
ph3py.save("phono3py_mlp_eval_dataset.yaml")
|
||||
|
||||
|
||||
def run_pypolymlp_to_compute_phonon_forces(
|
||||
|
|
|
@ -163,6 +163,14 @@ def finalize_phono3py(
|
|||
else:
|
||||
yaml_filename = filename
|
||||
|
||||
if phono3py.mlp_dataset is not None:
|
||||
mlp_eval_filename = "phono3py_mlp_eval_dataset.yaml"
|
||||
if log_level:
|
||||
print(
|
||||
f'Dataset generated using MMLPs was written in "{mlp_eval_filename}".'
|
||||
)
|
||||
phono3py.save(mlp_eval_filename)
|
||||
|
||||
_physical_units = get_default_physical_units(phono3py.calculator)
|
||||
|
||||
ph3py_yaml = Phono3pyYaml(
|
||||
|
|
|
@ -173,6 +173,7 @@ def test_type2_forces_energies_setter_Si(si_111_222_rd: Phono3py):
|
|||
def test_use_pypolymlp_mgo(mgo_222rd_444rd: Phono3py):
|
||||
"""Test use_pypolymlp in produce_fc3."""
|
||||
pytest.importorskip("pypolymlp")
|
||||
pytest.importorskip("symfc")
|
||||
|
||||
ph3_in = mgo_222rd_444rd
|
||||
ph3 = Phono3py(
|
||||
|
|
|
@ -36,6 +36,7 @@ class MockArgs:
|
|||
is_bterta: Optional[bool] = None
|
||||
mesh_numbers: Optional[Sequence] = None
|
||||
temperatures: Optional[Sequence] = None
|
||||
use_pypolymlp: bool = False
|
||||
input_filename = None
|
||||
output_filename = None
|
||||
input_output_filename = None
|
||||
|
@ -114,6 +115,54 @@ def test_phono3py_with_QE_calculator(load_phono3py_yaml):
|
|||
file_path.unlink()
|
||||
|
||||
|
||||
def test_phono3py_load_with_pypolymlp_si():
|
||||
"""Test phono3py-load script with pypolymlp.
|
||||
|
||||
First run generates phono3py.pmlp.
|
||||
Second run uses phono3py.pmlp.
|
||||
|
||||
"""
|
||||
pytest.importorskip("pypolymlp")
|
||||
pytest.importorskip("symfc")
|
||||
|
||||
argparse_control = _get_phono3py_load_args(
|
||||
cwd / ".." / "phono3py_params_Si-111-222-rd.yaml.xz",
|
||||
fc_calculator="symfc",
|
||||
use_pypolymlp=True,
|
||||
)
|
||||
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
main(**argparse_control)
|
||||
assert excinfo.value.code == 0
|
||||
|
||||
# phono3py.yaml and fc2.hd5 are used in the next run. So they are not deleted.
|
||||
for created_filename in ("fc3.hdf5", "phono3py_mlp_eval_dataset.yaml"):
|
||||
file_path = pathlib.Path(cwd_called / created_filename)
|
||||
if file_path.exists():
|
||||
file_path.unlink()
|
||||
|
||||
argparse_control = _get_phono3py_load_args(
|
||||
cwd / "phono3py.yaml",
|
||||
fc_calculator="symfc",
|
||||
use_pypolymlp=True,
|
||||
)
|
||||
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
main(**argparse_control)
|
||||
assert excinfo.value.code == 0
|
||||
|
||||
for created_filename in (
|
||||
"phono3py.yaml",
|
||||
"fc2.hdf5",
|
||||
"fc3.hdf5",
|
||||
"phono3py.pmlp",
|
||||
"phono3py_mlp_eval_dataset.yaml",
|
||||
):
|
||||
file_path = pathlib.Path(cwd_called / created_filename)
|
||||
if file_path.exists():
|
||||
file_path.unlink()
|
||||
|
||||
|
||||
def _get_phono3py_load_args(
|
||||
phono3py_yaml_filepath: Union[str, pathlib.Path],
|
||||
fc_calculator: Optional[str] = None,
|
||||
|
@ -121,6 +170,7 @@ def _get_phono3py_load_args(
|
|||
is_bterta: bool = False,
|
||||
temperatures: Optional[Sequence] = None,
|
||||
mesh_numbers: Optional[Sequence] = None,
|
||||
use_pypolymlp: bool = False,
|
||||
):
|
||||
# Mock of ArgumentParser.args.
|
||||
if load_phono3py_yaml:
|
||||
|
@ -130,6 +180,7 @@ def _get_phono3py_load_args(
|
|||
is_bterta=is_bterta,
|
||||
temperatures=temperatures,
|
||||
mesh_numbers=mesh_numbers,
|
||||
use_pypolymlp=use_pypolymlp,
|
||||
log_level=1,
|
||||
)
|
||||
else:
|
||||
|
@ -141,6 +192,7 @@ def _get_phono3py_load_args(
|
|||
is_bterta=is_bterta,
|
||||
temperatures=temperatures,
|
||||
mesh_numbers=mesh_numbers,
|
||||
use_pypolymlp=use_pypolymlp,
|
||||
)
|
||||
|
||||
# See phono3py-load script.
|
||||
|
|
Loading…
Reference in New Issue