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

test_utils to make it easier for downstream implementations to check correctness #1825

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

st--
Copy link
Member

@st-- st-- commented Mar 24, 2022

PR type: new feature

Summary

A common use-case of GPflow is to implement your own down-stream kernels / models / likelihoods / etc.
We should make it easy for such users to check their implementation for basic correctness (e.g. kernel is pos-def on test inputs) and adherence to interfaces (accepts tensors of appropriate shapes & returns the right things).

Proposed changes

  • Provide a test_utils submodule with basic checks for interfaces.

Minimal working example

import gpflow
from gpflow.test_utils import test_kernel

class MyKernel(gpflow.kernels.Kernel):
    # ...

test_kernel(MyKernel())

Release notes

Fully backwards compatible: yes

PR checklist

  • New features: code is well-documented
    • detailed docstrings (API documentation)
    • notebook examples (usage demonstration)
  • The bug case / new feature is covered by unit tests
  • Code has type annotations
  • Build checks
    • I ran the black+isort formatter (make format)
    • I locally tested that the tests pass (make check-all)
  • Release management
    • RELEASE.md updated with entry for this change
    • New contributors: I've added myself to CONTRIBUTORS.md

assert np.linalg.eigvals(A).min() > -tol, "test for positive semi definite matrix"


def test_kernel(kernel: Kernel, X: np.ndarray, X2: np.ndarray):
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we provide default arguments for X and X2?

@st-- st-- marked this pull request as ready for review March 25, 2022 12:13
@st-- st-- requested a review from jesnie March 25, 2022 12:13
@codecov
Copy link

codecov bot commented Mar 25, 2022

Codecov Report

Merging #1825 (a0274a1) into develop (1a77914) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop    #1825   +/-   ##
========================================
  Coverage    98.00%   98.01%           
========================================
  Files          107      108    +1     
  Lines         5761     5785   +24     
========================================
+ Hits          5646     5670   +24     
  Misses         115      115           
Impacted Files Coverage Δ
gpflow/__init__.py 100.00% <ø> (ø)
gpflow/test_utils.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a77914...a0274a1. Read the comment docs.

Copy link
Member

@jesnie jesnie left a comment

Choose a reason for hiding this comment

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

LGTM

gpflow/test_utils.py Outdated Show resolved Hide resolved
Co-authored-by: Jesper Nielsen <44195043+jesnie@users.noreply.github.com>
RELEASE.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants