kaanaksit / odak

Scientific computing library for optics, computer graphics and visual perception.
https://kaanaksit.com/odak
Mozilla Public License 2.0
176 stars 52 forks source link

Pytorch and numpy/cupy comparison for beam propagation #19

Closed askaradeniz closed 3 years ago

askaradeniz commented 3 years ago

Currently, beam propagation functions of odak.wave and odak.learn.wave give different outputs for the same input field.

As discussed in #7 and #10, these are some of the functions that we can compare:

An example output for comparison from test_learn_beam_propagation.py with Bandlimited Angular Spectrum method:

AssertionError: 
Arrays are not almost equal to 3 decimals

Mismatched elements: 250000 / 250000 (100%)
Max absolute difference: 9.45276863
Max relative difference: 129.77451864
 x: array([[-301.293   +2.111j,  317.095 -225.884j, -209.758 +613.112j, ...,
         232.588  +45.735j,  250.056  +82.582j,  181.349 +147.647j],
       [-239.635  -60.857j, -221.058 +125.061j,   11.215 -475.677j, ...,...
 y: array([[-294.892   -1.521j,  310.806 -225.954j, -204.181 +611.055j, ...,
         230.09   +46.909j,  252.016  +83.05j ,  176.521 +149.347j],
       [-245.039  -56.122j, -215.765 +124.03j ,    6.634 -472.519j, ...,...
kaanaksit commented 3 years ago

Commit 78341250164d746876cf183b22bc1d2a7d0982d3 :

Current test/test_learn_beam_propagation.py returns no AssertionError for TR Fresnel method. However, Bandlimited Angular Spectrum method is still raising AssertionErrror.

kaanaksit commented 3 years ago

Looks like numpy and torch has a relatively different exp definition and this is an open issue at the moment.

kaanaksit commented 3 years ago

Commit 3e5b2163f86d910d98da36b789d7372a51f886cc adds assertion statement to the beam propagation methods in odak.learn.wave that are not matching Numpy/Cupy version.

kaanaksit commented 3 years ago

I am closing the issue as the latest and greatest code resolves this issue.