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

Equilibrium emittance in presence of SR and IBS #157

Draft
wants to merge 113 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
9d60d14
Add function to compute the equilibrium emittance in presence of SR a…
Jan 3, 2025
3d49542
Fix small bug with 'excitation' constraint.
Jan 3, 2025
5aed27d
Add tests.
Jan 3, 2025
e76d4a2
Additional fixes and simplifications.
Jan 9, 2025
60584cc
Proper initialization of the emittances when forcing an emittance cou…
Jan 10, 2025
a104d83
Remove 'natural_emittances' from 'ibs_rates' to avoid potential confu…
Jan 13, 2025
2e706f0
Remove last 'natural_emittances' traces
Jan 13, 2025
9a5d910
imports shuffle, xo class for derivatives to simplify passing data ar…
fsoubelet Jan 13, 2025
98eed04
rename function to explicit name and make private
fsoubelet Jan 13, 2025
e6468ce
return as classes and beware of order in call line
fsoubelet Jan 13, 2025
717f6ac
unpack as tuple, specify comment
fsoubelet Jan 13, 2025
896060d
rename to emittance_derivatives
fsoubelet Jan 13, 2025
87caa65
commented out code to return a Table for the user's enjoyment
fsoubelet Jan 13, 2025
e1fd86a
do not export private function
fsoubelet Jan 13, 2025
4b3deaf
rename params that are not used in private function anymore - emittan…
fsoubelet Jan 13, 2025
25b2c64
explicitely name attributions
fsoubelet Jan 13, 2025
6b4357d
docstring rework and TODOs
fsoubelet Jan 13, 2025
59c9a00
input_sigma_zeta and input_sigma_delta are not in this function, remo…
fsoubelet Jan 13, 2025
53d3511
replace call of intermediate badly named natural_emittance_[xyz] to d…
fsoubelet Jan 13, 2025
692b664
also remove attribution to vars, could add later a check for presence…
fsoubelet Jan 13, 2025
57270e4
remove damping rates from parameters and take it directly from the Tw…
fsoubelet Jan 13, 2025
2e46884
and rework the return statement in docstring
fsoubelet Jan 13, 2025
8c20bfc
commented out potential check for presence of expected attributes in …
fsoubelet Jan 13, 2025
7363448
asserts and checks as high as possible
fsoubelet Jan 13, 2025
25f5b99
comments to walk through the function, pretty clean already
fsoubelet Jan 13, 2025
eb8c687
one last todo
fsoubelet Jan 13, 2025
d858ab0
Merge pull request #1 from SebastienJoly/cosmetics
SebastienJoly Jan 14, 2025
da11a19
bunch_intensity -> total_beam_intensity to mimic the rest of the APIs
fsoubelet Jan 14, 2025
02124e5
pass kwargs to IBS growth rates method, document in docstring
fsoubelet Jan 14, 2025
4d66bb8
remove bunched=True as it is default, and with kwargs passing the use…
fsoubelet Jan 14, 2025
ff81624
no default for formalism, place it as second arg to mimic API pf IBS …
fsoubelet Jan 14, 2025
d94f1a9
add formalism to main function as the user NEEDS to be able to choose…
fsoubelet Jan 14, 2025
f4fa9db
some walkthrough
fsoubelet Jan 14, 2025
447a104
reworking of the docstring, part1
fsoubelet Jan 14, 2025
3e44bf5
reworking of the docstring, part2
fsoubelet Jan 14, 2025
6f89e98
natural emittances is not a param anymore, remove from docstring
fsoubelet Jan 14, 2025
7a48a4c
clarify rtol
fsoubelet Jan 14, 2025
369f660
clear up call to _ibs_rates_and_emittance_derivatives which was using…
fsoubelet Jan 14, 2025
d5b3650
propagate kwargs to inner function
fsoubelet Jan 14, 2025
f514a23
rework the whole emittance constraint thing in docstring, should be c…
fsoubelet Jan 14, 2025
7dcbfe6
commented out code for Table return, and global quantities included
fsoubelet Jan 14, 2025
d73c041
commented out docstring for when we return a table
fsoubelet Jan 14, 2025
6effcb5
use new parameter names in warning
fsoubelet Jan 14, 2025
69c577a
some harmless renaming
fsoubelet Jan 14, 2025
e8f6948
some todo
fsoubelet Jan 14, 2025
b876bb1
put back this piece of docstring
fsoubelet Jan 14, 2025
cbde1b3
fix my mess of overriding names
fsoubelet Jan 14, 2025
7234e33
small correction to emittance_coupling_factor
fsoubelet Jan 14, 2025
6ae0a8f
typos
fsoubelet Jan 14, 2025
42a1b94
verbose flag and xobjects print
fsoubelet Jan 15, 2025
2619c33
todo for emittance constraint checks
fsoubelet Jan 15, 2025
b7d9270
review changes for emittance constraint
fsoubelet Jan 15, 2025
34f953c
only transverse constraints enforced in loop
fsoubelet Jan 15, 2025
77f4008
correct info on default value
fsoubelet Jan 15, 2025
51749da
typo
fsoubelet Jan 15, 2025
39f9504
add todo for api changes
fsoubelet Jan 15, 2025
5d77c42
should be elif
fsoubelet Jan 15, 2025
079e5f7
Merge pull request #2 from SebastienJoly/api_changes
SebastienJoly Jan 15, 2025
db29a81
file rename
fsoubelet Jan 15, 2025
3754409
Merge pull request #3 from SebastienJoly/rename
fsoubelet Jan 15, 2025
21b85a0
return a Table, add return docstring and build
fsoubelet Jan 15, 2025
d43cf4b
do not change names from the TwissTable, be explicit in those we retu…
fsoubelet Jan 15, 2025
f508b00
proper numpy arrays for columns, fix varname not updated
fsoubelet Jan 15, 2025
e89f859
function rename, and fix in docstring
fsoubelet Jan 15, 2025
8b43266
update main docstring chunk, fix return type
fsoubelet Jan 15, 2025
c97746d
imports order
fsoubelet Jan 15, 2025
71bfb16
also here
fsoubelet Jan 15, 2025
c97cdde
private function explicitely requires individual (geometric) emittanc…
fsoubelet Jan 15, 2025
cb0e623
public function checks for correct radiation state of TwissTable firs…
fsoubelet Jan 15, 2025
9dbc735
check for valid emittance_constraint and if it is, warn if coupling f…
fsoubelet Jan 15, 2025
8d9cc79
move these up
fsoubelet Jan 15, 2025
cac2b79
this todo has been done
fsoubelet Jan 15, 2025
7d8ebfc
commented out check for when we require emittances
fsoubelet Jan 15, 2025
95a8145
no umpacking, let's be verbose
fsoubelet Jan 15, 2025
c661d70
type hint
fsoubelet Jan 15, 2025
41da9b9
type hints and tweaks
fsoubelet Jan 15, 2025
361f6e3
avoid attribute access in loop for print
fsoubelet Jan 15, 2025
8385252
use logging.warning instead of warning module
fsoubelet Jan 15, 2025
86a2079
TYPE CHECKING guard
fsoubelet Jan 15, 2025
a98eb87
constraint first as it makes the conditionals clearer
fsoubelet Jan 15, 2025
9dc4390
also add sigma_zeta and sigma_delta into the result table
fsoubelet Jan 16, 2025
e41b2e4
also add these to docstring
fsoubelet Jan 16, 2025
54124e0
typo fix and note admonition about required radiation config
fsoubelet Jan 16, 2025
604f7c4
make it very clear we recompute the emittance
fsoubelet Jan 16, 2025
40a585e
consistency in units
fsoubelet Jan 16, 2025
9ad6de7
also speficy in docstring that overwriting args force eps_zeta recompute
fsoubelet Jan 16, 2025
eb6ef54
Merge pull request #4 from SebastienJoly/apis
SebastienJoly Jan 17, 2025
aa3ba4d
create checks for important params, shuffle some comments around
fsoubelet Jan 17, 2025
8f87d39
start taking from normalized emittances if they are provided, compute…
fsoubelet Jan 17, 2025
c685455
shuffle around a bit
fsoubelet Jan 17, 2025
646ac2b
if no initial emittance, take the SR eq value, log and set a flag
fsoubelet Jan 17, 2025
a84c63f
use starting_gemitt_[x,y,zeta] and different logic for renormalization
fsoubelet Jan 17, 2025
90bb403
and use these new variables, will need to run tests here
fsoubelet Jan 17, 2025
233c649
todo for discussion and review with Seb
fsoubelet Jan 17, 2025
f64a8c7
docstring for the starting emittance parameters
fsoubelet Jan 17, 2025
7bc2f65
remove initial_emittances from params and docstring
fsoubelet Jan 17, 2025
df3744e
start warning admonition with TODO
fsoubelet Jan 17, 2025
a5b4512
no more trace of input_emittances
fsoubelet Jan 17, 2025
97ed5c5
some formatting
fsoubelet Jan 17, 2025
cfe428d
simpler message
fsoubelet Jan 17, 2025
4c5c10c
also check for provided values, should be renormalized if given as tw…
fsoubelet Jan 17, 2025
248ba6e
docstring warning about providing values and constraint
fsoubelet Jan 17, 2025
8cbbddc
one more todo, suggestion for behaviour
fsoubelet Jan 17, 2025
4dd19e9
tstep parameter commented out everywhere, for later feature if we wan…
fsoubelet Jan 21, 2025
79fd22d
todo for later on sigma_zeta/delta
fsoubelet Jan 21, 2025
f19f08e
start name with eq_ for stored results
fsoubelet Jan 21, 2025
0b74c9c
also in the docstring
fsoubelet Jan 21, 2025
e666d05
remove unused imports
fsoubelet Jan 21, 2025
e8f7237
ref for derivatives computation
fsoubelet Jan 21, 2025
62dca8b
log here that we would renormalize
fsoubelet Jan 21, 2025
1365649
use starting_gemitt here as discussed
fsoubelet Jan 21, 2025
c778699
Merge pull request #5 from SebastienJoly/user_api_force
fsoubelet Jan 22, 2025
12bc224
Merge branch 'xsuite:main' into feature/equilibrium_emittance
fsoubelet Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions tests/test_ibs_equilibrium_emittances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import pytest
import xfields as xf
import xobjects as xo
import xtrack as xt
from ibs_conftest import XTRACK_TEST_DATA
from numpy.testing import assert_allclose

bunch_intensity = 6.2e9 # 1C bunch intensity

bessy3_dir = XTRACK_TEST_DATA / "bessy3"
line = xt.Line.from_json(str(bessy3_dir / "line.json"))
line.build_tracker(_context=xo.ContextCpu())
line.matrix_stability_tol = 1e-2
line.configure_radiation(model='mean')
line.compensate_radiation_energy_loss()

twiss = line.twiss(eneloss_and_damping=True)

@pytest.mark.parametrize('emittance_constraint', ['coupling', 'excitation'])
def test_ibs_emittance_constraints(emittance_constraint):

#######################################
# Equilibrium emittances calculations #
#######################################

emittance_coupling_factor = 0.02

time, emittances_x_list, emittances_y_list, emittances_z_list, T_x, T_y, T_z = xf.ibs.compute_equilibrium_emittances_from_sr_and_ibs(
twiss, bunch_intensity,
emittance_coupling_factor=emittance_coupling_factor,
emittance_constraint=emittance_constraint,
)

if emittance_constraint == 'coupling':
# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 + emittance_coupling_factor) / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=5e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
# Check emittance coupling constraint
assert_allclose(
emittances_y_list[-1] / emittances_x_list[-1],
emittance_coupling_factor,
rtol=2e-2
)

else:
# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=5e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
# Check emittance coupling constraint
assert_allclose(
emittances_y_list[-1] / emittances_x_list[-1],
emittance_coupling_factor,
)

@pytest.mark.parametrize('emittance_coupling_factor', [0.02, 0.1, 0.2])
def test_ibs_emittance_coupling_factor(emittance_coupling_factor):
"""
As the emittance coupling factor increases, the equilibrium emittance
cannot be compared anymore to the solution of the differential equation
describing the emittance evolution in presence of IBS and SR if a
constraint on the emittance is enforced.
"""
#######################################
# Equilibrium emittances calculations #
#######################################

time, emittances_x_list, emittances_y_list, emittances_z_list, T_x, T_y, T_z = xf.ibs.compute_equilibrium_emittances_from_sr_and_ibs(
twiss, bunch_intensity,
emittance_coupling_factor=emittance_coupling_factor,
)

# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 + emittance_coupling_factor) / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=1e-1
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
# Check emittance coupling constraint
assert_allclose(
emittances_y_list[-1] / emittances_x_list[-1],
emittance_coupling_factor,
)

@pytest.mark.parametrize('emittance_coupling_factor', [0.02, 0.1, 1.])
def test_ibs_emittance_no_constraint(emittance_coupling_factor):
"""
Without any emittance constraint, the equilibrium emittance becomes
almost identical to the solution of the differential equation describing
the emittance evolution in presence of IBS and SR.
"""
initial_emittances=(
twiss.eq_gemitt_x, emittance_coupling_factor*twiss.eq_gemitt_x,
twiss.eq_gemitt_zeta
)
emittance_constraint=""
natural_emittances=(
twiss.eq_gemitt_x, emittance_coupling_factor*twiss.eq_gemitt_x,
twiss.eq_gemitt_zeta
)

#######################################
# Equilibrium emittances calculations #
#######################################

time, emittances_x_list, emittances_y_list, emittances_z_list, T_x, T_y, T_z = xf.ibs.compute_equilibrium_emittances_from_sr_and_ibs(
twiss, bunch_intensity,
initial_emittances=initial_emittances,
emittance_coupling_factor=emittance_coupling_factor,
emittance_constraint=emittance_constraint,
natural_emittances=natural_emittances,
)

# Check equilibrium emittance
assert_allclose(
emittances_x_list[-1],
twiss.eq_gemitt_x / (1 - T_x[-1] / 2 / twiss.damping_constants_s[0]),
rtol=2e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_y_list[-1],
emittance_coupling_factor*twiss.eq_gemitt_x / (1 - T_y[-1] / 2 / twiss.damping_constants_s[1]),
rtol=2e-2
)
# Check equilibrium emittance
assert_allclose(
emittances_z_list[-1],
twiss.eq_gemitt_zeta / (1 - T_z[-1] / 2 / twiss.damping_constants_s[2]),
rtol=2e-2
)
2 changes: 2 additions & 0 deletions xfields/ibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

from ._analytical import BjorkenMtingwaIBS, IBSGrowthRates, NagaitsevIBS
from ._api import configure_intrabeam_scattering, get_intrabeam_scattering_growth_rates
from ._equilibrium import compute_equilibrium_emittances_from_sr_and_ibs
from ._kicks import IBSAnalyticalKick, IBSKineticKick

__all__ = [
"BjorkenMtingwaIBS",
"compute_equilibrium_emittances_from_sr_and_ibs",
"configure_intrabeam_scattering",
"get_intrabeam_scattering_growth_rates",
"IBSGrowthRates",
Expand Down
Loading