|
| 1 | +""" |
| 2 | + createexperiment(instance::MLFlow; name=missing, artifact_location=missing, |
| 3 | + tags=[]) |
| 4 | +
|
| 5 | +Create an experiment with a name. Returns the newly created experiment. |
| 6 | +Validates that another experiment with the same name does not already exist and |
| 7 | +fails if another experiment with the same name already exists. |
| 8 | +
|
| 9 | +# Arguments |
| 10 | +- `instance`: [`MLFlow`](@ref) configuration. |
| 11 | +- `name::String`: Experiment name. This field is required. |
| 12 | +- `artifact_location::String`: Location where all artifacts for the experiment |
| 13 | +are stored. If not provided, the remote server will select an appropriate |
| 14 | +default. |
| 15 | +- `tags`: A collection of tags to set on the experiment. |
| 16 | +
|
| 17 | +# Returns |
| 18 | +An object of type [`Experiment`](@ref). |
| 19 | +""" |
| 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()) |
| 24 | + end |
| 25 | + |
| 26 | + try |
| 27 | + result = mlfpost(instance, "experiments/create"; name=name, |
| 28 | + artifact_location=artifact_location, tags=tags) |
| 29 | + return getexperiment(instance, result["experiment_id"]) |
| 30 | + catch e |
| 31 | + if isa(e, HTTP.ExceptionRequest.StatusError) && e.status == 400 |
| 32 | + error_code = JSON.parse(String(e.response.body))["error_code"] |
| 33 | + if error_code == MLFLOW_ERROR_CODES.RESOURCE_ALREADY_EXISTS |
| 34 | + error("Experiment with name \"$name\" already exists") |
| 35 | + end |
| 36 | + end |
| 37 | + throw(e) |
| 38 | + end |
| 39 | +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 | + |
| 53 | +""" |
| 54 | + getexperiment(instance::MLFlow, experiment_id::String) |
| 55 | +
|
| 56 | +Get metadata for an experiment. This method works on deleted experiments. |
| 57 | +
|
| 58 | +# Arguments |
| 59 | +- `instance`: [`MLFlow`](@ref) configuration. |
| 60 | +- `experiment_id`: ID of the associated experiment. |
| 61 | +
|
| 62 | +# Returns |
| 63 | +An object of type [`Experiment`](@ref). |
| 64 | +""" |
| 65 | +function getexperiment(instance::MLFlow, experiment_id::String) |
| 66 | + try |
| 67 | + arguments = (:experiment_id => experiment_id,) |
| 68 | + result = mlfget(instance, "experiments/get"; arguments...) |
| 69 | + return Experiment(result["experiment"]) |
| 70 | + catch e |
| 71 | + if isa(e, HTTP.ExceptionRequest.StatusError) && e.status == 404 |
| 72 | + return missing |
| 73 | + end |
| 74 | + throw(e) |
| 75 | + end |
| 76 | +end |
| 77 | +getexperiment(instance::MLFlow, experiment_id::Integer) = |
| 78 | + getexperiment(instance, experiment_id) |
0 commit comments