Running PDG Work Item with Python script

   3759   6   0
User Avatar
Member
83 posts
Joined: April 2014
Offline
I was wondering if there was a way I could cook a PDG node, then select a specific work item index on that node.

I am doing something where I am submitting some rops to our farm (NOT using PDG), but a lot of the variables are being driven byt a CSV input PDG node. I can select the work item and send the rop to the farm, however the work item is not selected when the farm blade picks up the job. My work around would be to run a pre-render python script that would select the correct work item to get all the variables, just like I do locally.

Is something like this possible?
User Avatar
Staff
585 posts
Joined: May 2014
Offline
If all you need are the attributes/inputs from the work item, you can use the standard .json serialization file written out by the work item. That's what rop.py does to make attributes available in ROP jobs running on the farm - it deserializes the work item data into the session as the global, active work item. From $HFS/houdini/python2.7libs/pdg/job/rop.py:

json_data = os.environ['PDG_TEMP'] + '/data/' + args.item_name + ".json"     
json_data = hou.expandString(json_data)                                      
with open(json_data, 'r') as f:                                              
    buf = f.read()                                                           
    ctx = pdg.GraphContext()                                                 
    ctx.deserializeWorkItemFromJSON(buf)

This assumes you have the .json file written to disk somewhere you farm job can find it (you can see examples of what that file looks like in $PDG_TEMP/data/item_name.json for any PDG graph cook).

The approach you described should also work. From HOM, you can do use hou.TopNode.setSelectedWorkItem(..) to select a work item by id.
User Avatar
Member
83 posts
Joined: April 2014
Offline
tpetrick
The approach you described should also work. From HOM, you can do use hou.TopNode.setSelectedWorkItem(..) to select a work item by id.

Thanks, this works great. Is there a way to Generate a selected node? I get Segment faults if I don't generate first.
I found executeGraph but it it seems like it works for the whole network, I just want to do a specific node.
User Avatar
Member
83 posts
Joined: April 2014
Offline
Nevermind, it looks like executeGraph does not run the whole network, only up until the specified node.

However I am still getting crashes, even when I have already exectuted the graph. I am doing something like this.

otlTopPath = ”/obj/Box/topnet1/CacheIt1“
otlTopNode = hou.node(otlTopPath)

otlTopNode.executeGraph(0, 1, 1)
otlTopNode.setSelectedWorkItem(1)

I am not getting an error when I manually generate the top node (Right Click - Generate Node). I am only getting the crashes after doing the executeGraph(0, 1, 1).

I found setting executeGraph to executeGraph(0, 1, 0) resulted in no crashes, however that so only if I have Static jobs. When I have Dynamic ones, I get the crashes again.
Edited by Tyler Britton2 - May 29, 2019 15:42:36
User Avatar
Member
83 posts
Joined: April 2014
Offline
Yeah I am still getting crashes after having tried a lot of combinations. I cannot use setSelectedWorkItem after using executeGraph to cook a dynamic PDG node. It does work if I cook the dynamic node using Right Click-Generate node, and then use the setSelectedWorkItem to select the work item.
User Avatar
Staff
585 posts
Joined: May 2014
Offline
The crash should be fixed in today's daily build. It was occuring when the ID passed to setSelectedWorkItem was invalid. How are you determine which work item ID to select?

executeGraph(self, False, True, True) is effectively what a RMB->Generate Node will do, except it has the block argument set to True which you'll need in your case.
User Avatar
Member
83 posts
Joined: April 2014
Offline
Thanks for the fix. I can't really test it out with my exact situation because we are in full production and are hesitant to switch to a non-production build, but I will check it out in the future. Should executeGraph(self, False, True, True) crash or did that require a fix as well?

For testing, the ID is set to an index I know will pickup a work item, but in the overall case it is corresponding to a variation or cluster that the user is caching geometry for. Basically we were using PDG to cache out all of our geometry, so we had a lot of setups that used it. However we now got Houdini on our farm so I wanted a way to run a work item for each variation/cluster, and then launch that on the farm.
  • Quick Links