Skip to content

Conversation

@jgray-19
Copy link

@jgray-19 jgray-19 commented Jul 8, 2025

Description

Here I implement a thick and a thin AC-dipole along with tests.

Will the documentation inside the element classes be automatically inserted? I.e. Do I need to write additional documentation?

Also, help with how to run the GPU contexts would be nice!

Checklist

Mandatory:

  • I have added tests to cover my changes
  • All the tests are passing, including my new ones.
  • I described my changes in this PR description

Optional:

  • The code I wrote follows good style practices (see PEP 8 and PEP 20).
  • I have updated the docs in relation to my changes, if applicable.
  • I have tested also GPU contexts.

@jgray-19 jgray-19 changed the title Inital commit Implement AC-Dipole Elements Jul 8, 2025
- Consolidated ACDipole classes into a single ACDipole class that handles both tracking and twiss modes.
- Updated the constructor to accept parameters for voltage, frequency, lag, ramp, plane, twiss_mode, beta_at_acdipole, and natural_q.
- Removed the old ACDipoleThickHorizontal, ACDipoleThickVertical, ACDipoleThinHorizontal, and ACDipoleThinVertical classes.
- Modified the tracking logic to apply kicks based on the specified plane (horizontal or vertical).
- Updated tests to reflect the new ACDipole structure, removing orientation parameters and replacing them with plane parameters.
- Added a new test file for ACDipole twiss behavior.
- Removed the old thin AC dipole tests as they are no longer necessary.
- Updated C source files to reflect the new ACDipole structure and removed unnecessary files.
Copy link
Collaborator

@szymonlopaciuk szymonlopaciuk left a comment

Choose a reason for hiding this comment

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

It's good, just a few really minor comments.

Comment on lines 135 to 142
if not (
(isinstance(ramp, (list, tuple)) or hasattr(ramp, "__iter__"))
and len(ramp) == 4
and all(isinstance(int(x), int) for x in ramp)
):
raise ValueError(
"The ramp parameter must be a list of four integers: [ramp1, ramp2, ramp3, ramp4]."
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this a bit complicated for what it does.

  1. isinstance(ramp, (list, tuple)) implies hasattr(ramp, "__iter__"), so the first check is not necessary
  2. In most cases __iter__ implies a __len__. Sure there are exceptions, but on the other hand it's not strict enough anyway: set passes all the checks, but it's probably not desired. You'd probably also need to add a check to assert that the list is sorted as well?
  3. Is the check for integer not a bit strict? What if someone gives a float for whatever reason?

I agree the built-in error message in Xobjects is not the clearest, so having some sort of check is an improvement for the user. I'm not sure what is the best way, but I'd try to simplify. One possibility:

if len(ramp) != 4 or list(ramp) != sorted(ramp):
    raise ValueError(
        "The ramp parameter must be an increasing list of four integers."
    ) 

Copy link
Author

@jgray-19 jgray-19 Nov 4, 2025

Choose a reason for hiding this comment

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

How about:

        if not (len(ramp) == 4 and all(v == int(v) and v >= 0 for v in ramp) and ramp == sorted(ramp)):
            raise ValueError(
                "The ramp parameter must be an increasing list of four integers:"
                "[ramp_up_start_turn, ramp_up_end_turn, ramp_down_start_turn, ramp_down_end_turn]."
            )

Also, I see no problem with using a set, even though this would fail it now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ramp == sorted(ramp) will sadly fail for (1, 2, 3) because of the type. Could go with np.all(np.diff(ramp) >= 0) if you prefer, though I don't find that better.

Also afk at the moment and can't check, but is v == int(v) a reliable check? Maybe I prefer isinstance after all, less annoying if things go wrong.

Sorry for splitting hairs.

Copy link
Collaborator

@szymonlopaciuk szymonlopaciuk left a comment

Choose a reason for hiding this comment

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

See the one comment

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