def test_filter_type_tests_message_filter_function(): broker = createBroker(2) fFed, fedinfo1 = createMessageFederate(1, "filter") mFed, fedinfo2 = createMessageFederate(1, "message") h.helicsFederateSetFlagOption(mFed, h.HELICS_FLAG_IGNORE_TIME_MISMATCH_WARNINGS, True) p1 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port1", "") p2 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port2", "") f1 = h.helicsFederateRegisterFilter(fFed, h.HELICS_FILTER_TYPE_DELAY, "filter1") h.helicsFilterAddSourceTarget(f1, "port1") h.helicsFilterSet(f1, "delay", 2.5) h.helicsFederateEnterExecutingModeAsync(fFed) h.helicsFederateEnterExecutingMode(mFed) h.helicsFederateEnterExecutingModeComplete(fFed) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_EXECUTION data = "".join(["a" for _ in range(0, 500)]).encode() h.helicsEndpointSendMessageRaw(p1, "port2", data) h.helicsFederateRequestTimeAsync(mFed, 1.0) h.helicsFederateRequestTime(fFed, 1.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsFederateHasMessage(mFed) is False h.helicsFederateRequestTimeAsync(mFed, 2.0) h.helicsFederateRequestTime(fFed, 2.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsEndpointHasMessage(p2) is False h.helicsFederateRequestTimeAsync(fFed, 3.0) h.helicsFederateRequestTime(mFed, 3.0) assert h.helicsEndpointHasMessage(p2) is True m2 = h.helicsEndpointGetMessage(p2) assert h.helicsMessageGetSource(m2) == "port1" assert h.helicsMessageGetOriginalSource(m2) == "port1" assert h.helicsMessageGetDestination(m2) == "port2" assert h.helicsMessageGetRawDataSize(m2) == len(data) assert h.helicsMessageGetTime(m2) == 2.5 h.helicsFederateRequestTime(mFed, 3.0) h.helicsFederateRequestTimeComplete(fFed) h.helicsFederateFinalizeAsync(mFed) h.helicsFederateFinalize(fFed) h.helicsFederateFinalizeComplete(mFed) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_FINALIZE destroyFederate(fFed, fedinfo1) destroyFederate(mFed, fedinfo2) destroyBroker(broker)
def test_messagefederate_test_message_federate_send(mFed): epid1 = h.helicsFederateRegisterEndpoint(mFed, "ep1", "") epid2 = h.helicsFederateRegisterGlobalEndpoint(mFed, "ep2", "random") h.helicsFederateSetTimeProperty(mFed, h.HELICS_PROPERTY_TIME_DELTA, 1.0) h.helicsFederateEnterExecutingMode(mFed) data = "random-data" h.helicsEndpointSendEventRaw(epid1, "ep2", data, 1.0) granted_time = h.helicsFederateRequestTime(mFed, 2.0) assert granted_time == 1.0 res = h.helicsFederateHasMessage(mFed) assert res is True res = h.helicsEndpointHasMessage(epid1) assert res is False res = h.helicsEndpointHasMessage(epid2) assert res is True message = h.helicsEndpointGetMessage(epid2) assert h.helicsMessageGetMessageID(message) == 55 assert h.helicsMessageIsValid(message) is True assert h.helicsMessageGetString(message) == "random-data" assert h.helicsMessageGetRawDataSize(message) == 11 assert h.helicsMessageGetOriginalDestination(message) == "" assert h.helicsMessageGetOriginalSource(message) == "TestA Federate/ep1" assert h.helicsMessageGetSource(message) == "TestA Federate/ep1" assert h.helicsMessageGetTime(message) == 1.0
def test_filter_test_types_clone_test_broker_dest_connections(): broker = createBroker(3) sFed, fedinfo1 = createMessageFederate(1, "source", 1.0) dFed, fedinfo2 = createMessageFederate(1, "dest", 1.0) dcFed, fedinfo3 = createMessageFederate(1, "dest_clone", 1.0) p1 = h.helicsFederateRegisterGlobalEndpoint(sFed, "src", "") p2 = h.helicsFederateRegisterGlobalEndpoint(dFed, "dest", "") p3 = h.helicsFederateRegisterGlobalEndpoint(dcFed, "cm", "") f1 = h.helicsFederateRegisterGlobalCloningFilter(dcFed, "filt1") h.helicsFilterAddDeliveryEndpoint(f1, "cm") h.helicsBrokerAddDestinationFilterToEndpoint(broker, "filt1", "dest") h.helicsBrokerAddDestinationFilterToEndpoint(broker, "", "dest") h.helicsFederateEnterExecutingModeAsync(sFed) h.helicsFederateEnterExecutingModeAsync(dcFed) h.helicsFederateEnterExecutingMode(dFed) h.helicsFederateEnterExecutingModeComplete(sFed) h.helicsFederateEnterExecutingModeComplete(dcFed) state = h.helicsFederateGetState(sFed) assert state == h.HELICS_STATE_EXECUTION data = "".join(["a" for _ in range(0, 500)]).encode() h.helicsEndpointSendMessageRaw(p1, "dest", data) h.helicsFederateRequestTimeAsync(sFed, 1.0) h.helicsFederateRequestTimeAsync(dcFed, 1.0) h.helicsFederateRequestTime(dFed, 1.0) h.helicsFederateRequestTimeComplete(sFed) h.helicsFederateRequestTimeComplete(dcFed) assert h.helicsFederateHasMessage(dFed) is True m2 = h.helicsEndpointGetMessage(p2) assert h.helicsMessageGetSource(m2) == "src" assert h.helicsMessageGetOriginalSource(m2) == "src" assert h.helicsMessageGetDestination(m2) == "dest" assert h.helicsMessageGetRawDataSize(m2) == len(data) h.helicsFederateFinalizeAsync(sFed) h.helicsFederateFinalizeAsync(dFed) # TODO: figure out why this test fails on CI # @test_broken False # assert h.helicsFederateHasMessage(dcFed) is False # h.helicsFederateRequestTime(dcFed, 2.0) # assert h.helicsFederateHasMessage(dcFed) is True # m2 = h.helicsEndpointGetMessage(p3) # assert h.helicsMessageGetSource(m2) == "src" # assert h.helicsMessageGetOriginalSource(m2) == "src" # assert h.helicsMessageGetDestination(m2) == "cm" # assert h.helicsMessageGetOriginalDestination(m2) == "dest" # assert h.helicsMessageGetRawDataSize(m2) == len(data) # _ = h.helicsFederateHasMessage(dcFed) h.helicsFederateFinalize(dcFed) h.helicsFederateFinalizeComplete(sFed) h.helicsFederateFinalizeComplete(dFed) state = h.helicsFederateGetState(sFed) assert state == h.HELICS_STATE_FINALIZE destroyFederate(sFed, fedinfo1) destroyFederate(dFed, fedinfo2) destroyFederate(dcFed, fedinfo3) destroyBroker(broker)
def test_filter_callback_test(): broker = createBroker(2) assert """helics.HelicsBroker(identifier = "mainbroker", address = "tcp://127.0.0.1:23404")""" in repr( broker) fFed, fedinfo1 = createMessageFederate(1, "filter", 1.0) mFed, fedinfo2 = createMessageFederate(1, "message", 1.0) h.helicsFederateSetFlagOption(mFed, h.HELICS_FLAG_IGNORE_TIME_MISMATCH_WARNINGS, True) p1 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port1") p2 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port2", "") assert ( """helics.HelicsEndpoint(name = "port1", type = "", info = "", is_valid = True, default_destination = "", n_pending_messages = 0)""" in repr(p1)) assert ( """helics.HelicsEndpoint(name = "port2", type = "", info = "", is_valid = True, default_destination = "", n_pending_messages = 0)""" in repr(p2)) f1 = h.helicsFederateRegisterFilter(fFed, h.HELICS_FILTER_TYPE_CUSTOM, "filter1") f2 = h.helicsFederateRegisterFilter(mFed, h.HELICS_FILTER_TYPE_DELAY, "dfilter") h.helicsFilterAddSourceTarget(f1, "port1") assert 'name = "Testfilter/filter1"' in repr(f1) userdata = UserData(5) handle = h.ffi.new_handle(userdata) h.helicsFilterSetCustomCallback(f1, filterFunc1, handle) with pt.raises(h.HelicsException): h.helicsFilterSetCustomCallback(f2, filterFunc1, handle) assert ( """helics.HelicsMessageFederate(name = "Testfilter", state = HelicsFederateState.STARTUP, current_time = -9223372036.854776, n_publications = 0, n_subscriptions = 0, n_endpoints = 0, n_filters = 1, n_pending_messages = 0)""" in repr(fFed)) assert ( """helics.HelicsMessageFederate(name = "Testmessage", state = HelicsFederateState.STARTUP, current_time = -9223372036.854776, n_publications = 0, n_subscriptions = 0, n_endpoints = 2, n_filters = 1, n_pending_messages = 0)""" in repr(mFed)) h.helicsFederateEnterExecutingModeAsync(fFed) h.helicsFederateEnterExecutingMode(mFed) h.helicsFederateEnterExecutingModeComplete(fFed) assert ( """helics.HelicsMessageFederate(name = "Testfilter", state = HelicsFederateState.EXECUTION, current_time = 0.0, n_publications = 0, n_subscriptions = 0, n_endpoints = 0, n_filters = 1, n_pending_messages = 0)""" in repr(fFed)) assert ( """helics.HelicsMessageFederate(name = "Testmessage", state = HelicsFederateState.EXECUTION, current_time = 0.0, n_publications = 0, n_subscriptions = 0, n_endpoints = 2, n_filters = 1, n_pending_messages = 0)""" in repr(mFed)) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_EXECUTION data = "".join(["a" for _ in range(0, 500)]).encode() h.helicsEndpointSendMessageRaw(p1, "port2", data) h.helicsFederateRequestTimeAsync(mFed, 1.0) h.helicsFederateRequestTime(fFed, 1.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsFederateHasMessage(mFed) is False h.helicsFederateRequestTimeAsync(mFed, 2.0) h.helicsFederateRequestTime(fFed, 2.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsEndpointHasMessage(p2) is False h.helicsFederateRequestTimeAsync(fFed, 3.0) h.helicsFederateRequestTime(mFed, 3.0) assert h.helicsEndpointHasMessage(p2) m2 = h.helicsEndpointGetMessage(p2) assert h.helicsMessageGetSource(m2) == "port1" assert h.helicsMessageGetOriginalSource(m2) == "port1" assert h.helicsMessageGetDestination(m2) == "port2" assert h.helicsMessageGetRawDataSize(m2) == len(data) assert h.helicsMessageGetTime(m2) == 2.5 h.helicsFederateRequestTime(mFed, 3.0) h.helicsFederateRequestTimeComplete(fFed) h.helicsFederateFinalizeAsync(mFed) h.helicsFederateFinalize(fFed) h.helicsFederateFinalizeComplete(mFed) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_FINALIZE destroyFederate(fFed, fedinfo1) destroyFederate(mFed, fedinfo2) destroyBroker(broker)
def test_filter_test_types_clone_test_connections(): broker = createBroker(3) sFed, fedinfo1 = createMessageFederate( 1, "source", 1.0, ) dFed, fedinfo2 = createMessageFederate(1, "dest", 1.0) dcFed, fedinfo3 = createMessageFederate(1, "dest_clone", 1.0) p1 = h.helicsFederateRegisterGlobalEndpoint(sFed, "src", "") p2 = h.helicsFederateRegisterGlobalEndpoint(dFed, "dest", "") p3 = h.helicsFederateRegisterGlobalEndpoint(dcFed, "cm", "") f1 = h.helicsFederateRegisterGlobalCloningFilter(dcFed, "filt1") h.helicsFilterAddDeliveryEndpoint(f1, "cm") cr = h.helicsFederateGetCoreObject(sFed) h.helicsCoreAddSourceFilterToEndpoint(cr, "filt1", "src") h.helicsCoreAddSourceFilterToEndpoint(cr, "", "src") h.helicsFederateEnterExecutingModeAsync(sFed) h.helicsFederateEnterExecutingModeAsync(dcFed) h.helicsFederateEnterExecutingMode(dFed) h.helicsFederateEnterExecutingModeComplete(sFed) h.helicsFederateEnterExecutingModeComplete(dcFed) q = h.helicsCreateQuery("", "filtered_endpoints") filteredEndpoints = h.helicsQueryExecute(q, sFed) assert "srcFilters" in str(filteredEndpoints) assert "(cloning)" in str(filteredEndpoints) h.helicsQueryFree(q) state = h.helicsFederateGetState(sFed) assert state == h.HELICS_STATE_EXECUTION data = "".join(["a" for _ in range(0, 500)]).encode() h.helicsEndpointSendMessageRaw(p1, "dest", data) h.helicsFederateRequestTimeAsync(sFed, 1.0) h.helicsFederateRequestTimeAsync(dcFed, 1.0) h.helicsFederateRequestTime(dFed, 1.0) h.helicsFederateRequestTimeComplete(sFed) h.helicsFederateRequestTimeComplete(dcFed) assert h.helicsFederateHasMessage(dFed) is True m2 = h.helicsEndpointGetMessage(p2) assert h.helicsMessageGetSource(m2) == "src" assert h.helicsMessageGetOriginalSource(m2) == "src" assert h.helicsMessageGetDestination(m2) == "dest" assert h.helicsMessageGetRawDataSize(m2) == len(data) assert h.helicsFederateHasMessage(dcFed) is True m2 = h.helicsEndpointGetMessage(p3) assert h.helicsMessageGetSource(m2) == "src" assert h.helicsMessageGetOriginalSource(m2) == "src" assert h.helicsMessageGetDestination(m2) == "cm" assert h.helicsMessageGetOriginalDestination(m2) == "dest" assert h.helicsMessageGetRawDataSize(m2) == len(data) h.helicsFederateFinalizeAsync(sFed) h.helicsFederateFinalizeAsync(dFed) h.helicsFederateFinalize(dcFed) h.helicsFederateFinalizeComplete(sFed) h.helicsFederateFinalizeComplete(dFed) state = h.helicsFederateGetState(sFed) assert state == h.HELICS_STATE_FINALIZE destroyFederate(sFed, fedinfo1) destroyFederate(dFed, fedinfo2) destroyFederate(dcFed, fedinfo3) destroyBroker(broker)
def test_filter_test_types_clone_test(): broker = createBroker(3) sFed, fedinfo1 = createMessageFederate(1, "source", 1) dFed, fedinfo2 = createMessageFederate(1, "dest", 1) dcFed, fedinfo3 = createMessageFederate(1, "dest_clone", 1) p1 = h.helicsFederateRegisterGlobalEndpoint(sFed, "src", "") p2 = h.helicsFederateRegisterGlobalEndpoint(dFed, "dest", "") p3 = h.helicsFederateRegisterGlobalEndpoint(dcFed, "cm", "") f1 = h.helicsFederateRegisterCloningFilter(dcFed, "") h.helicsFilterAddDeliveryEndpoint(f1, "cm") h.helicsFilterAddSourceTarget(f1, "src") h.helicsFederateEnterExecutingModeAsync(sFed) h.helicsFederateEnterExecutingModeAsync(dcFed) h.helicsFederateEnterExecutingMode(dFed) h.helicsFederateEnterExecutingModeComplete(sFed) h.helicsFederateEnterExecutingModeComplete(dcFed) state = h.helicsFederateGetState(sFed) assert state == h.HELICS_STATE_EXECUTION state = h.helicsFederateGetState(dcFed) assert state == h.HELICS_STATE_EXECUTION state = h.helicsFederateGetState(dFed) assert state == h.HELICS_STATE_EXECUTION data = "".join(["a" for _ in range(0, 500)]).encode() h.helicsEndpointSendMessageRaw(p1, "dest", data) h.helicsFederateRequestTimeAsync(sFed, 1.0) h.helicsFederateRequestTimeAsync(dcFed, 1.0) h.helicsFederateRequestTime(dFed, 1.0) h.helicsFederateRequestTimeComplete(sFed) h.helicsFederateRequestTimeComplete(dcFed) assert h.helicsFederateHasMessage(dFed) m2 = h.helicsEndpointGetMessage(p2) assert h.helicsMessageGetSource(m2) == "src" assert h.helicsMessageGetOriginalSource(m2) == "src" assert h.helicsMessageGetDestination(m2) == "dest" assert h.helicsMessageGetRawDataSize(m2) == len(data) assert h.helicsFederateHasMessage(dcFed) m2 = h.helicsEndpointGetMessage(p3) assert h.helicsMessageGetSource(m2) == "src" assert h.helicsMessageGetOriginalSource(m2) == "src" assert h.helicsMessageGetDestination(m2) == "cm" assert h.helicsMessageGetOriginalDestination(m2) == "dest" assert h.helicsMessageGetRawDataSize(m2) == len(data) h.helicsFederateFinalizeAsync(sFed) h.helicsFederateFinalizeAsync(dFed) h.helicsFederateFinalize(dcFed) h.helicsFederateFinalizeComplete(sFed) h.helicsFederateFinalizeComplete(dFed) state = h.helicsFederateGetState(sFed) assert state == h.HELICS_STATE_FINALIZE destroyFederate(sFed, fedinfo1) destroyFederate(dFed, fedinfo2) destroyFederate(dcFed, fedinfo3) destroyBroker(broker)
def test_filter_test_types_message_filter_function3(): broker = createBroker(2) fFed, fedinfo1 = createMessageFederate(1, "filter", 1) mFed, fedinfo2 = createMessageFederate(1, "message", 1) p1 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port1", "") p2 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port2", "random") f1 = h.helicsFederateRegisterGlobalFilter(fFed, h.HELICS_FILTER_TYPE_CUSTOM, "filter1") h.helicsFilterAddSourceTarget(f1, "port1") f2 = h.helicsFederateRegisterGlobalFilter(fFed, h.HELICS_FILTER_TYPE_DELAY, "filter2") h.helicsFilterAddSourceTarget(f2, "port1") h.helicsFederateRegisterEndpoint(fFed, "fout", "") f3 = h.helicsFederateRegisterFilter(fFed, h.HELICS_FILTER_TYPE_RANDOM_DELAY, "filter3") h.helicsFilterAddSourceTarget(f3, "filter0/fout") h.helicsFilterSet(f2, "delay", 2.5) h.helicsFederateEnterExecutingModeAsync(fFed) h.helicsFederateEnterExecutingMode(mFed) h.helicsFederateEnterExecutingModeComplete(fFed) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_EXECUTION data = "hello world".encode() h.helicsEndpointSendMessageRaw(p1, "port2", data) h.helicsFederateRequestTimeAsync(mFed, 1.0) h.helicsFederateRequestTime(fFed, 1.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsFederateHasMessage(mFed) is False h.helicsEndpointSendMessageRaw(p2, "port1", data) h.helicsFederateRequestTimeAsync(mFed, 2.0) h.helicsFederateRequestTime(fFed, 2.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsEndpointHasMessage(p2) is False # there may be something wrong here yet but this test isn't the one to find it and # this may prevent spurious errors for now. # std::this_thread::yield() h.helicsFederateRequestTimeAsync(mFed, 3.0) h.helicsFederateRequestTime(fFed, 3.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsEndpointHasMessage(p2) m2 = h.helicsEndpointGetMessage(p2) assert h.helicsMessageGetSource(m2) == "port1" assert h.helicsMessageGetOriginalSource(m2) == "port1" assert h.helicsMessageGetDestination(m2) == "port2" assert h.helicsMessageGetRawDataSize(m2) == len(data) assert h.helicsMessageGetTime(m2) == 2.5 assert h.helicsEndpointHasMessage(p1) is True h.helicsFederateFinalize(mFed) h.helicsFederateFinalize(fFed) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_FINALIZE destroyFederate(mFed, fedinfo1) destroyFederate(fFed, fedinfo2) destroyBroker(broker)
def test_filter_test_types_function2(): broker = createBroker(2) fFed, fedinfo1 = createMessageFederate(1, "filter") mFed, fedinfo2 = createMessageFederate(1, "message") p1 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port1", "") p2 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port2", "") f1 = h.helicsFederateRegisterFilter(fFed, h.HELICS_FILTER_TYPE_DELAY, "filter1") h.helicsFilterAddSourceTarget(f1, "port1") h.helicsFilterSet(f1, "delay", 2.5) f2 = h.helicsFederateRegisterFilter(fFed, h.HELICS_FILTER_TYPE_DELAY, "filter2") h.helicsFilterAddSourceTarget(f2, "port2") h.helicsFilterSet(f2, "delay", 2.5) # this is expected to fail since a regular filter doesn't have a delivery endpoint # @test_throws h.HELICSErrorInvalidObject h.helicsFilterAddDeliveryEndpoint(f2, "port1") h.helicsFederateEnterExecutingModeAsync(fFed) h.helicsFederateEnterExecutingMode(mFed) h.helicsFederateEnterExecutingModeComplete(fFed) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_EXECUTION data = "".join(["a" for _ in range(0, 500)]).encode() h.helicsEndpointSendMessageRaw(p1, "port2", data) h.helicsFederateRequestTimeAsync(mFed, 1.0) h.helicsFederateRequestTime(fFed, 1.0) h.helicsFederateRequestTimeComplete(mFed) res = h.helicsFederateHasMessage(mFed) assert res is False h.helicsEndpointSendMessageRaw(p2, "port1", data) h.helicsFederateRequestTimeAsync(mFed, 2.0) h.helicsFederateRequestTime(fFed, 2.0) h.helicsFederateRequestTimeComplete(mFed) assert h.helicsEndpointHasMessage(p2) is False # there may be something wrong here yet but this test isn't the one to find it and # this may prevent spurious errors for now. # std::this_thread::yield() h.helicsFederateRequestTime(mFed, 3.0) assert h.helicsEndpointHasMessage(p2) is True m2 = h.helicsEndpointGetMessage(p2) assert h.helicsMessageGetSource(m2) == "port1" assert h.helicsMessageGetOriginalSource(m2) == "port1" assert h.helicsMessageGetDestination(m2) == "port2" assert h.helicsMessageGetRawDataSize(m2) == len(data) assert h.helicsMessageGetTime(m2) == 2.5 assert h.helicsEndpointHasMessage(p1) is False h.helicsFederateRequestTime(mFed, 4.0) assert h.helicsEndpointHasMessage(p1) is True h.helicsFederateFinalizeAsync(mFed) h.helicsFederateFinalize(fFed) h.helicsFederateFinalizeComplete(mFed) state = h.helicsFederateGetState(fFed) assert state == h.HELICS_STATE_FINALIZE destroyFederate(fFed, fedinfo1) destroyFederate(mFed, fedinfo2) destroyBroker(broker)
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()