Formulas
Last updated
Last updated
Formulas allow for using mathematical expressions for specifications. There are three different parameter types that support formulas:
Integer
Number
PhysicalQuantity
The formula syntax is different for each parameter type and becomes richer wen traversing the list from top to bottom.
The Integer formula syntax allows any kind of mathematical expression that is valid Python syntax (including parentheses, e.g. "(2 + 3*4) * 5**6"
) and which will result in an integer value. For that reason the Integer formula syntax forbids true division expressions by default (e.g. 4 / 2
, see ). Floor division however is allowed (4 // 2
).
The Number formula syntax extends the Integer formula syntax by true division as well as by references to a broad set of functions (and the constant pi
). These can be used directly within the expressions: (2 + 3) * 4 * sin(pi / 4)
. To see which numpy functions are available check Number.np_members
.
The PhysicalQuantity formula syntax extends the Number formula syntax by the possibility to reference constants defined in . These constants can be refered to by their name using the syntax {name of constant}
.
By default the formula syntax for all parameters is activated. You can deactivate it by setting e.g. Integer.formulas = False
. If you want to deactivate on a per instance basis you can do so via Integer(formulas=False)
. You can even customize what kind of formula syntax is allowed by providing a regular expression to formulas
. This regular expression will be matched against the specified formula and raise a ValueError
if the formula is invalid. If for example you want to allow only addition in the formulas for a specific Integer parameter you can do so via Integer(formulas=r'^(\d+\s*\+\s*)*\d+$')
.