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

ref: exp cmd index, make_checkpoint() fn #2199

Merged
merged 22 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bebbf34
ref: add exp cmd and make_checkpoint() fn
jorgeorpinel Feb 16, 2021
ecfd6b9
ref: add auto link to exp[eriments] cmds, beter api ref
jorgeorpinel Feb 16, 2021
8f5cf67
ref: 2.0 warning in exp
jorgeorpinel Feb 16, 2021
f7cb618
ref: remove examples from exp index
jorgeorpinel Feb 16, 2021
19a6593
ref: reorder exp list in index and intro note
jorgeorpinel Feb 16, 2021
c811458
ref: fix exp index title and link to guide from intro
jorgeorpinel Feb 16, 2021
22af4cf
ref: gc --all-experiments
jorgeorpinel Feb 16, 2021
597161c
ref: update make_checkpoint example
jorgeorpinel Feb 17, 2021
3bfe780
ref: check make_checkpoint example
jorgeorpinel Feb 17, 2021
d90ac09
Merge branch 'guide/experiments' into ref/experiments
jorgeorpinel Feb 17, 2021
7bbd5b1
term: review "experiment" links/tooltips
jorgeorpinel Feb 17, 2021
e7c2584
ref: exapnd make_checkpoints example, use exp tooltips
jorgeorpinel Feb 17, 2021
a5c9aa8
ref: finish initial make_checkpoint() example
jorgeorpinel Feb 17, 2021
bb82194
Add dvc experiments to linked-terms
rogermparent Feb 17, 2021
ca9d31f
ref: complete exp index Desc
jorgeorpinel Feb 17, 2021
e20490d
Merge branch 'ref/experiments' of github.com:iterative/dvc.org into r…
jorgeorpinel Feb 17, 2021
8e2e1cb
Merge branch 'master' into ref/experiments
jorgeorpinel Feb 21, 2021
3ec578d
ref: explain exp run --reset and exp apply in make_checkpoint()
jorgeorpinel Feb 21, 2021
5e81e22
ref: hyperparams -> params in exp index
jorgeorpinel Feb 21, 2021
c7b734c
Merge branch 'master' into ref/experiments
jorgeorpinel Feb 22, 2021
56bf275
Update content/docs/api-reference/make_checkpoint.md
jorgeorpinel Feb 22, 2021
bec199e
ref: mention exp run --reset in make_checkpoint ex.
jorgeorpinel Feb 21, 2021
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
2 changes: 2 additions & 0 deletions config/prismjs/dvc-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module.exports = [
'gc',
'freeze',
'fetch',
'exp',
'experiments',
jorgeorpinel marked this conversation as resolved.
Show resolved Hide resolved
'doctor',
jorgeorpinel marked this conversation as resolved.
Show resolved Hide resolved
'diff',
'destroy',
Expand Down
83 changes: 83 additions & 0 deletions content/docs/api-reference/make_checkpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# dvc.api.make_checkpoint()

Make an
[in-code checkpoint](/doc/user-guide/experiment-management#checkpoints-in-source-code).

```py
def make_checkpoint()
```

#### Usage:

```py
from dvc.api import make_checkpoint

while True:
# ... write a stage output
make_checkpoint()
```

## Description

To track successive steps in a longer
[experiment](/doc/user-guide/experiment-management), you can write your code so
it registers checkpoints with DVC during runtime. This function should be called
by the code in stages executes by `dvc exp run` (see `cmd` field of `dvc.yaml`).

> Note that for non-Python code, the alternative is to write a
> `.dvc/tmp/DVC_CHECKPOINT` signal file.

## Exceptions

None
jorgeorpinel marked this conversation as resolved.
Show resolved Hide resolved

## Example: Mark a checkpoint every 100 iterations

Let's consider the following `dvc.yaml` file:

```yaml
stages:
Copy link
Contributor Author

@jorgeorpinel jorgeorpinel Feb 17, 2021

Choose a reason for hiding this comment

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

Adapted from https://github.com/iterative/dvc/wiki/Experiments#checkpoint-experiments for now. May need a less hypothetical example?

Copy link
Contributor Author

@jorgeorpinel jorgeorpinel Feb 23, 2021

Choose a reason for hiding this comment

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

I'll improve the examples in a future iteration (maybe once @dberenbaum's #2195 is merged).

foo:
cmd: python src/mystage.py
params:
- start
outs:
- int.txt:
checkpoint: true
```

> See `dvc params` for information on stage parameters.

Here's the example code that the stage above will execute. It continuously
increments an integer value in the `int.txt` file, starting at the `start`
param. It makes a checkpoint with `dvc exp` every time the value adds 100:

```py
import os
from ruamel.yaml import YAML
from dvc.api import make_checkpoint

output_file = "int.txt"

with open("params.yaml") as fobj:
params = yaml.load(fobj)
start = params.get("start", 0)

while True:
try:
if os.path.exists(output_file):
with open(output_file, "r") as fobj:
try:
data = fobj.read()
iter_ = int(data) + 1
except ValueError:
iter_ = start
else:
iter_ = start

with open(output_file, "w") as fobj:
fobj.write(f"{iter_}")

if iter_ % 100 == 0:
make_checkpoint()
```
39 changes: 39 additions & 0 deletions content/docs/command-reference/exp/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# dvc experiments

> Aliased to `dvc exp`.

A set of commands to generate and manage experiments:
[run](/doc/command-reference/exp/run), [show](/doc/command-reference/exp/show),
[diff](/doc/command-reference/exp/diff),
[apply](/doc/command-reference/exp/apply),
[branch](/doc/command-reference/exp/branch),
[list](/doc/command-reference/exp/list),
[resume](/doc/command-reference/exp/resume),
[push](/doc/command-reference/exp/list),
[pull](/doc/command-reference/exp/pull), and
[gc](/doc/command-reference/exp/gc).

## Synopsis

```usage
usage: dvc experiments [-h] [-q | -v]
{show,apply,diff,run,resume,res,gc,branch,list,push,pull} ...

positional arguments:
COMMAND
show Print experiments.
apply Apply the changes from an experiment to your workspace.
diff Show changes between experiments in the DVC repository.
run Reproduce complete or partial experiment pipelines.
resume (res) Resume checkpoint experiments.
gc Garbage collect unneeded experiments.
branch Promote an experiment to a Git branch.
list List local and remote experiments.
push Push a local experiment to a Git remote.
pull Pull an experiment from a Git remote.
```

## Description

> Note that DVC assumes that experiments are deterministic (see **Avoiding
> unexpected behavior** in `dvc run`).
9 changes: 9 additions & 0 deletions content/docs/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@
"label": "doctor",
"slug": "doctor"
},
{
"label": "experiments",
"slug": "exp",
"source": "exp/index.md"
},
{
"label": "fetch",
"slug": "fetch",
Expand Down Expand Up @@ -399,6 +404,10 @@
{
"slug": "read",
"label": "read()"
},
{
"slug": "make_checkpoint",
"label": "make_checkpoint()"
}
]
},
Expand Down