Mutable vs Immutable #43
Replies: 2 comments 1 reply
-
So interestingly this is what wavefront.update_phasor()
.do_something()
.do_another_thing()
.do_more_things()
.do_final_thing() While we can't do this at the moment except for when using import dLux
wavefront = dLux.GaussianWavefront(parameters)
def gradable_with_respect_to_everything(wavefront, *other_required_params):
return wavefront.apply_optic(dLux.CircularApperture(radius))
.apply_propagator(dLux.FresnelDiffractor(distance))
.apply_optic(dLux.HexagonalMirror(required_params))
.apply_propagator(dLux.FraunhoferDiffractor(distance))
.apply_optic(dLux.Coronagraph(hope_I_spelled_it_correct))
.apply_propagator(dLux.FresnelDiffractor(distance))
.apply_detector(dLux.JitteredDetector(params)) Now obviously this syntax is almost the exact reverse of our current syntax, but I thought it was worth mentioning as a toy idea. |
Beta Was this translation helpful? Give feedback.
-
Neat stuff. I am a bit tempted to say that this isn't very equinoxy - we would want to be careful so that our code resembles ordinary equinox modules so that it plays nicely with other NNs. I would also say that a stack of methods like above is probably how I would have written this a year ago before equinox came out, to make a really nice functional Jax code, but we probably want to instead do all of the stacking of layers in an equinox |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I have been doing some fiddling this morning and despite the fact that
equinox
andjax
enforce immutability, it is possible for us to implement a mutable interface. This is easy and instead of returning the modified state viaequinox.tree_at
we re-assign it toself
. There is no computational benefit to doing this, but I thought it was worth mentioning that it was possible. Let me know what you think.Beta Was this translation helpful? Give feedback.
All reactions