From 46582a19e524f30b2e851ca3a87737a164a12ea7 Mon Sep 17 00:00:00 2001 From: William Thompson Date: Wed, 3 Apr 2024 14:44:50 -0700 Subject: [PATCH 1/6] support PDF output --- src/InferenceReport.jl | 14 +++++++++++--- src/ReportOptions.jl | 7 +++++++ src/building_blocks.jl | 34 ++++++++++++++++++++++------------ src/processors.jl | 22 +++++++++++----------- 4 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/InferenceReport.jl b/src/InferenceReport.jl index 01677201..c145981c 100644 --- a/src/InferenceReport.jl +++ b/src/InferenceReport.jl @@ -1,6 +1,8 @@ module InferenceReport using CairoMakie +CairoMakie.activate!(type = "png", px_per_unit = 2) + using Documenter using MCMCChains using PairPlots @@ -117,8 +119,14 @@ as_doc_page(context) = "`$(target_name(context))`" => "generated/$(basename(dirn """ $SIGNATURES """ -view_webpage(exec_folder) = open_in_default_browser("$exec_folder/build/index.html") - +function view_webpage(exec_folder) + # Try to autodect if we built HTML or a PDF + if isfile("$exec_folder/build/InferenceReport.pdf") + open_in_default_browser("$exec_folder/build/InferenceReport.pdf") + else + open_in_default_browser("$exec_folder/build/index.html") + end +end """ $SIGNATURES """ @@ -127,7 +135,7 @@ render(context) = root = dirname(context.output_directory), sitename = "InferenceReport", repo="https://github.com/Julia-Tempering/Pigeons.jl/blob/{commit}{path}#{line}", - format = Documenter.HTML(size_threshold=nothing), + format = context.options.writer, pages = ["`$(target_name(context))`" => "index.md"]) # Controls defaults such as whether to render and open webpage right away diff --git a/src/ReportOptions.jl b/src/ReportOptions.jl index a0222075..50786a44 100644 --- a/src/ReportOptions.jl +++ b/src/ReportOptions.jl @@ -58,4 +58,11 @@ $FIELDS the [Inputs](https://pigeons.run/dev/reference/#Pigeons.Inputs). """ reproducibility_command::Union{String, Nothing} = nothing + + + """ + A Documenter.Writer instance used to render the document. Default is an HTML + page, but other options including Documenter.LaTeX() are also possible. + """ + writer::Documenter.Writer=Documenter.HTML(size_threshold=nothing) end \ No newline at end of file diff --git a/src/building_blocks.jl b/src/building_blocks.jl index 26bad75f..f6ad0c1a 100644 --- a/src/building_blocks.jl +++ b/src/building_blocks.jl @@ -30,18 +30,28 @@ end $SIGNATURES """ function add_plot(context; file, title, url_help = nothing, description = "", movie = nothing) - info_link = isnothing(url_help) ? "" : """⏐🔗 Info """ - movie_link = isnothing(movie) ? "" : """⏐🍿 Movie """ - add_markdown(context; - title, - contents = """ - $description - ```@raw html - - 🔍 Full page $movie_link $info_link - ``` - """ - ) + if context.options.writer isa Documenter.HTML + info_link = isnothing(url_help) ? "" : """⏐🔗 Info """ + movie_link = isnothing(movie) ? "" : """⏐🍿 Movie """ + add_markdown(context; + title, + contents = """ + $description + ```@raw html + + 🔍 Full page $movie_link $info_link + ``` + """ + ) + else + add_markdown(context; + title, + contents = """ + $description + ![]($file) + """ + ) + end end """ diff --git a/src/processors.jl b/src/processors.jl index 05be19a1..9f946a4b 100644 --- a/src/processors.jl +++ b/src/processors.jl @@ -5,8 +5,8 @@ Create a pair plot using [PairPlot.jl](https://github.com/sefffal/PairPlots.jl). """ function pair_plot(context) plot = PairPlots.pairplot(get_chains(context)) - file = output_file(context, "pair_plot", "svg") - CairoMakie.save(file, plot) + file = output_file(context, "pair_plot", "png") + CairoMakie.save(file, plot, px_per_unit=2) description = """ Diagonal entries show estimates of the marginal @@ -25,7 +25,7 @@ function pair_plot(context) end add_plot(context; - file = "pair_plot.svg", + file = "pair_plot.png", title = "Pair plot", url_help = "https://sefffal.github.io/PairPlots.jl", movie = moving_pair_plot(context), @@ -127,10 +127,10 @@ function trace_plot(context, cumulative) resize_to_layout!(fig) name = cumulative ? "cumulative_trace_plot" : "trace_plot" - file = output_file(context, name, "svg") - CairoMakie.save(file, fig, size= (800, 200 * n_params)) + file = output_file(context, name, "png") + CairoMakie.save(file, fig, size= (800, 200 * n_params), px_per_unit=2) add_plot(context; - file = "$name.svg", + file = "$name.png", title = cumulative ? "Cumulative traces" : "Trace plots", description = cumulative ? """ For each iteration ``i``, shows the running average up to ``i``, @@ -268,10 +268,10 @@ function lcb(context) ax.xlabel = "β" ax.ylabel = "λ(β)" name = "local_barrier" - file = output_file(context, name, "svg") - CairoMakie.save(file, f) + file = output_file(context, name, "png") + CairoMakie.save(file, f, px_per_unit=2) add_plot(context; - file = "$name.svg", + file = "$name.png", title = "Local communication barrier", url_help = "https://pigeons.run/dev/output-pt/#Local-communication-barrier", description = """ @@ -319,10 +319,10 @@ function pigeons_progress(context; property, title, args...) mapping(:round, property) * visual(Lines) plot = draw(recipe) - file = output_file(context, "$(property)_progress", "svg") + file = output_file(context, "$(property)_progress", "png") CairoMakie.save(file, plot) add_plot(context; - file = "$(property)_progress.svg", + file = "$(property)_progress.png", title, args...) end From 390de9e787f701b785f12a33f01571f8f02b7b9a Mon Sep 17 00:00:00 2001 From: William Thompson Date: Wed, 3 Apr 2024 15:02:31 -0700 Subject: [PATCH 2/6] better sizing of plot outputs in HTML --- src/building_blocks.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/building_blocks.jl b/src/building_blocks.jl index f6ad0c1a..45d31bda 100644 --- a/src/building_blocks.jl +++ b/src/building_blocks.jl @@ -38,7 +38,7 @@ function add_plot(context; file, title, url_help = nothing, description = "", mo contents = """ $description ```@raw html - + 🔍 Full page $movie_link $info_link ``` """ From 053563d9effc3b653e6072ff9200eb27f867e7e4 Mon Sep 17 00:00:00 2001 From: Alexandre Bouchard Date: Mon, 15 Apr 2024 06:33:53 -0700 Subject: [PATCH 3/6] No-op --- docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/index.md b/docs/src/index.md index 4931ed1d..6d49dcc0 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -238,4 +238,4 @@ See our [Documenter.jl make file](https://github.com/Julia-Tempering/InferenceRe integrate InferenceReport into a broader documentation page. The key functions used are [`headless`](@ref), [`report_to_docs`](@ref) and -[`as_doc_page`](@ref). \ No newline at end of file +[`as_doc_page`](@ref). \ No newline at end of file From f951b297fd6a99cb575ed891bca6988e26e06e51 Mon Sep 17 00:00:00 2001 From: Alexandre Bouchard Date: Mon, 15 Apr 2024 08:31:21 -0700 Subject: [PATCH 4/6] Add test --- test/test_pdf.jl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/test_pdf.jl diff --git a/test/test_pdf.jl b/test/test_pdf.jl new file mode 100644 index 00000000..80297543 --- /dev/null +++ b/test/test_pdf.jl @@ -0,0 +1,22 @@ +@testset "PDF output" begin + + inputs, reproducibility_command = + @reproducible Inputs( + target = toy_mvn_target(2), + n_rounds = 4, + record = [traces; round_trip; record_default()]) + + pt = pigeons(inputs) + + context = report(pt; + view = false, + writer=InferenceReport.Documenter.LaTeX(platform = "docker"), + target_description = "Description", + reproducibility_command) + + @test isfile("$(context.options.exec_folder)/build/InferenceReport.pdf") + + @test length(context.generated_markdown) == + length(InferenceReport.default_postprocessors()) - 1 # MPI output + +end \ No newline at end of file From ce73bba1b7181aa8b0a07b0c2318cddd9cd7f1d9 Mon Sep 17 00:00:00 2001 From: Alexandre Bouchard Date: Mon, 15 Apr 2024 09:17:54 -0700 Subject: [PATCH 5/6] on github action CI, docker available out of the box on linux only --- test/test_pdf.jl | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/test/test_pdf.jl b/test/test_pdf.jl index 80297543..467f9a24 100644 --- a/test/test_pdf.jl +++ b/test/test_pdf.jl @@ -1,22 +1,28 @@ @testset "PDF output" begin - inputs, reproducibility_command = + if (get(ENV, "CI", "false") == "true") && !Sys.islinux() + + @warn "on github action CI, docker available out of the box on linux only" + + else + + inputs, reproducibility_command = @reproducible Inputs( target = toy_mvn_target(2), n_rounds = 4, record = [traces; round_trip; record_default()]) - pt = pigeons(inputs) - - context = report(pt; - view = false, - writer=InferenceReport.Documenter.LaTeX(platform = "docker"), - target_description = "Description", - reproducibility_command) + pt = pigeons(inputs) - @test isfile("$(context.options.exec_folder)/build/InferenceReport.pdf") + context = report(pt; + view = false, + writer=InferenceReport.Documenter.LaTeX(platform = "docker"), + target_description = "Description", + reproducibility_command) - @test length(context.generated_markdown) == - length(InferenceReport.default_postprocessors()) - 1 # MPI output + @test isfile("$(context.options.exec_folder)/build/InferenceReport.pdf") + @test length(context.generated_markdown) == + length(InferenceReport.default_postprocessors()) - 1 # MPI output + end end \ No newline at end of file From c5b2c6215094fd6b982b63477e52f8b90ba97358 Mon Sep 17 00:00:00 2001 From: Alexandre Bouchard Date: Mon, 15 Apr 2024 09:34:42 -0700 Subject: [PATCH 6/6] Add doc --- docs/src/index.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/src/index.md b/docs/src/index.md index 6d49dcc0..57a463e7 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -54,6 +54,14 @@ See `Examples` in the left side bar to see examples of such reports. See [`report`](@ref) for more information on the options available. +You may also generate a TeX/PDF version using +Documenter.jl's [TeX support](https://documenter.juliadocs.org/stable/man/other-formats/) +as follows: + +```@example pigeons +report(pt; writer=InferenceReport.Documenter.LaTeX(platform = "docker")) +``` + ### From MCMCChains