Closed Jordan-Dennis closed 1 year ago
Here is a minimal working example of the problem and proposed hack, which does not work,
import equinox as eqx
class A(eqx.Module):
a: int
def __init__(self, a: int) -> object:
self.a = a
class B(A):
_a: int
_b: int
_c: bool
def __init__(self, _a: int, _b: int, _c: bool) -> object:
self._a: int = _a
self._b: int = _b
self._c: bool = _c
self.a = property(lambda: self._a if self._c else self._b)
B(1, 2, True).a # A property object
B(1, 2, True).a.fget # The lambda function (needs to be evaluated).
This shows that the hack is not available. For now I will simply override the required methods and add the additional getter. Regards Jordan
This lead me to have an interesting thought. Using meta-classes it should be possible to make equinox
automatically turn variables into properties (the setter
using tree_at
). This would give us back the traditional python
syntax class.parameter = new_value
. However, because of immutability you would end up with variable: object = class.parameter = new_value
, which would probably cause a lot of headaches.
Sorry I don't really follow, why do you need to access a modified versoin of the pixel scale for the GaussianWavefront?
The pixel_scale
changes if the wavefront is angular or not. It is an implementation detail really ...
I mean it only changes the units. Can't we just have a BaseGaussianWavefront
and then and CartesianGaussianWavefront
and AngularGaussianWavefront
that implements the function to output in the right units? This would match the way Wavefronts
behaves current
I do not believe that would work since the Wavefront
becomes angular within the waist of the beam (if I am recalling correctly).
Closing this for now, until we try to re-implement this functionality.
Hi all, The (not so) new
property
based implementation of theWavefront
class is great but I have encountered a small inconvinience trying to upgrade theGaussianWavefront
to match. The problem ispixel_positions
accessespixel_scale
as a parameter. Via the inheritance mechanisms ofequinox
pixel_scale
must be kept as a parameter so I cannot, transfer it to aproperty
. This implies that I will require aget_pixel_scale
method and then re-implementpixel_positions
accessing thepixel_scale
parameter via theget_pixel_scale
method. This seems like a fair amount of extra work. It may be possible to hack a solution using alambda
function closure, but I am not sure if this is a good idea. Regards Jordan.