Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Mar 4, 2025
2 parents 7a2b54f + 806bad7 commit 7806f7e
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
exclude: ^example/AlN-LDA/

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
rev: v0.9.9
hooks:
- id: ruff
args: [ "--fix", "--show-fixes" ]
Expand Down
4 changes: 4 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Change Log

## Mar-4-2025: Version 3.15.0

- Release to follow the change of phonopy

## Mar-1-2025: Version 3.14.1

- Release to follow the change of phonopy
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
# built documents.
#
# The short X.Y version.
version = "3.14"
version = "3.15"
# The full version, including alpha/beta/rc tags.
release = "3.14.1"
release = "3.15.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
35 changes: 23 additions & 12 deletions doc/pypolymlp.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ in the distribution from GitHub or PyPI.
`phono3py_params.yaml`. Use {ref}`--cf3 <cf3_option>` and {ref}`--sp
<sp_option>` option simultaneously.
4. Develop MLPs. By default, 90 and 10 percents of the dataset are used for the
training and test, respectively. At this step `phono3py.pmlp` is saved.
training and test, respectively. At this step `polymlp.yaml` is saved.
5. Generate displacements in supercells either systematic or random displacements.
6. Evaluate MLPs for forces of the supercells generated in step 5.
7. Calculate force constants from displacement-force dataset from steps 5 and 6.
Expand Down Expand Up @@ -217,7 +217,7 @@ Regression: model selection ...
- alpha = 1.000e-01 : rmse (train, test) = 0.00002 0.00002
- alpha = 1.000e+00 : rmse (train, test) = 0.00002 0.00002
- alpha = 1.000e+01 : rmse (train, test) = 0.00002 0.00002
MLPs were written into "phono3py.pmlp"
MLPs were written into "polymlp.yaml"
------------------------------ pypolymlp end -------------------------------
Generate displacements (--rd or -d) for proceeding to phonon calculations.
Summary of calculation was written in "phono3py.yaml".
Expand All @@ -231,7 +231,7 @@ Summary of calculation was written in "phono3py.yaml".

Information about the development of MLPs using pypolymlp is provided between
the `pypolymlp start` and `pypolymlp end` sections. The polynomial MLPs are
saved in the `phono3py.pmlp` file, which can be reused in subsequent phono3py
saved in the `polymlp.yaml` file, which can be reused in subsequent phono3py
executions with the `--pypolymlp` option when only displacements (and no forces)
are provided.

Expand All @@ -240,7 +240,7 @@ are provided.

With the `-d` option, displacements are systematically generated while taking
crystal symmetry into account. When running with the `--pypolymlp` option, MLPs
are read from `phono3py.pmlp` if the file exists. In this case, training data is
are read from `polymlp.yaml` if the file exists. In this case, training data is
no longer required, and files such as `phono3py.yaml` can be used as the input
structure file.

Expand Down Expand Up @@ -274,7 +274,7 @@ NAC parameters were read from "phono3py.yaml".
Pypolymlp is a generator of polynomial machine learning potentials.
Please cite the paper: A. Seko, J. Appl. Phys. 133, 011101 (2023).
Pypolymlp is developed at https://github.com/sekocha/pypolymlp.
Load MLPs from "phono3py.pmlp".
Load MLPs from "polymlp.yaml".
------------------------------ pypolymlp end -------------------------------
Generate displacements
Displacement distance: 0.01
Expand Down Expand Up @@ -318,7 +318,7 @@ Random displacements are generated by specifying {ref}`--rd
<random_displacements_option>` option. To compute force constants with random
displacements, an external force constants calculator is necessary. By default,
symfc is used unless another force constants solver is explicitly specified.
When running with the `--pypolymlp` option, MLPs are read from `phono3py.pmlp`
When running with the `--pypolymlp` option, MLPs are read from `polymlp.yaml`
if the file exists. In this case, training data is no longer required, and files
such as `phono3py.yaml` can be used as the input structure file.

Expand Down Expand Up @@ -352,7 +352,7 @@ NAC parameters were read from "phono3py.yaml".
Pypolymlp is a generator of polynomial machine learning potentials.
Please cite the paper: A. Seko, J. Appl. Phys. 133, 011101 (2023).
Pypolymlp is developed at https://github.com/sekocha/pypolymlp.
Load MLPs from "phono3py.pmlp".
Load MLPs from "polymlp.yaml".
------------------------------ pypolymlp end -------------------------------
Generate random displacements
Twice of number of snapshots will be generated for plus-minus displacements.
Expand Down Expand Up @@ -406,10 +406,10 @@ displacements. Note that to achieve accurate force constants, the actual number
of generated supercells is twice the specified number. If `--rd` is omitted,
systematic displacements are introduced.

Once the file `phono3py.pmlp` is obtained, force constants can be calculated
using MLPs from `phono3py.pmlp`. After removing the `fc3.hdf5` and `fc2.hdf5`
files, `phono3py-load` will detect `phono3py.pmlp` and then compute the force
constants by loading the MLPs from `phono3py.pmlp` as follows:
Once the file `polymlp.yaml` is obtained, force constants can be calculated
using MLPs from `polymlp.yaml`. After removing the `fc3.hdf5` and `fc2.hdf5`
files, `phono3py-load` will detect `polymlp.yaml` and then compute the force
constants by loading the MLPs from `polymlp.yaml` as follows:

```
% phono3py-load --pypolymlp --rd 100 --amplitude 0.005 phono3py.yaml
Expand Down Expand Up @@ -441,7 +441,7 @@ NAC parameters were read from "phono3py.yaml".
Pypolymlp is a generator of polynomial machine learning potentials.
Please cite the paper: A. Seko, J. Appl. Phys. 133, 011101 (2023).
Pypolymlp is developed at https://github.com/sekocha/pypolymlp.
Load MLPs from "phono3py.pmlp".
Load MLPs from "polymlp.yaml".
------------------------------ pypolymlp end -------------------------------
Generate random displacements
Twice of number of snapshots will be generated for plus-minus displacements.
Expand Down Expand Up @@ -542,3 +542,14 @@ the next 100 supercells) will be computed and included. With this procedure in
mind, it may be convenient to generate a sufficiently large number of supercells
with random displacements in advance, such as 1000 supercells, before starting
the LTC calculation with pypolymlp.

## Converting `phono3py.pmlp` to `polymlp.yaml`

In older versions, polynomial MLPs were stored in `phono3py.pmlp`. This file can
be converted to `polymlp.yaml` using the following Python snippet.

```python
from pypolymlp.mlp_dev.pypolymlp import Pypolymlp
polymlp = Pypolymlp()
polymlp.convert_to_yaml(filename_txt="phono3py.pmlp", filename_yaml="polymlp.yaml”)
```
65 changes: 43 additions & 22 deletions phono3py/cui/create_force_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def run_pypolymlp_to_compute_forces(
random_seed: Optional[int] = None,
prepare_dataset: bool = False,
cutoff_pair_distance: Optional[float] = None,
mlp_filename: str = "phono3py.pmlp",
mlp_filename: Optional[str] = None,
log_level: int = 0,
):
"""Run pypolymlp to compute forces."""
Expand All @@ -535,27 +535,48 @@ def run_pypolymlp_to_compute_forces(
print("Please cite the paper: A. Seko, J. Appl. Phys. 133, 011101 (2023).")
print("Pypolymlp is developed at https://github.com/sekocha/pypolymlp.")

if pathlib.Path(mlp_filename).exists():
if log_level:
print(f'Load MLPs from "{mlp_filename}".')
ph3py.load_mlp(mlp_filename)
elif forces_in_dataset(ph3py.mlp_dataset):
if log_level:
if mlp_params is None:
pmlp_params = PypolymlpParams()
else:
pmlp_params = parse_mlp_params(mlp_params)
print("Parameters:")
for k, v in asdict(pmlp_params).items():
if v is not None:
print(f" {k}: {v}")
print("Developing MLPs by pypolymlp...", flush=True)
ph3py.develop_mlp(params=mlp_params)
ph3py.save_mlp(filename=mlp_filename)
if log_level:
print(f'MLPs were written into "{mlp_filename}"', flush=True)
else:
raise RuntimeError(f'"{mlp_filename}" is not found.')
mlp_loaded = False
for mlp_filename in ["polymlp.yaml", "phono3py.pmlp"]:
_mlp_filename_list = list(pathlib.Path().glob(f"{mlp_filename}*"))
if _mlp_filename_list:
_mlp_filename = _mlp_filename_list[0]
print(_mlp_filename)
if _mlp_filename.suffix not in [
".yaml",
".pmlp",
".xz",
".gz",
".bz2",
"lzma",
]:
continue
if log_level:
print(f'Load MLPs from "{mlp_filename}".')
ph3py.load_mlp(mlp_filename)
mlp_loaded = True
if log_level and mlp_filename == "phono3py.pmlp":
print(f'Loading MLPs from "{_mlp_filename}" is obsolete.')
break

mlp_filename = "polymlp.yaml"
if not mlp_loaded:
if forces_in_dataset(ph3py.mlp_dataset):
if log_level:
if mlp_params is None:
pmlp_params = PypolymlpParams()
else:
pmlp_params = parse_mlp_params(mlp_params)
print("Parameters:")
for k, v in asdict(pmlp_params).items():
if v is not None:
print(f" {k}: {v}")
print("Developing MLPs by pypolymlp...", flush=True)
ph3py.develop_mlp(params=mlp_params)
ph3py.save_mlp(filename=mlp_filename)
if log_level:
print(f'MLPs were written into "{mlp_filename}"', flush=True)
else:
raise RuntimeError(f'"{mlp_filename}" is not found.')

if log_level:
print("-" * 30 + " pypolymlp end " + "-" * 31, flush=True)
Expand Down
2 changes: 1 addition & 1 deletion phono3py/cui/phono3py_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ def main(**argparse_control):
)
ph3py.save(mlp_eval_filename)

# pypolymlp dataset is stored in "phono3py.pmlp" and stop here.
# pypolymlp dataset is stored in "polymlp.yaml" and stop here.
if not prepare_dataset:
if log_level:
print(
Expand Down
2 changes: 1 addition & 1 deletion phono3py/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

__version__ = "3.14.1"
__version__ = "3.15.0"
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ dependencies = [
"matplotlib",
"h5py",
"spglib",
"phonopy>=2.37.1,<2.38",
"phonopy>=2.38.0,<2.39",
]
license = { file = "LICENSE" }
license = "BSD-3-Clause"
license-files = ["LICENSE"]

[project.urls]
Homepage = "https://phonopy.github.io/phono3py/"
Expand Down
8 changes: 4 additions & 4 deletions test/cui/test_phono3py_load_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def test_phono3py_with_QE_calculator(load_phono3py_yaml):
def test_phono3py_load_with_pypolymlp_si():
"""Test phono3py-load script with pypolymlp.
First run generates phono3py.pmlp.
Second run uses phono3py.pmlp.
First run generates polymlp.yaml.
Second run uses polymlp.yaml.
"""
pytest.importorskip("pypolymlp")
pytest.importorskip("pypolymlp", minversion="0.9.2")
pytest.importorskip("symfc")

argparse_control = _get_phono3py_load_args(
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_phono3py_load_with_pypolymlp_si():
"phono3py.yaml",
"fc2.hdf5",
"fc3.hdf5",
"phono3py.pmlp",
"polymlp.yaml",
"phono3py_mlp_eval_dataset.yaml",
):
file_path = pathlib.Path(cwd_called / created_filename)
Expand Down

0 comments on commit 7806f7e

Please sign in to comment.