String representation - #351
Conversation
|
Thanks ! Yes for very long representation we used pydantic feature attached_to(self) -> str:
"""
Returns a string of which peer the element is attached to.
"""
return "None" if self._peer is None else f"{self._peer.__class__.__name__}:{self._peer.name()}"Concerning devices x_pos,..., I think we should remove the |
|
@JeanLucPons @GamelinAl including properties like x_pos "publically" would also solve #44 and give control system access easily. For example (preudocode that may contain mistakes, |
|
In case of `public' x_pos, y_pos, tilt_name, x_offset, y_offset we also can remove the get_X_device functions, right? |
|
I also remarked issue with from pyaml.accelerator import Accelerator
sr = Accelerator.load("tests/config/EBSOrbit.yaml")
print(sr.design.magnet.get("QF6B-C04"))I works better with IdentityCFMagnetModel but powerconverters (or physics) are not printed. from pyaml.accelerator import Accelerator
sr = Accelerator.load("tests/config/EBSOrbit.yaml")
print(sr.design.magnet.get("SJ2E-C04-H")) |
|
I think we should also aim to improve the string repr for our array-like elements. This is usefull: But currently the repr of the full array is just not useful. I would rather have something like: Currently methods like sr.design.get_all_bpms return a list so it's not possible to do something custom but this will soon change with #199 if I am not mistaken. Then something more custom is possible. Do you think we need another issue to discuss this? |
|
The new API: sr.design.bpm.all() # Return a python list a all BPM
sr.design.bpms.get() # Return a BPMArray containing all BPM
sr.design.bpms.get("BPM") # Return a BPMArray named BPM from the configFor the moment both (list and array) print the same thing. I agree we can print somehing like: For Array: |
|
In fact, it's better to wait for @TeresiaOlsson to finish removing ConfigModel. Right now it's a bit painful to go through the string representation because some strings are printed from ConfigModel and not from new pyaml_repr. I will continue once ConfigModels are removed. |
I like this. My modifications to the I saw that you have finished reviewing and merging most of the PRs for removing the ConfigModels now :) I will be back at work tomorrow and then I will rebase the last ones and continue working on the documentation. My hope was that we as part of the documentation somehow can call the |
|
I think it depends on what you want. The idea was here: https://github.com/orgs/python-accelerator-middle-layer/discussions/52 to use In some cases I made a private attribute because the attribute is used in the constructor to initialize other things. So if I made it public the user could potentially change it but without triggering the required changes in other attributes. The fix for those cases is to add a property setter but I skipped doing it in these PRs to not make them too large. My thinking was that we more easily can add this later when we discover where it would be useful. So my suggestion is to instead of making the attributes public (unless they are simple ones), add a property. Also read-only properties (without a setter) should automatically show up in the string representation otherwise it's a bug. I think in general it is a nice idea that what shows up in the string representation is only the public interface of the class because it's a common way for the users to know which attributes are available for them to read and change. |
Yes, but the point is that x_pos and y_pos should be public. They can be used for direct access to underlying control system attributes, like requested in #44 . So, for most objects, we could provide some kind of control_system_names. |
Okay, then it sounds like a bug in the BPM class. I was conservative and made attributes private unless I was fully sure that it was something the user should be allowed to change. |
|
I think the problem is what type But maybe this is not true anymore after the changes to the controlsystem backend? Maybe I think there were many places like this where I made an attribute private since it internally changed type from a string to something else and a property would be needed to handle changes to it correctly. |
It does not need to be changed I think. Your proposal to make it a property with no setter is a good one. |
Work in progress!
Modified pyaml_repr to print nested string representation. For BPM, this gives better results.
There are a few issues still that can be resolved in different ways.
When solved resolves #345