Speed up the simulation without affecting the physics

Basically I am looking for the parameter which is equivalent to Unity’s “time scale”, the parameter that I can speed up the simulation without affecting the physics. I know I can make the simulation faster by changing the time step bigger (“update per second” smaller), but that will actually make the simulation unstable (etc. unstable collision detection).

Is there any way to execute more step in the simulation in short time without making the physics worse??

2 Likes

Hi,

According to the docstrings of the update method (line 170 of /isaac-sim/_build/linux-x86_64/release/exts/omni.isaac.synthetic_utils/omni/isaac/synthetic_utils/scripts/omnikit.py) you can decouple the physics step size from rendering using the /physics/timeStepsPerSecond and /physics/maxNumSteps parameters.

/isaac-sim/_build/linux-x86_64/release/exts/omni.isaac.synthetic_utils/omni/isaac/synthetic_utils/scripts/omnikit.py

def update(self, dt=0.0, physics_dt=None, physics_substeps=None):
    """Render one frame. Optionally specify dt in seconds, specify None to use wallclock. 
    Specify physics_dt and  physics_substeps to decouple the physics step size from rendering

    For example: to render with a dt of 1/30 and simulate physics at 1/120 use:
        - dt = 1/30.0
        - physics_dt = 1/120.0
        - physics_substeps = 4

    Args:
        dt (float): The step size used for the overall update, set to None to use wallclock
        physics_dt (float, optional): If specified use this value for physics step
        physics_substeps (int, optional): Maximum number of physics substeps to perform
    """
    # dont update if exit was called
    if self._exiting:
        return
    if physics_substeps is not None and physics_substeps > 0:
        self.kit_settings.set("/physics/maxNumSteps", int(physics_substeps))
    if dt is not None:
        if self.kit_settings and dt > 0.0:
            if physics_dt is None or physics_dt <= 0.0:
                self.kit_settings.set("/physics/timeStepsPerSecond", float(1.0 / dt))
            else:
                self.kit_settings.set("/physics/timeStepsPerSecond", float(1.0 / physics_dt))
        self.app.update(dt)
    else:
        time_now = time.time()
        dt = time_now - self.last_update_t
        self.last_update_t = time_now
        if self.kit_settings and dt > 0.0:
            if physics_dt is None or physics_dt <= 0.0:
                self.kit_settings.set("/physics/timeStepsPerSecond", float(1.0 / dt))
            else:
                self.kit_settings.set("/physics/timeStepsPerSecond", float(1.0 / physics_dt))
        self.app.update(dt)

Also, you can configure your simulation in the Simulator section from the Physics > Settings window.

1 Like

The parameter "/physics/timeStepsPerSecond" tells the simulator what is the physics time stepping.

Isaac sim is set to run real-time, and automatically compute how many simulation steps to run per rendering, constrained by the Max num steps (/physics/maxNumSteps) setting.

Below is a script to force execute physics time-steps decoupled from rendering or timeline buttons. Bear in mind that the stepping loop is a locking function, and UI will freeze for the duration of the loop. There is a known bug currently being worked on on this approach where the simulation may freeze if a contact report happens during one of the steps.

from pxr import Usd, UsdGeom
import omni.usd
from omni.physx import  acquire_physx_interface


stage = omni.usd.get_context().get_stage()
print(stage)

physx = acquire_physx_interface()

dt = 1/60.0
physx.reset_simulation()
physx.start_simulation()
# Simulate 20 steps, increase start_time if the desired initial step time is not at zero
start_time = 0.0
for i in range(20):
    physx.update_simulation(dt, start_time+ i*dt)
    physx.update_transformations(False, True)

# To stop the simulation and reset the scene:
def stop():
    physx.reset_simulation()
    physx.update_transformations(False, True)
1 Like

Thanks for the reply. I have tried changing the /physics/timeStepsPerSecond but it seems to only change the frame rate that physics updates instead of how fast the system runs. Is there a way to make isaac sim runs faster/slower than realtime?

Yes – Using the script in the previous reply should show you how to step the physics scene decoupled from rendering,

The only issue in using this script with the released version is if you have any object with the ContactReportAPI enabled, it will freeze the simulation. This issue has already been fixed for upcoming releases.

thanks, I have been trying your script in extension, but it does not seem to work. To be specific, currently, I am running a robotics application as an extension using isaac-sim, but we want to be able to test it at a faster speed. I am able to make the simulation run slower by changing the /physics/timeStepsPerSecond and `/physics/maxNumSteps, but there is no minNumSteps. I think the better question is how to adjust how many simulation steps per rendering when running an extension?

How are you trying to run the script? What is the error you are getting? A video or some other sort of information to help us understand what’s happening would greatly assist us to provide you with the correct next steps.

You may want to decouple physics from rendering on your extension, and on the editor update callback, call the equivalent of:

for i in range(n_steps):
    physx.update_simulation(dt, start_time+ i*dt)
    physx.update_transformations(False, True)

for as many time-steps as you want to perform on each rendering. Make sure to not click on the UI Play if you are updating the physics with your own steps, as it would recapture the physics scene and you’d need to reload the stage to be able to control through with the scripted update.

as a side note: Please be sure that the settings in the physics panel are as such:

  • Enable Update to USD
  • Enable Update Velocities to USD
  • Enable Use Fast Cache
  • Enable Reset Simulation On Stop.