Skip to content

Commit 9437c21

Browse files
authored
Adding artifact_location modification to getorcreateexperiment (#26)
* Adding artifact_location modification to getorcreateexperiment function (and updating LICENSE year) * updating run creation/edition functions adding run_name. misc on test * Updating CI mlflow image to the last version
1 parent b94b409 commit 9437c21

File tree

10 files changed

+71
-71
lines changed

10 files changed

+71
-71
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
services:
1717
mlflow:
18-
image: adacotechjp/mlflow:1.21.0
18+
image: adacotechjp/mlflow:2.3.1
1919
ports:
2020
- 5000:5000
2121

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-2021 @deyandyankov and contributors
3+
Copyright (c) 2021-2023 @deyandyankov and contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/experiments.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,24 @@ function _getexperimentbyname(mlf::MLFlow, experiment_name::String)
8383
end
8484

8585
"""
86-
getorcreateexperiment(mlf::MLFlow, experiment_name::String)
86+
getorcreateexperiment(mlf::MLFlow, experiment_name::String; artifact_location=missing, tags=missing)
8787
8888
Gets an experiment if one alrady exists, or creates a new one.
8989
9090
# Arguments
9191
- `mlf`: [`MLFlow`](@ref) configuration.
9292
- `experiment_name`: Experiment name.
93+
- `artifact_location`: directory where artifacts of this experiment will be stored. If not specified, MLFlow uses its default configuration.
94+
- `tags`: a Dictionary of key-values which tag the experiment.
9395
9496
# Returns
9597
An instance of type [`MLFlowExperiment`](@ref)
9698
9799
"""
98-
function getorcreateexperiment(mlf::MLFlow, experiment_name::String)
100+
function getorcreateexperiment(mlf::MLFlow, experiment_name::String; artifact_location=missing, tags=missing)
99101
exp = getexperiment(mlf, experiment_name)
100102
if ismissing(exp)
101-
exp = createexperiment(mlf, name=experiment_name)
103+
exp = createexperiment(mlf, name=experiment_name, artifact_location=artifact_location, tags=tags)
102104
end
103105
exp
104106
end

src/runs.jl

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
createrun(mlf::MLFlow, experiment_id; start_time=missing, tags=missing)
2+
createrun(mlf::MLFlow, experiment_id; run_name=missing, start_time=missing, tags=missing)
33
44
Creates a run associated to an experiment.
55
@@ -8,27 +8,28 @@ Creates a run associated to an experiment.
88
- `experiment_id`: experiment identifier.
99
1010
# Keywords
11+
- `run_name`: run name. If not specified, MLFlow sets it.
1112
- `start_time`: if provided, must be a UNIX timestamp in milliseconds. By default, set to current time.
1213
- `tags`: if provided, must be a key-value structure such as a dictionary.
1314
1415
# Returns
1516
- an instance of type [`MLFlowRun`](@ref)
1617
"""
17-
function createrun(mlf::MLFlow, experiment_id; start_time=missing, tags=missing)
18+
function createrun(mlf::MLFlow, experiment_id; run_name=missing, start_time=missing, tags=missing)
1819
endpoint = "runs/create"
1920
if ismissing(start_time)
2021
start_time = Int(trunc(datetime2unix(now(UTC)) * 1000))
2122
end
22-
result = mlfpost(mlf, endpoint; experiment_id=experiment_id, start_time=start_time, tags=tags)
23+
result = mlfpost(mlf, endpoint; experiment_id=experiment_id, run_name=run_name, start_time=start_time, tags=tags)
2324
MLFlowRun(result["run"]["info"], result["run"]["data"])
2425
end
2526
"""
26-
createrun(mlf::MLFlow, experiment::MLFlowExperiment; start_time=missing, tags=missing)
27+
createrun(mlf::MLFlow, experiment::MLFlowExperiment; run_name=missing, start_time=missing, tags=missing)
2728
28-
Dispatches to `createrun(mlf::MLFlow, experiment_id; start_time=start_time, tags=tags)`
29+
Dispatches to `createrun(mlf::MLFlow, experiment_id; run_name=run_name, start_time=start_time, tags=tags)`
2930
"""
30-
createrun(mlf::MLFlow, experiment::MLFlowExperiment; start_time=missing, tags=missing) =
31-
createrun(mlf, experiment.experiment_id; start_time=start_time, tags=tags)
31+
createrun(mlf::MLFlow, experiment::MLFlowExperiment; run_name=missing, start_time=missing, tags=missing) =
32+
createrun(mlf, experiment.experiment_id; run_name=run_name, start_time=start_time, tags=tags)
3233

3334
"""
3435
getrun(mlf::MLFlow, run_id)
@@ -59,13 +60,15 @@ Updates the status of an experiment's run.
5960
- `status`: either `String` and one of ["RUNNING", "SCHEDULED", "FINISHED", "FAILED", "KILLED"], or an instance of `MLFlowRunStatus`
6061
6162
# Keywords
63+
- `run_name`: if provided, must be a String. By default, not set.
6264
- `end_time`: if provided, must be a UNIX timestamp in milliseconds. By default, set to current time.
6365
"""
64-
function updaterun(mlf::MLFlow, run_id::String, status::MLFlowRunStatus; end_time=missing)
66+
function updaterun(mlf::MLFlow, run_id::String, status::MLFlowRunStatus; run_name=missing, end_time=missing)
6567
endpoint = "runs/update"
6668
kwargs = Dict(
6769
:run_id => run_id,
6870
:status => status.status,
71+
:run_name => run_name,
6972
:end_time => end_time
7073
)
7174
if ismissing(end_time) && status.status == "FINISHED"
@@ -75,16 +78,16 @@ function updaterun(mlf::MLFlow, run_id::String, status::MLFlowRunStatus; end_tim
7578
result = mlfpost(mlf, endpoint; kwargs...)
7679
MLFlowRun(result["run_info"])
7780
end
78-
updaterun(mlf::MLFlow, run_id::String, status::String; end_time=missing) =
79-
updaterun(mlf, run_id, MLFlowRunStatus(status); end_time=end_time)
80-
updaterun(mlf::MLFlow, run_info::MLFlowRunInfo, status::String; end_time=missing) =
81-
updaterun(mlf, run_info.run_id, MLFlowRunStatus(status); end_time=end_time)
82-
updaterun(mlf::MLFlow, run::MLFlowRun, status::String; end_time=missing) =
83-
updaterun(mlf, run.info, MLFlowRunStatus(status), end_time=end_time)
84-
updaterun(mlf::MLFlow, run_info::MLFlowRunInfo, status::MLFlowRunStatus; end_time=missing) =
85-
updaterun(mlf, run_info.run_id, status, end_time=end_time)
86-
updaterun(mlf::MLFlow, run::MLFlowRun, status::MLFlowRunStatus; end_time=missing) =
87-
updaterun(mlf, run.info, status; end_time=end_time)
81+
updaterun(mlf::MLFlow, run_id::String, status::String; run_name=missing, end_time=missing) =
82+
updaterun(mlf, run_id, MLFlowRunStatus(status); run_name=run_name, end_time=end_time)
83+
updaterun(mlf::MLFlow, run_info::MLFlowRunInfo, status::String; run_name=missing, end_time=missing) =
84+
updaterun(mlf, run_info.run_id, MLFlowRunStatus(status); run_name=run_name, end_time=end_time)
85+
updaterun(mlf::MLFlow, run::MLFlowRun, status::String; run_name=missing, end_time=missing) =
86+
updaterun(mlf, run.info, MLFlowRunStatus(status); run_name=run_name, end_time=end_time)
87+
updaterun(mlf::MLFlow, run_info::MLFlowRunInfo, status::MLFlowRunStatus; run_name=missing, end_time=missing) =
88+
updaterun(mlf, run_info.run_id, status; run_name=run_name, end_time=end_time)
89+
updaterun(mlf::MLFlow, run::MLFlowRun, status::MLFlowRunStatus; run_name=missing, end_time=missing) =
90+
updaterun(mlf, run.info, status; run_name=run_name, end_time=end_time)
8891

8992
"""
9093
deleterun(mlf::MLFlow, run)

src/types.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,22 @@ Represents run metadata.
100100
- `run_id::String`: run identifier.
101101
- `experiment_id::Integer`: experiment identifier.
102102
- `status::MLFlowRunStatus`: run status.
103+
- `run_name::String`: run name.
103104
- `start_time::Union{Int64,Missing}`: when was the run started, UNIX time in milliseconds.
104105
- `end_time::Union{Int64,Missing}`: when did the run end, UNIX time in milliseconds.
105106
- `artifact_uri::String`: where are artifacts from this run stored.
106107
- `lifecycle_stage::String`: one of `active` or `deleted`.
107108
108109
# Constructors
109110
110-
- `MLFlowRunInfo(run_id, experiment_id, status, start_time, end_time, artifact_uri, lifecycle_stage)`
111+
- `MLFlowRunInfo(run_id, experiment_id, status, run_name, start_time, end_time, artifact_uri, lifecycle_stage)`
111112
- `MLFlowRunInfo(info::Dict{String,Any})`
112113
"""
113114
struct MLFlowRunInfo
114115
run_id::String
115116
experiment_id::Integer
116117
status::MLFlowRunStatus
118+
run_name::String
117119
start_time::Union{Int64,Missing}
118120
end_time::Union{Int64,Missing}
119121
artifact_uri::String
@@ -123,6 +125,7 @@ function MLFlowRunInfo(info::Dict{String,Any})
123125
run_id = get(info, "run_id", missing)
124126
experiment_id = get(info, "experiment_id", missing)
125127
status = get(info, "status", missing)
128+
run_name = get(info, "run_name", missing)
126129
start_time = get(info, "start_time", missing)
127130
end_time = get(info, "end_time", missing)
128131
artifact_uri = get(info, "artifact_uri", "")
@@ -138,7 +141,7 @@ function MLFlowRunInfo(info::Dict{String,Any})
138141
if !ismissing(end_time) && !(typeof(end_time) <: Int)
139142
end_time = parse(Int64, end_time)
140143
end
141-
MLFlowRunInfo(run_id, experiment_id, status, start_time, end_time, artifact_uri, lifecycle_stage)
144+
MLFlowRunInfo(run_id, experiment_id, status, run_name, start_time, end_time, artifact_uri, lifecycle_stage)
142145
end
143146
Base.show(io::IO, t::MLFlowRunInfo) = show(io, ShowCase(t, new_lines=true))
144147
get_run_id(runinfo::MLFlowRunInfo) = runinfo.run_id

test/issues/test_issue17.jl

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/issues/test_issue20.jl

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
include("test_functional.jl")
2-
include.(filter(contains(r"\.jl$"), readdir("./issues"; join=true)))

test/test_functional.jl

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,55 @@ end
6161

6262
@testset "createrun" begin
6363
@ensuremlf
64-
expname = "getorcreate-$(UUIDs.uuid4())"
64+
expname = "createrun-$(UUIDs.uuid4())"
6565
e = getorcreateexperiment(mlf, expname)
66-
r = createrun(mlf, e.experiment_id)
66+
runname = "run-$(UUIDs.uuid4())"
67+
r = createrun(mlf, e.experiment_id; run_name=runname)
68+
6769
@test isa(r, MLFlowRun)
70+
@test r.info.run_name == runname
71+
deleteexperiment(mlf, e)
72+
end
73+
74+
@testset "deleterun" begin
75+
@ensuremlf
76+
expname = "deleterun-$(UUIDs.uuid4())"
77+
e = getorcreateexperiment(mlf, expname)
78+
r = createrun(mlf, e.experiment_id)
79+
6880
@test deleterun(mlf, r)
69-
rr = createrun(mlf, e)
70-
@test isa(rr, MLFlowRun)
71-
@test deleterun(mlf, rr)
72-
@test deleteexperiment(mlf, e)
81+
deleteexperiment(mlf, e)
82+
end
83+
84+
@testset "updaterun" begin
85+
@ensuremlf
86+
expname = "updaterun-$(UUIDs.uuid4())"
87+
e = getorcreateexperiment(mlf, expname)
88+
runname = "run-$(UUIDs.uuid4())"
89+
r = createrun(mlf, e.experiment_id; run_name=runname)
90+
91+
new_runname = "new_updaterun-$(UUIDs.uuid4())"
92+
new_status = "FINISHED"
93+
r_updated = updaterun(mlf, r, new_status; run_name=new_runname)
94+
95+
@test isa(r_updated, MLFlowRun)
96+
@test r_updated.info.run_name != r.info.run_name
97+
@test r_updated.info.status.status != r.info.status
98+
@test r_updated.info.run_name == new_runname
99+
@test r_updated.info.status.status == new_status
100+
deleteexperiment(mlf, e)
73101
end
74102

75103
@testset "getorcreateexperiment" begin
76104
@ensuremlf
77105
expname = "getorcreate"
78-
e = getorcreateexperiment(mlf, expname)
106+
artifact_location = "test$(expname)"
107+
e = getorcreateexperiment(mlf, expname; artifact_location=artifact_location)
79108
@test isa(e, MLFlowExperiment)
80109
ee = getorcreateexperiment(mlf, expname)
81110
@test isa(ee, MLFlowExperiment)
82111
@test e === ee
112+
@test occursin(artifact_location, e.artifact_location)
83113
@test deleteexperiment(mlf, ee)
84114
@test deleteexperiment(mlf, ee)
85115
end
@@ -255,4 +285,5 @@ end
255285
deleterun(mlf, exprun2)
256286

257287
deleteexperiment(mlf, exp)
288+
deleteexperiment(mlf, experiment)
258289
end

test/test_utils.jl

Whitespace-only changes.

0 commit comments

Comments
 (0)