Skip to content

Commit

Permalink
Upgrade Python versions and add PyPI YAML file (#35)
Browse files Browse the repository at this point in the history
* Upgrade Python versions

* Remove roberto

* Fix missing comma

* Fix failing test due to numerical issue

One example is ACTUAL: array([0.51]) vs.  array([0.51000012])

* Remove setup.py to support pyproject.toml

* Add pyproject.toml

* Add pypi_release.yaml

* Add dynamic version to pyproject.toml

* Update the pytest configurations

* Update Python version to 3.13

* Update flake8 linting

* Update supported Python versions
  • Loading branch information
FanwangM authored Nov 2, 2024
1 parent 466c026 commit f9e9b44
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 224 deletions.
110 changes: 0 additions & 110 deletions .github/workflows/ci_rob.yml

This file was deleted.

13 changes: 6 additions & 7 deletions .github/workflows/ci_tox.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
name: CI Tox
on:
push:
branches: [master]
branches: [master, main]
pull_request:
branches: [master]
branches: [master, main]

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
# architecture: x64
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Testing with tox
run: tox

149 changes: 149 additions & 0 deletions .github/workflows/pypi_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: PyPI Release
on:
push:
tags:
# Trigger on version tags (e.g., v1.0.0)
- "v[0-9].[0-9].[0-9]*"
- "[0-9].[0-9].[0-9]*"
# Trigger on pre-release tags (e.g., v1.0.0-alpha.1)
- "v[0-9].[0-9].[0-9]*-*"
- "[0-9].[0-9].[0-9]*-*"
branches:
# Trigger on the main branch
- main
- master

env:
# package name
PYPI_NAME: qc-BFit

jobs:
build:
name: Build and Test Distribution
runs-on: ${{ matrix.os }}

strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
# python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.11"]
outputs:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build pytest pytest-cov codecov
python -m pip install -r requirements.txt
# python -m pip install -r requirements_dev.txt
- name: Test package
run: |
python -m pytest -c pyproject.toml --cov-config=.coveragerc --cov-report=xml --color=yes --cov=bfit bfit/test
- name: Build package
run: python -m build --sdist --wheel
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
# Name of the artifact to upload, unique for each OS and Python version
name: python-package-distributions
path: dist/
# Optional parameters for better artifact management
overwrite: false
include-hidden-files: false

publish-to-pypi:
name: Publish Python distribution to PyPI
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
environment:
name: PyPI-Release
url: https://pypi.org/p/${{ env.PYPI_NAME }}
permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

github-release:
name: Sign and Upload Python Distribution to GitHub Release
needs:
- build
- publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-none-pypi:
name: Publish Python distribution to TestPyPI (none)
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
environment:
name: TestPyPI
url: https://test.pypi.org/p/${{ env.PYPI_NAME }}
permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution with relaxed constraints
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
BFit
====
<a href='https://docs.python.org/3.6/'><img src='https://img.shields.io/badge/python-3.6-blue.svg'></a>
<a href='https://docs.python.org/3.7/'><img src='https://img.shields.io/badge/python-3.7-blue.svg'></a>
<a href='https://docs.python.org/3.8/'><img src='https://img.shields.io/badge/python-3.8-blue.svg'></a>
<a href='https://docs.python.org/3.9/'><img src='https://img.shields.io/badge/python-3.9-blue.svg'></a>
[![This project supports Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://python.org/downloads)
[![GitHub Actions CI Tox Status](https://github.com/theochem/bfit/actions/workflows/ci_tox.yml/badge.svg?branch=master)](https://github.com/theochem/bfit/actions/workflows/ci_tox.yml)
[![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/theochem/bfit/master?labpath=%2Fexamples%2F)
Expand All @@ -17,9 +14,9 @@ See the example [section](#kl-fpi-models-of-atomic-densities) down below or the
[Jupyter binder](https://mybinder.org/v2/gh/theochem/bfit/master?labpath=%2Fexamples%2)
or various files in the example [folder](https://github.com/theochem/BFit/tree/master/examples)
to see specific examples on how to fit using the different algorithms and objective
functions.
functions.
For further information about the api, please visit
[**BFit Documentation**](https://bfit.qcdevs.org/).
[**BFit Documentation**](https://bfit.qcdevs.org/).

The instructions to access the results of the fitted atomic densities using KL-FI method is
shown in the section below.
Expand Down Expand Up @@ -63,7 +60,7 @@ conda install -c theochem qc-bfit
pip install qc-bfit

# run tests to make sure BFit was installed properly
pytest -v .
pytest -v .
```


Expand All @@ -74,7 +71,7 @@ The features of this software are:

* Gaussian Basis set model:
* Construct s-type and p-type Gaussian functions,
* Compute Atomic Densities or Molecular Densities.
* Compute Atomic Densities or Molecular Densities.

* Fitting measures:
* Least-squares,
Expand All @@ -93,9 +90,9 @@ The features of this software are:
* Positive definite kinetic energy density.


Final Models of Fitting Atomic Densities
Final Models of Fitting Atomic Densities
------------------------------------------
The final model of fitting the atomic densities using the Kullback-Leibler (KL) divergence fixed point iteration method
The final model of fitting the atomic densities using the Kullback-Leibler (KL) divergence fixed point iteration method
can be accessed by opening the file `./bfit/data/kl_fpi_results.npz` with numpy.
Similarly, the results from optimizing KL with SLSQP method using `kl_fpi_results.npz`
as initial guesses can be accessed by opening the file `./bfit/data/kl_slsqp_results.npz` with numpy.
Expand Down Expand Up @@ -140,7 +137,7 @@ grid = ClenshawRadialGrid(4, num_core_pts=10000, num_diffuse_pts=899, extra_pts=
model = AtomicGaussianDensity(grid.points, num_s=num_s, num_p=num_p, normalize=True)
model_pts = model.evaluate(coefficients, exponents)

print("Numerical integral (spherically) of the model %f." %
print("Numerical integral (spherically) of the model %f." %
grid.integrate(model_pts * 4.0 * np.pi * grid.points**2.0)
)
```
Expand Down Expand Up @@ -193,5 +190,5 @@ print("Optimized coefficients are: ", result["coeffs"])
print("Optimized exponents are: ", result["exps"])
print("Final performance measures are: ", result["fun"][-1])
```
See the [example directory](examples/) for more examples or launch the interactive binder
See the [example directory](examples/) for more examples or launch the interactive binder
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/theochem/bfit/master?labpath=%2Fexamples%2F)
6 changes: 3 additions & 3 deletions bfit/test/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ def test_ls_fit_normalized_dens_normalized_1s_gaussian():
# opt. coeffs & expons
result = ls.run(np.array([0.1]), np.array([3.5]), True, True)
assert_almost_equal(cs0, result["coeffs"], decimal=8)
assert_almost_equal(es0, result["exps"], decimal=8)
assert_almost_equal(es0, result["exps"], decimal=6)
assert_almost_equal(0., result["fun"], decimal=8)
# opt. coeffs
result = ls.run(np.array([10.]), np.array([0.51]), True, False)
assert_almost_equal(cs0, result["coeffs"], decimal=8)
assert_almost_equal(es0, result["exps"], decimal=8)
assert_almost_equal(es0, result["exps"], decimal=6)
assert_almost_equal(0., result["fun"], decimal=8)
# model density is two normalized 1s Gaussian
model = AtomicGaussianDensity(grid.points, num_s=2, num_p=0, normalize=True)
Expand Down Expand Up @@ -692,7 +692,7 @@ def test_ls_fit_normalized_dens_normalized_2s_gaussian():
assert_almost_equal(0., result["fun"], decimal=8)
# opt. coeffs
result = ls.run(initial_cs, es0, True, False)
assert_almost_equal(cs0, result["coeffs"], decimal=8)
assert_almost_equal(cs0, result["coeffs"], decimal=6)
assert_almost_equal(es0, result["exps"], decimal=8)
assert_almost_equal(0., result["fun"], decimal=8)

Expand Down
Loading

0 comments on commit f9e9b44

Please sign in to comment.