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

Orientation refinement produces rubbish results on some Windows installations #494

Closed
hakonanes opened this issue Jan 8, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@hakonanes
Copy link
Member

Histogram of scores before and after refinement:

image003.png

Corresponding score maps:

image001.png

Not sure of the reason yet, might be related to some incorrect use of data types. Tests on Windows don't catch this. Haven't experienced on Linux yet. Don't know about macOS.

A fix should be released as a 0.5.7 patch as soon as the cause is identified!

@hakonanes hakonanes added the bug Something isn't working label Jan 8, 2022
@hakonanes hakonanes pinned this issue Jan 9, 2022
@hakonanes
Copy link
Member Author

Identified the culprit:

@nb.jit("float64[:](float64, float64, float64)", nogil=True, nopython=True)
def _rotation_from_euler(alpha: float, beta: float, gamma: float) -> np.ndarray:
"""Convert three Euler angles (alpha, beta, gamma) to a unit
quaternion.
Taken from :meth:`orix.quaternion.Rotation.from_euler`.
Parameters
----------
alpha, beta, gamma
Euler angles in the Bunge convention in radians.
Returns
-------
rotation
Unit quaternion.
Notes
-----
This function is optimized with Numba, so care must be taken with
array shapes and data types.
"""
sigma = 0.5 * np.add(alpha, gamma)
delta = 0.5 * np.subtract(alpha, gamma)
c = np.cos(beta / 2)
s = np.sin(beta / 2)
rotation = np.zeros(4)
rotation[0] = c * np.cos(sigma)
rotation[1] = -s * np.cos(delta)
rotation[2] = -s * np.sin(delta)
rotation[3] = -c * np.sin(sigma)
if rotation[0] < 0:
rotation = -rotation
return rotation

This Numba function is used by objective functions during refinement to obtain an updated Rotation quaternion from a Euler angle triplet, which is returned by SciPy after each iteration in the parameter search. The function returned a completely different quaternion on Windows and Ubuntu when passing the same Euler angles. Turns out that initializing a zero (4,) NumPy array and setting each element is the cause for the different results. I replaced this with creating a Numpy array from the computed quaternion components, and Windows and Ubuntu produces the same quaternion, as expected. This in turn gave the same orientation refinement results on Windows and Ubuntu.

Will be fixed in a PR, and a new patch release 0.5.7 will be made tomorrow Monday January 10th.

@hakonanes
Copy link
Member Author

Solved in #495.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant