Evaluate a node in a Maya MEL script - maya

I have a Maya MEL script, which inserts some nodes. The evaluation seems to be deferred until the script finishes. I guess this comes from the pipeline evaluating when the shape is requested by the renderer, so the dirty propagation starts.
Now I want to run commands if the inserted node calculated a certain output like this:
$node = `insertMyNode`;
dgdirty ($node+".outputAttr");
if(`getAttr ($node+".outputAttr")` == 1) {
print("true");
} else {
print("false");
}
This always prints false. When I insert the node and then run getAttr ($node+".outputAttr") in the MEL editor, the node is computed and I get 1.
I tried dgeval as well and it didn't work either. I think in principle neither dgeval nor dgdirty should be needed but getAttr should start the dirty propagation.
But it always returns the default value of the node, not the evaluated one.
dgdirty $node works for me, but I still would rather only dirty the output I am using (and if possible automatically, not with a command which is documented to be for debugging purposeses), so the node does not need to recompute all outputs.
myNode has defined and inputMesh parameter which affects an output bool outputAttr value using attributeAffects in its C++ code. the insertMyNode command connects an input mesh. It is correct that the node is not computed without a connection to an output plug, but when reading the plug it should be computed. When I open the node editor and hover over the output plug, the node is computed correctly. I would expect getAttr to do the same in the example code above.

The dirty propagation usually works if you are dirtying input attributes and request output attributes. To it seems you are dirtying an input attribute and try to get the same input attribute. Usually in a node this is coded with "affects" like: affects(attrA, attrB). and if attrB is requested, the compute() method is called.
So I suppose it could work better if you try to get an output attribute.

Related

How do I select whether the routine continues based on the participant's response?

I want to create an experiment in PsychoPy Builder that conditionally shows a second routine to participants based on their keyboard response.
In the task, I have a loop that first goes through a routine where participants have three options to respond ('left','right','down') and only if they select 'left', regardless of the correct answer, should they see a second routine that asks a follow-up question to respond to. The loop should then restart with routine 1 each time.
I've tried using bits of code in the "begin experiment" section as such:
if response.key=='left':
continueRoutine=True
elif response.key!='left':
continueRoutine=False
But here I get an error saying response.key is not defined.
Assuming your keyboard component is actually called response, the attribute you are looking for is called response.keys. It is pluralised as it returns a list rather than a single value. This is because it is capable of storing multiple keypresses. Even if you only specify a single response, it will still be returned as a list containing just that single response (e.g. ['left'] rather than 'left'). So you either need to extract just one element from that list (e.g. response.keys[0]) and test against that, or use a construction like if 'left' in response.keys to check inside the list.
Secondly, you don't need to have a check that assigns True to continueRoutine, as it defaults to being True at the beginning of a routine. So it is only setting it to False that results in any action. So you could simply do something like this:
if not 'left' in response.keys:
continueRoutine = False
Lastly, for PsychoPy-specific questions, you might get better support via the dedicated forum at https://discourse.psychopy.org as it allows for more to-and-fro discussion than the single question/answer structure here at SO.

Verify edge and create edge in the same instruction (gremlin python)

My initial logic of checking if an edge is present and creating an edge needs to query. Im trying to verify and create an edge in one instruction.
This query does not seem to work
ipdb> prop = self._graph.V('pppp').outE('friend').hasId('testEdge').as_('e').inV()
.hasId('dddd').select('e').
coalesce(__.property('testedder', 1111).fold().unfold(),
__.V('dddd'). as_('to_a').V('pppp').addE('friend').to('to_a')).
toList()
1) The first part of the coalesce - updating the property of Edges work fine
2) The second part of the coalesce is either not being called or not working. It is working as an independent query. Does 'as' not work in anonymous traversals?
PS: Im using AWS Neptune
You had the right idea but you needed some simplification. I'll try to do it in steps. First, whenever I see labelled steps, I try to see if there is a way to avoid using them. In this case, they can be factored out:
g.V('pppp').outE('friend').
filter(hasId('testEdge').inV().hasId('dddd')).
coalesce(__.property('testedder', 1111).fold().unfold(),
__.V('dddd'). as_('to_a').V('pppp').addE('friend').to('to_a'))
Readability of the traversal improves on those first two lines because the reader can immediately see that you want to find an edge given some criteria which was only implied by the step labeling approach. Next, I looked at coalesce(). As it stands, if filter() returns no edges then coalesce() will never get a chance to execute and that's why the second part of coalesce() never has an opportunity to work for you. So, let's clean that part up:
g.V(1).outE('knows').
filter(hasId(6).inV().hasId(2)).
fold().
coalesce(unfold().property('testedder', 1111),
V('dddd').as_('to_a').V('pppp').addE('friend').to('to_a'))
If it's not clear why the fold() and unfold() are where they are, you should check out my detailed explanation of the approach here. So, with fold() and unfold() where they should be, the coalesce() should now trigger both conditions depending on whether or not an edge passes the filter(). The first part of the coalesce() is fine, but the second could still use a bit of work as I'd again like to factor out the step labels if the aren't necessary:
g.V('pppp').outE('friend').
filter(hasId('testEdge').inV().hasId('dddd')).
fold().
coalesce(unfold().property('testedder', 1111),
addE('friend').from(V('pppp')).to(V('dddd')))
The above Gremlin assumes that you know "pppp" vertex exists. If you do not then you might try (as suggested by Daniel Kuppitz):
g.V('pppp').
not_(outE('friend').hasId('testEdge').
filter(inV().hasId('dddd')).
property('testedder', 1111)).as('p').
V('dddd').
addE('friend').from('p')

how to use jump to if I need to evaluate a condition of context variable for two different nodes at same time

I have one parent node ,based on the user input Iam setting a context variable at my application level eligibility:yes or no and passing back.And for my parent node I have two child nodes for conditions $eligibility=="yes" and $eligibility=="no".So once users input from parent node validation is done and context variable is passed back ,then I need to jump and look for condition of eligibility.If yes I need to go one node ,if no then to other.How can I do?
I tried putting true to node and added these two nodes to this and jump to true..But didnt worked..How can we achieve this?
what #data_henrik has mentioned is a good way to set context value and then switch to different flows depending upon the set value. But when you need to perform some logic before setting that value in the context from your application, it won't be a suitable way.
I had a requirement like this, so we used to send a dummy text from our application after we were done with setting the value in context after the parent node execution. Check out the images and explanation after that.
We didn't use Jump because we had to do some validation in the Conversation service after parent node before moving forward. Using jumps would've allowed the Conversation to move to next node before we could set value in context.
Use case flow - once user enters text for the parent node intent, for my case "#send-mail" intent, I show the parent response and do some functional validation in my app after that and add a value to the context. Now we send a dummy text "valid" which satisfies the intent "#Valid" and hence move to the next node in flow. In this node we check for the value in context (which is already set by now) and show appropriate response to user.
You can set within your first two test nodes, $testMe==true and $testMe==false a temp output variable within the output json packet, i.e. output{"temp":"true"} or "false". Then you can jump to a new set of nodes and test for the output.temp value, i.e. output.temp == 'true' then do something, or output.temp == 'false' then do something.
The nice side effect of this action is that the output.temp variable only has a life of that current conversation input. Unlike context variables which need to be removed / deleted.

PETSC_VIEWER_DRAW_WORLD shows nothing

I just started with PETSC and I'm trying to plot a matrix using matView. My code is like:
MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD, nodes, nodes, rows, cols, values, net); //I want to visualize "net"
//Visualization
if(display >= 1){
PetscPrintf(PETSC_COMM_WORLD, "CSR structure created.\n");
MatView(*net,PETSC_VIEWER_DRAW_WORLD);
}
When I use MatView this way:
MatView(*net,PETSC_VIEWER_STDOUT_WORLD);
I can see a list with the rows. But when I change it to
MatView(*net,PETSC_VIEWER_DRAW_WORLD);
nothing happens.
I can't see anything about net structure, not even the list.
I tried to run the examples but they don't work at all. Also, the PETSC documentation just makes things worse. Can someone help me? I don't want to see a list of rows, but the matrix (graphically).
More context from the comments:
X windows is functioning properly -- was able to confirm with gvim, xlogo, xeyes, etc.
Library has been rebuilt using --with-x option in configure. Still nothing appears.
Try using "-draw_pause -1" as an argument to your PETSc program, if you're not doing it yet.
-draw_pause - Sets time (in seconds) that the program pauses after PetscDrawPause() has been called (0 is default, -1 implies until user input).

libxml2: missing children when dumping a node with xmlNodeDump()

I'm facing an issue with libxml2 (version 2.7.8.13).
I'm attempting to dump a node while parsing an in-memory document with a xmlTextReaderPtr reader.
So upon parsing the given node, I use xmlNodeDump() to get its whole content, and then switch to the next node.
Here is how I proceed:
[...]
// get the xmlNodePtr from the text reader
node = xmlTextReaderCurrentNode(reader);
// allocate a buffer to dump into
buf = xmlBufferCreate();
// dump the node
xmlNodeDump(buf, node->doc, node, 0 /* level of indentation */, 0 /* disable formatting */);
result = strdup((char*)xmlBufferContent(buf));
This works in most cases, but sometimes the result is missing some children from the parsed node. For instance, the whole in-memory xml document contains
[...]
<aList>
<a>
<b>42</b>
<c>aaa</c>
<d/>
</a>
<a>
<b>43</b>
...
</aList>
and I get something like:
<aList>
<a>
<b>42</b>
</c>
</a>
</aList>
The result is well formed but it lacks some data ! A whole bunch of children has "disappeared". xmlNodeDump() should recursively dumps all children of .
It looks like some kind of size limitation.
I guess I do something wrong, but I can't figure out what.
Thank you for your answers.
I succeeded in implementing this correctly another way, still I do not understand what happened there. Thank you for having read my question.
FYI, instead of trying to tinker an existing parsing code based on xmlTextReader, I have just rewritten a small parsing module for my case (dump all the 1st level siblings into separate memory chunks).
I did so by using the parsing and tree modules of libxml2, so:
get the tree from the in-memory xml document with xmlReadMemory()
get the first node with xmlDocGetRootElement()
for each sibling (with xmlNextElementSibling() ), dump its content (all children recursively) with xmlNodeDump()
Et voilĂ , kinda straightforward actually. Sometimes it's easier to start from scratch...
I guess there was some side effect.

Resources