OmniSafe Offline Data#

Data Collector#

Documentation

class omnisafe.common.offline.OfflineDataCollector(size, env_name)[source]#

A class for collecting offline data.

Example

>>> # please change agent path and env name
>>> env_name = 'SafetyPointCircle1-v0'
>>> size = 2_000_000
>>> agents = [
>>>     ('./runs/PPO', 'epoch-500', 1_000_000),
>>>     ('./runs/CPO', 'epoch-500', 1_000_000),
>>> ]
>>> save_dir = './data'
>>> col = OfflineDataCollector(size, env_name)
>>> for agent, model_name, size in agents:
>>>     col.register_agent(agent, model_name, size)
>>> col.collect(save_dir)

Initialize the data collector.

Parameters:
  • size (int) – The total number of data to collect.

  • env_name (str) – The name of the environment.

collect(save_dir)[source]#

Collect data from the registered agents.

Parameters:

save_dir (str) – The directory to save the collected data.

Return type:

None

register_agent(save_dir, model_name, size)[source]#

Register an agent to the data collector.

Parameters:
  • save_dir (str) – The directory of the agent.

  • model_name (str) – The name of the model.

  • size (int) – The number of data to collect from this agent.

Return type:

None

Offline Dataset#

Documentation

class omnisafe.common.offline.OfflineDataset(dataset_name, batch_size=256, gpu_threshold=1024, device=DEVICE_CPU)[source]#

A dataset for offline algorithms.

Initialize the dataset.

Parameters:
  • dataset_name (str) –

    The name of the dataset. could be one of the following:

    • SafetyPointCircle1-v0_mixed_0.5

    • some local .npz file

  • batch_size (int) – The batch size of the dataset.

  • gpu_threshold (int) – The threshold of size(MB) of the dataset to be loaded on GPU.

  • device (device) – The device to load the dataset.

sample()[source]#

Sample a batch of data from the dataset.

Return type:

tuple[Tensor, ...]

class omnisafe.common.offline.OfflineDatasetWithInit(dataset_name, batch_size=256, gpu_threshold=1024, device=DEVICE_CPU)[source]#

A dataset with first observation in every episodes for offline algorithms.

Initialize the dataset.

Parameters:
  • dataset_name (str) –

    The name of the dataset. could be one of the following:

    • SafetyPointCircle1-v0_mixed_0.5

    • some local .npz file

  • batch_size (int) – The batch size of the dataset.

  • gpu_threshold (int) – The threshold of size(MB) of the dataset to be loaded on GPU.

  • device (device) – The device to load the dataset.

sample()[source]#

Sample a batch of data from the dataset.

Return type:

tuple[Tensor, ...]