Skip to content

Commit 7dd0d50

Browse files
committedFeb 17, 2021
ref: update make_checkpoint example
1 parent 22af4cf commit 7dd0d50

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed
 

‎content/docs/api-reference/make_checkpoint.md

+9-17
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@ by the code in stages executes by `dvc exp run` (see `cmd` field of `dvc.yaml`).
2727
> Note that for non-Python code, the alternative is to write a
2828
> `.dvc/tmp/DVC_CHECKPOINT` signal file.
2929
30-
## Exceptions
31-
32-
None
33-
34-
## Example: Mark a checkpoint every 100 iterations
30+
## Example: Every 100th iteration
3531

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

3834
```yaml
3935
stages:
4036
foo:
41-
cmd: python src/mystage.py
37+
cmd: python iterate.py
4238
params:
4339
- start
4440
outs:
@@ -49,35 +45,31 @@ stages:
4945
> See `dvc params` for information on stage parameters.
5046

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

5551
```py
5652
import os
57-
from ruamel.yaml import YAML
5853
from dvc.api import make_checkpoint
5954
6055
output_file = "int.txt"
61-
62-
with open("params.yaml") as fobj:
63-
params = yaml.load(fobj)
64-
start = params.get("start", 0)
56+
start = _load_param('start') # Load start from params.yaml
6557
6658
while True:
6759
try:
6860
if os.path.exists(output_file):
69-
with open(output_file, "r") as fobj:
61+
with open(output_file, "r") as fd:
7062
try:
71-
data = fobj.read()
72-
iter_ = int(data) + 1
63+
iter_ = int(fd.read()) + 1
7364
except ValueError:
7465
iter_ = start
7566
else:
7667
iter_ = start
7768
78-
with open(output_file, "w") as fobj:
69+
with open(output_file, "w") as fd:
7970
fobj.write(f"{iter_}")
8071
8172
if iter_ % 100 == 0:
8273
make_checkpoint()
74+
# ...
8375
```

0 commit comments

Comments
 (0)