Read and process Action Graph from USD file

Hi,

I am trying to write an extension which has to open an USD file, find an Action Graph in it and execute the graph.
I could read the .usda file this way:

stage: Usd.Stage = Usd.Stage.Open(filename)

‘fileName’ comes from the extension.toml as a property.

But when I try to get the Action Graph in it like this:

(graph, _, _, _) = og.Controller.edit("/World/ag1")

I get this error:
2023-10-03 08:05:01 [2,240,102ms] [Error] [omni.ui.python] OmniGraphError: Could not find orchestration graph for stage GraphPipelineStage.GRAPH_PIPELINE_STAGE_SIMULATION

So it seems for me somehow the stage should be bundled to OmniGraph or application context but I don’t know how to do it from python code.
I tried to get the given graph on an other way too (e.g.: path = Sdf.Path(“/World/ag1”) …), I have found some examples but none of them works, obviously OmniGraph can’t see the stage I have loaded from .usda file.

How should I make Omnigraph connected to the stage I read from an .usda file, to be able to use the graph for further actions?

Try using something like the code below. It could be the stage has not loaded so it cannot grab the graph:

import asyncio
import carb
import omni.usd
import omni.graph.core as og

path_to_usd_file = 'path'
graph_id = '/World/ActionGraph'

async def open_stage():
	result, error = await omni.usd.get_context().open_stage_async(path_to_usd_file, load_set=omni.usd.UsdContextInitialLoadSet.LOAD_NONE)
	stage = omni.usd.get_context().get_stage()
	controller = og.Controller()
	graph = controller.graph(graph_id)
	if graph:
		carb.log_info("graph exists")
run_loop = asyncio.get_event_loop()
run_loop.create_task(open_stage())