Commits

Michał Odnous  committed af64af2

Rosenbrock: Basic evaluator parts.

  • Participants
  • Parent commits bfddec7

Comments (0)

Files changed (2)

File 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
+
+
+class RosenbrockEvaluator(BaseHandler):
+    def __init__(self, local_mode=False, addresses=None, ports=None):
+        # Initialize communication,.
+        if local_mode:
+            print "Starting Evalutor in local mode."
+            self.comm = LocalServerComm(addresses=addresses)
+        else:
+            print "Starting Evalutor in network mode."
+            self.comm = NetworkServerComm(ports=ports)
+
+    def run(self):
+        self.comm.listen_forever(handler=self)

File examples/rosenbrock/run.py

+#!/usr/bin/env python
+import argparse
+from evaluator import RosenbrockEvaluator
+
+
+def main():
+    parser = argparse.ArgumentParser(description="Example Rosenbrock function"
+        " evaluator")
+    parser.add_argument("-local-mode", action="store_true", default=False)
+
+    local = parser.add_argument_group("Local mode")
+    local.add_argument("-local-pull-address", metavar="<address>",
+        dest="local_pull", type=str, help=u"Listening address of task manager")
+    local.add_argument("-local-publish-address", metavar="<address>",
+        dest="local_publish", type=str, help=u"Task result publishing address")
+
+    network = parser.add_argument_group("Network mode")
+    network.add_argument("-network-pull-port", metavar="<port>",
+        dest="network_pull", type=str, default="5558",
+        help=u"Listening port for task manager commands")
+    network.add_argument("-network-publish-port", metavar="<port>",
+        dest="network_publish", type=str, default="5559",
+        help=u"Listening port for task result broadcasting")
+
+    # Parse execution arguments.
+    args = parser.parse_args()
+
+    # Initialize evaluator and listen for commands.
+    e = RosenbrockEvaluator(local_mode=args.local_mode,
+        addresses=[args.local_pull, args.local_publish],
+        ports=[args.network_pull, args.network_publish])
+    e.run()
+
+
+if __name__ == '__main__':
+    main()