Skip to content

Commit b51fae6

Browse files
committed
Uploading finished run service
1 parent 6a96cf1 commit b51fae6

File tree

5 files changed

+181
-15
lines changed

5 files changed

+181
-15
lines changed

src/MLFlowClient.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export
6363

6464
include("services/run.jl")
6565
export
66-
createrun
67-
66+
createrun,
67+
deleterun,
68+
restorerun,
69+
getrun
6870
end

src/services/experiment.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,14 @@ Get metadata for an experiment. This method works on deleted experiments.
4949
- `experiment_id`: ID of the associated experiment.
5050
5151
# Returns
52-
An object of type [`Experiment`](@ref).
52+
An instance of type [`Experiment`](@ref).
5353
"""
5454
function getexperiment(instance::MLFlow, experiment_id::String)
5555
try
5656
arguments = (:experiment_id => experiment_id,)
5757
result = mlfget(instance, "experiments/get"; arguments...)
5858
return result["experiment"] |> Experiment
5959
catch e
60-
if isa(e, HTTP.ExceptionRequest.StatusError) && e.status == 404
61-
return missing
62-
end
6360
throw(e)
6461
end
6562
end
@@ -80,7 +77,7 @@ deleted experiments share the same name, the API will return one of them.
8077
- `experiment_name`: Name of the associated experiment.
8178
8279
# Returns
83-
An object of type [`Experiment`](@ref).
80+
An instance of type [`Experiment`](@ref).
8481
"""
8582
function getexperimentbyname(instance::MLFlow, experiment_name::String)
8683
try
@@ -163,9 +160,9 @@ function restoreexperiment(instance::MLFlow, experiment_id::String)
163160
end
164161
end
165162
restoreexperiment(instance::MLFlow, experiment_id::Integer) =
166-
deleteexperiment(instance, string(experiment_id))
163+
restoreexperiment(instance, string(experiment_id))
167164
restoreexperiment(instance::MLFlow, experiment::Experiment) =
168-
deleteexperiment(instance, experiment.experiment_id)
165+
restoreexperiment(instance, experiment.experiment_id)
169166

170167
"""
171168
updateexperiment(instance::MLFlow, experiment_id::String, new_name::String)

src/services/run.jl

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,90 @@ function createrun(instance::MLFlow, experiment_id::String;
3131
throw(e)
3232
end
3333
end
34+
createrun(instance::MLFlow, experiment_id::Integer;
35+
run_name::Union{String, Missing}=missing,
36+
start_time::Union{Integer, Missing}=missing,
37+
tags::Union{Dict{<:Any}, Array{<:Any}}=[]) =
38+
createrun(instance, string(experiment_id); run_name=run_name,
39+
start_time=start_time, tags=tags)
40+
createrun(instance::MLFlow, experiment::Experiment;
41+
run_name::Union{String, Missing}=missing,
42+
start_time::Union{Integer, Missing}=missing,
43+
tags::Union{Dict{<:Any}, Array{<:Any}}=[]) =
44+
createrun(instance, string(experiment.experiment_id); run_name=run_name,
45+
start_time=start_time, tags=tags)
46+
47+
"""
48+
deleterun(instance::MLFlow, run_id::String)
49+
deleterun(instance::MLFlow, run::Run)
50+
51+
Mark a run for deletion.
52+
53+
# Arguments
54+
- `instance`: [`MLFlow`](@ref) configuration.
55+
- `run_id`: ID of the run to delete.
56+
57+
# Returns
58+
59+
`true` if successful. Otherwise, raises exception.
60+
"""
61+
function deleterun(instance::MLFlow, run_id::String)
62+
endpoint = "runs/delete"
63+
try
64+
mlfpost(instance, endpoint; run_id=run_id)
65+
return true
66+
catch e
67+
throw(e)
68+
end
69+
end
70+
deleterun(instance::MLFlow, run::Run) = deleterun(instance, run.info.run_id)
71+
72+
"""
73+
restorerun(instance::MLFlow, run_id::String)
74+
restorerun(instance::MLFlow, run::Run)
75+
76+
Restore a deleted run.
77+
78+
# Arguments
79+
- `instance`: [`MLFlow`](@ref) configuration.
80+
- `run_id`: ID of the run to restore.
81+
82+
# Returns
83+
84+
`true` if successful. Otherwise, raises exception.
85+
"""
86+
function restorerun(instance::MLFlow, run_id::String)
87+
endpoint = "runs/restore"
88+
try
89+
mlfpost(instance, endpoint; run_id=run_id)
90+
return true
91+
catch e
92+
throw(e)
93+
end
94+
end
95+
restorerun(instance::MLFlow, run::Run) = restorerun(instance, run.info.run_id)
96+
97+
"""
98+
getrun(instance::MLFlow, run_id::String)
99+
100+
Get metadata, metrics, params, and tags for a run. In the case where multiple
101+
metrics with the same key are logged for a run, return only the value with the
102+
latest timestamp. If there are multiple values with the latest timestamp,
103+
return the maximum of these values.
104+
105+
# Arguments
106+
- `instance`: [`MLFlow`](@ref) configuration.
107+
- `run_id`: ID of the run to fetch.
108+
109+
# Returns
110+
An instance of type [`Run`](@ref).
111+
"""
112+
function getrun(instance::MLFlow, run_id::String)
113+
try
114+
arguments = (:run_id => run_id,)
115+
result = mlfget(instance, "runs/get"; arguments...)
116+
return result["run"] |> Run
117+
catch e
118+
throw(e)
119+
end
120+
end

test/services/experiment.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ end
6767
@test isa(experiment, Experiment)
6868
end
6969

70-
@testset "not found" begin
71-
@test isa(getexperiment(mlf, 123), Missing)
72-
end
73-
7470
deleteexperiment(mlf, experiment_id)
7571
end
7672

@@ -119,6 +115,12 @@ end
119115
deleteexperiment(mlf, experiment_id)
120116
@test restoreexperiment(mlf, experiment)
121117
end
118+
119+
@testset "restore not found" begin
120+
@test_throws ErrorException restoreexperiment(mlf, 123)
121+
end
122+
123+
deleteexperiment(mlf, experiment_id)
122124
end
123125

124126
@testset verbose = true "update experiment" begin

test/services/run.jl

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,92 @@
11
@testset verbose = true "create run" begin
22
@ensuremlf
3-
43
experiment_id = createexperiment(mlf, UUIDs.uuid4() |> string)
54

65
@testset "base" begin
76
run = createrun(mlf, experiment_id)
87

9-
@test run isa Run
8+
@test run.info isa RunInfo
9+
@test run.data isa RunData
10+
@test run.inputs isa RunInputs
11+
@test run.info.experiment_id == experiment_id
12+
end
13+
14+
@testset "with experiment id as string" begin
15+
run = createrun(mlf, experiment_id)
16+
1017
@test run.info.experiment_id == experiment_id
1118
end
1219

20+
@testset "with experiment id as integer" begin
21+
run = createrun(mlf, parse(Int, experiment_id))
22+
23+
@test run.info.experiment_id == experiment_id
24+
end
25+
26+
@testset "with experiment" begin
27+
experiment = getexperiment(mlf, experiment_id)
28+
run = createrun(mlf, experiment)
29+
30+
@test run.info.experiment_id == experiment_id
31+
end
32+
33+
deleteexperiment(mlf, experiment_id)
34+
end
35+
36+
@testset verbose = true "delete run" begin
37+
@ensuremlf
38+
experiment_id = createexperiment(mlf, UUIDs.uuid4() |> string)
39+
run = createrun(mlf, experiment_id)
40+
41+
@testset "using string id" begin
42+
@test deleterun(mlf, run.info.run_id)
43+
restorerun(mlf, run.info.run_id)
44+
end
45+
46+
@testset "using Run" begin
47+
@test deleterun(mlf, run)
48+
restorerun(mlf, run.info.run_id)
49+
end
50+
51+
@testset "delete already deleted" begin
52+
deleterun(mlf, run.info.run_id)
53+
@test deleterun(mlf, run.info.run_id)
54+
end
55+
56+
deleteexperiment(mlf, experiment_id)
57+
end
58+
59+
@testset verbose = true "restore run" begin
60+
@ensuremlf
61+
experiment_id = createexperiment(mlf, UUIDs.uuid4() |> string)
62+
run = createrun(mlf, experiment_id)
63+
64+
@testset "using string id" begin
65+
deleterun(mlf, run.info.run_id)
66+
@test restorerun(mlf, run.info.run_id)
67+
end
68+
69+
@testset "using Run" begin
70+
deleterun(mlf, run)
71+
@test restorerun(mlf, run)
72+
end
73+
74+
deleteexperiment(mlf, experiment_id)
75+
end
76+
77+
@testset verbose = true "get run" begin
78+
@ensuremlf
79+
experiment_id = createexperiment(mlf, UUIDs.uuid4() |> string)
80+
run = createrun(mlf, experiment_id)
81+
82+
@testset "using id" begin
83+
retrieved_run = getrun(mlf, run.info.run_id)
84+
85+
@test retrieved_run.info isa RunInfo
86+
@test retrieved_run.data isa RunData
87+
@test retrieved_run.inputs isa RunInputs
88+
@test retrieved_run.info.experiment_id == experiment_id
89+
end
90+
1391
deleteexperiment(mlf, experiment_id)
1492
end

0 commit comments

Comments
 (0)