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

Test new openff-models w/ pydantic v2 #336

Closed
wants to merge 12 commits into from
Closed
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
18 changes: 11 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
# Note: pinned to macos-12
# see https://github.com/OpenFreeEnergy/openfe/issues/842
- os: "macos-12"
python-version: "3.11"
python-version: "3.12"
pydantic-version: ">1"
- os: "ubuntu-latest"
python-version: "3.11"
python-version: "3.12"
pydantic-version: "<2"

env:
Expand All @@ -66,16 +66,20 @@ jobs:
- name: "Install"
run: python -m pip install --no-deps -e .

- name: "Test imports"
run: |
# if we add more to this, consider changing to for + env vars
python -Ic "import gufe; print(gufe.__version__)"

- name: "Environment Information"
run: |
micromamba info
micromamba list

- name: "test pydantic"
run: |
python -Ic "import pydantic; print(pydantic.__version__)"

- name: "Test imports"
run: |
# if we add more to this, consider changing to for + env vars
python -Ic "import gufe; print(gufe.__version__)"

- name: "Run tests"
run: |
pytest -n 2 -v --cov=gufe --cov-report=xml
Expand Down
7 changes: 4 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ dependencies:
- openff-toolkit >=0.15.1
- openff-units ==0.2.0 # https://github.com/openforcefield/openff-units/issues/69
- pint <0.22 # https://github.com/openforcefield/openff-units/issues/69
- openff-models >=0.0.5
- pip
- pydantic >1
- pydantic ==2.7.3
- pytest
- pytest-cov
- pytest-xdist
- typing-extensions
- ambertools >=22.0 # why were we getting old ones?
# docs
- autodoc-pydantic
- pydata-sphinx-theme
- sphinx-jsonschema==1.15
- sphinx <7.1.2
- pip:
- autodoc_pydantic<2.0.0
- git+https://github.com/openforcefield/openff-models@pydantic-2-redo
IAlibay marked this conversation as resolved.
Show resolved Hide resolved
- git+https://github.com/openforcefield/openff-units@main
44 changes: 21 additions & 23 deletions gufe/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@
from typing import Optional, Union

from openff.models.models import DefaultModel
from openff.models.types import FloatQuantity
from openff.models.types.dimension_types import (
TemperatureQuantity,
LengthQuantity,
build_dimension_type,
)
from openff.units import unit
import pprint

try:
from pydantic.v1 import (
Extra,
Field,
PositiveFloat,
PrivateAttr,
validator,
)
except ImportError:
from pydantic import (
Extra,
Field,
PositiveFloat,
PrivateAttr,
validator,
)
from pydantic import (
Extra,
Field,
PositiveFloat,
PrivateAttr,
validator,
)
import pydantic


PressureQuantity = build_dimension_type("standard_atmosphere")


class SettingsBaseModel(DefaultModel):
"""Settings and modifications we want for all settings classes."""
_is_frozen: bool = PrivateAttr(default_factory=lambda: False)
Expand All @@ -40,7 +38,7 @@ class Config:
:noindex:
"""
extra = pydantic.Extra.forbid
arbitrary_types_allowed = False
arbitrary_types_allowed = True
smart_union = True

def _ipython_display_(self):
Expand Down Expand Up @@ -112,14 +110,14 @@ class ThermoSettings(SettingsBaseModel):
possible.
"""

temperature: FloatQuantity["kelvin"] = Field(
temperature: TemperatureQuantity = Field(
None, description="Simulation temperature, default units kelvin"
)
pressure: FloatQuantity["standard_atmosphere"] = Field(
pressure: Union[PressureQuantity, None] = Field(
None, description="Simulation pressure, default units standard atmosphere (atm)"
)
ph: Union[PositiveFloat, None] = Field(None, description="Simulation pH")
redox_potential: Optional[float] = Field(
redox_potential: Union[float, None] = Field(
None, description="Simulation redox potential"
)

Expand Down Expand Up @@ -169,12 +167,12 @@ class Config:
small_molecule_forcefield: str = "openff-2.1.1" # other default ideas 'openff-2.0.0', 'gaff-2.11', 'espaloma-0.2.0'
"""Name of the force field to be used for :class:`SmallMoleculeComponent` """

nonbonded_method = 'PME'
nonbonded_method: str = 'PME'
"""
Method for treating nonbonded interactions, currently only PME and
NoCutoff are allowed. Default PME.
"""
nonbonded_cutoff: FloatQuantity['nanometer'] = 1.0 * unit.nanometer
nonbonded_cutoff: LengthQuantity = 1.0 * unit.nanometer
"""
Cutoff value for short range nonbonded interactions.
Default 1.0 * unit.nanometer.
Expand Down
20 changes: 17 additions & 3 deletions gufe/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
)


def test_model_schema():
Settings.schema_json(indent=2)
#def test_model_schema():
# Settings.schema_json(indent=2)


@pytest.mark.xfail # issue #125
Expand All @@ -42,7 +42,7 @@ def test_default_settings():
my_settings = Settings.get_defaults()
my_settings.thermo_settings.temperature = 298 * unit.kelvin
my_settings.json()
my_settings.schema_json(indent=2)
#my_settings.schema_json(indent=2)


@pytest.mark.parametrize('value,good', [
Expand Down Expand Up @@ -97,6 +97,20 @@ def test_frozen_equality(self):
# should be considered equal
s = Settings.get_defaults()
s2 = s.frozen_copy()
s3 = s2.unfrozen_copy()

assert s3 == s

#err_list = []
#for entry in s.__dict__:
# if s.__dict__[entry] != s2.__dict__[entry]:
# err_list.append(entry)

#for entry in s.__dict__['forcefield_settings']:


#if len(err_list) > 0:
# raise ValueError(err_list)

assert s == s2

Expand Down
Loading