superduper icon indicating copy to clipboard operation
superduper copied to clipboard

[BUGS-0.2.0]: The predict function of the graph model cannot handle models with default parameter values.

Open jieguangzhou opened this issue 1 year ago • 0 comments
trafficstars

Contact Details [Optional]

No response

System Information

main

What happened?

from superduperdb import ObjectModel
from superduperdb.components.graph import Graph, document_node, input_node


def func1(x, k=100):
    return x + k

def func2(x, y):
    return x + y


model1 = ObjectModel('model_1', object=func1)
model2 = ObjectModel('model_2', object=func2)
in_ = input_node('number')
out1 = model1(x=in_)
out2 = model2(x=out1, y=in_)
graph = out2.to_graph('my_graph')

Execution of graph.predict_one(5) succeeded, but execution of graph.predict([5]) failed.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[11], line 1
----> 1 print(graph.predict([5]))

File [~/workspace/SuperDuperDB/superduperdb/superduperdb/components/component.py:389](http://localhost:8888/lab/tree/docs/content/use_cases/~/workspace/SuperDuperDB/superduperdb/superduperdb/components/component.py#line=388), in ensure_initialized.<locals>.wrapper(self, *args, **kwargs)
    387     self._is_initialized = True
    388     logging.info(f"Initialized  {model_message} successfully")
--> 389 return func(self, *args, **kwargs)

File [~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py:542](http://localhost:8888/lab/tree/docs/content/use_cases/~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py#line=541), in Graph.predict(self, dataset)
    540 # Validate the node for incompletion
    541 if isinstance(self.output_identifiers, list):
--> 542     list(map(self.validate, self.output_identifiers))
    543 else:
    544     self.validate(self.output_identifiers)

File [~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py:387](http://localhost:8888/lab/tree/docs/content/use_cases/~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py#line=386), in Graph.validate(self, node)
    384 # TODO: Create a cache to reduce redundant validation in predict in db
    386 predecessors = list(self.G.predecessors(node))
--> 387 dependencies = [self.validate(node=p) for p in predecessors]
    388 model = self.nodes[node]
    389 if dependencies and len(model.inputs) != len(dependencies):

File [~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py:387](http://localhost:8888/lab/tree/docs/content/use_cases/~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py#line=386), in <listcomp>(.0)
    384 # TODO: Create a cache to reduce redundant validation in predict in db
    386 predecessors = list(self.G.predecessors(node))
--> 387 dependencies = [self.validate(node=p) for p in predecessors]
    388 model = self.nodes[node]
    389 if dependencies and len(model.inputs) != len(dependencies):

File [~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py:390](http://localhost:8888/lab/tree/docs/content/use_cases/~/workspace/SuperDuperDB/superduperdb/superduperdb/components/graph.py#line=389), in Graph.validate(self, node)
    388 model = self.nodes[node]
    389 if dependencies and len(model.inputs) != len(dependencies):
--> 390     raise TypeError(
    391         f'Graph disconnected at Node: {model.identifier} '
    392         f'and is partially connected with {dependencies}\n'
    393         f'Required connected node is {len(model.inputs)} '
    394         f'but got only {len(dependencies)}, '
    395         f'Node required params: {model.inputs.params}'
    396     )
    397 return node

TypeError: Graph disconnected at Node: model_1 and is partially connected with ['_input']
Required connected node is 2 but got only 1, Node required params: ['x', 'k']

Steps to reproduce

...

Relevant log output

No response

jieguangzhou avatar May 23 '24 15:05 jieguangzhou