Skip to content

42 string representation of pyaml objects#52

Merged
gubaidulinvadim merged 9 commits intomainfrom
42-string-representation-of-pyaml-objects
Nov 5, 2025
Merged

42 string representation of pyaml objects#52
gubaidulinvadim merged 9 commits intomainfrom
42-string-representation-of-pyaml-objects

Conversation

@JeanLucPons
Copy link
Contributor

@JeanLucPons JeanLucPons commented Nov 5, 2025

This PR add string representation of various items.
I didn't add some test as it is just print.

from pyaml.pyaml import pyaml,PyAML
from pyaml.configuration.factory import Factory
from pyaml.instrument import Instrument
from pyaml.arrays.bpm_array import BPMArray

ml:PyAML = pyaml("tests/config/EBSOrbit.yaml")
sr:Instrument = ml.get('sr')

print(sr.design)
print(sr.live)

m = sr.design.get_magnet("SH1A-C04-H")
print(m)
m = sr.live.get_magnet("SH1A-C05-H")
print(m)

print(sr.design.get_rf_plant("RF"))
print(sr.live.get_bpm("BPM_C03-08"))
print(sr.live.get_betatron_tune_monitor("BETATRON_TUNE"))
print(sr.live.get_betatron_tune_monitor("BETATRON_TUNE").tune.get())
print(sr.design.get_betatron_tune_monitor("BETATRON_TUNE").tune.get())

bpms = BPMArray("TestBPM",[sr.live.get_bpm("BPM_C03-08"),sr.live.get_bpm("BPM_C04-08")])
print(bpms)
 
Factory.clear()

outputs:

Simulator(name='design', lattice='sr/lattices/ebs.mat', mat_key=None, linker=None)
TangoControlSystem(name='live', tango_host='ebs-simu-3:10000', debug_level=None, lazy_devices=True, scalar_aggregator='tango.pyaml.multi_attribute', vector_aggregator=None, timeout_ms=3000)
HCorrector(peer='Simulator:design', name='SH1A-C04-H', model='SH1A-C04', magnet_model=LinearCFMagnetModel(multipoles=['B0', 'A0', 'A1', 'B2'], curves=[CSVCurve(file='sr/magnet_models/SHI_h_strength.csv'), CSVCurve(file='sr/magnet_models/SHI_v_strength.csv'), CSVCurve(file='sr/magnet_models/SHI_sq_strength.csv'), CSVCurve(file='sr/magnet_models/SHI_sext_strength.csv')], calibration_factors=None, calibration_offsets=None, pseudo_factors=[1.0, -1.0, -1.0, -1.0], pseudo_offsets=None, powerconverters=[Attribute(attribute='srmag/ps-corr-sh1/c04-a-ch1/current', unit='A'), Attribute(attribute='srmag/ps-corr-sh1/c04-a-ch2/current', unit='A'), Attribute(attribute='srmag/ps-corr-sh1/c04-a-ch3/current', unit='A'), Attribute(attribute='srmag/ps-corr-sh1/c04-a-ch5/current', unit='A'), Attribute(attribute='srmag/ps-corr-sh1/c04-a-ch6/current', unit='A')], matrix=CSVMatrix(file='sr/magnet_models/SHI_matrix.csv'), units=['rad', 'rad', 'm-1', 'm-2']))
HCorrector(peer='TangoControlSystem:live', name='SH1A-C05-H', model='SH1A-C05', magnet_model=LinearCFMagnetModel(multipoles=['B0', 'A0', 'A1'], curves=[CSVCurve(file='sr/magnet_models/SH1_SH3_h_strength.csv'), CSVCurve(file='sr/magnet_models/SH1_SH3_v_strength.csv'), CSVCurve(file='sr/magnet_models/SH1_SH3_sq_strength.csv')], calibration_factors=None, calibration_offsets=None, pseudo_factors=[1.0, -1.0, -1.0], pseudo_offsets=None, powerconverters=[Attribute(attribute='srmag/ps-corr-sh1/c05-a-ch1/current', unit='A'), Attribute(attribute='srmag/ps-corr-sh1/c05-a-ch2/current', unit='A'), Attribute(attribute='srmag/ps-corr-sh1/c05-a-ch3/current', unit='A')], matrix=CSVMatrix(file='sr/magnet_models/SH_matrix.csv'), units=['rad', 'rad', 'm-1']))
RFPlant(peer='Simulator:design', name='RF', masterclock=Attribute(attribute='sy/ms/1/Frequency', unit='Hz'), transmitters=[RFTransmitter(peer='None', name='RFTRA', voltage=Attribute(attribute='sys/ringsimulator/ebs/RfVoltage', unit='V'), phase=None, cavities=['CAV_C05_01', 'CAV_C05_02', 'CAV_C05_03', 'CAV_C05_04', 'CAV_C05_05', 'CAV_C07_01', 'CAV_C07_02', 'CAV_C07_03', 'CAV_C07_04', 'CAV_C07_05', 'CAV_C25_01', 'CAV_C25_02', 'CAV_C25_03'], harmonic=1.0, distribution=1.0)])
BPM(peer='TangoControlSystem:live', name='BPM_C03-08', model=BPMSimpleModel(x_pos=AttributeReadOnly(attribute='srdiag/bpm/c03-08/SA_HPosition', unit='m'), y_pos=AttributeReadOnly(attribute='srdiag/bpm/c03-08/SA_VPosition', unit='m')))
BetatronTuneMonitor(peer='TangoControlSystem:live', name='BETATRON_TUNE', tune_h=AttributeReadOnly(attribute='sys/ringsimulator/ebs/Tune_h', unit=''), tune_v=AttributeReadOnly(attribute='sys/ringsimulator/ebs/Tune_v', unit=''))
[0.15759235 0.34006444]
[0.15999673 0.33999769]
[BPM(peer='TangoControlSystem:live', name='BPM_C03-08', model=BPMSimpleModel(x_pos=AttributeReadOnly(attribute='srdiag/bpm/c03-08/SA_HPosition', unit='m'), y_pos=AttributeReadOnly(attribute='srdiag/bpm/c03-08/SA_VPosition', unit='m'))), BPM(peer='TangoControlSystem:live', name='BPM_C04-08', model=BPMSimpleModel(x_pos=AttributeReadOnly(attribute='srdiag/bpm/c04-08/SA_HPosition', unit='m'), y_pos=AttributeReadOnly(attribute='srdiag/bpm/c04-08/SA_VPosition', unit='m')))]

@JeanLucPons JeanLucPons linked an issue Nov 5, 2025 that may be closed by this pull request
Copy link
Contributor

@gubaidulinvadim gubaidulinvadim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! It's a bit of a shame that we need essentially the same repr in all elements. I also think we should add str that will do mostly the same. Sometimes in pyAT, there's only str and no repr or only repr and no str and it is a bit annoying.

gubaidulinvadim

This comment was marked as duplicate.

@JeanLucPons
Copy link
Contributor Author

Great! It's a bit of a shame that we need essentially the same repr in all elements. I also think we should add str that will do mostly the same. Sometimes in pyAT, there's only str and no repr or only repr and no str and it is a bit annoying.

I will try to factorize all the repr() that are identical. I will try to put it in Element and use getattr() to get the model.
Concerning str() I have an issue with it.
The problem is that when you print with both str() and repr() defined it uses str() but when printing elements of a list, they are printed using repr() which create a discrepancy.

@gubaidulinvadim
Copy link
Contributor

It is fine with only repr for me.

@gubaidulinvadim gubaidulinvadim merged commit cc9a30d into main Nov 5, 2025
2 checks passed
@gubaidulinvadim gubaidulinvadim deleted the 42-string-representation-of-pyaml-objects branch December 17, 2025 08:54
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.

String representation of pyAML objects

2 participants