VideoRecorder

class fluidgym.wrappers.video_recorder.VideoRecorder(env: FluidEnvLike, filename: str, output_path: Path | None = None, render_kwargs: dict[str, Any] | None = None, env_ids: int | Sequence[int] | None = None, fps: int = 24)[source]

Bases: FluidWrapper

Render and save every episode of the environment as gif.

The frames returned by render() (the environment’s default render slice) are kept by the wrapper and written when the next episode starts or the environment is closed. For a vectorized environment, including a ParallelFluidEnv, each recorded environment gets its own gif.

Parameters:
  • env (FluidEnvLike) – The environment to wrap.

  • filename (str) – The base name of the gifs. Episode k is saved as <filename>_ep<k>.gif.

  • output_path (Path | None) – The directory to save the gifs to. If None, the current directory is used. Defaults to None.

  • render_kwargs (dict[str, Any] | None) – Keyword arguments of every render() call. Defaults to None.

  • env_ids (int | Sequence[int] | None) – The environments of a vectorized environment to record, each into its own gif (<filename>_env<i>_ep<k>.gif). None (the default) records all of them. Must be None for a single environment.

  • fps (int) – The frames per second of the gifs. Defaults to 24.

close() → None[source]

Save the recorded frames of the current episode and close the environment.

reset(seed: int | None = None, randomize: bool | None = None, domain_idx: int | Sequence[int] | None = None) → tuple[dict[str, Tensor], dict[str, Tensor]][source]

Resets the environment to an initial internal state, returning an initial observation and info.

Parameters:
  • seed (int | None) – The seed to use for random number generation. If None, the current seed is used.

  • randomize (bool | None) – Whether to randomize the initial state. If None, the default behavior is used.

  • domain_idx (int | Sequence[int] | None) – Index of the initial domain to load, one for all environments or one per environment of a vectorized environment. If None, the default behavior is used. Defaults to None.

Returns:

A tuple containing the initial observation and an info dictionary.

Return type:

tuple[dict[str, torch.Tensor], dict[str, torch.Tensor]]

step(action: Tensor) → tuple[dict[str, Tensor], Tensor, bool | Tensor, bool | Tensor, dict[str, Tensor]][source]

Run one timestep of the environment’s dynamics using the agent actions.

When the end of an episode is reached (terminated or truncated), it is necessary to call reset() to reset this environment’s state for the next episode.

Parameters:

action (torch.Tensor) – The action to take.

Returns:

  • tuple[

  • dict[str, torch.Tensor], torch.Tensor, bool, bool, dict[str, torch.Tensor]] – A tuple containing the observation, reward, terminated flag, truncated flag, and info dictionary.