Skip to content

Commit

Permalink
Merge branch 'develop' into publish-gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Sep 13, 2024
2 parents 7087bb8 + a3d7d26 commit 4616b78
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 421 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
git clone https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
cd ..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phono3py-pytest-conda-mkl-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
git clone https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
cd ..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phono3py-pytest-conda-mkl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
git clone https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
cd ..
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phono3py-pytest-conda-numpy2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ jobs:
- name: Install symfc develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/symfc/symfc.git
git clone https://github.com/symfc/symfc.git
cd symfc
pip install -e . -vvv
cd ..
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
git clone https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
cd ..
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phono3py-pytest-conda-phphmtblas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ jobs:
- name: Install symfc develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/symfc/symfc.git
git clone https://github.com/symfc/symfc.git
cd symfc
pip install -e . -vvv
cd ..
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
git clone https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
cd ..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phono3py-pytest-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
git clone https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
cd ..
Expand Down
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.6.3
rev: v0.6.4
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

## Sep-13-2024: Version 3.5

- Maintenance release.

## Aug-23-2024: Version 3.4

- Update for spglib v2.5 and for following the change in 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.4"
version = "3.5"
# The full version, including alpha/beta/rc tags.
release = "3.4.0"
release = "3.5.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
5 changes: 1 addition & 4 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ Papers that may introduce phono3py:
[JPCM.35.353001](https://iopscience.iop.org/article/10.1088/1361-648X/acd831)
(open access)


## Documentation

```{toctree}
:maxdepth: 1
:hidden:
install
workflow
examples
Expand Down
28 changes: 7 additions & 21 deletions phono3py/api_phono3py.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from phonopy.interface.pypolymlp import (
PypolymlpData,
PypolymlpParams,
develop_mlp_by_pypolymlp,
develop_polymlp,
evalulate_polymlp,
load_polymlp,
Expand Down Expand Up @@ -2204,30 +2205,15 @@ def develop_mlp(
if self._mlp_dataset is None:
raise RuntimeError("MLP dataset is not set.")

if params is not None:
_params = parse_mlp_params(params)
else:
_params = params

disps = self._mlp_dataset["displacements"]
forces = self._mlp_dataset["forces"]
energies = self._mlp_dataset["supercell_energies"]
n = int(len(disps) * (1 - test_size))
train_data = PypolymlpData(
displacements=disps[:n], forces=forces[:n], supercell_energies=energies[:n]
)
test_data = PypolymlpData(
displacements=disps[n:], forces=forces[n:], supercell_energies=energies[n:]
)
self._mlp = develop_polymlp(
self._mlp = develop_mlp_by_pypolymlp(
self._mlp_dataset,
self._supercell,
train_data,
test_data,
params=_params,
verbose=self._log_level - 1 > 0,
params=params,
test_size=test_size,
log_level=self._log_level,
)

def load_mlp(self, filename: str = "pypolymlp.mlp"):
def load_mlp(self, filename: str = "phono3py.pmlp"):
"""Load machine learning potential of pypolymlp."""
self._mlp = load_polymlp(filename=filename)

Expand Down
53 changes: 22 additions & 31 deletions phono3py/cui/create_force_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,28 @@ def create_phono3py_force_constants(
if settings.read_fc3:
_read_phono3py_fc3(phono3py, symmetrize_fc3r, input_filename, log_level)
else: # fc3 from FORCES_FC3 or ph3py_yaml
_read_dataset_fc3(
dataset = _read_dataset_fc3(
phono3py,
ph3py_yaml,
phono3py_yaml_filename,
settings.cutoff_pair_distance,
calculator,
settings.use_pypolymlp,
settings.mlp_params,
settings.displacement_distance,
settings.random_displacements,
settings.random_seed,
log_level,
)

if settings.use_pypolymlp:
phono3py.mlp_dataset = dataset
run_pypolymlp_to_compute_forces(
phono3py,
settings.mlp_params,
displacement_distance=settings.displacement_distance,
number_of_snapshots=settings.random_displacements,
random_seed=settings.random_seed,
log_level=log_level,
)
else:
phono3py.dataset = dataset

phono3py.produce_fc3(
symmetrize_fc3r=symmetrize_fc3r,
is_compact_fc=settings.is_compact_fc,
Expand Down Expand Up @@ -214,7 +223,7 @@ def parse_forces(
fc_type: Literal["fc3", "phonon_fc2"] = "fc3",
calculator: Optional[str] = None,
log_level=0,
):
) -> dict:
"""Read displacements and forces.
Physical units of displacements and forces are converted following the
Expand Down Expand Up @@ -459,13 +468,8 @@ def _read_dataset_fc3(
phono3py_yaml_filename: Optional[str],
cutoff_pair_distance: Optional[float],
calculator: Optional[str],
use_pypolymlp: bool,
mlp_params: Union[str, dict, PypolymlpParams],
displacement_distance: Optional[float],
number_of_snapshots: Optional[int],
random_seed: Optional[int],
log_level: int,
):
) -> dict:
"""Read or calculate fc3.
Note
Expand Down Expand Up @@ -501,19 +505,7 @@ def _read_dataset_fc3(
# from _get_type2_dataset
file_exists(e.filename, log_level=log_level)

if use_pypolymlp:
if forces_in_dataset(dataset):
phono3py.mlp_dataset = dataset
run_pypolymlp_to_compute_forces(
phono3py,
mlp_params,
displacement_distance=displacement_distance,
number_of_snapshots=number_of_snapshots,
random_seed=random_seed,
log_level=log_level,
)
else:
phono3py.dataset = dataset
return dataset


def run_pypolymlp_to_compute_forces(
Expand All @@ -522,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."""
Expand All @@ -536,13 +528,14 @@ def run_pypolymlp_to_compute_forces(
for k, v in asdict(parse_mlp_params(mlp_params)).items():
if v is not None:
print(f" {k}: {v}")
if log_level > 1:
print("")

if forces_in_dataset(ph3py.mlp_dataset):
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:
Expand Down Expand Up @@ -613,8 +606,6 @@ def run_pypolymlp_to_compute_phonon_forces(
for k, v in asdict(parse_mlp_params(mlp_params)).items():
if v is not None:
print(f" {k}: {v}")
if log_level > 1:
print("")
if log_level:
print("Developing MLPs by pypolymlp...", flush=True)

Expand Down
15 changes: 10 additions & 5 deletions phono3py/cui/phono3py_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,23 @@ def finalize_phono3py(
else:
yaml_filename = filename

_physical_units = get_default_physical_units(phono3py.calculator)
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)

write_force_sets = phono3py.mlp is not None
_write_displacements = write_displacements or phono3py.mlp is not None
_physical_units = get_default_physical_units(phono3py.calculator)

ph3py_yaml = Phono3pyYaml(
configuration=confs_dict,
calculator=phono3py.calculator,
physical_units=_physical_units,
settings={
"force_sets": write_force_sets,
"displacements": _write_displacements,
"force_sets": False,
"displacements": write_displacements,
},
)
ph3py_yaml.set_phonon_info(phono3py)
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.4.0"
__version__ = "3.5.0"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies = [
"matplotlib>=2.2.2",
"h5py>=3.0",
"spglib>=2.3",
"phonopy>=2.27,<2.28",
"phonopy>=2.28,<2.29",
]
license = { file = "LICENSE" }

Expand Down
7 changes: 0 additions & 7 deletions setup-legacy.cfg

This file was deleted.

Loading

0 comments on commit 4616b78

Please sign in to comment.