@@ -15,12 +15,24 @@ An object of type [`MLFlowExperiment`](@ref).
15
15
"""
16
16
function createexperiment (mlf:: MLFlow ; name= missing , artifact_location= missing , tags= missing )
17
17
endpoint = " experiments/create"
18
+
18
19
if ismissing (name)
19
20
name = string (UUIDs. uuid4 ())
20
21
end
21
- result = mlfpost (mlf, endpoint; name= name, artifact_location= artifact_location, tags= tags)
22
- experiment_id = parse (Int, result[" experiment_id" ])
23
- getexperiment (mlf, experiment_id)
22
+
23
+ try
24
+ result = mlfpost (mlf, endpoint; name= name, artifact_location= artifact_location, tags= tags)
25
+ experiment_id = parse (Int, result[" experiment_id" ])
26
+ return getexperiment (mlf, experiment_id)
27
+ catch e
28
+ if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 400
29
+ error_code = JSON. parse (String (e. response. body))[" error_code" ]
30
+ if error_code == MLFLOW_ERROR_CODES. RESOURCE_ALREADY_EXISTS
31
+ error (" Experiment with name \" $name \" already exists" )
32
+ end
33
+ end
34
+ throw (e)
35
+ end
24
36
end
25
37
26
38
"""
@@ -38,7 +50,9 @@ An instance of type [`MLFlowExperiment`](@ref)
38
50
"""
39
51
function getexperiment (mlf:: MLFlow , experiment_id:: Integer )
40
52
try
41
- result = _getexperimentbyid (mlf, experiment_id)
53
+ endpoint = " experiments/get"
54
+ arguments = (:experiment_id => experiment_id,)
55
+ result = mlfget (mlf, endpoint; arguments... )[" experiment" ]
42
56
return MLFlowExperiment (result)
43
57
catch e
44
58
if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
@@ -62,7 +76,9 @@ An instance of type [`MLFlowExperiment`](@ref)
62
76
"""
63
77
function getexperiment (mlf:: MLFlow , experiment_name:: String )
64
78
try
65
- result = _getexperimentbyname (mlf, experiment_name)
79
+ endpoint = " experiments/get-by-name"
80
+ arguments = (:experiment_name => experiment_name,)
81
+ result = mlfget (mlf, endpoint; arguments... )[" experiment" ]
66
82
return MLFlowExperiment (result)
67
83
catch e
68
84
if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
@@ -71,16 +87,6 @@ function getexperiment(mlf::MLFlow, experiment_name::String)
71
87
throw (e)
72
88
end
73
89
end
74
- function _getexperimentbyid (mlf:: MLFlow , experiment_id:: Integer )
75
- endpoint = " experiments/get"
76
- arguments = (:experiment_id => experiment_id,)
77
- mlfget (mlf, endpoint; arguments... )[" experiment" ]
78
- end
79
- function _getexperimentbyname (mlf:: MLFlow , experiment_name:: String )
80
- endpoint = " experiments/get-by-name"
81
- arguments = (:experiment_name => experiment_name,)
82
- mlfget (mlf, endpoint; arguments... )[" experiment" ]
83
- end
84
90
85
91
"""
86
92
getorcreateexperiment(mlf::MLFlow, experiment_name::String; artifact_location=missing, tags=missing)
@@ -98,11 +104,12 @@ An instance of type [`MLFlowExperiment`](@ref)
98
104
99
105
"""
100
106
function getorcreateexperiment (mlf:: MLFlow , experiment_name:: String ; artifact_location= missing , tags= missing )
101
- exp = getexperiment (mlf, experiment_name)
102
- if ismissing (exp)
103
- exp = createexperiment (mlf, name= experiment_name, artifact_location= artifact_location, tags= tags)
107
+ experiment = getexperiment (mlf, experiment_name)
108
+
109
+ if ismissing (experiment)
110
+ return createexperiment (mlf, name= experiment_name, artifact_location= artifact_location, tags= tags)
104
111
end
105
- exp
112
+ return experiment
106
113
end
107
114
108
115
"""
@@ -122,14 +129,14 @@ function deleteexperiment(mlf::MLFlow, experiment_id::Integer)
122
129
endpoint = " experiments/delete"
123
130
try
124
131
mlfpost (mlf, endpoint; experiment_id= experiment_id)
132
+ return true
125
133
catch e
126
134
if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
127
135
# experiment already deleted
128
136
return true
129
137
end
130
138
throw (e)
131
139
end
132
- true
133
140
end
134
141
135
142
"""
@@ -164,14 +171,16 @@ function restoreexperiment(mlf::MLFlow, experiment_id::Integer)
164
171
endpoint = " experiments/restore"
165
172
try
166
173
mlfpost (mlf, endpoint; experiment_id= experiment_id)
174
+ return true
167
175
catch e
168
176
if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
169
- # experiment already restored
170
- return true
177
+ error_code = JSON. parse (String (e. response. body))[" error_code" ]
178
+ if error_code == MLFLOW_ERROR_CODES. RESOURCE_DOES_NOT_EXIST
179
+ error (" Experiment with id \" $experiment_id \" does not exist" )
180
+ end
171
181
end
172
182
throw (e)
173
183
end
174
- true
175
184
end
176
185
177
186
restoreexperiment (mlf:: MLFlow , experiment:: MLFlowExperiment ) =
0 commit comments