Mystery Error

Hi all, just wondering if anyone had any suggestions for getting around this error or what may be causing it. Thanks!!

RuntimeError: A pyRegion with name ‘AnomalyRegion’ already exists. Unregister the existing region or register the new region using a different name.

1 Like

Are you using the Network API directly? If so, is there a way to inspect your network and list the existing regions? (I honestly don’t know, I’ve not used the network api yet.)

Hey Matt! So I was trying to run the code (run.py) from within my python environment (Spyder), but I just got it working by running the same script from the shell! I’m not sure why it works this way and not the other and I would be curious, but mostly relieved for now =D

I’m not too surprised to see this error. Regions used to be hard coded and we switched to an extensible model where you can explicitly declare a new region type. But there are a certain set that get registered automatically. And we have seen cases where things accidentally get registered multiple times. I actually think we may want to change it so that is ok.

Can you share the command that you were running so we can try to reproduce?

Hey Scott,

So I actually got that error not from the command line but just by running it from within Spyder. It won’t let me attach a python file here so I’ll paste the code here if its of any use. Its the same ‘run.py’ from the hotgym example set to TemporalAnomaly and with a modified runModel function to create multiple models from multiple data sets. When I tried to run the same script from the command line instead I didn’t get any error.

– Sam

mypath = '/home/sheiser1/Desktop/zaychik_proj1-master/Dr_Zaychik_Data/selectedData'
file_list = [f for f in listdir(mypath) if isfile(join(mypath,f)) and os.path.splitext(f)[1] == '.csv']

def runModel(file_list, plot=False): #def runModel(gymName, plot=False):
  """
  Assumes the gynName corresponds to both a like-named model_params file in the
  model_params directory, and that the data exists in a like-named CSV file in
  the current directory.
  :param gymName: Important for finding model params and input CSV file
  :param plot: Plot in matplotlib? Don't use this unless matplotlib is
  installed.
  """
  for file1 in file_list:
    save = False
    file_name = os.path.splitext(file1)[0]
    path = '/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym$' + file_name
    model = None
    if os.path.exists(path):
      model = Model.load(path)
    else:
      model = createModel(getModelParamsFromName(GYM_NAME))
      save = True
    print "Creating model from %s..." % file_name
    inputData = "%s/%s.csv" % (DATA_DIR, file_name.replace(" ", "_"))
    runIoThroughNupic(inputData, model, file_name, plot)
    if save:
      model.save(path) 
    for file2 in file_list:
      file2_name = os.path.splitext(file2)[0]
      model.disableLearning()
      print "Running model: " + file_name + 'on: ' + file2_name
      inputData = "%s/%s.csv" % (DATA_DIR, file2_name.replace(" ", "_"))
      runIoThroughNupic(inputData, model, file2_name, plot)
      os.rename(file2_name + '_out.csv', file_name + '_' + file2_name + '_out.csv')

if __name__ == "__main__":
  print DESCRIPTION
  plot = False 
  new_model = False
  args = sys.argv[1:]
  if "--plot" in args:
    plot = True
  runModel(file_list, plot=plot)

Sorry for the delay. I can probably figure out the cause if I can reproduce the problem somehow. Do you know what line it is throwing the exception at? The Traceback might be enough to figure it out.

Hi Scott,

So here’s the error I’ve gotten. Oddly enough I didn’t see this when I ran the ‘run.py’ file from the command line, only when I tried to run it from within Spyder. I think this happens in line 128, within the ‘runIOThroughNupic’ function. If I can provide you with the data itself or anything else that might help let me know and you got it. Again I seem to be able to run it ok from the command line, so its not stopping me from moving forward, though I am curious if something is going haywire below my radar. Thanks again,

– Sam

>   File "<ipython-input-1-ba70c37d590f>", line 1, in <module>
>     runfile('/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym/run.py', wdir='/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym')

>   File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
>     execfile(filename, namespace)

>   File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
>     builtins.execfile(filename, *where)

>   File "/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym/run.py", line 190, in <module>
>     runModel(only_csv_files, plot=plot) #runModel(GYM_NAME, plot=plot)

>   File "/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym/run.py", line 164, in runModel
>     runIoThroughNupic(inputData, model, file_name, plot)

>   File "/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym/run.py", line 128, in runIoThroughNupic
>     "Error": consumption #"kw_energy_consumption": consumption

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/clamodel.py", line 390, in run
>     self._tpCompute()

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/clamodel.py", line 507, in _tpCompute
>     tp.compute()

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/engine/__init__.py", line 460, in compute
>     return self._region.compute()

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/bindings/engine_internal.py", line 1436, in compute
>     return _engine_internal.Region_compute(self)

> RuntimeError: Python exception raised. Unable to extract info


> In [2]: runfile('/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym/run.py', wdir='/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym')
> Reloaded modules: nupic.research.TP10X2, validictory, nupic.encoders.utils, nupic.encoders.geospatial_coordinate, nupic.research.monitor_mixin.metric, nupic.regions, nupic.encoders.base, nupic.data.jsonhelpers, nupic.encoders.logenc, nupic.support.fshelpers, nupic.encoders.category, nupic.encoders.delta, nupic.utils, nupic.frameworks.opf.two_gram_model, nupic.encoders.pass_through_encoder, nupic.frameworks.opf.CLAModelProto_capnp, nupic.research.fdrutilities, nupic.encoders.sdrcategory, nupic.frameworks.opf, nupic.frameworks.opf.opfutils, nupic.regions.KNNClassifierRegion, nupic.encoders.multi, nupic.algorithms.sdr_classifier, nupic.research.spatial_pooler, nupic.encoders, nupic.encoders.date, nupic.support.consoleprinter, nupic.data.inference_shifter, nupic.regions.TPRegion, nupic.research.TP, nupic.algorithms.sdr_classifier_factory, nupic_anomaly_output, nupic.regions.SDRClassifierRegion_capnp, nupic.research.monitor_mixin, nupic.support.configuration_custom, nupic.algorithms, _engine_internal, capnp.lib, nupic.encoders.scalar, nupic.engine, _algorithms, nupic.algorithms.anomaly, nupic.frameworks.opf.clamodel, nupic.bindings.regions, nupic.encoders.record_sensor_capnp, nupic.regions.SPRegion_capnp, nupic.research.monitor_mixin.monitor_mixin_base, nupic.frameworks.opf.previousvaluemodel, nupic.frameworks.opf.modelfactory, capnp.version, nupic.regions.SDRClassifierRegion, nupic.data, nupic.support.configuration_base, nupic.data.fieldmeta, nupic.encoders.adaptivescalar, _math, nupic.encoders.scalarspace, nupic.bindings.regions.PyRegion, nupic.support.lockattributes, pyproj, nupic.bindings, nupic.encoders.sparse_pass_through_encoder, nupic.research.temporal_memory, nupic.data.functionsource, nupic.regions.RecordSensor, nupic.math, pyproj._proj, capnp, nupic.research.TP_shim, nupic.frameworks, nupic.support, nupic.research.monitor_mixin.plot, nupic.encoders.random_distributed_scalar, nupic.research.connections, nupic.encoders.coordinate, prettytable, nupic.regions.KNNAnomalyClassifierRegion, nupic.research.monitor_mixin.temporal_memory_monitor_mixin, nupic.frameworks.opf.model, pyproj.datadir, nupic.support.enum, nupic.frameworks.opf.exceptions, nupic.bindings.math, nupic.research.monitor_mixin.trace, nupic.algorithms.KNNClassifier, validictory.validator, nupic.regions.SPRegion, nupic.bindings.engine_internal, nupic.research, capnp.lib.capnp, nupic.support.configuration, nupic.algorithms.anomaly_likelihood, nupic.bindings.algorithms, nupic.support.group_by
> Traceback (most recent call last):

>   File "<ipython-input-2-ba70c37d590f>", line 1, in <module>
>     runfile('/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym/run.py', wdir='/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym')

>   File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
>     execfile(filename, namespace)

>   File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
>     builtins.execfile(filename, *where)

>   File "/home/sheiser1/nupic/examples/opf/clients/hotgym/anomaly/one_gym/run.py", line 36, in <module>
>     from nupic.frameworks.opf.modelfactory import ModelFactory

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/modelfactory.py", line 32, in <module>
>     from clamodel import CLAModel

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/clamodel.py", line 44, in <module>
>     from nupic.engine import Network

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/engine/__init__.py", line 78, in <module>
>     registerBuiltInRegions()

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/engine/__init__.py", line 74, in registerBuiltInRegions
>     engine.Network.registerPyRegion(module, className)

>   File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/bindings/engine_internal.py", line 1196, in registerPyRegion
>     return _engine_internal.Network_registerPyRegion(*args, **kwargs)

> RuntimeError: A pyRegion with name 'AnomalyRegion' already exists. Unregister the existing region or register the new region using a different name.

That is odd. It almost seems like nupic/engine/init.py is being imported multiple times but that should be impossible inside the same Python process. Perhaps this is a Spyder-specific thing or perhaps that isn’t what is happening. Regardless, I think we should allow regions to be registered multiple times as long as the import paths match. I created an issue for that here:
https://github.com/numenta/nupic.core/issues/1194

That wouldn’t help if somehow AnomalyRegion exists in multiple absolute-path locations but that would be a separate and probably fixable problem.

That probably isn’t a very satisfying answer but I’m not familiar with Spyder and, unfortunately, won’t have time to investigate Spyder-specific issues. I think we should try to get #1194 fixed and push a new version. With the holidays, that might not happen right away though.

1 Like