Skip to content

Commit b5be208

Browse files
committed
Adding Makie extension for artifact logging
1 parent a9b53d5 commit b5be208

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Project.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ ShowCases = "605ecd9f-84a6-4c9e-81e2-4798472b76a3"
1515
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
1616
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1717

18+
[weakdeps]
19+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
20+
1821
[compat]
1922
AWSS3 = "0.11.4"
2023
Base64 = "1.0"
24+
CairoMakie = "0.15.7"
2125
FileTypes = "0.1.1"
2226
HTTP = "1.0"
2327
JSON = "0.21"
@@ -32,3 +36,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3236

3337
[targets]
3438
test = ["Base64", "Test"]
39+
40+
[extensions]
41+
MLFlowMakieExt = "CairoMakie"

ext/logger.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
module MLFlowMakieExt
3+
4+
using CairoMakie
5+
6+
"""
7+
logartifact(s3_cfg::MinioConfig, run::Run, fig::Makie.Figure, artifact_name::String="")
8+
9+
Log artifact for a run. Supports only S3 buckets.
10+
11+
# Arguments
12+
- `s3_cfg`: Minio configuration
13+
- `Run`: ['Run'](@ref) instance
14+
- `fig`: `Makie.Figure` to store
15+
- `artifact_name`: Name of the artifact in the bucket
16+
17+
# Returns
18+
`true` if successful. Otherwise, raises exception.
19+
20+
"""
21+
22+
function logartifact(s3_cfg::MinioConfig, run::Run, fig::Makie.Figure, artifact_name::String="")
23+
# Parse the URI
24+
u = URI(run.info.artifact_uri)
25+
u.scheme == "s3" || ArgumentError("The artifact URI for the run has to be a S3 bucket. Got: $(run.info.artifact_uri)")
26+
isfile(path) || ArgumentError("Can not read file $(path).")
27+
bucket_name = u.host
28+
artifacts_base_path = u.path
29+
30+
isempty(artifact_name) || ArgumentError("The provided artifact_name is empty")
31+
32+
# Store figure as png
33+
io = IOBuffer()
34+
show(io, MIME"figure/png"(), fig)
35+
content = take!(io)
36+
37+
# Create artifact path
38+
artifact_path = joinpath(artifacts_base_path, artifact_name)
39+
40+
# store in bucket
41+
s3_put(s3_cfg, bucket_name, artifact_path, content, "figure/png")
42+
return true
43+
end
44+
45+
end

src/services/logger.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ logmodel(instance::MLFlow, run::Run, model_json::String)::Bool =
141141
logmodel(instance, run.info.run_id, model_json)
142142

143143
"""
144-
logartifact(s3_cfg::MinioConfig, run::Run, s3_cfg::MinioConfig, path::String="", artifact_name::String="")
144+
logartifact(s3_cfg::MinioConfig, run::Run, path::String="", artifact_name::String="")
145145
146146
Log artifact for a run. Supports only S3 buckets.
147147
@@ -184,3 +184,5 @@ function logartifact(s3_cfg::MinioConfig, run::Run, path::String="", artifact_na
184184
end
185185

186186

187+
188+

0 commit comments

Comments
 (0)