Skip to content

Commit ac5c3ea

Browse files
Add examples section with matplotlib dependency (#756)
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
1 parent 4c758e6 commit ac5c3ea

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

examples/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Autograd examples
2+
3+
## Usage instructions
4+
5+
Some of the examples require additional dependencies beyond Autograd and its
6+
core dependencies. These are set up under the `examples` dependency group. To
7+
install them, navigate to the root directory of where you cloned Autograd and
8+
run
9+
```sh
10+
pip install --group examples
11+
```
12+
from the command line. Note that dependency groups are a recent feature so you
13+
may need to upgrade `pip` with
14+
```sh
15+
pip install --upgrade pip
16+
```
17+
18+
Having installed the additional dependencies, you may navigate to the `examples`
19+
subdirectory and run any of the Python scripts. For example:
20+
```sh
21+
python3 tanh.py
22+
```
23+
Some of the examples print to the terminal and others open pop-up windows for
24+
plots.

noxfile.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ def check(session):
2828
@nox.session(name="tests", tags=["tests"])
2929
def run_tests(session):
3030
"""Run unit tests and generate a coverage report"""
31+
pyproject = nox.project.load_toml("pyproject.toml")
32+
session.install(*nox.project.dependency_groups(pyproject, "test"))
3133
# SciPy doesn't have wheels on PyPy
3234
if platform.python_implementation() == "PyPy":
33-
session.install("-e", ".[test]", silent=False)
35+
session.install("-e.", silent=False)
3436
else:
35-
session.install("-e", ".[test,scipy]", silent=False)
37+
session.install("-e", ".[scipy]", silent=False)
3638
session.run("pytest", "--cov=autograd", "--cov-report=xml", "--cov-append", *session.posargs)
3739

3840

@@ -46,7 +48,9 @@ def ruff(session):
4648
@nox.session(name="nightly-tests", tags=["tests"])
4749
def run_nightly_tests(session):
4850
"""Run tests against nightly versions of dependencies"""
49-
session.install("-e", ".[test]", silent=False)
51+
session.install("-e.", silent=False)
52+
pyproject = nox.project.load_toml("pyproject.toml")
53+
session.install(*nox.project.dependency_groups(pyproject, "test"))
5054
# SciPy doesn't have wheels on PyPy
5155
if platform.python_implementation() == "PyPy":
5256
session.install(

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ Source = "https://github.com/HIPS/autograd"
5555
scipy = [
5656
"scipy",
5757
]
58+
59+
[dependency-groups]
5860
test = [
5961
"pytest",
6062
"pytest-cov",
6163
"pytest-xdist",
6264
]
65+
examples = ["matplotlib"]
6366

6467
[tool.coverage.run]
6568
source = ["autograd"]

0 commit comments

Comments
 (0)