-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add a new combined Corrector
element
#207
base: master
Are you sure you want to change the base?
Conversation
Implementing a corrector with kicks in horizontal and vertical planes
Derived from the Corrector class, tests are included
Random asserts gone (8)
… into 203-new-corrector-class
To fix test_lattice_json.py
So ... changing the failing test as in the following works: def test_ea_magnets():
"""
Test that gradients are tracking when the magnet settings in the ARES experimental
area require grad.
"""
ea = cheetah.Segment.from_ocelot(ares.cell, warnings=False).subcell(
"AREASOLA1", "AREABSCR1"
)
incoming_beam = cheetah.ParticleBeam.from_astra(
"tests/resources/ACHIP_EA1_2021.1351.001"
)
ea.AREAMQZM2.k1 = nn.Parameter(ea.AREAMQZM2.k1)
ea.AREAMQZM1.k1 = nn.Parameter(ea.AREAMQZM1.k1)
# ea.AREAMCVM1.angle = nn.Parameter(ea.AREAMCVM1.angle)
ea.AREAMCVM1.horizontal_angle = nn.Parameter(ea.AREAMCVM1.horizontal_angle)
ea.AREAMQZM3.k1 = nn.Parameter(ea.AREAMQZM3.k1)
# ea.AREAMCHM1.angle = nn.Parameter(ea.AREAMCHM1.angle)
ea.AREAMCHM1.horizontal_angle = nn.Parameter(ea.AREAMCHM1.horizontal_angle)
outgoing_beam = ea.track(incoming_beam)
assert outgoing_beam.particles.grad_fn is not None
```
This pretty much confirms the issue. So the question is, do we solve the `Parameter` / `Buffer` assignment issue as a whole now before this can be merged, or do we merge this as a hack?
In terms of a hack: Just ignoring the test would in some potentially unforeseen situations break differentiability. I think a better hack would be just to make three different classes. There is even a case for that not being a hack. (Maybe a corrector transfer map function and three different classes use it (kind of like `base_rmatrix`.) |
tests/test_horizontal_corrector.py
Outdated
def test_vertical_angle_property(): | ||
try: | ||
HorizontalCorrector( | ||
length=torch.tensor([0.3]), | ||
vertical_angle=torch.tensor([0.0]), | ||
) | ||
except TypeError: | ||
pass | ||
|
||
|
||
def test_horizontal_angle_property(): | ||
try: | ||
HorizontalCorrector( | ||
length=torch.tensor([0.3]), | ||
vertical_angle=torch.tensor([0.0]), | ||
) | ||
except TypeError: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ansantam, what is this? 🦦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to matrix generating function instead of inheritance as we talked about.
Description
Implementation of a new class
Corrector
.To build the
Corrector
class I took the oldHorizontalCorrector
class and added an extra entry in the transfer matrix to includeyp
(vertical angle).Corrector
has thehorizontal_angle
andvertical_angle
properties.xp
is in position (1,6) of tmyp
is in position (3,6) of tmI then derived
HorizontalCorrector
andVerticalCorrector
from theCorrector
class.vertical_angle
orhorizontal_angle
as property and kept the other, but this was a breaking change.angle
can be used forHorizontalCorrector
andVerticalCorrector
, but creates additional problems (see tests)What solution is best?
Motivation and Context
The motivation is because I need it to continue with the MAD-X converter, using the AWAKE lattice which contains combined correctors. Probably also useful to other people in the future.
Closes issue New Corrector class #203
Types of changes
Checklist
flake8
(required).pytest
tests pass (required).pytest
on a machine with a CUDA GPU and made sure all tests pass (required).Note: We are using a maximum length of 88 characters per line