Skip to content

Commit

Permalink
Loglevels reduction in cpymadtools (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoubelet committed Mar 2, 2022
1 parent 465b0d2 commit e7a4d37
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 70 deletions.
4 changes: 2 additions & 2 deletions docker/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ dependencies:
- zlib=1.2.11
- zstd=1.5.2
- pip:
- cpymad==1.9.2
- cpymad==1.9.3
- importlib-resources==5.4.0
- minrpc==0.1.0
- pyhdtoolkit==0.16.0
- pyhdtoolkit==0.16.1
- pynaff==1.1.4
- rich==11.1.0
14 changes: 14 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ Release Notes

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

.. _release_0.16.1:

0.16.1
------

Maintenance
~~~~~~~~~~~

* The **info** level logging statements in the `pyhdtoolkit.cpymadtools` modules have been adjusted to **debug** level. Info logging is left to the user.
* The **warning** level logging statements in the `pyhdtoolkit.cpymadtools` modules have been modified to give a bit more information.

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>`_.


.. _release_0.16.0:

0.16.0
Expand Down
2 changes: 1 addition & 1 deletion pyhdtoolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__title__ = "pyhdtoolkit"
__description__ = "An all-in-one toolkit package to easy my Python work in my PhD."
__url__ = "https://github.com/fsoubelet/PyhDToolkit"
__version__ = "0.16.0"
__version__ = "0.16.1"
__author__ = "Felix Soubelet"
__author_email__ = "felix.soubelet@cern.ch"
__license__ = "MIT"
4 changes: 2 additions & 2 deletions pyhdtoolkit/cpymadtools/correctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def query_triplet_correctors_powering(madx: Madx) -> Dict[str, float]:
>>> triplet_knobs = query_triplet_correctors_powering(madx)
"""
logger.info("Querying triplets correctors powering")
logger.debug("Querying triplets correctors powering")
result: Dict[str, float] = {}

logger.debug("Querying triplet skew quadrupole correctors (MQSXs) powering")
Expand Down Expand Up @@ -99,7 +99,7 @@ def query_arc_correctors_powering(madx: Madx) -> Dict[str, float]:
>>> arc_knobs = query_arc_correctors_powering(madx)
"""
logger.info("Querying triplets correctors powering")
logger.debug("Querying triplets correctors powering")
result: Dict[str, float] = {}

logger.debug("Querying arc tune trim quadrupole correctors (MQTs) powering")
Expand Down
6 changes: 3 additions & 3 deletions pyhdtoolkit/cpymadtools/coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_closest_tune_approach(
qy_target = int(q2) + middle_of_fractional_tunes
logger.debug(f"Targeting tunes Qx = {qx_target} | Qy = {qy_target}")

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

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

Expand Down
2 changes: 1 addition & 1 deletion pyhdtoolkit/cpymadtools/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def misalign_lhc_ir_quadrupoles(
logger.trace("Clearing error flag")
madx.select(flag="error", clear=True)

logger.info(f"Applying alignment errors to IR quads '{quadrupoles}', with arguments {kwargs}")
logger.debug(f"Applying alignment errors to IR quads '{quadrupoles}', with arguments {kwargs}")
for ip in ips:
logger.debug(f"Applying errors for IR{ip}")
for side in sides:
Expand Down
38 changes: 19 additions & 19 deletions pyhdtoolkit/cpymadtools/lhc.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def make_lhc_beams(madx: Madx, energy: float = 7000, emittance: float = 3.75e-6,
>>> make_lhc_beams(madx, energy=6800, emittance=2.5e-6)
"""
logger.info("Making default beams for 'lhcb1' and 'lhbc2' sequences")
logger.debug("Making default beams for 'lhcb1' and 'lhbc2' sequences")
madx.globals["NRJ"] = energy
madx.globals["brho"] = energy * 1e9 / madx.globals.clight
geometric_emit = madx.globals["geometric_emit"] = emittance / (energy / 0.938)
Expand Down Expand Up @@ -104,7 +104,7 @@ def power_landau_octupoles(madx: Madx, beam: int, mo_current: float, defective_a
logger.exception("The global MAD-X variable 'NRJ' should have been set in the optics files but is not defined.")
raise EnvironmentError("No 'NRJ' variable found in scripts") from madx_error

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

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

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

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

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

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

if top_turns > 6600:
logger.warning(
Expand Down Expand Up @@ -353,7 +353,7 @@ def install_ac_dipole_as_kicker(
f"ramp2={ramp2}, ramp3={ramp3}, ramp4={ramp4};"
)

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

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

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

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

logger.warning(
f"Sequence LHCB{beam:d} is now re-used for changes to take effect. Beware that this will reset it, "
f"Sequence LHCB{beam:d} is now re-USEd for changes to take effect. Beware that this will reset it, "
"remove errors etc."
)
madx.use(sequence=f"lhcb{beam:d}")
Expand Down Expand Up @@ -503,7 +503,7 @@ def reset_lhc_bump_flags(madx: Madx) -> None:
>>> reset_lhc_bump_flags(madx)
"""
logger.info("Resetting all LHC IP bump flags")
logger.debug("Resetting all LHC IP bump flags")
ALL_BUMPS = (
LHC_ANGLE_FLAGS
+ LHC_CROSSING_ANGLE_FLAGS
Expand Down Expand Up @@ -533,7 +533,7 @@ def make_sixtrack_output(madx: Madx, energy: int) -> None:
>>> make_sixtrack_output(madx, energy=6800)
"""
logger.info("Preparing outputs for SixTrack")
logger.debug("Preparing outputs for SixTrack")

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

Expand Down
10 changes: 5 additions & 5 deletions pyhdtoolkit/cpymadtools/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def match(*args, **kwargs):
madx.twiss(chrom=True) # prevents errors if the user forgets to TWISS before querying tables

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

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

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

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

logger.info("Restoring saved knobs")
logger.debug("Restoring saved knobs")
with madx.batch():
madx.globals.update(saved_knobs)
madx.command.twiss(chrom=True) # make sure TWISS and SUMM tables are returned to their original state
Expand Down
2 changes: 1 addition & 1 deletion pyhdtoolkit/cpymadtools/orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def correct_lhc_orbit(
>>> correct_lhc_orbit(madx, sequence="lhcb1", plane="y")
"""
logger.info("Starting orbit correction")
logger.debug("Starting orbit correction")
for default_kicker in ("kicker", "hkicker", "vkicker", "virtualcorrector"):
logger.trace(f"Disabling default corrector class '{default_kicker}'")
madx.command.usekick(sequence=sequence, status="off", class_=default_kicker)
Expand Down
2 changes: 1 addition & 1 deletion pyhdtoolkit/cpymadtools/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ def query_beam_attributes(madx: Madx) -> MADXBeam:
Returns:
A validated `~.models.madx.MADXBeam` object.
"""
logger.info("Retrieving BEAM attributes from the MAD-X process")
logger.debug("Retrieving BEAM attributes from the MAD-X process")
return MADXBeam(**dict(madx.beam))
Loading

0 comments on commit e7a4d37

Please sign in to comment.