Can't set element attribute values as strings
For the CLI interactive shell (!34 (closed)) it is desirable to be able to set element attributes such as Mirror.R
using strings, e.g. "0.98"
. This is because the text input to the CLI is always as strings, so if the user wants to update an element attribute the value passed to the setter will be a string. For instance, the !set
command in the shell currently fails when setting a mirror's R
(using the branch in !34 (closed)):
$ kat3 shell
Welcome to the finesse 0.1.1.dev2013+gc19a1772 shell. Type help or ? to list commands.
(kat) mirror m1 R=0.99 T=0.01
(kat) !info m1
Mirror m1
Parameters:
╒═════════════════════════╤═════════╕
│ Description │ Value │
╞═════════════════════════╪═════════╡
│ Reflectivity │ 0.99 │
├─────────────────────────┼─────────┤
│ Transmission │ 0.01 │
├─────────────────────────┼─────────┤
│ Loss │ 0 │
├─────────────────────────┼─────────┤
│ Phase │ 0 │
├─────────────────────────┼─────────┤
│ Radius of curvature (x) │ inf │
├─────────────────────────┼─────────┤
│ Radius of curvature (y) │ inf │
├─────────────────────────┼─────────┤
│ Misalignment (x) │ 0 │
├─────────────────────────┼─────────┤
│ Misalignment (y) │ 0 │
╘═════════════════════════╧═════════╛
(kat) !set m1.R 0.98
Traceback (most recent call last):
File "src/finesse/element.pyx", line 567, in finesse.element.Parameter.__update_state
raise Exception(f"Unexpected input '{self.__value}'")
Exception: Unexpected input '0.98'
Exception ignored in: 'finesse.element.Parameter._set_value'
Traceback (most recent call last):
File "src/finesse/element.pyx", line 567, in finesse.element.Parameter.__update_state
raise Exception(f"Unexpected input '{self.__value}'")
Exception: Unexpected input '0.98'
I think if possible, we should allow strings to be set as any model parameter as long as it actually has an equivalent float/complex/whatever representation.
Related is the discussion of handling units in #168 (closed). We may wish to, alongside supporting strings in general, also support the specification of one or both of units and SI prefices (m
, k
, M
, etc.).