I have an instance of an OPF model (the same one used in the numenta detector in NAB, actually) that I’d like to make a deep copy of in my code. The simplest solution (trying “model_copy = copy.deepcopy(model)”) does not work. When trying to do model_copy.run(), it breaks because self.__restoringFromState gets set to true inside model_copy which doesn’t pass an assert statement.
Could somebody explain or point me in the direction of documentation which explains how to make deep copies of models?
Thanks for the quick responses…I have to create and load many copies and unfortunately writing to the file system is exceedingly slow. I’m going to keep trying to deep copy a model all within memory.
I notice the eq method is not overwritten in the base model class or the htm_prediction_model. Is there any code out there to test equality between two model instances?
I think you can probably use the new or old serialization completely in memory. The old method requires separate steps for the Python state (pickle) and C++ state so the new method is probably easier (and faster).
For the new method, you can see how to do an in-memory copy here:
And you probably want to save the result of builderProto.to_bytes() into a variable that you can call from_bytes on multiple times to create multiple copies of the model.
Excellent. You’re right, that method is much faster. For determining equality I’m just checking that they are giving the same output over time which is the case. Thanks so much for your help.