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

Variants: allow registering callbacks for variant changes #1367

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

Conversation

merlinND
Copy link
Member

Description

As discussed with @njroussel.

Currently, upon each variant change, we explicitly reload the custom Python integrators shipped in mitsuba.python.ad.integrators.
Users don't have access to such a mechanism.

By allowing users to register callbacks, they can now implement module loading & reloading for their custom Python plugins.
In the future, there may be a higher-level way for users to register plugins that will automatically create such a reload callback.

I also added an alias scoped_set_variant to variant_context so that it matches dr.scoped_set_flag().

Testing

Added a unit test check.

Checklist

  • My code follows the style guidelines of this project
  • My changes generate no new warnings
  • My code also compiles for cuda_* and llvm_* variants. If you can't test this, please leave below
  • I have commented my code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I cleaned the commit history and removed any "Merge" commits
  • I give permission that the Mitsuba 3 project may redistribute my contributions under the terms of its license

njroussel added a commit that referenced this pull request Nov 5, 2024
This reverts commits:
* 1fc2337
* 07d7c7a
* e88979f
* 1d2a28b
* aa823d4
* d4bef56
* 920fa62
@@ -44,6 +44,10 @@ PyObject *mi_dict = nullptr;
/// Current variant (string)
nb::object curr_variant;

/// Set of user-provided callback functions to call when switching variants
PyObject *variant_change_callbacks;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not an std::set or at least an nb::object?

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