This repository was archived by the owner on Apr 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
FWEP 1 Json/Dictionary type of I/O definition #74
Copy link
Copy link
Open
Labels
Milestone
Description
FWEP (FUSED-Wind Enhancement Proposal) 1:
Json/Dictionary type of I/O definition
Hey FUSED people,
We have had a short discussion with Justin on their upcoming big change of API. They are apparently planning to change the way they define the I/Os:
instead of
class MyComp(Component):
x = Float(x, iotype="in")
y = Float(x, iotype="out")
def execute(self):
self.y = 2*self.xyou would do something like:
class MyComp(Component):
def __init__(self):
self.add_input('x', float)
self.add_output('y', float)
def execute(self, inputs, outputs):
outputs['y']= 2*inputs['x']So this is a quite drastic change for us, as we rely on the components I/O definition to define our standard interfaces. What I propose is to add a layer on top of OpenMDAO (that might hopefully eventually be supported by OpenMDAO) so that things are defined this way:
@FUSED_IO(
inputs=[
{name:’x’, 'type':float},
{name:’x2’, 'type':list},
{name:’x3’, 'type':array},
],
outputs=[
{name:’y’, 'type':float},
{name:’y2’, 'type':list, 'size':…, 'desc':‘blabla'},
{name:’y3’, 'type':array, 'size':..},
])
class MyComp(Component):
def execute(self, inputs, outputs):
outputs['y']= 2*inputs['x’]
...Here are a few advantages of doing that:
- To do the repetitive add_input / add_output call under the hood through the decorator
- To have a set of thin decorators that can take a non openmdao function or class and wrap them into a FUSED-Wind openmdao component
- To have a list of standard FUSED-Wind variables:
wind_speed = {name:’wind_speed’, type:float, min:4.0, max:25.0, desc:’A wind speed float’, unit:’m/s’}
hub_wind_speed = expand(wind_speed, {name:’hub_height_wind_speed’, desc:’The wind speed at hub height'})
rotor_height = {’name’:’rotor_height’, ….}
wt_layout = {
‘wt_list’: {'name':’wt_list’, type:[wt_descriptor],…} # we would need to define some kind of elegant way to inform what are the contents of the lists
‘wt_positions’: {‘type’:array, ’size’:’[n,2]'}
‘wt_wind_roses’: {...}}expandcould be function keeping track of inheritance, for multi-fidelity I/O definition, if necessary.
dico = {'name':'dico',
'a':1,
'b':2,
'based_on':[]}
expand = lambda x, y: dict(x.items() + y.items() + [('based_on', [x['name']]+x['based_on'])])
expand(dico, {'name':'new_dico','c':3, 'a':3})
{'a': 3, 'b': 2, 'based_on': ['dico'], 'c': 3, 'name': 'new_dico'}- These standard variables could then be used to define our FUSED-Wind interfaces:
from fusedwind.variables import wind_speed, wind_direction, wt_layout, net_aep, gross_aep
@FUSED_IO(
inputs=[wind_speed, wind_direction, wt_layout],
outputs=[net_aep, gross_aep])
class MyComp(Component):
...- Our standard interfaces could then be defined as dictionaries:
GenericAEP = FUSED_IO(
inputs=[wind_speed, wind_direction, wt_layout],
outputs=[net_aep, gross_aep])- Then any component satisfying this interface could be done like that:
@FUSED_IO(
based_on=GenericAEP,
inputs=[wind_speed, wind_direction, wt_layout],
outputs=[net_aep, gross_aep, capacity_factor])
…Or something looking like that
@GenericAEP
@FUSED_IO(outputs=[capacity_factor])
…(a bit less verbose...)
- As everything is already defined in dictionary, it’s a simple step to go to Json files, defined standard inputs/outputs files, REST interfaces etc..
- To use this definition to generated automatically a standard RESTful web API. So being able to deploy quickly a FUSED-Wind compatible function of Component into a webmodel.
So potentially somebody developing in another language could deploy their model online using the same standard API as we defined in FUSED-Wind and thereby make their model available to run in a FUSED-Wind assembly. We would “just” need to inform the web address and credentials, and the Component could automatically generate it’s input/outputs from the REST interface definition. This would be our way to open up FUSED-Wind collaboration beyond the python and openmdao community to anybody else able to deploy REST interfaces (hint: could be something we advocate through the IEA SE task).
What do you think about this idea?