Skip to content

Commit

Permalink
Pydanticv2again (#414)
Browse files Browse the repository at this point in the history
* Use Pydantic v1 API even with v2

The correct version of #736. I had originally had branched from a point way in the past.

* alt qcngrecords

* no records for now

* faux upgrate

* better sed

* only certain lanes

* tweak

* records back

* master qcenginerecords

* forgive

* mamba

* where'd they go?

* still work?

* update node12 to 16. retract adcc

* now adcc?

* try again adcc

* my bad

* adcc again

* check sphinx

* appease sphinx black

* sphinx

* maybe finally ready

---------

Co-authored-by: Levi Naden <lnaden@vt.edu>
  • Loading branch information
loriab and Lnaden authored Aug 2, 2023
1 parent 1887e71 commit 47f9c40
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 35 deletions.
39 changes: 32 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
runs-on: ${{ matrix.cfg.runs-on }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -83,6 +83,12 @@ jobs:
environment-file: devtools/conda-envs/${{ matrix.cfg.conda-env }}.yaml
python-version: ${{ matrix.cfg.python-version }}
auto-activate-base: false
show-channel-urls: true
miniforge-variant: Mambaforge
use-mamba: true
add-pip-as-python-dependency: true
# note: conda-forge chnl req'd for Mambaforge, but we'll spec in file, not here `channels: conda-forge,...`
# note: any activate/deactivate use the conda cmd. other cmds use mamba cmd.

- name: Special Config - NWChem
if: "(matrix.cfg.label == 'NWChem')"
Expand All @@ -94,15 +100,30 @@ jobs:
run: |
qcore --accept-license
# note: psi4 on c-f pins to a single qcel and qcng, so this may be handy for solve-and-replace
#- name: Special Config - QCElemental Dep
# if: (matrix.cfg.label == 'ADCC')
# run: |
# conda remove qcelemental --force
# python -m pip install qcelemental>=0.26.0 --no-deps

# note: conda remove --force, not mamba remove --force b/c https://github.com/mamba-org/mamba/issues/412
# alt. is micromamba but not yet ready for setup-miniconda https://github.com/conda-incubator/setup-miniconda/issues/75
- name: Special Config - QCEngine Dep
if: "(matrix.cfg.label == 'Psi4-nightly') || (matrix.cfg.label == 'ADCC') || (matrix.cfg.label == 'optimization-dispersion')"
run: |
conda remove qcengine --force
# QCEngine CI and Psi4 are circularly dependent, so a hack is in order
- name: Special Config - Faux Pydantic Upgrade
if: "(matrix.cfg.label == 'Psi4-nightly') || (matrix.cfg.label == 'optimization-dispersion')"
run: |
sed -i s/from\ pydantic\ /from\ pydantic.v1\ /g ${CONDA_PREFIX}/lib/python${{ matrix.cfg.python-version }}/site-packages/psi4/driver/*py
- name: Environment Information
run: |
conda info
conda list --show-channel-urls
mamba info
mamba list
- name: Install QCEngine
run: |
Expand All @@ -120,7 +141,7 @@ jobs:
pytest -rws -v --cov=qcengine --color=yes --cov-report=xml qcengine/
- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3

release_sphinx:
needs: [build]
Expand All @@ -140,7 +161,7 @@ jobs:
runs-on: ${{ matrix.cfg.runs-on }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Create Environment
uses: conda-incubator/setup-miniconda@v2
Expand All @@ -149,11 +170,15 @@ jobs:
environment-file: devtools/conda-envs/${{ matrix.cfg.conda-env }}.yaml
python-version: ${{ matrix.cfg.python-version }}
auto-activate-base: false
miniforge-variant: Mambaforge
use-mamba: true
add-pip-as-python-dependency: true
channels: conda-forge

- name: Environment Information
run: |
conda info
conda list --show-channel-urls
mamba info
mamba list --show-channel-urls
- name: Build Documentation
run: |
Expand Down
13 changes: 5 additions & 8 deletions devtools/conda-envs/adcc.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
name: test
channels:
#- adcc
- defaults
- psi4/label/dev
- conda-forge
- nodefaults
dependencies:
- conda-forge::adcc>=0.15.7
- psi4
- blas=*=mkl # not needed but an example of disuading solver from openblas and old psi
- intel-openmp!=2019.5
- adcc>=0.15.7
- psi4>=1.8.1
- conda-forge/label/libint_dev::libint

# Core
- python
- pyyaml
- py-cpuinfo
- psutil
- qcelemental >=0.24.0
- pydantic>=1.0.0
- pydantic=1
- msgpack-python

# Testing
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/docs-cf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- python
- networkx
- pydantic
- pydantic=1
- numpy
- pint

Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/opt-disp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies:
- pyyaml
- py-cpuinfo
- psutil
- qcelemental >=0.24.0
- qcelemental >=0.26.0
- pydantic>=1.0.0
- msgpack-python

Expand Down
3 changes: 1 addition & 2 deletions devtools/conda-envs/psi-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ channels:
dependencies:
- psi4
- blas=*=mkl # not needed but an example of disuading solver from openblas and old psi
- intel-openmp!=2019.5

# Core
- python
- pyyaml
- py-cpuinfo
- psutil
- qcelemental >=0.24.0
- qcelemental >=0.26.0
- pydantic>=1.0.0
- msgpack-python

Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/psi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- psutil
- qcelemental=0.24.0
- pydantic=1.8.2 # test minimun stated version.
- msgpack-python

# Testing
- pytest
Expand Down
19 changes: 18 additions & 1 deletion docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Changelog
=========

.. vX.Y.0 / 2022-MM-DD
.. vX.Y.0 / 2023-MM-DD
.. Unreleased
.. --------------------
..
.. Breaking Changes
Expand All @@ -17,6 +18,22 @@ Changelog
.. +++++++++
v0.27.0 / 2023-08-DD
--------------------

Bug Fixes
+++++++++
- (:pr:`414`) Import `pydantic.v1` from pydantic v2 so that QCEngine can work with any >=1.8.2 pydantic
until QCEngine is updated for v2. If using v2, use QCElemental >=v0.26.0 that has a similar change.
QCEngineRecords received similar treatment. @Lnaden, @loriab
- (:pr:`414`) Versioneer - update so works with Python 3.12.
- (:pr:`414`) Maintenance
- Sphinx - fix build errors.
- Lint - pin black to 2022 format.
- GHA - switch to mamba solver. @loriab
- (:pr:`394`) Entos/Qcore - updated model environments. @loriab


v0.26.0 / 2022-11-30
--------------------

Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -190,8 +190,8 @@
# -- Extension configuration -------------------------------------------------

extlinks = {
'issue': ('https://github.com/MolSSI/QCEngine/issues/%s', 'GH#'),
'pr': ('https://github.com/MolSSI/QCEngine/pull/%s', 'GH#')
'issue': ('https://github.com/MolSSI/QCEngine/issues/%s', 'GH#%s'),
'pr': ('https://github.com/MolSSI/QCEngine/pull/%s', 'GH#%s')
}

# -- Options for intersphinx extension ---------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion qcengine/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
from .util import compute_wrapper, environ_context, handle_output_metadata, model_wrapper

if TYPE_CHECKING:
from pydantic.main import BaseModel
try:
from pydantic.v1.main import BaseModel
except ImportError:
from pydantic.main import BaseModel
from qcelemental.models import AtomicResult


Expand Down
5 changes: 4 additions & 1 deletion qcengine/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import socket
from typing import Any, Dict, Optional, Union

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from .extras import get_information

Expand Down
5 changes: 4 additions & 1 deletion qcengine/procedures/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import abc
from typing import Any, Dict, Union

from pydantic import BaseModel
try:
from pydantic.v1 import BaseModel
except ImportError:
from pydantic import BaseModel

from ..util import model_wrapper

Expand Down
5 changes: 4 additions & 1 deletion qcengine/programs/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import logging
from typing import Any, Dict, List, Optional, Tuple, Union

from pydantic import BaseModel
try:
from pydantic.v1 import BaseModel
except ImportError:
from pydantic import BaseModel
from qcelemental.models import AtomicInput, AtomicResult, FailedOperation

from qcengine.exceptions import KnownErrorException
Expand Down
1 change: 1 addition & 0 deletions qcengine/programs/tests/test_qchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"root.provenance.routine",
"root.provenance.creator",
"root.extras",
"root.molecule.extras",
]


Expand Down
2 changes: 1 addition & 1 deletion qcengine/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import qcengine as qcng

QCENGINE_RECORDS_COMMIT = "aa4a1b2"
QCENGINE_RECORDS_COMMIT = "0e2fdb4"


def _check_qcenginerecords(return_data=False):
Expand Down
5 changes: 4 additions & 1 deletion qcengine/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import copy

import pydantic
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
import pytest

import qcengine as qcng
Expand Down
2 changes: 1 addition & 1 deletion qcengine/tests/test_harness_canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_compute_gradient(program, model, keywords):
with pytest.raises(qcng.exceptions.InputError) as e:
qcng.compute(inp, program, raise_error=True)

assert "Driver gradient not implemented" in str(e.value)
assert "gradient not implemented" in str(e.value)

else:
ret = qcng.compute(inp, program, raise_error=True)
Expand Down
5 changes: 4 additions & 1 deletion qcengine/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from threading import Thread
from typing import Any, BinaryIO, Dict, List, Optional, TextIO, Tuple, Union

from pydantic import BaseModel, ValidationError
try:
from pydantic.v1 import BaseModel, ValidationError
except ImportError:
from pydantic import BaseModel, ValidationError
from qcelemental.models import AtomicResult, FailedOperation, OptimizationResult

from qcengine.config import TaskConfig
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
cmdclass=versioneer.get_cmdclass(),
packages=setuptools.find_packages(),
setup_requires=[] + pytest_runner,
install_requires=["pyyaml", "py-cpuinfo", "psutil", "qcelemental>=0.24.0,<0.26.0", "pydantic>=1.8.2"],
install_requires=["pyyaml", "py-cpuinfo", "psutil", "qcelemental>=0.24.0,<0.27.0", "pydantic>=1.8.2"],
entry_points={"console_scripts": ["qcengine=qcengine.cli:main"]},
extras_require={
"docs": [
Expand All @@ -38,7 +38,7 @@
"numpydoc",
],
"tests": ["pytest", "pytest-cov"],
"lint": ["black"],
"lint": ["black>=22.1.0,<23.0a0"],
},
tests_require=["pytest", "pytest-cov"],
classifiers=[
Expand All @@ -50,6 +50,8 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
zip_safe=False,
long_description=long_description,
Expand Down
4 changes: 2 additions & 2 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def get_config_from_root(root):
# configparser.NoOptionError (if it lacks "VCS="). See the docstring at
# the top of versioneer.py for instructions on writing your setup.cfg .
setup_cfg = os.path.join(root, "setup.cfg")
parser = configparser.SafeConfigParser()
parser = configparser.ConfigParser()
with open(setup_cfg, "r") as f:
parser.readfp(f)
parser.read_file(f)
VCS = parser.get("versioneer", "VCS") # mandatory

def get(parser, name):
Expand Down

0 comments on commit 47f9c40

Please sign in to comment.