Skip to content

Commit e7a4d37

Browse files
authored
Loglevels reduction in cpymadtools (#75)
1 parent 465b0d2 commit e7a4d37

16 files changed

+84
-70
lines changed

docker/environment.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ dependencies:
221221
- zlib=1.2.11
222222
- zstd=1.5.2
223223
- pip:
224-
- cpymad==1.9.2
224+
- cpymad==1.9.3
225225
- importlib-resources==5.4.0
226226
- minrpc==0.1.0
227-
- pyhdtoolkit==0.16.0
227+
- pyhdtoolkit==0.16.1
228228
- pynaff==1.1.4
229229
- rich==11.1.0

docs/release.rst

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ Release Notes
33

44
The full list of releases can be found in the Github repository's `releases page <https://github.com/fsoubelet/PyhDToolkit/releases>`.
55

6+
.. _release_0.16.1:
7+
8+
0.16.1
9+
------
10+
11+
Maintenance
12+
~~~~~~~~~~~
13+
14+
* The **info** level logging statements in the `pyhdtoolkit.cpymadtools` modules have been adjusted to **debug** level. Info logging is left to the user.
15+
* The **warning** level logging statements in the `pyhdtoolkit.cpymadtools` modules have been modified to give a bit more information.
16+
17+
See `v0.16.1 release notes on GitHub <https://github.com/fsoubelet/PyhDToolkit/releases/tag/0.16.1>`_ and the `full changes since v0.16.0 <https://github.com/fsoubelet/PyhDToolkit/compare/0.16.0...0.16.1>`_.
18+
19+
620
.. _release_0.16.0:
721

822
0.16.0

pyhdtoolkit/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
__title__ = "pyhdtoolkit"
1414
__description__ = "An all-in-one toolkit package to easy my Python work in my PhD."
1515
__url__ = "https://github.com/fsoubelet/PyhDToolkit"
16-
__version__ = "0.16.0"
16+
__version__ = "0.16.1"
1717
__author__ = "Felix Soubelet"
1818
__author_email__ = "[email protected]"
1919
__license__ = "MIT"

pyhdtoolkit/cpymadtools/correctors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def query_triplet_correctors_powering(madx: Madx) -> Dict[str, float]:
5353
5454
>>> triplet_knobs = query_triplet_correctors_powering(madx)
5555
"""
56-
logger.info("Querying triplets correctors powering")
56+
logger.debug("Querying triplets correctors powering")
5757
result: Dict[str, float] = {}
5858

5959
logger.debug("Querying triplet skew quadrupole correctors (MQSXs) powering")
@@ -99,7 +99,7 @@ def query_arc_correctors_powering(madx: Madx) -> Dict[str, float]:
9999
100100
>>> arc_knobs = query_arc_correctors_powering(madx)
101101
"""
102-
logger.info("Querying triplets correctors powering")
102+
logger.debug("Querying triplets correctors powering")
103103
result: Dict[str, float] = {}
104104

105105
logger.debug("Querying arc tune trim quadrupole correctors (MQTs) powering")

pyhdtoolkit/cpymadtools/coupling.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def get_closest_tune_approach(
112112
qy_target = int(q2) + middle_of_fractional_tunes
113113
logger.debug(f"Targeting tunes Qx = {qx_target} | Qy = {qy_target}")
114114

115-
logger.info("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin")
115+
logger.debug("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin")
116116
match_tunes_and_chromaticities(
117117
madx,
118118
accelerator,
@@ -130,7 +130,7 @@ def get_closest_tune_approach(
130130
cminus = abs(dqmin)
131131
logger.debug(f"Matching got to a Closest Tune Approach of {cminus:.5f}")
132132

133-
logger.info("Restoring saved knobs")
133+
logger.debug("Restoring saved knobs")
134134
with madx.batch():
135135
madx.globals.update(saved_knobs)
136136
madx.command.twiss(chrom=True) # make sure TWISS and SUMM tables are returned to their original state
@@ -151,7 +151,7 @@ def match_no_coupling_through_ripkens(
151151
location (str): the name of the element at which one wants the cross-term Ripkens to be 0.
152152
vary_knobs (Sequence[str]): the variables names to ``VARY`` in the ``MAD-X`` routine.
153153
"""
154-
logger.info(f"Matching Ripken parameters for no coupling at location {location}")
154+
logger.debug(f"Matching Ripken parameters for no coupling at location {location}")
155155
logger.debug("Creating macro to update Ripkens")
156156
madx.input("do_ripken: macro = {twiss, ripken=True;}") # cpymad needs .input for macros
157157

pyhdtoolkit/cpymadtools/errors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def misalign_lhc_ir_quadrupoles(
166166
logger.trace("Clearing error flag")
167167
madx.select(flag="error", clear=True)
168168

169-
logger.info(f"Applying alignment errors to IR quads '{quadrupoles}', with arguments {kwargs}")
169+
logger.debug(f"Applying alignment errors to IR quads '{quadrupoles}', with arguments {kwargs}")
170170
for ip in ips:
171171
logger.debug(f"Applying errors for IR{ip}")
172172
for side in sides:

pyhdtoolkit/cpymadtools/lhc.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def make_lhc_beams(madx: Madx, energy: float = 7000, emittance: float = 3.75e-6,
6363
6464
>>> make_lhc_beams(madx, energy=6800, emittance=2.5e-6)
6565
"""
66-
logger.info("Making default beams for 'lhcb1' and 'lhbc2' sequences")
66+
logger.debug("Making default beams for 'lhcb1' and 'lhbc2' sequences")
6767
madx.globals["NRJ"] = energy
6868
madx.globals["brho"] = energy * 1e9 / madx.globals.clight
6969
geometric_emit = madx.globals["geometric_emit"] = emittance / (energy / 0.938)
@@ -104,7 +104,7 @@ def power_landau_octupoles(madx: Madx, beam: int, mo_current: float, defective_a
104104
logger.exception("The global MAD-X variable 'NRJ' should have been set in the optics files but is not defined.")
105105
raise EnvironmentError("No 'NRJ' variable found in scripts") from madx_error
106106

107-
logger.info(f"Powering Landau Octupoles, beam {beam} @ {madx.globals.nrj} GeV with {mo_current} A.")
107+
logger.debug(f"Powering Landau Octupoles, beam {beam} @ {madx.globals.nrj} GeV with {mo_current} A.")
108108
strength = mo_current / madx.globals.Imax_MO * madx.globals.Kmax_MO / brho
109109
beam = 2 if beam == 4 else beam
110110

@@ -134,7 +134,7 @@ def deactivate_lhc_arc_sextupoles(madx: Madx, beam: int) -> None:
134134
# KSF1 and KSD2 - Strong sextupoles of sectors 81/12/45/56
135135
# KSF2 and KSD1 - Weak sextupoles of sectors 81/12/45/56
136136
# Rest: Weak sextupoles in sectors 78/23/34/67
137-
logger.info(f"Deactivating all arc sextupoles for beam {beam}.")
137+
logger.debug(f"Deactivating all arc sextupoles for beam {beam}.")
138138
beam = 2 if beam == 4 else beam
139139

140140
for arc in _all_lhc_arcs(beam):
@@ -165,8 +165,8 @@ def apply_lhc_colinearity_knob(madx: Madx, colinearity_knob_value: float = 0, ir
165165
166166
>>> apply_lhc_colinearity_knob(madx, colinearity_knob_value=5, ir=1)
167167
"""
168-
logger.info(f"Applying Colinearity knob with a unit setting of {colinearity_knob_value}")
169-
logger.warning("You should re-match tunes & chromaticities after this")
168+
logger.debug(f"Applying Colinearity knob with a unit setting of {colinearity_knob_value}")
169+
logger.warning("You should re-match tunes & chromaticities after this colinearity knob is applied")
170170
knob_variables = (f"KQSX3.R{ir:d}", f"KQSX3.L{ir:d}") # MQSX IP coupling correctors
171171
right_knob, left_knob = knob_variables
172172

@@ -211,8 +211,8 @@ def apply_lhc_rigidity_waist_shift_knob(
211211
>>> apply_lhc_rigidity_waist_shift_knob(madx, rigidty_waist_shift_value=1.5, ir=5)
212212
>>> matching.match_tunes_and_chromaticities(madx, "lhc", "lhcb1", 62.31, 60.32)
213213
"""
214-
logger.info(f"Applying Rigidity Waist Shift knob with a unit setting of {rigidty_waist_shift_value}")
215-
logger.warning("You should re-match tunes & chromaticities after this")
214+
logger.debug(f"Applying Rigidity Waist Shift knob with a unit setting of {rigidty_waist_shift_value}")
215+
logger.warning("You should re-match tunes & chromaticities after this rigid waist shift knob is applied")
216216
right_knob, left_knob = f"kqx.r{ir:d}", f"kqx.l{ir:d}" # IP triplet default knob (no trims)
217217

218218
current_right_knob = madx.globals[right_knob]
@@ -251,8 +251,8 @@ def apply_lhc_coupling_knob(
251251
252252
>>> apply_lhc_coupling_knob(madx, coupling_knob=5e-4, beam=1)
253253
"""
254-
logger.info("Applying coupling knob")
255-
logger.warning("You should re-match tunes & chromaticities after this")
254+
logger.debug("Applying coupling knob")
255+
logger.warning("You should re-match tunes & chromaticities after this coupling knob is applied")
256256
suffix = "_sq" if telescopic_squeeze else ""
257257
knob_name = f"CMRS.b{beam:d}{suffix}"
258258

@@ -317,7 +317,7 @@ def install_ac_dipole_as_kicker(
317317
... )
318318
"""
319319
logger.warning("This AC Dipole is implemented as a kicker and will not affect TWISS functions!")
320-
logger.info("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam")
320+
logger.debug("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam")
321321

322322
if top_turns > 6600:
323323
logger.warning(
@@ -353,7 +353,7 @@ def install_ac_dipole_as_kicker(
353353
f"ramp2={ramp2}, ramp3={ramp3}, ramp4={ramp4};"
354354
)
355355

356-
logger.info(f"Installing AC Dipole kicker with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}")
356+
logger.debug(f"Installing AC Dipole kicker with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}")
357357
madx.command.seqedit(sequence=f"lhcb{beam:d}")
358358
madx.command.flatten()
359359
# The kicker version is meant for a thin lattice and is installed a right at MKQA.6L4.B[12] (at=0)
@@ -362,7 +362,7 @@ def install_ac_dipole_as_kicker(
362362
madx.command.endedit()
363363

364364
logger.warning(
365-
f"Sequence LHCB{beam:d} is now re-used for changes to take effect. Beware that this will reset it, "
365+
f"Sequence LHCB{beam:d} is now re-USEd for changes to take effect. Beware that this will reset it, "
366366
"remove errors etc."
367367
)
368368
madx.use(sequence=f"lhcb{beam:d}")
@@ -396,7 +396,7 @@ def install_ac_dipole_as_matrix(madx: Madx, deltaqx: float, deltaqy: float, beam
396396
>>> install_ac_dipole_as_matrix(madx, deltaqx=-0.01, deltaqy=0.012, beam=1)
397397
"""
398398
logger.warning("This AC Dipole is implemented as a matrix and will not affect particle tracking!")
399-
logger.info("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam.")
399+
logger.debug("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam.")
400400

401401
logger.debug("Retrieving tunes from internal tables")
402402
q1, q2 = madx.table.summ.q1[0], madx.table.summ.q2[0]
@@ -416,7 +416,7 @@ def install_ac_dipole_as_matrix(madx: Madx, deltaqx: float, deltaqy: float, beam
416416
madx.input(f"hacmap: matrix, l=0, rm21=hacmap21;")
417417
madx.input(f"vacmap: matrix, l=0, rm43=vacmap43;")
418418

419-
logger.info(f"Installing AC Dipole matrix with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}")
419+
logger.debug(f"Installing AC Dipole matrix with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}")
420420
madx.command.seqedit(sequence=f"lhcb{beam:d}")
421421
madx.command.flatten()
422422
# The matrix version is meant for a thick lattice and is installed a little after MKQA.6L4.B[12]
@@ -425,7 +425,7 @@ def install_ac_dipole_as_matrix(madx: Madx, deltaqx: float, deltaqy: float, beam
425425
madx.command.endedit()
426426

427427
logger.warning(
428-
f"Sequence LHCB{beam:d} is now re-used for changes to take effect. Beware that this will reset it, "
428+
f"Sequence LHCB{beam:d} is now re-USEd for changes to take effect. Beware that this will reset it, "
429429
"remove errors etc."
430430
)
431431
madx.use(sequence=f"lhcb{beam:d}")
@@ -503,7 +503,7 @@ def reset_lhc_bump_flags(madx: Madx) -> None:
503503
504504
>>> reset_lhc_bump_flags(madx)
505505
"""
506-
logger.info("Resetting all LHC IP bump flags")
506+
logger.debug("Resetting all LHC IP bump flags")
507507
ALL_BUMPS = (
508508
LHC_ANGLE_FLAGS
509509
+ LHC_CROSSING_ANGLE_FLAGS
@@ -533,7 +533,7 @@ def make_sixtrack_output(madx: Madx, energy: int) -> None:
533533
534534
>>> make_sixtrack_output(madx, energy=6800)
535535
"""
536-
logger.info("Preparing outputs for SixTrack")
536+
logger.debug("Preparing outputs for SixTrack")
537537

538538
logger.debug("Powering RF cavities")
539539
madx.globals["VRF400"] = 8 if energy < 5000 else 16 # is 6 at injection for protons iirc?
@@ -571,7 +571,7 @@ def make_lhc_thin(madx: Madx, sequence: str, slicefactor: int = 1, **kwargs) ->
571571
572572
>>> make_lhc_thin(madx, sequence="lhcb1", slicefactor=4)
573573
"""
574-
logger.info(f"Slicing sequence '{sequence}'")
574+
logger.debug(f"Slicing sequence '{sequence}'")
575575
madx.select(flag="makethin", clear=True)
576576
four_slices_patterns = [r"mbx\.", r"mbrb\.", r"mbrc\.", r"mbrs\."]
577577
four_slicefactor_patterns = [
@@ -675,7 +675,7 @@ def match_no_coupling_through_ripkens(
675675
location (str): the name of the element at which one wants the cross-term Ripkens to be 0.
676676
vary_knobs (Sequence[str]): the variables names to ``VARY`` in the ``MAD-X`` routine.
677677
"""
678-
logger.info(f"Matching Ripken parameters for no coupling at location {location}")
678+
logger.debug(f"Matching Ripken parameters for no coupling at location {location}")
679679
logger.debug("Creating macro to update Ripkens")
680680
madx.input("do_ripken: macro = {twiss, ripken=True;}") # cpymad needs .input for macros
681681

pyhdtoolkit/cpymadtools/matching.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def match(*args, **kwargs):
184184
madx.twiss(chrom=True) # prevents errors if the user forgets to TWISS before querying tables
185185

186186
if q1_target is not None and q2_target is not None and dq1_target is not None and dq2_target is not None:
187-
logger.info(
187+
logger.debug(
188188
f"Doing combined matching to Qx={q1_target}, Qy={q2_target}, "
189189
f"dqx={dq1_target}, dqy={dq2_target} for sequence '{sequence}'"
190190
)
@@ -193,13 +193,13 @@ def match(*args, **kwargs):
193193
match(*varied_knobs, q1=q1_target, q2=q2_target, dq1=dq1_target, dq2=dq2_target)
194194

195195
elif q1_target is not None and q2_target is not None:
196-
logger.info(f"Matching tunes to Qx={q1_target}, Qy={q2_target} for sequence '{sequence}'")
196+
logger.debug(f"Matching tunes to Qx={q1_target}, Qy={q2_target} for sequence '{sequence}'")
197197
tune_knobs = varied_knobs or tune_knobs # if accelerator was given we've extracted this already
198198
logger.trace(f"Vary knobs sent are {tune_knobs}")
199199
match(*tune_knobs, q1=q1_target, q2=q2_target) # sent varied_knobs should be tune knobs
200200

201201
elif dq1_target is not None and dq2_target is not None:
202-
logger.info(f"Matching chromaticities to dq1={dq1_target}, dq2={dq2_target} for sequence {sequence}")
202+
logger.debug(f"Matching chromaticities to dq1={dq1_target}, dq2={dq2_target} for sequence {sequence}")
203203
chroma_knobs = varied_knobs or chroma_knobs # if accelerator was given we've extracted this already
204204
logger.trace(f"Vary knobs sent are {chroma_knobs}")
205205
match(*chroma_knobs, dq1=dq1_target, dq2=dq2_target) # sent varied_knobs should be chromaticity knobs
@@ -296,7 +296,7 @@ def get_closest_tune_approach(
296296
qy_target = int(q2) + middle_of_fractional_tunes
297297
logger.debug(f"Targeting tunes Qx = {qx_target} | Qy = {qy_target}")
298298

299-
logger.info("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin")
299+
logger.debug("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin")
300300
match_tunes_and_chromaticities(
301301
madx,
302302
accelerator,
@@ -314,7 +314,7 @@ def get_closest_tune_approach(
314314
cminus = abs(dqmin)
315315
logger.debug(f"Matching got to a Closest Tune Approach of {cminus:.5f}")
316316

317-
logger.info("Restoring saved knobs")
317+
logger.debug("Restoring saved knobs")
318318
with madx.batch():
319319
madx.globals.update(saved_knobs)
320320
madx.command.twiss(chrom=True) # make sure TWISS and SUMM tables are returned to their original state

pyhdtoolkit/cpymadtools/orbit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def correct_lhc_orbit(
175175
176176
>>> correct_lhc_orbit(madx, sequence="lhcb1", plane="y")
177177
"""
178-
logger.info("Starting orbit correction")
178+
logger.debug("Starting orbit correction")
179179
for default_kicker in ("kicker", "hkicker", "vkicker", "virtualcorrector"):
180180
logger.trace(f"Disabling default corrector class '{default_kicker}'")
181181
madx.command.usekick(sequence=sequence, status="off", class_=default_kicker)

pyhdtoolkit/cpymadtools/parameters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ def query_beam_attributes(madx: Madx) -> MADXBeam:
2929
Returns:
3030
A validated `~.models.madx.MADXBeam` object.
3131
"""
32-
logger.info("Retrieving BEAM attributes from the MAD-X process")
32+
logger.debug("Retrieving BEAM attributes from the MAD-X process")
3333
return MADXBeam(**dict(madx.beam))

0 commit comments

Comments
 (0)