Skip to content

Commit cf9f96c

Browse files
authored
Feature implementation, code refactoring, new test suite and increasing code coverage (#27)
* uploading refactoring; implementing and separating test cases * general searchrun tests and code formatting * empty commit to test * Adding coverage and improving test suite * Adding new features, test reimplementation and code coverage increase * fix to test, removing unused implementation, and updates to get documenter working * changed Project.toml entries and fixed a test to work with all kind of exceptions * up corrections
1 parent 599d87d commit cf9f96c

19 files changed

+832
-521
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
Manifest.toml
55
/docs/build/
66
mlruns
7+
coverage

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1414

1515
[compat]
1616
FilePathsBase = "0.9"
17-
HTTP = "0.9,1.2"
17+
HTTP = "1.9"
1818
JSON = "0.21"
1919
ShowCases = "0.1"
20-
URIs = "1"
21-
julia = "1"
20+
URIs = "1.0"
21+
julia = "1.0"
2222

2323
[extras]
2424
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

docs/make.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ makedocs(;
1111
format=Documenter.HTML(;
1212
prettyurls=get(ENV, "CI", "false") == "true",
1313
canonical="https://juliaai.github.io/MLFlowClient.jl",
14-
assets=String[],
14+
assets=String[]
1515
),
1616
pages=[
1717
"Home" => "index.md",
1818
"Tutorial" => "tutorial.md",
1919
"Reference" => "reference.md"
20-
],
20+
]
2121
)
2222

2323
deploydocs(;
2424
repo="github.com/JuliaAI/MLFlowClient.jl",
25-
devbranch="main",
25+
devbranch="main"
2626
)

docs/src/reference.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ MLFlowArtifactDirInfo
2626
createexperiment
2727
getexperiment
2828
getorcreateexperiment
29-
listexperiments
3029
deleteexperiment
30+
searchexperiments
31+
listexperiments
3132
```
3233

3334
# Runs
@@ -50,5 +51,8 @@ listartifacts
5051
mlfget
5152
mlfpost
5253
uri
54+
generatefilterfromentity_type
5355
generatefilterfromparams
56+
generatefilterfromattributes
57+
5458
```

src/MLFlowClient.jl

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ using JSON
2020
using ShowCases
2121
using FilePathsBase: AbstractPath
2222

23-
include("types.jl")
23+
include("types/core.jl")
2424
export
2525
MLFlow,
26-
MLFlowExperiment,
26+
MLFlowExperiment
27+
28+
include("types/runs.jl")
29+
export
2730
MLFlowRunStatus,
2831
MLFlowRunInfo,
29-
get_run_id,
30-
MLFlowRunData,
31-
get_params,
3232
MLFlowRunDataMetric,
33+
MLFlowRunData,
3334
MLFlowRun,
3435
get_info,
3536
get_data,
37+
get_run_id,
38+
get_params
39+
40+
include("types/artifacts.jl")
41+
export
3642
MLFlowArtifactFileInfo,
3743
MLFlowArtifactDirInfo,
3844
get_path,
@@ -41,25 +47,29 @@ export
4147
include("utils.jl")
4248
export
4349
generatefilterfromparams
50+
generatefilterfromattributes
51+
generatefilterfromentity_type
4452

4553
include("experiments.jl")
4654
export
4755
createexperiment,
4856
getexperiment,
4957
getorcreateexperiment,
5058
deleteexperiment,
51-
listexperiments
59+
searchexperiments
5260

5361
include("runs.jl")
5462
export
5563
createrun,
5664
getrun,
5765
updaterun,
5866
deleterun,
59-
searchruns,
67+
searchruns
68+
69+
include("loggers.jl")
70+
export
6071
logparam,
6172
logmetric,
6273
logartifact,
6374
listartifacts
64-
6575
end

src/deprecated.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
listexperiments(mlf::MLFlow)
3+
4+
Returns a list of MLFlow experiments.
5+
6+
Deprecated (last MLFlow version: 1.30.1) in favor of [`searchexperiments`](@ref).
7+
"""
8+
9+
function listexperiments(mlf::MLFlow)
10+
endpoint = "experiments/list"
11+
mlfget(mlf, endpoint)
12+
end

src/experiments.jl

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ function getexperiment(mlf::MLFlow, experiment_name::String)
7373
end
7474
function _getexperimentbyid(mlf::MLFlow, experiment_id::Integer)
7575
endpoint = "experiments/get"
76-
arguments = (:experiment_id => experiment_id, )
76+
arguments = (:experiment_id => experiment_id,)
7777
mlfget(mlf, endpoint; arguments...)["experiment"]
7878
end
7979
function _getexperimentbyname(mlf::MLFlow, experiment_name::String)
8080
endpoint = "experiments/get-by-name"
81-
arguments = (:experiment_name => experiment_name, )
81+
arguments = (:experiment_name => experiment_name,)
8282
mlfget(mlf, endpoint; arguments...)["experiment"]
8383
end
8484

@@ -147,13 +147,59 @@ deleteexperiment(mlf::MLFlow, experiment::MLFlowExperiment) =
147147
deleteexperiment(mlf, experiment.experiment_id)
148148

149149
"""
150-
listexperiments(mlf::MLFlow)
150+
searchexperiments(mlf::MLFlow)
151151
152-
Returns a list of MLFlow experiments.
152+
Searches for experiments in an MLFlow instance.
153+
154+
# Arguments
155+
- `mlf`: [`MLFlow`](@ref) configuration.
156+
157+
# Keywords
158+
- `filter::String`: filter as defined in [MLFlow documentation](https://mlflow.org/docs/latest/rest-api.html#search-experiments)
159+
- `filter_attributes::AbstractDict{K,V}`: if provided, `filter` is automatically generated based on `filter_attributes` using [`generatefilterfromattributes`](@ref). One can only provide either `filter` or `filter_attributes`, but not both.
160+
- `run_view_type::String`: one of `ACTIVE_ONLY`, `DELETED_ONLY`, or `ALL`.
161+
- `max_results::Integer`: 50,000 by default.
162+
- `order_by::String`: as defined in [MLFlow documentation](https://mlflow.org/docs/latest/rest-api.html#search-experiments)
163+
- `page_token::String`: paging functionality, handled automatically. Not meant to be passed by the user.
164+
165+
# Returns
166+
- vector of [`MLFlowExperiment`](@ref) experiments that were found in the MLFlow instance
153167
154-
TODO: not yet entirely implemented
155168
"""
156-
function listexperiments(mlf::MLFlow)
157-
endpoint = "experiments/list"
158-
mlfget(mlf, endpoint)
169+
function searchexperiments(mlf::MLFlow;
170+
filter::String="",
171+
filter_attributes::AbstractDict{K,V}=Dict{}(),
172+
run_view_type::String="ACTIVE_ONLY",
173+
max_results::Int64=50000,
174+
order_by::AbstractVector{<:String}=["attribute.last_update_time"],
175+
page_token::String=""
176+
) where {K,V}
177+
endpoint = "experiments/search"
178+
run_view_type ["ACTIVE_ONLY", "DELETED_ONLY", "ALL"] || error("Unsupported run_view_type = $run_view_type")
179+
180+
if length(filter_attributes) > 0 && length(filter) > 0
181+
error("Cannot specify both filter and filter_attributes")
182+
end
183+
184+
if length(filter_attributes) > 0
185+
filter = generatefilterfromattributes(filter_attributes)
186+
end
187+
188+
kwargs = (; filter, run_view_type, max_results, order_by)
189+
if !isempty(page_token)
190+
kwargs = (; kwargs..., page_token=page_token)
191+
end
192+
193+
result = mlfpost(mlf, endpoint; kwargs...)
194+
haskey(result, "experiments") || return MLFlowExperiment[]
195+
196+
experiments = map(x -> MLFlowExperiment(x), result["experiments"])
197+
198+
if haskey(result, "next_page_token") && !isempty(result["next_page_token"])
199+
kwargs = (; filter, run_view_type, max_results, order_by, page_token=result["next_page_token"])
200+
next_experiments = searchexperiments(mlf; kwargs...)
201+
return vcat(experiments, next_experiments)
202+
end
203+
204+
experiments
159205
end

0 commit comments

Comments
 (0)