How to Efficiently Load Scenes via Python API and Reduce Computational Load During Simulations

I am planning to conduct simulations where I add a large number of objects (spheres) and apply forces to them. However, once the number of objects exceeds 10,000, loading the scene takes a significant amount of time. Additionally, the performance becomes sluggish during simulations. What approach would be appropriate to resolve this issue?
It’s worth noting that CPU and memory usage remain low, so I attempted parallel processing, but it resulted in errors and the simulation was forcibly terminated. Is it possible to incorporate parallel processing into the simulation?

Below is the code for the simulation that I would like to make more efficient. I am also planning to calculate the forces to be applied to the spheres, so I want to run it efficiently. The version I am using is Isaac Sim 2022.1.1.

from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.core.objects import DynamicSphere, DynamicCuboid
from omni.isaac.dynamic_control import _dynamic_control
import numpy as np
import random

class HelloWorld(BaseSample):
    def __init__(self) -> None:
        super().__init__()

        self.initial_force_applied = False  # 初期力が適用されたかどうかをチェック
        self.num_pedestrians = 1000 # 歩行者の数
        self.num_obstacle = 100 # 障害物の数
        self.position_range = (-5, 5) #設置範囲

    def setup_scene(self):
        world = self.get_world()
        world.scene.add_default_ground_plane()

        self.pedestrians = []
        self.obstacles = []
        self.goal_positions = []

        # 歩行者(球体)をランダムな位置に生成
        for i in range(self.num_pedestrians):
            position = np.array([random.uniform(*self.position_range), random.uniform(*self.position_range), 0]) 

            pedestrian = world.scene.add(
                DynamicSphere(
                    prim_path=f"/Environment/Pedestrian_{i}",
                    name=f"Pedestrian_{i}",
                    position=position,
                    scale=np.array([0.5, 0.5, 0.5]), 
                    color=np.array([1.0, 0, 0]),
                    mass=0.05
                ))
            self.pedestrians.append(pedestrian)

        # 障害物(立方体)をランダムな位置に生成
        for i in range(self.num_obstacle):
            position = np.array([random.uniform(*self.position_range), random.uniform(*self.position_range), 0]) 
            obstacle = world.scene.add(
                DynamicCuboid(
                    prim_path=f"/Environment/Obstacle_{i}",
                    name=f"Obstacle_{i}",
                    position=position,
                    scale=np.array([2, 2, 2]),  # 立方体のサイズ
                    color=np.array([0, 1.0, 0]), 
                    mass=0.5))
            
            self.obstacles.append(obstacle)

    async def setup_post_load(self):
        self._world = self.get_world()
        self._dc = _dynamic_control.acquire_dynamic_control_interface()

        self.pedestrian_handles = [self._dc.get_rigid_body(f"/Environment/Pedestrian_{i}") for i in range(self.num_pedestrians)]
        self.obstacle_handles = [self._dc.get_rigid_body(f"/Environment/Obstacle_{i}") for i in range(self.num_obstacle)]

        self._world.add_physics_callback("send_actions", self.send_actions)
    
    def send_actions(self, step_size):
        # シミュレーション開始時にのみランダムな力を適用
        if not self.initial_force_applied:
            for pedestrian_handle in self.pedestrian_handles:
                # ランダムな力のベクトルを生成
                random_force = np.array([random.uniform(-1, 1), random.uniform(-1, 1), 0])
                # 力のベクトルを正規化して、方向は保持しつつ大きさを1にする
                random_force = random_force / np.linalg.norm(random_force)
                # 力の大きさを所望の値にスケール
                force_magnitude = 5  # 必要に応じてこの値を調整
                scaled_random_force = random_force * force_magnitude
                # 歩行者に力を適用
                self._dc.apply_body_force(pedestrian_handle, scaled_random_force, np.array([0, 0, 0]), True)
        
            self.initial_force_applied = True  # フラグをTrueに設定して再適用を防止

@rthaker Can you help me?

Hi @Atsushisaku - Couple of questions for you:

  1. Why use older Isaac Sim version?, ideally you should use the latest version.
  2. Are you trying to add multiple objects for reinforcement learning?
    if yes, can you pls review this section of doc?
    9.7. Instanceable Assets — Omniverse IsaacSim latest documentation