### SFSolver Usage Example Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/sf_solver.html This example demonstrates how to initialize the SFSolver, set up a scene with SF options, add a rope entity, build the scene, and run the simulation. ```APIDOC ## SFSolver Usage This section provides a Python code example demonstrating the usage of the SFSolver. ### Code Example ```python import genesis as gs gs.init() scene = gs.Scene( sf_options=gs.options.SFOptions( iterations=20, ), ) # Add rope/cable rope = scene.add_entity( gs.morphs.Mesh(file="rope.obj"), material=gs.materials.SF.Rope( stretch_stiffness=1.0, bend_stiffness=0.1, ), ) scene.build() for i in range(1000): scene.step() ``` ### Explanation 1. **Initialization**: `gs.init()` initializes the Genesis simulation environment. 2. **Scene Setup**: A `gs.Scene` is created with specific `SFOptions`, including the number of constraint `iterations`. 3. **Entity Addition**: A rope is added to the scene using `gs.morphs.Mesh` and configured with `gs.materials.SF.Rope` properties like `stretch_stiffness` and `bend_stiffness`. 4. **Scene Building**: `scene.build()` prepares the simulation environment. 5. **Simulation Loop**: The `scene.step()` method is called within a loop to advance the simulation over time. ``` -------------------------------- ### MPMSolver Usage Example Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/mpm_solver.html Demonstrates how to initialize the MPMSolver, set up a scene with MPM options, add an MPM entity with an elastic material, build the scene, and run simulation steps. ```python import genesis as gs gs.init() scene = gs.Scene( mpm_options=gs.options.MPMOptions( dt=1e-4, lower_bound=(-1, -1, 0), upper_bound=(1, 1, 2), grid_density=64, ), ) # Add MPM entity soft_box = scene.add_entity( gs.morphs.Box(pos=(0, 0, 0.5), size=(0.2, 0.2, 0.2)), material=gs.materials.MPM.Elastic( E=1e5, # Young's modulus nu=0.3, # Poisson's ratio rho=1000, # Density ), ) scene.build() for i in range(1000): scene.step() ``` -------------------------------- ### Install Genesis World Source: https://genesis-world.readthedocs.io/en/latest/_sources/index.md.txt Install the Genesis World package using pip. Ensure PyTorch is installed separately following official instructions. ```bash pip install genesis-world ``` -------------------------------- ### elem_start Property Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/pbd_entity/pbd_3d.html The starting index of the elements in the global solver. ```APIDOC ## elem_start ### Description The starting index of the elements in the global solver. ### Property Type int ``` -------------------------------- ### Trajectory Optimization Example Source: https://genesis-world.readthedocs.io/en/latest/api_reference/differentiation/index.html This example demonstrates optimizing a control sequence for a robot using Genesis. It involves forward simulation, loss computation, and gradient-based optimization using PyTorch's Adam optimizer. ```python import genesis as gs import torch gs.init() scene = gs.Scene( sim_options=gs.options.SimOptions( dt=0.01, requires_grad=True, ), ) robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf")) scene.build() # Optimize control sequence n_steps = 100 n_dofs = robot.n_dofs controls = torch.zeros(n_steps, n_dofs, requires_grad=True, device=gs.device) optimizer = torch.optim.Adam([controls], lr=0.01) target = torch.tensor([1.0, 0.0, 0.5], device=gs.device) for epoch in range(100): scene.reset() # Forward simulation for t in range(n_steps): robot.control_dofs_force(controls[t]) scene.step() # Compute loss final_pos = robot.get_pos() loss = torch.nn.functional.mse_loss(final_pos, target) # Optimize optimizer.zero_grad() loss.backward() optimizer.step() print(f"Epoch {epoch}: loss = {loss.item():.4f}") ``` -------------------------------- ### RigidSolver Usage Example Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/rigid_solver.html Demonstrates how to initialize the Genesis engine, set up a scene with RigidSolver options, add rigid entities like planes, robots, and boxes, build the scene, control robot joint positions and velocities, and step through the simulation. ```python import genesis as gs gs.init() scene = gs.Scene( rigid_options=gs.options.RigidOptions( enable_collision=True, enable_joint_limit=True, constraint_solver=gs.constraint_solver.Newton, ), ) # Add rigid entities plane = scene.add_entity(gs.morphs.Plane()) robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf")) box = scene.add_entity(gs.morphs.Box(pos=(0, 0, 1), size=(1.0, 1.0, 1.0))) scene.build() # Control robot robot.set_dofs_position(target_positions) robot.set_dofs_velocity(target_velocities) for i in range(1000): scene.step() ``` -------------------------------- ### SPHSolver Fluid Simulation Example Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/sph_solver.html Demonstrates how to set up and run a fluid simulation using the SPHSolver. This includes initializing the scene with SPH options, adding a fluid entity with specified density and viscosity, and a rigid container. The simulation is then run for a set number of steps. ```python import genesis as gs gs.init() scene = gs.Scene( sph_options=gs.options.SPHOptions( lower_bound=(-1, -1, 0), upper_bound=(1, 1, 2), particle_size=0.02, ), ) # Add fluid fluid = scene.add_entity( gs.morphs.Box(pos=(0, 0, 0.5), size=(0.4, 0.4, 0.4)), material=gs.materials.SPH.Liquid( rho=1000, # Density mu=0.01, ), ) # Add rigid container container = scene.add_entity( gs.morphs.Box( pos=(0, 0, 0.5), size=(0.5, 0.5, 0.5), ), vis_mode="collision", ) scene.build() for i in range(1000): scene.step() ``` -------------------------------- ### Initialize Scene with SAPCoupler Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/sap_coupler.html Initializes the Genesis simulation environment and creates a scene configured with SAPCoupler options. This is the standard setup for using the SAPCoupler. ```python import genesis as gs gs.init() scene = gs.Scene( coupler_options=gs.options.SAPCouplerOptions(), ) ``` -------------------------------- ### Quick Start Differentiable Simulation Source: https://genesis-world.readthedocs.io/en/latest/api_reference/differentiation/index.html Initialize the scene with gradient tracking enabled. Perform forward simulation by controlling entity forces and stepping the scene. Compute loss and perform a backward pass to access gradients. ```python import genesis as gs import torch gs.init() # Enable gradient tracking scene = gs.Scene( sim_options=gs.options.SimOptions( dt=0.01, requires_grad=True, # Enable differentiability ), ) robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf")) scene.build() # Forward simulation initial_pos = torch.tensor([0.0, 0.0, 0.0], requires_grad=True, device=gs.device) robot.set_dofs_position(initial_pos) for i in range(100): robot.control_dofs_force(forces) scene.step() # Compute loss final_pos = robot.get_pos() target = torch.tensor([1.0, 0.0, 0.5], device=gs.device) loss = torch.nn.functional.mse_loss(final_pos, target) # Backward pass loss.backward() # Access gradients print(initial_pos.grad) ``` -------------------------------- ### Simulate Tool Interacting with Fluid Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/index.html Sets up a simulation with a kinematic tool and a fluid material, showcasing multi-physics interaction. This example is suitable for simulating scenarios involving tools and liquids. ```python # Kinematic tool tool = scene.add_entity( gs.morphs.Mesh(file="paddle.obj"), material=gs.materials.Tool(), ) ``` -------------------------------- ### Initialize Scene with IPCCoupler Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/ipc_coupler.html Initializes the Genesis simulation scene using the IPCCoupler with custom contact distance threshold. This setup is suitable for complex deformable-deformable contact scenarios where intersection-free guarantees and stability are paramount. ```python import genesis as gs gs.init() scene = gs.Scene( coupler_options=gs.options.IPCCouplerOptions( d_hat=0.001, # Contact distance threshold ), ) ``` -------------------------------- ### Configure Rigid Solver with Newton Solver Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/rigid_solver.html Use the Newton solver for improved convergence in rigid body simulations. This example sets the constraint solver to Newton and specifies 10 iterations. ```python # Use Newton solver for better convergence rigid_options = gs.options.RigidOptions( constraint_solver=gs.constraint_solver.Newton, iterations=10, ) ``` -------------------------------- ### Initialize FEMSolver and Add Entity Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/fem_solver.html Initializes the genesis engine, sets up FEM solver options, and adds a deformable mesh entity to the scene. This snippet demonstrates the basic setup for using the FEM solver. ```python import genesis as gs gs.init() scene = gs.Scene( fem_options=gs.options.FEMOptions( dt=1e-3, damping=0.1, ), ) # Add FEM entity soft_body = scene.add_entity( gs.morphs.Mesh(file="soft_object.obj"), material=gs.materials.FEM.Elastic( E=1e5, nu=0.4, rho=1000, ), ) scene.build() for i in range(1000): scene.step() ``` -------------------------------- ### SPHEntity.init_sampler() Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/sph_entity.html Initializes the sampler for the SPHEntity. ```APIDOC ## SPHEntity.init_sampler() ### Description Initializes the sampler for the SPHEntity. ### Parameters #### Path Parameters - **envs_idx** (_None_ | __int_ | __array_like_, __shape_ _(__M_,)__,__optional_) – The indices of the environments to set. If None, all environments will be considered. Defaults to None. ### Returns - **poss** (torch.Tensor) – Tensor of particle activeness boolean flags. ### Return Type torch.Tensor, shape (M, n_particles, 3) ``` -------------------------------- ### Initialize Scene and Add Rope Entity with SFSolver Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/sf_solver.html Demonstrates how to initialize the Genesis simulation environment, create a scene with SFOptions, add a rope entity using a mesh and SF material, and then build the scene. ```python import genesis as gs gs.init() scene = gs.Scene( sf_options=gs.options.SFOptions( iterations=20, ), ) # Add rope/cable rope = scene.add_entity( gs.morphs.Mesh(file="rope.obj"), material=gs.materials.SF.Rope( stretch_stiffness=1.0, bend_stiffness=0.1, ), ) scene.build() for i in range(1000): scene.step() ``` -------------------------------- ### get_dofs_act_gain Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Gets the actuator gain for the entity's dofs. ```APIDOC ## get_dofs_act_gain(dofs_idx_local=None, envs_idx=None) ### Description Get the actuator gain for the entity’s dofs. ### Parameters #### Path Parameters - **dofs_idx_local** (None | array_like) - Optional - The indices of the dofs to get. If None, all dofs will be returned. Note that here this uses the local q_idx, not the scene-level one. Defaults to None. - **envs_idx** (None | array_like) - Optional - The indices of the environments. If None, all environments will be considered. Defaults to None. ### Returns #### Success Response - **act_gain** (torch.Tensor) - The actuator gain. shape (n_dofs,) or (n_envs, n_dofs) ``` -------------------------------- ### HybridEntity.build() Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/hybrid_entity.html Finalizes the hybrid entity setup during the simulation build process. ```APIDOC ## HybridEntity.build() ### Description Finalize the hybrid entity setup during simulation build. ### Method build() ``` -------------------------------- ### get_dofs_force_range Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Gets the force range (min and max limits) for the entity's dofs. ```APIDOC ## get_dofs_force_range(dofs_idx_local=None, envs_idx=None) ### Description Get the force range (min and max limits) for the entity’s dofs. ### Parameters #### Path Parameters - **dofs_idx_local** (None | array_like) - Optional - The indices of the dofs to get. If None, all dofs will be returned. Note that here this uses the local q_idx, not the scene-level one. Defaults to None. - **envs_idx** (None | array_like) - Optional - The indices of the environments. If None, all environments will be considered. Defaults to None. ``` -------------------------------- ### Plastic Surface Initialization Source: https://genesis-world.readthedocs.io/en/latest/api_reference/options/surface/plastic/plastic.html Demonstrates how to initialize the Plastic surface with various parameters. This includes setting basic properties like color and IOR, as well as applying textures for diffuse, specular, opacity, roughness, normal, and emissive properties. ```APIDOC ## Plastic Surface ### Description Initializes a plastic surface with customizable properties. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **color** (tuple | None) - Optional - Diffuse color of the surface. Shortcut for diffuse_texture with a single color. - **ior** (float | None) - Optional - Index of Refraction. Defaults to 1.0. - **diffuse_texture** (gs.textures.Texture | None) - Optional - Diffuse (basic color) texture of the surface. - **specular_texture** (gs.textures.Texture | None) - Optional - Specular texture of the surface. - **opacity_texture** (gs.textures.Texture | None) - Optional - Opacity texture of the surface. - **roughness_texture** (gs.textures.Texture | None) - Optional - Roughness texture of the surface. - **normal_texture** (gs.textures.Texture | None) - Optional - Normal texture of the surface. - **emissive_texture** (gs.textures.Texture | None) - Optional - Emissive texture of the surface. ### Request Example ```python plastic_surface = gs.surfaces.Plastic( color=(0.8, 0.2, 0.1), ior=1.5, roughness_texture=gs.textures.load_texture("path/to/roughness.png") ) ``` ### Response #### Success Response (200) Represents the initialized Plastic surface object. #### Response Example ```json { "type": "Plastic", "color": [0.8, 0.2, 0.1], "ior": 1.5, "roughness_texture": { "type": "Texture", "path": "path/to/roughness.png" } } ``` ``` -------------------------------- ### IPCCoupler Initialization and Usage Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/ipc_coupler.html Demonstrates how to initialize the scene with IPCCoupler and configure its options. ```APIDOC ## Initialize Scene with IPCCoupler ### Description This snippet shows how to initialize the `genesis` simulator with the `IPCCoupler` and set specific coupler options. ### Method Python SDK ### Endpoint N/A (SDK Usage) ### Parameters #### Request Body (Implicit via SDK) - `coupler_options` (gs.options.IPCCouplerOptions) - Options for the IPCCoupler. - `d_hat` (float) - Required - Contact distance threshold. ### Request Example ```python import genesis as gs gs.init() scene = gs.Scene( coupler_options=gs.options.IPCCouplerOptions( d_hat=0.001, # Contact distance threshold ), ) ``` ### Response #### Success Response Scene object initialized with IPCCoupler. #### Response Example N/A (SDK Usage) ``` -------------------------------- ### get_dofs_act_bias Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Gets the actuator bias [constant, pos_coeff, vel_coeff] for the entity's dofs. ```APIDOC ## get_dofs_act_bias(dofs_idx_local=None, envs_idx=None) ### Description Get the actuator bias [constant, pos_coeff, vel_coeff] for the entity’s dofs. ### Parameters #### Path Parameters - **dofs_idx_local** (None | array_like) - Optional - The indices of the dofs to get. If None, all dofs will be returned. Note that here this uses the local q_idx, not the scene-level one. Defaults to None. - **envs_idx** (None | array_like) - Optional - The indices of the environments. If None, all environments will be considered. Defaults to None. ### Returns #### Success Response - **bias0** (torch.Tensor) - **bias1** (torch.Tensor) - **bias2** (torch.Tensor) - The actuator bias [constant, pos_coeff, vel_coeff] for the entity’s dofs. ``` -------------------------------- ### Initialize Scene with PBDSolver and Add Cloth Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/pbd_solver.html Demonstrates how to initialize the Genesis engine, set up a scene with PBD options, add a cloth entity using a mesh, and apply PBD cloth material properties. The top edge of the cloth is then fixed. ```python import genesis as gs gs.init() scene = gs.Scene( pbd_options=gs.options.PBDOptions( iterations=10, damping=0.99, ), ) # Add cloth cloth = scene.add_entity( gs.morphs.Mesh(file="cloth.obj"), material=gs.materials.PBD.Cloth( stretch_stiffness=0.9, bend_stiffness=0.1, ), ) # Fix top edge cloth.fix_vertices(y_max=0.99) scene.build() for i in range(1000): scene.step() ``` -------------------------------- ### get_dofs_force Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Gets the entity's dofs' internal force at the current time step. ```APIDOC ## get_dofs_force(dofs_idx_local=None, envs_idx=None) ### Description Get the entity’s dofs’ internal force at the current time step. Different from get_dofs_control_force, this function returns the actual internal force experienced by all the dofs at the current time step. ### Parameters #### Path Parameters - **dofs_idx_local** (None | array_like) - Optional - The indices of the dofs to get. If None, all dofs will be returned. Note that here this uses the local q_idx, not the scene-level one. Defaults to None. - **envs_idx** (None | array_like) - Optional - The indices of the environments. If None, all environments will be considered. Defaults to None. ### Returns #### Success Response - **force** (torch.Tensor) - The entity’s dofs’ force. shape (n_dofs,) or (n_envs, n_dofs) ``` -------------------------------- ### Initialize Scene with LegacyCoupler Options Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/index.html Demonstrates how to initialize the Genesis simulator and create a scene, specifying options for the LegacyCoupler. This is useful when you need to configure specific parameters for this coupler. ```python import genesis as gs gs.init() scene = gs.Scene( coupler_options=gs.options.LegacyCouplerOptions( # Coupler-specific options ), ) ``` -------------------------------- ### get_dofs_kv Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Gets the velocity gain (kv) for the entity's dofs used by the PD controller. ```APIDOC ## get_dofs_kv(dofs_idx_local=None, envs_idx=None) ### Description Get the velocity gain (kv) for the entity’s dofs used by the PD controller. ### Parameters #### Path Parameters - **dofs_idx_local** (None | array_like) - Optional - The indices of the dofs to get. If None, all dofs will be returned. Note that here this uses the local q_idx, not the scene-level one. Defaults to None. - **envs_idx** (None | array_like) - Optional - The indices of the environments. If None, all environments will be considered. Defaults to None. ### Returns #### Success Response - **kv** (torch.Tensor) - The velocity gain (kv) for the entity’s dofs. shape (n_dofs,) or (n_envs, n_dofs) ``` -------------------------------- ### Combine Multiple Solvers in a Scene Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/index.html Demonstrates how to initialize Genesis, create a scene, add entities with different materials (URDF for rigid, MPM for soft, PBD for cloth), build the scene, and step all solvers together. ```python import genesis as gs gs.init() scene = gs.Scene() # Rigid robot robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf")) # Soft object (MPM) soft = scene.add_entity( gs.morphs.Box(pos=(0.5, 0, 0.5), size=(1.0, 1.0, 1.0)), material=gs.materials.MPM.Elastic(), ) # Cloth (PBD) cloth = scene.add_entity( gs.morphs.Mesh(file="cloth.obj"), material=gs.materials.PBD.Cloth(), ) scene.build() # All solvers step together for i in range(1000): scene.step() ``` -------------------------------- ### get_dofs_kp Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Gets the positional gain (kp) for the entity's dofs used by the PD controller. ```APIDOC ## get_dofs_kp(dofs_idx_local=None, envs_idx=None) ### Description Get the positional gain (kp) for the entity’s dofs used by the PD controller. ### Parameters #### Path Parameters - **dofs_idx_local** (None | array_like) - Optional - The indices of the dofs to get. If None, all dofs will be returned. Note that here this uses the local q_idx, not the scene-level one. Defaults to None. - **envs_idx** (None | array_like) - Optional - The indices of the environments. If None, all environments will be considered. Defaults to None. ### Returns #### Success Response - **kp** (torch.Tensor) - The positional gain (kp) for the entity’s dofs. shape (n_dofs,) or (n_envs, n_dofs) ``` -------------------------------- ### init_ckpt Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/fem_entity.html Initializes the checkpoint storage dictionary. ```APIDOC ## `init_ckpt` ### Description Initialize the checkpoint storage dictionary. Creates an empty container for storing simulation checkpoints. ``` -------------------------------- ### get_dofs_control_force Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Gets the entity's dofs' internal control force, computed based on the position/velocity control command. ```APIDOC ## get_dofs_control_force(dofs_idx_local=None, envs_idx=None) ### Description Get the entity’s dofs’ internal control force, computed based on the position/velocity control command. ### Parameters #### Path Parameters - **dofs_idx_local** (None | array_like) - Optional - The indices of the dofs to get. If None, all dofs will be returned. Note that here this uses the local q_idx, not the scene-level one. Defaults to None. - **envs_idx** (None | array_like) - Optional - The indices of the environments. If None, all environments will be considered. Defaults to None. ### Returns #### Success Response - **control_force** (torch.Tensor) - The entity’s dofs’ internal control force. shape (n_dofs,) or (n_envs, n_dofs) ``` -------------------------------- ### plan_path Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/rigid_entity/rigid_entity.html Plans a motion path from a start state to a goal state for the rigid entity, with options for resolution, timeout, smoothing, and collision checking. ```APIDOC ## plan_path ### Description Plan a path from qpos_start to qpos_goal. ### Method plan_path ### Parameters #### Path Parameters - **qpos_goal** (array_like) - The goal state. [B, Nq] or [1, Nq] - **qpos_start** (None | array_like, optional) - The start state. If None, the current state of the rigid entity will be used. Defaults to None. [B, Nq] or [1, Nq] - **resolution** (float, optional) - Joint-space resolution. It corresponds to the maximum distance between states to be checked for validity along a path segment. - **timeout** (float, optional) - The max time to spend for each planning in seconds. Note that the timeout is not exact. - **max_retry** (float, optional) - Maximum number of retry in case of timeout or convergence failure. Default to 1. - **smooth_path** (bool, optional) - Whether to smooth the path after finding a solution. Defaults to True. - **num_waypoints** (int, optional) - The number of waypoints to interpolate the path. If None, no interpolation will be performed. Defaults to 100. - **ignore_collision** (bool, optional) - Whether to ignore collision checking during motion planning. Defaults to False. - **planner** (str, optional) - The name of the motion planning algorithm to use. Supported planners: ‘RRT’, ‘RRTConnect’. Defaults to ‘RRTConnect’. - **envs_idx** (None | array_like, optional) - The indices of the environments to set. If None, all environments will be set. Defaults to None. - **return_valid_mask** (bool) - Obtain valid mask of the succesful planed path over batch. - **ee_link_name** (str) - The name of the link, which we “attach” the object during the planning - **with_entity** (RigidEntity) - The (non-articulated) object to “attach” during the planning ### Returns - **path** (torch.Tensor) - A tensor of waypoints representing the planned path. Each waypoint is an array storing the entity’s qpos of a single time step. - **is_invalid** (torch.Tensor) - A tensor of boolean mask indicating the batch indices with failed plan. ``` -------------------------------- ### Simulator, Coupler & Solver Options Overview Source: https://genesis-world.readthedocs.io/en/latest/api_reference/options/simulator_coupler_and_solver_options/index.html This section configures the global simulator, all the solvers inside it, and the inter-solver coupler. `SimOptions` specifies the global settings for the simulator. Parameters present in both `SimOptions` and `SolverOptions` will be overridden by `SolverOptions` for that specific solver. ```APIDOC ## Simulator, Coupler & Solver Options This configures the global simulator, all the solvers inside it, and the inter-solver coupler. Note `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. ### Available Options: - `gs.options.SimOptions` - `SimOptions` - `gs.options.CouplerOptions` - `gs.options.ToolOptions` - `ToolOptions` - `gs.options.RigidOptions` - `RigidOptions` - `gs.options.MPMOptions` - `MPMOptions` - `gs.options.SPHOptions` - `SPHOptions` - `gs.options.PBDOptions` - `PBDOptions` - `gs.options.FEMOptions` - `FEMOptions` - `gs.options.SFOptions` - `SFOptions` ``` -------------------------------- ### Initialize and Run Simulation Loop Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/index.html Initializes the Genesis engine and sets up a simulation scene with specified options. The simulation then runs for a fixed number of steps using the scene.step() method. ```python import genesis as gs gs.init() scene = gs.Scene( sim_options=gs.options.SimOptions( dt=0.01, # Timestep substeps=4, # Physics substeps per step gravity=(0, 0, -9.81), ), ) # Add entities... scene.build() # Each step() executes the full simulation loop for i in range(1000): scene.step() ``` -------------------------------- ### Initialize Scene and Add Kinematic Tool Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/tool_solver.html Demonstrates how to initialize the Genesis engine, create a scene with ToolOptions, and add a kinematic tool entity. The tool is defined using a mesh and a Tool material. ```python import genesis as gs gs.init() scene = gs.Scene( tool_options=gs.options.ToolOptions(), ) # Add kinematic tool tool = scene.add_entity( gs.morphs.Mesh(file="tool.obj"), material=gs.materials.Tool(), ) scene.build() ``` -------------------------------- ### Add SPH Fluid Entity Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/index.html Adds an SPH fluid entity to the scene using a Box shape and Liquid material. This is a basic setup for fluid simulation. ```python fluid = scene.add_entity( gs.morphs.Box(pos=(0, 0, 0.5), size=(1.0, 1.0, 1.0)), material=gs.materials.SPH.Liquid(), ) ``` -------------------------------- ### LegacyCoupler Initialization and Usage Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/legacy_coupler.html Demonstrates how to initialize the Genesis engine and create a scene using the LegacyCoupler with custom options. ```APIDOC ## LegacyCoupler Initialization and Usage ### Description This snippet shows how to initialize the Genesis engine and set up a scene utilizing the `LegacyCoupler`. It includes an example of configuring `LegacyCouplerOptions` to set parameters like friction. ### Code Example ```python import genesis as gs # Initialize the Genesis engine gs.init() # Create a scene with LegacyCoupler and custom options scene = gs.Scene( coupler_options=gs.options.LegacyCouplerOptions( friction=0.5, ), ) ``` ### See Also * [Couplers](link-to-couplers-overview) * [SAPCoupler](link-to-sapcoupler) ``` -------------------------------- ### PBDParticleEntity Constructor Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/pbd_entity/pbd_particle.html Initializes a PBDParticleEntity. This entity is defined purely by particles and requires scene, solver, material, morph, surface, particle size, entity index, and particle start index. ```APIDOC ## PBDParticleEntity Constructor ### Description Initializes a PBDParticleEntity, which represents a PBD entity composed solely of particles. It requires several parameters to define its physical properties, shape, and position within the simulation. ### Parameters * **scene** (Scene) - Required - The simulation scene this entity is part of. * **solver** (Solver) - Required - The PBD solver instance managing this entity. * **material** (Material) - Required - Material model defining physical properties such as density and compliance. * **morph** (Morph) - Required - Morph object specifying shape and initial transform (position and rotation). * **surface** (Surface) - Required - Surface or texture representation. * **particle_size** (float) - Required - Target size for particle spacing. * **idx** (int) - Required - Unique index of this entity within the scene. * **particle_start** (int) - Required - Starting index of this entity’s particles in the global particle buffer. * **name** (str | None) - Optional - The name of the entity. ``` -------------------------------- ### FEMEntity Initialization Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/fem_entity.html Initializes a FEMEntity with essential simulation components and parameters. ```APIDOC ## `FEMEntity` Constructor ### Description Initializes a finite element method (FEM)-based entity for deformable simulation. This class represents a deformable object using tetrahedral elements and interfaces with the physics solver. ### Parameters * **scene** (Scene) – The simulation scene that this entity belongs to. * **solver** (Solver) – The physics solver instance used for simulation. * **material** (Material) – The material properties defining elasticity, density, etc. * **morph** (Morph) – The morph specification that defines the entity’s shape. * **surface** (Surface) – The surface mesh associated with the entity (for rendering or collision). * **idx** (int) – Unique identifier of the entity within the scene. * **v_start** (int, optional) – Starting index of this entity’s vertices in the global vertex array (default is 0). * **el_start** (int, optional) – Starting index of this entity’s elements in the global element array (default is 0). * **s_start** (int, optional) – Starting index of this entity’s surface triangles in the global surface array (default is 0). * **name** (str | None, optional) – An optional name for the entity. ``` -------------------------------- ### Snow Class Initialization Source: https://genesis-world.readthedocs.io/en/latest/api_reference/material/mpm/snow.html Initializes the Snow material with various physical properties. Snow is a special type of ElastoPlastic that gets harder when compressed and does not support the von Mises yield criterion. ```APIDOC ## Snow ### Description Initializes the Snow material class for MPM simulations. This material exhibits hardening under compression and does not support the von Mises yield criterion. ### Parameters * **E** (float, optional) - Young’s modulus. Default is 1e6. * **nu** (float, optional) - Poisson ratio. Default is 0.2. * **rho** (float, optional) - Density (kg/m³). Default is 1000. * **sampler** (str, optional) - Particle sampler. Default is ‘random’. * **yield_lower** (float, optional) - Lower bound of yield condition. Default is 2.5e-2. * **yield_higher** (float, optional) - Upper bound of yield condition. Default is 4.5e-3. * **lam** (float | None, optional) - Lame parameter lambda. * **mu** (float | None, optional) - Lame parameter mu. * **update_F_S_Jp** (Any, optional) - Function to update F_S_Jp. * **update_stress** (Any, optional) - Function to update stress. * **idx** (int | None, optional) - Index of the material. * **use_von_mises** (bool, optional) - Whether to use von Mises yield criterion. Default is False. * **von_mises_yield_stress** (float, optional) - Von Mises yield stress. Default is 10000.0. ``` -------------------------------- ### v_start Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/fem_entity.html Global vertex index offset for this entity. ```APIDOC ## v_start ### Description Global vertex index offset for this entity. ``` -------------------------------- ### Copper Surface Initialization Source: https://genesis-world.readthedocs.io/en/latest/api_reference/options/surface/metal/copper.html This snippet shows how to initialize the Copper surface option, which is a shortcut for a metallic surface with `metal_type` set to 'copper'. You can optionally specify parameters like color, opacity, roughness, and more. ```APIDOC ## `gs.surfaces.Copper` ### Description Shortcut for a metallic surface with `metal_type` = ‘copper’. ### Parameters This class inherits parameters from its parent and has specific defaults for copper. - **color** (tuple[float, ...], optional): The base color of the surface. - **opacity** (float, optional): The opacity of the surface. - **roughness** (float, optional): The roughness of the surface. Defaults to 0.1. - **metallic** (float, optional): The metallic value of the surface. - **emissive** (tuple[float, ...], optional): The emissive color of the surface. - **ior** (float, optional): The index of refraction. - **default_roughness** (float): Default roughness value. Defaults to 1.0. - **vis_mode** (~typing.Literal['visual', 'collision', 'particle', 'sdf', 'recon'], optional): Visualization mode. - **smooth** (bool): Whether to use smooth shading. Defaults to True. - **double_sided** (bool, optional): Whether the surface is double-sided. - **cutoff** (float): Cutoff value. Defaults to 180.0. - **normal_diff_clamp** (float): Normal difference clamp value. Defaults to 180.0. - **recon_backend** (~typing.Literal['splashsurf', 'openvdb']): Reconstruction backend. Defaults to 'splashsurf'. - **generate_foam** (bool): Whether to generate foam. Defaults to False. - **foam_options** (~genesis.options.misc.FoamOptions): Foam generation options. - **metal_type** (~typing.Literal['aluminium', 'gold', 'copper', 'brass', 'iron', 'titanium', 'vanadium', 'lithium']): The type of metal. Defaults to 'copper'. - **diffuse_texture** (~genesis.options.textures.Texture, optional): Diffuse texture. - **opacity_texture** (~genesis.options.textures.Texture, optional): Opacity texture. - **roughness_texture** (~genesis.options.textures.Texture, optional): Roughness texture. - **normal_texture** (~genesis.options.textures.Texture, optional): Normal texture. - **emissive_texture** (~genesis.options.textures.Texture, optional): Emissive texture. ### Example ```python from genesis.options.surfaces import Copper # Initialize with default copper properties copper_surface = Copper() # Initialize with custom color and roughness copper_surface_custom = Copper(color=(0.8, 0.7, 0.6), roughness=0.2) ``` ``` -------------------------------- ### RigidOptions Configuration Source: https://genesis-world.readthedocs.io/en/latest/api_reference/options/simulator_coupler_and_solver_options/rigid_options.html Instantiate and configure RigidOptions for the simulation. ```APIDOC ## RigidOptions ### Description Options configuring the RigidSolver. ### Parameters - **dt** (float, optional) - Time duration for each simulation step in seconds. If none, it will inherit from SimOptions. Defaults to None. - **gravity** (tuple, optional) - Gravity force in N/kg. If none, it will inherit from SimOptions. Defaults to None. - **enable_collision** (bool, optional) - Whether to enable collision detection. Defaults to True. - **enable_joint_limit** (bool, optional) - Whether to enable joint limit. Defaults to True. - **enable_self_collision** (bool, optional) - Whether to enable self collision within each entity. Defaults to True. - **enable_neutral_collision** (bool, optional) - Whether to enable self collision occurring in neutral configuration (qpos0) within each entity. Defaults to False. - **enable_adjacent_collision** (bool, optional) - Whether to enable collision between successive parent-child body pairs within each entity. Defaults to False. - **disable_constraint** (bool, optional) - Whether to disable all constraints. Defaults to False. - **max_collision_pairs** (int, optional) - Maximum number of collision pairs. Defaults to 100. - **integrator** (gs.integrator, optional) - Integrator type. Current supported integrators are ‘gs.integrator.Euler’, ‘gs.integrator.implicitfast’ and ‘gs.integrator.approximate_implicitfast’. Defaults to ‘approximate_implicitfast’. - **IK_max_targets** (int, optional) - Maximum number of IK targets. Defaults to 6. - **constraint_solver** (gs.constraint_solver, optional) - Constraint solver type. Current supported constraint solvers are ‘gs.constraint_solver.CG’ and ‘gs.constraint_solver.Newton’. Defaults to ‘Newton’. - **iterations** (int, optional) - Number of iterations for the constraint solver. Defaults to 50. - **tolerance** (float, optional) - Tolerance for the constraint solver. Defaults to 1e-6. - **ls_iterations** (int, optional) - Number of line search iterations for the constraint solver. Defaults to 50. - **ls_tolerance** (float, optional) - Tolerance for the line search. Defaults to 1e-2. ``` -------------------------------- ### Configure MPM Grid Options Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/mpm_solver.html Set up the background grid for MPM computations by defining the grid boundaries and resolution. ```python mpm_options = gs.options.MPMOptions( lower_bound=(-2, -2, 0), # Grid min upper_bound=(2, 2, 4), # Grid max grid_density=128, # Resolution ) ``` -------------------------------- ### PBD2DEntity.sample() Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/pbd_entity/pbd_2d.html Samples and preprocesses the 2D mesh for the PBD cloth-like entity. ```APIDOC ## PBD2DEntity.sample() ### Description Sample and preprocess the 2D mesh for the PBD cloth-like entity. ### Method (Implicitly called during initialization or by the solver) ### Endpoint N/A (Method call on an object instance) ### Parameters None ``` -------------------------------- ### init_tgt_keys Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/mpm_entity.html Initializes target keys for buffer-based state tracking, including velocity, position, activeness, and actuation. ```APIDOC ## init_tgt_keys() ### Description Initialize target keys used for buffer-based state tracking. Sets up the list of keys for target states, including velocity, position, activeness, and finally actuation (for muscle only). ### Method APIDOC ``` -------------------------------- ### Rigid Class Initialization Source: https://genesis-world.readthedocs.io/en/latest/api_reference/material/rigid.html Initializes a Rigid material with various physical properties for simulation. ```APIDOC ## Rigid Class ### Description Represents a material used in rigid body simulation, providing parameters for physical interactions. ### Parameters #### Optional Parameters - **rho** (float | None) - Density of the material. Defaults to context-dependent values (1000 kg/m^3 with MuJoCo compatibility, 600 kg/m^3 for basic objects, 1500 kg/m^3 for robots). - **friction** (float | None) - Friction coefficient. Defaults to 1.0 or parsed from file if None. - **needs_coup** (bool) - Whether the material participates in coupling with other solvers. Defaults to True. - **coup_friction** (float) - Friction used during coupling. Must be non-negative. Defaults to 0.1. - **coup_softness** (float) - Softness of coupling interaction. Must be non-negative. Defaults to 0.002. - **coup_restitution** (float) - Restitution coefficient in collision coupling. Should be between 0 and 1. Defaults to 0.0. - **sdf_cell_size** (float) - Cell size in SDF grid in meters. Defines grid resolution. Defaults to 0.005. - **sdf_min_res** (int) - Minimum resolution of the SDF grid. Must be at least 16. Defaults to 32. - **sdf_max_res** (int) - Maximum resolution of the SDF grid. Must be >= sdf_min_res. Defaults to 128. - **gravity_compensation** (float) - Compensation factor for gravity. 1.0 cancels gravity. Defaults to 0.0. - **coup_type** (str | None) - Coupling mode for IPC coupler. Auto-selected if None. Valid values: 'two_way_soft_constraint', 'external_articulation', 'ipc_only'. Requires `needs_coup=True`. - **coup_links** (tuple[str, ...] | None) - Tuple of link names to include in coupling. Only supported with `needs_coup=True` and `two_way_soft_constraint` type in IPC. - **enable_coup_collision** (bool) - Whether coupler collision is enabled for this entity’s links. Default is True. - **coup_collision_links** (tuple[str, ...] | None) - Tuple of link names whose geoms participate in coupler collision. Only effective when `enable_coup_collision=True`. - **contact_resistance** (float | None) - IPC coupling contact resistance/stiffness override. `None` means use `IPCCouplerOptions.contact_resistance`. ``` -------------------------------- ### el_start Source: https://genesis-world.readthedocs.io/en/latest/api_reference/entity/fem_entity.html Global element index offset for this entity. ```APIDOC ## el_start ### Description Global element index offset for this entity. ``` -------------------------------- ### Initialize Scene with LegacyCoupler Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/couplers/legacy_coupler.html Initializes the Genesis simulation environment and creates a scene using LegacyCoupler with custom friction options. This is useful for basic scenarios requiring impulse-based contact resolution. ```python import genesis as gs gs.init() scene = gs.Scene( coupler_options=gs.options.LegacyCouplerOptions( friction=0.5, ), ) ``` -------------------------------- ### Configure Cloth Material with PBD Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/pbd_solver.html Sets up a cloth entity with specific PBD material properties. Adjust stretch and bend stiffness to control cloth behavior. ```python cloth = scene.add_entity( gs.morphs.Mesh(file="cloth.obj"), material=gs.materials.PBD.Cloth( stretch_stiffness=0.95, # Resist stretching bend_stiffness=0.05, # Allow bending thickness=0.01, # Collision thickness ), ) ``` -------------------------------- ### SFSolver Configuration Options Source: https://genesis-world.readthedocs.io/en/latest/api_reference/engine/solvers/sf_solver.html Details the key configuration options available for the SFSolver through `SFOptions`. ```APIDOC ## Configuration Key options in `SFOptions` for configuring the SFSolver: | Option | Type | Description | |--------------|-------|---------------------| | `iterations` | int | Constraint iterations | | `damping` | float | Velocity damping | ### See Also * `gs.options.SFOptions` - Full options ```