Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components should be reset when state changes are not due to execution #2695

Open
kmantel opened this issue Jun 10, 2023 · 0 comments
Open
Assignees
Labels
bug Should work but doesn't

Comments

@kmantel
Copy link
Collaborator

kmantel commented Jun 10, 2023

In many cases, avoiding changing integrator state (mainly previous_value) during initialization is handled by checking for Component.is_initializing with the function body. Some cases are missed, due to changes after a Component is no longer detected as being initialized or due to deeper nesting of functions in Parameters, etc, leading to advanced integration state before any real execution has occurred. ex:

import psyneulink as pnl

obj = pnl.ObjectiveMechanism()
mech = pnl.ProcessingMechanism()

comp = pnl.Composition()
comp.add_node(mech)
comp.add_linear_processing_pathway([mech, obj])

integrator = pnl.SimpleIntegrator()
print(integrator.previous_value)
# [0]

comp.add_controller(
    pnl.OptimizationControlMechanism(
        objective_mechanism=obj,
        state_features=[mech.input_port],
        control_signals=pnl.ControlSignal(
            modulates=('intercept', mech),
            allocation_samples=[0],
            cost_options=pnl.CostFunctions.DURATION,
            duration_cost_function=integrator
        ),
    )
)

print(comp.controller.control_signals[0].function.duration_cost_fct.previous_value)
# [4.]

Components should be reset to a default state on initialization-like executions, from actual initialization or updates to default variable shape, for example. The manual checks in integrators are also not comprehensive, because there may be other kinds of integrator-like state in other types of Components.

@kmantel kmantel added the bug Should work but doesn't label Jun 10, 2023
@kmantel kmantel self-assigned this Jun 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Should work but doesn't
Projects
None yet
Development

No branches or pull requests

1 participant