Skip to content
New issue

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

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

Already on GitHub? # to your account

Plugins not reliably tracked if loaded externally #1542

Closed
mattwthompson opened this issue Feb 6, 2023 · 0 comments
Closed

Plugins not reliably tracked if loaded externally #1542

mattwthompson opened this issue Feb 6, 2023 · 0 comments

Comments

@mattwthompson
Copy link
Member

Describe the bug

The logic I introduced in #1467 only works if its call to load_handler_plugins is the first one.

To Reproduce

The simple behavior, which works fine, is

>>> from openff.toolkit import ForceField
>>> ForceField(load_plugins=True)._plugin_parameter_handler_classes
[<class 'custom_plugins.handler_plugins.CustomHandler'>]

If anything is done out of order, however, custom handlers are not tracked. This includes, for example, if the plugins are loaded before creating the ForceField:

>>> from openff.toolkit import ForceField
>>> from openff.toolkit.typing.engines.smirnoff.plugins import load_handler_plugins
>>> from openff.toolkit.typing.engines.smirnoff import ParameterHandler
>>> load_handler_plugins()
[<class 'custom_plugins.handler_plugins.CustomHandler'>]
>>> ForceField(load_plugins=True)._plugin_parameter_handler_classes
[]

This might sound like an esoteric case but downstream developers might want to know which plugins are available prior to creating a force field and this is unexpected behavior.

I think this is due to an interaction with all_subclasses:

>>> from openff.toolkit.typing.engines.smirnoff import ParameterHandler
>>> from openff.toolkit.utils.utils import all_subclasses
>>> from openff.toolkit.typing.engines.smirnoff.plugins import load_handler_plugins
>>> assert load_handler_plugins()[0] in ParameterHandler.__subclasses__()  # does not raise

This is a private attribute but one I'd like to behave more in line with expectations.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant