Skip to content

Fix chroma tool + global moment compaction factor#222

Merged
JeanLucPons merged 11 commits intomainfrom
fix-chromaticity-tool
Mar 20, 2026
Merged

Fix chroma tool + global moment compaction factor#222
JeanLucPons merged 11 commits intomainfrom
fix-chromaticity-tool

Conversation

@JeanLucPons
Copy link
Copy Markdown
Contributor

This PR fix chroma tool and add unit test for it.
This PR also add moment compaction factor as global accelerator parameters (similarly to energy).

type: pyaml.accelerator
facility: ESRF
machine: sr
energy: 6e9
alphac: 8.623614679299252e-05

@JeanLucPons JeanLucPons changed the title Fix chroma tool + global moment compatciont factor Fix chroma tool + global moment compaction factor Mar 18, 2026
@TeresiaOlsson
Copy link
Copy Markdown
Contributor

It's nice to be able to give the momentum compaction factor in the config if you don't have a lattice model, but I don't entirely understand the _set_mcf. Does it set it on all elements? If so, why? Feels to me like it should be a property of the accelerator rather than the individual elements since it's a global property? Same for the energy, that also feels like a global property to me.

Also, can it optionally automatically be read from the lattice model if you have configured a simulator? If I have a lattice model I would like to get the energy and momentum compaction factor from that instead of putting it in the config.

@JeanLucPons
Copy link
Copy Markdown
Contributor Author

_set_mcf and _set_energy methods are private methods used for propagation.
Then a random element that needs the energy or the mcf just override set_mcf() as there
If you want to set up mcf by code then you can call set_mcf() at the Accelerator level.

@JeanLucPons
Copy link
Copy Markdown
Contributor Author

JeanLucPons commented Mar 19, 2026

@kparasch
I get a strange problem with logging. You have definitely a better experience than me with logging.

When i do Ctrl+C in tune reponse matrix, the logging is incomplete:

def callback(action: Action, data:dict):
    print(f"{action}, data:{data}")
    return True

sr: Accelerator = Accelerator.load("tests/config/EBSTune.yaml",ignore_external=True,use_fast_loader=True)
sr.design.trm.measure(n_step=3,n_avg_meas=3, callback=callback)
Action.MEASURE, data:{'step': 0, 'avg_step': 2, 'magnet': 'QD2E-C04', 'tune': array([0.15999673, 0.33999769]), 'mode': 'Simulator:design', 'source_name': 'DEFAULT_TUNE_RESPONSE_MATRIX'}
Action.APPLY, data:{'step': 0, 'magnet': 'QD2E-C04', 'strength': -0.6174884055295032, 'mode': 'Simulator:design', 'source_name': 'DEFAULT_TUNE_RESPONSE_MATRIX'}
Action.MEASURE, data:{'step': 0, 'avg_step': 0, 'magnet': 'QD2E-C04', 'tune': array([0.16001458, 0.33987169]), 'mode': 'Simulator:design', 'source_name': 'DEFAULT_TUNE_RESPONSE_MATRIX'}
^CAction.RESTORE, data:{'step': 0, 'magnet': 'QD2E-C04', 'dtune': array([0., 0.]), 'mode': 'Simulator:design', 'source_name': 'DEFAULT_TUNE_RESPONSE_MATRIX'}
DEFAULT_TUNE_RESPONSE_MATRIX : measurement aborted

While it works well in chroma response matrix:

sr: Accelerator = Accelerator.load("tests/config/EBSOrbit.yaml",ignore_external=True,use_fast_loader=True)
sr.design.crm.measure(n_step=3,n_avg_meas=3, callback=callback)
Action.APPLY, data:{'step': 0, 'rf': 352372199.7865967, 'mode': 'Simulator:design', 'source_name': 'CHROMATICITY_MONITOR'}
Action.MEASURE, data:{'step': 0, 'avg_step': 0, 'rf': 352372199.7865967, 'tune': array([0.1515107 , 0.33441885]), 'mode': 'Simulator:design', 'source_name': 'CHROMATICITY_MONITOR'}
Action.APPLY, data:{'step': 1, 'rf': 352372184.59298766, 'mode': 'Simulator:design', 'source_name': 'CHROMATICITY_MONITOR'}
^CAction.RESTORE, data:{'step': 1, 'rf': 352372169.3993786, 'mode': 'Simulator:design', 'source_name': 'CHROMATICITY_MONITOR'}
19 Mar 2026, 09:46:04 | WARNING | CHROMATICITY_MONITOR : measurement aborted
Action.RESTORE, data:{'step': 0, 'magnet': 'SF2A-C05-S', 'strength': 16.995995697665187, 'dchroma': array([0., 0.]), 'mode': 'Simulator:design', 'source_name': 'DEFAULT_CHROMATICITY_RESPONSE_MATRIX'}
19 Mar 2026, 09:46:04 | WARNING | DEFAULT_CHROMATICITY_RESPONSE_MATRIX : measurement aborted

Thanks for help !

@JeanLucPons JeanLucPons marked this pull request as draft March 19, 2026 09:15
@JeanLucPons
Copy link
Copy Markdown
Contributor Author

So the logging behavior difference is explained by pySC.
From @kparasch :

It is changed in the __init__.py of pySC:

logging.basicConfig(
    format="{asctime} | {levelname} | {message}",
    datefmt="%d %b %Y, %H:%M:%S",
    level=logging.INFO,
    style='{',
    stream=sys.stdout
)

Unfortunatly logging.basicConfig() affects all loggers :/

@JeanLucPons JeanLucPons marked this pull request as ready for review March 19, 2026 15:41
@JeanLucPons
Copy link
Copy Markdown
Contributor Author

Ready to merge

@JeanLucPons JeanLucPons merged commit e04efa6 into main Mar 20, 2026
3 checks passed
@JeanLucPons JeanLucPons deleted the fix-chromaticity-tool branch March 20, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants