def run_simple():
    """ create a ZMQServer for simple model, run & query it
    """
    server_id = "OptimizationUnconstrained"
    classpath = "openmdao.examples.simple.optimization_unconstrained.OptimizationUnconstrained"
    mgr = ZMQServerManager(classpath)
    srv = mgr.server(server_id)
    if srv is not None:
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector("OPT OUT", out_url, "OptimizationUnconstrained.out")
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector("OPT PUB", pub_url, "OptimizationUnconstrained.pub")
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        srv.dir()
        srv.register_published_vars(["paraboloid.x", "paraboloid.y", "paraboloid.f_xy"])
        srv.run()

        print "x =", srv.get("paraboloid.x")
        print "y =", srv.get("paraboloid.y")
        print "f_xy =", srv.get("paraboloid.f_xy")

        time.sleep(15)  # give it time to finish
        mgr.delete_server("OptimizationUnconstrained")
        out_rdr.terminate()
        pub_rdr.terminate()
 def setUp(self):
     self.server_mgr = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')
     self.cserver = self.server_mgr.server('test')
     
     out_url = self.server_mgr.get_out_socket_url('test')
     self.out_rdr = OutStreamRedirector('OUT',out_url,'test.out')
     self.out_rdr.start()
         
     pub_url = self.server_mgr.get_pub_socket_url('test')
     self.pub_rdr = OutStreamRedirector('PUB',pub_url,'test.pub')
     self.pub_rdr.start()
     
     time.sleep(2)   # give them time to start up 
def run_cserver():
    """ create a ZMQ-based console server & exercise it
    """
    server_id = "ConsoleServer"
    classpath = "openmdao.gui.consoleserver.ConsoleServer"
    mgr = ZMQServerManager(classpath)
    cserver = mgr.server(server_id)
    if cserver is not None:
        print "=============================================================="
        print "================= started cserver ============================"
        print "=============================================================="
        # print cserver.onecmd("!!!!!!!!!!!!!!!!!!!  I'm Alive   !!!!!!!!!!!!!")
        print cserver.getcwd()
        # print 'types:'
        # print cserver.get_available_types()

        print "=============================================================="
        print "================= redirecting streams ========================"
        print "=============================================================="
        # subscriber to the cserver output & print to stdout
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector("CSERVER OUT", out_url, "cserver.out")
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector("CSERVER PUB", pub_url, "cserver.pub")
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        print "=============================================================="
        print "================ load project ================================"
        print "=============================================================="
        path = os.path.dirname(os.path.abspath(__file__))
        proj_file = os.path.join(path, "sellar.proj")
        print cserver.load_project(proj_file)
        print_dict(cserver.get_files())

        print "=============================================================="
        print "================ import from  file ==========================="
        print "=============================================================="
        print cserver.onecmd("from sellar_CO import SellarCO")
        print_dict(cserver.get_workingtypes())
        # print cserver.onecmd('trace')

        print "=============================================================="
        print "=============== execute script to set up the problem ========="
        print "=============================================================="
        script = """
top = SellarCO()
top.z1_t = 5.0
top.dis1.z1 = 5.0
top.dis2.z1 = 5.0

top.z2_t = 2.0
top.dis1.z2 = 2.0
top.dis2.z2 = 2.0

top.x1_t = 1.0
top.dis1.x1 = 1.0

top.y1_t = 3.16
top.y2_t = 0.0
top.dis1.y2 = 0.0
top.dis2.y1 = 3.16
"""
        cserver.onecmd(script)
        # print cserver.onecmd('trace')

        print cserver.onecmd("print dir(top)")
        print_json(cserver.get_structure(""))
        print_json(cserver.get_workflow("top"))
        print cserver.get_value("top.dis1.z1")
        print cserver.get_value("top.dis1.z2")
        print cserver.get_value("top.dis1.x1")

        print "=============================================================="
        print "================= register published vars and run ============"
        print "=============================================================="
        cserver.onecmd("top.register_published_vars(['dis1.z1', 'dis1.z2', 'dis1.x1'])")
        cserver.run()

        print "=============================================================="
        print "================ get results ================================="
        print "=============================================================="
        print cserver.onecmd("trace")
        print cserver.get_value("top.dis1.z1")
        print cserver.get_value("top.dis1.z2")
        print cserver.get_value("top.dis1.x1")

        print "=============================================================="
        print "================ delete server ==============================="
        print "=============================================================="
        time.sleep(15)  # give it time to finish
        mgr.delete_server(server_id)
        out_rdr.terminate()
        pub_rdr.terminate()
Example #4
0
def run_cserver():
    ''' create a ZMQ-based console server & exercise it
    '''
    server_id = 'ConsoleServer'
    classpath = 'openmdao.gui.consoleserver.ConsoleServer'
    mgr = ZMQServerManager(classpath)
    cserver = mgr.server(server_id)
    if cserver is not None:
        print '=============================================================='
        print '================= started cserver ============================'
        print '=============================================================='
        #print cserver.onecmd("!!!!!!!!!!!!!!!!!!!  I'm Alive   !!!!!!!!!!!!!")
        print cserver.getcwd()
        #print 'types:'
        #print cserver.get_available_types()

        print '=============================================================='
        print '================= redirecting streams ========================'
        print '=============================================================='
        # subscriber to the cserver output & print to stdout
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector('CSERVER OUT', out_url, 'cserver.out')
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector('CSERVER PUB', pub_url, 'cserver.pub')
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        print '=============================================================='
        print '================ load project ================================'
        print '=============================================================='
        path = os.path.dirname(os.path.abspath(__file__))
        proj_file = os.path.join(path, 'sellar.proj')
        print cserver.load_project(proj_file)
        print_dict(cserver.get_files())

        print '=============================================================='
        print '================ import from  file ==========================='
        print '=============================================================='
        print cserver.onecmd('from sellar_CO import SellarCO')
        print_dict(cserver.get_workingtypes())
        #print cserver.onecmd('trace')

        print '=============================================================='
        print '=============== execute script to set up the problem ========='
        print '=============================================================='
        script = """
top = SellarCO()
top.z1_t = 5.0
top.dis1.z1 = 5.0
top.dis2.z1 = 5.0

top.z2_t = 2.0
top.dis1.z2 = 2.0
top.dis2.z2 = 2.0

top.x1_t = 1.0
top.dis1.x1 = 1.0

top.y1_t = 3.16
top.y2_t = 0.0
top.dis1.y2 = 0.0
top.dis2.y1 = 3.16
"""
        cserver.onecmd(script)
        #print cserver.onecmd('trace')

        print cserver.onecmd('print dir(top)')
        print_json(cserver.get_structure(''))
        print_json(cserver.get_workflow('top'))
        print cserver.get_value('top.dis1.z1')
        print cserver.get_value('top.dis1.z2')
        print cserver.get_value('top.dis1.x1')

        print '=============================================================='
        print '================= register published vars and run ============'
        print '=============================================================='
        cserver.onecmd(
            "top.register_published_vars(['dis1.z1', 'dis1.z2', 'dis1.x1'])")
        cserver.run()

        print '=============================================================='
        print '================ get results ================================='
        print '=============================================================='
        print cserver.onecmd('trace')
        print cserver.get_value('top.dis1.z1')
        print cserver.get_value('top.dis1.z2')
        print cserver.get_value('top.dis1.x1')

        print '=============================================================='
        print '================ delete server ==============================='
        print '=============================================================='
        time.sleep(15)  # give it time to finish
        mgr.delete_server(server_id)
        out_rdr.terminate()
        pub_rdr.terminate()
Example #5
0
def run_simple():
    ''' create a ZMQServer for simple model, run & query it
    '''
    server_id = 'OptimizationUnconstrained'
    classpath = 'openmdao.examples.simple.optimization_unconstrained.OptimizationUnconstrained'
    mgr = ZMQServerManager(classpath)
    srv = mgr.server(server_id)
    if srv is not None:
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector('OPT OUT', out_url,
                                      'OptimizationUnconstrained.out')
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector('OPT PUB', pub_url,
                                      'OptimizationUnconstrained.pub')
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        srv.dir()
        srv.register_published_vars(
            ['paraboloid.x', 'paraboloid.y', 'paraboloid.f_xy'])
        srv.run()

        print 'x =', srv.get('paraboloid.x')
        print 'y =', srv.get('paraboloid.y')
        print 'f_xy =', srv.get('paraboloid.f_xy')

        time.sleep(15)  # give it time to finish
        mgr.delete_server('OptimizationUnconstrained')
        out_rdr.terminate()
        pub_rdr.terminate()
class test_cserver(unittest.TestCase):
    
    def setUp(self):
        self.server_mgr = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')
        self.cserver = self.server_mgr.server('test')
        
        out_url = self.server_mgr.get_out_socket_url('test')
        self.out_rdr = OutStreamRedirector('OUT',out_url,'test.out')
        self.out_rdr.start()
            
        pub_url = self.server_mgr.get_pub_socket_url('test')
        self.pub_rdr = OutStreamRedirector('PUB',pub_url,'test.pub')
        self.pub_rdr.start()
        
        time.sleep(2)   # give them time to start up 

    def test_conmin(self):
        div = '-'*70
        
        print div
        print 'LOAD PROJECT'
        path = os.path.dirname(os.path.abspath(__file__))
        self.cserver.load_project(os.path.join(path,'simple_1.proj'))
            
        print div
        print 'CHECK FILES (note paraboloid.py defining Paraboloid)'
        print_dict(self.cserver.get_files())
        
        print div
        print 'IMPORT PARABOLOID'
        self.cserver.onecmd('from paraboloid import Paraboloid')

        print div
        print 'WORKING TYPES'
        print_dict(self.cserver.get_workingtypes())

        print div
        print 'CREATE ASSEMBLY'
        print self.cserver.add_component('prob','openmdao.main.assembly.Assembly','');
        
        print div
        print 'COMPONENTS'
        print_json(self.cserver.get_components())
        
        print div
        print 'ADD CONMIN DRIVER'
        print self.cserver.add_component('driver',
           'openmdao.lib.drivers.conmindriver.CONMINdriver','prob');
        
        print div
        print 'CHECK DRIVER ATTRIBUTES'
        print_json(self.cserver.get_attributes('prob.driver'))

        print div
        print 'CREATE PARABOLOID'
        self.cserver.add_component('p','Paraboloid','prob');
        
        print div
        print 'COMPONENTS'
        print_json(self.cserver.get_components())

        print div
        print 'STRUCTURE'
        print print_json(self.cserver.get_structure('prob'))

        print div
        print 'dir()'
        print self.cserver.onecmd('dir()')
        
    def tearDown(self):
        time.sleep(2)
        self.out_rdr.terminate()
        self.pub_rdr.terminate()
        self.cserver.terminate()