Skip to content

Commit

Permalink
Support Pydantic v2 installation (#524)
Browse files Browse the repository at this point in the history
* Support Pydantic v2 installation

* No channel priority

* Add shim file

* Re-jigger test environment setup

* Syntax?

* Loadscope

* Run tutorials sequentially

* Typo

* Fix import
  • Loading branch information
mattwthompson authored Nov 17, 2023
1 parent 6575945 commit 4fe5b81
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 20 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

test:

name: 💻 ${{ matrix.os }}, 🐍 ${{ matrix.python-version }}, 👀 ${{ matrix.openeye }}, pymbar ${{ matrix.pymbar-version }}, OpenMM ${{ matrix.openmm-version }}
name: 💻 ${{ matrix.os }}, 🐍 ${{ matrix.python-version }}, 👀 ${{ matrix.openeye }}, pymbar ${{ matrix.pymbar-version }}, Pydantic ${{ matrix.pydantic-version }}, OpenMM ${{ matrix.openmm-version }}
runs-on: ${{ matrix.os }}

env:
Expand All @@ -35,6 +35,9 @@ jobs:
- "3.10"
pymbar-version:
- "3.1"
pydantic-version:
- "1"
- "2"
openmm-version:
- "7"
- "8"
Expand All @@ -55,9 +58,8 @@ jobs:
create-args: >-
python=${{ matrix.python-version }}
pymbar=${{ matrix.pymbar-version }}
pydantic=${{ matrix.pydantic-version }}
openmm=${{ matrix.openmm-version }}
jax>=0.3
jaxlib>=0.3
- name: Install OpenEye
if: matrix.openeye
Expand All @@ -69,6 +71,11 @@ jobs:
env:
SECRET_OE_LICENSE: ${{ secrets.OE_LICENSE }}

- name: Install Foyer
if: ${{ matrix.pydantic-version == 1 }}
shell: bash -l {0}
run: micromamba install foyer -c conda-forge

- name: Install PASCAL Compiler (MacOS)
if: startsWith(matrix.os, 'macOS')
run: brew install fpc
Expand All @@ -88,20 +95,19 @@ jobs:
- name: Install Package and test plugins
run: python -m pip install . utilities/test_plugins/

- name: Conda Environment Information
run: conda info && conda list

- name: Run tests
run: python -m pytest -v --cov=openff openff/evaluator/_tests/ --cov-report=xml --color=yes

- name: Run (non-GPU) tutorials
if: ${{ matrix.pymbar-version == 3 }}
if: ${{ matrix.pymbar-version == 3.1 }}
run: |
# ForceBalance requires pymbar 3, so don't run these tests if we are using pymbar 4,
# even though we're not running the fitting tutorial
# https://github.com/conda-forge/forcebalance-feedstock/blob/9793b0205489f8ec7826d301a3c82cfb96997c57/recipe/meta.yaml#L29
micromamba install "forcebalance >=1.9.5" -c conda-forge -yq
python -m pytest --nbval-lax docs/tutorials/tutorial01.ipynb docs/tutorials/tutorial03.ipynb
python -m pytest --nbval-lax --dist loadscope -nauto -p no:randomly \
docs/tutorials/tutorial01.ipynb \
docs/tutorials/tutorial03.ipynb
- name: Code coverage
uses: codecov/codecov-action@v3
Expand Down
5 changes: 3 additions & 2 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ dependencies:
- nbval
- requests-mock # For testing http requests.
# smirnoff-plugins =0.0.3
- foyer
# Add back when MoSDeF supports pydantic v2
# foyer

# Shims
- pint =0.20.1
Expand All @@ -32,7 +33,7 @@ dependencies:
- pyyaml
- requests
- python-dateutil
- pydantic <2.0.0a0
- pydantic
- paprika
- taproom
- dataclasses
Expand Down
32 changes: 32 additions & 0 deletions openff/evaluator/_pydantic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
try:
from pydantic.v1 import (
BaseModel,
Field,
HttpUrl,
PositiveFloat,
PositiveInt,
ValidationError,
confloat,
conint,
conlist,
constr,
root_validator,
validator,
)
from pydantic.v1.validators import dict_validator
except ModuleNotFoundError:
from pydantic import (
BaseModel,
Field,
HttpUrl,
PositiveFloat,
PositiveInt,
ValidationError,
confloat,
conint,
conlist,
constr,
root_validator,
validator,
)
from pydantic.validators import dict_validator
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import pandas
import pytest
from openff.units import unit
from pydantic import ValidationError

from openff.evaluator._pydantic import ValidationError
from openff.evaluator.datasets import (
MeasurementSource,
PhysicalPropertyDataSet,
Expand Down
3 changes: 3 additions & 0 deletions openff/evaluator/_tests/test_protocols/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from openff.toolkit.topology import Molecule
from openff.toolkit.utils.rdkit_wrapper import RDKitToolkitWrapper
from openff.units import unit
from openff.utilities import skip_if_missing

from openff.evaluator._tests.utils import build_tip3p_smirnoff_force_field
from openff.evaluator.backends import ComputeResources
Expand Down Expand Up @@ -168,6 +169,7 @@ def download_callback(_, context):
assert path.isfile(assign_parameters.parameterized_system.system_path)


@skip_if_missing("foyer")
def test_build_foyer_oplsaa_system():
force_field_source = FoyerForceFieldSource("oplsaa")
substance = Substance.from_components("C", "CC", "c1ccccc1", "CC(=O)O")
Expand Down Expand Up @@ -202,6 +204,7 @@ def test_build_foyer_oplsaa_system():
assert path.isfile(energy_minimisation.output_coordinate_file)


@skip_if_missing("foyer")
def test_build_foyer_xml_system():
with tempfile.TemporaryDirectory() as directory:
force_field_source_path = path.join(directory, "ff.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import overload

import pandas
from pydantic import BaseModel

from openff.evaluator._pydantic import BaseModel
from openff.evaluator.datasets import PhysicalPropertyDataSet

logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions openff/evaluator/datasets/curation/components/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from typing import TYPE_CHECKING, Union

import pandas
from pydantic import Field
from typing_extensions import Literal

from openff.evaluator._pydantic import Field
from openff.evaluator.datasets.curation.components import (
CurationComponent,
CurationComponentSchema,
Expand All @@ -19,7 +19,7 @@
PositiveFloat = float

else:
from pydantic import conint
from openff.evaluator._pydantic import conint

logger = logging.getLogger(__name__)

Expand Down
10 changes: 8 additions & 2 deletions openff/evaluator/datasets/curation/components/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import numpy
import pandas
from openff.units import unit
from pydantic import Field, root_validator, validator
from scipy.optimize import linear_sum_assignment
from typing_extensions import Literal

from openff.evaluator._pydantic import Field, root_validator, validator
from openff.evaluator.datasets.curation.components import (
CurationComponent,
CurationComponentSchema,
Expand All @@ -31,7 +31,13 @@
PositiveFloat = float

else:
from pydantic import PositiveFloat, PositiveInt, confloat, conint, constr
from openff.evaluator._pydantic import (
PositiveFloat,
PositiveInt,
confloat,
conint,
constr,
)

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions openff/evaluator/datasets/curation/components/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import numpy
import pandas
from pydantic import BaseModel, Field, conlist, validator
from typing_extensions import Literal

from openff.evaluator._pydantic import BaseModel, Field, conlist, validator
from openff.evaluator.datasets.curation.components import (
CurationComponent,
CurationComponentSchema,
Expand Down Expand Up @@ -36,7 +36,7 @@
OEFingerPrint = None

else:
from pydantic import PositiveInt
from openff.evaluator._pydantic import PositiveInt


class State(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion openff/evaluator/datasets/curation/components/thermoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import pandas
import requests
from pydantic import Field, HttpUrl
from typing_extensions import Literal

from openff.evaluator._pydantic import Field, HttpUrl
from openff.evaluator.datasets.curation.components import (
CurationComponent,
CurationComponentSchema,
Expand Down
2 changes: 1 addition & 1 deletion openff/evaluator/datasets/curation/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import numpy
import pandas
from pydantic import BaseModel, Field

from openff.evaluator._pydantic import BaseModel, Field
from openff.evaluator.datasets import PhysicalPropertyDataSet
from openff.evaluator.datasets.curation.components import CurationComponent
from openff.evaluator.datasets.curation.components.conversion import (
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ignore = E203, E266, E501, W503
select = B,C,E,F,W,T4,B9
per-file-ignores =
openff/evaluator/__init__.py:F401
openff/evaluator/_pydantic.py:F401

[isort]
multi_line_output=3
Expand Down

0 comments on commit 4fe5b81

Please sign in to comment.