Simulator#

The Simulator owns the physics solvers and the coupler, and advances them each time you call scene.step(). It is configured by SimOptions (timestep, gravity, substeps, differentiable mode) passed to the scene as sim_options, and built automatically when the scene builds.

Options#

class genesis.options.solvers.SimOptions(*, dt: float = 0.01, substeps: int = 1, substeps_local: int | None = None, gravity: tuple[float, float, float] = (0.0, 0.0, -9.81), floor_height: float = 0.0, requires_grad: bool = False) None[source]#

Options configuring the top-level simulator.

Note

  1. SimOptions specifies the global settings for the simulator. Some parameters exist both in SimOptions and SolverOptions. In this case, if such parameters are given in SolverOptions, it will override the one specified in SimOptions for this specific solver. For example, if dt is only given in SimOptions, it will be shared by all the solvers, but it’s also possible to let a solver run at a different temporal speed by setting its own dt to be a different value.

  2. In differentiable mode, substeps_local must be divisible by substeps, as external command is input per step, but substep. If requires_grad is False, we can use arbitrary substeps_local.

Parameters:
  • dt (float, optional) – Time duration for each simulation step in seconds. Defaults to 1e-2.

  • substeps (int, optional) – Number of substeps per simulation step. Defaults to 1.

  • substeps_local (int, optional) – Number of substeps stored in GPU memory. Defaults to None. This is used for differentiable mode.

  • gravity (tuple, optional) – Gravity force in N/kg. Defaults to (0.0, 0.0, -9.81).

  • floor_height (float, optional) – Height of the floor in meters. Defaults to 0.0.

  • requires_grad (bool, optional) – Whether to enable differentiable mode. Defaults to False.

  • use_hydroelastic_contact (bool, optional) – Whether to use hydroelastic contact. Defaults to False.

Simulator#

class genesis.engine.simulator.Simulator(scene: Scene, options: SimOptions, tool_options: ToolOptions, rigid_options: RigidOptions, kinematic_options: KinematicOptions, mpm_options: MPMOptions, sph_options: SPHOptions, fem_options: FEMOptions, sf_options: SFOptions, pbd_options: PBDOptions, coupler_options: BaseCouplerOptions)[source]#

Bases: RBC

A simulator is a scene-level simulation manager, which manages all simulation-related operations in the scene, including multiple solvers and the inter-solver coupler.

Parameters:
  • scene (gs.Scene) – The scene object that the simulator is associated with.

  • options (gs.SimOptions) – A SimOptions object that contains all simulator-level options.

  • tool_options (gs.ToolOptions) – A ToolOptions object that contains all the options for the ToolSolver.

  • rigid_options (gs.RigidOptions) – A RigidOptions object that contains all the options for the RigidSolver.

  • mpm_options (gs.MPMOptions) – An MPMOptions object that contains all the options for the MPMSolver.

  • sph_options (gs.SPHOptions) – An SPHOptions object that contains all the options for the SPHSolver.

  • fem_options (gs.FEMOptions) – An FEMOptions object that contains all the options for the FEMSolver.

  • sf_options (gs.SFOptions) – An SFOptions object that contains all the options for the SFSolver.

  • pbd_options (gs.PBDOptions) – A PBDOptions object that contains all the options for the PBDSolver.

  • coupler_options (gs.CouplerOptions) – A CouplerOptions object that contains all the options for the coupler.

build()[source]#
destroy()[source]#
reset(state: SimState, envs_idx=None)[source]#
reset_grad()[source]#
f_global_to_f_local(f_global)[source]#
f_local_to_s_local(f_local)[source]#
f_global_to_s_local(f_global)[source]#
f_global_to_s_global(f_global)[source]#
step(in_backward=False)[source]#
process_input(in_backward=False)[source]#

setting _tgt state using external commands note that external inputs are given at step level, not substep

process_input_grad()[source]#
substep(f)[source]#
sub_step_grad(f)[source]#
substep_pre_coupling(f)[source]#
substep_pre_coupling_grad(f)[source]#
substep_post_coupling(f)[source]#
substep_post_coupling_grad(f)[source]#
add_grad_from_state(state)[source]#
collect_output_grads()[source]#

Collect gradients from downstream queried states.

save_ckpt()[source]#

This function refreshes the gpu memory (copy the last frame to the first frame in the local memory), and then saves the checkpoint. This function is called every substeps_local steps, which means it’s called only once per step when requires_grad is True.

load_ckpt()[source]#
get_state()[source]#
set_gravity(gravity, envs_idx=None)[source]#
property dt: float#

The time duration for each simulation step.

property substeps#

The number of substeps per simulation step.

property scene#

The scene object that the simulator is associated with.

property gravity#

The gravity vector.

property requires_grad#

Whether the simulator requires gradients.

property n_entities: int#

The number of entities in the simulator.

property entities#

The list of entities in the simulator.

property substeps_local#

The number of substeps stored in local memory.

property cur_substep_global#

The current substep of the simulation.

property cur_substep_local#

The current substep of the simulation in local memory.

property cur_step_local#

The current step of the simulation in local memory.

property cur_step_global#

The current step of the simulation.

property cur_t#

The current time of the simulation.

property coupler#

The coupler object that manages the inter-solver coupling.

property solvers#

The list of solvers in the simulator.

property active_solvers#

The list of active solvers in the simulator.