Skip to content

Commit dbde026

Browse files
authored
fix: resume experiment will reset to running (#185)
Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent 5670eb8 commit dbde026

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

alphatrion/experiment/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ def _start(
217217
# to avoid confusion.
218218
if exp_obj and exp_obj.status != Status.COMPLETED:
219219
self._id = exp_obj.uuid
220+
# reset to running status.
221+
self._runtime._metadb.update_experiment(
222+
experiment_id=self._id,
223+
status=Status.RUNNING,
224+
)
220225
elif exp_obj and exp_obj.status == Status.COMPLETED:
221226
raise RuntimeError(
222227
f"Experiment with name '{name}' already exists and is completed. \

tests/unit/experiment/test_experimant.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ async def test_experiment_with_done_with_cancel():
178178

179179
assert global_runtime().metadb.get_run(run_id=run_id).status == Status.CANCELLED
180180

181+
async with CraftExperiment.start(name="first-experiment") as exp:
182+
run = exp.run(lambda: asyncio.sleep(2))
183+
exp_obj = global_runtime().metadb.get_experiment(experiment_id=exp.id)
184+
# will be reset to running
185+
assert exp_obj.status == Status.RUNNING
186+
187+
# finally should be completed after context exit
188+
exp_obj = global_runtime().metadb.get_experiment(experiment_id=exp.id)
189+
assert exp_obj.status == Status.COMPLETED
190+
181191

182192
@pytest.mark.asyncio
183193
async def test_experiment_with_wait():

0 commit comments

Comments
 (0)