Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Created simple_server example for running a basic NuPIC model api #2213

Merged
merged 6 commits into from Jul 21, 2015

Conversation

jaredweiss
Copy link
Contributor

fixes #2212
Created a basic server for trying out NuPIC models with an easy to use api

@jaredweiss jaredweiss changed the title Created simple_server example for running a basic NuPIC model api (fixes #2212) Created simple_server example for running a basic NuPIC model api Jun 12, 2015

MODEL_PARAMS = {
# Type of model that the rest of these parameters apply to.
'model': "CLA",
Copy link
Member

Choose a reason for hiding this comment

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

can you just import the model params from the hotgym example file? to avoid duplication

Copy link
Member

Choose a reason for hiding this comment

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

I don't really mind having duplicate model params within example code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Examples aren't on the PYTHONPATH so importing between them is hacky at best. I think it is a good idea to share the suggested parameters though. @tomsilver added something similar for making standard network configurations reusable:
https://github.com/numenta/nupic/blob/master/nupic/engine/common_networks/__init__.py

@rhyolight
Copy link
Member

👍




g_models = {}
Copy link
Member

Choose a reason for hiding this comment

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

if #1929 gets merged, this can be simplified

@rhyolight
Copy link
Member

@scottpurdy Did you see this? There is a use-case in this PR for @breznak's global dict in #1929. @jaredweiss is keeping a g_models variable to keep track of models, which would not be necessary if #1929 were merged.

@scottpurdy
Copy link
Contributor

@rhyolight @breznak - What benefit is there from GlobalDict instead of a regular dict? It seems like that just adds another dependency and uses a custom class that people reading the code may not know about.

@jaredweiss
Copy link
Contributor Author

Any update on the g_models issue?

#!/usr/bin/env python
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
Copy link
Contributor

Choose a reason for hiding this comment

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

year

@breznak
Copy link
Member

breznak commented Jun 30, 2015

@jaredweiss ad g_models my POW #1929 (comment)

@@ -0,0 +1,247 @@

# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
Copy link
Contributor

Choose a reason for hiding this comment

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

year

@rhyolight
Copy link
Member

@jaredweiss I would say proceed with g_models for now.

@rhyolight
Copy link
Member

@jaredweiss ping

@scottpurdy
Copy link
Contributor

@jaredweiss - Please ping me when you're ready for me to look again

@jaredweiss
Copy link
Contributor Author

@scottpurdy It looks done to me but I'm still having that import error when I try to run the server from the directory it's in. Outside the directory it works fine. I think its got something to do with swig.

@scottpurdy
Copy link
Contributor

What's the exception message?

@jaredweiss
Copy link
Contributor Author

ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
  File "./nupic/simple_server.py", line 28, in <module>
    import web
  File "/Users/jweiss/Library/Python/2.7/lib/python/site-packages/web.py-0.37-py2.7.egg/web/__init__.py", line 14, in <module>
    import utils, db, net, wsgi, http, webapi, httpserver, debugerror
  File "/Users/jweiss/Library/Python/2.7/lib/python/site-packages/web.py-0.37-py2.7.egg/web/wsgi.py", line 8, in <module>
    import http
  File "/Users/jweiss/Library/Python/2.7/lib/python/site-packages/web.py-0.37-py2.7.egg/web/http.py", line 16, in <module>
    import net, utils, webapi as web
  File "/Users/jweiss/Library/Python/2.7/lib/python/site-packages/web.py-0.37-py2.7.egg/web/webapi.py", line 31, in <module>
    import sys, cgi, Cookie, pprint, urlparse, urllib
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cgi.py", line 41, in <module>
    import mimetools
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
    from random import Random as _Random
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 45, in <module>
    from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
  File "/Users/jweiss/nta/nupic/nupic/math/__init__.py", line 53, in <module>
    from nupic.bindings.math import (GetNTAReal,
  File "/Users/jweiss/nta/nupic/nupic/bindings/math.py", line 28, in <module>
    _math = swig_import_helper()
  File "/Users/jweiss/nta/nupic/nupic/bindings/math.py", line 24, in swig_import_helper
    _mod = imp.load_module('_math', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import

@scottpurdy
Copy link
Contributor

@jaredweiss - When you are in the nupic module then anything that does import math will import nupic.math instead of the builtin module. Normally you would run things from somewhere outside the nupic package and it wouldn't be a problem. To avoid confusion if someone runs it from inside, we can do the following:

  • Check if we are running from the directory that simple_server is in and if so then change the current working directory to be one level higher. This has to happen before the imports
  • Print a warning if we change the directory. The directory change only affects that process but it is good to print a warning just in case
  • Make sure that simple_server isn't affected by the directory it is run from

@scottpurdy
Copy link
Contributor

For avoiding the import error, do something like this, after copyright header and doc string but before the first import:

...end of module doc string ...
"""

# To avoid relative import of math module, ensure we don't run from this
# directory. This must be done before importing the web package.
import os
if os.getcwd() == os.path.dirname(os.path.realpath(__file__)):
  os.chdir(os.path.join(os.getcwd(), ".."))

import first_import

…ix 'import web' when simple_server was run from within nupic directory.
@jaredweiss
Copy link
Contributor Author

@scottpurdy ping

@jaredweiss
Copy link
Contributor Author

@scottpurdy Ping! Not sure if you've looked over my most recent commit yet.



if __name__ == "__main__":
parser = OptionParser()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend argparse which is replacing optparse but let's not hold up this example

scottpurdy added a commit that referenced this pull request Jul 21, 2015
Created simple_server example for running a basic NuPIC model api
@scottpurdy scottpurdy merged commit 5bc16fd into numenta:master Jul 21, 2015
mihail911 pushed a commit to mihail911/nupic that referenced this pull request Aug 5, 2015
Created simple_server example for running a basic NuPIC model api
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add simple HTTP server tool as model interface
4 participants