Skip to content

Commit 1552bb3

Browse files
committed
Some formatting changes and extra functions using types
1 parent a6579ec commit 1552bb3

File tree

15 files changed

+190
-253
lines changed

15 files changed

+190
-253
lines changed

src/MLFlowClient.jl

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ include("types/tag.jl")
1515
export Tag
1616

1717
include("types/enums.jl")
18-
export
19-
ViewType,
20-
RunStatus,
21-
ModelVersionStatus
18+
export ViewType, RunStatus, ModelVersionStatus
2219

2320
include("types/dataset.jl")
24-
export
25-
Dataset,
26-
DatasetInput
21+
export Dataset, DatasetInput
2722

2823
include("types/artifact.jl")
2924
export FileInfo
@@ -32,56 +27,30 @@ include("types/model_version.jl")
3227
export ModelVersion
3328

3429
include("types/registered_model.jl")
35-
export
36-
RegisteredModel,
37-
RegisteredModelAlias
30+
export RegisteredModel, RegisteredModelAlias
3831

3932
include("types/experiment.jl")
4033
export Experiment
4134

4235
include("types/run.jl")
43-
export
44-
Run,
45-
Param,
46-
Metric,
47-
RunData,
48-
RunInfo,
49-
RunInputs
36+
export Run, Param, Metric, RunData, RunInfo, RunInputs
5037

5138
include("utils.jl")
5239
export refresh
40+
5341
include("api.jl")
5442

5543
include("services/experiment.jl")
56-
export
57-
getexperiment,
58-
createexperiment,
59-
deleteexperiment,
60-
setexperimenttag,
61-
updateexperiment,
62-
restoreexperiment,
63-
searchexperiments,
64-
getexperimentbyname
44+
export getexperiment, createexperiment, deleteexperiment, setexperimenttag,
45+
updateexperiment, restoreexperiment, searchexperiments, getexperimentbyname
6546

6647
include("services/run.jl")
67-
export
68-
getrun,
69-
createrun,
70-
deleterun,
71-
setruntag,
72-
restorerun,
73-
searchruns,
74-
deleteruntag
48+
export getrun, createrun, deleterun, setruntag, restorerun, searchruns, deleteruntag
7549

7650
include("services/loggers.jl")
77-
export
78-
logbatch,
79-
loginputs,
80-
logmetric,
81-
logparam
51+
export logbatch, loginputs, logmetric, logparam
8252

8353
include("services/misc.jl")
84-
export
85-
getmetrichistory
54+
export getmetrichistory
8655

8756
end

src/api.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ MLFlowClient.uri(mlf, "experiments/get", Dict(:experiment_id=>10))
1010
"""
1111
uri(mlf::MLFlow, endpoint::String;
1212
parameters::Dict{Symbol, <:Any}=Dict{Symbol, NumberOrString}()) =
13-
URI("$(mlf.apiroot)/$(mlf.apiversion)/mlflow/$(endpoint)";
14-
query=parameters)
13+
URI("$(mlf.apiroot)/$(mlf.apiversion)/mlflow/$(endpoint)"; query=parameters)
1514

1615
"""
1716
headers(mlf::MLFlow,custom_headers::AbstractDict)
@@ -40,8 +39,7 @@ function mlfget(mlf, endpoint; kwargs...)
4039
return response.body |> String |> JSON.parse
4140
catch e
4241
error_response = e.response.body |> String |> JSON.parse
43-
error_message =
44-
"$(error_response["error_code"]) - $(error_response["message"])"
42+
error_message = "$(error_response["error_code"]) - $(error_response["message"])"
4543
@error error_message
4644
throw(ErrorException(error_message))
4745
end
@@ -50,7 +48,8 @@ end
5048
"""
5149
mlfpost(mlf, endpoint; kwargs...)
5250
53-
Performs a HTTP POST to the specified endpoint. kwargs are converted to JSON and become the POST body.
51+
Performs a HTTP POST to the specified endpoint. kwargs are converted to JSON and become the
52+
POST body.
5453
"""
5554
function mlfpost(mlf, endpoint; kwargs...)
5655
apiuri = uri(mlf, endpoint;)
@@ -62,8 +61,7 @@ function mlfpost(mlf, endpoint; kwargs...)
6261
return response.body |> String |> JSON.parse
6362
catch e
6463
error_response = e.response.body |> String |> JSON.parse
65-
error_message =
66-
"$(error_response["error_code"]) - $(error_response["message"])"
64+
error_message = "$(error_response["error_code"]) - $(error_response["message"])"
6765
@error error_message
6866
throw(ErrorException(error_message))
6967
end

src/services/experiment.jl

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""
2-
createexperiment(instance::MLFlow, name::String;
3-
artifact_location::String="",
2+
createexperiment(instance::MLFlow, name::String; artifact_location::String="",
43
tags::Union{Dict{<:Any}, Array{<:Any}}=[])
54
6-
Create an experiment with a name. Returns the newly created experiment.
7-
Validates that another experiment with the same name does not already exist and
8-
fails if another experiment with the same name already exists.
5+
Create an experiment with a name. Returns the newly created experiment. Validates that
6+
another experiment with the same name does not already exist and fails if another
7+
experiment with the same name already exists.
98
109
# Arguments
1110
- `instance`: [`MLFlow`](@ref) configuration.
@@ -51,9 +50,9 @@ getexperiment(instance::MLFlow, experiment_id::Integer)::Experiment =
5150
5251
Get metadata for an experiment.
5352
54-
This endpoint will return deleted experiments, but prefers the active
55-
experiment if an active and deleted experiment share the same name. If multiple
56-
deleted experiments share the same name, the API will return one of them.
53+
This endpoint will return deleted experiments, but prefers the active experiment if an
54+
active and deleted experiment share the same name. If multiple deleted experiments share
55+
the same name, the API will return one of them.
5756
5857
# Arguments
5958
- `instance`: [`MLFlow`](@ref) configuration.
@@ -62,10 +61,8 @@ deleted experiments share the same name, the API will return one of them.
6261
# Returns
6362
An instance of type [`Experiment`](@ref).
6463
"""
65-
function getexperimentbyname(instance::MLFlow,
66-
experiment_name::String)::Experiment
67-
result = mlfget(instance, "experiments/get-by-name";
68-
experiment_name=experiment_name)
64+
function getexperimentbyname(instance::MLFlow, experiment_name::String)::Experiment
65+
result = mlfget(instance, "experiments/get-by-name"; experiment_name=experiment_name)
6966
return result["experiment"] |> Experiment
7067
end
7168

@@ -74,9 +71,8 @@ end
7471
deleteexperiment(instance::MLFlow, experiment_id::Integer)
7572
deleteexperiment(instance::MLFlow, experiment::Experiment)
7673
77-
Mark an experiment and associated metadata, runs, metrics, params, and tags for
78-
deletion. If the experiment uses FileStore, artifacts associated with
79-
experiment are also deleted.
74+
Mark an experiment and associated metadata, runs, metrics, params, and tags for deletion.
75+
If the experiment uses FileStore, artifacts associated with experiment are also deleted.
8076
8177
# Arguments
8278
- `instance`: [`MLFlow`](@ref) configuration.
@@ -99,9 +95,9 @@ deleteexperiment(instance::MLFlow, experiment::Experiment)::Bool =
9995
restoreexperiment(instance::MLFlow, experiment_id::Integer)
10096
restoreexperiment(instance::MLFlow, experiment::Experiment)
10197
102-
Restore an experiment marked for deletion. This also restores associated
103-
metadata, runs, metrics, params, and tags. If experiment uses FileStore,
104-
underlying artifacts associated with experiment are also restored.
98+
Restore an experiment marked for deletion. This also restores associated metadata, runs,
99+
metrics, params, and tags. If experiment uses FileStore, underlying artifacts associated
100+
with experiment are also restored.
105101
106102
# Arguments
107103
- `instance`: [`MLFlow`](@ref) configuration.
@@ -121,62 +117,52 @@ restoreexperiment(instance::MLFlow, experiment::Experiment)::Bool =
121117

122118
"""
123119
updateexperiment(instance::MLFlow, experiment_id::String, new_name::String)
124-
updateexperiment(instance::MLFlow, experiment_id::Integer,
125-
new_name::String)
126-
updateexperiment(instance::MLFlow, experiment::Experiment,
127-
new_name::String)
120+
updateexperiment(instance::MLFlow, experiment_id::Integer, new_name::String)
121+
updateexperiment(instance::MLFlow, experiment::Experiment, new_name::String)
128122
129123
Update experiment metadata.
130124
131125
# Arguments
132126
- `instance`: [`MLFlow`](@ref) configuration.
133127
- `experiment_id`: ID of the associated experiment.
134-
- `new_name`: If provided, the experiment’s name is changed to the new name.
135-
The new name must be unique.
128+
- `new_name`: If provided, the experiment’s name is changed to the new name. The new name
129+
must be unique.
136130
137131
# Returns
138132
`true` if successful. Otherwise, raises exception.
139133
"""
140-
function updateexperiment(instance::MLFlow, experiment_id::String,
141-
new_name::String)::Bool
142-
mlfpost(instance, "experiments/update"; experiment_id=experiment_id,
143-
new_name=new_name)
134+
function updateexperiment(instance::MLFlow, experiment_id::String, new_name::String)::Bool
135+
mlfpost(instance, "experiments/update"; experiment_id=experiment_id, new_name=new_name)
144136
return true
145137
end
146-
updateexperiment(instance::MLFlow, experiment_id::Integer,
147-
new_name::String)::Bool =
138+
updateexperiment(instance::MLFlow, experiment_id::Integer, new_name::String)::Bool =
148139
updateexperiment(instance, string(experiment_id), new_name)
149-
updateexperiment(instance::MLFlow, experiment::Experiment,
150-
new_name::String)::Bool =
140+
updateexperiment(instance::MLFlow, experiment::Experiment, new_name::String)::Bool =
151141
updateexperiment(instance, experiment.experiment_id, new_name)
152142

153143
"""
154-
searchexperiments(instance::MLFlow; max_results::Int64=20000,
155-
page_token::String="", filter::String="", order_by::Array{String}=[],
156-
view_type::ViewType=ACTIVE_ONLY)
144+
searchexperiments(instance::MLFlow; max_results::Int64=20000, page_token::String="",
145+
filter::String="", order_by::Array{String}=[], view_type::ViewType=ACTIVE_ONLY)
157146
158147
# Arguments
159148
- `instance`: [`MLFlow`](@ref) configuration.
160149
- `max_results`: Maximum number of experiments desired.
161150
- `page_token`: Token indicating the page of experiments to fetch.
162-
- `filter`: A filter expression over experiment attributes and tags that allows
163-
returning a subset of experiments. See [MLFlow documentation](https://mlflow.org/docs/latest/rest-api.html#search-experiments).
164-
- `order_by`: List of columns for ordering search results, which can include
165-
experiment name and id with an optional “DESC” or “ASC” annotation, where “ASC”
166-
is the default.
167-
- `view_type`: Qualifier for type of experiments to be returned. If
168-
unspecified, return only active experiments.
151+
- `filter`: A filter expression over experiment attributes and tags that allows returning a
152+
subset of experiments. See [MLFlow documentation](https://mlflow.org/docs/latest/rest-api.html#search-experiments).
153+
- `order_by`: List of columns for ordering search results, which can include experiment
154+
name and id with an optional “DESC” or “ASC” annotation, where “ASC” is the default.
155+
- `view_type`: Qualifier for type of experiments to be returned. If unspecified, return
156+
only active experiments.
169157
170158
# Returns
171159
- Vector of [`Experiment`](@ref) that were found in the MLFlow instance.
172160
- The next page token if there are more results.
173161
"""
174162
function searchexperiments(instance::MLFlow; max_results::Int64=20000,
175163
page_token::String="", filter::String="", order_by::Array{String}=String[],
176-
view_type::ViewType=ACTIVE_ONLY
177-
)::Tuple{Array{Experiment}, Union{String, Nothing}}
178-
parameters = (; max_results, page_token, filter,
179-
:view_type => view_type |> Integer)
164+
view_type::ViewType=ACTIVE_ONLY)::Tuple{Array{Experiment}, Union{String, Nothing}}
165+
parameters = (; max_results, page_token, filter, :view_type => view_type |> Integer)
180166

181167
if order_by |> !isempty
182168
parameters = (; order_by, parameters...)
@@ -191,12 +177,9 @@ function searchexperiments(instance::MLFlow; max_results::Int64=20000,
191177
end
192178

193179
"""
194-
setexperimenttag(instance::MLFlow, experiment_id::String, key::String,
195-
value::String)
196-
setexperimenttag(instance::MLFlow, experiment_id::Integer, key::String,
197-
value::String)
198-
setexperimenttag(instance::MLFlow, experiment::Experiment, key::String,
199-
value::String)
180+
setexperimenttag(instance::MLFlow, experiment_id::String, key::String, value::String)
181+
setexperimenttag(instance::MLFlow, experiment_id::Integer, key::String, value::String)
182+
setexperimenttag(instance::MLFlow, experiment::Experiment, key::String, value::String)
200183
201184
Set a tag on an experiment. Experiment tags are metadata that can be updated.
202185
@@ -210,8 +193,8 @@ Set a tag on an experiment. Experiment tags are metadata that can be updated.
210193
"""
211194
function setexperimenttag(instance::MLFlow, experiment_id::String, key::String,
212195
value::String)::Bool
213-
mlfpost(instance, "experiments/set-experiment-tag";
214-
experiment_id=experiment_id, key=key, value=value)
196+
mlfpost(instance, "experiments/set-experiment-tag"; experiment_id=experiment_id,
197+
key=key, value=value)
215198
return true
216199
end
217200
setexperimenttag(instance::MLFlow, experiment_id::Integer, key::String,

0 commit comments

Comments
 (0)