1
1
"""
2
- createexperiment(instance::MLFlow; name=missing, artifact_location=missing,
3
- tags=[])
2
+ createexperiment(instance::MLFlow; name::String="",
3
+ artifact_location::String="",
4
+ tags::Union{Dict{<:Any}, Array{<:Any}}=[])
4
5
5
6
Create an experiment with a name. Returns the newly created experiment.
6
7
Validates that another experiment with the same name does not already exist and
7
8
fails if another experiment with the same name already exists.
8
9
9
10
# Arguments
10
11
- `instance`: [`MLFlow`](@ref) configuration.
11
- - `name::String `: Experiment name. This field is required.
12
- - `artifact_location::String `: Location where all artifacts for the experiment
12
+ - `name`: Experiment name. This field is required.
13
+ - `artifact_location`: Location where all artifacts for the experiment
13
14
are stored. If not provided, the remote server will select an appropriate
14
15
default.
15
16
- `tags`: A collection of tags to set on the experiment.
16
17
17
18
# Returns
18
- An object of type [`Experiment`](@ref) .
19
+ The ID of the newly created experiment .
19
20
"""
20
- function createexperiment (instance:: MLFlow ; name:: String = missing ,
21
- artifact_location:: String = missing , tags:: Array{Dict{Any, Any}} = [])
22
- if ismissing (name)
23
- name = string (UUIDs. uuid4 ())
21
+ function createexperiment (instance:: MLFlow ; name:: String = " " ,
22
+ artifact_location:: String = " " ,
23
+ tags:: Union{Dict{<:Any}, Array{<:Any}} = []):: String
24
+ if name |> isempty
25
+ name = UUIDs. uuid4 () |> string
24
26
end
25
27
28
+ tags = tags |> parsetags
29
+
26
30
try
27
31
result = mlfpost (instance, " experiments/create" ; name= name,
28
32
artifact_location= artifact_location, tags= tags)
29
- return getexperiment (instance, result[" experiment_id" ])
33
+ return result[" experiment_id" ]
30
34
catch e
31
35
if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 400
32
- error_code = JSON . parse ( String ( e. response. body) )[" error_code" ]
36
+ error_code = ( e. response. body |> String |> JSON . parse )[" error_code" ]
33
37
if error_code == MLFLOW_ERROR_CODES. RESOURCE_ALREADY_EXISTS
34
38
error (" Experiment with name \" $name \" already exists" )
35
39
end
36
40
end
37
41
throw (e)
38
42
end
39
43
end
40
- createexperiment (instance:: MLFlow ; name:: String = missing ,
41
- artifact_location:: String = missing , tags:: Array{Pair{Any, Any}} = []) =
42
- createexperiment (instance, name= name, artifact_location= artifact_location,
43
- tags= tags |> transform_pair_array_to_dict_array)
44
- createexperiment (instance:: MLFlow ; name:: String = missing ,
45
- artifact_location:: String = missing , tags:: Dict{Any, Any} = []) =
46
- createexperiment (instance, name= name, artifact_location= artifact_location,
47
- tags= tags |> transform_dict_to_dict_array)
48
- createexperiment (instance:: MLFlow ; name:: String = missing ,
49
- artifact_location:: String = missing , tags:: Array{Tag} = []) =
50
- createexperiment (instance, name= name, artifact_location= artifact_location,
51
- tags= tags |> transform_tag_array_to_dict_array)
52
44
53
45
"""
54
46
getexperiment(instance::MLFlow, experiment_id::String)
47
+ getexperiment(instance::MLFlow, experiment_id::Integer)
55
48
56
49
Get metadata for an experiment. This method works on deleted experiments.
57
50
@@ -66,7 +59,7 @@ function getexperiment(instance::MLFlow, experiment_id::String)
66
59
try
67
60
arguments = (:experiment_id => experiment_id,)
68
61
result = mlfget (instance, " experiments/get" ; arguments... )
69
- return Experiment ( result[" experiment" ])
62
+ return result[" experiment" ] |> Experiment
70
63
catch e
71
64
if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
72
65
return missing
@@ -75,4 +68,174 @@ function getexperiment(instance::MLFlow, experiment_id::String)
75
68
end
76
69
end
77
70
getexperiment (instance:: MLFlow , experiment_id:: Integer ) =
78
- getexperiment (instance, experiment_id)
71
+ getexperiment (instance, string (experiment_id))
72
+
73
+ """
74
+ getexperimentbyname(instance::MLFlow, experiment_name::String)
75
+
76
+ Get metadata for an experiment.
77
+
78
+ This endpoint will return deleted experiments, but prefers the active
79
+ experiment if an active and deleted experiment share the same name. If multiple
80
+ deleted experiments share the same name, the API will return one of them.
81
+
82
+ # Arguments
83
+ - `instance`: [`MLFlow`](@ref) configuration.
84
+ - `experiment_name`: Name of the associated experiment.
85
+
86
+ # Returns
87
+ An object of type [`Experiment`](@ref).
88
+ """
89
+ function getexperimentbyname (instance:: MLFlow , experiment_name:: String )
90
+ try
91
+ arguments = (:experiment_name => experiment_name,)
92
+ result = mlfget (instance, " experiments/get-by-name" ; arguments... )
93
+ return result[" experiment" ] |> Experiment
94
+ catch e
95
+ if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
96
+ return missing
97
+ end
98
+ throw (e)
99
+ end
100
+ end
101
+
102
+ """
103
+ deleteexperiment(mlf::MLFlow, experiment_id::String)
104
+ deleteexperiment(mlf::MLFlow, experiment_id::Integer)
105
+ deleteexperiment(mlf::MLFlow, experiment::Experiment)
106
+
107
+ Mark an experiment and associated metadata, runs, metrics, params, and tags for
108
+ deletion. If the experiment uses FileStore, artifacts associated with
109
+ experiment are also deleted.
110
+
111
+ # Arguments
112
+ - `mlf`: [`MLFlow`](@ref) configuration.
113
+ - `experiment_id`: ID of the associated experiment.
114
+
115
+ # Returns
116
+
117
+ `true` if successful. Otherwise, raises exception.
118
+ """
119
+ function deleteexperiment (mlf:: MLFlow , experiment_id:: String )
120
+ endpoint = " experiments/delete"
121
+ try
122
+ mlfpost (mlf, endpoint; experiment_id= experiment_id)
123
+ return true
124
+ catch e
125
+ if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
126
+ # experiment already deleted
127
+ return true
128
+ end
129
+ throw (e)
130
+ end
131
+ end
132
+ deleteexperiment (mlf:: MLFlow , experiment_id:: Integer ) =
133
+ deleteexperiment (mlf, string (experiment_id))
134
+ deleteexperiment (mlf:: MLFlow , experiment:: Experiment ) =
135
+ deleteexperiment (mlf, experiment. experiment_id)
136
+
137
+ """
138
+ restoreexperiment(mlf::MLFlow, experiment_id::String)
139
+ restoreexperiment(mlf::MLFlow, experiment_id::Integer)
140
+ restoreexperiment(mlf::MLFlow, experiment::Experiment)
141
+
142
+ Restore an experiment marked for deletion. This also restores associated
143
+ metadata, runs, metrics, params, and tags. If experiment uses FileStore,
144
+ underlying artifacts associated with experiment are also restored.
145
+
146
+ # Arguments
147
+ - `mlf`: [`MLFlow`](@ref) configuration.
148
+ - `experiment_id`: ID of the associated experiment.
149
+
150
+ # Returns
151
+
152
+ `true` if successful. Otherwise, raises exception.
153
+ """
154
+ function restoreexperiment (mlf:: MLFlow , experiment_id:: String )
155
+ endpoint = " experiments/restore"
156
+ try
157
+ mlfpost (mlf, endpoint; experiment_id= experiment_id)
158
+ return true
159
+ catch e
160
+ if isa (e, HTTP. ExceptionRequest. StatusError) && e. status == 404
161
+ error_code = JSON. parse (String (e. response. body))[" error_code" ]
162
+ if error_code == MLFLOW_ERROR_CODES. RESOURCE_DOES_NOT_EXIST
163
+ error (" Experiment with id \" $experiment_id \" does not exist" )
164
+ end
165
+ end
166
+ throw (e)
167
+ end
168
+ end
169
+ restoreexperiment (mlf:: MLFlow , experiment_id:: Integer ) =
170
+ deleteexperiment (mlf, string (experiment_id))
171
+ restoreexperiment (mlf:: MLFlow , experiment:: Experiment ) =
172
+ deleteexperiment (mlf, experiment. experiment_id)
173
+
174
+ """
175
+ updateexperiment(mlf::MLFlow, experiment_id::String, new_name::String)
176
+ updateexperiment(mlf::MLFlow, experiment_id::Integer, new_name::String)
177
+ updateexperiment(mlf::MLFlow, experiment::Experiment, new_name::String)
178
+
179
+ Update experiment metadata.
180
+
181
+ # Arguments
182
+ - `mlf`: [`MLFlow`](@ref) configuration.
183
+ - `experiment_id`: ID of the associated experiment.
184
+ - `new_name`: If provided, the experiment’s name is changed to the new name.
185
+ The new name must be unique.
186
+
187
+ # Returns
188
+ `true` if successful. Otherwise, raises exception.
189
+ """
190
+ function updateexperiment (mlf:: MLFlow , experiment_id:: String , new_name:: String )
191
+ endpoint = " experiments/update"
192
+ try
193
+ mlfpost (mlf, endpoint; experiment_id= experiment_id, new_name= new_name)
194
+ return true
195
+ catch e
196
+ throw (e)
197
+ end
198
+ end
199
+ updateexperiment (mlf:: MLFlow , experiment_id:: Integer , new_name:: String ) =
200
+ updateexperiment (mlf, string (experiment_id), new_name)
201
+ updateexperiment (mlf:: MLFlow , experiment:: Experiment , new_name:: String ) =
202
+ updateexperiment (mlf, experiment. experiment_id, new_name:: String )
203
+
204
+ """
205
+ searchexperiments(mlf::MLFlow; max_results::Integer=20000,
206
+ page_token::String="", filter::String="", order_by::Array{String}=[],
207
+ view_type::ViewType=ACTIVE_ONLY)
208
+
209
+ # Arguments
210
+ - `mlf`: [`MLFlow`](@ref) configuration.
211
+ - `max_results`: Maximum number of experiments desired.
212
+ - `page_token`: Token indicating the page of experiments to fetch.
213
+ - `filter`: A filter expression over experiment attributes and tags that allows
214
+ returning a subset of experiments. See [MLFlow documentation](https://mlflow.org/docs/latest/rest-api.html#search-experiments).
215
+ - `order_by`: List of columns for ordering search results, which can include
216
+ experiment name and id with an optional “DESC” or “ASC” annotation, where “ASC”
217
+ is the default.
218
+ - `view_type`: Qualifier for type of experiments to be returned. If
219
+ unspecified, return only active experiments.
220
+
221
+ # Returns
222
+ - vector of [`MLFlowExperiment`](@ref) experiments that were found in the MLFlow instance
223
+ """
224
+ function searchexperiments (mlf:: MLFlow ; max_results:: Integer = 20000 ,
225
+ page_token:: String = " " , filter:: String = " " , order_by:: Array{String} = String[],
226
+ view_type:: ViewType = ACTIVE_ONLY)
227
+ endpoint = " experiments/search"
228
+ parameters = (; max_results, page_token, filter,
229
+ :view_type => view_type |> Integer)
230
+
231
+ if order_by |> ! isempty
232
+ parameters = (; order_by, parameters... )
233
+ end
234
+
235
+ try
236
+ result = mlfget (mlf, endpoint; parameters... )
237
+ return result[" experiments" ] |> (x -> [Experiment (y) for y in x])
238
+ catch e
239
+ throw (e)
240
+ end
241
+ end
0 commit comments