Skip to content

New directory for community contributions #2167

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

Closed
wants to merge 1 commit into from
Closed
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
93 changes: 57 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,122 +2,144 @@

We want to make contributing to BoTorch is as easy and transparent as possible.


## Development installation

To get the development installation with all the necessary dependencies for
linting, testing, and building the documentation, run the following:

```bash
git clone https://github.com/pytorch/botorch.git
cd botorch
pip install -e .[dev]
pip install -e ".[dev]"
```


## Our Development Process

#### Code Style

BoTorch uses [ufmt](https://github.com/omnilib/ufmt) to enforce consistent
code formatting (based on [black](https://github.com/ambv/black)) and
import sorting (based on [µsort](https://github.com/facebook/usort))
across the code base. Install via `pip install ufmt`, and
auto-format and auto-sort by running
BoTorch uses [ufmt](https://github.com/omnilib/ufmt) to enforce consistent code
formatting (based on [black](https://github.com/ambv/black)) and import sorting
(based on [µsort](https://github.com/facebook/usort)) across the code base.
Install via `pip install ufmt`, and auto-format and auto-sort by running

```bash
ufmt format .
```
from the repository root.

from the repository root.

#### Flake8 linting

BoTorch uses `flake8` for linting. To run the linter locally, install
`flake8` via `pip install flake8`, and then run
BoTorch uses `flake8` for linting. To run the linter locally, install `flake8`
via `pip install flake8`, and then run

```bash
flake8 .
```
from the repository root.

from the repository root.

#### Docstring formatting

BoTorch uses [Google-style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) docstrings.
To make sure documentation is rendered correctly, we require that every
`__init__` function contains an `Args:` block. We use the `flake8-docstrings`
plugin to check this - install via `pip install flake8-docstrings` and
run `flake8` as above to check.

BoTorch uses
[Google-style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)
docstrings. To make sure documentation is rendered correctly, we require that
every `__init__` function contains an `Args:` block. We use the
`flake8-docstrings` plugin to check this - install via
`pip install flake8-docstrings` and run `flake8` as above to check.

#### Type Hints

BoTorch is fully typed using python 3.9+
[type hints](https://www.python.org/dev/peps/pep-0484/).
We expect any contributions to also use proper type annotations. While we
currently do not enforce full consistency of these in our continuous integration
test, you should strive to type check your code locally. For this we recommend
using [pyre](https://pyre-check.org/).

[type hints](https://www.python.org/dev/peps/pep-0484/). We expect any
contributions to also use proper type annotations. While we currently do not
enforce full consistency of these in our continuous integration test, you should
strive to type check your code locally. For this we recommend using
[pyre](https://pyre-check.org/).

#### Unit Tests

To run the unit tests, you can either use `pytest` (if installed):

```bash
pytest -ra
```

or python's `unittest`:

```bash
python -m unittest
```

To get coverage reports we recommend using the `pytest-cov` plugin:

```bash
pytest -ra --cov=. --cov-report term-missing
```


#### Documentation

BoTorch's website is also open source, and is part of this very repository (the
code can be found in the [website](/website/) folder).
It is built using [Docusaurus](https://docusaurus.io/), and consists of three
main elements:
code can be found in the [website](/website/) folder). It is built using
[Docusaurus](https://docusaurus.io/), and consists of three main elements:

1. The documentation in Docusaurus itself (if you know Markdown, you can
already contribute!). This lives in the [docs](/docs/).
1. The documentation in Docusaurus itself (if you know Markdown, you can already
contribute!). This lives in the [docs](/docs/).
2. The API reference, auto-generated from the docstrings using
[Sphinx](http://www.sphinx-doc.org), and embedded into the Docusaurus website.
The sphinx .rst source files for this live in [sphinx/source](/sphinx/source/).
[Sphinx](http://www.sphinx-doc.org), and embedded into the Docusaurus
website. The sphinx .rst source files for this live in
[sphinx/source](/sphinx/source/).
3. The Jupyter notebook tutorials, parsed by `nbconvert`, and embedded into the
Docusaurus website. These live in [tutorials](/tutorials/).

To build the documentation you will need [Node](https://nodejs.org/en/) >= 8.x
and [Yarn](https://yarnpkg.com/en/) >= 1.5.

The following command will both build the docs and serve the site locally:

```bash
./scripts/build_docs.sh
```

## Pull Requests

We actively welcome your pull requests.

1. Fork the repo and create your branch from `main`.
2. If you have added code that should be tested, add unit tests.
In other words, add unit tests.
2. If you have added code that should be tested, add unit tests. In other words,
add unit tests.
3. If you have changed APIs, update the documentation. Make sure the
documentation builds.
4. Ensure the test suite passes.
5. Make sure your code passes both `ufmt` and `flake8` formatting checks.
6. If you haven't already, complete the Contributor License Agreement ("CLA").

### Community Contributions (Beta)

In order to reduce the maintenance work required from our team, while continuing
to support contributions from BoTorch community, we're trying out a revised
support model for community contributions.

Contributing new methods & notebooks: We're asking our contributors to add these
under `botorch_community` & `community_notebooks`, and their help in maintaining
added code going forward. The maintenance expectations include keeping the code
up to date against any deprecations in BoTorch and dependencies, fixing any
breakages, and help in responding to issues & discussions from other users. We
will notify the contributors of any maintenance needs and expect a resolution of
the issues within 90 days. We may decide to move any contribution into core
BoTorch at a future date, at which point our team will assume all maintenance
responsibility.

Fixes & improvements to core BoTorch: We appreciate the support from our
community and continue welcoming PRs with bug-fixes & improvements to core
BoTorch.

## Contributor License Agreement ("CLA")

In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects. You can
complete your CLA here: <https://code.facebook.com/cla>


## Issues

We use GitHub issues to track public bugs. Please ensure your description is
Expand All @@ -127,7 +149,6 @@ Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.


## License

By contributing to BoTorch, you agree that your contributions will be licensed
Expand Down
5 changes: 5 additions & 0 deletions botorch_community/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This directory contains methods contributed by the BoTorch community.

Each file should list the GitHub handle of its contributors, who may be asked
for help in maintaining & updating the code against future versions for BoTorch
and dependencies.
4 changes: 4 additions & 0 deletions botorch_community/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
Empty file.
Empty file.
43 changes: 43 additions & 0 deletions botorch_community/models/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

"""
This file contains a simple modification of SingleTaskGP as an example.

References:

.. [Example2024paper]
S. Cakmak, D.Eriksson, M. Balandat, E. Bakshy. Example Paper.
Proceedings of the Example Conference, 2024.

Contributor: saitcakmak
"""

from typing import Optional

from botorch.models.gp_regression import SingleTaskGP
from gpytorch.kernels import RBFKernel, ScaleKernel
from torch import Tensor


class ExampleModel(SingleTaskGP):
def __init__(
self, train_X: Tensor, train_Y: Tensor, train_Yvar: Optional[Tensor] = None
) -> None:
r"""Initialize the example model from [Example2024paper]_.

Args:
train_X: A `batch_shape x n x d` tensor of training features.
train_Y: A `batch_shape x n x m` tensor of training observations.
train_Yvar: An optional `batch_shape x n x m` tensor of observed
measurement noise.
"""
super().__init__(
train_X=train_X,
train_Y=train_Y,
train_Yvar=train_Yvar,
covar_module=ScaleKernel(RBFKernel(ard_num_dims=train_X.shape[-1])),
)
10 changes: 10 additions & 0 deletions community_notebooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This directory contains notebooks contributed by the BoTorch community.

Unlike BoTorch tutorials, the notebooks here are not subject to strict runtime
limitations. As such, they can be used to demonstrate a method using longer
running experiments or for comparing multiple methods.

Each notebook should include a timestamp of last update, as well as the version
of BoTorch that was used during execution. Each notebook should also list the
GitHub handle of its contributors, who may be asked for help in maintaining &
updating the notebook against future versions for BoTorch and dependencies.
93 changes: 93 additions & 0 deletions community_notebooks/example.ipynb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions test_community/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

"""
Unit tests for BoTorch community contributions.
"""
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions test_community/models/test_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import torch
from botorch.utils.testing import BotorchTestCase
from botorch_community.models.example import ExampleModel
from gpytorch.kernels import RBFKernel, ScaleKernel


class TestExampleModel(BotorchTestCase):
def test_example_gp(self) -> None:
model = ExampleModel(
train_X=torch.rand(2, 2),
train_Y=torch.rand(2, 1),
)
self.assertIsInstance(model.covar_module, ScaleKernel)
self.assertIsInstance(model.covar_module.base_kernel, RBFKernel)