desy-ml / cheetah

Fast and differentiable particle accelerator optics simulation for reinforcement learning and optimisation applications.
https://cheetah-accelerator.readthedocs.io
GNU General Public License v3.0
35 stars 14 forks source link

Plotting routines fail for segments that contain tensors with `require_grad=True` #287

Closed Hespe closed 1 week ago

Hespe commented 1 month ago

The plotting routines of Cheetah currently fail if the Segment they are called on contain tensors with require_grad=True. This is because Matplotlib internally calls tensor.numpy(), which fails for tensors that include gradients.

RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.