Skip to content

[EXPERIMENTAL] Add "onchange" hook #262

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eriknw
Copy link
Member

@eriknw eriknw commented Jun 12, 2022

This is a PoC to see how invasive it is to add "onchange" hooks.

There may be two uses for this from graphblas-algorithms:

  1. Automatically invalidate the cache when the graph is modified.
    • This allows us to more safely expose the adjacency matrix A to the user.
  2. Make cached values read-only.

Overall, I'd say this isn't very invasive all things considered. The number of places hooks are in each file is:

  • expr.py: 2
  • base.py: 4
  • scalar.py: 2
  • vector.py: 3
  • matrix.py: 3
  • _ss/matrix.py and _ss/vector.py: a bunch due to pack methods

This hook system is pretty simple for now. It only has one hook, "onchange", and it only passes the object that would be changed to the function. Other hooks and arguments to pass to the callbacks are possible (hence our use of **kwargs in the callback for future compatibility). This also doesn't try to manage having multiple callbacks, which is fine for our current use cases where the objects with hooks will be managed by graphblas-algorithms.

We may want to add a simple API to manage hooks such as _add_hook, _has_hook, _call_hook, etc. to make it easier to evolve.

We can let this stew for a bit.

@eriknw eriknw added feature Something is missing lowpriority labels Jun 12, 2022
@eriknw eriknw requested a review from jim22k June 12, 2022 15:53
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 99.333% when pulling 5e625ac on eriknw:hooks into ececafc on python-graphblas:main.

@eriknw eriknw marked this pull request as draft October 19, 2022 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Something is missing lowpriority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants