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

PyAT: improved timelag solver #451

Merged
merged 7 commits into from
Jul 29, 2022
Merged

PyAT: improved timelag solver #451

merged 7 commits into from
Jul 29, 2022

Conversation

swhite2401
Copy link
Contributor

In get_timelag_from_U0 the numerical synchronous phase solver was failing in some cases in the presence of multiple rf systems, such as higher order cavities.
This PR proposes a simpler more robust version.

@swhite2401 swhite2401 requested review from lcarver and lfarv July 26, 2022 15:21
@swhite2401 swhite2401 added enhancement Python For python AT code labels Jul 27, 2022
@lcarver
Copy link
Contributor

lcarver commented Jul 27, 2022

I tested 2 cases. Single and multi harmonic. For both cases when the returned timelag is set on the cavities using

at.set_value_refpts(ring, cavpts, 'TimeLag', tl, copy=False)

then the equilibrium position for ct was on the order of 1e-5.

On closer inspection, I realised that I am not able to trigger the warning seen on line 163 of energy_loss.py. I put a 4th harmonic cavity with very high voltage (6.5e6/1.5) which gives multiple possible phis but it doesn't seem to catch the warning.

@swhite2401
Copy link
Contributor Author

On closer inspection, I realised that I am not able to trigger the warning seen on line 163 of energy_loss.py. I put a 4th harmonic cavity with very high voltage (6.5e6/1.5) which gives multiple possible phis but it doesn't seem to catch the warning.

Could you send a figure of the wave form you got for this one? the initial points for the 2 solutions are at +/-lambda/4 around TimeLag so it is possible that if a solution is far off these initial values it is not found

@lcarver
Copy link
Contributor

lcarver commented Jul 27, 2022

image

it finds a solution, but it doesn't find the others so doesn't throw a warning

@lcarver
Copy link
Contributor

lcarver commented Jul 27, 2022

It's ok now. If I keep the harmonic TimeLag=0 then it triggers the warning. For TimeLag=0.1 (what you see in the figure) then it doesn't. So the warning can be triggered. but I guess the question now is why it doesn't find the second solution on the left of the main one?

@swhite2401
Copy link
Contributor Author

It's ok now. If I keep the harmonic TimeLag=0 then it triggers the warning. For TimeLag=0.1 (what you see in the figure) then it doesn't. So the warning can be triggered. but I guess the question now is why it doesn't find the second solution on the left of the main one?

Right, can you send me your lattice?

@swhite2401
Copy link
Contributor Author

It's ok now. If I keep the harmonic TimeLag=0 then it triggers the warning. For TimeLag=0.1 (what you see in the figure) then it doesn't. So the warning can be triggered. but I guess the question now is why it doesn't find the second solution on the left of the main one?

Right, can you send me your lattice?

There was a logic issues settings the boundaries and initial guesses, this is fixed. In addition the range is now divided in 8 initial guesses over the full wake length on the main RF, instead of just 2 before. This should mitigate the issue with solutions not found

@lfarv
Copy link
Contributor

lfarv commented Jul 28, 2022

Please put the modifications of lattice_object.py and elements.py in a different pull request. They don't affect your initial PR (unless there is a diffusion element in the lattice). It avoids mixing unrelated things, makes validation easier and makes history easier to read (think of listing the changes in the release notes of the next version)… Thanks!

@swhite2401
Copy link
Contributor Author

As request I have created #453 to propose the QuantDiffElement and the modified radiation_on/off()

@lfarv
Copy link
Contributor

lfarv commented Jul 29, 2022

For the computation, I trust @lcarver and you. But:

  • Why changing the default method for TRACKING ? It's decoupled from the topic of this PR: get a better solution for the equation V(cτ)= U0, whatever U0. INTEGRAL is robust, fast, works with or without radiation. Even if it may be less accurate, it's probably good enough in most cases as an initial guess for find_orbit. Why not keeping TRACKING for the cases where INTEGRAL is not accurate enough?

    UPDATE: find_orbit forces the default to TRACKING. So my remark on orbit search is irrelevant. But remains: why changing something without justification?

  • Why changing math.pi to numpy.pi ? I have no opinion on which is best, apart from matching its type (float of numpy scalar array) to the type of the rest of the expression… Here it's mixed.

@swhite2401
Copy link
Contributor Author

  • UPDATE: find_orbit forces the default to TRACKING. So my remark on orbit search is irrelevant. But remains: why changing something without justification?

Exactly for that reason: we have to be consistent in the default we use and stick to the decision made in other places.
TRACKING is more precise and will give the correct result in any condition. I questioned the choice of TRACKING for find_orbit once because I thought integral was more robust but you replied exactly this to me.

@swhite2401
Copy link
Contributor Author

  • Why changing math.pi to numpy.pi ? I have no opinion on which is best, apart from matching its type (float of numpy scalar array) to the type of the rest of the expression… Here it's mixed.

I have no opinion on that. I always use numpy rather than math, but this is just an habit. Isn't the expression mixed anyway because of numpy.arcsin(). Again we have to be consistent an use the same everywhere...shall we add the preferred one to constants.py?

@lfarv
Copy link
Contributor

lfarv commented Jul 29, 2022

I have no opinion on that. I always use numpy rather than math, but this is just an habit. Isn't the expression mixed anyway because of numpy.arcsin(). Again we have to be consistent an use the same everywhere...shall we add the preferred one to constants.py?

So no reason to change anything, let's keep the expression type decide, and in this particular case it's mixed. I was just curious about the reason for the change !

So it's ok for me.

Copy link
Contributor

@lfarv lfarv left a comment

Choose a reason for hiding this comment

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

ok

@swhite2401
Copy link
Contributor Author

Ok I merge then

@swhite2401 swhite2401 merged commit 551ed7e into master Jul 29, 2022
@swhite2401 swhite2401 deleted the improved_timelag_solver branch July 29, 2022 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Python For python AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants