Python 3 Migration: _paramTypeCache not found

Again working on the and true for many other engine relation python code. I keep getting the error:

RuntimeError: Attribute _paramTypeCache not found

I understand that the _paramTypeCache is send to nupic.core’s engine_internal module in here.
What I’s struggling with is that I have no idea what to do with it. Am I suppose to cache it in the c++ region object? If yes, where would it be stored?

I have tried to read the swig code and also nupic.core c++ code but I cannot see what is going.

Any help is appreciated.

Maybe I should give more information to get a response.

Please consider the following python code:

# Create network
network = Network()

# Create cpp region
r = network.addRegion('consumptionSensor', 'ScalarSensor', json.dumps({'n': 120, 'w': 21, 'minValue': 0.0, 'maxValue': 100.0, 'clipInput': True}))

During addRegion a python Region object will be created. The class is defined in nupic\
The Region constructor tries to create a attribute called “_paramTypeCache”. For that Region’s __setattr__ is called which will forward the attribute to self._region, meaning into cpp space. It is here where I don’t understand what to do. I cannot find anything in the swig files nor in the cpp code.

Any help would be appreciated!


1 Like

Working on this today.

Now that I’ve had a chance to look at this, I don’ think _paramTypeCache needs to be expressed in C++ at all. It looks like just a python convenience to me. If you are getting an error running examples/network/ in python3, there may be some difference in how py3 deals with automatic setters and getters with underscore properties? I think you can ignore this property.

Thanks for your time Matt!

I’ll take closer look today. I might have just misunderstood the python and swig interaction.

Here is a bit more light. Consider this python code:

def createNetwork():
  network = Network()

  # Sensors

  # C++
  consumptionSensor = network.addRegion('consumptionSensor', 'ScalarSensor',
                                        json.dumps({'n': 120,
                                                    'w': 21,
                                                    'minValue': 0.0,
                                                    'maxValue': 100.0,
                                                    'clipInput': True}))

  # Python
  timestampSensor = network.addRegion("timestampSensor",
                                      'py.PluggableEncoderSensor', "")
  timestampSensor.getSelf().encoder = DateEncoder(timeOfDay=(21, 9.5),

  return network

In python 2.7 the two regions consumptionSensor and timestampSensor have this structure:

The internal attribute _region is a swig object which contains _paramTypeCache.

Now, we don’t have swig anymore and so the next step is to figure out how to emulate the current behavior with pybind11 and c++…

@scott I tried not to bother you on this, but I don’t think I can help at this point. Can you give this topic a quick read and chime in with your opinion?

The swig object is a Python class that, in this case, is storing some state. If you remove SWIG, the most analogous thing to do would be to have a Python class that plays the same role: stores the _paramTypeCache, has a reference to the C++, etc. I’m not familiar with pybind but one way to do it is take whatever the Python interface is to C++ and create a Python subclass of it that holds the _paramTypeCache.

I’m not sure if this makes sense so please let me know if I got something wrong here. The code is a bit of a mess and it isn’t clear to me why the cache is even needed (or how it avoids returning stale values) but in the sake of making progress I’d probably try to find a simple way to mimic the Python wrapper classes that SWIG generates.

1 Like