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

Csse pyd2 internal classes #453

Merged
merged 9 commits into from
Oct 4, 2024
Merged
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
13 changes: 8 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@ jobs:
run: |
sed -i s/from\ pydantic\ /from\ pydantic.v1\ /g ${CONDA_PREFIX}/lib/python${{ matrix.cfg.python-version }}/site-packages/psi4/driver/*py

- name: Install QCEngine
run: |
python -m pip install . --no-deps

- name: Environment Information
run: |
conda info
conda list

- name: Install QCEngine
run: |
python -m pip install . --no-deps
python -c "import qcelemental as q;print(q.__file__, q.__version__)"
python -c "import qcengine as q;print(q.__file__, q.__version__)"
git describe

- name: QCEngineRecords
if: "(matrix.cfg.label != 'Psi4-1.6')"
Expand All @@ -197,7 +200,7 @@ jobs:
matrix:
cfg:
- conda-env: docs-cf
python-version: 3.8
python-version: "3.10"
label: Sphinx
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/adcc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
- psutil
- qcelemental >=0.24.0
- pydantic=2
- pydantic-settings
- msgpack-python

# Testing
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/aimnet2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- psutil
- qcelemental >=0.12.0
- pydantic>=2.0.0
- pydantic-settings

# Testing
- pytest
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- psutil
- qcelemental >=0.12.0
- pydantic>=2.0.0
- pydantic-settings

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

Expand All @@ -18,7 +19,7 @@ dependencies:
- sphinx-autodoc-typehints
- sphinx-automodapi
- sphinx_rtd_theme
- autodoc-pydantic
- autodoc-pydantic=2

# testing
- pytest>=4.0.0
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/mace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- psutil
- qcelemental >=0.12.0
- pydantic>=2.0.0
- pydantic-settings

# mace deps
- pymace
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/mrchem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
- psutil
- qcelemental>=0.24
- pydantic=2
- pydantic-settings

# Testing
- pytest
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/nwchem-cf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
- qcelemental >=0.24.0
- pydantic>=2.0.0
- networkx>=2.4.0
- pydantic-settings

# Testing
- pytest
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/nwchem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- qcelemental >=0.24.0
- pydantic>=2.0.0
- networkx>=2.4.0
- pydantic-settings

# Testing
- pytest
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/openmm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- psutil
- qcelemental >=0.11.1
- pydantic >=2
- pydantic-settings
- pint <0.22

# Testing
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/opt-disp-cf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- psutil
- qcelemental >=0.26.0
- pydantic=2
- pydantic-settings
- msgpack-python

# Testing
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/opt-disp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
#- intel-openmp!=2019.5
- rdkit
- mopac
- pydantic-settings

# Mixed Tests
- dftd3 3.2.1
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/psi-cf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ channels:
dependencies:
- psi4=1.8
- numpy<2
- pydantic-settings

# Core
- python
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/psi-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
- psutil
- qcelemental >=0.26.0
- pydantic>=2.0.0
- pydantic-settings
- msgpack-python
- numpy=1

Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/rdkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
- psutil
- qcelemental >=0.12.0
- pydantic>=2
- pydantic-settings

# Testing
- pytest
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/torchani.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
- psutil
- qcelemental >=0.12.0
- pydantic>=2
- pydantic-settings

- pytorch

Expand Down
1 change: 1 addition & 0 deletions devtools/conda-envs/xtb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
- psutil
- qcelemental >=0.11.1
- pydantic >=2
- pydantic-settings

# Extras
- gcp-correction
Expand Down
35 changes: 35 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,41 @@ Changelog
.. - UNSOLVED (:issue:`397`) extras failed


vX.Y.0 / 2024-MM-DD (Unreleased)
--------------------

Breaking Changes
++++++++++++++++
- (:pr:`453`) Deps - Require pydantic v2 dependency (don't worry, this isn't
changing QCEngine's role as QCSchema I/O runner. Also require pydantic-settings
for CLI. @loriab

New Features
++++++++++++

Enhancements
++++++++++++
- (:pr:`453`) Maint - Convert internal (non-QCSchema) pydantic classes to
pydantic v2 API, namely `NodeDescriptor`, `TaskConfig`, `ProgramHarness`,
`ProcedureHarness`. @loriab

Bug Fixes
+++++++++
- (:pr:`453`) Maint - Fix a warning thrown by `execute` about unclosed files. @loriab

Misc.
+++++
- (:pr:`452`) Maint - Set up pre-commit and run over repository. @loriab
- (:pr:`453`) CI - Dropped Entos/QCore and Psi4 v1.5 as too hard to solve with
pydantic v2 and modern python versions. @loriab

MUST (Unmerged)
+++++++++++++++

WIP (Unmerged)
++++++++++++++


v0.30.0 / 2024-06-25
--------------------

Expand Down
10 changes: 8 additions & 2 deletions docs/source/single_compute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ The results contain a complete record of the computation:
Input Fields
-------------

.. autopydantic_model:: qcelemental.models.AtomicInput
Note this is QCSchema v2 ``AtomicInput``. See the QCElemental docs for the
longstanding v1 model.

.. autopydantic_model:: qcelemental.models.v2.AtomicInput
:noindex:

Returned Fields
---------------

.. autopydantic_model:: qcelemental.models.AtomicResult
Note this is QCSchema v2 ``AtomicResult``. See the QCElemental docs for the
longstanding v1 model.

.. autopydantic_model:: qcelemental.models.v2.AtomicResult
:noindex:

FAQ
Expand Down
5 changes: 1 addition & 4 deletions qcengine/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
from .util import compute_wrapper, environ_context, handle_output_metadata, model_wrapper

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


Expand Down
42 changes: 18 additions & 24 deletions qcengine/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import socket
from typing import Any, Dict, Optional, Union

try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from pydantic import BaseModel, ConfigDict, Field
from pydantic_settings import BaseSettings, SettingsConfigDict

from .extras import get_information

Expand Down Expand Up @@ -69,7 +67,7 @@ def get_global(key: Optional[str] = None) -> Union[str, Dict[str, Any]]:
return _global_values[key]


class NodeDescriptor(pydantic.BaseModel):
class NodeDescriptor(BaseModel):
"""
Description of an individual node
"""
Expand All @@ -83,7 +81,7 @@ class NodeDescriptor(pydantic.BaseModel):
memory_safety_factor: int = 10 # Percentage of memory as a safety factor

# Specifications
ncores: Optional[int] = pydantic.Field(
ncores: Optional[int] = Field(
None,
description="""Number of cores accessible to each task on this node

Expand All @@ -93,9 +91,9 @@ class NodeDescriptor(pydantic.BaseModel):
retries: int = 0

# Cluster options
is_batch_node: bool = pydantic.Field(
is_batch_node: bool = Field(
False,
help="""Whether the node running QCEngine is a batch node
description="""Whether the node running QCEngine is a batch node

Some clusters are configured such that tasks are launched from a special "batch" or "MOM" onto the compute nodes.
The compute nodes on such clusters often have a different CPU architecture than the batch nodes and
Expand All @@ -108,7 +106,7 @@ class NodeDescriptor(pydantic.BaseModel):
``mpiexec_command`` must always be used even for serial jobs (e.g., getting the version number)
""",
)
mpiexec_command: Optional[str] = pydantic.Field(
mpiexec_command: Optional[str] = Field(
None,
description="""Invocation for launching node-parallel tasks with MPI

Expand Down Expand Up @@ -145,31 +143,27 @@ def __init__(self, **data: Dict[str, Any]):
if "{ranks_per_node}" not in self.mpiexec_command:
raise ValueError("mpiexec_command must explicitly state the number of ranks per node")

class Config:
extra = "forbid"
model_config = ConfigDict(extra="forbid")


class TaskConfig(pydantic.BaseSettings):
class TaskConfig(BaseSettings):
"""Description of the configuration used to launch a task."""

# Specifications
ncores: int = pydantic.Field(None, description="Number cores per task on each node")
nnodes: int = pydantic.Field(None, description="Number of nodes per task")
memory: float = pydantic.Field(
None, description="Amount of memory in GiB (2^30 bytes; not GB = 10^9 bytes) per node."
)
ncores: int = Field(None, description="Number cores per task on each node")
nnodes: int = Field(None, description="Number of nodes per task")
memory: float = Field(None, description="Amount of memory in GiB (2^30 bytes; not GB = 10^9 bytes) per node.")
scratch_directory: Optional[str] # What location to use as scratch
retries: int # Number of retries on random failures
mpiexec_command: Optional[str] # Command used to launch MPI tasks, see NodeDescriptor
use_mpiexec: bool = False # Whether it is necessary to use MPI to run an executable
cores_per_rank: int = pydantic.Field(1, description="Number of cores per MPI rank")
scratch_messy: bool = pydantic.Field(
False, description="Leave scratch directory and contents on disk after completion."
)
cores_per_rank: int = Field(1, description="Number of cores per MPI rank")
scratch_messy: bool = Field(False, description="Leave scratch directory and contents on disk after completion.")

class Config(pydantic.BaseSettings.Config):
extra = "forbid"
env_prefix = "QCENGINE_"
model_config = SettingsConfigDict(
extra="forbid",
env_prefix="QCENGINE_",
)


def _load_defaults() -> None:
Expand Down
4 changes: 2 additions & 2 deletions qcengine/procedures/berny.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import traceback
from io import StringIO
from typing import Any, Dict, Union
from typing import Any, ClassVar, Dict, Union

import numpy as np
from qcelemental.models import FailedOperation, OptimizationInput, OptimizationResult
Expand All @@ -16,7 +16,7 @@


class BernyProcedure(ProcedureHarness):
_defaults = {"name": "Berny", "procedure": "optimization"}
_defaults: ClassVar[Dict[str, Any]] = {"name": "Berny", "procedure": "optimization"}

def found(self, raise_error: bool = False) -> bool:
return which_import(
Expand Down
7 changes: 2 additions & 5 deletions qcengine/procedures/geometric.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Union
from typing import Any, ClassVar, Dict, Union

from qcelemental.models import OptimizationInput, OptimizationResult
from qcelemental.util import safe_version, which_import
Expand All @@ -8,13 +8,10 @@

class GeometricProcedure(ProcedureHarness):

_defaults = {"name": "geomeTRIC", "procedure": "optimization"}
_defaults: ClassVar[Dict[str, Any]] = {"name": "geomeTRIC", "procedure": "optimization"}

version_cache: Dict[str, str] = {}

class Config(ProcedureHarness.Config):
pass

def found(self, raise_error: bool = False) -> bool:
return which_import(
"geometric",
Expand Down
Loading
Loading