@@ -27,18 +27,14 @@ by the code in stages executes by `dvc exp run` (see `cmd` field of `dvc.yaml`).
27
27
> Note that for non-Python code, the alternative is to write a
28
28
> ` .dvc/tmp/DVC_CHECKPOINT ` signal file.
29
29
30
- ## Exceptions
31
-
32
- None
33
-
34
- ## Example: Mark a checkpoint every 100 iterations
30
+ ## Example: Every 100th iteration
35
31
36
32
Let's consider the following ` dvc.yaml ` file:
37
33
38
34
``` yaml
39
35
stages :
40
36
foo :
41
- cmd : python src/mystage .py
37
+ cmd : python iterate .py
42
38
params :
43
39
- start
44
40
outs :
@@ -49,35 +45,31 @@ stages:
49
45
> See ` dvc params` for information on stage parameters.
50
46
51
47
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 :
54
50
55
51
` ` ` py
56
52
import os
57
- from ruamel.yaml import YAML
58
53
from dvc.api import make_checkpoint
59
54
60
55
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
65
57
66
58
while True:
67
59
try:
68
60
if os.path.exists(output_file):
69
- with open(output_file, "r") as fobj :
61
+ with open(output_file, "r") as fd :
70
62
try:
71
- data = fobj.read()
72
- iter_ = int(data) + 1
63
+ iter_ = int(fd.read()) + 1
73
64
except ValueError:
74
65
iter_ = start
75
66
else:
76
67
iter_ = start
77
68
78
- with open(output_file, "w") as fobj :
69
+ with open(output_file, "w") as fd :
79
70
fobj.write(f"{iter_}")
80
71
81
72
if iter_ % 100 == 0:
82
73
make_checkpoint()
74
+ # ...
83
75
` ` `
0 commit comments