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

pupil_u, pupil_v being modified in RubinOptics.applyTo #475

Closed
esheldon opened this issue May 17, 2024 · 5 comments
Closed

pupil_u, pupil_v being modified in RubinOptics.applyTo #475

esheldon opened this issue May 17, 2024 · 5 comments

Comments

@esheldon
Copy link
Contributor

I noticed that the pupil positions of the photon array are being modifed by RubinOptics.applyTo

Here "x, y" are references to the pupil values, not copies

x, y = photon_array.pupil_u, photon_array.pupil_v

subsequently these get modified in place in the trace call.

I suggest that those x, y should be copies of the pupil values rather than references

@rmjarvis
Copy link
Contributor

I think I would probably consider this a bug in batoid.RayVector._directInit. That function shouldn't modify it's input parameters. @jmeyers314 Would this be an easy fix to make? Or should we add a line to make copies in imsim?

@jmeyers314
Copy link
Member

I think I'd probably just make copies on the line @esheldon highlighted. A bunch of batoid operates in-place by design b/c I noticed it made a noticeable speed difference.

As an aside, supposedly the public RayVector ctor makes copies, so we could theoretically switch to that: https://github.com/jmeyers314/batoid/blob/07edb511630c57131d9072494e7855571865e3fa/batoid/rayVector.py#L23-L25.

Though now I'm looking at the docs for np.ascontiguousarray and see that it only copies if needed, so the above docstring might be a lie.

Weird:

In [13]: arr = np.arange(10)

In [14]: arr1 = np.ascontiguousarray(arr)

In [15]: arr1.data == arr.data
Out[15]: True

In [16]: arr1.data
Out[16]: <memory at 0x105859b40>

In [17]: arr.data
Out[17]: <memory at 0x11fe374c0>

In [18]: arr1 is arr
Out[18]: True

So the str() prints out different addresses but they're actually the same?

@rmjarvis
Copy link
Contributor

I think these are two different pointers to the same place in memory. The hex value you see here is the address of the pointer. Not the address it points to.
Check either arr.ctypes.data or arr.__array_interface__['data']. These should match if the arrays point to the same place in memory.

@rmjarvis
Copy link
Contributor

And I take back the comment that this is a bug in batoid. It's a leading underscore method, which (in my framework of UI design) is allowed to take this kind of shortcut. So I agree it's on us to use that method properly. There may still be a bug in the non-underscore version, but that's a separate matter.

@jmeyers314
Copy link
Member

Addressed by #477 .

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

No branches or pull requests

3 participants