Full run example#
This file serves as a reference for a full run, in a python file instead of a notebook. This can be used on remote systems, e.g. in an HPC environement This example makes the following assumptions:
the global parameters for this run are specified as a yaml file under
./parameters.yamlthe underlying nbody input data has been generated by the THESAN simulation and resides under
<scratch>/Thesan/during the simulation, intermediate and output data is written to
<scratch>/thesan_run/(beware of the 100GB+ files this may generate)
from pathlib import Path
import os
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
import numpy as np
import beorn
# change the simulation-related paths here
SCRATCH_ROOT = Path("/xdisk/timeifler/yhhuang/BEoRN-v2/")
FILE_ROOT = Path("/xdisk/timeifler/yhhuang/Thesan/")
CACHE_ROOT = SCRATCH_ROOT / "thesan_run" / "cache"
OUTPUT_ROOT = SCRATCH_ROOT / "thesan_run" / "output"
PARAMETER_FILE = Path(".") / "parameters_thesan.yaml"
### Parameter setup
parameters = beorn.structs.Parameters.from_yaml(PARAMETER_FILE)
parameters.simulation.file_root = FILE_ROOT
parameters.solver.redshifts = np.sort(parameters.solver.redshifts)
### IO setup
loader = beorn.load_input_data.ThesanLoader(
parameters,
is_high_res = False # in our example we have used the Thesan-Dark-2 simulation which is the low-res counterpart to Thesan-Dark-1
)
cache_handler = beorn.io.Handler(file_root=CACHE_ROOT)
output_handler = beorn.io.Handler(file_root=OUTPUT_ROOT)
# redirect logs to a file under the OUTPUT_ROOT directory - this can be useful for cases where you want to retrace many parallel runs later on.
output_handler.save_logs(parameters)
### In a first step, we compute the radiation profiles around sources at all redshifts of interest
solver = beorn.precomputation.RadiationProfileSolver(parameters, loader.redshifts)
# the computation does not depend on the spatial information, so the profiles are reusable
# instead of recomputing them every time, we can reuse a cached version if available
profiles = solver.get_or_compute_profiles(cache_handler)
### In a second step, we use the precomputed profiles to paint the desired quantities onto the simulation grids
painter = beorn.painting.PaintingCoordinator(
parameters,
loader = loader,
cache_handler = cache_handler,
output_handler = output_handler
)
final_output = painter.paint_full(profiles)
# The final_output object contains all individual grids (corresponding to each computed quantity) for each redshift
# This object has been written to an .hdf5 format and can be inspected manually
# You can also load it from within your code by running:
output = output_handler.load_file(parameters, beorn.structs.TemporalCube)
# the data associated to this run is uniquely identified by the hash of the parameters - no need to manually specify the path