Skip to content

Commit

Permalink
Updating testing and building infrastructure (#184)
Browse files Browse the repository at this point in the history
* don't run news check on bot PR

* applying updated pre-commit

* switching to nox for testing

* removing setup.py

* news

* version for news check

* copyright in docs

* font on rtds
  • Loading branch information
dfm authored Sep 27, 2023
1 parent 1b7798a commit dbb6bc2
Show file tree
Hide file tree
Showing 59 changed files with 404 additions and 807 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/news.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ name: News

on:
pull_request:
paths-ignore:
- ".pre-commit-config.yaml"

jobs:
news:
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'pre-commit-ci[bot]' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -15,11 +14,10 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install -U pip
# FIXME: using github towncrier until next release
python -m pip install https://github.com/twisted/towncrier/archive/6b1527b6bf2cbb293ef411ac4f300bd50a5c98ae.zip
python -m pip install towncrier
- name: Check for news
run: python -m towncrier check --compare-with origin/main
95 changes: 23 additions & 72 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11"]
nox-session: ["test"]
include:
- python-version: "3.10"
nox-session: "doctest"

steps:
- name: Checkout
Expand All @@ -27,68 +31,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U coveralls coverage[toml] tox tox-gh-actions
python -m pip install nox
- name: Run tests
run: python -m tox
- name: Combine and upload coverage
run: |
python -m coverage combine
python -m coverage xml -i
python -m coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: ${{ matrix.python-version }}

coverage:
needs: tests
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Finish coverage collection
run: |
python -m pip install -U pip
python -m pip install -U coveralls
python -m coveralls --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

doctest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install tox
- name: Lint the code
run: python -m tox -e doctest

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install tox
- name: Lint the code
run: python -m tox -e lint
python -m nox --non-interactive --error-on-missing-interpreter \
--session ${{ matrix.nox-session }} --python ${{ matrix.python-version }}
build:
runs-on: ubuntu-latest
Expand All @@ -99,27 +46,31 @@ jobs:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: "3.9"
- name: Build sdist and wheel
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U build
python -m build .
python -m pip install -U build twine
- name: Build the distribution
run: python -m build .
- name: Check the distribution
run: python -m twine check --strict dist/*
- uses: actions/upload-artifact@v3
with:
path: dist/*

upload_pypi:
needs: [tests, lint, build]
publish:
environment:
name: pypi
url: https://pypi.org/p/tinygp
permissions:
id-token: write
needs: [tests, build]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.pypi_password }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*_version.py
.coverage
.nox
.tox
.coverage*
/*.ipynb
Expand Down
23 changes: 7 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,22 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: "v4.4.0"
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude_types: [json, binary]
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort
additional_dependencies: [toml]
exclude: docs/tutorials
- repo: https://github.com/psf/black
rev: "23.7.0"
rev: "23.9.1"
hooks:
- id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.291"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/kynan/nbstripout
rev: "0.6.1"
hooks:
- id: nbstripout
exclude: docs/benchmarks.ipynb
- repo: https://github.com/hadialqattan/pycln
rev: "v2.2.2"
hooks:
- id: pycln
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.5.1"
hooks:
- id: mypy
8 changes: 7 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
version: 2

build:
os: ubuntu-20.04
apt_packages:
- fonts-liberation
tools:
python: "3.10"

python:
version: 3.8
install:
- method: pip
path: .
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Tracker](https://github.com/dfm/tinygp/issues).
## How to test the project

```bash
python -m pip install tox
python -m tox
python -m pip install nox
python -m nox -s test -p 3.10
```

## How to submit changes
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright 2021, 2022 Simons Foundation, Inc.
Copyright 2021, 2022, 2023 Simons Foundation, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 3 additions & 9 deletions docs/benchmarks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@
" return gp.log_likelihood(y)\n",
"\n",
"\n",
"hodlr_loglike = partial(\n",
" george_loglike, solver=george.solvers.HODLRSolver, tol=0.5\n",
")\n",
"hodlr_loglike = partial(george_loglike, solver=george.solvers.HODLRSolver, tol=0.5)\n",
"\n",
"\n",
"def celerite_loglike(x, y):\n",
Expand Down Expand Up @@ -340,9 +338,7 @@
" lw=1,\n",
" label=\"george (approx)\",\n",
")\n",
"plt.loglog(\n",
" ns, celerite_time, \"^--\", color=\"k\", lw=0.75, label=\"celerite2 (struct)\"\n",
")\n",
"plt.loglog(ns, celerite_time, \"^--\", color=\"k\", lw=0.75, label=\"celerite2 (struct)\")\n",
"\n",
"plt.loglog(\n",
" ns[: len(cpu_time)],\n",
Expand All @@ -360,9 +356,7 @@
" lw=2,\n",
" label=\"tinygp (exact; GPU)\",\n",
")\n",
"plt.loglog(\n",
" ns, quasisep_time, \"^--\", color=\"C2\", lw=2, label=\"tinygp (struct; CPU)\"\n",
")\n",
"plt.loglog(ns, quasisep_time, \"^--\", color=\"C2\", lw=2, label=\"tinygp (struct; CPU)\")\n",
"\n",
"plt.legend(fontsize=10)\n",
"plt.xlabel(\"number of data points\")\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import tinygp

extensions = [
Expand All @@ -22,7 +20,7 @@

# General information about the project.
project = "tinygp"
copyright = tinygp.__copyright__
copyright = "2021, 2022, 2023 Simons Foundation, Inc."
version = tinygp.__version__
release = tinygp.__version__

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GitHub Repository <https://github.com/dfm/tinygp>

## Authors & license

Copyright 2021, 2022 Simons Foundation, Inc.
Copyright 2021, 2022, 2023 Simons Foundation, Inc.

Built by [Dan Foreman-Mackey](https://github.com/dfm) and contributors (see [the
contribution graph](https://github.com/dfm/tinygp/graphs/contributors) for the
Expand Down
4 changes: 2 additions & 2 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ If you installed from source, you can run the unit tests. From the root of the
source directory, run:

```bash
python -m pip install tox
python -m tox
python -m pip install nox
python -m nox -s test -p 3.10
```
29 changes: 8 additions & 21 deletions docs/tutorials/derivative.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@
" -np.sin(X) + 2 * np.cos(2 * X),\n",
" )\n",
")\n",
"flag = np.concatenate(\n",
" (np.zeros(len(X), dtype=bool), np.ones(len(X), dtype=bool))\n",
")\n",
"flag = np.concatenate((np.zeros(len(X), dtype=bool), np.ones(len(X), dtype=bool)))\n",
"X = np.concatenate((X, X))\n",
"y += 0.1 * np.random.default_rng(1234).normal(size=len(y))\n",
"\n",
Expand Down Expand Up @@ -215,9 +213,7 @@
" kernel = DerivativeKernel(base_kernel)\n",
"\n",
" # Note that we're passing in (X, flag) as the input coordinates.\n",
" return tinygp.GaussianProcess(\n",
" kernel, (X, flag), diag=jnp.exp(params[\"log_diag\"])\n",
" )\n",
" return tinygp.GaussianProcess(kernel, (X, flag), diag=jnp.exp(params[\"log_diag\"]))\n",
"\n",
"\n",
"@jax.jit\n",
Expand Down Expand Up @@ -337,12 +333,7 @@
" b2 = self.coeff_deriv[label2]\n",
"\n",
" # Construct the matrix element\n",
" return (\n",
" a1 * a2 * K\n",
" + a1 * b2 * dK_dx2\n",
" + b1 * a2 * dK_dx1\n",
" + b1 * b2 * d2K_dx1dx2\n",
" )"
" return a1 * a2 * K + a1 * b2 * dK_dx2 + b1 * a2 * dK_dx1 + b1 * b2 * d2K_dx1dx2"
]
},
{
Expand All @@ -363,9 +354,9 @@
"metadata": {},
"outputs": [],
"source": [
"base_kernel = tinygp.kernels.ExpSquared(\n",
" scale=1.5\n",
") * tinygp.kernels.ExpSineSquared(scale=2.5, gamma=0.5)\n",
"base_kernel = tinygp.kernels.ExpSquared(scale=1.5) * tinygp.kernels.ExpSineSquared(\n",
" scale=2.5, gamma=0.5\n",
")\n",
"kernel = LatentKernel(base_kernel, [1.0, 0.5], [-0.1, 0.3])\n",
"\n",
"random = np.random.default_rng(5678)\n",
Expand Down Expand Up @@ -424,12 +415,8 @@
" ) * tinygp.kernels.ExpSineSquared(\n",
" scale=jnp.exp(params[\"log_period\"]), gamma=params[\"gamma\"]\n",
" )\n",
" kernel = LatentKernel(\n",
" base_kernel, params[\"coeff_prim\"], params[\"coeff_deriv\"]\n",
" )\n",
" return tinygp.GaussianProcess(\n",
" kernel, X_obs, diag=jnp.exp(params[\"log_diag\"])\n",
" )\n",
" kernel = LatentKernel(base_kernel, params[\"coeff_prim\"], params[\"coeff_deriv\"])\n",
" return tinygp.GaussianProcess(kernel, X_obs, diag=jnp.exp(params[\"log_diag\"]))\n",
"\n",
"\n",
"@jax.jit\n",
Expand Down
8 changes: 2 additions & 6 deletions docs/tutorials/geometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,15 @@
"random = np.random.default_rng(456)\n",
"X_obs = random.normal(size=(100, 3))\n",
"X_obs /= np.sqrt(np.sum(X_obs**2, axis=1))[:, None]\n",
"theta_obs = np.arctan2(\n",
" X_obs[:, 2], np.sqrt(X_obs[:, 0] ** 2 + X_obs[:, 1] ** 2)\n",
")\n",
"theta_obs = np.arctan2(X_obs[:, 2], np.sqrt(X_obs[:, 0] ** 2 + X_obs[:, 1] ** 2))\n",
"phi_obs = np.arctan2(X_obs[:, 1], X_obs[:, 0])\n",
"\n",
"# Our kernel is parameterized by a length scale in **radians**\n",
"ell = 0.5\n",
"kernel = 1.5 * kernels.Matern52(ell, distance=GreatCircleDistance())\n",
"\n",
"# Sample a simulated dataset\n",
"gp = GaussianProcess(\n",
" kernel, np.concatenate((X_grid, X_obs), axis=0), diag=0.01\n",
")\n",
"gp = GaussianProcess(kernel, np.concatenate((X_grid, X_obs), axis=0), diag=0.01)\n",
"y_samp = gp.sample(jax.random.PRNGKey(10))\n",
"y_grid = y_samp[: len(X_grid)]\n",
"y_obs = y_samp[len(X_grid) :] + 0.5 * random.normal(size=len(X_obs))\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/tutorials/ipython_kernel_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# mypy: ignore-errors

c.InlineBackend.rc = {}
c.InlineBackend.rc = {} # noqa
Loading

0 comments on commit dbb6bc2

Please sign in to comment.