Skip to content

Commit

Permalink
Enable automatic versioning via setuptools_scm (#2111)
Browse files Browse the repository at this point in the history
* Enable automatic versioning via setuptools_scm

Based on cornellius-gp/linear_operator#2

* Resolve RTD warnings from example notebooks
  • Loading branch information
gpleiss committed Aug 30, 2022
1 parent ed9d662 commit fd99baf
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install setuptools_scm setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m setuptools_scm
python setup.py sdist bdist_wheel
twine upload dist/*
Expand All @@ -44,11 +45,13 @@ jobs:
- name: Install dependencies
run: |
conda install -y anaconda-client conda-build
pip install setuptools_scm
- name: Build and publish
run: |
conda config --set anaconda_upload yes
conda config --append channels pytorch
/usr/share/miniconda/bin/anaconda login --username ${{ secrets.CONDA_USERNAME }} --password ${{ secrets.CONDA_PASSWORD }}
python -m setuptools_scm
cd .conda
conda build .
/usr/share/miniconda/bin/anaconda logout
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@ Temporary Items
# Data files that might be downloaded
**/*.tar.gz
**/*.txt

# version file (auto-generated by setuptools_scm)
gpytorch/version.py
9 changes: 8 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
# Required
version: 2

build:
os: "ubuntu-22.04"
tools:
python: "3.8"
jobs:
pre_build:
- python -m setuptools_scm

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/source/conf.py
Expand All @@ -16,7 +24,6 @@ sphinx:

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.8
install:
- requirements: requirements.txt
- requirements: docs/requirements.txt
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setuptools_scm
nbformat
ipython
ipykernel
Expand Down
12 changes: 7 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ def read(*names, **kwargs):


def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
if version_match:
try:
with io.open(os.path.join(os.path.dirname(__file__), *file_paths), encoding="utf8") as fp:
version_file = fp.read()
version_match = re.search(r"^__version__ = version = ['\"]([^'\"]*)['\"]", version_file, re.M)
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
except Exception as e:
raise RuntimeError("Unable to find version string:\n", e)


sys.path.append(os.path.abspath(os.path.join(__file__, "..", "..", "..")))
Expand Down Expand Up @@ -63,7 +65,7 @@ def find_version(*file_paths):
author = "Cornellius GP"

# The short X.Y version
version = find_version("gpytorch", "__init__.py")
version = find_version("..", "..", "gpytorch", "version.py")
# The full version, including alpha/beta/rc tags
release = version

Expand Down
13 changes: 7 additions & 6 deletions examples/00_Basic_Usage/Metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"\n",
"We'll be modeling the function\n",
"\n",
"$$\n",
"\\begin{align}\n",
"y &= \\sin(2\\pi x) + \\epsilon \\\\\n",
" y &= \\sin(2\\pi x) + \\epsilon \\\\\n",
" \\epsilon &\\sim \\mathcal{N}(0, 0.04) \n",
"\\end{align}"
"\\end{align}\n",
"$$\n"
]
},
{
Expand Down Expand Up @@ -441,7 +443,7 @@
"hash": "d4d1e4263499bec80672ea0156c357c1ee493ec2b1c70f0acce89fc37c4a6abe"
},
"kernelspec": {
"display_name": "Python 3.8.12 ('base')",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -455,9 +457,8 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
},
"orig_nbformat": 4
"version": "3.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"\n",
"In this notebook, we're going to demonstrate one way of dealing with uncertainty in our training data. Let's say that we're collecting training data that models the following function.\n",
"\n",
"$$\n",
"\\begin{align}\n",
"y &= \\sin(2\\pi x) + \\epsilon \\\\\n",
" \\epsilon &\\sim \\mathcal{N}(0, 0.2) \n",
"\\end{align}\n",
"$$\n",
"\n",
"However, now assume that we're a bit uncertain about our features. In particular, we're going to assume that every `x_i` value is not a point but a distribution instead. E.g.\n",
"\n",
Expand Down Expand Up @@ -780,9 +782,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.7.4 64-bit ('base': conda)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python37464bitbaseconda52eab690427c4f7ea56588deee120c46"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -794,7 +796,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.8.0"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions examples/01_Exact_GPs/Simple_GP_Regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"\n",
"In this notebook, we demonstrate many of the design features of GPyTorch using the simplest example, training an RBF kernel Gaussian process on a simple function. We'll be modeling the function\n",
"\n",
"$$\n",
"\\begin{align}\n",
"y &= \\sin(2\\pi x) + \\epsilon \\\\\n",
" \\epsilon &\\sim \\mathcal{N}(0, 0.04) \n",
"\\end{align}\n",
"$$\n",
"\n",
"with 100 training examples, and testing on 51 test examples.\n",
"\n",
Expand Down Expand Up @@ -361,7 +363,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -375,7 +377,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.8.0"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
"\n",
"In this notebook, we demonstrate many of the design features of GPyTorch using the simplest example, training an RBF kernel Gaussian process on a simple function. We'll be modeling the function\n",
"\n",
"$$\n",
"\\begin{align}\n",
" y &= \\sin(2\\pi x) + \\epsilon \\\\ \n",
" \\epsilon &\\sim \\mathcal{N}(0, 0.2) \n",
"\\end{align}\n",
"$$\n",
"\n",
"with 11 training examples, and testing on 51 test examples."
]
Expand Down Expand Up @@ -326,7 +328,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -340,7 +342,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.0"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@
"The **predictive log likelihood** is an alternative to the variational ELBO that was proposed in [Jankowiak et al., 2020](https://arxiv.org/abs/1910.07123).\n",
"It typically produces predictive variances than the `gpytorch.mlls.VariationalELBO` objective.\n",
"\n",
"$$\n",
"\\begin{align}\n",
"\\mathcal{L}_\\text{PLL} &= \\mathbb{E}_{p_\\text{data}( y, \\mathbf x )} \\left[ \\log p( y \\! \\mid \\! \\mathbf x) \\right] - \\beta \\: \\text{KL} \\left[ q( \\mathbf u) \\Vert p( \\mathbf u) \\right] \\\\ \n",
" &\\approx \\sum_{i=1}^N \\log \\mathbb{E}_{q(\\mathbf u)} \\left[ \\int p( y_i \\! \\mid \\! f_i) p(f_i \\! \\mid \\! \\mathbf u) \\: d f_i \\right] - \\beta \\: \\text{KL} \\left[ q( \\mathbf u) \\Vert p( \\mathbf u) \\right] \n",
"\\end{align}\n",
"$$\n",
"\n",
"Note that this objective is *very similar* to the variational ELBO.\n",
"The only difference is that the $\\log$ occurs *outside* the expectation $\\mathbb E_{q(\\mathbf u)}$.\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"\n",
"In this notebook, we're going to demonstrate one way of dealing with uncertainty in our training data. Let's say that we're collecting training data that models the following function.\n",
"\n",
"$$\n",
"\\begin{align}\n",
"y &= \\sin(2\\pi x) + \\epsilon \\\\\n",
" \\epsilon &\\sim \\mathcal{N}(0, 0.2) \n",
"\\end{align}\n",
"$$\n",
"\n",
"However, now assume that we're a bit uncertain about our features. In particular, we're going to assume that every `x_i` value is not a point but a distribution instead. E.g.\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
"## Introduction\n",
"In this notebook, we show how to train a GP regression model in GPyTorch of an unknown function given function value and derivative observations. We consider modeling the function:\n",
"\n",
"$$\n",
"\\begin{align}\n",
" y &= \\sin(2x) + cos(x) + \\epsilon \\\\\n",
" \\frac{dy}{dx} &= 2\\cos(2x) - \\sin(x) + \\epsilon \\\\ \n",
" \\epsilon &\\sim \\mathcal{N}(0, 0.5)\n",
"\\end{align}\n",
"$$\n",
"\n",
"using 50 value and derivative observations."
]
Expand Down
7 changes: 6 additions & 1 deletion gpytorch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ def sqrt_inv_matmul(input: Anysor, rhs: Tensor, lhs: Optional[Tensor] = None) ->
return linear_operator.sqrt_inv_matmul(input=input, rhs=rhs, lhs=lhs)


__version__ = "1.8.1"
# Read version number as written by setuptools_scm
try:
from gpytorch.version import version as __version__
except Exception: # pragma: no cover
__version__ = "Unknown" # pragma: no cover


__all__ = [
# Submodules
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = ["setuptools", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
local_scheme = "node-and-date"
write_to = "./gpytorch/version.py"
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[bdist_wheel]
universal=1

[pep8]
max-line-length = 120

Expand Down
32 changes: 22 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,38 @@
import io
import os
import re
import sys

from setuptools import find_packages, setup

REQUIRED_MAJOR = 3
REQUIRED_MINOR = 8

# Get version
def read(*names, **kwargs):
with io.open(os.path.join(os.path.dirname(__file__), *names), encoding=kwargs.get("encoding", "utf8")) as fp:
return fp.read()
# Check for python version
if sys.version_info < (REQUIRED_MAJOR, REQUIRED_MINOR):
error = (
"Your version of python ({major}.{minor}) is too old. You need python >= {required_major}.{required_minor}."
).format(
major=sys.version_info.major,
minor=sys.version_info.minor,
required_minor=REQUIRED_MINOR,
required_major=REQUIRED_MAJOR,
)
sys.exit(error)


# Get version
def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
if version_match:
try:
with io.open(os.path.join(os.path.dirname(__file__), *file_paths), encoding="utf8") as fp:
version_file = fp.read()
version_match = re.search(r"^__version__ = version = ['\"]([^'\"]*)['\"]", version_file, re.M)
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
except Exception:
return None


readme = open("README.md").read()
version = find_version("gpytorch", "__init__.py")


torch_min = "1.11"
Expand All @@ -43,7 +55,7 @@ def find_version(*file_paths):
# Run the setup
setup(
name="gpytorch",
version=version,
version=find_version("gpytorch", "version.py"),
description="An implementation of Gaussian Processes in Pytorch",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

2 comments on commit fd99baf

@ankushaggarwal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this commit missing version.py file? I cannot seem to find it.

@gpleiss
Copy link
Member Author

@gpleiss gpleiss commented on fd99baf Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ankushaggarwal the version.py file is autogenerated locally. It is generated when you run python -m setuptools_scm.

Please sign in to comment.