cogwheel.sampling.Zeus¶
- class cogwheel.sampling.Zeus(posterior, run_kwargs=None, sample_prior=False, dir_permissions=493, file_permissions=420)¶
Bases:
SamplerSample a posterior or prior using
zeus.https://zeus-mcmc.readthedocs.io/en/latest/index.html.
run_kwargscan take kwargs tozeus.EnsembleSamplerzeus.EnsembleSampler.run_mcmczeus.EnsembleSampler.get_chain(discard, thin)
with the caveat that they must be JSON-serializable. Therefore: To use
callbacks, pass a list of the form[(callback_name, kwargs), ...]. To parallelize with a pool, pass a kwargprocesses(int). SeeZeus.DEFAULT_RUN_KWARGSfor examples. Note you can override these by editingzeus_sampler.run_kwargs.- Parameters:
- posteriorcogwheel.posterior.Posterior
Implements the prior and likelihood.
- run_kwargsdict
Keyword arguments for the sampler or its run method. Allowed keys depend on the particular sampler used.
- sample_priorFalse
Deprecated, will raise ValueError if it is not False.
- dir_permissions, file_permissionsoctal
Directory and file permissions.
Methods
Return whether the run completed successfully.
Keyword arguments to instantiate the class.
Name of the module that defines the instance's class.
Return a pathlib.Path object with a new run directory, following a standardized naming scheme for output directories.
Define for sampling classes which compute evidence.
Return a pandas.DataFrame with the posterior samples.
Return a new instance of the class, possibly updating init_kwargs.
Make a directory to save results and run sampler.
Return list of possible parameters to configure sampler, along with their default values.
Submit a parameter estimation run using the HTCondor scheduler.
Write class instance to json file.
Attributes
DEFAULT_RUN_KWARGSJSON_FILENAMEPROFILING_FILENAMELike
.posterior.prior.sampled_paramsbut the folded parameters have 'folded_' prepended.subclass_registry- static completed(rundir) bool¶
Return whether the run completed successfully.
- get_init_dict(**kwargs)¶
Keyword arguments to instantiate the class.
- get_module_name()¶
Name of the module that defines the instance’s class.
- get_rundir(parentdir)¶
Return a pathlib.Path object with a new run directory, following a standardized naming scheme for output directories. Directory will be of the form {parentdir}/{prior_name}/{eventname}/{RUNDIR_PREFIX}{run_id}
- Parameters:
- parentdiros.PathLike
Path to a directory where to store parameter estimation data.
- load_evidence() dict¶
Define for sampling classes which compute evidence.
Return a dict with the following items:
‘log_ev’ = log evidence from sampling
‘log_ev_std’ = log standard deviation of evidence
If using nested importance sampling (NIS), should also have:
‘log_ev_NIS’ = log evidence from nested importance sampling
‘log_ev_std_NIS’ = log standard deviation of NIS evidence
- load_samples()¶
Return a pandas.DataFrame with the posterior samples.
- reinstantiate(**new_init_kwargs)¶
Return a new instance of the class, possibly updating init_kwargs.
Values not passed will be taken from the current instance.
- run(rundir)¶
Make a directory to save results and run sampler.
- Parameters:
- rundiros.PathLike
Directory where to save output, will create if needed.
- run_kwargs_options()¶
Return list of possible parameters to configure sampler, along with their default values.
Refer to each sampler’s documentation for details. Sampler parameters not listed here are handled automatically by
cogwheel.- Returns:
- list of inspect.Parameter
- property sampled_params¶
Like
.posterior.prior.sampled_paramsbut the folded parameters have ‘folded_’ prepended.- Returns:
- list of str
- submit_condor(rundir, request_cpus=1, request_memory='8G', request_disk='1G', resuming=False, postprocess=True, **submit_kwargs)¶
Submit a parameter estimation run using the HTCondor scheduler.
This method generates ‘submit.sub’ and ‘executable.sh’ files, the user should provide any instructions for the submit file as **submit_kwargs.
- Parameters:
- rundirstr, os.PathLike
Run directory, e.g. from self.get_rundir
- request_cpus, request_memory, request_diskint or str
Specifications in the HTCondor submit file.
- resumingbool
Whether to attempt resuming a previous run if rundir already exists.
- postprocessbool
Whether to perform convergence tests to the run after sampling. See
postprocessing.postprocess_rundir.- **submit_kwargs
Further options to include in the HTCondor submit file. Do not pass executable, output, error, log, queue, which will be dealt with automatically.
- submit_lsf(rundir, n_hours_limit=48, memory_per_task='32GB', resuming=False, bsub_cmds=(), postprocess=True)¶
- Parameters:
- rundirstr, os.PathLike
Run directory, e.g. from self.get_rundir
- n_hours_limitint
Number of hours to allocate for the job.
- memory_per_taskstr
Determines the memory and number of cpus.
- resumingbool
Whether to attempt resuming a previous run if rundir already exists.
- bsub_cmdstuple of str
Strings with BSUB commands.
- postprocessbool
Whether to perform convergence tests to the run after sampling. See
postprocessing.postprocess_rundir.
- submit_slurm(rundir, n_hours_limit=48, memory_per_task='32G', resuming=False, sbatch_cmds=(), postprocess=True)¶
- Parameters:
- rundirstr, os.PathLike
Run directory, e.g. from self.get_rundir
- n_hours_limitint
Number of hours to allocate for the job.
- memory_per_taskstr
Determines the memory and number of cpus.
- resumingbool
Whether to attempt resuming a previous run if rundir already exists.
- sbatch_cmdstuple of str
Strings with SBATCH commands.
- postprocessbool
Whether to perform convergence tests to the run after sampling. See
postprocessing.postprocess_rundir.
- to_json(dirname, basename=None, *, dir_permissions=493, file_permissions=420, overwrite=False)¶
Write class instance to json file.
It can then be loaded with read_json.