Running Python Script from VS Code

I am running this Python Script of Simple Stack example directly retrieved from the omni.isaac.examples on VSCode.

My adjustment is to add the following lines at the bottom of the script to set up and load the scene. I am wondering whether running pure Python Script requires any additional setup step to run it in Isaac Sim.

sim = SimpleStack()
sim.setup_scene()
sim.setup_post_load()


from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.core import World
from omni.isaac.franka.controllers.stacking_controller import StackingController
from omni.isaac.franka.tasks import Stacking

class SimpleStack(BaseSample):
def init(self) → None:
super().init()
self._controller = None
self._articulation_controller = None

def setup_scene(self):
    world = World()
    world.add_task(Stacking(name="stacking_task"))
    return

async def setup_post_load(self):
    self._franka_task = self._world.get_task(name="stacking_task")
    self._task_params = self._franka_task.get_params()
    my_franka = self._world.scene.get_object(self._task_params["robot_name"]["value"])
    self._controller = StackingController(
        name="stacking_controller",
        gripper=my_franka.gripper,
        robot_articulation=my_franka,
        picking_order_cube_names=self._franka_task.get_cube_names(),
        robot_observation_name=my_franka.name,
    )
    self._articulation_controller = my_franka.get_articulation_controller()
    return

def _on_stacking_physics_step(self, step_size):
    observations = self._world.get_observations()
    actions = self._controller.forward(observations=observations)
    self._articulation_controller.apply_action(actions)
    if self._controller.is_done():
        self._world.pause()
    return

async def _on_stacking_event_async(self):
    world = self.get_world()
    world.add_physics_callback("sim_step", self._on_stacking_physics_step)
    await world.play_async()
    return

async def setup_pre_reset(self):
    world = self.get_world()
    if world.physics_callback_exists("sim_step"):
        world.remove_physics_callback("sim_step")
    self._controller.reset()
    return

def world_cleanup(self):
    self._controller = None
    return

sim = SimpleStack()
sim.setup_scene()
sim.setup_post_load()

Here is the log:

[2:32:00 PM] executing at 127.0.0.1:8226…

[2:32:00 PM] executed without output

This is the log from the Isaac Sim console

Which version are you currently using? If it’s not version 4.5.0, please upgrade to that version.

I am using 4.2.0. I will upgrade to 4.5.0 and try it again, but a quick question: does running pure Python scripts require additional set-up? I saw some discussion SimulationApp but I dont understand how it would help me.

The SimpleStack class above works when it is launched from the Isaac Sim GUI with the Load, Start, Reset buttons. But when the exact script of Simple Stack is run on VSCode (as above), it does not work.

Do I misunderstand the workflow anywhere?

Thanks in advance!

How are you running the script prior to VSCode? as an extension? When a script isn’t running within an existing Isaac Sim application, you’ll need to import SimulationApp to properly manage the application’s lifecycle.

Its API Documentation:

Thanks Vick. I realised that I need more setup to run that python script.

Context: I am running Isaac Sim via AWS EC2, stream Isaac Sim GUI using Omniverse Streaming client, and ssh connect VSCode to the AWS EC2 instance. From here, I can run Python script on VSCode that connects to Isaac Sim. However, I am unable to launch VSCode from Isaac Sim (unable to open the source code of Isaac Examples for instance).

My code now works without SimulationApp, but I am uncertain about whether I could use SimulationApp for my use case.

From Isaac Sim tutorial, using VSCode is technically using Script Editor from Isaac Sim and it is different from running standalone python script. Would you mind help me clarify this?

Please refer to Hello World — Isaac Sim Documentation. You should be able to open its source code in VS Code.