From ac45507ced139fc642bdffb82f25a7994f005d8d Mon Sep 17 00:00:00 2001 From: qchempku2017 Date: Tue, 14 Nov 2023 12:20:38 +0800 Subject: [PATCH] DEV: Update to pydantic 2. Need to regenerate taskdocs for testing. --- CHANGES.md | 5 +++-- .../semi_automation_BCC_AlLi/fit_model.py | 6 ++++-- .../semi_automation_BCC_AlLi/generate.py | 5 +++-- pyproject.toml | 6 +++--- requirements-optional.txt | 1 + requirements.txt | 16 ++++++++-------- tests/conftest.py | 10 +++++----- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f2885df..5e4beea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,8 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 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. +- Implemented support to generic structural calculation makers. +- Upgraded to Pydantic 2. ## [v0.0.0](https://github.com/CederGroupHub/WFacer/tree/0.0.0) (2023-09-20) Initial relatively *stable* version of the code. diff --git a/docs/src/example_scripts/semi_automation_BCC_AlLi/fit_model.py b/docs/src/example_scripts/semi_automation_BCC_AlLi/fit_model.py index 6c3a713..da06b3b 100644 --- a/docs/src/example_scripts/semi_automation_BCC_AlLi/fit_model.py +++ b/docs/src/example_scripts/semi_automation_BCC_AlLi/fit_model.py @@ -5,7 +5,7 @@ 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 @@ -13,7 +13,9 @@ # 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 diff --git a/docs/src/example_scripts/semi_automation_BCC_AlLi/generate.py b/docs/src/example_scripts/semi_automation_BCC_AlLi/generate.py index 35528f2..2a56e28 100644 --- a/docs/src/example_scripts/semi_automation_BCC_AlLi/generate.py +++ b/docs/src/example_scripts/semi_automation_BCC_AlLi/generate.py @@ -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"] diff --git a/pyproject.toml b/pyproject.toml index 211f9da..78a3523 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/requirements-optional.txt b/requirements-optional.txt index 0397d15..bbdedcc 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -1,3 +1,4 @@ gurobipy==10.0.3 pyscipopt==4.3.0 fireworks==2.0.3 +ase==3.22.1 diff --git a/requirements.txt b/requirements.txt index 9dd32bd..bcaad72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index cd6a9e8..e9e4eb7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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)