-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
NUP-2506: Add test to all Serializable subclasses and fix related issues #3826
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b2c9fa
NUP-2506: Add test to all Serializable subclasses making sure all the…
lscheinkman a780a7c
NUP-2506: Fix new serialization issues
lscheinkman 1dbcc2f
NUP-2506: Make sure cells4 are serialized when using BacktrackingTMCPP
lscheinkman a2ecf98
NUP-2506: Fix serializable test
lscheinkman 1eb20ea
NUP-2506: Fix linux test and lint issues
lscheinkman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pic/regions/AnomalyLikelihoodRegion.capnp → ...nupic/algorithms/anomaly_likelihood.capnp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ def __init__(self, | |
# If set to False, Cells4 will *not* be treated as an ephemeral member | ||
# and full BacktrackingTMCPP pickling is possible. This is useful for testing | ||
# pickle/unpickle without saving Cells4 to an external file | ||
self.makeCells4Ephemeral = True | ||
self.makeCells4Ephemeral = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦♂️ |
||
|
||
#--------------------------------------------------------------------------------- | ||
# Store the seed for constructing Cells4 | ||
|
@@ -162,6 +162,8 @@ def __init__(self, | |
outputType = outputType, | ||
) | ||
|
||
if not self.makeCells4Ephemeral: | ||
self._initCells4() | ||
|
||
@classmethod | ||
def getSchema(cls): | ||
|
@@ -211,41 +213,44 @@ def read(cls, proto): | |
|
||
return obj | ||
|
||
def _initCells4(self): | ||
self.cells4 = Cells4(self.numberOfCols, | ||
self.cellsPerColumn, | ||
self.activationThreshold, | ||
self.minThreshold, | ||
self.newSynapseCount, | ||
self.segUpdateValidDuration, | ||
self.initialPerm, | ||
self.connectedPerm, | ||
self.permanenceMax, | ||
self.permanenceDec, | ||
self.permanenceInc, | ||
self.globalDecay, | ||
self.doPooling, | ||
self.seed, | ||
self.allocateStatesInCPP, | ||
self.checkSynapseConsistency) | ||
|
||
self.cells4.setVerbosity(self.verbosity) | ||
self.cells4.setPamLength(self.pamLength) | ||
self.cells4.setMaxAge(self.maxAge) | ||
self.cells4.setMaxInfBacktrack(self.maxInfBacktrack) | ||
self.cells4.setMaxLrnBacktrack(self.maxLrnBacktrack) | ||
self.cells4.setMaxSeqLength(self.maxSeqLength) | ||
self.cells4.setMaxSegmentsPerCell(self.maxSegmentsPerCell) | ||
self.cells4.setMaxSynapsesPerCell(self.maxSynapsesPerSegment) | ||
|
||
# Reset internal C++ pointers to states | ||
self._setStatePointers() | ||
|
||
|
||
def __setstate__(self, state): | ||
""" | ||
Set the state of ourself from a serialized state. | ||
""" | ||
super(BacktrackingTMCPP, self).__setstate__(state) | ||
if self.makeCells4Ephemeral: | ||
self.cells4 = Cells4(self.numberOfCols, | ||
self.cellsPerColumn, | ||
self.activationThreshold, | ||
self.minThreshold, | ||
self.newSynapseCount, | ||
self.segUpdateValidDuration, | ||
self.initialPerm, | ||
self.connectedPerm, | ||
self.permanenceMax, | ||
self.permanenceDec, | ||
self.permanenceInc, | ||
self.globalDecay, | ||
self.doPooling, | ||
self.seed, | ||
self.allocateStatesInCPP, | ||
self.checkSynapseConsistency) | ||
|
||
self.cells4.setVerbosity(self.verbosity) | ||
self.cells4.setPamLength(self.pamLength) | ||
self.cells4.setMaxAge(self.maxAge) | ||
self.cells4.setMaxInfBacktrack(self.maxInfBacktrack) | ||
self.cells4.setMaxLrnBacktrack(self.maxLrnBacktrack) | ||
self.cells4.setMaxSeqLength(self.maxSeqLength) | ||
self.cells4.setMaxSegmentsPerCell(self.maxSegmentsPerCell) | ||
self.cells4.setMaxSynapsesPerCell(self.maxSynapsesPerSegment) | ||
|
||
# Reset internal C++ pointers to states | ||
self._setStatePointers() | ||
self._initCells4() | ||
|
||
|
||
def _getEphemeralMembers(self): | ||
|
@@ -276,33 +281,7 @@ def _initEphemerals(self): | |
self.retrieveLearningStates = False | ||
|
||
if self.makeCells4Ephemeral: | ||
self.cells4 = Cells4(self.numberOfCols, | ||
self.cellsPerColumn, | ||
self.activationThreshold, | ||
self.minThreshold, | ||
self.newSynapseCount, | ||
self.segUpdateValidDuration, | ||
self.initialPerm, | ||
self.connectedPerm, | ||
self.permanenceMax, | ||
self.permanenceDec, | ||
self.permanenceInc, | ||
self.globalDecay, | ||
self.doPooling, | ||
self.seed, | ||
self.allocateStatesInCPP, | ||
self.checkSynapseConsistency) | ||
|
||
self.cells4.setVerbosity(self.verbosity) | ||
self.cells4.setPamLength(self.pamLength) | ||
self.cells4.setMaxAge(self.maxAge) | ||
self.cells4.setMaxInfBacktrack(self.maxInfBacktrack) | ||
self.cells4.setMaxLrnBacktrack(self.maxLrnBacktrack) | ||
self.cells4.setMaxSeqLength(self.maxSeqLength) | ||
self.cells4.setMaxSegmentsPerCell(self.maxSegmentsPerCell) | ||
self.cells4.setMaxSynapsesPerCell(self.maxSynapsesPerSegment) | ||
|
||
self._setStatePointers() | ||
self._initCells4() | ||
|
||
def saveToFile(self, filePath): | ||
""" | ||
|
@@ -315,6 +294,7 @@ def loadFromFile(self, filePath): | |
""" | ||
Load Cells4 state from a file saved with :meth:`saveToFile`. | ||
""" | ||
self._setStatePointers() | ||
self.cells4.loadFromFile(filePath) | ||
|
||
|
||
|
@@ -336,7 +316,7 @@ def __getattr__(self, name): | |
""" | ||
|
||
try: | ||
return super(BacktrackingTM, self).__getattr__(name) | ||
return super(BacktrackingTMCPP, self).__getattr__(name) | ||
except AttributeError: | ||
raise AttributeError("'TM' object has no attribute '%s'" % name) | ||
|
||
|
@@ -428,8 +408,8 @@ def _copyAllocatedStates(self): | |
assert False | ||
(activeT, activeT1, predT, predT1, colConfidenceT, colConfidenceT1, confidenceT, | ||
confidenceT1) = self.cells4.getStates() | ||
self.confidence['t-1'] = confidenceT1.reshape((self.numberOfCols, self.cellsPerColumn)) | ||
self.confidence['t'] = confidenceT.reshape((self.numberOfCols, self.cellsPerColumn)) | ||
self.cellConfidence['t'] = confidenceT.reshape((self.numberOfCols, self.cellsPerColumn)) | ||
self.cellConfidence['t-1'] = confidenceT1.reshape((self.numberOfCols, self.cellsPerColumn)) | ||
self.colConfidence['t'] = colConfidenceT.reshape(self.numberOfCols) | ||
self.colConfidence['t-1'] = colConfidenceT1.reshape(self.numberOfCols) | ||
self.infActiveState['t-1'] = activeT1.reshape((self.numberOfCols, self.cellsPerColumn)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this. Is it a workaround to allow a proto to contain a null value? I see this pattern in several other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a way to handle 'None' in pycapnp. You first create a union with a 'Void' element representing 'None' and then initialize it with 'None'
see https://jparyani.github.io/pycapnp/quickstart.html#unions