holodeck.librarian.gen_lib
Library generation interface.
This file can be run from the command-line to generate holodeck libraries, and also provides some
API methods for quick/easy generation of simulations. In general, these methods are designed to
run simulations for populations constructed from parameter-spaces (i.e.
_Param_Space
subclasses).
This script can be run by executing:
python -m holodeck.librarian.gen_lib <ARGS>
Run python -m holodeck.librarian.gen_lib -h
for usage information.
- holodeck.librarian.gen_lib.main()[source]
Parent method for generating libraries from the command-line.
This function requires
mpi4py
for parallelization.This method does the following:
Loads arguments from the command-line (
args
, via_setup_argparse()
).The
output
directory is created as needed, along with thesims/
andlogs/
subdirectories in which the simulation datafiles and log output files are saved.
Sets up a
logging.Logger
instance for each processor.Constructs the parameter space specified by
args.param_space
. If this run is being resumed, then the param-space is loaded from an existing save file in the output directory.Samples from the parameter space are allocated to all processors.
Each processor iterates over it’s allocated parameters, calculates populations, saves them to files in the output directories. This is handled in
run_sam_at_pspace_num()
.All of the individual simulation files are combined using
holodeck.librarian.combine.sam_lib_combine()
.
- Parameters:
None –
- Return type:
None
- holodeck.librarian.gen_lib.run_sam_at_pspace_num(args, space, pnum)[source]
Run a given simulation (index number
pnum
) in thespace
parameter-space.This function performs the following:
Constructs the appropriate filename for this simulation, and checks if it already exist. If the file exists and the
args.recreate
option is not specified, the function returnsTrue
, otherwise the function runs this simulation.Calls
space.model_for_sample_number
to generate the semi-analytic model and hardening instances; see the functionholodeck.librarian.libraries._Param_Space.model_for_sample_number()
.Calculates populations and GW signatures from the SAM and hardening model using
holodeck.librarian.libraries.run_model()
, and saves the results to an output file.Optionally: some diagnostic plots are created in the
make_plots()
function.
- Parameters:
args (
argparse.ArgumentParser
instance) – Arguments from the gen_lib_sams.py script. NOTE: this should be improved.space (
holodeck.librarian.libraries._Param_space
instance) – Parameter space from which to construct populations.pnum (int) – Which parameter-sample from
space
should be run.
- Returns:
rv (bool) –
True
if this simulation was successfully run,False
otherwise.sim_fname (
pathlib.Path
instance) – Path of the simulation save file.
- holodeck.librarian.gen_lib._setup_argparse(*args, **kwargs)[source]
Setup the argument-parser for command-line usage.
- Parameters:
*args (arguments) –
**kwargs (keyword arguments) –
- holodeck.librarian.gen_lib._setup_log(comm, args)[source]
Setup up the logging module logger for output messaging.
Arguemnts
comm args
- returns:
log
- rtype:
logging.Logger
instance
- holodeck.librarian.gen_lib.make_plots(args, data, sim_fname)[source]
Generate diagnostic plots from the given simulation data and save to file.