Skip to content

Conversation

@kyrsjo
Copy link
Contributor

@kyrsjo kyrsjo commented Jul 4, 2025

This patch adds support for negative strength (defocusing) for ChrPlasmaLens and ConstF elements. It also fixes a bug (use of uninitialized variable) in reference particle tracking for ChrPlasmaLens.

@kyrsjo
Copy link
Contributor Author

kyrsjo commented Jul 4, 2025

Hm, as soon as I made the PR I realized I forgot to fix tabs / spaces. However the bot seems to have messed up the number of spaces needed.

I'll fix (and probably force push to override its broken fixes).

Looks like the CI is running the tests for me, that's nice :)

@kyrsjo kyrsjo changed the title Negative k in APLs Negative k in APLs + avoid using uninitialized variables Jul 4, 2025
@ax3l ax3l requested review from ax3l and cemitch99 July 7, 2025 16:23
@ax3l ax3l added the component: elements Elements/external fields label Jul 7, 2025
@ax3l
Copy link
Member

ax3l commented Jul 7, 2025

Thank you for your first PR to ImpactX, @kyrsjo!

Those changes look great, let us structure & test them to make them best documented/portable/covered by CI.
Please simply push additional commits as needed to the PR to update it as needed.

I also started CI and sent you an invite to our GitHub org, please accept to auto-run CI even before your first PR got merged on updates.

Please make sure to provide a detailed description on the change and try to do one change at a time. e.g., if you fix a bug do it in one PR, adding a feature in another. Ideally, if it affects multiple elements as in your case, with unrelated bugs, then please make a PR per element (plasma lens, quad and ConstF here could be each a PR.)
This makes it easier for us to document changes for users and we can also "backport" fixes to older releases, when needed. It also enables us to merge things faster, because they are less complex and orthogonal changes can progress in parallel.

Please feel free to add your name to the author list of the respective files you changed.

If a specific bug is fixed (or feature added), then I usually structure my PR (branch) like this:

  • a commit that adds a test that triggers the exact bug (to cover it) / covers the new feature
  • another commit that adds the fix / feature
  • documentation updates, if needed (usually for new features)

Welcome again, looking forward to merging those! Please let us know if you have any questions ✨

@ax3l ax3l added bug Something isn't working bug: affects latest release Bug also exists in latest release version labels Jul 7, 2025
@kyrsjo
Copy link
Contributor Author

kyrsjo commented Jul 8, 2025

Hi @ax3l , thanks for the invite and for looking over it! Most fixes are easy, will do. For the "use ternary operator" thing, please see my comments.

I guess I should add tests for negative-k cases of these elements also.

Is it OK that we keep the elements in 1 PR? I'll separate out the m_slice_ds uninitialized stuff to a separate PR.

I see that the apochromat_pl and apochromat_pl.py tests are failing, will look into that.

General comment: I appreciate that you are insisting on small and readable PRs! Having been involved in a few codes myself, especially being the former release manager and git-repo-czar of sixtrack, it's a very good thing.

@ax3l
Copy link
Member

ax3l commented Jul 9, 2025

Thanks a lot @kyrsjo !

Is it OK that we keep the elements in 1 PR? I'll separate out the m_slice_ds uninitialized stuff to a separate PR.

I would really prefer to do one PR for each, because that way we can merge the quad right away and then decide for ConstF and plasma lens if and how much testing we add, too. Also makes the release notes that we auto-generate readable.

I already moved the Quad fix into #1038. Please merge in development here and it will vanish from the diff in this PR.

Please do the same for ConstF 🙏

Copy link
Member

@cemitch99 cemitch99 left a comment

Choose a reason for hiding this comment

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

I made some small comments, and will try to help pin down why the CI tests are currently failing.

@kyrsjo
Copy link
Contributor Author

kyrsjo commented Aug 25, 2025

I think this is ready for review/merging now, @ax3l & @cemitch99 ?

There are two questions I wonder about (datatype and tolerance) + 1 question I've answered (why negative).

Note that I've made the tests so that I can fit the ConstF tests into the same framework :)


# Forward-propagate that through the focusing/defocusing lens
# from the beginning, ignoring energy spread
# [Doesn't give same result as ChrPlasmaLens and ChrQuad for some reason, even when sigpt_0 = 0]
Copy link
Member

Choose a reason for hiding this comment

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

Does this comment still apply? If so, this needs to be addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, this was fixed here:

bb670a1#diff-a95909e2ce0d4e807a3fa1dc18e09c9c822ec1dbb1275b60b056c775609e216eL125

and then I started using the analytical estimate here:
7f06ab2

I will cleanup when I do constF, PR #1041 - the tests should share quite a bit of code.

beta_y = sigy2 / emittance_y
alpha_y = -epstrms["position_y"]["momentum_y"] / emittance_y

return (beta_x, beta_y, alpha_x, alpha_y)
Copy link
Member

Choose a reason for hiding this comment

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

Note: This works, but the values defined here are computed internally and stored as reduced_diagnostics. See this example for an alternative approach: https://impactx.readthedocs.io/en/latest/usage/examples/fodo_space_charge/README.html
It's fine to keep this for now.

Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for this! 🚀 ✨

@cemitch99 cemitch99 enabled auto-merge (squash) September 18, 2025 22:44
@cemitch99 cemitch99 merged commit 771000b into BLAST-ImpactX:development Sep 18, 2025
16 checks passed
@kyrsjo
Copy link
Contributor Author

kyrsjo commented Sep 22, 2025

Thank you @ax3l and @cemitch99 for merging! I will now proceed to ConstF. Also, PhD student @aellings will now be able to simulate diverging APLs in ImpactX :)

Maybe see you at Elba?

@ax3l ax3l deleted the APL-negK branch September 22, 2025 18:01
@ax3l
Copy link
Member

ax3l commented Sep 22, 2025

@kyrsjo Awesome, thanks for the contribution!!

Yes, I am at EAAC until Thursday noon, let's catch up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug: affects latest release Bug also exists in latest release version bug Something isn't working component: elements Elements/external fields

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants