9
9
from dvclive import Live
10
10
from dvclive .env import DVC_EXP_BASELINE_REV , DVC_EXP_NAME , DVC_ROOT
11
11
from dvclive .plots import Image , Metric
12
- from dvclive .studio import _adapt_image , get_dvc_studio_config
12
+ from dvclive .studio import _adapt_image , get_dvc_studio_config , post_to_studio
13
13
14
14
15
15
def get_studio_call (event_type , exp_name , ** kwargs ):
@@ -46,7 +46,9 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post):
46
46
)
47
47
48
48
live .log_metric ("foo" , 1 )
49
- live .next_step ()
49
+ live .step = 0
50
+ live .make_summary ()
51
+ post_to_studio (live , "data" )
50
52
51
53
mocked_post .assert_called_with (
52
54
"https://0.0.0.0/api/live" ,
@@ -58,8 +60,10 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post):
58
60
),
59
61
)
60
62
63
+ live .step += 1
61
64
live .log_metric ("foo" , 2 )
62
- live .next_step ()
65
+ live .make_summary ()
66
+ post_to_studio (live , "data" )
63
67
64
68
mocked_post .assert_called_with (
65
69
"https://0.0.0.0/api/live" ,
@@ -72,7 +76,8 @@ def test_post_to_studio(tmp_dir, mocked_dvc_repo, mocked_studio_post):
72
76
)
73
77
74
78
mocked_post .reset_mock ()
75
- live .end ()
79
+ live .save_dvc_exp ()
80
+ post_to_studio (live , "done" )
76
81
77
82
mocked_post .assert_called_with (
78
83
"https://0.0.0.0/api/live" ,
@@ -118,11 +123,15 @@ def test_post_to_studio_failed_data_request(
118
123
error_response .status_code = 400
119
124
mocker .patch ("requests.post" , return_value = error_response )
120
125
live .log_metric ("foo" , 1 )
121
- live .next_step ()
126
+ live .step = 0
127
+ live .make_summary ()
128
+ post_to_studio (live , "data" )
122
129
123
130
mocked_post = mocker .patch ("requests.post" , return_value = valid_response )
131
+ live .step += 1
124
132
live .log_metric ("foo" , 2 )
125
- live .next_step ()
133
+ live .make_summary ()
134
+ post_to_studio (live , "data" )
126
135
mocked_post .assert_called_with (
127
136
"https://0.0.0.0/api/live" ,
128
137
** get_studio_call (
@@ -154,6 +163,7 @@ def test_post_to_studio_failed_start_request(
154
163
live .next_step ()
155
164
156
165
assert mocked_post .call_count == 1
166
+ assert live ._studio_events_to_skip == {"start" , "data" , "done" }
157
167
158
168
159
169
def test_post_to_studio_done_only_once (tmp_dir , mocked_dvc_repo , mocked_studio_post ):
@@ -210,7 +220,9 @@ def test_post_to_studio_dvc_studio_config(
210
220
211
221
with Live () as live :
212
222
live .log_metric ("foo" , 1 )
213
- live .next_step ()
223
+ live .step = 0
224
+ live .make_summary ()
225
+ post_to_studio (live , "data" )
214
226
215
227
assert mocked_post .call_args .kwargs ["headers" ]["Authorization" ] == "token token"
216
228
@@ -231,7 +243,9 @@ def test_post_to_studio_skip_if_no_token(
231
243
232
244
with Live () as live :
233
245
live .log_metric ("foo" , 1 )
234
- live .next_step ()
246
+ live .step = 0
247
+ live .make_summary ()
248
+ post_to_studio (live , "data" )
235
249
236
250
assert mocked_post .call_count == 0
237
251
@@ -241,7 +255,8 @@ def test_post_to_studio_shorten_names(tmp_dir, mocked_dvc_repo, mocked_studio_po
241
255
242
256
live = Live ()
243
257
live .log_metric ("eval/loss" , 1 )
244
- live .next_step ()
258
+ live .make_summary ()
259
+ post_to_studio (live , "data" )
245
260
246
261
plots_path = Path (live .plots_dir )
247
262
loss_path = (plots_path / Metric .subfolder / "eval/loss.tsv" ).as_posix ()
@@ -269,7 +284,9 @@ def test_post_to_studio_inside_dvc_exp(
269
284
270
285
with Live () as live :
271
286
live .log_metric ("foo" , 1 )
272
- live .next_step ()
287
+ live .step = 0
288
+ live .make_summary ()
289
+ post_to_studio (live , "data" )
273
290
274
291
call_types = [call .kwargs ["json" ]["type" ] for call in mocked_post .call_args_list ]
275
292
assert "start" not in call_types
@@ -287,7 +304,8 @@ def test_post_to_studio_inside_subdir(
287
304
288
305
live = Live ()
289
306
live .log_metric ("foo" , 1 )
290
- live .next_step ()
307
+ live .make_summary ()
308
+ post_to_studio (live , "data" )
291
309
292
310
foo_path = (Path (live .plots_dir ) / Metric .subfolder / "foo.tsv" ).as_posix ()
293
311
@@ -317,7 +335,8 @@ def test_post_to_studio_inside_subdir_dvc_exp(
317
335
318
336
live = Live ()
319
337
live .log_metric ("foo" , 1 )
320
- live .next_step ()
338
+ live .make_summary ()
339
+ post_to_studio (live , "data" )
321
340
322
341
foo_path = (Path (live .plots_dir ) / Metric .subfolder / "foo.tsv" ).as_posix ()
323
342
@@ -370,7 +389,9 @@ def test_post_to_studio_images(tmp_dir, mocked_dvc_repo, mocked_studio_post):
370
389
371
390
live = Live ()
372
391
live .log_image ("foo.png" , ImagePIL .new ("RGB" , (10 , 10 ), (0 , 0 , 0 )))
373
- live .next_step ()
392
+ live .step = 0
393
+ live .make_summary ()
394
+ post_to_studio (live , "data" )
374
395
375
396
foo_path = (Path (live .plots_dir ) / Image .subfolder / "foo.png" ).as_posix ()
376
397
@@ -409,11 +430,13 @@ def test_post_to_studio_name(tmp_dir, mocked_dvc_repo, mocked_studio_post):
409
430
410
431
411
432
def test_post_to_studio_if_done_skipped (tmp_dir , mocked_dvc_repo , mocked_studio_post ):
412
- live = Live ()
413
- live ._studio_events_to_skip .add ("start" )
414
- live ._studio_events_to_skip .add ("done" )
415
- live .log_metric ("foo" , 1 )
416
- live .end ()
433
+ with Live () as live :
434
+ live ._studio_events_to_skip .add ("start" )
435
+ live ._studio_events_to_skip .add ("done" )
436
+ live .log_metric ("foo" , 1 )
437
+ live .step = 0
438
+ live .make_summary ()
439
+ post_to_studio (live , "data" )
417
440
418
441
mocked_post , _ = mocked_studio_post
419
442
call_types = [call .kwargs ["json" ]["type" ] for call in mocked_post .call_args_list ]
@@ -439,8 +462,9 @@ def test_post_to_studio_no_repo(tmp_dir, monkeypatch, mocked_studio_post):
439
462
)
440
463
441
464
live .log_metric ("foo" , 1 )
465
+ live .make_summary ()
466
+ post_to_studio (live , "data" )
442
467
443
- live .next_step ()
444
468
mocked_post .assert_called_with (
445
469
"https://0.0.0.0/api/live" ,
446
470
** get_studio_call (
@@ -452,9 +476,11 @@ def test_post_to_studio_no_repo(tmp_dir, monkeypatch, mocked_studio_post):
452
476
),
453
477
)
454
478
479
+ live .step += 1
455
480
live .log_metric ("foo" , 2 )
481
+ live .make_summary ()
482
+ post_to_studio (live , "data" )
456
483
457
- live .next_step ()
458
484
mocked_post .assert_called_with (
459
485
"https://0.0.0.0/api/live" ,
460
486
** get_studio_call (
@@ -466,7 +492,7 @@ def test_post_to_studio_no_repo(tmp_dir, monkeypatch, mocked_studio_post):
466
492
),
467
493
)
468
494
469
- live . end ( )
495
+ post_to_studio ( live , "done" )
470
496
mocked_post .assert_called_with (
471
497
"https://0.0.0.0/api/live" ,
472
498
** get_studio_call ("done" , baseline_sha = "0" * 40 , exp_name = live ._exp_name ),
@@ -485,7 +511,9 @@ def test_post_to_studio_skip_if_no_repo_url(
485
511
486
512
with Live () as live :
487
513
live .log_metric ("foo" , 1 )
488
- live .next_step ()
514
+ live .step = 0
515
+ live .make_summary ()
516
+ post_to_studio (live , "data" )
489
517
490
518
assert mocked_post .call_count == 0
491
519
@@ -503,7 +531,8 @@ def test_post_to_studio_repeat_step(tmp_dir, mocked_dvc_repo, mocked_studio_post
503
531
live .step = 0
504
532
live .log_metric ("foo" , 1 )
505
533
live .log_metric ("bar" , 0.1 )
506
- live .sync ()
534
+ live .make_summary ()
535
+ post_to_studio (live , "data" )
507
536
508
537
mocked_post .assert_called_with (
509
538
"https://0.0.0.0/api/live" ,
@@ -521,7 +550,8 @@ def test_post_to_studio_repeat_step(tmp_dir, mocked_dvc_repo, mocked_studio_post
521
550
live .log_metric ("foo" , 2 )
522
551
live .log_metric ("foo" , 3 )
523
552
live .log_metric ("bar" , 0.2 )
524
- live .sync ()
553
+ live .make_summary ()
554
+ post_to_studio (live , "data" )
525
555
526
556
mocked_post .assert_called_with (
527
557
"https://0.0.0.0/api/live" ,
0 commit comments