"Error: Import torch after isaacgym" restrictive when combining with ray[rllib]

Hi! I’m wondering how important it is to import isaac-gym before torch. I’m trying to use it with ray[rllib], which has a register_env() function that get’s called multiple times deep in the weeds by rollout workers and unfortunately by the time it creates these envs internally, torch is already loaded, resulting in the below error:

File "/home/code/isaacgym/python/isaacgym/gymdeps.py", line 21, in _import_deps
(pid=151175)     raise ImportError("PyTorch was imported before isaacgym modules.  Please import torch after isaacgym modules.")

Any suggestions how I can make sure isaac-gym is imported before, even with more involved libraries and env-factories?
And thanks so much for this great simulator!

Hi @alexander.w.winkler

You can always import issacgym before torch at the beginning of the first script called by the python interpreter, even if they are not going to be used there…

By doing this the condition can be fulfilled for all cases. Python only loads a module the first time the import statement is executed, next time it just gets a reference.

import isaacgym
import torch
3 Likes

Cool, thanks for clarifying! Seems like adding import isaacgym to ray’s private function_manager.py file allows it to be imported first, even with multiple threads/workers.

2 Likes

@alexander.w.winkler
Awesome, it works! B.t.w, could you share some experience (or repositories) for combining rllib and Isaac gym. Cause I’m working on this part now.