Checking Mera's Claims

How do you know that Mera computes what it says? This page takes each claim of the Mera.jl paper and gives you a few lines of code that check it on a public test simulation. Each check ends in true. Next to it are the test that checks the same claim more thoroughly and the page that explains it. Everything runs on a laptop, with test simulations of a few MB each.

This page checks itself

Every code block on this page runs in Mera's test suite, in order, and each check must return true (test 93). The continuous integration runs it on every push (fixtures workflow), so a change to Mera that breaks a claim breaks the tests.

For reviewers of the paper

The version under review is the registered release, Mera 1.11. The readers for other codes (PLUTO, Athena++, FLASH, Chombo, AMReX/Quokka, GADGET, AREPO) live on a development branch. The paper mentions them as work in progress, and they are not part of the review.

To save you time, here is a path through the review and where to find each item of the review checklist.

stepwhat
1install Mera and run the tests without data (section 1)
2download the test simulations and run the tests again, which also runs every check on this page (about 8 minutes on a laptop)
3read section 2 and try the checks you want to see for yourself
checklist itemwhere
Repository, Licensegithub.com/ManuelBehrendt/Mera.jl, MIT (LICENSE)
Contribution and authorshipone author; contributors are named in the paper's acknowledgements and in the git history
Substantial scholarly effortdeveloped since 2018, about 2500 commits, about 56 000 lines of Julia, about 75 documentation pages; used in three refereed papers and seven theses (see the paper)
Data sharingthe fifteen test simulations are public (The Test Simulations), with the RAMSES namelists that made them in testdata/
Reproducibilitythis page; the Gallery recipes pin their environments; every saved result gets a record of where it came from (section 2.12)
Human and animal researchdoes not apply
Installationsection 1
Functionalitysection 2, and the checks on real simulations in section 3
Performancesection 2.14 and Measured Performance, measured on a 53 GB research output, with the raw reports in benchmark_results/
Statement of needthe paper; Why Mera? in the README
Installation instructionsInstallation in the README; Julia's package manager installs every dependency
Example usageFirst Steps, the Gallery and the tutorials in the menu
Functionality documentationthe API reference, a docstring for every exported function
Automated testssection 1, the test folder, continuous integration
Community guidelinesCONTRIBUTING.md (contributing, reporting problems, getting help), code of conduct, issues, discussions

Questions about the review are welcome in the review issue.

1. Install and run the tests

Install Mera (Julia 1.10 or later) and run its tests:

pkg> add Mera
pkg> test Mera

This runs the tests that need no data: code quality (Aqua), the unit system, the types, the reader interface, input and output, the region algebra on synthetic cells, the clump finder on a synthetic field with a known answer, and other analytic checks. The same tests run in continuous integration on Linux, macOS and Windows with Julia 1.10 to 1.13.

Then download the fifteen public test simulations (about 300 MB) and run the tests again:

julia> using Mera
julia> download_testdata()      # into ~/.julia/mera_testdata
pkg> test Mera

The tests find the simulations by themselves and say so at the start. Each simulation was run with RAMSES for this purpose and has an answer that is known before you load it (The Test Simulations):

  • the Sedov blast radius grows as t^(2/5) over seven snapshots
  • a magnetic shock tube keeps Bx constant, as a divergence-free field must
  • an ionised sphere has its front at the analytic Strömgren radius
  • three runs reproduce the reference values that RAMSES publishes for its own tests
  • RAMSES outputs rewritten for another number of MPI processes keep every value bit for bit

This run also executes every code block of section 2. Tests that need the author's research simulations, which are not public, skip themselves; the summary at the end lists them as "Broken".

2. Check the claims yourself

Start Julia with four threads (julia -t 4), so that the check of the thread count in section 2.10 has something to compare. Every block continues the session of the blocks before it.

using Mera
sedov = download_testdata("sedov3d_amr")   # a blast wave in a periodic box, 7 outputs, 2 MB
info  = getinfo(7, sedov)
gas   = gethydro(info)                     # a table, one row per leaf cell

The units of this run are cm, g and s, so the numbers below are small.

2.1 A known answer: the Sedov blast

The radius of a point explosion grows as t^(2/5). The shock compresses the gas, so the radius of the shell is the largest distance of a cell denser than 1.5 times the ambient gas:

t = Float64[]; R = Float64[]
for n in 2:7
    g = gethydro(getinfo(n, sedov))
    r = getvar(g, :r_sphere_periodic, center=[0, 0, 0])   # the blast sits at a box corner
    push!(t, g.info.time)
    push!(R, maximum(r[getvar(g, :rho) .> 1.5]))
end
slope = ([ones(length(t)) log.(t)] \ log.(R))[2]        # least-squares fit of log R against log t
isapprox(slope, 2/5; rtol=0.1)                           # true

Test 76 runs this and the other known answers listed in section 1.

2.2 Every kind of RAMSES data

The released version reads RAMSES […] gas […], together with gravity, radiation, particles, sinks and clumps. Mera.jl reads all of it into Julia tables.

blobs = getinfo(4, download_testdata("clumps3d"))           # gas, gravity, clumps
stars = getinfo(7, download_testdata("sedov3d_grav_part"))  # gas, gravity, particles
grav   = getgravity(blobs)
clumps = getclumps(blobs)
part   = getparticles(stars)
sinks  = getsinks(getinfo(2, download_testdata("sinks3d")))
rt     = getrt(getinfo(7, download_testdata("stromgren3d")))
all(!isempty, (grav.data, clumps.data, part.data, sinks.data, rt.data))   # true

Tests 82 and 76. Pages: First Steps, Test Simulations.

2.3 Any quantity in any unit

It selects regions, derives quantities in any unit […].

The same quantity in two units differs by the unit's factor, and a mass is the same in grams and in solar masses:

rho_code = getvar(gas, :rho)                # code units
rho_cgs  = getvar(gas, :rho, :g_cm3)
rho_cgs ≈ rho_code .* info.scale.g_cm3 &&
    isapprox(msum(gas, :Msol) * info.constants.Msol, msum(gas, :g); rtol=1e-12)   # true

The strong test of the units is a known answer in physical units: the Strömgren sphere in test 76 must reach its analytic radius in kpc at the analytic time in Myr. Tests 02 and 70 check every unit. Page: Units and Constants.

2.4 Maps from any angle

[…] makes maps from any angle […].

A map of the surface density holds the whole mass, seen face-on or from any other direction:

pixel_area(m) = (m.pixsize * info.scale.cm)^2
map_mass(m)   = sum(m.maps[:sd]) * pixel_area(m)
face = projection(gas, :sd, :g_cm2; pxsize=[0.005, :cm])
side = projection(gas, :sd, :g_cm2; inclination=60, azimuth=30, pxsize=[0.005, :cm])
isapprox(map_mass(face), msum(gas, :g); rtol=1e-12) &&
    isapprox(map_mass(side), msum(gas, :g); rtol=1e-12)   # true

Test 68 checks the ways to set the angle. Pages: Gas projections, Off-axis projections, Off-axis cheatsheet.

2.5 Volume renderings

[…] volume renderings […].

Mera defines the opacity per unit length, so the picture does not change when the pixels get smaller:

coarse = volumerender(gas, :rho; inclination=60, pxsize=[0.005, :cm])
fine   = volumerender(gas, :rho; inclination=60, pxsize=[0.0025, :cm])
mean_opacity(v) = sum(v.alpha) / length(v.alpha)
isapprox(mean_opacity(coarse), mean_opacity(fine); rtol=0.01)   # true

Test 84 checks the opacity law 1 − exp(−σL) on a uniform slab. Page: Volume Rendering.

2.6 Profiles

[…] profiles […].

A radial profile of the mass holds the whole mass:

p = profile(gas, :r_sphere; weight=:mass, center=[0, 0, 0], nbins=20)
isapprox(sum(p.sum), msum(gas); rtol=1e-12)   # true

Test 42. Page: Profiles and Phase Diagrams.

2.7 Clump catalogues

[…] clump catalogues […].

The simulation clumps3d holds four dense blobs, so a clump finder must return four:

cat = clumpfind(gethydro(blobs),
                ThresholdFoF(:rho; threshold=10, threshold_unit=:g_cm3, linking_length=0.02);
                pos_unit=:cm)
length(cat) == 4 && length(clumps.data) == 4    # true: Mera's finder and RAMSES's agree

Tests 54 and 40 compare the finders with a synthetic field whose clumps are known. Pages: Clump finding, on synthetic data.

2.8 Movies

[…] and movies.

movie = getmovie(sedov, :sd; unit=:g_cm2, pxsize=[0.01, :cm])
gif   = joinpath(mktempdir(), "sedov.gif")
savemovie(movie, gif)
length(movie.frames) == 7 && isfile(gif * ".meta.json")   # true: one frame per output, and a record

Test 51. Page: Movies.

2.9 A cell cut by a region's edge counts with the share inside it

For a region given as a value, such as sphere(10), Mera.jl keeps the share of each cell that lies inside, also when regions are combined and filtered, so a region and the rest of the volume add up exactly. The share is exact for a box and sampled for other shapes.

ball    = sphere(0.1; center=[:bc], range_unit=:cm)
inside  = msum(subregion(gas, ball), :g)
outside = msum(subregion(gas, !ball), :g)
isapprox(inside + outside, msum(gas, :g); rtol=1e-12)   # true

For other shapes Mera.jl counts how many of 8 × 8 × 8 points lie inside, only in the cells that the edge cuts. So the volume of a box is exact, and that of a sphere is right to the sampling:

box = cuboid(xrange=[-0.1, 0.1], yrange=[-0.1, 0.1], zrange=[-0.1, 0.1],
             center=[:bc], range_unit=:cm)
volume(region) = sum(getvar(subregion(gas, region), :volume, :cm3))
isapprox(volume(box), 0.2^3; rtol=1e-12) &&
    isapprox(volume(ball), 4/3 * π * 0.1^3; rtol=1e-3)   # true

Tests 55 (every shape against its analytic volume, combinations, complements) and 75. Pages: How the numbers are computed, Subregions cheatsheet.

2.10 Selections return a complete dataset, the same for any thread count

Selections take a table and return one, cut in all columns alike, so the result is again a complete dataset.

dense = filterdata(gas, Above(:rho, 1; unit=:g_cm3))
typeof(dense) == typeof(gas) && msum(dense, :g) < msum(gas, :g)   # true

A map made with one thread and with four is the same, bit for bit:

one  = projection(gas, :sd, :g_cm2; pxsize=[0.005, :cm], max_threads=1)
four = projection(gas, :sd, :g_cm2; pxsize=[0.005, :cm], max_threads=4)
one.maps[:sd] == four.maps[:sd]   # true

Tests 56 and 90. Pages: Masking and Filtering, Reproducibility.

2.11 Each kind of data has its own type

Multiple dispatch picks the method by the kind of data […]. getvar(gravity, gas, :Fg) takes the acceleration from gravity and the mass from the gas. […] a function written once for a parent type, such as msum for all types that hold mass, serves every type below it.

g4 = gethydro(blobs)
a  = sqrt.(getvar(grav, :ax).^2 .+ getvar(grav, :ay).^2 .+ getvar(grav, :az).^2)
getvar(grav, g4, :Fg) ≈ getvar(g4, :mass) .* a &&
    which(msum, (typeof(gas), Symbol)) == which(msum, (typeof(part), Symbol))   # true

Test 81 checks that the type figure in the paper matches the code. Page: How the numbers are computed.

2.12 A record beside every saved result

Mera files, exported maps and tables, clump catalogues and movies get a small JSON file beside them. […] The record holds the snapshot, the units, the package versions, the thread count and checksums of the file, of the run's input files and, when Julia knows it, of the script.

dir  = mktempdir()
file = joinpath(dir, "map.h5")
exportdata(face, file)
record = readsidecar(file)
record.status == :unchanged && !isempty(record.data["input_files"])   # true

bundle checks each file against the checksum in its record and describes the folder as an RO-Crate. datacite prepares the metadata of the run for a DOI:

crate = bundle(dir; title="A Sedov blast", creators=["Doe, Jane"])
meta  = datacite(simulationrecord(sedov); title="A Sedov blast", creators=["Doe, Jane"])
isfile(crate) && haskey(meta, "relatedIdentifiers")   # true

A file changed after it was written no longer matches its record:

open(io -> write(io, 0x00), file, "a")
readsidecar(file).status == :changed   # true

Tests 89, 91 and 92. Pages: Sharing Results and Sidecars, Provenance.

2.13 RAMSES restarts on any number of processes

repartition rewrites an output bit for bit so that RAMSES can restart on any number of MPI processes, and writeramses writes one from Mera data.

RAMSES itself stops when the number of processes differs from the one that wrote the output.

three = mktempdir()
repartition(7, sedov, 3; outpath=three)          # written by 8 processes, now for 3
c = compareramses(7, sedov, three)
c.same_tree && all(v -> all(iszero, v), values(c.maxdiff))   # true
written = joinpath(mktempdir(), "run")
writeramses(2; hydro=gas, outpath=written)       # from the table in memory
c = compareramses(7, sedov, written; leaves_only=true)
c.same_tree && all(v -> all(iszero, v), values(c.maxdiff))   # true

Test 86 does this for four simulations, to 1 and 7 processes and back. Page: RAMSES Restart.

2.14 Mera files: smaller, and faster to load

A Mera file stores these tables, compressed in one JLD2 file. It can be much smaller than the original and reloads much faster, but it is read whole.

The file holds the same table:

merafiles = mktempdir()
savedata(gas, merafiles, :write)
loaddata(7, merafiles, :hydro).data == gas.data   # true

and it is smaller than the RAMSES files of the gas, which also store every parent cell:

output     = joinpath(sedov, "output_00007")
ramses_gas = filter(f -> occursin(r"^(amr|hydro)_", basename(f)), readdir(output; join=true))
mera_file  = joinpath(merafiles, "output_00007.jld2")
sum(filesize, ramses_gas) > filesize(mera_file)   # true

How much smaller and faster depends on the simulation: on its refinement structure, which sets how many parent cells RAMSES stores besides the leaves, on the number of quantities and on how well they compress. That is why the paper gives no factor, and why the test simulations, a few MB each, are too small to show it.

Measured Performance shows it on a real output instead: a Milky-Way run of the AVALON project, 53 GB in 5120 files, read at full resolution. There the Mera file is 4.2 times smaller, reading it again is 23 times faster, and the peak memory is 1.9 times lower. That simulation is not public, so these numbers cannot be rerun, but the raw reports of every measurement are in the repository (benchmark_results/), and the page shows the function to measure the same on any output. Test 10. Page: Mera Files.

2.15 Readers for other codes

A reader for another code needs two functions […]. register_reader! connects it to getinfo, gethydro and getparticles.

There is no second code in the release to show this on. Test 62 registers a small reader for a made-up code and checks that getinfo and gethydro reach it. Page: Adding a Reader.

2.16 Calling Mera from Python

Python users can call it through JuliaCall.

Calling Mera from Python shows how: Mera's functions are called from a Python session, and columns and maps come back as NumPy arrays. The example is Python, so test 93 cannot run it; the continuous integration runs it on every push instead, on the same Sedov blast (test/python/juliacall_example.py).

3. More evidence in the documentation

Several pages of the documentation check Mera against an answer known in advance, on real simulations. Most of these simulations are not public, so you can read the checks and their output but not rerun them; the public checks in section 2 cover the same functions.

pagewhat it checks
RAMSES RestartRAMSES itself runs on the rewritten files. Four checks: the same files RAMSES writes, the same values, the same data inside RAMSES, and the same evolution to round-off ($10^{-15}$ for the gas), the difference RAMSES shows when it restarts from its own files. Also the result tables of the RAMSES validation suite run on rewritten outputs
Clump finding on synthetic dataa field whose clumps are known; every finder scored on how well it recovers them, and an unbound hot clump that the boundedness check must reject
Magnetic Fieldsa shock tube in which Bx must stay constant to machine precision, a check of how the reader turns the face values of RAMSES into cell values
Gas subregions, step 8zones of a real galaxy that add up to the mass of the disc
Gravity subregionsa combined region (a slab minus a sphere) against its analytic volume, to 0.02 %, and a box to $10^{-15}$
Off-axis projectionsthe stellar mass in the frame over a full camera orbit, and a table of the guarantees of the page with the tests that hold them
Particle projectionsa surface density map whose pixels times their area give the particle mass
The Test Simulationseach public simulation with its known answer and the test that checks it
How the numbers are computedevery derived quantity written out as a formula, transcribed from the source code
Measured Performancereading, memory, disk and projection measured on a 53 GB research output, with the raw reports in the repository

4. What you cannot rerun

  • Figure 1 shows a galaxy of the AVALON project. The simulation is not public yet, so the figure cannot be reproduced. The checks in section 2.4 use the same function.
  • The memory figure (167 million cells with five quantities in about 12 GB) and the measurements in Measured Performance are from AVALON simulations. Their raw reports are in the repository, and usedmemory(gas) gives the size of any table.
  • The session in the paper needs a galaxy. All its functions appear in section 2.
  • Tests that need the author's simulations run before each release on the author's laptop. Every claim above has a check here that runs on public data.

5. Questions

If something on this page does not work as described, that is a bug. Please open an issue, or ask in the discussions.