def test_bad_port_connection(self): """ Make a bad port connection and make sure that a suitable error is raised """ model = mdl.Model() model.add_subsystem('EngineCycle', ex.PerfModel()) model.add_subsystem('IPC', ex.CompIPC()) # good connection model.connect(src='EngineCycle.get_ipc_data', dst='IPC.set_perf_data') # typos in subsys name self.assertRaises(AttributeError, model.connect, src='EngineCycleZ.get_ipc_data', dst='IPC.set_perf_data') self.assertRaises(AttributeError, model.connect, src='EngineCycle.get_ipc_data', dst='IPCZ.set_perf_data') # typos in port name self.assertRaises(AttributeError, model.connect, src='EngineCycle.get_ipc_dataZ', dst='IPC.set_perf_data') self.assertRaises(AttributeError, model.connect, src='EngineCycle.get_ipc_data', dst='IPC.set_perf_dataZ')
def test_simple_model_execution(self): """ Run a simple model and check that we can look at some results """ model = mdl.Model() model.add_subsystem('EngineCycle', ex.PerfModel()) runnable_model = model.configure({'EngineCycle': 'lalala'}) datastore = mdl.DataStore() runnable_model.run('EngineCycle', datastore) self.assertTrue('EngineCycle' in datastore) ditem = datastore['EngineCycle'][-1] perf_data = ex.PerfAccessor(ditem) print(perf_data.data)
def test_coupled_model_execution(self): """ Run a model with one node connected to another """ model = mdl.Model() model.add_subsystem('EngineCycle', ex.PerfModel()) model.add_subsystem('IPC', ex.CompIPC()) # good connection model.connect(src='EngineCycle.get_ipc_data', dst='IPC.set_perf_data') runnable_model = model.configure(defaultdict(lambda: 'asdf')) datastore = mdl.DataStore() runnable_model.run('EngineCycle', datastore) runnable_model.run('IPC', datastore) print(datastore) print(datastore['EngineCycle'][-1]['result'].read()) print(datastore['IPC'][-1]['result'].read())
def test_cyclic_model_execution(self): """ Set up a simple model with a cyclic data dependency and get the thing to run """ model = mdl.Model() model.add_subsystem('EngineCycle', ex.PerfModel()) model.add_subsystem('IPC', ex.CompIPC()) model.connect(src='EngineCycle.get_ipc_data', dst='IPC.set_perf_data') model.connect(src='IPC.get_perf_bid', dst='EngineCycle.set_ipc_bid') runnable_model = model.configure(defaultdict(lambda: 'asdf')) datastore = mdl.DataStore() history = [] for _ in range(5): runnable_model.run('EngineCycle', datastore) runnable_model.run('IPC', datastore) d = model.get(datastore, 'EngineCycle', 'get_ipc_data') if history: self.assertTrue(d is not history[-1]) history.append(d) print(d.flow)
def test_create(self): """ Make our example model without doing anything smart """ empty_model = mdl.Model() built_model = ex.build_model()