mirror of
https://github.com/wassname/ray.git
synced 2026-08-02 13:01:01 +08:00
[Tune] Pbt Function API (#9958)
* adding function convnet example * add unit test * update test * update example * wip * move error from experiment to tune * wip * Fix checkpoint deletion * updating code * adding smoke test * updating pbt guide * formatting * fix build * add best checkpoint analysis util * update test * add comments * remove class api * fix example * add setup and teardown to tests * formatting * Update python/ray/tune/tests/test_trial_scheduler_pbt.py Co-authored-by: Kai Fricke <kai@anyscale.com> Co-authored-by: Richard Liaw <rliaw@berkeley.edu>
This commit is contained in:
co-authored by
Kai Fricke
Richard Liaw
parent
fba5906ce3
commit
f87a4aa45d
@@ -1,6 +1,8 @@
|
||||
# coding: utf-8
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -128,6 +130,35 @@ class CheckpointManagerTest(unittest.TestCase):
|
||||
self.assertEqual(newest, checkpoints[1])
|
||||
self.assertEqual(checkpoint_manager.best_checkpoints(), [])
|
||||
|
||||
def testSameCheckpoint(self):
|
||||
checkpoint_manager = CheckpointManager(
|
||||
1, "i", delete_fn=lambda c: os.remove(c.value))
|
||||
|
||||
tmpfiles = []
|
||||
for i in range(3):
|
||||
tmpfile = tempfile.mktemp()
|
||||
with open(tmpfile, "wt") as fp:
|
||||
fp.write("")
|
||||
tmpfiles.append(tmpfile)
|
||||
|
||||
checkpoints = [
|
||||
Checkpoint(Checkpoint.PERSISTENT, tmpfiles[0],
|
||||
self.mock_result(5)),
|
||||
Checkpoint(Checkpoint.PERSISTENT, tmpfiles[1],
|
||||
self.mock_result(10)),
|
||||
Checkpoint(Checkpoint.PERSISTENT, tmpfiles[2],
|
||||
self.mock_result(0)),
|
||||
Checkpoint(Checkpoint.PERSISTENT, tmpfiles[1],
|
||||
self.mock_result(20))
|
||||
]
|
||||
for checkpoint in checkpoints:
|
||||
checkpoint_manager.on_checkpoint(checkpoint)
|
||||
self.assertTrue(os.path.exists(checkpoint.value))
|
||||
|
||||
for tmpfile in tmpfiles:
|
||||
if os.path.exists(tmpfile):
|
||||
os.remove(tmpfile)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import pytest
|
||||
|
||||
Reference in New Issue
Block a user