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

Function repo plugin system #128

Closed
jesper-friis opened this issue Aug 30, 2023 · 0 comments · Fixed by #152
Closed

Function repo plugin system #128

jesper-friis opened this issue Aug 30, 2023 · 0 comments · Fixed by #152
Assignees

Comments

@jesper-friis
Copy link
Contributor

jesper-friis commented Aug 30, 2023

The current implementation of add_function() is very simple. It just stores the function in an internal dict. This has several drawbacks:

  • it is not persistent
  • it is not shared between processes or sessions (which might be needed with OTEAPI services running on a distributed system)
  • it stores information outside the triplestore

I can think about two solutions:

  1. Pickle the function and store the pickle in the triplestore. The pickle module in the standard library will not work, since it requires the function to be available when unpickled. But dill will work for most functions, except for functions with recursive inner functions. However, there is an article about how to also solve that case, see https://medium.com/@greyboi/serialising-all-the-functions-in-python-cd880a63b591.

  2. Identify the function with a set of string properties:

    • PyPI package name (a string in the same form as requirements.txt files including version requirements), optional
    • package name, optional
    • module name
    • function name

    These can easily be stored in the triplestore. To get the conversion function, you can give module and package names as arguments to importlib.import_module() and then fetch the function with getattr() on the return module object. The PyPI package name may be useful if we want to hint the user about a missing package or to dynamically install it if it is missing. Automatic installation raises some security concerns, so if implemented, this feature should probably be explicit enabled.

    This approach has already been implemented in the convert strategy in oteapi-dlite and seems to work well. See https://github.com/EMMC-ASBL/oteapi-dlite/blob/convert-function-strategy/oteapi_dlite/strategies/convert.py#L57.

Personally I prefer the second option, since it is simple and clean and stores no byte code that might result in portability issues.

@jesper-friis jesper-friis changed the title Design: Function repo plugin system Function repo plugin system Nov 12, 2023
@jesper-friis jesper-friis self-assigned this Nov 12, 2023
@jesper-friis jesper-friis linked a pull request Nov 12, 2023 that will close this issue
9 tasks
jesper-friis added a commit that referenced this issue Jan 25, 2024
# Description:
Closes #128 

See #128 for design and reasoning behind this PR. Needed for using
mapping functions in OTEAPI pipelines.

## Type of change:
- [ ] Bug fix.
- [x] New feature.
- [ ] Documentation update.
- [ ] Testing.
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 a pull request may close this issue.

1 participant