-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quick little first test to check for grad_fn in results
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import torch | ||
|
||
import cheetah | ||
|
||
|
||
def test_simple_quadrupole(): | ||
""" | ||
Simple test on a [D, Q, D] lattice with the qudrupole's k1 requiring grad, checking | ||
if PyTorch tracked a grad_fn into the outgoing beam. | ||
""" | ||
segment = cheetah.Segment( | ||
[ | ||
cheetah.Drift(torch.tensor(1.0)), | ||
cheetah.Quadrupole(torch.tensor(0.2), k1=torch.tensor(1.0), name="my_quad"), | ||
cheetah.Drift(1.0), | ||
] | ||
) | ||
incoming_beam = cheetah.ParticleBeam.from_astra( | ||
"benchmark/astra/ACHIP_EA1_2021.1351.001" | ||
) | ||
|
||
segment.my_quad.k1.requires_grad = True | ||
|
||
outgoing_beam = segment.track(incoming_beam) | ||
|
||
assert hasattr(outgoing_beam, "grad_fn") |