lnls-fac / pyaccel

Python module for beam dynamics tracking and optics calculations
MIT License
7 stars 5 forks source link

Standardize default energy offset in optics module #152

Closed vellosok75 closed 1 month ago

vellosok75 commented 1 month ago

When trying to calculate optics with calc_edwards_teng, I was getting bugs related to the default None-type energy-deviation. As in #149, I standardized energy-offset to 0.0. I also did it for calc_twiss, despite the None-type not being a problem there.

Additionally, I use this PR to highlight an issue I found during some tests. There are inconsistencies between the optics obtained by providing calc_edwards_teng with an energy-offset vs those obtained by providing the function with an initial edteng object. The snipped below should replicate the discrepancies:

import numpy as np
import pyaccel as pa
from pymodels import si

model = si.create_accelerator()
model = si.fitted_models.vertical_dispersion_and_coupling(model)

init_edteng = pa.optics.calc_edwards_teng( model, energy_offset=1e-2)[0][0]
edteng, _ = pa.optics.calc_edwards_teng(energy_offset=1e-2)
edteng_, _ = pa.optics.calc_edwards_teng(model, init_edteng=init_edteng)
np.allclose(edteng.beta1, edteng_.beta1)
np.allclose(edteng.eta1, edteng_.eta1)

The last two commands should return False.