From fe72cf9120831b9117142bfe829e8b172a20a7fd Mon Sep 17 00:00:00 2001 From: Sean Kavanagh Date: Thu, 23 May 2024 12:36:12 +0100 Subject: [PATCH 1/3] Remove `spglib` version limit, and add warning catches for versions --- .github/workflows/pip_install_test.yml | 1 + .github/workflows/test.yml | 1 + README.md | 6 +++++ docs/Installation.rst | 13 +++++++++++ docs/Troubleshooting.rst | 20 +++++----------- doped/utils/symmetry.py | 32 ++++++++++++++++++++++++++ pyproject.toml | 7 ++++-- 7 files changed, 64 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pip_install_test.yml b/.github/workflows/pip_install_test.yml index 889f8cf0..e9c8b369 100644 --- a/.github/workflows/pip_install_test.yml +++ b/.github/workflows/pip_install_test.yml @@ -40,6 +40,7 @@ jobs: sleep 360 # wait 10 minutes for PyPI to update with the new release python -m pip install --upgrade pip pip install doped[tests] # install only from PyPI + conda install -c conda-forge spglib - name: Test run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48b7b3d1..03cc19a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,6 +34,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -e .[tests] + conda install -c conda-forge spglib - name: Test run: | diff --git a/README.md b/README.md index 906b0156..b7d86873 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,14 @@ displacements from DFT supercell calculations. See the [JOSS paper](https://doi. ## Installation ```bash pip install doped # install doped and dependencies +conda install -c conda-forge spglib # bundle C libraries with spglib ``` +Note that either `conda install -c conda-forge spglib` or +`pip install git+https://github.com/spglib/spglib --config-settings=cmake.define.SPGLIB_SHARED_LIBS=OFF` +should be used after `pip install doped`, which ensures that the correct C libraries are bundled with +`spglib`, to prevent unnecessary warnings. + Alternatively if desired, `doped` can also be installed from `conda` with: ```bash diff --git a/docs/Installation.rst b/docs/Installation.rst index 00911c61..3f273395 100644 --- a/docs/Installation.rst +++ b/docs/Installation.rst @@ -6,6 +6,19 @@ Installation .. code-block:: bash pip install doped # install doped and dependencies + conda install -c conda-forge spglib # bundle C libraries with spglib + +Note that either ``conda install -c conda-forge spglib`` or +``pip install git+https://github.com/spglib/spglib --config-settings=cmake.define.SPGLIB_SHARED_LIBS=OFF`` +should be used after ``pip install doped``, which ensures that the correct C libraries are bundled with +``spglib``, to prevent unnecessary warnings. You can check that the correct C libraries have been bundled +by running the following in Python, and confirming that the same version numbers are printed: + +.. code-block:: python + + import spglib + print(spglib.__version__) + print(spglib.spg_get_version_full()) Alternatively if desired, ``doped`` can also be installed from ``conda`` with: diff --git a/docs/Troubleshooting.rst b/docs/Troubleshooting.rst index 8dc7e712..5af2ab75 100644 --- a/docs/Troubleshooting.rst +++ b/docs/Troubleshooting.rst @@ -65,7 +65,7 @@ that it is rebuilt with the new ``numpy`` C API: ``spglib`` Errors/Warnings -------------------------- -A previous known issue with ``spglib`` is that it could give an error or warnings similar to: +A known issue with ``spglib`` is that it can give unnecessary errors or warnings similar to: .. code:: python @@ -76,20 +76,12 @@ A previous known issue with ``spglib`` is that it could give an error or warning spglib: get_bravais_exact_positions_and_lattice failed spglib: ref_get_exact_structure_and_symmetry failed. -This can be fixed by reinstalling ``spglib`` with ``conda install -c conda-forge spglib==2.0.2``. -Sometimes installation with ``conda`` rather than ``pip`` is required, as ``conda`` will bundle the C -and Fortran libraries, while using version ``2.0.2`` for now avoids some unnecessary warnings (see this -`Issue `_ on the ``spglib`` GitHub for details). +This can be fixed by reinstalling ``spglib`` with ``conda install -c conda-forge spglib`` or +``pip install git+https://github.com/spglib/spglib --config-settings=cmake.define.SPGLIB_SHARED_LIBS=OFF`` +as detailed in the `Installation `__ instructions. +This ensures the correct C libraries are bundled with ``spglib``. -.. If this still does not remove these warnings, then setting the environment variable: ``SPGLIB_WARNING=OFF`` -and re-installing ``spglib`` with: - -.. .. code:: bash - -.. pip uninstall spglib - pip install git+https://github.com/spglib/spglib --config-settings=cmake.define.SPGLIB_SHARED_LIBS=OFF - -.. should fix it. – STILL DOESN'T FULLY FIX IT YET (see doped_spglib_warnings.ipynb) +.. see doped_spglib_warnings.ipynb ``ShakeNBreak`` ------------------- diff --git a/doped/utils/symmetry.py b/doped/utils/symmetry.py index 9d6bf921..d80b2233 100644 --- a/doped/utils/symmetry.py +++ b/doped/utils/symmetry.py @@ -27,6 +27,38 @@ ) +def _set_spglib_warnings_env_var(): + """ + Set the SPGLIB environment variable to suppress spglib warnings. + """ + os.environ["SPGLIB_WARNING"] = "OFF" + + +def _check_spglib_version(): + """ + Check the versions of spglib and its C libraries, and raise a warning if + the correct installation instructions have not been followed. + """ + import spglib + + python_version = spglib.__version__ + c_version = spglib.spg_get_version_full() + + if python_version != c_version: + warnings.warn( + f"Your spglib Python version (spglib.__version__ = {python_version}) does not match its C " + f"library version (spglib.spg_get_version_full() = {c_version}). This can lead to unnecessary " + f"spglib warning messages, but can be avoided by installing spglib with `conda install -c " + f"conda-forge spglib` or `pip install git+https://github.com/spglib/spglib " + f"--config-settings=cmake.define.SPGLIB_SHARED_LIBS=OFF` as detailed in the doped " + f"installation instructions: https://doped.readthedocs.io/en/latest/Installation.html" + ) + + +_check_spglib_version() +_set_spglib_warnings_env_var() + + def _round_floats(obj, places=5): """ Recursively round floats in a dictionary to ``places`` decimal places. diff --git a/pyproject.toml b/pyproject.toml index 11cb213d..f8e9b0fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,8 +22,11 @@ dependencies = [ "matplotlib>=3.5.2", "numpy>=1.21.0", "pymatgen>=2023.11.12", # limiting factor: POTCAR_STATS_PATH available from pymatgen.io.vasp.inputs - "spglib<=2.0.2", # dependent of pymatgen, but explicitly set to <=2.0.2 here to avoid unnecessary warnings - # see https://github.com/spglib/spglib/issues/338; remove this limit when issue resolved + "spglib>=2.4.0", # previously explicitly set to <=2.0.2 to avoid unnecessary warnings + # (https://github.com/spglib/spglib/issues/338) but causing dependency issues + # (https://github.com/SMTG-Bham/doped/issues/73), being worked on in + # https://github.com/spglib/spglib/issues/462 -- update Troubleshooting.rst and spglib warning in + # doped.utils.symmetry when finally resolved "pymatgen-analysis-defects>=2023.8.22", "shakenbreak>=3.3.1", "pandas", From 932d8c81e9c02daf80204b9a152d672c3671f65f Mon Sep 17 00:00:00 2001 From: Sean Kavanagh Date: Thu, 23 May 2024 16:50:48 +0100 Subject: [PATCH 2/3] Use `pip` rather than `conda` for `macos` GH Actions --- .github/workflows/pip_install_test.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pip_install_test.yml b/.github/workflows/pip_install_test.yml index e9c8b369..afdab899 100644 --- a/.github/workflows/pip_install_test.yml +++ b/.github/workflows/pip_install_test.yml @@ -40,7 +40,7 @@ jobs: sleep 360 # wait 10 minutes for PyPI to update with the new release python -m pip install --upgrade pip pip install doped[tests] # install only from PyPI - conda install -c conda-forge spglib + pip install git+https://github.com/spglib/spglib --config-settings=cmake.define.SPGLIB_SHARED_LIBS=OFF # avoid spglib warnings - name: Test run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03cc19a0..1389bbc8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -e .[tests] - conda install -c conda-forge spglib + pip install git+https://github.com/spglib/spglib --config-settings=cmake.define.SPGLIB_SHARED_LIBS=OFF # avoid spglib warnings - name: Test run: | From 2b90ba3935530eab0d09f639332e8403d65e3717 Mon Sep 17 00:00:00 2001 From: Sean Kavanagh Date: Thu, 23 May 2024 16:54:49 +0100 Subject: [PATCH 3/3] Bump version number and changelog for release --- CHANGELOG.rst | 4 ++++ docs/conf.py | 2 +- pyproject.toml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 05bd2da2..25547693 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ Change Log ========== +v.2.4.3 +---------- +- Remove ``spglib<=2.0.2`` dependency (set to avoid unnecessary warnings), and update installation instructions accordingly. + v.2.4.2 ---------- - Allow cases where the calculated host material is unstable wrt competing phases (above the hull), by downshifting to the hull and warning the user about this. diff --git a/docs/conf.py b/docs/conf.py index 6fcd640a..816c26e9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ author = 'Seán R. Kavanagh' # The full version, including alpha/beta/rc tags -release = '2.4.2' +release = '2.4.3' # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index f8e9b0fe..82ba059e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "doped" -version = "2.4.2" +version = "2.4.3" description = "Python package to setup, process and analyse solid-state defect calculations with VASP" authors = [{name = "Seán Kavanagh", email = "skavanagh@seas.harvard.edu"}] readme = "README.md"