Ejemplo n.º 1
0
    def test_netcdf_input(self):
        engine = Coordinator()


        args = dict(ncpath = './TWDEF_distributed/prcp.nc',
                    tdim = 'time',
                    xdim = 'x',
                    ydim = 'y',
                    tunit = 'hours',
                    starttime = '10-26-2015 00:00:00',
                    type = wrappers.Types.NETCDF)



        # add the WaterOneFlow component to the engine
        engine.add_model(id=1234, attrib=args)

        # load ueb component
        mdl = '../ueb.mdl'
        args = dict(mdl = mdl)
        # config_params = parse_config(mdl)
        engine.add_model(id=1235, attrib=args)

        # assert that the models have been added correctly
        models = engine.get_all_models()
        self.assertTrue(len(models) == 2)

        spatial_interpolation = space.spatial_nearest_neighbor()


         # add a link from NetCDF to UEB
        netcdf = engine.get_output_exchange_items_summary(id=1234)
        ueb = engine.get_input_exchange_items_summary(id=1235)
        engine.add_link(from_id=1234, from_item_id = netcdf[0]['name'],
                        to_id=1235, to_item_id = ueb[0]['name'],
                        spatial_interp=spatial_interpolation,
                        temporal_interp=None,
                        uid=None)

        links = engine.get_all_links()
        self.assertTrue(len(links) == 1)

        # run the simulation
        engine.run_simulation()



        print 'done'
Ejemplo n.º 2
0
    def test_netcdf_input(self):
        engine = Coordinator()

        args = dict(ncpath='./TWDEF_distributed/prcp.nc',
                    tdim='time',
                    xdim='x',
                    ydim='y',
                    tunit='hours',
                    starttime='10-26-2015 00:00:00',
                    type=wrappers.Types.NETCDF)

        # add the WaterOneFlow component to the engine
        engine.add_model(id=1234, attrib=args)

        # load ueb component
        mdl = '../ueb.mdl'
        args = dict(mdl=mdl)
        # config_params = parse_config(mdl)
        engine.add_model(id=1235, attrib=args)

        # assert that the models have been added correctly
        models = engine.get_all_models()
        self.assertTrue(len(models) == 2)

        spatial_interpolation = space.spatial_nearest_neighbor()

        # add a link from NetCDF to UEB
        netcdf = engine.get_output_exchange_items_summary(id=1234)
        ueb = engine.get_input_exchange_items_summary(id=1235)
        engine.add_link(from_id=1234,
                        from_item_id=netcdf[0]['name'],
                        to_id=1235,
                        to_item_id=ueb[0]['name'],
                        spatial_interp=spatial_interpolation,
                        temporal_interp=None,
                        uid=None)

        links = engine.get_all_links()
        self.assertTrue(len(links) == 1)

        # run the simulation
        engine.run_simulation()

        print 'done'
Ejemplo n.º 3
0
class testWofSimulation(unittest.TestCase):


    def setUp(self):
        self.engine = Coordinator()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = DebugListener()

        self.engine = Coordinator()
        PrintTarget.CONSOLE = 1134

        self.basepath = os.path.dirname(__file__)

    def tearDown(self):
        pass


    def test_wof_feedforward(self):

        args = dict(network='iutah',
                    site='LR_WaterLab_AA',
                    variable='RH_enc',
                    start=datetime.datetime(2015, 10, 26, 0, 0, 0),
                    end=datetime.datetime(2015, 10, 30, 0, 0, 0),
                    wsdl='http://data.iutahepscor.org/LoganRiverWOF/cuahsi_1_1.asmx?WSDL',
                    type=wrappers.Types.WOF)


        # add the WaterOneFlow component to the engine
        m1 = self.engine.add_model(id=1234, **args)
        self.assertTrue(m1)


        # load a test component
        multiplier_mdl = os.path.join(self.basepath, '../../app_data/models/multiplier/multiplier.mdl')
        args = dict(mdl=multiplier_mdl)
        m2 = self.engine.add_model(id=1235, attrib=args)
        self.assertTrue(m1)

        # assert that the models have been added correctly
        models = self.engine.get_all_models()
        self.assertTrue(len(models) == 2)

        # add a link from WaterOneFlow to multiplier
        wof_oei =  self.engine.get_exchange_item_info(modelid=1234, eitype=stdlib.ExchangeItemType.OUTPUT)
        mul_iei =  self.engine.get_exchange_item_info(modelid=1235, eitype=stdlib.ExchangeItemType.INPUT)
        self.engine.add_link(from_id=1234, from_item_id=wof_oei[0]['name'],
                             to_id=1235, to_item_id=mul_iei[0]['name'],
                             spatial_interp=None,
                             temporal_interp=None,
                             uid=None)

        links = self.engine.get_all_links()
        self.assertTrue(len(links) == 1)


        # run the simulation
        self.engine.run_simulation()

        status = stdlib.Status.UNDEFINED
        while status != stdlib.Status.FINISHED and status != stdlib.Status.ERROR:
            status = self.engine.get_status()
            time.sleep(1)

        # check that output data was generated
        m = self.engine.get_model_by_id(id = 1235)

        values = m.instance().outputs()['multipliedValue'].getValues2()
        self.assertTrue(len(values) > 0)
        self.assertTrue(values[0] != 0)
Ejemplo n.º 4
0
class test_link_order(unittest.TestCase):

    def setUp(self):

        # initialize environment variables
        environment.getEnvironmentVars()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()

        self.engine = Coordinator()
        sprint.PrintTarget.CONSOLE = 1134

        self.g = n.DiGraph()

    def tearDown(self):
        del self.g

    def test_determine_execution_order(self):

        # add models
        mdl1 = '../data/randomizer.mdl'
        mdl2 = '../data/multiplier.mdl'

        # add both models.  ids can be anything
        id1 = 'm1'
        id2 = 'm2'
        m1 = self.engine.add_model(id=id1, attrib={'mdl': mdl1})
        m2 = self.engine.add_model(id=id2, attrib={'mdl': mdl2})
        self.assertTrue(m1)
        self.assertTrue(m2)
        self.assertTrue(len(self.engine.Models()) == 2)

        # create link
        rand_oei =  self.engine.get_exchange_item_info(modelid=id1, eitype=stdlib.ExchangeItemType.OUTPUT)
        mult_iei = self.engine.get_exchange_item_info(modelid=id2, eitype=stdlib.ExchangeItemType.INPUT)
        self.engine.add_link(from_id=id1, from_item_id=rand_oei[0]['name'],
                             to_id=id2, to_item_id=mult_iei[0]['name'],
                             spatial_interp=None,
                             temporal_interp=None,
                             uid=None)

        self.assertTrue(len(self.engine.get_all_links()) == 1)


        # get execution order
        order = self.engine.determine_execution_order()

        self.assertTrue(''.join(order) == 'm1m2')

    def test_basic(self):
        """

        m1 -> m2 -> m3 -> m4 -> m5 -> m6
        """

        # add some edges to simulate links
        self.g.add_edge('m1','m2')
        self.g.add_edge('m2','m3')
        self.g.add_edge('m3','m4')
        self.g.add_edge('m4','m5')
        self.g.add_edge('m5','m6')

        order = n.topological_sort(self.g)

        self.assertTrue(''.join(order) == 'm1m2m3m4m5m6')


    def test_simple_tree(self):
        """
              m1 -> m2
                        -> m3
        m6 -> m5 -> m4
        """
        self.g.add_edge('m1','m2')
        self.g.add_edge('m2','m3')

        self.g.add_edge('m6','m5')
        self.g.add_edge('m5','m4')
        self.g.add_edge('m4','m3')


        order = n.topological_sort(self.g)

        self.assertTrue(''.join(order) == 'm1m2m6m5m4m3')

    def test_loop(self):
        """

        m6 -> m5 -> m4 \
        ^               \
        |                -> m3
         <- |m1| -> m2 /

        """

        self.g.add_edge('m1','m2')
        self.g.add_edge('m1','m6')

        self.g.add_edge('m2','m3')
        self.g.add_edge('m6','m5')
        self.g.add_edge('m5','m4')
        self.g.add_edge('m4','m3')

        order = n.topological_sort(self.g)

        self.assertTrue(''.join(order) == 'm1m2m6m5m4m3')

    def test_bidirectional(self):
        """
         m1 <-> m2 -> m3

        """


        self.g.add_edge('m1','m2')
        self.g.add_edge('m2','m3')
        self.g.add_edge('m3','m2')
        self.g.add_edge('m3','m4')

        # remove any models that done have links
        #for

        # determine cycles
        cycles = n.recursive_simple_cycles(self.g)
        for cycle in cycles:
            # remove edges that form cycles
            self.g.remove_edge(cycle[0],cycle[1])

        # perform toposort
        order = n.topological_sort(self.g)

        # re-add bidirectional dependencies (i.e. cycles)
        for cycle in cycles:
            # find index of inverse link
            for i in xrange(0,len(order)-1):
                if order[i] == cycle[1] and order[i+1] == cycle[0]:
                    order.insert(i+2, cycle[1])
                    order.insert(i+3,cycle[0])
                    break

        self.assertTrue(''.join(order) == 'm1m2m3m2m3m4')
Ejemplo n.º 5
0
class test_link_order(unittest.TestCase):
    def setUp(self):

        # initialize environment variables
        environment.getEnvironmentVars()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()

        self.engine = Coordinator()
        sprint.PrintTarget.CONSOLE = 1134

        self.g = n.DiGraph()

    def tearDown(self):
        del self.g

    def test_determine_execution_order(self):

        # add models
        mdl1 = '../data/randomizer.mdl'
        mdl2 = '../data/multiplier.mdl'

        # add both models.  ids can be anything
        id1 = 'm1'
        id2 = 'm2'
        m1 = self.engine.add_model(id=id1, attrib={'mdl': mdl1})
        m2 = self.engine.add_model(id=id2, attrib={'mdl': mdl2})
        self.assertTrue(m1)
        self.assertTrue(m2)
        self.assertTrue(len(self.engine.Models()) == 2)

        # create link
        rand_oei = self.engine.get_exchange_item_info(
            modelid=id1, eitype=stdlib.ExchangeItemType.OUTPUT)
        mult_iei = self.engine.get_exchange_item_info(
            modelid=id2, eitype=stdlib.ExchangeItemType.INPUT)
        self.engine.add_link(from_id=id1,
                             from_item_id=rand_oei[0]['name'],
                             to_id=id2,
                             to_item_id=mult_iei[0]['name'],
                             spatial_interp=None,
                             temporal_interp=None,
                             uid=None)

        self.assertTrue(len(self.engine.get_all_links()) == 1)

        # get execution order
        order = self.engine.determine_execution_order()

        self.assertTrue(''.join(order) == 'm1m2')

    def test_basic(self):
        """

        m1 -> m2 -> m3 -> m4 -> m5 -> m6
        """

        # add some edges to simulate links
        self.g.add_edge('m1', 'm2')
        self.g.add_edge('m2', 'm3')
        self.g.add_edge('m3', 'm4')
        self.g.add_edge('m4', 'm5')
        self.g.add_edge('m5', 'm6')

        order = n.topological_sort(self.g)

        self.assertTrue(''.join(order) == 'm1m2m3m4m5m6')

    def test_simple_tree(self):
        """
              m1 -> m2
                        -> m3
        m6 -> m5 -> m4
        """
        self.g.add_edge('m1', 'm2')
        self.g.add_edge('m2', 'm3')

        self.g.add_edge('m6', 'm5')
        self.g.add_edge('m5', 'm4')
        self.g.add_edge('m4', 'm3')

        order = n.topological_sort(self.g)

        self.assertTrue(''.join(order) == 'm1m2m6m5m4m3')

    def test_loop(self):
        """

        m6 -> m5 -> m4 \
        ^               \
        |                -> m3
         <- |m1| -> m2 /

        """

        self.g.add_edge('m1', 'm2')
        self.g.add_edge('m1', 'm6')

        self.g.add_edge('m2', 'm3')
        self.g.add_edge('m6', 'm5')
        self.g.add_edge('m5', 'm4')
        self.g.add_edge('m4', 'm3')

        order = n.topological_sort(self.g)

        self.assertTrue(''.join(order) == 'm1m2m6m5m4m3')

    def test_bidirectional(self):
        """
         m1 <-> m2 -> m3

        """

        self.g.add_edge('m1', 'm2')
        self.g.add_edge('m2', 'm3')
        self.g.add_edge('m3', 'm2')
        self.g.add_edge('m3', 'm4')

        # remove any models that done have links
        #for

        # determine cycles
        cycles = n.recursive_simple_cycles(self.g)
        for cycle in cycles:
            # remove edges that form cycles
            self.g.remove_edge(cycle[0], cycle[1])

        # perform toposort
        order = n.topological_sort(self.g)

        # re-add bidirectional dependencies (i.e. cycles)
        for cycle in cycles:
            # find index of inverse link
            for i in xrange(0, len(order) - 1):
                if order[i] == cycle[1] and order[i + 1] == cycle[0]:
                    order.insert(i + 2, cycle[1])
                    order.insert(i + 3, cycle[0])
                    break

        self.assertTrue(''.join(order) == 'm1m2m3m2m3m4')
Ejemplo n.º 6
0
class testFeedForwardSimulation(unittest.TestCase):


    def setUp(self):
        # initialize environment variables
        environment.getEnvironmentVars()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()

        self.engine = Coordinator()
        sprint.PrintTarget.CONSOLE = 1134


        self.basepath = os.path.dirname(__file__)

    def tearDown(self):
        pass

    def test_feedforward_simulation(self):

        sprint.sPrint('test', sprint.MessageType.DEBUG)

        randomizer_path = os.path.join(self.basepath, '../../app_data/models/randomizer/randomizer.mdl')
        multiplier_mdl = os.path.join(self.basepath, '../../app_data/models/multiplier/multiplier.mdl')


        m1 = self.engine.add_model(id=1234,  attrib={'mdl':randomizer_path})
        self.assertTrue(m1)

        m2 = self.engine.add_model(id=1235,  attrib={'mdl':multiplier_mdl})
        self.assertTrue(m2)

        # assert that the models have been added correctly
        models = self.engine.get_all_models()
        self.assertTrue(len(models) == 2)


        # add a link from randomizer to multiplier
        rand_oei =  self.engine.get_exchange_item_info(modelid=1234, eitype=stdlib.ExchangeItemType.OUTPUT)
        mult_iei = self.engine.get_exchange_item_info(modelid=1235, eitype=stdlib.ExchangeItemType.INPUT)
        self.engine.add_link(from_id=1234, from_item_id=rand_oei[0]['name'],
                             to_id=1235, to_item_id=mult_iei[0]['name'],
                             spatial_interp=None,
                             temporal_interp=None,
                             uid=None)

        # assert that the link has been established correctly
        links = self.engine.get_all_links()
        self.assertTrue(len(links) == 1)



        # run the simulation, without saving results
        self.engine.run_simulation()

        status = stdlib.Status.UNDEFINED
        while status != stdlib.Status.FINISHED and status != stdlib.Status.ERROR:
            status = self.engine.get_status()
            time.sleep(1)

        # check that output data was generated
        m = self.engine.get_model_by_id(id = 1235)

        values = m.instance().outputs()['multipliedValue'].getValues2()
        self.assertTrue(len(values) > 0)
        self.assertTrue(values[0] != 0)
Ejemplo n.º 7
0
class testNetcdfSimulation(unittest.TestCase):


    def setUp(self):
        self.engine = Coordinator()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = DebugListener()

        self.engine = Coordinator()
        PrintTarget.CONSOLE = 1134

        self.basepath = os.path.dirname(__file__)

    def tearDown(self):
        pass


    def test_netcdf_feedforward(self):

        nc_path = os.path.join(self.basepath, 'data/prcp.nc')
        self.assertTrue(os.path.exists(nc_path))
        args = dict(ncpath = nc_path,
                    tdim = 'time',
                    xdim = 'x',
                    ydim = 'y',
                    tunit = 'hours',
                    starttime = '10-26-2015 00:00:00',
                    type = wrappers.Types.NETCDF)

        # add the WaterOneFlow component to the engine
        self.engine.add_model(id=1234, attrib=args)

        # load a test component
        multiplier_mdl = os.path.join(self.basepath, '../../app_data/models/multiplier/multiplier.mdl')
        self.assertTrue(os.path.exists(multiplier_mdl), 'Path does not exist: %s'%multiplier_mdl)
        args = dict(mdl=multiplier_mdl)
        self.engine.add_model(id=1235, attrib=args)

        # assert that the models have been added correctly
        models = self.engine.get_all_models()
        self.assertTrue(len(models) == 2)

        # add a link from WaterOneFlow to multiplier
        wof_oei =  self.engine.get_exchange_item_info(modelid=1234, eitype=stdlib.ExchangeItemType.OUTPUT)
        mul_iei =  self.engine.get_exchange_item_info(modelid=1235, eitype=stdlib.ExchangeItemType.INPUT)
        self.engine.add_link(from_id=1234, from_item_id=wof_oei[0]['name'],
                             to_id=1235, to_item_id=mul_iei[0]['name'],
                             spatial_interp=None,
                             temporal_interp=None,
                             uid=None)

        links = self.engine.get_all_links()
        self.assertTrue(len(links) == 1)


        # run the simulation
        self.engine.run_simulation()

        status = stdlib.Status.UNDEFINED
        while status != stdlib.Status.FINISHED and status != stdlib.Status.ERROR:
            status = self.engine.get_status()
            time.sleep(1)

        # check that output data was generated
        m = self.engine.get_model_by_id(id = 1235)

        values = m.instance().outputs()['multipliedValue'].getValues2()
        self.assertTrue(len(values) > 0)
        self.assertTrue(values[0] != 0)
Ejemplo n.º 8
0
class testNetcdfSimulation(unittest.TestCase):
    def setUp(self):
        self.engine = Coordinator()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = DebugListener()

        self.engine = Coordinator()
        PrintTarget.CONSOLE = 1134

        self.basepath = os.path.dirname(__file__)

    def tearDown(self):
        pass

    def test_netcdf_feedforward(self):

        nc_path = os.path.join(self.basepath, 'data/prcp.nc')
        self.assertTrue(os.path.exists(nc_path))
        args = dict(ncpath=nc_path,
                    tdim='time',
                    xdim='x',
                    ydim='y',
                    tunit='hours',
                    starttime='10-26-2015 00:00:00',
                    type=wrappers.Types.NETCDF)

        # add the WaterOneFlow component to the engine
        self.engine.add_model(id=1234, attrib=args)

        # load a test component
        multiplier_mdl = os.path.join(
            self.basepath, '../../app_data/models/multiplier/multiplier.mdl')
        self.assertTrue(os.path.exists(multiplier_mdl),
                        'Path does not exist: %s' % multiplier_mdl)
        args = dict(mdl=multiplier_mdl)
        self.engine.add_model(id=1235, attrib=args)

        # assert that the models have been added correctly
        models = self.engine.get_all_models()
        self.assertTrue(len(models) == 2)

        # add a link from WaterOneFlow to multiplier
        wof_oei = self.engine.get_exchange_item_info(
            modelid=1234, eitype=stdlib.ExchangeItemType.OUTPUT)
        mul_iei = self.engine.get_exchange_item_info(
            modelid=1235, eitype=stdlib.ExchangeItemType.INPUT)
        self.engine.add_link(from_id=1234,
                             from_item_id=wof_oei[0]['name'],
                             to_id=1235,
                             to_item_id=mul_iei[0]['name'],
                             spatial_interp=None,
                             temporal_interp=None,
                             uid=None)

        links = self.engine.get_all_links()
        self.assertTrue(len(links) == 1)

        # run the simulation
        self.engine.run_simulation()

        status = stdlib.Status.UNDEFINED
        while status != stdlib.Status.FINISHED and status != stdlib.Status.ERROR:
            status = self.engine.get_status()
            time.sleep(1)

        # check that output data was generated
        m = self.engine.get_model_by_id(id=1235)

        values = m.instance().outputs()['multipliedValue'].getValues2()
        self.assertTrue(len(values) > 0)
        self.assertTrue(values[0] != 0)