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_python_api6(): broker = h.helicsCreateBroker("zmq", "broker", "--federates 1") fi = h.helicsCreateFederateInfo() fed = h.helicsCreateCombinationFederate("test1", fi) fed.enter_initializing_mode() fed.enter_executing_mode() fed.core.disconnect() assert fed.core.wait_for_disconnect() del fed broker.disconnect() assert broker.wait_for_disconnect() del broker h.helicsCleanupLibrary() h.helicsCloseLibrary()
def test_python_api5(): broker = h.helicsCreateBroker("zmq", "broker", "--federates 1") fi = h.helicsCreateFederateInfo() fed = h.helicsCreateCombinationFederate("test1", fi) with pt.raises(h.HelicsException): fed.register_interfaces("unknownfile.json") fed.core.disconnect() assert fed.core.wait_for_disconnect() del fed broker.disconnect() assert broker.wait_for_disconnect() del broker h.helicsCleanupLibrary() h.helicsCloseLibrary()
def test_logging_api(): fi = h.helicsCreateFederateInfo() broker = h.helicsCreateBroker("zmq", "broker", "--federates 1 --loglevel 1") h.helicsFederateInfoSetCoreInitString(fi, "--federates 1") h.helicsFederateInfoSetIntegerProperty(fi, h.HELICS_PROPERTY_INT_LOG_LEVEL, 5) fed = h.helicsCreateValueFederate("test1", fi) userdata = UserData(5) handle = h.ffi.new_handle(userdata) h.helicsFederateSetLoggingCallback(fed, logger, handle) h.helicsFederateEnterExecutingMode(fed) h.helicsFederateLogInfoMessage(fed, "test MEXAGE") h.helicsFederateRequestNextStep(fed) h.helicsFederateLogInfoMessage(fed, "test MEXAGE") h.helicsFederateRequestNextStep(fed) h.helicsFederateLogInfoMessage(fed, "test MEXAGE") h.helicsFederateRequestNextStep(fed) h.helicsFederateLogInfoMessage(fed, "test MEXAGE") h.helicsFederateRequestNextStep(fed) h.helicsFederateFinalize(fed) assert userdata.x == 9 h.helicsFederateFree(fed) h.helicsFederateInfoFree(fi) h.helicsBrokerDisconnect(broker) h.helicsBrokerFree(broker) h.helicsCleanupLibrary() h.helicsCloseLibrary()
def test_python_api7(): broker = h.helicsCreateBroker("zmq", "broker", "--federates 1") fi = h.helicsCreateFederateInfo() fed = h.helicsCreateCombinationFederate("test1", fi) _ = fed.register_filter(h.HELICS_FILTER_TYPE_DELAY, "core1SourceFilter") assert fed.get_filter_by_name( "core1SourceFilter").name == fed.get_filter_by_index(0).name fed.set_global("hello", "world") # TODO: is_async_operation_completed assert fed.is_async_operation_completed() is False fed.enter_initializing_mode_async() fed.enter_initializing_mode_complete() assert fed.is_async_operation_completed() is False fed.enter_executing_mode_async() fed.enter_executing_mode_complete() assert fed.is_async_operation_completed() is False fed.request_time_advance(2.0) assert fed.current_time == 2.0 fed.request_time_async(4.0) assert fed.current_time == 2.0 fed.request_time_complete() assert fed.current_time == 4.0 try: assert fed.query("hello", "world") == "#invalid" except AssertionError: assert fed.query("hello", "world") == { "error": { "code": 404, "message": "query not valid" } } fed.local_error(0, "local") fed.global_error(0, "global") fed.log_message("error", logging.ERROR) fed.log_message("warn", logging.WARN) fed.log_message("info", logging.INFO) fed.log_message("debug", logging.DEBUG) fed.log_message("summary", h.HELICS_LOG_LEVEL_SUMMARY) fed.finalize_async() fed.finalize_complete() fed.core.disconnect() assert fed.core.wait_for_disconnect() del fed broker.disconnect() assert broker.wait_for_disconnect() del broker h.helicsCleanupLibrary() h.helicsCloseLibrary()
def test_python_api2(): broker = h.helicsCreateBroker("zmq", "broker", "--federates 1 --loglevel 1") assert broker.is_connected() broker.set_global("hello", "world") broker.data_link("hello", "world") broker.add_destination_filter_to_endpoint("hello", "world") broker.add_source_filter_to_endpoint("hello", "world") try: assert broker.query("hello", "world") == "#invalid" except AssertionError: assert broker.query("hello", "world") == { "error": { "code": 404, "message": "query not valid" } } fi = h.helicsCreateFederateInfo() fi.core_init = "--federates 1" fi.property[h.HELICS_PROPERTY_INT_LOG_LEVEL] = 2 fed = h.helicsCreateCombinationFederate("test1", fi) assert "HelicsCore" in repr(fed.core) assert 'address = "tcp://127.0.0.1' in repr(fed.core) assert fed.core.is_connected() fed.core.set_ready_to_init() assert "n_publications = 0" in repr(fed) assert "n_subscriptions = 0" in repr(fed) assert "n_endpoints = 0" in repr(fed) assert "n_filters = 0" in repr(fed) assert fed.property["DELTA"] == 1e-09 assert fed.property["PERIOD"] == 0.0 assert fed.property["OFFSET"] == 0.0 assert fed.property["RT_LAG"] == 0.0 assert fed.property["RT_LEAD"] == 0.0 assert fed.property["RT_TOLERANCE"] == 0.0 assert fed.property["INPUT_DELAY"] == 0.0 assert fed.property["OUTPUT_DELAY"] == 0.0 assert fed.property["MAX_ITERATIONS"] == 50 assert fed.property["LOG_LEVEL"] == 2 assert fed.property["FILE_LOG_LEVEL"] == 2 assert fed.property["CONSOLE_LOG_LEVEL"] == 2 fed.property[h.HELICS_PROPERTY_INT_LOG_LEVEL] = 5 fed.separator = "_" assert fed.separator == "_" fed.separator = "/" assert fed.separator == "/" assert fed.property[h.HelicsProperty.TIME_DELTA] == 1e-09 assert fed.property[h.HelicsProperty.TIME_PERIOD] == 0.0 assert fed.property[h.HelicsProperty.TIME_OFFSET] == 0.0 assert fed.property[h.HelicsProperty.TIME_RT_LAG] == 0.0 assert fed.property[h.HelicsProperty.TIME_RT_LEAD] == 0.0 assert fed.property[h.HelicsProperty.TIME_RT_TOLERANCE] == 0.0 assert fed.property[h.HelicsProperty.TIME_INPUT_DELAY] == 0.0 assert fed.property[h.HelicsProperty.TIME_OUTPUT_DELAY] == 0.0 assert fed.property[h.HelicsProperty.INT_MAX_ITERATIONS] == 50 assert fed.property[h.HelicsProperty.INT_LOG_LEVEL] == 5 assert fed.property[h.HelicsProperty.INT_FILE_LOG_LEVEL] == 5 assert fed.property[h.HelicsProperty.INT_CONSOLE_LOG_LEVEL] == 5 assert fed.property[h.HelicsProperty.TIME_DELTA.value] == 1e-09 assert fed.property[h.HelicsProperty.TIME_PERIOD.value] == 0.0 assert fed.property[h.HelicsProperty.TIME_OFFSET.value] == 0.0 assert fed.property[h.HelicsProperty.TIME_RT_LAG.value] == 0.0 assert fed.property[h.HelicsProperty.TIME_RT_LEAD.value] == 0.0 assert fed.property[h.HelicsProperty.TIME_RT_TOLERANCE.value] == 0.0 assert fed.property[h.HelicsProperty.TIME_INPUT_DELAY.value] == 0.0 assert fed.property[h.HelicsProperty.TIME_OUTPUT_DELAY.value] == 0.0 assert fed.property[h.HelicsProperty.INT_MAX_ITERATIONS.value] == 50 assert fed.property[h.HelicsProperty.INT_LOG_LEVEL.value] == 5 assert fed.property[h.HelicsProperty.INT_FILE_LOG_LEVEL.value] == 5 assert fed.property[h.HelicsProperty.INT_CONSOLE_LOG_LEVEL.value] == 5 assert "'TIME_DELTA' = 1e-09" in repr(fed.property) assert "'TIME_PERIOD' = 0.0" in repr(fed.property) assert "'TIME_OFFSET' = 0.0" in repr(fed.property) assert "'TIME_RT_LAG' = 0.0" in repr(fed.property) assert "'TIME_RT_LEAD' = 0.0" in repr(fed.property) assert "'TIME_RT_TOLERANCE' = 0.0" in repr(fed.property) assert "'TIME_INPUT_DELAY' = 0.0" in repr(fed.property) assert "'TIME_OUTPUT_DELAY' = 0.0" in repr(fed.property) assert "'INT_MAX_ITERATIONS' = 50" in repr(fed.property) assert "'INT_LOG_LEVEL' = 5" in repr(fed.property) assert "'INT_FILE_LOG_LEVEL' = 5" in repr(fed.property) assert "'INT_CONSOLE_LOG_LEVEL' = 5" in repr(fed.property) assert fed.flag[h.HELICS_FLAG_OBSERVER] is False assert fed.flag[h.HELICS_FLAG_UNINTERRUPTIBLE] is False assert fed.flag[h.HELICS_FLAG_INTERRUPTIBLE] is True assert fed.flag[h.HELICS_FLAG_SOURCE_ONLY] is False assert fed.flag[h.HELICS_FLAG_ONLY_TRANSMIT_ON_CHANGE] is False assert fed.flag[h.HELICS_FLAG_ONLY_UPDATE_ON_CHANGE] is False assert fed.flag[h.HELICS_FLAG_WAIT_FOR_CURRENT_TIME_UPDATE] is False assert fed.flag[h.HELICS_FLAG_RESTRICTIVE_TIME_POLICY] is False assert fed.flag[h.HELICS_FLAG_REALTIME] is False assert fed.flag[h.HELICS_FLAG_SLOW_RESPONDING] is False assert fed.flag[h.HELICS_FLAG_IGNORE_TIME_MISMATCH_WARNINGS] is False assert fed.flag[h.HELICS_FLAG_TERMINATE_ON_ERROR] is False assert fed.flag["TERMINATE_ON_ERROR"] is False fed.flag["TERMINATE_ON_ERROR"] = False assert fed.flag[h.HELICS_FLAG_OBSERVER.value] is False assert fed.flag[h.HELICS_FLAG_UNINTERRUPTIBLE.value] is False assert fed.flag[h.HELICS_FLAG_INTERRUPTIBLE.value] is True assert fed.flag[h.HELICS_FLAG_SOURCE_ONLY.value] is False assert fed.flag[h.HELICS_FLAG_ONLY_TRANSMIT_ON_CHANGE.value] is False assert fed.flag[h.HELICS_FLAG_ONLY_UPDATE_ON_CHANGE.value] is False assert fed.flag[h.HELICS_FLAG_WAIT_FOR_CURRENT_TIME_UPDATE.value] is False assert fed.flag[h.HELICS_FLAG_RESTRICTIVE_TIME_POLICY.value] is False assert fed.flag[h.HELICS_FLAG_REALTIME.value] is False assert fed.flag[h.HELICS_FLAG_SLOW_RESPONDING.value] is False assert fed.flag[h.HELICS_FLAG_IGNORE_TIME_MISMATCH_WARNINGS.value] is False assert fed.flag[h.HELICS_FLAG_TERMINATE_ON_ERROR.value] is False assert "'OBSERVER' = False" in repr(fed.flag) assert "'UNINTERRUPTIBLE' = False" in repr(fed.flag) assert "'INTERRUPTIBLE' = True" in repr(fed.flag) assert "'SOURCE_ONLY' = False" in repr(fed.flag) assert "'ONLY_TRANSMIT_ON_CHANGE' = False" in repr(fed.flag) assert "'ONLY_UPDATE_ON_CHANGE' = False" in repr(fed.flag) assert "'WAIT_FOR_CURRENT_TIME_UPDATE' = False" in repr(fed.flag) assert "'RESTRICTIVE_TIME_POLICY' = False" in repr(fed.flag) assert "'REALTIME' = False" in repr(fed.flag) assert "'SLOW_RESPONDING' = False," in repr(fed.flag) assert "'IGNORE_TIME_MISMATCH_WARNINGS' = False," in repr(fed.flag) assert "'TERMINATE_ON_ERROR' = False" in repr(fed.flag) fed.flag[h.HELICS_FLAG_TERMINATE_ON_ERROR] = True assert fed.flag[h.HELICS_FLAG_TERMINATE_ON_ERROR] is True fed.core.register_filter(h.HelicsFilterType.DELAY, "") fed.core.register_cloning_filter("") fed.register_filter(h.HelicsFilterType.DELAY, "") fed.register_cloning_filter("") fed.register_global_filter(h.HelicsFilterType.DELAY, "") fed.register_global_cloning_filter("") fed.core.set_global("hello", "world") try: assert fed.core.query("broker", "something") == "#invalid" except AssertionError: assert fed.core.query("broker", "something") == { "error": { "code": 400, "message": "unrecognized broker query" } } fed.add_dependency("hello") fed.core.disconnect() assert fed.core.wait_for_disconnect() del fed broker.disconnect() assert broker.wait_for_disconnect() del broker h.helicsCleanupLibrary() h.helicsCloseLibrary()
def test_misc_api(): fedInfo1 = h.helicsCreateFederateInfo() h.helicsFederateInfoSetCoreInitString(fedInfo1, "-f 1") h.helicsFederateInfoSetCoreName(fedInfo1, "core3") h.helicsFederateInfoSetCoreType(fedInfo1, 3) h.helicsFederateInfoSetCoreTypeFromString(fedInfo1, "zmq") h.helicsFederateInfoSetFlagOption(fedInfo1, 1, True) h.helicsFederateInfoSetTimeProperty(fedInfo1, h.HELICS_PROPERTY_TIME_INPUT_DELAY, 1.0) h.helicsFederateInfoSetIntegerProperty(fedInfo1, h.HELICS_PROPERTY_INT_LOG_LEVEL, 1) h.helicsFederateInfoSetIntegerProperty( fedInfo1, h.HELICS_PROPERTY_INT_MAX_ITERATIONS, 100) h.helicsFederateInfoSetTimeProperty(fedInfo1, h.HELICS_PROPERTY_TIME_OUTPUT_DELAY, 1.0) h.helicsFederateInfoSetTimeProperty(fedInfo1, h.HELICS_PROPERTY_TIME_PERIOD, 1.0) h.helicsFederateInfoSetTimeProperty(fedInfo1, h.HELICS_PROPERTY_TIME_DELTA, 1.0) h.helicsFederateInfoSetTimeProperty(fedInfo1, h.HELICS_PROPERTY_TIME_OFFSET, 0.1) h.helicsFederateInfoFree(fedInfo1) broker3 = h.helicsCreateBroker("zmq", "broker3", "--federates 1 --loglevel 1") fedInfo2 = h.helicsCreateFederateInfo() coreInitString = "--federates 1" h.helicsFederateInfoSetCoreInitString(fedInfo2, coreInitString) h.helicsFederateInfoSetCoreTypeFromString(fedInfo2, "zmq") h.helicsFederateInfoSetIntegerProperty(fedInfo2, h.HELICS_PROPERTY_INT_LOG_LEVEL, 1) h.helicsFederateInfoSetTimeProperty(fedInfo2, h.HELICS_PROPERTY_TIME_DELTA, 1.0) fed1 = h.helicsCreateCombinationFederate("fed1", fedInfo2) fed2 = h.helicsFederateClone(fed1) _ = h.helicsGetFederateByName("fed1") h.helicsFederateSetFlagOption(fed2, 1, False) h.helicsFederateSetTimeProperty(fed2, h.HELICS_PROPERTY_TIME_INPUT_DELAY, 1.0) h.helicsFederateSetIntegerProperty(fed1, h.HELICS_PROPERTY_INT_LOG_LEVEL, 1) h.helicsFederateSetIntegerProperty(fed2, h.HELICS_PROPERTY_INT_MAX_ITERATIONS, 100) h.helicsFederateSetTimeProperty(fed2, h.HELICS_PROPERTY_TIME_OUTPUT_DELAY, 1.0) h.helicsFederateSetTimeProperty(fed2, h.HELICS_PROPERTY_TIME_PERIOD, 0.0) h.helicsFederateSetTimeProperty(fed2, h.HELICS_PROPERTY_TIME_DELTA, 1.0) _ = h.helicsFederateRegisterCloningFilter(fed1, "fed1/Ep1") fed1DestinationFilter = h.helicsFederateRegisterFilter( fed1, h.HELICS_FILTER_TYPE_DELAY, "fed1DestinationFilter") h.helicsFilterAddDestinationTarget(fed1DestinationFilter, "Ep2") ep1 = h.helicsFederateRegisterEndpoint(fed1, "Ep1", "string") ep2 = h.helicsFederateRegisterGlobalEndpoint(fed1, "Ep2", "string") pub1 = h.helicsFederateRegisterGlobalPublication(fed1, "pub1", h.HELICS_DATA_TYPE_DOUBLE, "") pub2 = h.helicsFederateRegisterGlobalTypePublication( fed1, "pub2", "complex", "") sub1 = h.helicsFederateRegisterSubscription(fed1, "pub1") sub2 = h.helicsFederateRegisterSubscription(fed1, "pub2") h.helicsInputAddTarget(sub2, "Ep2") pub3 = h.helicsFederateRegisterPublication(fed1, "pub3", h.HELICS_DATA_TYPE_STRING, "") pub1KeyString = h.helicsPublicationGetKey(pub1) pub1TypeString = h.helicsPublicationGetType(pub1) pub1UnitsString = h.helicsPublicationGetUnits(pub1) sub1KeyString = h.helicsSubscriptionGetKey(sub1) sub1UnitsString = h.helicsInputGetUnits(sub1) assert "pub1" == pub1KeyString assert "double" == pub1TypeString assert "" == pub1UnitsString assert "pub1" == sub1KeyString assert "" == sub1UnitsString fed1SourceFilter = h.helicsFederateRegisterFilter( fed1, h.HELICS_FILTER_TYPE_DELAY, "fed1SourceFilter") h.helicsFilterAddSourceTarget(fed1SourceFilter, "Ep2") h.helicsFilterAddDestinationTarget(fed1SourceFilter, "fed1/Ep1") h.helicsFilterRemoveTarget(fed1SourceFilter, "fed1/Ep1") h.helicsFilterAddSourceTarget(fed1SourceFilter, "Ep2") h.helicsFilterRemoveTarget(fed1SourceFilter, "Ep2") fed1SourceFilterNameString = h.helicsFilterGetName(fed1SourceFilter) assert fed1SourceFilterNameString == "fed1/fed1SourceFilter" sub3 = h.helicsFederateRegisterSubscription(fed1, "fed1/pub3", "") pub4 = h.helicsFederateRegisterTypePublication(fed1, "pub4", "int", "") sub4 = h.helicsFederateRegisterSubscription(fed1, "fed1/pub4", "") pub5 = h.helicsFederateRegisterGlobalTypePublication( fed1, "pub5", "boolean", "") sub5 = h.helicsFederateRegisterSubscription(fed1, "pub5", "") pub6 = h.helicsFederateRegisterGlobalPublication(fed1, "pub6", h.HELICS_DATA_TYPE_VECTOR, "") sub6 = h.helicsFederateRegisterSubscription(fed1, "pub6", "") pub7 = h.helicsFederateRegisterGlobalPublication( fed1, "pub7", h.HELICS_DATA_TYPE_NAMED_POINT, "") sub7 = h.helicsFederateRegisterSubscription(fed1, "pub7", "") assert """helics.HelicsPublication(name = "pub1", type = "double", units = "", info = "")""" in repr( pub1) assert """helics.HelicsPublication(name = "pub2", type = "complex", units = "", info = "")""" in repr( pub2) assert """helics.HelicsPublication(name = "fed1/pub3", type = "string", units = "", info = "")""" in repr( pub3) assert """helics.HelicsPublication(name = "fed1/pub4", type = "int", units = "", info = "")""" in repr( pub4) assert """helics.HelicsPublication(name = "pub5", type = "boolean", units = "", info = "")""" in repr( pub5) assert """helics.HelicsPublication(name = "pub6", type = "double_vector", units = "", info = "")""" in repr( pub6) assert """helics.HelicsPublication(name = "pub7", type = "named_point", units = "", info = "")""" in repr( pub7) assert ( """helics.HelicsInput(name = "_input_18", units = "", injection_units = "", publication_type = "", type = "", target = "pub7", info = "")""" in repr(sub7)) h.helicsInputSetDefaultBoolean(sub5, False) h.helicsInputSetDefaultComplex(sub2, -9.9 + 2.5j) h.helicsInputSetDefaultDouble(sub1, 3.4) h.helicsInputSetDefaultInteger(sub4, 6) h.helicsInputSetDefaultNamedPoint(sub7, "hollow", 20.0) h.helicsInputSetDefaultString(sub3, "default") sub6Default = [3.4, 90.9, 4.5] h.helicsInputSetDefaultVector(sub6, sub6Default) h.helicsEndpointSubscribe(ep2, "fed1/pub3") h.helicsFederateEnterInitializingModeAsync(fed1) rs = h.helicsFederateIsAsyncOperationCompleted(fed1) if rs == 0: time.sleep(0.500) rs = h.helicsFederateIsAsyncOperationCompleted(fed1) if rs == 0: time.sleep(0.500) rs = h.helicsFederateIsAsyncOperationCompleted(fed1) if rs == 0: assert True is False h.helicsFederateEnterInitializingModeComplete(fed1) h.helicsFederateEnterExecutingModeAsync(fed1) h.helicsFederateEnterExecutingModeComplete(fed1) assert ( """helics.HelicsInput(name = "_input_18", units = "", injection_units = "", publication_type = "named_point", type = "", target = "pub7", info = "")""" in repr(sub7)) mesg1 = h.helicsFederateCreateMessage(fed1) h.helicsMessageSetString(mesg1, "Hello") h.helicsMessageSetSource(mesg1, "fed1/Ep1") h.helicsMessageSetOriginalSource(mesg1, "fed1/Ep1") h.helicsMessageSetDestination(mesg1, "Ep2") h.helicsMessageSetOriginalDestination(mesg1, "Ep2") h.helicsEndpointSendMessage(ep1, mesg1) mesg1 = h.helicsFederateCreateMessage(fed1) h.helicsMessageSetString(mesg1, "There") h.helicsMessageSetSource(mesg1, "fed1/Ep1") h.helicsMessageSetOriginalSource(mesg1, "fed1/Ep1") h.helicsMessageSetDestination(mesg1, "Ep2") h.helicsMessageSetOriginalDestination(mesg1, "Ep2") h.helicsEndpointSendMessage(ep1, mesg1) h.helicsEndpointSetDefaultDestination(ep2, "fed1/Ep1") ep1NameString = h.helicsEndpointGetName(ep1) ep1TypeString = h.helicsEndpointGetType(ep1) assert ep1NameString == "fed1/Ep1" assert ep1TypeString == "string" _ = h.helicsFederateGetCoreObject(fed1) fed1Time = h.helicsFederateGetCurrentTime(fed1) assert fed1Time == 0.0 fed1EndpointCount = h.helicsFederateGetEndpointCount(fed1) assert fed1EndpointCount == 2 fed1NameString = h.helicsFederateGetName(fed1) assert fed1NameString == "fed1" fed1State = h.helicsFederateGetState(fed1) assert fed1State == 2 fed1PubCount = h.helicsFederateGetPublicationCount(fed1) assert fed1PubCount == 7 fed1SubCount = h.helicsFederateGetInputCount(fed1) assert fed1SubCount == 7 h.helicsPublicationPublishBoolean(pub5, True) h.helicsPublicationPublishComplex(pub2, 5.6 + -0.67j) h.helicsPublicationPublishDouble(pub1, 457.234) h.helicsPublicationPublishInteger(pub4, 1) h.helicsPublicationPublishNamedPoint(pub7, "Blah Blah", 20.0) h.helicsPublicationPublishString(pub3, "Mayhem") pub6Vector = [4.5, 56.5] h.helicsPublicationPublishVector(pub6, pub6Vector) time.sleep(0.500) h.helicsFederateRequestTimeAsync(fed1, 1.0) returnTime = h.helicsFederateRequestTimeComplete(fed1) assert returnTime == 1.0 ep2MsgCount = h.helicsEndpointPendingMessages(ep2) assert ep2MsgCount == 2 ep2HasMsg = h.helicsEndpointHasMessage(ep2) assert ep2HasMsg == 1 msg2 = h.helicsEndpointGetMessage(ep2) assert h.helicsMessageGetTime(msg2) == 1.0 assert h.helicsMessageGetString(msg2) == "Hello" assert h.helicsMessageGetOriginalSource(msg2) == "fed1/Ep1" assert h.helicsMessageGetSource(msg2) == "fed1/Ep1" assert h.helicsMessageGetDestination(msg2) == "Ep2" assert h.helicsMessageGetOriginalDestination(msg2) == "Ep2" fed1MsgCount = h.helicsFederatePendingMessages(fed1) assert fed1MsgCount == 1 assert h.helicsFederateHasMessage(fed1) == 1 msg3 = h.helicsFederateGetMessage(fed1) assert h.helicsMessageGetTime(msg3) == 1.0 assert h.helicsMessageGetString(msg3) == "There" assert h.helicsMessageGetOriginalSource(msg3) == "fed1/Ep1" assert h.helicsMessageGetSource(msg3) == "fed1/Ep1" assert h.helicsMessageGetDestination(msg3) == "Ep2" assert h.helicsMessageGetOriginalDestination(msg3) == "Ep2" sub1Updated = h.helicsInputIsUpdated(sub1) # TODO: figure out why this test is broken assert sub1Updated is False # TODO: figure out why this test is broken assert h.helicsInputLastUpdateTime(sub2) == 0.0 # assert h.helicsInputGetComplex(sub2) == 5.6 - 0.67j # assert h.helicsInputGetDouble(sub1) == 457.234 # assert h.helicsInputGetInteger(sub4) == 1 sub7PointString, sub7DoubleValue = h.helicsInputGetNamedPoint(sub7) # assert sub7PointString == "Blah Blah" assert sub7DoubleValue == 20.0 # assert h.helicsInputGetBoolean(sub5) == True # assert h.helicsInputGetString(sub3) == "Mayhem" sub3ValueSize = h.helicsInputGetRawValueSize(sub3) # assert sub3ValueSize == 6 # assert h.helicsInputGetVector(sub6) == [4.5, 56.5] h.helicsFederateFinalize(fed1) h.helicsFederateFinalize(fed2) h.helicsFederateFree(fed1) h.helicsFederateFinalize(fed2) h.helicsFederateFree(fed2) h.helicsFederateInfoFree(fedInfo2) h.helicsBrokerDisconnect(broker3) h.helicsBrokerFree(broker3) h.helicsCleanupLibrary() h.helicsCloseLibrary()
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))