INTO-CPS-Association / pyfmu

https://into-cps-application.readthedocs.io/en/latest/submodules/pyfmu/docs/index.html
7 stars 2 forks source link

Make register_variable return a variable #22

Closed clegaard closed 4 years ago

clegaard commented 4 years ago

To suppress undefined variable IDE/Linting warnings, it is necessary to declare a variable explicitly as follows:

self.a = 0
self.register_variable("a", "real", "input", description='acceleration',start=0)

There are at least two problems with this:

  1. It requires two lines of code rather than one
  2. start value mismatch, what if the two do not match?

A solution to this would be to have the register_variable function return the start value:

self.a = register_variable("a","real","input",description="acceleration",start=0)

This would ensure that the two values are identical and would also open the possibility of returning a variable object rather than a primitive. This object could ensure that only valid values could be written to the variable.

clegaard commented 4 years ago

This has been mitigated by two checks:

  1. register_variable checks for the existence of the attribute
  2. start values are now inferred by reading the attributes when a model description is generated.

The first one ensures that the IntelliSense works correctly, the second one ensures that start value and the value declared in python are identical