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

photon shooting? #50

Closed
beckermr opened this issue Aug 5, 2023 · 12 comments
Closed

photon shooting? #50

beckermr opened this issue Aug 5, 2023 · 12 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@beckermr
Copy link
Collaborator

beckermr commented Aug 5, 2023

How do we feel about photon shooting?

some initial thoughts:

  • GalSim has its own RNGs and jax requires you to use their RNG system
  • from a technical perspective, photon shooting is not so bad to get right
  • gradients through images made with photon shooting will be very odd / will not work since the binning into the pixels is discrete
  • however from the point of view of making images, being able to photon shoot on the GPUs would potentially be very efficient

BTW, I am very impressed by the work here everyone!

@EiffL
Copy link
Member

EiffL commented Aug 6, 2023

I have nothing against photon shooting :-)

I'm not too worried about the stochastic aspect of it. We have to replace GalSim's internal RNG system by a jax-based one anyway (which I think we can do while keeping the same API).

But yeah to make it differentiable we might want to use some relaxation tricks (essentially making the pixel assignment continuous and not discrete, so blurring a bit the pixel edges).

Also, I have NOT looked at the photon shooting implementation in GalSim, I'm not sure how it works in practice. Like do you draw from a base profile, then apply jacobian transformations for each photons, and somehow also apply the deviations caused by the PSF?
Or do you get the surface brightness profile after psf convolution, and just draw photons from that profile?

@beckermr
Copy link
Collaborator Author

beckermr commented Aug 6, 2023

The psf is added as a random perturbation to the photon locations. I agree the relaxation tricks would be good. We should add those as an option.

@EiffL
Copy link
Member

EiffL commented Aug 6, 2023 via email

@EiffL
Copy link
Member

EiffL commented Aug 7, 2023

Ah... one more serious complication. We need to know the number of photons we are going to draw at JIt time... And because that will depend on the magnitude of the object (which we certainly want to keep as a dynamically traced parameter) we can't know it.
The simple (but very ugly) solution is to have a fixed array of size N_max photons, and then give a weight to each photon (0 or 1) . this solution maintains fixed dimensionality, but of course is problematic for other reasons....

@beckermr
Copy link
Collaborator Author

beckermr commented Aug 7, 2023

Yup good point. I'm skeptical that making photon shooting differentiable is going to be worth the time and trouble in the end. I'd be tempted to just give up on the first pass and use while loops which can have variable sized lengths.

@EiffL
Copy link
Member

EiffL commented Aug 7, 2023

We might be able to do this in a clever way, like drawing by batches with a jax.lax.scan. The batches can have fixed sizes, and the last batch can be partially filled, with some photons having zero weight, so this way you reduce the memory overhead of assuming the worse case scenario.

@beckermr
Copy link
Collaborator Author

beckermr commented Aug 7, 2023

@rmjarvis Can explain in detail why galsim has a flux per photon? It seems logical, but I feel like I am missing some details in how this is used internally.

@rmjarvis
Copy link
Member

rmjarvis commented Aug 8, 2023

Normally it's 1 e- per photon (which is 1 ADU per photon with the default gain=1). The primary exception is InterpolatedImage, which can have negative flux parts. This implies that some of the photons need to have negative flux to implement this properly. To get the right Poisson statistics, the positive (and negative) flux photons can't have flux=1. There is a detailed discussion of this in section 6.3.6 of Rowe et all. Also in the code comment here.

@EiffL
Copy link
Member

EiffL commented Aug 8, 2023

Sorry for this very noob question, but can I ask what are the advantages of photon shooting?
FFTs are pretty cheap on GPU, do they have particular limitations that photon shooting gets around?

@rmjarvis
Copy link
Member

rmjarvis commented Aug 8, 2023

It depends on how bright the object is. Shooting ~10 photons is MUCH faster than doing FFTs. In realistic sims, we render lots of objects with flux<100.

@rmjarvis
Copy link
Member

rmjarvis commented Aug 8, 2023

Also, if you care about wavelength-dependent effects, photon shooting is significantly more efficient at almost any flux level.

@ismael-mendoza ismael-mendoza added enhancement New feature or request question Further information is requested labels Sep 12, 2023
@ismael-mendoza
Copy link
Collaborator

Closed by #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants