Weird behavior when enabling gpu_dynamics through python code in Isaac Sim

Isaac Sim Version

4.0.0

Operating System

Ubuntu

Background Introduction

I am using python to do RL training in a self-defined Isaac Sim environment which involves particle simulation that requires me to set enable_gpu_dynamics = True in the physics_context. Each time the python script runs, it creates a simulation_context, loads the assets, and let the prims perform cerain tasks during the training. This is how I initialize my simulation:

        # variables for loading assets
        self.asset_path = "omniverse://cerlabnucleus.lan.local.cmu.edu/Users/yonghant/wheel_loader/new_env.usd"
        
        self.stage = stage_utils.get_current_stage()

        self.simulation_context = SimulationContext()
        self.physics_context = self.simulation_context.get_physics_context()
        
        # Enable GPU Dynamics for particle simulation
        self.physics_context.enable_gpu_dynamics(True)

        self.simulation_context.play()  # Start simulation
        self.simulation_context.step(render=True)

        self.simulation_context.initialize_physics()

        add_reference_to_stage(usd_path=self.asset_path, prim_path="/World")

        for _ in range(10):
            self.simulation_context.step(render=True)

Problem Noticed

However, each time I run the python script, an error message always appears and my particle system doesn’t work:

[Error] [omni.physx.plugin] Particles feature is only supported on GPU. Please enable GPU dynamics flag in Property/Scene of physics scene!

Here comes the most weird thing: The error message goes away after I manually click on the “physicscene” prim in the stage and reset my training environment, which means that my gpu dynamics is indeed enabled at the start, but there’s some updating issues going on with the physics_context that prevents it to realize that. This picture shows the behavior after manually clicking the “physicscene” prim, we can see that the “Enable GPU Dynamics” checkbox is already checked.

I also tried print the is_gpu_dynamics_enabled() for my physics_context, it always returns True, and the “enable gpu dynamics” flag is also checked in the GUI for the physicscene.

Related Issues

I tried all the methods listed in this forum, but none of them worked so far. I wonder is there any solution for this problem right now, or is there something wrong with my current code.