It's not always the case that layers == nodes, but where possible, LOPs will record a node's id to the "HoudiniPrimEditorNodes". This custom data is set per-primitive, and you can see it in the Scene Graph Details.
You can get at the nodes with a help function we have in loputils, by passing a lop node and prim path to loputils.getEditorNodes(). It just helps get node paths from the node ids stored as customdata.
This is used in the Scene Graph Tree's "Jump to Existing Editor Nodes" option, when you RMB on a prim.
Ok, after some exploration i found out using the USD api instead.
Since our prims are most of the time synced with the node name (with some exception that we can specify in code), i could look up every anonymous usd layers containing the name of the node. This allows to retrieve specific nodes quite fast :
prim=stage.GetPrimAtPath("/world/primitive")prim_name=prim.GetName()forprim_specinprim.GetPrimStack():forlyrinprim_spec.layer.GetLoadedLayers():lyr_name=lyr.GetDisplayName()# contains the houdini node name