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

Copy fixes #1271

Merged
merged 3 commits into from
Feb 17, 2017
Merged

Copy fixes #1271

merged 3 commits into from
Feb 17, 2017

Conversation

jgosmann
Copy link
Collaborator

@jgosmann jgosmann commented Feb 16, 2017

Motivation and context:
It was brought to my attention that copying of SPA models did not work (#1266). While investigating, it became apparent that only part of the problem is SPA specific. The other part is related to copying instance parameters. This are a somewhat obscure feature and rarely used, but unfortunately the current SPA system depends on them (e7b0edc).

This PR fixes all those problems.

Interactions with other PRs:
It might be necessary to fix this in the new SPA system too. Thus, I would like to keep the associated issue #1266 open.

How has this been tested?
Added two tests. One for copying instance parameters and one for copying a SPA model.

How long should this take to review?

  • Average (neither quick nor lengthy)
  • Lengthy (more than 150 lines changed or changes are complicated)

Not many lines have changed which can make this a normal length review, but the config and param system is quite complex and intricated. So depending on prior familarity with it and how much one desires to understand how all the pieces work together, this can get a length review.

Where should a reviewer start?
This is a bit difficult. I split this up in multiple commits concerned with specific things, but all of these commits (except the last SPA commit) are needed just to fix the copying of instance params.

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.

Still to do:

Copy link
Contributor

@Seanny123 Seanny123 left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Member

@tbekolay tbekolay left a comment

Choose a reason for hiding this comment

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

This looks good to me, and makes sense to get in as a bug fix in 2.3.1. Thanks @jgosmann! I'll add the changelog entry in the merge.

The keys of the WeakKeyIDDictionaries do not get updated on a normal
copy operation. This is rarely a problem because Parameters are usually
class variables that will not get copied, but there is the possibility
to define instance parameters (slightly obscure usage, but is for
example used in the current SPA system). In this case the Parameter
instance needs to be copied. Adding the __getstate__ and __setstate__
handler allows to convert the WeakKeyIDDictionaries to normal
dictionaries with strong references and convert them back. This will
cause the keys to be updated (partially due to Python's copy magic).

It also seems to me that obtaining strong references during the copy
process is a good idea because than none of the objects can disappear
during copying (or serialization).

Addresses #1266.
The involved __getattr__/__setattr__ logic would otherwise screw up.

Addresses #1266.
When reconstructing objects during copy, the check for whether a
module has been added twice to a model needs to be avoided.

Addresses #1266.
@tbekolay tbekolay merged commit 666b555 into master Feb 17, 2017
@tbekolay tbekolay deleted the copy-fixes branch February 17, 2017 15:44
jgosmann added a commit to nengo/nengo-spa that referenced this pull request May 9, 2017
jgosmann added a commit to nengo/nengo-spa that referenced this pull request May 10, 2017
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