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

qcschema generating, testing, and reconciliation #235

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
76c5b10
fix a few mypy and linting complaints
loriab Aug 17, 2020
29fbe5c
fix up mypy provenance
loriab Aug 18, 2020
c1af6bd
incr min pydantic to 1.5
loriab Aug 18, 2020
cb58b4e
first stab at qcsk/qcel diff
loriab Jan 28, 2020
23d24cc
alt py cmd?
loriab Jan 28, 2020
a3343eb
count directories
loriab Jan 28, 2020
04ed4a2
more actions
loriab Jan 28, 2020
e0e1304
working-dir
loriab Jan 28, 2020
03ef749
chdir
loriab Jan 28, 2020
26ce029
get PR number
loriab Jan 28, 2020
41b971e
colon
loriab Jan 28, 2020
3c014ae
try a branch
loriab Jan 28, 2020
4ae28ef
name
loriab Jan 28, 2020
67817e5
cleanup
loriab Feb 9, 2020
703738b
try a helper action
loriab Mar 2, 2020
db76928
repo name
loriab Mar 2, 2020
7bbd7cb
token
loriab Mar 2, 2020
cb65f6d
persist
loriab Mar 2, 2020
f642904
old way
loriab Mar 2, 2020
219a4e4
checkout v1
loriab Mar 2, 2020
f658835
v1v2
loriab Mar 2, 2020
c9e2ca8
alt token
loriab Mar 2, 2020
bd7f02b
from branch
loriab Mar 2, 2020
a47e47e
var branch
loriab Mar 3, 2020
8e1a07f
echo?
loriab Mar 3, 2020
97ea4c0
alt access
loriab Mar 3, 2020
aee7aea
pr only
loriab Mar 3, 2020
73855fe
define qcsk models
loriab Mar 3, 2020
12f3ebe
clean gha
loriab Mar 3, 2020
a9537c4
adapt to more schema
loriab Mar 3, 2020
8d19d79
reconcile qcsk and qcel models, test gen schema, generate schema
loriab Aug 30, 2020
fecb6d9
install jsonschema
loriab Aug 30, 2020
0c1930b
mostly black v20 formatting
loriab Aug 31, 2020
bd917fe
try alt init for ErrorCorrectionProtocol to appease schema generation
loriab Aug 31, 2020
526b685
another schema fix try
loriab Aug 31, 2020
3472650
CI try
loriab Aug 31, 2020
cf89c3b
CI try 2
loriab Aug 31, 2020
0084c23
CI try 3
loriab Aug 31, 2020
e5ea314
CI try 4
loriab Aug 31, 2020
e1efdba
CI try 5
loriab Aug 31, 2020
116c6c8
CI try 6
loriab Aug 31, 2020
f957193
CI try 7
loriab Aug 31, 2020
bdec278
CI try 8
loriab Sep 1, 2020
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
10 changes: 10 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ jobs:
cfg:
- conda-env: minimal
python-version: 3.6
label: mindep
- conda-env: base
python-version: 3.6
label: minpy
- conda-env: base
python-version: 3.8
label: full
env:
PYVER: ${{ matrix.cfg.python-version }}
CONDA_ENV: ${{ matrix.cfg.conda-env }}
Expand Down Expand Up @@ -54,5 +57,12 @@ jobs:
eval "$(conda shell.bash hook)" && conda activate test
pytest -rws -v --cov=qcelemental --color=yes --cov-report=xml qcelemental/

- name: PyTest Validate
shell: bash
if: matrix.cfg.label == 'full'
run: |
eval "$(conda shell.bash hook)" && conda activate test
pytest -rws -v --color=yes --validate qcelemental/

- name: CodeCov
uses: codecov/codecov-action@v1
91 changes: 91 additions & 0 deletions .github/workflows/QCSchema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: QCSchema

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
conda-env: [base]
python-version: [3.7]
env:
PYVER: ${{ matrix.python-version }}
CONDA_ENV: ${{ matrix.conda-env }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: qcel

- name: Checkout schema repo
uses: actions/checkout@v2
with:
repository: MolSSI/QCSchema
path: qcsk
ref: qcsk_export_2
#ref: master
# persist-credentials: false
fetch-depth: 0
token: ${{ secrets.qcschema_from_qcelemental }}

- name: Python Setup
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Create Environment
shell: bash
working-directory: ./qcel
run: |
eval "$(conda shell.bash hook)" && conda activate
python devtools/scripts/create_conda_env.py -n=test -p=$PYVER devtools/conda-envs/$CONDA_ENV.yaml

- name: Install
shell: bash
working-directory: ./qcel
run: |
eval "$(conda shell.bash hook)" && conda activate test
python -m pip install . --no-deps

- name: Environment Information
shell: bash
run: |
eval "$(conda shell.bash hook)" && conda activate test
conda list --show-channel-urls

- name: QCSchema from QCElemental
shell: bash
working-directory: ./qcel
run: |
eval "$(conda shell.bash hook)" && conda activate test
make qcschema
ls -l qcschema
cp -p qcschema/* ../qcsk/qcschema/data/vdev/
mv ../qcsk/qcschema/data/vdev/QCSchema.schema ../qcsk/qcschema/dev/

- name: Compare Schemas (generated vs. community)
shell: bash
working-directory: ./qcsk
run: |
git diff --color-words
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
branch=qcel-${pull_number}
git checkout -b ${branch}
git remote -v
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add -A
git commit -m "auto-generated from QCElemental"
echo "::set-env name=prbranch::${branch}"

- name: Propose changes
uses: ad-m/github-push-action@master
with:
directory: ./qcsk
repository: MolSSI/QCSchema
branch: ${{ env.prbranch }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.qcschema_from_qcelemental }}
force: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,7 @@ runinfo/*
# VSCode
.vscode/
raw_data/**/*_blob.py

# autogen
qcschema/*.schema
qcelemental/tests/qcschema_instances/*/*.json
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ data: cpu_data
cpu_data:
(cd raw_data/cpu_data; python build_cpu_data.py; mv cpu_data_blob.py ../../qcelemental/info/data/)

.PHONY: qcschema
qcschema:
mkdir -p qcschema
python -c "exec(\"import pathlib, qcelemental\nfor md in qcelemental.models.qcschema_models():\n\tmfile = (pathlib.Path('qcschema') / md.__name__).with_suffix('.schema')\n\twith open(mfile, 'w') as fp:\n\t\tfp.write(md.schema_json(indent=None))\")"
python -c "exec(\"import json, pathlib, pydantic, qcelemental\nwith open((pathlib.Path('qcschema') / 'QCSchema').with_suffix('.schema'), 'w') as fp:\n\tjson.dump(pydantic.schema.schema(qcelemental.models.qcschema_models(), title='QCSchema'), fp, indent=4)\")"

.PHONY: clean
clean:
rm -rf `find . -name __pycache__`
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 @@ -20,3 +20,4 @@ dependencies:
- pytest-cov
- codecov
- scipy # tests an aspect of a helper fn not used by qcel functionality
- jsonschema
3 changes: 2 additions & 1 deletion devtools/conda-envs/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ dependencies:
- nomkl
- python
- pint=0.10.0 # technically, qcel has no lower bound for pint version for py36,37 but needs 0.10 for 38
- pydantic=1.2.0 # technically, qcel works with 1.0.0 but c-f doesn't have py38 builds for it
- pydantic=1.5.0

# Testing
- pytest=4.6.4 # technically, qcel works with 4.0.0 but c-f doesn't have py38 builds for it
- pytest-cov
- codecov
- jsonschema
29 changes: 29 additions & 0 deletions qcelemental/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pathlib import Path

import pytest


def pytest_addoption(parser):
parser.addoption(
"--validate", action="store_true", help="validate JSON from previous test run against exported schema"
)


@pytest.fixture(scope="session", autouse=True)
def set_up_overall(request):
# in all pytest runs except --validate (which uses the files), clear away the JSON examples and generate fresh
if not request.config.getoption("--validate", default=False):
_data_path = Path(__file__).parent.resolve() / "tests" / "qcschema_instances"
for fl in _data_path.rglob("*.json"):
fl.unlink()


def pytest_runtest_setup(item):
# there's a bug where can only set options if specify path in call, so needs to be ``pytest qcelemental/ --validate``

# skip the validate-generated-instances-against-exported-schema tests on most ``pytest`` runs.
# run only the validate-generated-instances-against-exported-schema tests on ``pytest --validate`` runs.
if not item.config.getoption("--validate", default=False) and item.name.startswith("test_qcschema"):
pytest.skip("can't run with --validate option")
elif item.config.getoption("--validate", default=False) and not item.name.startswith("test_qcschema"):
pytest.skip("need --validate option to run")
6 changes: 2 additions & 4 deletions qcelemental/info/cpu_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@


class VendorEnum(str, Enum):
"""Allowed processor vendors, used for validation.
"""
"""Allowed processor vendors, used for validation."""

amd = "amd"
intel = "intel"
Expand All @@ -24,8 +23,7 @@ class VendorEnum(str, Enum):


class InstructionSetEnum(int, Enum):
"""Allowed instruction sets for CPUs in an ordinal enum.
"""
"""Allowed instruction sets for CPUs in an ordinal enum."""

none = 0
sse = 1
Expand Down
17 changes: 15 additions & 2 deletions qcelemental/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,18 @@
from .basis import BasisSet
from .common_models import ComputeError, DriverEnum, FailedOperation, Provenance
from .molecule import Molecule
from .procedures import Optimization, OptimizationInput, OptimizationResult
from .results import AtomicInput, AtomicResult, AtomicResultProperties, Result, ResultInput, ResultProperties
from .procedures import OptimizationInput, OptimizationResult
from .procedures import Optimization # scheduled for removal
from .results import AtomicInput, AtomicResult, AtomicResultProperties
from .results import Result, ResultInput, ResultProperties # scheduled for removal


def qcschema_models():
return [
AtomicInput,
AtomicResult,
AtomicResultProperties,
BasisSet,
Molecule,
Provenance,
]
12 changes: 3 additions & 9 deletions qcelemental/models/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ class AlignmentMill(ProtoModel):

"""

shift: Optional[Array[float]] = Field( # type: ignore
None, description="Translation array (3,) for coordinates."
)
rotation: Optional[Array[float]] = Field( # type: ignore
None, description="Rotation array (3, 3) for coordinates."
)
atommap: Optional[Array[int]] = Field( # type: ignore
None, description="Atom exchange map (nat,) for coordinates."
)
shift: Optional[Array[float]] = Field(None, description="Translation array (3,) for coordinates.") # type: ignore
rotation: Optional[Array[float]] = Field(None, description="Rotation array (3, 3) for coordinates.") # type: ignore
atommap: Optional[Array[int]] = Field(None, description="Atom exchange map (nat,) for coordinates.") # type: ignore
mirror: bool = Field(False, description="Do mirror invert coordinates?")

class Config:
Expand Down
13 changes: 13 additions & 0 deletions qcelemental/models/basemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def serialize(
include: Optional[Set[str]] = None,
exclude: Optional[Set[str]] = None,
exclude_unset: Optional[bool] = None,
exclude_defaults: Optional[bool] = None,
exclude_none: Optional[bool] = None,
) -> Union[bytes, str]:
"""Generates a serialized representation of the model

Expand All @@ -138,6 +140,10 @@ def serialize(
Fields to be excluded in the serialization.
exclude_unset : Optional[bool], optional
If True, skips fields that have default values provided.
exclude_defaults: Optional[bool], optional
If True, skips fields that have set or defaulted values equal to the default.
exclude_none: Optional[bool], optional
If True, skips fields that have value ``None``.

Returns
-------
Expand All @@ -152,6 +158,10 @@ def serialize(
kwargs["exclude"] = exclude
if exclude_unset:
kwargs["exclude_unset"] = exclude_unset
if exclude_defaults:
kwargs["exclude_defaults"] = exclude_defaults
if exclude_none:
kwargs["exclude_none"] = exclude_none

data = self.dict(**kwargs)

Expand Down Expand Up @@ -182,3 +192,6 @@ def compare(self, other: Union["ProtoModel", BaseModel], **kwargs) -> bool:
class AutodocBaseSettings(BaseSettings):
def __init_subclass__(cls) -> None:
cls.__doc__ = AutoPydanticDocGenerator(cls, always_apply=True)


qcschema_draft = "http://json-schema.org/draft-04/schema#"
Loading