def BMecho_singleCore(federates): """This function performs the echo test. Args: federates (int) - The number of federates to create for the single core echo test. Returns: (null) """ logging.info("starting the single core test") t = Timer(1, timer) t.cancel() feds = [f for f in range(0, federates)] wcore = h.helicsCreateCore( "inproc", None, "--autobroker --federates={}".format((federates))) hub = EchoHub_c() hub_vFed = hub.create_value_federate(h.helicsCoreGetIdentifier(wcore)) hub.initialize(hub_vFed, federates) leafs = [EchoLeaf_c() for f in range(0, federates)] i = 0 leaf_vFeds = [] logging.info("preparing the federates") for f in feds: leaf_vFed = leafs[f].create_value_federate( h.helicsCoreGetIdentifier(wcore), i) leafs[f].initialize(leaf_vFed, i) leaf_vFeds.append(leaf_vFed) i += 1 threads = [] i = 0 logging.info("creating the threads") for l, f in zip(leaf_vFeds, feds): x = Thread(target=leafs[f].run, name=leafs[f], args=(len(feds) + 1, l)) threads.append(x) x.start() i += 1 time.sleep(0.1) hub.make_ready(hub_vFed) logging.info("executing the echo hub") t.start() hub.run(len(feds) + 1, hub_vFed) t.cancel() logging.info("joining the threads") for thrd in threads: thrd.join() h.helicsCoreFree(wcore) h.helicsCleanupLibrary() logging.info("finished the single core test")
def test_filter_types_tests_core_fitler_registration(): core1 = h.helicsCreateCore("inproc", "core1", "--autobroker") core2 = h.helicsCoreClone(core1) core1IdentifierString = h.helicsCoreGetIdentifier(core1) assert core1IdentifierString == "core1" sourceFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1SourceFilter") h.helicsFilterAddSourceTarget(sourceFilter1, "ep1") destinationFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1DestinationFilter") h.helicsFilterAddDestinationTarget(destinationFilter1, "ep2") cloningFilter1 = h.helicsCoreRegisterCloningFilter(core1, "ep3") h.helicsFilterRemoveDeliveryEndpoint(cloningFilter1, "ep3") core1IsConnected = h.helicsCoreIsConnected(core1) assert core1IsConnected != 0 h.helicsCoreSetReadyToInit(core1) h.helicsCoreDisconnect(core1) h.helicsCoreDisconnect(core2) h.helicsCoreFree(core1) h.helicsCoreFree(core2) h.helicsCloseLibrary()
def test_core_api(): core1 = h.helicsCreateCore("inproc", "core1", "--autobroker") assert h.helicsCoreIsValid(core1) is True core2 = h.helicsCoreClone(core1) assert "core1" in h.helicsCoreGetIdentifier(core1) assert h.helicsCoreIsConnected(core1) == 0 sourceFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1SourceFilter") h.helicsFilterAddSourceTarget(sourceFilter1, "ep1") destinationFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1DestinationFilter") h.helicsFilterAddDestinationTarget(destinationFilter1, "ep2") cloningFilter1 = h.helicsCoreRegisterCloningFilter(core1, "ep3") h.helicsFilterRemoveDeliveryEndpoint(cloningFilter1, "ep3") h.helicsCoreSetReadyToInit(core1) h.helicsCoreDisconnect(core1) h.helicsCoreDisconnect(core2) h.helicsCoreFree(core1) h.helicsCoreFree(core2) h.helicsCloseLibrary()
def test_broker_test_make_core_connections(broker): cr = h.helicsCreateCoreFromArgs("zmq", "gcore", ["--broker=gbrokertest"]) assert h.helicsCoreGetIdentifier(cr) == "gcore" with pt.raises(h.HelicsException): h.helicsCoreMakeConnections(cr, "invalidfile.json") h.helicsCoreDisconnect(cr)
def test_other_tests_core_creation(broker): cr = h.helicsCreateCoreFromArgs("zmq", "gcore", ["--broker=gbrokertest"]) assert h.helicsCoreGetIdentifier(cr) == "gcore" # TODO: why is this not raising an exception? with pt.raises(h.HelicsException): cr2 = h.helicsCreateCoreFromArgs( "test", "gcore2", ["--broker=gbrokerc", "--log-level=what_logs?"]) h.helicsCoreDisconnect(cr)
def BMecho_multiCore(cTypeString, federates): """This function performs the multicore test for a specific core type. Args: cTypeString (str) - Specific core type, e.g. inproc federates (int) - The number of federates to create for the echo multicore test. Returns: (null) """ logging.info("starting the multicore test for {}".format(cTypeString)) t = Timer(1, timer) t.cancel() if h.helicsIsCoreTypeAvailable(cTypeString) == h.helics_false: t.start() feds = [f for f in range(0, federates)] initString = "--log_level=no_print --federates={}".format(federates) broker = h.helicsCreateBroker(cTypeString, "brokerf", initString) wcore = h.helicsCreateCore(cTypeString, "", "--federates=1 --log_level=no_print") hub = EchoHub_c() hub_vFed = hub.create_value_federate(h.helicsCoreGetIdentifier(wcore)) hub.initialize(hub_vFed, federates) leafs = [EchoLeaf_c() for f in range(0, federates)] cores = [] i = 0 leaf_vFeds = [] logging.info("preparing the federates") for f in feds: core = h.helicsCreateCore(cTypeString, None, "-f 1 --log_level=no_print") h.helicsCoreConnect(core) leaf_vFed = leafs[f].create_value_federate( h.helicsCoreGetIdentifier(core), i) leafs[f].initialize(leaf_vFed, i) leaf_vFeds.append(leaf_vFed) cores.append(core) i += 1 threads = [] i = 0 logging.info("creating the threads") for l, f in zip(leaf_vFeds, feds): x = Thread(target=leafs[f].run, name=leafs[f], args=(len(feds) + 1, l)) threads.append(x) x.start() i += 1 time.sleep(0.1) hub.make_ready(hub_vFed) logging.info("executing the echo hub") t.start() hub.run(len(feds) + 1, hub_vFed) t.cancel() logging.info("joining the threads") for thrd in threads: thrd.join() h.helicsBrokerDisconnect(broker) h.helicsBrokerFree(broker) logging.info("clearing the cores") for cr in cores: h.helicsCoreFree(cr) cores.clear() h.helicsCoreFree(wcore) h.helicsCleanupLibrary() logging.info("finished the multicore test for {}".format(cTypeString))