Unverified Commit 07fc74d2 authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Adds try-catch in all the scripts for safe app closing (#185)

# Description

Propogates the try-except-finally paradigm from the unit tests to all
the scripts. This ensures a cleaner exit of the script and allows a
better traceback print.

```python
import traceback

import carb

if __name__ == "__main__":
    try:
        # Run the main function
        main()
    except Exception as err:
        carb.log_error(err)
        carb.log_error(traceback.format_exc())
        raise
    finally:
        # close sim app
        simulation_app.close()
```

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
parent 8ba18efa
......@@ -23,7 +23,9 @@ simulation_app = SimulationApp({"headless": False})
"""Rest everything follows."""
import ctypes
import traceback
import carb
from omni.isaac.core.simulation_context import SimulationContext
from omni.isaac.orbit.devices import Se3Keyboard
......@@ -85,7 +87,13 @@ def main():
if __name__ == "__main__":
# Runs the main function
main()
# Close the simulator
simulation_app.close()
try:
# Run the main function
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -29,6 +29,10 @@ simulation_app = app_launcher.app
"""Rest everything follows."""
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.assets import AssetBaseCfg
from omni.isaac.orbit.assets.config.anymal import ANYMAL_C_CFG
......@@ -154,7 +158,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# Run the main function
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -35,7 +35,9 @@ simulation_app = SimulationApp(config)
import torch
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
from omni.isaac.cloner import GridCloner
from omni.isaac.core.simulation_context import SimulationContext
......@@ -175,7 +177,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# Run the main function
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -42,7 +42,9 @@ simulation_app = SimulationApp(config)
import numpy as np
import torch
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
from omni.isaac.cloner import GridCloner
from omni.isaac.core.objects import DynamicSphere
......@@ -182,7 +184,13 @@ def main():
if __name__ == "__main__":
# Runs the main function
main()
# Close the simulator
simulation_app.close()
try:
# Run the main function
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -63,7 +63,9 @@ simulation_app = SimulationApp(config)
import numpy as np
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
import omni.kit.commands
from omni.isaac.cloner import GridCloner
......@@ -200,7 +202,13 @@ def main():
if __name__ == "__main__":
# Runs the main function
main()
# Close the simulator
simulation_app.close()
try:
# Run the main function
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -41,6 +41,9 @@ simulation_app = app_launcher.app
import torch
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.assets import Articulation
......@@ -140,7 +143,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -36,7 +36,9 @@ import numpy as np
import os
import random
import torch
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
import omni.isaac.debug_draw._debug_draw as omni_debug_draw
import omni.replicator.core as rep
......@@ -226,7 +228,13 @@ def main():
if __name__ == "__main__":
# Runs the main function
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -33,7 +33,9 @@ simulation_app = app_launcher.app
import torch
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
from omni.isaac.cloner import GridCloner
......@@ -147,7 +149,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -25,6 +25,9 @@ simulation_app = app_launcher.app
"""Rest everything follows."""
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.sim import SimulationContext
......@@ -61,7 +64,13 @@ def main():
if __name__ == "__main__":
# Run empty stage
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -32,7 +32,9 @@ simulation_app = app_launcher.app
"""Rest everything follows."""
import torch
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
from omni.isaac.cloner import GridCloner
from omni.isaac.core.simulation_context import SimulationContext
......@@ -224,7 +226,13 @@ def main():
if __name__ == "__main__":
# Run IK example with Manipulator
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -28,6 +28,9 @@ simulation_app = app_launcher.app
"""Rest everything follows."""
import torch
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.markers import VisualizationMarkers, VisualizationMarkersCfg
......@@ -136,7 +139,13 @@ def main():
if __name__ == "__main__":
# Run empty stage
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -33,6 +33,9 @@ simulation_app = app_launcher.app
"""Rest everything follows."""
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.assets import Articulation
......@@ -118,7 +121,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -38,6 +38,9 @@ simulation_app = app_launcher.app
import torch
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.assets import Articulation
......@@ -156,7 +159,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -35,7 +35,9 @@ simulation_app = app_launcher.app
import torch
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
from omni.isaac.cloner import GridCloner
from omni.isaac.core.simulation_context import SimulationContext
......@@ -245,7 +247,13 @@ def main():
if __name__ == "__main__":
# Run IK example with Manipulator
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -28,6 +28,9 @@ app_launcher = AppLauncher(headless=args_cli.headless)
simulation_app = app_launcher.app
"""Rest everything follows."""
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.assets import AssetBaseCfg
......@@ -147,7 +150,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -28,6 +28,9 @@ simulation_app = app_launcher.app
"""Rest everything follows."""
import torch
import traceback
import carb
import omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.assets import RigidObject, RigidObjectCfg
......@@ -116,7 +119,13 @@ def main():
if __name__ == "__main__":
# Run the main function
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -31,6 +31,9 @@ simulation_app = app_launcher.app
import gym
import torch
import traceback
import carb
import omni.isaac.contrib_envs # noqa: F401
import omni.isaac.orbit_envs # noqa: F401
......@@ -58,8 +61,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -31,9 +31,11 @@ simulation_app = app_launcher.app
import gym
import torch
import traceback
from enum import Enum
from typing import Sequence
import carb
import warp as wp
from omni.isaac.orbit.utils.timer import Timer
......@@ -278,7 +280,13 @@ def main():
if __name__ == "__main__":
# run main function
main()
# close simulation
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -33,6 +33,7 @@ simulation_app = app_launcher.app
import gym
import torch
import traceback
import carb
......@@ -114,8 +115,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -30,6 +30,9 @@ simulation_app = app_launcher.app
import gym
import torch
import traceback
import carb
import omni.isaac.contrib_envs # noqa: F401
import omni.isaac.orbit_envs # noqa: F401
......@@ -57,8 +60,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -38,7 +38,9 @@ simulation_app = app_launcher.app
import gym
import math
import os
import traceback
import carb
from rl_games.common import env_configurations, vecenv
from rl_games.common.player import BasePlayer
from rl_games.torch_runner import Runner
......@@ -138,8 +140,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -43,8 +43,10 @@ simulation_app = app_launcher.app
import gym
import math
import os
import traceback
from datetime import datetime
import carb
from rl_games.common import env_configurations, vecenv
from rl_games.common.algo_observer import IsaacAlgoObserver
from rl_games.torch_runner import Runner
......@@ -131,8 +133,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -36,6 +36,9 @@ import contextlib
import gym
import os
import torch
import traceback
import carb
from omni.isaac.orbit.devices import Se3Keyboard, Se3SpaceMouse
from omni.isaac.orbit.utils.io import dump_pickle, dump_yaml
......@@ -158,8 +161,16 @@ def main():
# close the simulator
collector_interface.close()
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -31,7 +31,9 @@ simulation_app = app_launcher.app
import gym
import torch
import traceback
import carb
import robomimic # noqa: F401
import robomimic.utils.file_utils as FileUtils
import robomimic.utils.torch_utils as TorchUtils
......@@ -79,8 +81,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -32,7 +32,9 @@ simulation_app = app_launcher.app
import gym
import os
import traceback
import carb
from rsl_rl.runners import OnPolicyRunner
import omni.isaac.contrib_envs # noqa: F401
......@@ -101,8 +103,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -44,8 +44,10 @@ simulation_app = app_launcher.app
import gym
import os
import torch
import traceback
from datetime import datetime
import carb
from rsl_rl.runners import OnPolicyRunner
from omni.isaac.orbit.utils.dict import print_dict
......@@ -129,8 +131,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -32,7 +32,9 @@ simulation_app = app_launcher.app
import gym
import traceback
import carb
from stable_baselines3 import PPO
from stable_baselines3.common.vec_env import VecNormalize
......@@ -88,8 +90,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -43,8 +43,10 @@ simulation_app = app_launcher.app
import gym
import os
import traceback
from datetime import datetime
import carb
from stable_baselines3 import PPO
from stable_baselines3.common.callbacks import CheckpointCallback
from stable_baselines3.common.logger import configure
......@@ -125,8 +127,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -37,7 +37,9 @@ simulation_app = app_launcher.app
import gym
import traceback
import carb
from skrl.agents.torch.ppo import PPO, PPO_DEFAULT_CONFIG
from skrl.utils.model_instantiators import deterministic_model, gaussian_model, shared_model
......@@ -143,8 +145,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -48,8 +48,10 @@ simulation_app = app_launcher.app
import gym
import traceback
from datetime import datetime
import carb
from skrl.agents.torch.ppo import PPO, PPO_DEFAULT_CONFIG
from skrl.memories.torch import RandomMemory
from skrl.utils import set_seed
......@@ -178,8 +180,16 @@ def main():
# close the simulator
env.close()
simulation_app.close()
if __name__ == "__main__":
main()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -65,7 +65,9 @@ simulation_app = SimulationApp(config)
"""Rest everything follows."""
import traceback
import carb
import omni.isaac.core.utils.prims as prim_utils
from omni.isaac.cloner import GridCloner
from omni.isaac.core.simulation_context import SimulationContext
......@@ -125,7 +127,13 @@ def main():
if __name__ == "__main__":
# Run cloning example
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
......@@ -71,7 +71,9 @@ simulation_app = SimulationApp(config)
"""Rest everything follows."""
import os
import traceback
import carb
import omni.isaac.core.utils.stage as stage_utils
import omni.kit.app
......@@ -134,7 +136,13 @@ def main():
if __name__ == "__main__":
# Run cloning example
main()
# Close the simulator
simulation_app.close()
try:
# run the main execution
main()
except Exception as err:
carb.log_error(err)
carb.log_error(traceback.format_exc())
raise
finally:
# close sim app
simulation_app.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment