-
Notifications
You must be signed in to change notification settings - Fork 37
Improvement of response matrices #974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3390122 to
c840e96
Compare
|
Hello, I'm still having this issue: I managed to make it work by doing the mod below: I expect that the response matrix engine can be fully ring independent. I didn't find a way to define a Here is a sample code and I would like that the ring is not passed at all to AT functions: def set_int_field(value:float,e:Magnet,ring:at.Lattice|None):
e.set_strength(value)
def get_int_field(e:Magnet,ring:at.Lattice|None):
return e.get_strength()
def eval_tune(ring): # Here ring should be a free param as Magnet object for a CustomVariable
return ring.get_tune()
def get_tune_matrix(ring:at.Lattice,qdTune:list[Magnet],qfTune:list[Magnet]):
variables = None
DT = 1e-5
varlist = []
for q in qdTune:
v = CustomVariable(set_int_field, get_int_field, q, delta=DT)
varlist.append(v)
for q in qfTune:
v = CustomVariable(set_int_field, get_int_field, q, delta=DT)
varlist.append(v)
variables = VariableList(varlist)
observables = ObservableList([RingObservable(eval_tune)])
observables.evaluate(ring=ring)
tune_response = ResponseMatrix(variables, observables, ring)
tune_response.build(use_mp=True)
tune_response.solve()
mat = tune_response.correction_matrix()
return mat |
|
I did some other corrections to avoid crashes with
For "custom observables", the easiest is to use the base With this, here is an updated version of your example: def set_int_field(value: float, e:Magnet, **_):
e.set_strength(value)
def get_int_field(e: Magnet, **_):
return e.get_strength()
def eval_tune(eval_data, **_):
return eval_data.get_tune()
def get_tune_matrix(eval_data, qdTune: list[Magnet], qfTune: list[Magnet]):
DT = 1e-5
variables = at.VariableList()
for q in qdTune:
variables.append(CustomVariable(set_int_field, get_int_field, q, delta=DT))
for q in qfTune:
variables.append(CustomVariable(set_int_field, get_int_field, q, delta=DT))
obs = Observable(eval_tune, eval_data, name="tunes")
observables = ObservableList([obs])
observables.evaluate()
tune_response = ResponseMatrix(variables, observables)
tune_response.build(use_mp=True)
tune_response.solve()
mat = tune_response.correction_matrix()
return matIs this what you expect ? I am still adding a few features, let me know if you have ideas ! |
ring as keyword hook restore variables
998f1b8 to
1dab835
Compare
|
I added the possibility to add keywords to the This gives the possibility to give "modifiers" to these functions ( These keywords given to def set_int_field(value: float, e:Magnet, **_):
# Keywords are ignored
e.set_strength(value)
def get_int_field(e: Magnet, **_):
# Keywords are ignored
return e.get_strength()
v = CustomVariable(set_int_field, get_int_field, q, delta=DT)
v.get(verbose=True) # get_int_field receives and ignores the "verbose" keywordSimilarly, there are optional keywords in def eval_tune(eval_data, scaling=1.0, **_):
# Accept a scaling custom keyword
return scaling*eval_data.get_tune()
obs = Observable(eval_tune, eval_data, name="tunes")
observables = ObservableList([obs])
observables.evaluate(scaling=0.9). # eval_tune gets the "scaling" value |
|
Thanks @lfarv |
The modifications described above give a solution for that: when adding a v = RefptsVariable("QD2[AE]", "PolynomB", index=1, ring=ring)
v.get()
np.float64(-2.6720252472931687)Here |
|
The problem with the tests comes from the release of a new version of |
|
@swhite2401 and @JeanLucPons : as far as I can see, this version answers all the points discussed in #962 and here above. Is there any remaining point, or can we merge this one, and take care of the next points in another PR? |
This PR implements the features requested in #962.
ResponseMatrixwithring=None(the default), if no lattice is necessary for any variable or observable,RefptsVariablewithring=None,