OpenModelica / OMPython

A Python interface to OpenModelica communicating via CORBA or ZeroMQ
Other
107 stars 58 forks source link

feat: get unit of scalars in quantitiesList #220

Closed jules-l-jimmy closed 4 months ago

jules-l-jimmy commented 4 months ago

Hi, I want to get the parameters and variables in python Quantities. Therefore I can get the unit by parsing the unit from xml database Then I do not know how do you want to edit getContinuous, getParameters and getSolutions functions to support Quantities. Do you want to have an additional argument in these functions ? Or do you prefer to have another function ?

Purpose

Get the unit of the parameters and variables to return python Quantities

jules-l-jimmy commented 4 months ago

Hi @arun3688, What do you think of this feature ? How do you believe I can add support for Quantities ?

arun3688 commented 4 months ago

@jules-l-jimmy I guess you have already implemented the feature for extracting units for getQuantities() API, getParameters(), getContinuous() are independant API, Can you elaborate what you want to do, may be it is already there, you can set parameters via setParameters() API

jules-l-jimmy commented 4 months ago

@jules-l-jimmy I guess you have already implemented the feature for extracting units for getQuantities() API, getParameters(), getContinuous() are independant API, Can you elaborate what you want to do, may be it is already there, you can set parameters via setParameters() API

I want to have an option or a dedicated function to return a Quantity class instead of a float when using getContinuous or getParameters the quantity would be equal to Quantity(value,unit) with value the float value that we got today.

And for set parameters, I want to be able to send a Quantity and the code would automatically do a get_in(unit) with unit the unit of the parameter

Best,

arun3688 commented 4 months ago

@jules-l-jimmy Ok i see that it is basically when you use getParameters(), you want to display with units as well, for this you can use the existing API to display the additional quantity information, But when you set parameters you should make sure that units cannot be overridden and only the values are allowed to be set and when we do simulate you must make sure only the values are passed and not the units, I guess having additional function means when u set the parameters you have to update the new values in old function as well, so it is better to have in the same API as optional arguments

jules-l-jimmy commented 4 months ago

@jules-l-jimmy Ok i see that it is basically when you use getParameters(), you want to display with units as well, for this you can use the existing API to display the additional quantity information, But when you set parameters you should make sure that units cannot be overridden and only the values are allowed to be set and when we do simulate you must make sure only the values are passed and not the units, I guess having additional function means when u set the parameters you have to update the new values in old function as well, so it is better to have in the same API as optional arguments

@arun3688 I understand. I believe, it is good to merge this PR for now. I will develop something in the next month but it will use unitregistry from pint which involve adding a new package for requirements. I will do another PR and you will decide if it can be merge or if it is more a "user" function that can be coded by the final user.