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

Feature qcio #42

Merged
merged 1 commit into from
Sep 10, 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
58 changes: 58 additions & 0 deletions .github/workflows/basic-code-quanlity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Basic Code Quality

on: [push]

env:
POETRY_VIRTUALENVS_CREATE: false

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install ruff
run: pip install ruff
- name: ruff
run: ruff check .

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install poetry
run: pip install poetry
- name: Install repo
run: poetry install --no-interaction --no-ansi
- name: mypy
run: mypy .

detect-secrets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install detect secrets
run: pip install detect-secrets
- name: Look for secrets
# Ignore jwt.txt; the token is supposed to be there.
run: git ls-files -z | xargs -0 detect-secrets-hook -v

typos:
name: "spell check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: crate-ci/typos@master
with:
files: .
9 changes: 5 additions & 4 deletions .github/workflows/publish-to-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Install Flit
run: pip install flit
- name: Install poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -

- name: Build distribution 📦
run: flit build
run: poetry build

- name: Publish package 📤 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
38 changes: 19 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.6.0
hooks:
- id: check-yaml
exclude: mkdocs.yml
- id: check-added-large-files
args: ["--maxkb=250"]
- repo: https://github.com/Yelp/detect-secrets
rev: v0.14.3
rev: v1.5.0
hooks:
- id: detect-secrets
exclude: Pipfile.lock
- repo: https://github.com/PyCQA/isort
rev: 5.7.0
stages: [commit]
exclude: 'poetry\.lock|tests/jwt\.txt'
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.5.7"
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 3.8.4
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies: [tokenize-rt==3.2.0, pydantic>=1.0.0]

additional_dependencies:
[tokenize-rt==3.2.0, pydantic>=2.0.0, types-protobuf]
pass_filenames: false
- repo: https://github.com/crate-ci/typos
rev: v1.23.6
hooks:
- id: typos
- repo: local
hooks:
- id: tests
name: tests
stages: [push]
language: python
entry: pytest
language: system
entry: poetry run pytest
types: [python]
pass_filenames: false
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{
"python.formatting.provider": "black",
"cSpell.words": [
"calcinfo",
"calctypes",
"casci",
"httpx",
"molden",
"nalpha",
"natoms",
"nbeta",
"orba",
"orbb",
"Protobuf",
"qcel",
"qcelemental",
"qcio",
"TCPB",
"Tera",
"terachem",
Expand Down
18 changes: 18 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [unreleased]

### Added

- GitHub workflows for basic code quality.
- `release.py` script.

### Changed

- Changed build system from `flit` to `poetry` to standardize with other `MtzGroup` lab projects.
- 🚨 Updated minimum Python version from `3.7` -> `3.9`.
- Updated package dependencies.
- Updated devops system. Removed `black`, `isort`, `flake8` in favor of latest version of `ruff`.
- Updated documentation dependencies.

### Removed

- Checks for `bond_order` in the tests as this value is no longer returned by default by the TeraChem server.
- `TCFEKeywords` checks. Just passing arguments to the `TCFEClient.compute()` function now.

## [0.13.2]

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions docs/clients.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# clients.py

::: tcpb.clients:TCFrontEndClient
::: tcpb.clients.TCFrontEndClient

::: tcpb.clients:TCProtobufClient
::: tcpb.clients.TCProtobufClient
4 changes: 2 additions & 2 deletions docs/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ All keywords for controlling the [TCFrontEndClient][tcpb.clients.TCFrontEndClien
| `scratch_messy` | `bool` | If set to `True` the scratch directory will not be cleaned up (deleted) after a compute job | `False` |
| `uploads_messy` | `bool` | If set to `True` the uploaded files will not be cleaned up (deleted) after a compute job | `False` |
| `native_files` | `list[str]` | If used in conjunction with `AtomicInput.protocols = {"native_files": "all"}` only the filenames listed in the array will be returned. This is useful when only a single file is needed and the overhead of downloading potentially many files is large. | `None` |
| `c0` or `ca0 and cb0` | `binary` | TeraChem's c0 file(s) to be put on the server as an initial guess wavefunction. If included, they will be automatically uploaded and the `AtomicInput` will be modified to pass the `guess` keyword to TeraChem referencing the wave function files. See [FrontEnd Guess Reuse](../Examples/frontend_guess_reuse) for an example | `None` |
| `c0` or `ca0 and cb0` | `binary` | TeraChem's c0 file(s) to be put on the server as an initial guess wavefunction. If included, they will be automatically uploaded and the `AtomicInput` will be modified to pass the `guess` keyword to TeraChem referencing the wave function files. See [FrontEnd Guess Reuse](Examples/frontend_guess_reuse.md) for an example | `None` |

::: tcpb.config:TCFEKeywords
::: tcpb.config.TCFEKeywords
29 changes: 12 additions & 17 deletions examples/basic_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Basic energy calculation
import sys

from qcelemental.models import AtomicInput, Molecule
from qcio import ProgramInput, Structure

from tcpb import TCProtobufClient as TCPBClient

Expand All @@ -11,23 +11,18 @@
exit(1)


# Water system
atoms = ["O", "H", "H"]
geom = [0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, 0.0, 1.5] # in bohr

molecule = Molecule(symbols=atoms, geometry=geom)
atomic_input = AtomicInput(
molecule=molecule,
model={
"method": "b3lyp",
"basis": "6-31g",
},
driver="energy",
protocols={"wavefunction": "all"},
structure = Structure(
symbols=["O", "H", "H"],
geometry=[[0.0, 0.0, 0.0], [0.0, 1.5, 0.0], [0.0, 0.0, 1.5]],
)
prog_inp = ProgramInput(
calctype="energy", # type: ignore
structure=structure,
model={"method": "b3lyp", "basis": "6-31g"}, # type: ignore
)

with TCPBClient(host=sys.argv[1], port=int(sys.argv[2])) as client:
result = client.compute(atomic_input)
prog_output = client.compute(prog_inp)

print(result)
print(result.return_result)
print(prog_output)
print(prog_output.results.energy)
39 changes: 14 additions & 25 deletions examples/frontend_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,32 @@
# Basic energy calculation
import sys

from qcelemental.models import AtomicInput, Molecule
from qcio import ProgramInput, Structure

from tcpb import TCFrontEndClient
from tcpb.config import TCFEKeywords, settings

if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} host port")
exit(1)


# Water system
atoms = ["O", "H", "H"]
geom = [0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, 0.0, 1.5] # in bohr

molecule = Molecule(symbols=atoms, geometry=geom)
atomic_input = AtomicInput(
molecule=molecule,
model={
"method": "b3lyp",
"basis": "6-31g",
},
driver="energy",
structure = Structure(
symbols=["O", "H", "H"], geometry=[0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, 0.0, 1.5]
)
atomic_input = ProgramInput(
structure=structure,
model={"method": "b3lyp", "basis": "6-31g"}, # type: ignore
calctype="energy", # type: ignore
keywords={"restricted": False},
# TCFrontEndClient can collect stdout
# TCFrontEnd can also collect native_files produced by TeraCHem from the computation
protocols={"wavefunction": "all", "stdout": True, "native_files": "all"},
# TCFrontEndClient will delete scratch unless scratch_messy: True
extras={settings.tcfe_keywords: {TCFEKeywords.scratch_messy: False}},
)

with TCFrontEndClient(host=sys.argv[1], port=int(sys.argv[2])) as client:
result = client.compute(atomic_input)
# Collect stdout and native files
prog_output = client.compute(atomic_input, collect_stdout=True, collect_files=True)

# NOTE: Addition of stdout field possible with TCFrontendClient
print(result.stdout)
print(result)
print(result.return_result)
print(result.extras["job_extras"])
print(prog_output.stdout)
print(prog_output)
print(prog_output.return_result)
# native_files will contain orb1a/b files in binary form
print(result.native_files.keys())
print(prog_output.files.keys())
41 changes: 14 additions & 27 deletions examples/guess_reuse_tcfe.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
#!/usr/bin/env python
# Basic energy calculation
import sys
from pprint import pprint

from qcelemental.models import AtomicInput, Molecule
from qcio import CalcType, ProgramInput, Structure

from tcpb import TCFrontEndClient
from tcpb.config import settings

if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} host port")
exit(1)


# Water system
atoms = ["O", "H", "H"]
geom = [0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, 0.0, 1.5] # in bohr

molecule = Molecule(symbols=atoms, geometry=geom)
atomic_input = AtomicInput(
molecule=molecule,
model={
"method": "b3lyp",
"basis": "6-31g",
},
struct = Structure(
symbols=["O", "H", "H"], geometry=[0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, 0.0, 1.5]
)
prog_inp = ProgramInput(
calctype=CalcType.energy,
structure=struct,
model={"method": "b3lyp", "basis": "6-31g"}, # type: ignore
# Density matrix purification appears buggy and messes with initial guess
keywords={"purify": "no"},
driver="energy",
protocols={"wavefunction": "all", "stdout": True, "native_files": "all"},
)

with TCFrontEndClient(host=sys.argv[1], port=int(sys.argv[2])) as client:
result = client.compute(atomic_input)
prog_output = client.compute(prog_inp, collect_files=True)

atomic_input_2 = atomic_input.dict()
atomic_input_2["extras"] = {settings.tcfe_keywords: {}}
atomic_input_2["extras"][settings.tcfe_keywords]["c0"] = result.native_files["c0"]
atomic_input_2["extras"][settings.tcfe_keywords]["uploads_messy"] = False
prog_inp_2 = prog_inp.model_dump()
prog_inp_2["files"]["c0"] = prog_output.results.files["scr/c0"]

with TCFrontEndClient(host=sys.argv[1], port=int(sys.argv[2])) as client:
result2 = client.compute(AtomicInput(**atomic_input_2))

print(result)
print(result.return_result)
prog_output_2 = client.compute(ProgramInput(**prog_inp_2))

pprint(result.stdout)
pprint(result2.stdout)
print(prog_output.stdout)
print(prog_output_2.stdout)
Loading
Loading