fast-aircraft-design / FAST-OAD

FAST-OAD: An open source framework for rapid Overall Aircraft Design
GNU General Public License v3.0
47 stars 25 forks source link

Allow String variables to be displayed in Variable Viewer #472

Closed felixpollet closed 1 year ago

felixpollet commented 1 year ago

Is your feature request related to a problem? Please describe. The variable viewer does not display a variable if its value is a string.

For example, the following variable in the xml file will not appear in the variable viewer: `

APC ` **Describe the solution you'd like** In the `VariableList` class, the `to_dataframe` method could be modified to allow for non-float values (line `value = self._as_list_or_float(variable.value)`) : ``` def to_dataframe(self) -> pd.DataFrame: var_dict = {"name": []} var_dict.update({metadata_name: [] for metadata_name in self.metadata_keys()}) for variable in self: value = self._as_list_or_float(variable.value) # Allow for non-float values var_dict["name"].append(variable.name) for metadata_name in self.metadata_keys(): if metadata_name == "val": var_dict["val"].append(value) else: # TODO: make this more generic if metadata_name in ["val", "initial_value", "lower", "upper"]: metadata = self._as_list_or_float(variable.metadata[metadata_name]) else: metadata = variable.metadata[metadata_name] var_dict[metadata_name].append(metadata) df = pd.DataFrame.from_dict(var_dict) return df ```
christophe-david commented 1 year ago

Thanks for this suggestion.

May I ask what is your use case ? I mean that FAST-OAD currently expects each process variable to be a float (we still do not use OpenMDAO feature for discrete variables), so it won't accept a string value in an XML data file. Therefore, only making the variable viewer able to read such a file may appear of limited interest.

felixpollet commented 1 year ago

Thank you for your quick reply.

I am developing an extension to FAST-OAD for electric drones. One of the features is discrete selection of off-the-shelf components from catalogs during the design process. So it would be convenient (though not absolutely necessary) to display in the variable viewer the names/references of the selected components.

christophe-david commented 1 year ago

I was expecting something like this. If I understand well, this is not only about the variable viewer. If you want to use an OpenMDAO component that uses discrete variables, all FAST-OAD needs to be compliant with this feature, and currently, it is not.

For the rare use cases that needed discrete variables, putting integers (indeed processed as float) among other variables was enough. That is why this feature has not been a priority. We may consider to raise the priority for this development, but anyway, I cannot tell a target date for now.

felixpollet commented 1 year ago

I only use discrete outputs to provide additional information, and I have had no problem adding such outputs to OpenMDAO components. In fact, the selection process is not done with discrete variables, I use continuous variables instead. Therefore, FAST-OAD does not have to handle discrete variables for the sizing process. It only has to read some discrete outputs that do not affect the procedure. Sorry for the misunderstanding.

The discrete outputs are visible in the output xml file. In my specific case, the only missing bridge seems to be between the xml file and the variable viewer.

christophe-david commented 1 year ago

Actually, I wasn't expecting discrete outputs to show up in the XML file, but you are right 😅. So Ok, it's just about the variable viewer. That should be doable for next release in January. Stay tuned...