sim_archive API

class rubin_scheduler.sim_archive.AnomalousOverheadFunc(seed, slew_scale, visit_scale=0.0, slew_loc=0.0, visit_loc=0.0)[source]

Bases: object

Callable to return random overhead.

Parameters:
  • seed (int) – Random number seed.

  • slew_scale (float) – The scale for the scatter in the slew offest (seconds).

  • visit_scale (float, optional) – The scale for the scatter in the visit overhead offset (seconds). Defaults to 0.0.

  • slew_loc (float, optional) – The location of the scatter in the slew offest (seconds). Defaults to 0.0.

  • visit_loc (float, optional) – The location of the scatter in the visit offset (seconds). Defaults to 0.0.

__call__(visittime, slewtime)[source]

Return a randomized offset for the visit overhead.

Parameters:
  • visittime (float) – The visit time (seconds).

  • slewtime (float) – The slew time (seconds).

Returns:

offset – Random offset (seconds).

Return type:

float

rubin_scheduler.sim_archive.add_make_scheduler_snapshot_args(parser)[source]

Add arguments needed for saving a scheduler to an argument parser.

Parameters:

parser (ArgumentParser)

Return type:

None

rubin_scheduler.sim_archive.check_opsim_archive_resource(archive_uri)[source]

Check the contents of an opsim archive resource.

Parameters:

archive_uri (str) – The URI of the archive resource to be checked.

Returns:

validity – A dictionary of files checked, and their validity.

Return type:

dict

rubin_scheduler.sim_archive.drive_sim(observatory, scheduler, archive_uri=None, label=None, tags=[], script=None, notebook=None, opsim_metadata=None, **kwargs)[source]

Run a simulation and archive the results.

Parameters:
  • observatory (ModelObservatory) – The model for the observatory.

  • scheduler (CoreScheduler) – The scheduler to use.

  • archive_uri (str, optional) – The root URI of the archive resource into which the results should be stored. Defaults to None.

  • label (str, optional) – The label for the simulation in the archive. Defaults to None.

  • tags (list of str, optional) – The tags for the simulation in the archive. Defaults to an empty list.

  • script (str) – The filename of the script producing this simulation. Defaults to None.

  • notebook (str, optional) – The filename of the notebook producing the simulation. Defaults to None.

  • opsim_metadata (dict, optional) – Extra metadata to store in the archive.

Returns:

  • observatory (ModelObservatory) – The model for the observatory.

  • scheduler (CoreScheduler) – The scheduler used.

  • observations (numpy.recarray) – The observations produced.

  • reward_df (pandas.DataFrame, optional) – The table of rewards. Present if record_rewards or scheduler.keep_rewards is True.

  • obs_rewards (pandas.Series, optional) – The mapping of entries in reward_df to observations. Present if record_rewards or scheduler.keep_rewards is True.

  • resource_path (ResourcePath, optional) – The resource path to the archive of the simulation. Present if archive_uri was set.

Notes

Additional parameters not described above will be passed into sim_runner.

If the archive_uri parameter is not supplied, sim_runner is run directly, so that drive_sim can act as a drop-in replacement of sim-runner.

In a jupyter notebook, the notebook can be saved for the notebook paramater using %notebook $notebook_fname (where notebook_fname is variable holding the filename for the notebook) in the cell prior to calling drive_sim.

rubin_scheduler.sim_archive.get_scheduler(config_repo, config_script, config_branch='main')[source]

Generate a CoreScheduler according to a configuration in git.

Parameters:
  • config_repo (str) – The git repository with the configuration.

  • config_script (str) – The configuration script path (relative to the repository root).

  • config_branch (str, optional) – The branch of the repository to use, by default “main”

Returns:

scheduler – An instance of the Rubin Observatory FBS.

Return type:

CoreScheduler

Raises:

ValueError – If the config file is invalid, or has invalid content.

rubin_scheduler.sim_archive.get_scheduler_instance_from_repo(config_repo, config_script, config_branch='main')[source]

Generate a CoreScheduler according to a configuration in git.

Parameters:
  • config_repo (str) – The git repository with the configuration.

  • config_script (str) – The configuration script path (relative to the repository root).

  • config_branch (str, optional) – The branch of the repository to use, by default “main”

Returns:

scheduler – An instance of the Rubin Observatory FBS.

Return type:

CoreScheduler

Raises:

ValueError – If the config file is invalid, or has invalid content.

rubin_scheduler.sim_archive.make_sim_archive_dir(observations, reward_df=None, obs_rewards=None, in_files={}, sim_runner_kwargs={}, tags=[], label=None, data_path=None, capture_env=True, opsim_metadata=None)[source]

Create or fill a local simulation archive directory.

Parameters:
  • observations (numpy.recarray) – The observations data, in the “obs” format as accepted and created by rubin_scheduler.scheduler.utils.SchemaConverter.

  • reward_df (pandas.DataFrame, optional) – The reward data, by default None.

  • obs_rewards (pandas.DataFrame, optional) – The observation rewards data, by default None.

  • in_files (dict, optional) – Additional input files to be included in the archive, by default {}.

  • sim_runner_kwargs (dict, optional) – Additional simulation runner keyword arguments, by default {}.

  • tags (list [str], optional) – A list of tags/keywords to be included in the metadata, by default [].

  • label (str, optional) – A label to be included in the metadata, by default None.

  • data_path (str or pathlib.Path, optional) – The path to the simulation archive directory, by default None.

  • capture_env (bool) – Use the current environment as the sim environment. Defaults to True.

  • opsim_metadata (dict) – Metadata to be included.

Returns:

data_dir – The temporary directory containing the simulation archive.

Return type:

pathlib.Path or tempfile.TemporaryDirectory

rubin_scheduler.sim_archive.read_archived_sim_metadata(base_uri, latest=None, num_nights=5, compilation_resource=None, verify_compilation=False)[source]

Read metadata for a time range of archived opsim output.

Parameters:
  • base_uri (str) – The base URI of the archive resource to be checked.

  • latest (str, optional) – The date of the latest simulation whose metadata should be loaded. This is the date on which the simulations was added to the archive, not necessarily the date on which the simulation was run, or any of the dates simulated. Default is today.

  • num_nights (int) – The number of nights of the date window to load.

  • compilation_resource (ResourcePath or str or None) – The ResourcePath to an hdf5 compilation of metadata.

  • verify_compilation (bool) – Verify that metadata in compilation corresponds to an existing resource, and the all existing resources have metadata. Defaults to False, which will work provided that the compilation is complete and correct up to the date of the last simulation it includes.

Returns:

sim_metadata – A dictionary of metadata for simulations in the date range.

Return type:

dict

rubin_scheduler.sim_archive.run_prenights(day_obs_mjd, archive_uri, scheduler_file=None, opsim_db=None, minutes_delays=(0, 1, 10, 60, 240), anomalous_overhead_seeds=(101, 102, 103, 104, 105), sim_nights=2, opsim_metadata=None)[source]

Run the set of scheduler simulations needed to prepare for a night.

Parameters:
  • day_obs_mjd (float) – The starting MJD.

  • archive_uri (str) – The URI of visits completed before this night.

  • scheduler_file (str, optional) – File from which to load the scheduler. None defaults to the example scheduler in rubin_sim, if it is installed. The default is None.

  • opsim_db (str, optional) – The file name of the visit database for visits preceeding the simulation. The default is None.

  • minutes_delays (tuple of float) – Delayed starts to be simulated.

  • anomalous_overhead_seeds (tuple of int) – Random number seeds to use for anomalous overhead runs.

  • sim_nights (int) – Number of nights to simulate. Defaults to 2.

  • opsim_metadata (dict) – Extra metadata for the archive

Return type:

None

rubin_scheduler.sim_archive.save_scheduler(scheduler, file_name)[source]

Save an instances of the scheduler in a pickle file, compressed according to its extension.

Parameters:
  • scheduler (CoreScheduler) – The scheduler to save.

  • file_name (str) – The file in which to save the schedulers.

Return type:

None

rubin_scheduler.sim_archive.transfer_archive_dir(archive_dir, archive_base_uri='s3://rubin-scheduler-prenight/opsim/')[source]

Transfer the contents of an archive directory to an resource.

Parameters:
  • archive_dir (str) – The path to the archive directory containing the files to be transferred.

  • archive_base_uri (str, optional) – The base URI where the archive files will be transferred to. Default is “s3://rubin-scheduler-prenight/opsim/”.

Returns:

resource_rpath – The destination resource.

Return type:

ResourcePath