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

Fixes #178, fixes #153 Modal Decomposition Bug #206

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

rob-shalloo
Copy link
Member

@rob-shalloo rob-shalloo commented Nov 1, 2023

There is a bug in modal_decompositon.py which has been raised in issues #153 and #178 raised by @alexanatoly and @RemiLehe . I've looked into this and found that where the coefficient for each mode is calculated, it remains complex when it should be cast to real. This previously threw some warnings but let the code run. However, recently it has stopped working altogether. The fix is simple, just cast to real. Have confirmed that the decomposition still functions on the test data.

Until this gets merged with development, a workaround would be to cast the modal coefficients to real before using them. For example starting at line 53 in example_modal_decompositon_data.py

# Reconstruct the pulse using a series of hermite-gauss modes
for i, mode_key in enumerate(list(modeCoeffs)):
    tmp_transverse_profile = HermiteGaussianTransverseProfile(
        waist, mode_key[0], mode_key[1]
    )
    if i == 0:
        reconstructedProfile = modeCoeffs[
            mode_key
        ] * CombinedLongitudinalTransverseProfile(
            wavelength, pol, energy, longitudinal_profile, tmp_transverse_profile
        )
    else:
        reconstructedProfile += modeCoeffs[
            mode_key
        ] * CombinedLongitudinalTransverseProfile(
            wavelength, pol, energy, longitudinal_profile, tmp_transverse_profile
        )

would become


# Reconstruct the pulse using a series of hermite-gauss modes
for i, mode_key in enumerate(list(modeCoeffs)):
    tmp_transverse_profile = HermiteGaussianTransverseProfile(
        waist, mode_key[0], mode_key[1]
    )
    if i == 0:
        reconstructedProfile = np.real(modeCoeffs[
            mode_key
        ] ) * CombinedLongitudinalTransverseProfile(
            wavelength, pol, energy, longitudinal_profile, tmp_transverse_profile
        )
    else:
        reconstructedProfile += np.real(modeCoeffs[
            mode_key
        ] ) * CombinedLongitudinalTransverseProfile(
            wavelength, pol, energy, longitudinal_profile, tmp_transverse_profile
        )

@rob-shalloo rob-shalloo changed the title Fixes #178, fixes #153 Fixes #178, fixes #153 Modal Decomposition Bug Nov 1, 2023
Copy link
Member

@RemiLehe RemiLehe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@RemiLehe RemiLehe merged commit 9c42cd3 into LASY-org:development Nov 1, 2023
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

Successfully merging this pull request may close these issues.

2 participants