Skip to content

Commit

Permalink
Sunset module pymatgen/util/serialization.py (#2736)
Browse files Browse the repository at this point in the history
* remove all calls to pmg_serialize()

* rm pymatgen/util/serialization.py

* replace pymatgen.util.serialization.{pmg_pickle_dump, pmg_pickle_load} with regular pickle.dump/load

* remove serialization module from docs_rst

* typos

* format issue + PR templates
  • Loading branch information
janosh committed Nov 16, 2022
1 parent f039377 commit dcf9e83
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 174 deletions.
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -8,6 +8,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,8 +25,8 @@ If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**

- OS: [e.g. Mac,Windows,Linux]
- Version [e.g. 2019.9.16]
- OS: (e.g. Mac, Windows, Linux)
- Version (e.g. 2022.11.17)

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Expand Up @@ -4,7 +4,7 @@ about: Suggest an idea for this project
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
A clear and concise description of what the problem is. Ex. I'm always frustrated when (...)

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
Expand Down
23 changes: 13 additions & 10 deletions .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -7,25 +7,28 @@ Include a summary of major changes in bullet points:
- Fix 1
- Fix 2

## TODO (if any)
## Todo (if any)

If this is a work-in-progress, write something about what else needs
to be done
If this is a work-in-progress, write something about what else needs to be done

- Feature 1 supports A, but not B.

## Checklist

Work-in-progress pull requests are encouraged, but please put [WIP]
in the pull request title.
Work-in-progress pull requests are encouraged, but please put \[WIP\] in the pull request title.

Before a pull request can be merged, the following items must be checked:

- [ ] Doc strings have been added in the [Google docstring format](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
Run [pydocstyle](http://www.pydocstyle.org/en/2.1.1/index.html) on your code.
- [ ] Type annotations are **highly*- encouraged. Run [`mypy`](https://github.com/python/mypy) `path/to/file.py` to type check your code.
- [ ] Doc strings have been added in the [Google docstring format](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). Run [pydocstyle](http://www.pydocstyle.org/en/2.1.1/index.html) on your code.
- [ ] Type annotations are *highly* encouraged. Run [`mypy path/to/file.py`](https://github.com/python/mypy) to type check your code.
- [ ] Tests have been added for any new functionality or bug fixes.
- [ ] All linting and tests pass.

Note that the CI system will run all the above checks. But it will be much more efficient if you already fix most
errors prior to submitting the PR. We highly recommended installing `pre-commit` hooks. Simply `pip install -U pre-commit && pre-commit install` in the repo's root directory. Afterwards linters will run before every commit and abort if any issues pop up.
Note that the CI system will run all the above checks. But it will be much more efficient if you already fix most errors prior to submitting the PR. We highly recommended installing `pre-commit` hooks. Simply Run

```sh
pip install -U pre-commit
pre-commit install
```

in the repo's root directory. Afterwards linters will run before every commit and abort if any issues pop up.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
@@ -1,6 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "weekly"
interval: weekly
1 change: 0 additions & 1 deletion docs_rst/pymatgen.util.rst
Expand Up @@ -23,7 +23,6 @@ Submodules
pymatgen.util.num
pymatgen.util.plotting
pymatgen.util.provenance
pymatgen.util.serialization
pymatgen.util.string
pymatgen.util.testing
pymatgen.util.typing
Expand Down
7 changes: 0 additions & 7 deletions docs_rst/pymatgen.util.serialization.rst

This file was deleted.

17 changes: 10 additions & 7 deletions pymatgen/io/abinit/abiobjects.py
Expand Up @@ -18,7 +18,6 @@
from monty.json import MontyDecoder, MontyEncoder, MSONable

from pymatgen.core import ArrayWithUnit, Lattice, Species, Structure, units
from pymatgen.util.serialization import pmg_serialize


def lattice_from_abivars(cls=None, *args, **kwargs):
Expand Down Expand Up @@ -388,10 +387,11 @@ def to_abivars(self):
"nspden": self.nspden,
}

@pmg_serialize
def as_dict(self):
"""Convert object to dict."""
return {k: getattr(self, k) for k in self._fields}
out = {k: getattr(self, k) for k in self._fields}
out.update({"@module": type(self).__module__, "@class": type(self).__name__})
return out

@classmethod
def from_dict(cls, d):
Expand Down Expand Up @@ -499,10 +499,14 @@ def to_abivars(self):
return {"occopt": 1, "tsmear": 0.0}
return {"occopt": self.occopt, "tsmear": self.tsmear}

@pmg_serialize
def as_dict(self):
"""json friendly dict representation of Smearing"""
return {"occopt": self.occopt, "tsmear": self.tsmear}
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
"occopt": self.occopt,
"tsmear": self.tsmear,
}

@staticmethod
def from_dict(d):
Expand Down Expand Up @@ -539,10 +543,9 @@ def to_abivars(self):
"""Dictionary with Abinit input variables."""
return self.copy()

@pmg_serialize
def as_dict(self):
"""Convert object to dict."""
return self.copy()
return {"@module": type(self).__module__, "@class": type(self).__name__, **self.copy()}

@classmethod
def from_dict(cls, d):
Expand Down
16 changes: 8 additions & 8 deletions pymatgen/io/abinit/inputs.py
Expand Up @@ -22,7 +22,6 @@
from pymatgen.io.abinit import abiobjects as aobj
from pymatgen.io.abinit.pseudos import Pseudo, PseudoTable
from pymatgen.io.abinit.variable import InputVariable
from pymatgen.util.serialization import pmg_serialize

logger = logging.getLogger(__file__)

Expand Down Expand Up @@ -769,7 +768,6 @@ def __init__(
if comment is not None:
self.set_comment(comment)

@pmg_serialize
def as_dict(self):
"""
JSON interface used in pymatgen for easier serialization.
Expand All @@ -781,12 +779,14 @@ def as_dict(self):
value = value.tolist()
abi_args.append((key, value))

return dict(
structure=self.structure.as_dict(),
pseudos=[p.as_dict() for p in self.pseudos],
comment=self.comment,
abi_args=abi_args,
)
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
"structure": self.structure.as_dict(),
"pseudos": [p.as_dict() for p in self.pseudos],
"comment": self.comment,
"abi_args": abi_args,
}

@property
def vars(self):
Expand Down
34 changes: 19 additions & 15 deletions pymatgen/io/abinit/pseudos.py
Expand Up @@ -26,7 +26,6 @@
from pymatgen.core.periodic_table import Element
from pymatgen.core.xcfunc import XcFunc
from pymatgen.util.plotting import add_fig_kwargs, get_ax_fig_plt
from pymatgen.util.serialization import pmg_serialize

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -250,21 +249,22 @@ def supports_soc(self):
Base classes should provide a concrete implementation that computes this value.
"""

@pmg_serialize
def as_dict(self, **kwargs):
"""Return dictionary for MSONable protocol."""
# pylint: disable=E1101
return dict(
basename=self.basename,
type=self.type,
symbol=self.symbol,
Z=self.Z,
Z_val=self.Z_val,
l_max=self.l_max,
md5=self.md5,
filepath=self.filepath,
# xc=self.xc.as_dict(),
)
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
"basename": self.basename,
"type": self.type,
"symbol": self.symbol,
"Z": self.Z,
"Z_val": self.Z_val,
"l_max": self.l_max,
"md5": self.md5,
"filepath": self.filepath,
# "xc": self.xc.as_dict(),
}

@classmethod
def from_dict(cls, d):
Expand Down Expand Up @@ -596,10 +596,14 @@ def __str__(self):
return f"ecut: {self.ecut}, pawecutdg: {self.pawecutdg}"
return f"ecut: {self.ecut}"

@pmg_serialize
def as_dict(self):
"""Return dictionary for MSONable protocol."""
return dict(ecut=self.ecut, pawecutdg=self.pawecutdg)
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
"ecut": self.ecut,
"pawecutdg": self.pawecutdg,
}

@classmethod
def from_dict(cls, d):
Expand Down
5 changes: 2 additions & 3 deletions pymatgen/util/convergence.py
Expand Up @@ -11,10 +11,10 @@
calculates which function fits best
for tol < 0
returns the x value for which y is converged within tol of the assymtotic value
returns the x value for which y is converged within tol of the asymptotic value
for tol > 0
returns the x_value for which dy(x)/dx < tol for all x >= x_value, conv is true is such a x_value exists
for the best fit a gnuplot line is printed plotting the data, the function and the assymthotic value
for the best fit a gnuplot line is printed plotting the data, the function and the asymptotic value
"""

import random
Expand All @@ -23,7 +23,6 @@
import numpy as np

__author__ = "Michiel van Setten"
__copyright__ = " "
__version__ = "0.9"
__maintainer__ = "Michiel van Setten"
__email__ = "mjvansetten@gmail.com"
Expand Down
113 changes: 0 additions & 113 deletions pymatgen/util/serialization.py

This file was deleted.

0 comments on commit dcf9e83

Please sign in to comment.