Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Upgrade to pydantic V2. #82

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.1.0](https://github.com/CederGroupHub/WFacer/tree/0.0.1) (2023-09-22)
- Upgraded to pymatgen==2023.09.10, and remove python==3.8 support.
- Implemented support to generic structural calculation makers.
- Upgraded to pymatgen==2023.09.10, and remove python==3.8 support.

Check warning on line 8 in CHANGES.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CHANGES.md#L8

[list-item-indent] Incorrect list-item indent: add 2 spaces
- Implemented support to generic structural calculation makers.

Check warning on line 9 in CHANGES.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CHANGES.md#L9

[list-item-indent] Incorrect list-item indent: add 2 spaces
- Upgraded to Pydantic 2.

Check warning on line 10 in CHANGES.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CHANGES.md#L10

[list-item-indent] Incorrect list-item indent: add 2 spaces

## [v0.0.0](https://github.com/CederGroupHub/WFacer/tree/0.0.0) (2023-09-20)
Initial relatively *stable* version of the code.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
from jobflow import SETTINGS
from monty.json import jsanitize
from monty.serialization import loadfn
from pydantic import parse_file_as, parse_obj_as
from pydantic import parse_obj_as

from WFacer.jobs import fit_calculations, parse_calculations, update_document
from WFacer.schema import CeOutputsDocument


# Execute this once all queue tasks has been completed and no job is lost.
def __main__():
document = parse_file_as(CeOutputsDocument, "document.json")
with open("documents.json") as fin:
json_str = fin.read()
document = CeOutputsDocument.model_validate_json(json_str)

iter_id = document.last_iter_id + 1
project_name = document.project_name
Expand Down
5 changes: 3 additions & 2 deletions docs/src/example_scripts/semi_automation_BCC_AlLi/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
from fireworks import LaunchPad
from jobflow.managers.fireworks import flow_to_workflow
from monty.serialization import dumpfn
from pydantic import parse_file_as

from WFacer.jobs import enumerate_structures, get_structure_calculation_flows
from WFacer.schema import CeOutputsDocument


def __main__():
document = parse_file_as(CeOutputsDocument, "document.json")
with open("documents.json") as fin:
json_str = fin.read()
document = CeOutputsDocument.model_validate_json(json_str)

iter_id = document.last_iter_id + 1
max_iter = document.ce_options["max_iter"]
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ dependencies = [
"sparse-lm>=0.4.0",
"sympy>=1.11.1",
"jobflow>=0.1.9",
"atomate2>=0.0.11",
"emmet-core>=0.51.1",
"atomate2>=0.0.12",
"emmet-core>=0.71.1",
"scikit-learn>=1.2.0",
"scikit-optimize>=0.9.0",
"scipy>=1.10.0, <=1.11.3",
"pydantic>=1.10.2,<2.0",
"pydantic>=2.0",
"polytope>=0.2.3",
"cvxpy>=1.2.1",
"cvxopt"
Expand Down
1 change: 1 addition & 0 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
gurobipy==10.0.3
pyscipopt==4.3.0
fireworks==2.0.3
ase==3.22.1
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
pyyaml==6.0.1
joblib==1.3.2
monty==2023.9.25
monty==2023.11.3
numpy==1.26.2
pymatgen==2023.10.4
pymatgen==2023.11.12
smol==0.5.3
sparse-lm==0.5.1
sympy==1.12
jobflow==0.1.13
atomate2==0.0.11
scikit-learn==1.3.1
emmet-core==0.68.0
jobflow==0.1.14
atomate2==0.0.12
scikit-learn==1.3.2
emmet-core==0.72.21
scikit-optimize==0.9.0
scipy==1.11.3
pydantic==1.10.12
pydantic==2.5.0
polytope==0.2.4
cvxpy==1.3.2
cvxpy==1.4.1
cvxopt==1.3.2
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from atomate2.forcefields.schemas import ForceFieldTaskDocument
from emmet.core.tasks import TaskDoc # emmet-core >= 0.60.0.
from monty.serialization import loadfn
from pydantic import parse_file_as
from smol.cofe import ClusterExpansion
from smol.moca import Ensemble

Expand Down Expand Up @@ -183,9 +182,10 @@ def single_wrangler_sin(single_ensemble_sin):

@pytest.fixture(scope="package", params=["zns_taskdoc.json", "zns_ff_taskdoc.json"])
def single_taskdoc(request):
with open(os.path.join(DATA_DIR, request.param)) as fin:
json_str = fin.read()
# In pydantic V2, we must change to using BaseModel.model_validate_json.
if "ff" not in request.param:
return parse_file_as(TaskDoc, os.path.join(DATA_DIR, request.param))
return TaskDoc.model_validate_json(json_str)
else:
return parse_file_as(
ForceFieldTaskDocument, os.path.join(DATA_DIR, request.param)
)
return ForceFieldTaskDocument.model_validate_json(json_str)
Loading