Logging to CSV at Physical Calculation Rates Above 61 Steps/Sec

I am examining how changes in the number of physical calculation steps affect the simulation. Specifically, I alter the step count, run the simulation, and log the coordinates to a CSV file.
However, when attempting to write to the CSV at rates above 61 steps/sec, the app crashes abruptly. What could be causing this?
I have confirmed that the simulation runs fine at rates above 61 steps/sec, and it is possible to display the logged coordinates in the terminal even at these higher rates.
I have tried buffering and threading the CSV writing process, but there has been no improvement.

Hi,
Can you please share more details so that I can try to repro the issue and check for a possible solution?
Thanks,
Ales

Thank hatou for your response.

Below is the code I have implemented using the Python API.
I am simulating 10 spheres navigating towards a target location while avoiding 5 boxes.
The xy coordinates are recorded in a CSV file.
The type of simulation does not matter for this context.

Please ensure that Time Steps Per Second, Min Simulation Frame Rate, and Time Codes Per Second are all set above 61. It is likely that Time Codes Per Second is the cause.

Additional information:
・Isaac Sim 2023.1.1
・Extension: PhysX Fabric on

import csv
from datetime import datetime
from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.dynamic_control import _dynamic_control
from omni.isaac.core.utils.stage import add_reference_to_stage
import numpy as np
import random
import time

class HelloWorld(BaseSample):
    def __init__(self) -> None:
        super().__init__()
        self.V0 = 1.0  # 速度の最大値 [m/s](default 1.34)
        self.tau = 0.4  # V0に達するまでの時間 [s](default 0.5)
        self.goal_range_x = (4, 4.5)  # 目的地の範囲
        self.goal_range_y = (-0.5, 0.5)  # 目的地の範囲
        self.close_to_goal_threshold = 0.8  # 斥力オフにする閾値
        self.update_frequency = 1 # 更新頻度の設定
        self.current_frame = 0  # 現在のフレーム数を追跡
        self.callback_count = 0  # コールバック実行回数
        self.start_time = time.time()  # 開始時刻

    def setup_scene(self):
        world = self.get_world()
        world.scene.add_default_ground_plane()
        self.file_path = "/////////////"
        add_reference_to_stage(usd_path=self.file_path, prim_path="/World/objects")
        self.goal_positions = [np.array([round(random.uniform(*self.goal_range_x), 2), 
                                         round(random.uniform(*self.goal_range_y), 2)]) for _ in range(10)]

    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"/World/objects/Pedestrian_{i}") for i in range(10)]
        self.obstacle_handles = [self._dc.get_rigid_body(f"/World/objects/Obstacle_{i}") for i in range(5)]
        self.pedestrian_orijinal = self._dc.get_rigid_body("/World/objects/Pedestrian")
        self.obstacle_orijinal = self._dc.get_rigid_body("/World/objects/Obstacle")
        self.record_log() 
        self._world.add_physics_callback("send_actions", self.send_actions)

    def record_log(self):
        current_time = datetime.now().strftime("%y%m%d.%H:%M")
        self.csv_file_name = f"/home/member/Desktop/log/log_{current_time}.csv"
        self.csv_file = open(self.csv_file_name, mode='w', newline='')
        self.csv_writer = csv.writer(self.csv_file)
        self.csv_writer.writerow(['name', 'x', 'y'])

    def send_actions(self, step_size):
        self._dc.set_rigid_body_disable_simulation(self.pedestrian_orijinal, True)
        self._dc.set_rigid_body_disable_simulation(self.obstacle_orijinal, True)

        if self.current_frame % self.update_frequency == 0:
            pedestrian_positions = np.array([self._dc.get_rigid_body_pose(handle).p[:2] for handle in self.pedestrian_handles])
            obstacle_positions = np.array([self._dc.get_rigid_body_pose(handle).p[:2] for handle in self.obstacle_handles])
            goal_positions = np.array(self.goal_positions)

            # Pedestrian_5 の位置情報をCSVファイルに記録
            self.csv_writer.writerow(['Pedestrian_5', pedestrian_positions[5][0], pedestrian_positions[5][1]])
            #self.csv_writer.writerow(['Obstacle_0', obstacle_positions[0][0], obstacle_positions[0][1]])

            directions = goal_positions - pedestrian_positions
            distances = np.linalg.norm(directions, axis=1)
            et = np.where(distances[:, None] > 0, directions / distances[:, None], 0)
            velocities = np.array([self._dc.get_rigid_body_linear_velocity(handle)[:2] for handle in self.pedestrian_handles])
            goal_forces = (self.V0 * et - velocities) / self.tau

            # 合力を計算して歩行者に適用
            total_forces = goal_forces  #+ obstacle_forces + pedestrian_forces
            for i, total_force in enumerate(total_forces):
                self._dc.apply_body_force(self.pedestrian_handles[i], np.append(total_force, 0), np.array([0, 0, 0]), True)

    def __del__(self):
        self.csv_file.close()

I have tried to register directly to physics stepping using this call:

from omni.physx import get_physx_interface

self._stepping_sub = get_physx_interface().subscribe_physics_step_events(self.send_actions)

With that I was able to get the state for every step and save the data.

One thing to check is whether you have multiple scenes in your stage, that could cause issues.

Regards,
Ales