217 strange behavior of serialized magnets#223
Conversation
…ith serialized magnets
|
OK Thanks. strength = m.strengths.get()
m.strengths.set(strength + 1e-4)I expect: strength = m.strength.get() # Should return the sum of all underlying strength
m.strength.set(strength + 1e-4) # Should spread the given strength to all underlying magnet according to the length>>> print(quadForTuneDesign.strengths.get())
[-0.61758841 -0.61758841 0.79250831 0.79250831]
# should return value ~32 times bigger |
There was a problem hiding this comment.
def get_serialized_magnet(self, name: str) should return a Magnet as before
|
That true that our QF1 and QD2 does not have the same current due to our canted beamlines. |
|
I add that when you want to deal with serialized magnet that are not all the same (the reality) m.hardware.set(...) |
It is implemented in the |
|
It should be OK now, @JeanLucPons. Could you take a look? Sorry to bother you, I don’t have your level of expertise on this matter. |
|
Thanks |
sr = Accelerator.load("tests/config/sr_serialized_magnets.yaml", use_fast_loader=True, ignore_external=True)
m = sr.design.get_serialized_magnet("QF1A")
print(m.strength.get())I expect that a string has a strength attribute not strengths (same for harware), otherwise no way to use it in tuning tools. |
|
Could you also update comments in |
…removing "combined function magnets" from several comments.
|
If it was your last remarks, it should be ok now. |
? |
Corrected |
…of-serialized-magnets
sr = Accelerator.load("tests/config/sr_serialized_magnets.yaml", use_fast_loader=True, ignore_external=True)
m:SerializedMagnets = sr.design.get_serialized_magnet("QF1A")
print(m.strength.get())
print(m.get_nb_magnets())
print(m.get_magnets()[0].strength.get())
print(m.get_magnets()[1].strength.get())outputs: |
|
With the same model for all QF1A magnets in the string, I expect: def get_strenghts_from_lattice(sr,sm):
ring = sr.design.get_lattice()
strs = []
for m in sm.get_magnets():
elt = ring.get_elements(f"{m.get_name()}")[0]
strs.append(elt.K*elt.Length)
return strs
sr = Accelerator.load("tests/config/sr_serialized_magnets.yaml", use_fast_loader=True, ignore_external=True)
m:SerializedMagnets = sr.design.get_serialized_magnet("QF1A")
print(m.strength.get())
print(m.get_nb_magnets())
# Strengths that should be returned using [m.strength.get() for m in m.get_mangets()]
print(get_strenghts_from_lattice(sr,m))
m.strength.set(24.0)
print(get_strenghts_from_lattice(sr,m)) 24.651047425284716
31
[0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7922118226646928, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.8172956386178192, 0.8257533472095736, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7922117043717326, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7925083076304686, 0.7922117785682908, 0.7925083076304686, 0.7922116233599168, 0.7925083076304686, 0.8195450222441725, 0.7925083076304686, 0.7922118961610275, 0.7925083076304686, 0.792211824217169, 0.7925083076304686]
[0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964, 0.7741935483870964] |
|
I added your code as a unit test. I'm working on it. |
…the sum of each sub magnets and each of them returns its strength.
|
It should be ok now. There is now a test with the tune and a test with your example. |
…of-serialized-magnets
|
I test it ASAP. |
Description
This PR fixes the strange behavior observed on serialized magnets when setting either the strength or the hardware value.
The issue report showed that, in the test configuration for serialized magnets, setting a strength on the serialized object could leave the first magnet with the requested strength while the others ended up with another common value, which was confusing and inconsistent from the user point of view .
From the discussion, two points emerged:
This PR makes the serialized magnet behavior consistent again for both directions:
Related Issue
Features/issues described there are:
strength.set(...)andhardware.set(...)keep the series coherentChanges to existing functionality
Describe the changes that had to be made to an existing functionality (if they were made)
Testing
The following tests (compatible with pytest) cover this change:
test_config_loadintest_serialized_magnets.py, which verifies that:Verify that your checklist complies with the project