PsyNeuLink icon indicating copy to clipboard operation
PsyNeuLink copied to clipboard

Termination Conditions in Compiled Compositions

Open tylergiallanza opened this issue 4 years ago • 3 comments

I am having trouble adding a termination condition to a compiled composition. Following #1585 , I tried setting the termination_processing property on the Composition directly instead of specifying it in the run method. However, this still results in an error with the following code:

python version=3.9.6 PNL version=0.9.1.1

mech = pnl.TransferMechanism(size=2,function=pnl.Linear,integrator_mode=True,integration_rate=.1)
comp = pnl.Composition(pathways=[mech],reinitialize_mechanisms_when=pnl.Never())

#response_layer.get_output_values(model)[0][0]
def converge(node, thresh, context):
    for val in node.get_output_values(comp)[0]:
        if abs(val) >= thresh:
            return True
    return False
epsilon = 0.01
comp.termination_processing = {pnl.TimeScale.TRIAL: pnl.While(converge, mech, 0.8)}
print(comp.run({mech:[0,1]},500))
print(comp.run({mech:[0,1]},500,execution_mode=pnl.ExecutionMode.LLVMRun))

AssertionError: Unsupported scheduling condition: While((TransferMechanism TransferMechanism-24), 0.8)

This is also the case when using a simpler condition, such as comp.termination_processing = {pnl.TimeScale.TRIAL: pnl.AfterPass(10)}.

tylergiallanza avatar Nov 10 '21 20:11 tylergiallanza

Only some conditions are supported in compiled mode as of now:

Always
Never
Not
All
AllHaveRun
Any
AtTrial
AtPass
EveryNCalls
BeforeNCalls
AtNCalls
AfterNCalls
WhenFinished
WhenFinishedAny
WhenFinishedAll

I think compiled versions of conditions like AfterPass could be written, but While may not because it takes an arbitrary python function. @jvesely would probably be able to correct me here if I'm wrong. Either way, I think we should document what's supported.

kmantel avatar Nov 13 '21 06:11 kmantel

correct. generic python functions won't work, unless PNL defines an API (similar to UDFs)

the current state of compiler support for scheduling conditions is tracked in https://github.com/PrincetonUniversity/PsyNeuLink/issues/1580 I'd close this as duplicate

jvesely avatar Nov 14 '21 16:11 jvesely

@tylergiallanza I've just merged changes in #2305 into the devel branch including a new Threshold condition, which works with compilation and should let you match the behavior in your custom condition above.

kmantel avatar Mar 08 '22 03:03 kmantel

Closing this because compiled Threshold is available since v0.11.0.0, and other conditions are tracked elsewhere as mentioned above

kmantel avatar Sep 15 '22 02:09 kmantel