COMPS.Data.Simulation module

class COMPS.Data.Simulation.Simulation(name, experiment_id=None, description=None, configuration=None)[source]

Bases: TaggableEntity, CommissionableEntity, RelatableEntity, SerializableEntity

Represents a single simulation run.

Contains various basic properties accessible by getters (and, in some cases, +setters):

  • id

  • +experiment_id

  • +name

  • +description

  • owner

  • date_created

  • last_modified

  • state

  • error_message

Also contains “child objects” (which must be specifically requested for retrieval using the QueryCriteria.select_children() method of QueryCriteria):

  • tags

  • configuration

  • files

  • hpc_jobs

property id
property experiment_id
property name
property description
property owner
property date_created
property last_modified
property state
property error_message
property tags
property configuration
property files
property hpc_jobs
classmethod get(id=None, query_criteria=None)[source]

Retrieve one or more Simulations.

Parameters:
  • id – The id (str or UUID) of the Simulation to retrieve

  • query_criteria – A QueryCriteria object specifying basic property filters and tag-filters to apply to the set of Simulations returned, as well as which properties and child-objects to fill for the returned Simulations

Returns:

A Simulation or list of Simulations (depending on whether ‘id’ was specified) with basic properties and child-objects assigned as specified by ‘query_criteria’

refresh(query_criteria=None)[source]

Update properties of an existing Simulation from the server.

Parameters:

query_criteria – A QueryCriteria object specifying which properties and child-objects to refresh on the Simulation

save(return_missing_files=False, save_semaphore=None)[source]

Save a single Simulation. If it’s a new Simulation, an id is automatically assigned.

Parameters:

return_missing_files – A boolean that determines the behavior when the Simulation being saved contains a SimulationFile to be saved by md5 checksum (i.e. without uploading the data) that is not yet in COMPS. If true, when there are such files, return an array of UUIDs representing the md5 checksums of the missing files. If false, raise an error when there are any such files.

classmethod get_save_semaphore()[source]
static save_all(save_batch_callback=<function Simulation.<lambda>>, return_missing_files=False, save_semaphore=None)[source]

Batch-save all unsaved Simulations.

Simulations are saved in batches of at most ‘__max_sim_batch_count’ and with a maximum request size of ‘__max_sim_batch_request_size_kb’.

Parameters:
  • save_batch_callback – Callback to call whenever a request to save a batch of Simulations completes. Default behavior is to print a single ‘.’ to the console. If the callback supplied takes 1 argument, the number of Simulations saved so far will be passed when it is called.

  • return_missing_files – A boolean that determines the behavior when any of the Simulations being saved contains a SimulationFile to be saved by md5 checksum (i.e. without uploading the data) that is not yet in COMPS. If true, when there are such files, return an array of UUIDs representing the md5 checksums of the missing files. If false, raise an error when there are any such files.

add_file(simulationfile, file_path=None, data=None, upload_callback=<function Simulation.<lambda>>)[source]

Add a SimulationFile to a Simulation.

The contents of the file to add can be specified either by providing a path to the file or by providing the actual data as a byte-array. Alternately, if the file/data is already in COMPS, you can skip uploading it again and just provide a SimulationFile that contains the md5 checksum of the data.

If the file exceeds AssetManager.large_asset_upload_threshold bytes in size, the file will be uploaded immediately, separately from the saving of the main Simulation. This allows saving of arbitrarily-large files while avoiding potential timeouts or having to start from scratch in case the upload is interrupted by network issues.

NOTE: providing both file/data and an md5 is considered invalid, as providing the md5 implies the caller knows the file/data is already in COMPS and doesn’t need to be uploaded again.

Parameters:
  • simulationfile – A SimulationFile containing the metadata for the file to add.

  • file_path – The path to the file to add.

  • data – The actual bytes of data to add.

  • upload_callback – Callback to call whenever a large file upload completes saving of a chunk of the file. Default behavior is to print a single ‘.’ to the console. If the callback supplied takes 1 argument, the number of bytes saved so far will be passed when it is called.

retrieve_output_files(paths, job=None, as_zip=False)[source]

Retrieve output files associated with this Simulation.

This essentially combines the functionality of retrieve_output_file_info() and retrieve_output_filess_from_info(), and can be used if user doesn’t care about specific metadata related to the files being retrieved.

Parameters:
  • paths – Partial paths (relative to the working directory) of the output files to retrieve. If ‘as_zip’ is true, this can be None/empty or not specified, and all output files will be included in the zip returned.

  • job – The HpcJob associated with the given Simulation to retrieve assets for. If not specified, will default to the last HpcJob chronologically.

  • as_zip – A boolean controlling whether the output files are returned individually or as a single zip-file (useful for attaching to an e-mail, etc).

Returns:

If ‘as_zip’ is true, returns a single byte-array of a zip-file; otherwise, returns a list of byte-arrays of the output files retrieved, in the same order as the ‘paths’ parameter.

retrieve_output_file_info(paths, job=None)[source]

Retrieve OutputFileMetadata about output files associated with this Simulation.

Parameters:
  • paths – Partial paths (relative to the working directory) of the output files to retrieve. If None/empty or not specified, will default to return all output files.

  • job – The HpcJob associated with the given Simulation to retrieve output files for. If not specified, will default to the last HpcJob chronologically.

Returns:

A list of OutputFileMetadata objects for the output files to retrieve, in the same order as the ‘paths’ parameter.

retrieve_output_files_from_info(metadata, job=None, as_zip=False)[source]

Actually retrieve the output files associated with this Simulation.

Parameters:
  • metadata – A list of OutputFileMetadata objects representing the output files to retrieve associated with this Simulation.

  • job – The HpcJob associated with the given Simulation to retrieve output files for. This should match the ‘job’ provided to the retrieve_output_file_info() call. If not specified, will default to the last HpcJob chronologically.

  • as_zip – A boolean controlling whether the output files are returned individually or as a single zip-file (useful for attaching to an e-mail, etc).

Returns:

If ‘as_zip’ is true, returns a single byte-array of a zip-file; otherwise, returns a list of byte-arrays of the output files retrieved, in the same order as the ‘paths’ parameter.

static static_retrieve_output_files(sim_id, paths, job=None, as_zip=False)[source]
class COMPS.Data.Simulation.SimulationState(value)[source]

Bases: Enum

An enumeration representing the current state of a Simulation

Created = 0
CommissionRequested = 1
Provisioning = 2
Commissioned = 3
Running = 4
Retry = 5
Succeeded = 6
Failed = 7
CancelRequested = 8
Canceled = 9