5555app_launcher = AppLauncher (args_cli )
5656simulation_app = app_launcher .app
5757
58+ """Check for installed RSL-RL version."""
59+
60+ import importlib .metadata as metadata
61+
62+ from packaging import version
63+
64+ installed_version = metadata .version ("rsl-rl-lib" )
65+
5866"""Rest everything follows."""
5967
6068import os
7684from isaaclab .utils .assets import retrieve_file_path
7785from isaaclab .utils .dict import print_dict
7886
79- from isaaclab_rl .rsl_rl import RslRlBaseRunnerCfg , RslRlVecEnvWrapper , export_policy_as_jit , export_policy_as_onnx
87+ from isaaclab_rl .rsl_rl import (
88+ RslRlBaseRunnerCfg ,
89+ RslRlVecEnvWrapper ,
90+ export_policy_as_jit ,
91+ export_policy_as_onnx ,
92+ handle_deprecated_rsl_rl_cfg ,
93+ )
8094from isaaclab_rl .utils .pretrained_checkpoint import get_published_pretrained_checkpoint
8195
8296from isaaclab_tasks .utils import get_checkpoint_path
@@ -100,6 +114,9 @@ def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agen
100114 agent_cfg : RslRlBaseRunnerCfg = cli_args .update_rsl_rl_cfg (agent_cfg , args_cli )
101115 env_cfg .scene .num_envs = args_cli .num_envs if args_cli .num_envs is not None else 64
102116
117+ # handle deprecated configurations
118+ agent_cfg = handle_deprecated_rsl_rl_cfg (agent_cfg , installed_version )
119+
103120 # set the environment seed
104121 # note: certain randomizations occur in the environment initialization so we set the seed here
105122 env_cfg .seed = agent_cfg .seed
@@ -189,27 +206,31 @@ def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agen
189206 # obtain the trained policy for inference
190207 policy = runner .get_inference_policy (device = env .unwrapped .device )
191208
192- # extract the neural network module
193- # we do this in a try-except to maintain backwards compatibility.
194- try :
195- # version 2.3 onwards
196- policy_nn = runner .alg .policy
197- except AttributeError :
198- # version 2.2 and below
199- policy_nn = runner .alg .actor_critic
200-
201- # extract the normalizer
202- if hasattr (policy_nn , "actor_obs_normalizer" ):
203- normalizer = policy_nn .actor_obs_normalizer
204- elif hasattr (policy_nn , "student_obs_normalizer" ):
205- normalizer = policy_nn .student_obs_normalizer
206- else :
207- normalizer = None
208-
209- # export policy to onnx/jit
209+ # export the trained policy to JIT and ONNX formats
210210 export_model_dir = os .path .join (os .path .dirname (resume_path ), "exported" )
211- export_policy_as_jit (policy_nn , normalizer = normalizer , path = export_model_dir , filename = "policy.pt" )
212- export_policy_as_onnx (policy_nn , normalizer = normalizer , path = export_model_dir , filename = "policy.onnx" )
211+
212+ if version .parse (installed_version ) >= version .parse ("4.0.0" ):
213+ # use the new export functions for rsl-rl >= 4.0.0
214+ runner .export_policy_to_jit (path = export_model_dir , filename = "policy.pt" )
215+ runner .export_policy_to_onnx (path = export_model_dir , filename = "policy.onnx" )
216+ else :
217+ # extract the neural network for rsl-rl < 4.0.0
218+ if version .parse (installed_version ) >= version .parse ("2.3.0" ):
219+ policy_nn = runner .alg .policy
220+ else :
221+ policy_nn = runner .alg .actor_critic
222+
223+ # extract the normalizer
224+ if hasattr (policy_nn , "actor_obs_normalizer" ):
225+ normalizer = policy_nn .actor_obs_normalizer
226+ elif hasattr (policy_nn , "student_obs_normalizer" ):
227+ normalizer = policy_nn .student_obs_normalizer
228+ else :
229+ normalizer = None
230+
231+ # export to JIT and ONNX
232+ export_policy_as_jit (policy_nn , normalizer = normalizer , path = export_model_dir , filename = "policy.pt" )
233+ export_policy_as_onnx (policy_nn , normalizer = normalizer , path = export_model_dir , filename = "policy.onnx" )
213234
214235 dt = env .unwrapped .step_dt
215236
@@ -226,7 +247,10 @@ def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agen
226247 # env stepping
227248 obs , _ , dones , _ = env .step (actions )
228249 # reset recurrent states for episodes that have terminated
229- policy_nn .reset (dones )
250+ if version .parse (installed_version ) >= version .parse ("4.0.0" ):
251+ policy .reset (dones )
252+ else :
253+ policy_nn .reset (dones )
230254 if args_cli .video :
231255 timestep += 1
232256 # Exit the play loop after recording one video
0 commit comments