Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functools.partial does not work properly for node outputs #1572

Open
hunse opened this issue Oct 23, 2019 · 1 comment
Open

Functools.partial does not work properly for node outputs #1572

hunse opened this issue Oct 23, 2019 · 1 comment

Comments

@hunse
Copy link
Collaborator

hunse commented Oct 23, 2019

Describe the bug

When using a functools.partial instance as a node output, we internally check inspect.isroutine on the output and if this is not true, we subtract 1 from the length of the argument list because we assume the first argument is self. However, functools.partial instances apparently do not register as routines, but do not have a self argument.

To reproduce

A minimal code snippet to reproduce the behavior:

import nengo

def input_fn(t, q):
    return t + q

with nengo.Network() as net:
    u = nengo.Node(partial(input_fn, q=3))

with nengo.Simulator(net) as sim:
    pass

Expected behavior

This should work. (e.g. should be able to probe node u above and get t + 3 as the output.

Error message and logs

/data/eric/workspace/nengo/nengo/node.py in coerce(self, node, output)
     71                 node.size_out = output.default_size_out
     72         elif callable(output):
---> 73             self.check_callable_args_list(node, output)
     74             # We trust user's size_out if set, because calling output
     75             # may have unintended consequences (e.g., network communication)

/data/eric/workspace/nengo/nengo/node.py in check_callable_args_list(self, node, output)
    134 
    135             if not required_len <= expected_len <= args_len:
--> 136                 raise self._fn_args_validation_error(output, self.name, node)
    137 
    138 

ValidationError: Node.output: output function 'functools.partial(<function input_f at 0x7f1c92addbf8>, phase_offset=0)' is expected to accept exactly 1 argument (time, as a float)
@drasmuss
Copy link
Member

Ran into this same issue for a different reason in NengoDL, which I fixed like this https://github.com/nengo/nengo-dl/blob/fbf57c612668bfcc231788b0ed5dccd22695e271/nengo_dl/tensor_graph.py#L701. Should probably be able to do something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants