mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.1k stars 246 forks source link

Variants: allow registering callbacks for variant changes #1367

Closed merlinND closed 3 days ago

merlinND commented 3 weeks ago

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

njroussel commented 3 days ago

I've added minor changes and rebased the branch.

Thanks @merlinND :+1:

merlinND commented 3 days ago

Sorry I was on holidays last week, thanks a lot for taking over @njroussel!

I had started with variant_change_callbacks as an nb::object but ended up downgrading it, I'm not sure why anymore. Probably I wasn't familiar enough with Nanobind to figure it out.

Edit: just saw your comment about nb::object vs nb::set, that must be what I ran into.

dvicini commented 3 days ago

Awesome, really nice addition!