Skip to content

Adding Model parameters

Daniel Brown requested to merge feature/allow_model_parameters into develop

Fixes #525 (closed) Closes !136 (closed)

Changes to allow parameters to be added to the Model. This is so that generic variables can be added which do not need a Variable element and stopping the need for .value.value accesses with symbolic variables.

Removed Parmeter.component, just Parameter.owner now as owner could be a ModelElement or a Model. Model doesn't have a name so there may be more code which needs to handle the fact that parameter.owner might not have a name.

Usages:

import finesse
model = finesse.Model()
model.parse("l l1")
model.parse("var C l1.P")

A = model.add_parameter('A', 1)
B = model.add_parameter('B', A.ref +1)
print(model.unparse())

Gives

l l1
var C l1.P
# Items below could not be matched to original script, or were not present when the model was originally parsed.
variable A 1.0
variable B (A+1)

Which also works with just usual math operations:

>>> model.A * 2
2.0
>>> model.A.ref * 2
❮Symbolic='(A*2)' @ 0x1566091e0❯

Parameters in the model can be retrieved with:

>>> model.parameters
(❮C=l1.P @ 0x156f34ac0❯, ❮A=1.0 @ 0x156f34a00❯, ❮B=(A+1) @ 0x156f34b80❯)
Edited by Daniel Brown

Merge request reports