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

Raise BuildError if conn function returns None #1319

Merged
merged 1 commit into from
Jun 6, 2017

Conversation

tbekolay
Copy link
Member

@tbekolay tbekolay commented Jun 6, 2017

Motivation and context:
In #1318 @ikajic reported that we don't raise a nice error if someone forgets to return a value from a connection function (which is a common thing to forget, especially when moving from a lambda to a named function). This raises a nice error when that happens.

How has this been tested?
Added a test that the error gets raised.

How long should this take to review?

  • Quick (less than 40 lines changed or changes are straightforward)

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the CONTRIBUTING.rst document.
  • I have updated the documentation accordingly.
  • I have included a changelog entry.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Discussion points

This error gets raised at build time, not a model creation time. This is because running a connection function might not be something the user expects when defining the model. It already gets run at build time, so this keeps the user's expectations the same. We could do this at model creation time though, if the consensus prefers that.

@tbekolay tbekolay requested a review from ikajic June 6, 2017 15:42
Copy link
Collaborator

@jgosmann jgosmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a small fixup to avoid evaluating the function twice. LGTM. 🍰

targets[i] = conn.function(ep)
out = conn.function(ep)
if out is None:
raise BuildError("Building %s: Connection function returned "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is good! I am just wondering if those memory locations (and other meta-data about Ensembles) is really necessary, e.g.,:
BuildError: Building <Connection from <Ensemble (unlabeled) at 0x7fe738f619d0> to <Ensemble (unlabeled) at 0x7fe738f61b90> computing 'f'>: Connection function returned None. Cannot solve for decoders.

I find they obfuscate the message, but if this is standard in error reporting for Nengo, then it's probably better to leave it as it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory locations go away if the pre and post of the connection have labels. I agree that they're not necessary for most purposes, but they are useful for debugging... might be worth making them something that show up in debug mode only?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory locations go away if the pre and post of the connection have labels.

Cool, I didn't know connections can have labels! :)

might be worth making them something that show up in debug mode only?

Yeah, (if it's not a hassle to implement) I'd say so. The error msg that appears when connections have labels is way clearer to me. I don't think we used label keyword once during the summer school tutorials so I am guessing someone new to Nengo will most likely end up with that long error, which is more useful to devs than regular users.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer to have the memory addresses in the error message for unlabeled objects because it is the only thing maybe allows me to identify the object. Adding a “debug mode” might make the error message to appear simpler, but it will require users to know about the debug mode and it is likely to introduce more complexity to the code base.

Copy link
Member Author

@tbekolay tbekolay Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a separate PR for it so we can discuss it in more depth there.

Doing this as model definition time is possible, but requires
running the function, which may not be desirable.
@tbekolay tbekolay merged commit 31b9c20 into master Jun 6, 2017
@tbekolay tbekolay deleted the error-for-none-function branch June 6, 2017 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants