Value parameter reassignment syntax
PROBLEM:
To reassign the value of a variable defined as var var_name var_value
we need to use the .value
syntax, like in Python style. That's not really similar to katScript language as much as possible.That I think is our goal. I noticed because an error raised.
KatScript starting point:
base = finesse.Model()
code = '''
#variable
var Rcxy 184.9 # we scan on var to change both Rcx/Rcy in the Xaxis
#laser
laser laser1 P=1
s s_ laser1.p1 bs1.p1 L=1
# bs(RoC)
bs bs1 R=1 T=0 Rc=[Rcxy,Rcxy]
pd pd1 bs1.p2.o
'''
base.parse(code)
The line that get me to the Error:
base.Rcxy=180
The Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_176054/1046847398.py in <module>
1 # first, let's try to reassign the Rcxy value
----> 2 base.Rcxy=180 # error arising
~/miniconda3/envs/finesse3/lib/python3.9/site-packages/finesse/model.py in __setattr__(self, name, value)
275 super().__setattr__(name, value)
276 elif isinstance(obj, ModelElement):
--> 277 raise AttributeError(f"Cannot overwrite element `{repr(obj)}` in model")
278 else:
279 super().__setattr__(name, value)
AttributeError: Cannot overwrite element `<'Rcxy' @ 0x7fc0d48b3430 (Variable)>` in model
How to fix it using similar Python language (not our goal):
base.Rcxy.valeu=180
FYI all the below methods to pass the same variable value to xaxis()
or Xaxis()
work fine (see plot attached).
out_1 = base.run('xaxis(Rcxy,lin,180,185,20)')
out_2 = base.run('xaxis(Rcxy.value,lin,180,185,20)')
out_3 = base.run(Xaxis("Rcxy","lin",180,185,20))
out_4 = base.run(Xaxis("Rcxy.value","lin",180,185,20))
This too is a bit ambiguous. To choose a single method would be preferred, I think.
Edited by Antonella Bianchi