diff --git a/.github/workflows/phono3py-pytest-conda-numpy2.yml b/.github/workflows/phono3py-pytest-conda-numpy2.yml deleted file mode 100644 index c2e05745..00000000 --- a/.github/workflows/phono3py-pytest-conda-numpy2.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Pytest with openblas and numpy 2.0 - -on: - pull_request: - branches: [ develop ] - -jobs: - build-linux: - runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} - strategy: - matrix: - python-version: ["3.12"] - - steps: - - uses: actions/checkout@v4 - # Use conda-incubator/setup-miniconda for precise control of conda infrastructure - - uses: conda-incubator/setup-miniconda@v3 - with: - miniforge-version: latest - - name: Install dependent packages - run: | - conda activate test - conda install --yes python=${{ matrix.python-version }} - conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py "numpy=2" scipy pytest cmake c-compiler cxx-compiler pypolymlp - - name: Install spglib develop branch - run: | - conda activate test - git clone --depth 1 https://github.com/spglib/spglib.git - cd spglib - pip install -e . -vvv - cd .. - - name: Install symfc develop branch - run: | - conda activate test - 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 https://github.com/phonopy/phonopy.git - cd phonopy - pip install -e . -vvv - cd .. - - name: Install phono3py - run: | - conda activate test - pip install -e . -vvv - - name: Run pytest - run: | - conda activate test - pytest -v test diff --git a/.github/workflows/phono3py-pytest-conda.yml b/.github/workflows/phono3py-pytest-conda.yml index 66bb1385..99b0a596 100644 --- a/.github/workflows/phono3py-pytest-conda.yml +++ b/.github/workflows/phono3py-pytest-conda.yml @@ -12,7 +12,7 @@ jobs: shell: bash -l {0} strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/publish-gh-pages.yml b/.github/workflows/publish-gh-pages.yml index 4e397cb2..15b4e26e 100644 --- a/.github/workflows/publish-gh-pages.yml +++ b/.github/workflows/publish-gh-pages.yml @@ -12,7 +12,7 @@ jobs: shell: bash -l {0} strategy: matrix: - python-version: ["3.11"] + python-version: ["3.12"] steps: - uses: actions/checkout@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6d3c4221..39c7ee27 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: exclude: ^example/AlN-LDA/ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.0 + rev: v0.7.3 hooks: - id: ruff args: [ "--fix", "--show-fixes" ] diff --git a/doc/changelog.md b/doc/changelog.md index 4faa2c1f..fea78c71 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,10 @@ # Change Log +## Nov-13-2024: Version 3.7.0 + +- Update to follow the change of phonopy's internal functions + ## Nov-3-2024: Version 3.6.0 - Maintenance release. diff --git a/doc/command-options.md b/doc/command-options.md index 33565035..748a074b 100644 --- a/doc/command-options.md +++ b/doc/command-options.md @@ -58,7 +58,7 @@ When using `phono3py-load` (see also {ref}`phono3py_load_command`) This specifies input unit cell filename. ```bash -% phono3py -c POSCAR-unitcell ... (options) +% phono3py -c POSCAR-unitcell [OPTIONS] ``` ## Calculator interface @@ -193,7 +193,7 @@ created from `FORCES_FC2` and `phono3py_disp.yaml` instead of `FORCES_FC3` and `phono3py_disp.yaml`. ```bash -% phono3py --cfs --dim-fc2="x x x" +% phono3py --cfs --dim-fc2 4 4 4 ``` (sp_option)= @@ -283,7 +283,7 @@ order force constants with larger supercell size. The filename is the same as that created in the usual phono3py run without `--dim-fc2` option. ```bash -% phono3py --dim="2 2 2" --dim_fc2="4 4 4" -c POSCAR-unitcell ... (many options) +% phono3py --dim 2 2 2 --dim_fc2 4 4 4 -c POSCAR-unitcell [OPTIONS] ``` (pa_option)= diff --git a/doc/conf.py b/doc/conf.py index 2f64b5f2..e42ff2fa 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -58,9 +58,9 @@ # built documents. # # The short X.Y version. -version = "3.6" +version = "3.7" # The full version, including alpha/beta/rc tags. -release = "3.6.0" +release = "3.7.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/doc/cutoff-pair.md b/doc/cutoff-pair.md index 88ab4299..0f193f33 100644 --- a/doc/cutoff-pair.md +++ b/doc/cutoff-pair.md @@ -2,9 +2,9 @@ # Force constants calculation with cutoff pair-distance ```{note} -Since usage of this calculation is complicated. It is recommended to try -{ref}`random-displacements` with `--fc-calc-opt "cutoff = VAL"` before trying -this option. +To reduce the computational demands of force constants or lattice thermal +conductivity calculations, it is recommended to try {ref}`pypolymlp-interface` +instead of using the `--cutoff-pair` option. ``` Here the detail of the command option {ref}`--cutoff-pair ` diff --git a/doc/pypolymlp.md b/doc/pypolymlp.md index eb2e2fd3..50e73093 100644 --- a/doc/pypolymlp.md +++ b/doc/pypolymlp.md @@ -48,10 +48,6 @@ in the distribution from GitHub or PyPI. conda-forge (recommended). Otherwise, pypolymlp can be installed from source-code. -- [symfc](https://github.com/symfc/symfc) - - Installed via pip, conda-forge, or source code. - ## How to calculate ### Workflow @@ -357,14 +353,6 @@ an additional 200 supercells. In total, 400 supercells are created. The forces for these supercells are then evaluated. Finally, the force constants are calculated using symfc. -## Convergence with respect to dataset size - -In general, increasing the amount of data improves the accuracy of representing -force constants. Therefore, it is recommended to check the convergence of the -target property with respect to the number of supercells in the training -dataset. Lattice thermal conductivity may be a convenient property to monitor -when assessing convergence. - ## Parameters for developing MLPs A few parameters can be specified using the `--mlp-params` option for the @@ -401,3 +389,30 @@ For parameter adjustments, it is recommended to consult the This method provides a straightforward dataset split: the first `ntrain` supercells from the list are used for training, while the last `ntest` supercells are reserved for testing. + +## Convergence with respect to dataset size + +In general, increasing the amount of data improves the accuracy of representing +force constants. Therefore, it is recommended to check the convergence of the +target property with respect to the number of supercells in the training +dataset. Lattice thermal conductivity may be a convenient property to monitor +when assessing convergence. + +For example, by preparing an initial set with 100 supercell data, calculations +can then be performed by varying the size of the training dataset while keeping +the test dataset unchanged as follows: + +```bash +% phono3py-load --pypolymlp --mlp-params="ntrain=20, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-20 +% phono3py-load --pypolymlp --mlp-params="ntrain=40, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-40 +% phono3py-load --pypolymlp --mlp-params="ntrain=60, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-60 +% phono3py-load --pypolymlp --mlp-params="ntrain=80, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-80 +``` + +The computed lattice thermal conductivities (LTCs) are plotted against the size +of the training dataset to observe LTC convergence. If the LTC has not +converged, an additional set of supercell data (e.g., forces and energies in +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. diff --git a/doc/random-displacements.md b/doc/random-displacements.md index 865d4c20..17217d88 100644 --- a/doc/random-displacements.md +++ b/doc/random-displacements.md @@ -1,5 +1,5 @@ (random-displacements)= -# Force constants calculation with randan displacements of atoms +# Force constants calculation with random displacements of atoms Random displacements and corresponding forces in supercells can be employed as a displacement-force dataset for computing force constants. This requires an diff --git a/phono3py/api_phono3py.py b/phono3py/api_phono3py.py index c1d8da07..c8cf0600 100644 --- a/phono3py/api_phono3py.py +++ b/phono3py/api_phono3py.py @@ -47,7 +47,6 @@ get_random_displacements_dataset, ) from phonopy.harmonic.dynamical_matrix import DynamicalMatrix -from phonopy.harmonic.force_constants import get_fc2 as get_phonopy_fc2 from phonopy.harmonic.force_constants import ( set_permutation_symmetry, set_translational_invariance, @@ -74,7 +73,6 @@ guess_primitive_matrix, shape_supercell_matrix, ) -from phonopy.structure.dataset import get_displacements_and_forces from phonopy.structure.symmetry import Symmetry from phonopy.units import VaspToTHz @@ -1540,30 +1538,19 @@ def produce_fc2( else: p2s_map = None - if fc_calculator is not None: - disps, forces = get_displacements_and_forces(disp_dataset) - self._fc2 = get_fc2( - self._phonon_supercell, - self._phonon_primitive, - disps, - forces, - fc_calculator=fc_calculator, - fc_calculator_options=fc_calculator_options, - atom_list=p2s_map, - symmetry=self._phonon_supercell_symmetry, - symprec=self._symprec, - log_level=self._log_level, - ) - else: - if "displacements" in disp_dataset: - msg = "fc_calculator to solve fc2 has to be set." - raise RuntimeError(msg) - self._fc2 = get_phonopy_fc2( - self._phonon_supercell, - self._phonon_supercell_symmetry, - disp_dataset, - atom_list=p2s_map, - ) + self._fc2 = get_fc2( + self._phonon_supercell, + self._phonon_primitive, + disp_dataset, + fc_calculator=fc_calculator, + fc_calculator_options=fc_calculator_options, + atom_list=p2s_map, + symmetry=self._phonon_supercell_symmetry, + symprec=self._symprec, + log_level=self._log_level, + ) + + if fc_calculator is None or fc_calculator == "traditional": if symmetrize_fc2: if is_compact_fc: symmetrize_compact_force_constants( diff --git a/phono3py/version.py b/phono3py/version.py index ea0e6101..6dc2d7e2 100644 --- a/phono3py/version.py +++ b/phono3py/version.py @@ -34,4 +34,4 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -__version__ = "3.6.0" +__version__ = "3.7.0" diff --git a/pyproject.toml b/pyproject.toml index 787f70be..094ad8eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ dynamic = ["version"] readme = { file = "README.md", content-type = "text/markdown" } description = "This is the phono3py module." authors = [{ name = "Atsushi Togo", email = "atztogo@gmail.com" }] -requires-python = ">=3.8" +requires-python = ">=3.9" dependencies = [ "numpy>=1.17.0", "scipy", @@ -16,7 +16,7 @@ dependencies = [ "matplotlib>=2.2.2", "h5py>=3.0", "spglib>=2.3", - "phonopy>=2.29,<2.30", + "phonopy>=2.30,<2.31", ] license = { file = "LICENSE" } diff --git a/test/other/test_isotope.py b/test/other/test_isotope.py index 3e168326..7a02a883 100644 --- a/test/other/test_isotope.py +++ b/test/other/test_isotope.py @@ -114,7 +114,7 @@ def test_Phono3pyIsotope_grg(si_pbesol_grg, lang): iso.grid.grid_matrix, [[-15, 15, 15], [15, -15, 15], [15, 15, -15]] ) iso.run([23, 103], lang=lang) - np.testing.assert_allclose(si_pbesol_grg_iso, iso.gamma[0], atol=2e-3) + np.testing.assert_allclose(si_pbesol_grg_iso, iso.gamma[0], atol=3e-3) @pytest.mark.parametrize("lang", ["C", "Py"]) diff --git a/test/sscha/test_sscha.py b/test/sscha/test_sscha.py index a1d80eaf..ef23f661 100644 --- a/test/sscha/test_sscha.py +++ b/test/sscha/test_sscha.py @@ -57,15 +57,17 @@ def get_supercell_phonon(ph3): return SupercellPhonon(supercell, fc2, frequency_factor_to_THz=factor) -def mass_sand(matrix, mass): +def mass_sand(matrix: np.ndarray, mass: np.ndarray) -> np.ndarray: """Calculate mass sandwich.""" return ((matrix * mass).T * mass).T -def mass_inv(matrix, mass): +def mass_inv(matrix: np.ndarray, mass: np.ndarray, tol: float = 1e-5) -> np.ndarray: """Calculate inverse mass sandwich.""" bare = mass_sand(matrix, mass) - inv_bare = np.linalg.pinv(bare) + eigvals, eigvecs = np.linalg.eigh(bare) + inv_eigvals = [1 / x if x > tol else 0 for x in eigvals] + inv_bare = (eigvecs * inv_eigvals) @ eigvecs.T return mass_sand(inv_bare, mass)