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

POEM 95: Support user/developer defined callback functions #193

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

A-CGray
Copy link

@A-CGray A-CGray commented Mar 6, 2024

No description provided.

@naylor-b
Copy link
Member

naylor-b commented Mar 7, 2024

@A-CGray are you familiar with OpenMDAO's 'hook' system? It's used by our report system, but it can also be used directly. It allows you to register functions either before or after (or both) a specific method in an OpenMDAO object, for example a Problem. So doing something like:

_register_hook('run_model', class_name='Problem', post=my_hook_function)

would call my_hook_function(p), where p is a Problem instance, at the end of the run_model method.

It's not very well documented, but if you're interested, take a look in openmdao/utils/hooks.py.

@A-CGray
Copy link
Author

A-CGray commented Mar 7, 2024

Thanks @naylor-b that does sound like it'd address the problem and driver level callbacks. Does it work at the component/system level too? i.e could the developer of a component implement a hook that will be called once at the end of run_model regardless of how the end user uses that component in their model? And without the user having to call _register_hook? If so then I think this would solve our problems

@naylor-b
Copy link
Member

naylor-b commented Mar 8, 2024

The use case where the component is registering hooks on the problem or driver might be hard to do in a non-hacky way. We may need to add something more specific for that instead of using the existing hook system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants