Michał Odnous avatar Michał Odnous committed 30673aa

Rewind: Basic evaluator skeleton without PyHO dependencies.

Comments (0)

Files changed (1)

examples/rosenbrock/evaluator.py

-# Communication classes from PyHO.
-from pyho.common.communication import LocalServerComm, NetworkServerComm
-# Skeleton class for evaluator.
-from pyho.common.communication import BaseHandler
+u"""
+    An implementation of basic evaluator using Rosenbrock function.
+    This example doesn't depend on PyHO libraries -- it's meant to
+    be a standalone testing tool.
+"""
+import zmq
 
 
-class RosenbrockEvaluator(BaseHandler):
+# A ZeroMQ global context.
+ctx = zmq.Context()
+
+
+# PyHO protocol: message types.
+class MessageType(object):
+    GET_OPTIONS = 1
+    RESP_OPTIONS = 101
+    EVALUATE = 2
+    RESP_SCORE = 102
+    GET_STATS = 3
+    RESP_STATS = 103
+    SAVE_OUTPUT = 4
+    RESP_SAVE = 104
+
+
+class RosenbrockEvaluator(object):
+    NUM_PARAMS = 2
+    # Default constraints for params.
+    CONSTRAINTS = [
+        [-100., 100.],
+        [-100., 100.],
+    ]
+
     def __init__(self, local_mode=False, addresses=None, ports=None):
-        # Initialize communication,.
+        # Set up communication.
+        # ZMQ socket listening for commands.
+        self.listener = ctx.socket(zmq.PULL)
+        # ZMQ socket publishing results.
+        self.publisher = ctx.socket(zmq.PUB)
+        # Depending on the mode connect to a node or start listening.
+        print "Starting Rosenbrock evalutor",
         if local_mode:
-            print "Starting Evalutor in local mode."
-            self.comm = LocalServerComm(addresses=addresses)
+            print "in local mode."
+            self.listener.connect(addresses[0])
+            self.publisher.connect(addresses[1])
         else:
-            print "Starting Evalutor in network mode."
-            self.comm = NetworkServerComm(ports=ports)
+            print "in network mode."
+            self.listener.bind("tcp://*:%s" % ports[0])
+            self.publisher.bind("tcp://*:%s" % ports[1])
 
     def run(self):
-        self.comm.listen_forever(handler=self)
+        print "Started"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.