Пример #1
0
def test_federate_tests_federateGeneratedGlobalError():

    brk = h.helicsCreateBroker("inproc", "gbrokerc", "--root")
    cr = h.helicsCreateCore("inproc", "gcore", "--broker=gbrokerc")

    argv = ["", "--corename=gcore"]

    fi = h.helicsCreateFederateInfo()
    h.helicsFederateInfoLoadFromArgs(fi, argv)

    fed1 = h.helicsCreateValueFederate("fed0", fi)

    h.helicsFederateInfoFree(fi)
    h.helicsFederateEnterExecutingMode(fed1)

    h.helicsFederateRequestTime(fed1, 2.0)
    h.helicsFederateGlobalError(fed1, 9827, "user generated global error")

    with pt.raises(h.HelicsException):
        h.helicsFederateRequestTime(fed1, 3.0)

    h.helicsFederateDestroy(fed1)
    h.helicsCoreDisconnect(cr)
    h.helicsBrokerDisconnect(brk)
    h.helicsCloseLibrary()
Пример #2
0
def test_system_tests_federate_logging():

    lfile = "log.txt"
    rm(lfile, force=True)
    core = h.helicsCreateCore("inproc", "clogf",
                              "--autobroker --log_level=trace")

    fi = h.helicsCreateFederateInfo()
    h.helicsFederateInfoSetBrokerKey(fi, "key")
    h.helicsFederateInfoSetCoreName(fi, "clogf")
    fed = h.helicsCreateValueFederate("f1", fi)
    h.helicsFederateSetLogFile(fed, lfile)
    h.helicsFederateLogLevelMessage(fed, 7, "hello")
    h.helicsFederateLogErrorMessage(fed, "hello")
    h.helicsFederateLogDebugMessage(fed, "hello")
    h.helicsFederateLogWarningMessage(fed, "hello")
    h.helicsFederateClearMessages(fed)
    h.helicsCoreSetLogFile(core, lfile)
    h.helicsCoreDisconnect(core)
    h.helicsFederateFinalize(fed)
    h.helicsFederateInfoFree(fi)
    h.helicsCloseLibrary()

    assert isfile(lfile)
    rm(lfile, force=True)
Пример #3
0
def setupFederateInfo(name="A Core", number=1, deltat=0.01):
    fedinitstring = f"--broker=mainbroker --federates={number}"

    # Create Federate Info object that describes the federate properties
    fedinfo = h.helicsCreateFederateInfo()
    # assert fedinfo isa h.FederateInfo

    # # Set Federate name
    h.helicsFederateInfoSetCoreName(fedinfo, f"Test{name}")

    # # Set core type from string
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")

    # # Federate init string
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)

    # # Set the message interval (timedelta) for federate. Note th#
    # # HELICS minimum message time interval is 1 ns and by default
    # # it uses a time delta of 1 second. What is provided to the
    # # setTimedelta routine is a multiplier for the default timedelta.

    # # Set one second message interval
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.HELICS_PROPERTY_TIME_DELTA,
                                        deltat)
    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.HELICS_PROPERTY_INT_LOG_LEVEL, -1)
    return fedinfo
Пример #4
0
    def create_helics_federate(self):
        self.fedName = self.settings['helics']['federate_name']
        self.fedinfo = h.helicsCreateFederateInfo()
        h.helicsFederateInfoSetCoreName(
            self.fedinfo, self.settings['helics']['federate_name'])
        h.helicsFederateInfoSetCoreTypeFromString(
            self.fedinfo, self.settings['helics']['core_type'])
        h.helicsFederateInfoSetCoreInitString(self.fedinfo, f"--federates=1")
        h.helicsFederateInfoSetBroker(self.fedinfo,
                                      self.settings['helics']['broker'])
        h.helicsFederateInfoSetBrokerPort(
            self.fedinfo, self.settings['helics']['broker_port'])
        h.helicsFederateInfoSetTimeProperty(
            self.fedinfo, h.helics_property_time_delta,
            self.settings['helics']['time_delta'])
        h.helicsFederateInfoSetIntegerProperty(
            self.fedinfo, h.helics_property_int_log_level,
            self.settings['helics']['helics_logging_level'])

        #h.helicsFederateInfoSetFlagOption(self.fedinfo, h.helics_flag_uninterruptible, True)
        h.helicsFederateInfoSetIntegerProperty(
            self.fedinfo, h.helics_property_int_max_iterations,
            self.settings["helics"]["max_coiter"])
        self.cymeFederate = h.helicsCreateValueFederate(
            self.settings['helics']['federate_name'], self.fedinfo)

        return
Пример #5
0
def AddFederate(broker,
                core_type="zmq",
                count=1,
                deltat=1.0,
                name_prefix="fed"):

    # Create Federate Info object that describes the federate properties #
    fedinfo = h.helicsCreateFederateInfo()

    # Set Federate name #
    h.helicsFederateInfoSetCoreName(fedinfo, name_prefix)

    # Set core type from string #
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")

    # Federate init string #
    fedinitstring = "--broker=mainbroker --federates={}".format(count)
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)

    # Set the message interval (timedelta) for federate. Note th#
    # HELICS minimum message time interval is 1 ns and by default
    # it uses a time delta of 1 second. What is provided to the
    # setTimedelta routine is a multiplier for the default timedelta.

    # Set one second message interval #
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta,
                                        deltat)

    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 1)

    mFed = h.helicsCreateMessageFederate(name_prefix, fedinfo)

    return mFed, fedinfo
Пример #6
0
 def _create_helics_federate(self):
     self.fedinfo = helics.helicsCreateFederateInfo()
     helics.helicsFederateInfoSetCoreName(
         self.fedinfo, self._settings.helics.federate_name)
     helics.helicsFederateInfoSetCoreTypeFromString(
         self.fedinfo, self._settings.helics.core_type)
     helics.helicsFederateInfoSetCoreInitString(self.fedinfo,
                                                f"--federates=1")
     IP = self._settings.helics.broker
     Port = self._settings.helics.broker_port
     self._logger.info(
         "Connecting to broker @ {}".format(f"{IP}:{Port}" if Port else IP))
     if self._settings.helics.broker:
         helics.helicsFederateInfoSetBroker(self.fedinfo,
                                            self._settings.helics.broker)
     if self._settings.helics.broker_port:
         helics.helicsFederateInfoSetBrokerPort(
             self.fedinfo, self._settings.helics.broker_port)
     helics.helicsFederateInfoSetTimeProperty(
         self.fedinfo, helics.helics_property_time_delta,
         self._settings.helics.time_delta)
     helics.helicsFederateInfoSetIntegerProperty(
         self.fedinfo, helics.helics_property_int_log_level,
         self._settings.helics.logging_level)
     helics.helicsFederateInfoSetIntegerProperty(
         self.fedinfo, helics.helics_property_int_max_iterations,
         self._settings.helics.max_co_iterations)
     self._PyDSSfederate = helics.helicsCreateValueFederate(
         self._settings.helics.federate_name, self.fedinfo)
     return
Пример #7
0
def create_message_federate(fedinitstring,name,period):
    # Create Federate Info object that describes the federate properties
    fedinfo = h.helicsCreateFederateInfo()
    # Set core type from string
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "tcpss")
    #assert status == 0
    # Federate init string
    # you need to tell helics what message bus to use
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
    #assert status == 0
    # Set one second message interval
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_period, period)
    #assert status == 0
    # set wait for current time update to true
    h.helicsFederateInfoSetFlagOption(fedinfo, h.helics_flag_uninterruptible, True)
    # h.helics_flag_uninterruptible should have integer value of 1
    #assert status == 0
    # see 'helics_federate_flags' in
    # https://docs.helics.org/en/latest/doxygen/helics__enums_8h_source.html
    h.helicsFederateInfoSetIntegerProperty(fedinfo, h.helics_property_int_log_level, 1)
    # more info:
    # https://docs.helics.org/en/latest/user-guide/logging.html
    # https://docs.helics.org/en/latest/doxygen/helics__enums_8h_source.html
    # scroll to section on 'helics_log_levels'
    #print('status is',status)
    # make sure these links aren't dead
    #assert status == 0
    # Create combo federate and give it a name
    fed = h.helicsCreateMessageFederate(name, fedinfo)

    # should this actually be a message federate?
    #fed = h.helicsCreateMessageFederate(name, fedinfo)
    print("Message federate created")

    return fed
Пример #8
0
    def _create_helics_federate(self):
        self.fedinfo = helics.helicsCreateFederateInfo()
        helics.helicsFederateInfoSetCoreName(self.fedinfo, self._options['Helics']['Federate name'])
        helics.helicsFederateInfoSetCoreTypeFromString(self.fedinfo, self._options['Helics']['Core type'])
        helics.helicsFederateInfoSetCoreInitString(self.fedinfo, f"--federates=1")
        bLoc = self._options['Helics']['Broker']
        Port = self._options['Helics']['Broker port']
        self._logger.info("Connecting to broker @ {}".format(f"{bLoc}:{Port}" if Port else bLoc))

        if self._options['Helics']['Broker']:
            helics.helicsFederateInfoSetBroker(self.fedinfo, self._options['Helics']['Broker'])
        if self._options['Helics']['Broker port']:
            helics.helicsFederateInfoSetBrokerPort(self.fedinfo, self._options['Helics']['Broker port'])
        helics.helicsFederateInfoSetTimeProperty(self.fedinfo, helics.helics_property_time_delta,
                                                 self._options['Helics']['Time delta'])
        helics.helicsFederateInfoSetIntegerProperty(self.fedinfo, helics.helics_property_int_log_level,
                                                    self._options['Helics']['Helics logging level'])

        helics.helicsFederateInfoSetFlagOption(self.fedinfo, helics.helics_flag_uninterruptible, True)
        helics.helicsFederateInfoSetIntegerProperty(self.fedinfo, helics.helics_property_int_max_iterations,
                                                    self._options["Helics"]["Max co-iterations"])
        self._PyDSSfederate = helics.helicsCreateValueFederate(self._options['Helics']['Federate name'], self.fedinfo)


        return
Пример #9
0
def test_value_federate_runFederateTimeoutTest(helicsBroker):

    fedinitstring = "--broker=mainbroker --federates=1"
    deltat = 0.01

    # Create Federate Info object that describes the federate properties #
    fedinfo = h.helicsCreateFederateInfo()

    # Set Federate name #
    h.helicsFederateInfoSetCoreName(fedinfo, "TestA Core")

    # Set core type from string #
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")

    # Federate init string #
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)

    # Set the message interval (timedelta) for federate. Note th#
    # HELICS minimum message time interval is 1 ns and by default
    # it uses a time delta of 1 second. What is provided to the
    # setTimedelta routine is a multiplier for the default timedelta.

    # Set one second message interval #
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta,
                                        deltat)

    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 1)

    vFed = h.helicsCreateValueFederate("TestA Federate", fedinfo)

    defaultValue = "String1"
    testValue = "String2"
    pubid = h.helicsFederateRegisterGlobalPublication(
        vFed, "pub1", h.helics_data_type_string, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")
    h.helicsInputSetDefaultString(subid, defaultValue)

    h.helicsFederateEnterExecutingMode(vFed)

    counter = 60
    while counter > 0:
        counter -= 1
        time.sleep(1)

    # Broker should be connected at this point
    assert h.helicsBrokerIsConnected(
        helicsBroker) == 1, "Broker should still be connected"

    h.helicsFederateFinalize(vFed)

    state = h.helicsFederateGetState(vFed)
    assert state == 3

    while (h.helicsBrokerIsConnected(helicsBroker)):
        time.sleep(1)

    h.helicsFederateInfoFree(fedinfo)
    h.helicsFederateFree(vFed)
Пример #10
0
def create_federate(deltat=1.0, fedinitstring="--federates=1"):
    fedinfo = h.helicsCreateFederateInfo()
    h.helicsFederateInfoSetCoreName(fedinfo, "PythonLoadshedFederate")
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta,
                                        deltat)
    fed = h.helicsCreateCombinationFederate("PythonLoadshedFederate", fedinfo)
    return fed
Пример #11
0
	def __init__(self, core_type = "zmq", time_delta = 1):
		self.__fedinfo = h.helicsCreateFederateInfo()
		h.helicsFederateInfoSetCoreName(self.__fedinfo, "")
		h.helicsFederateInfoSetCoreTypeFromString(self.__fedinfo, core_type)
		h.helicsFederateInfoSetCoreInitString(self.__fedinfo, "--federates=1")
		h.helicsFederateInfoSetTimeProperty(self.__fedinfo, h.helics_property_time_delta, time_delta)
		self.vfed = ""
		self.pub = []
		self.sub = []		
Пример #12
0
def vFed():

    initstring = "-f 1 --name=mainbroker"
    fedinitstring = "--broker=mainbroker --federates=1"
    deltat = 0.01
    #TODO: should add an assert here about helicsGetVersion
    h.helicsGetVersion()

    # Create broker #
    broker = h.helicsCreateBroker("zmq", "", initstring)

    isconnected = h.helicsBrokerIsConnected(broker)

    if isconnected == 1:
        pass

    # Create Federate Info object that describes the federate properties #
    fedinfo = h.helicsCreateFederateInfo()

    # Set Federate name #
    h.helicsFederateInfoSetCoreName(fedinfo, "TestA Core")

    # Set core type from string #
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")

    # Federate init string #
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)

    # Set the message interval (timedelta) for federate. Note th#
    # HELICS minimum message time interval is 1 ns and by default
    # it uses a time delta of 1 second. What is provided to the
    # setTimedelta routine is a multiplier for the default timedelta.

    # Set one second message interval #
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta,
                                        deltat)

    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 1)

    vFed = h.helicsCreateValueFederate("TestA Federate", fedinfo)

    yield vFed

    h.helicsFederateFinalize(vFed)

    state = h.helicsFederateGetState(vFed)
    assert state == 3

    while (h.helicsBrokerIsConnected(broker)):
        time.sleep(1)

    h.helicsFederateInfoFree(fedinfo)
    h.helicsFederateFree(vFed)
    h.helicsCloseLibrary()
Пример #13
0
def test_system_test_federate_global_value():

    brk = h.helicsCreateBroker("inproc", "gbrokerc", "--root")
    cr = h.helicsCreateCore("inproc", "gcore", "--broker=gbrokerc")

    argv = ["", "--corename=gcore"]

    fi = h.helicsCreateFederateInfo()
    h.helicsFederateInfoLoadFromArgs(fi, argv)

    fed = h.helicsCreateValueFederate("fed0", fi)

    fi2 = h.helicsFederateInfoClone(fi)

    h.helicsFederateInfoFree(fi2)
    h.helicsFederateInfoFree(fi)

    globalVal = "this is a string constant that functions as a global"
    globalVal2 = "this is a second string constant that functions as a global"
    h.helicsFederateSetGlobal(fed, "testglobal", globalVal)
    q = h.helicsCreateQuery("global", "testglobal")
    res = h.helicsQueryExecute(q, fed)
    assert res == globalVal
    h.helicsFederateSetGlobal(fed, "testglobal2", globalVal2)
    h.helicsQueryFree(q)
    q = h.helicsCreateQuery("global", "testglobal2")
    h.helicsQueryExecuteAsync(q, fed)
    while h.helicsQueryIsCompleted(q) is False:
        time.sleep(0.20)
    res = h.helicsQueryExecuteComplete(q)
    assert res == globalVal2

    q2 = h.helicsCreateQuery("", "isinit")
    h.helicsQueryExecuteAsync(q2, fed)
    while h.helicsQueryIsCompleted(q2) is False:
        time.sleep(0.20)
    res = h.helicsQueryExecuteComplete(q2)
    assert str(res).lower() == "false"

    h.helicsFederateFinalize(fed)

    h.helicsCoreDisconnect(cr)
    h.helicsBrokerDisconnect(brk)

    h.helicsQueryFree(q)
    h.helicsQueryFree(q2)
    assert h.helicsBrokerIsConnected(brk) is False

    h.helicsBrokerDisconnect(brk)
    h.helicsCoreDisconnect(cr)

    assert h.helicsBrokerIsConnected(brk) is False
    h.helicsCloseLibrary()
Пример #14
0
def mFed():
    initstring = "-f 1 --name=mainbroker"
    fedinitstring = "--broker=mainbroker --federates=1"
    deltat = 0.01

    h.helicsGetVersion()

    # Create broker #
    broker = h.helicsCreateBroker("zmq", "", initstring)

    isconnected = h.helicsBrokerIsConnected(broker)

    if isconnected == 1:
        pass

    # Create Federate Info object that describes the federate properties #
    fedinfo = h.helicsCreateFederateInfo()

    # Set Federate name #
    h.helicsFederateInfoSetCoreName(fedinfo, "CoreA Federate")

    # Set core type from string #
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")

    # Federate init string #
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)

    # Set the message interval (timedelta) for federate. Note th#
    # HELICS minimum message time interval is 1 ns and by default
    # it uses a time delta of 1 second. What is provided to the
    # setTimedelta routine is a multiplier for the default timedelta.

    # Set one second message interval #
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.HELICS_PROPERTY_TIME_DELTA,
                                        deltat)

    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.HELICS_PROPERTY_INT_LOG_LEVEL, 1)

    mFed = h.helicsCreateMessageFederate("TestA Federate", fedinfo)

    yield mFed

    h.helicsFederateFinalize(mFed)
    state = h.helicsFederateGetState(mFed)
    assert state == 3
    while h.helicsBrokerIsConnected(broker):
        time.sleep(1)

    h.helicsFederateInfoFree(fedinfo)
    h.helicsFederateFree(mFed)
    h.helicsCloseLibrary()
Пример #15
0
def test_python_api4():
    fi = h.helicsCreateFederateInfo()
    fi.separator = "_"
    fi.broker = "broker test"

    fi.broker_key = "hello-world"

    fi.broker_port = 8929
    fi.local_port = 8229

    fi.broker_init = "-f 3"

    fi.flag[h.HelicsFederateFlag.TERMINATE_ON_ERROR] = True
    fi.property[h.HelicsProperty.TIME_DELTA] = 1.0
    fi.property["TIME_DELTA"] = 1.0
Пример #16
0
def create_message_federate(fedinitstring, name, period):
    fedinfo = h.helicsCreateFederateInfo()
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "tcpss")
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
    # Set one second message interval
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_period,
                                        period)
    # set wait for current time update to true
    h.helicsFederateInfoSetFlagOption(fedinfo, h.helics_flag_uninterruptible,
                                      True)
    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 1)
    fed = h.helicsCreateMessageFederate(name, fedinfo)
    #print("Message federate created")
    return fed
Пример #17
0
def test_python_api0():
    broker = h.helicsCreateBroker("zmq", "", "-f 1 --name=mainbroker")
    fedinfo = h.helicsCreateFederateInfo()
    assert "HelicsFederateInfo()" in repr(fedinfo)
    fedinfo.core_name = "TestFederate"
    fedinfo.core_type = "zmq"
    fedinfo.core_init = "-f 1 --broker=mainbroker"
    mFed = h.helicsCreateCombinationFederate("TestFederate", fedinfo)

    assert (
        """HelicsCombinationFederate(name = "TestFederate", state = HelicsFederateState.STARTUP, current_time = -9223372036.854776, n_publications = 0, n_subscriptions = 0, n_endpoints = 0, n_filters = 0, n_pending_messages = 0)"""
        in repr(mFed))

    _ = mFed.register_endpoint("ep1")
    _ = mFed.register_global_endpoint("ep2")

    pub = mFed.register_publication("publication", h.HELICS_DATA_TYPE_STRING,
                                    "custom-units")
    assert """HelicsPublication(name = "TestFederate/publication", type = "string", units = "custom-units", info = "")""" in repr(
        pub)

    sub = mFed.register_subscription("subscription", "custom-units")
    assert (
        """HelicsInput(name = "_input_3", units = "custom-units", injection_units = "", publication_type = "", type = "", target = "subscription", info = "")"""
        in repr(sub))
    assert (
        """{ 'CONNECTION_REQUIRED' = 0, 'CONNECTION_OPTIONAL' = 0, 'SINGLE_CONNECTION_ONLY' = 0, 'MULTIPLE_CONNECTIONS_ALLOWED' = 1, 'BUFFER_DATA' = 0, 'STRICT_TYPE_CHECKING' = 0, 'IGNORE_UNIT_MISMATCH' = 0, 'ONLY_TRANSMIT_ON_CHANGE' = 0, 'ONLY_UPDATE_ON_CHANGE' = 0, 'IGNORE_INTERRUPTS' = 0, 'MULTI_INPUT_HANDLING_METHOD' = 0, 'INPUT_PRIORITY_LOCATION' = -1, 'CLEAR_PRIORITY_LIST' = 1, 'CONNECTIONS' = 0 }"""
        in repr(sub.option))
    sub.option["CONNECTION_REQUIRED"] = 1
    sub.option[h.HELICS_HANDLE_OPTION_CONNECTION_REQUIRED] = 1
    assert sub.option["CONNECTION_REQUIRED"] == 1

    sub.add_target("")

    mFed.property[h.HELICS_PROPERTY_TIME_DELTA] = 1.0
    assert mFed.property[h.HELICS_PROPERTY_TIME_DELTA] == 1.0

    mFed.property["TIME_DELTA"] = 1.0
    assert mFed.property["TIME_DELTA"] == 1.0

    with pt.raises(h.HelicsException):
        mFed.enter_executing_mode()

    h.helicsCloseLibrary()

    del mFed
    del broker
Пример #18
0
    def create_value_federate(self, coreName):
        """This function creates a value federate.

        Args:
            coreName (str) - The name of the core for creating the
            value federate.

        Returns:
            vFed (helics federate object) - The value federate.
        """
        name = "echohub Test--T"
        fi = h.helicsCreateFederateInfo()
        h.helicsFederateInfoSetCoreName(fi, coreName)
        global vFed
        vFed = h.helicsCreateValueFederate(name, fi)
        logging.info("echo hub - created the value federate")
        return vFed
Пример #19
0
 def create_federate(self):
     fedinfo = h.helicsCreateFederateInfo()
     h.helicsFederateInfoSetCoreName(fedinfo,
                                     self.settings['Federate name'])
     h.helicsFederateInfoSetCoreTypeFromString(fedinfo,
                                               self.settings['Core type'])
     h.helicsFederateInfoSetCoreInitString(fedinfo, "--federates=1")
     h.helicsFederateInfoSetTimeProperty(
         fedinfo, h.helics_property_time_delta,
         self.settings["Step resolution (sec)"])
     h.helicsFederateInfoSetIntegerProperty(
         fedinfo, h.helics_property_int_log_level,
         self.settings['Helics logging level'])
     h.helicsFederateInfoSetFlagOption(fedinfo,
                                       h.helics_flag_uninterruptible, True)
     self.PSSEfederate = h.helicsCreateValueFederate(
         self.settings['Federate name'], fedinfo)
     return
Пример #20
0
def create_value_federate(deltat=1.0, fedinitstring="--federates=1 --tick=0"):

    fedinfo = h.helicsCreateFederateInfo()

    h.helicsFederateInfoSetCoreName(fedinfo, "TestB Federate")

    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")

    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)

    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta,
                                        deltat)

    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 1)

    fed = h.helicsCreateCombinationFederate("TestB Federate", fedinfo)

    return fed
Пример #21
0
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()
Пример #22
0
    def _create_helics_federate(self):
        self.fedinfo = helics.helicsCreateFederateInfo()
        helics.helicsFederateInfoSetCoreName(self.fedinfo, self._options['Helics']['Federate name'])
        helics.helicsFederateInfoSetCoreTypeFromString(self.fedinfo, self._options['Helics']['Core type'])
        helics.helicsFederateInfoSetCoreInitString(self.fedinfo, f"--federates=1")
        #helics.helicsFederateInfoSetBroker(self.fedinfo, self._options['Helics']['Broker'])
        #helics.helicsFederateInfoSetBrokerPort(self.fedinfo, self._options['Helics']['Broker port'])
        helics.helicsFederateInfoSetTimeProperty(self.fedinfo, helics.helics_property_time_delta,
                                                 self._options['Helics']['Time delta'])
        helics.helicsFederateInfoSetIntegerProperty(self.fedinfo, helics.helics_property_int_log_level,
                                                self._options['Helics']['Helics logging level'])

        helics.helicsFederateInfoSetFlagOption(self.fedinfo, helics.helics_flag_uninterruptible, True)
        helics.helicsFederateInfoSetIntegerProperty(self.fedinfo, helics.helics_property_int_max_iterations,
                                                    self._options["Helics"]["Max co-iterations"])
        self._PyDSSfederate = helics.helicsCreateValueFederate(self._options['Helics']['Federate name'], self.fedinfo)


        return
Пример #23
0
def test_bad_inputs_frees():
    broker = createBroker(1)
    vFed1, fedinfo = createValueFederate(1, "fed0")

    fi = h.helicsCreateFederateInfo()
    h.helicsFederateInfoSetBroker(fi, "broker test")
    h.helicsFederateEnterInitializingMode(vFed1)
    h.helicsFederateFinalize(vFed1)

    h.helicsFederateInfoSetBrokerPort(fi, 8929)
    h.helicsFederateInfoSetLocalPort(fi, "8229")

    h.helicsFederateInfoFree(fi)
    h.helicsFederateFree(vFed1)

    # @test_throws h.HELICSErrorInvalidObject
    with pt.raises(h.HelicsException):
        destroyFederate(vFed1, fedinfo)
    destroyBroker(broker)
Пример #24
0
def create_message_federate(fedinitstring, name, timedelta):
    fedinfo = h.helicsCreateFederateInfo()
    # "coreType": "zmq",
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
    # "loglevel": 1,
    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 11)
    # "timedelta": 1,
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta,
                                        timedelta)
    # "uninterruptible": false,
    h.helicsFederateInfoSetFlagOption(fedinfo, h.helics_flag_uninterruptible,
                                      False)
    # "terminate_on_error": true,
    h.helicsFederateInfoSetFlagOption(fedinfo,
                                      h.HELICS_FLAG_TERMINATE_ON_ERROR, True)
    # "name": "Controller",
    fed = h.helicsCreateMessageFederate(name, fedinfo)
    return fed
Пример #25
0
def create_value_federate(fedinitstring, name, period):
    fedinfo = h.helicsCreateFederateInfo()
    # "coreType": "zmq",
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
    # "loglevel": 1,
    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 7)
    # "period": 60,
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_period,
                                        period)
    # "uninterruptible": false,
    h.helicsFederateInfoSetFlagOption(fedinfo, h.helics_flag_uninterruptible,
                                      False)
    # "terminate_on_error": true,
    #h.helicsFederateInfoSetFlagOption(fedinfo, h.HELICS_FLAG_TERMINATE_ON_ERROR, True)
    h.helicsFederateInfoSetFlagOption(fedinfo, 72, True)
    # "name": "Charger",
    fed = h.helicsCreateValueFederate(name, fedinfo)
    return fed
Пример #26
0
    def create_value_federate(self, coreName, index):
        """This function creates a value federate.

        Args:
            coreName (str) - The name of the core for creating the
            value federate.

            index (int) - The number that indicates which value federate
            is created and used during the test.

        Returns:
            vFed (helics federate object) - The value federate.
        """
        name = "echoleaf_{} Test--T".format(index)
        fi = h.helicsCreateFederateInfo()
        h.helicsFederateInfoSetCoreName(fi, coreName)
        global vFed
        vFed = h.helicsCreateValueFederate(name, fi)
        logging.info("echo leaf - created the value federate")
        return vFed
Пример #27
0
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()
Пример #28
0
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()
Пример #29
0
def create_value_federate(fedinitstring, name, period):
    fedinfo = h.helicsCreateFederateInfo()
    # "coreType": "zmq",
    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")
    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
    # "loglevel": 1,
    h.helicsFederateInfoSetIntegerProperty(fedinfo,
                                           h.helics_property_int_log_level, 1)
    # "period": 60,
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_period,
                                        period)
    # "uninterruptible": false,
    h.helicsFederateInfoSetFlagOption(fedinfo, h.helics_flag_uninterruptible,
                                      False)
    # "terminate_on_error": true,
    h.helicsFederateInfoSetFlagOption(fedinfo, 72, True)
    # "wait_for_current_time_update": true,
    h.helicsFederateInfoSetFlagOption(
        fedinfo, h.helics_flag_wait_for_current_time_update, True)
    # "name": "Battery",
    fed = h.helicsCreateValueFederate(name, fedinfo)
    return fed
Пример #30
0
def create_federate(deltat=1.0, fedinitstring="--federates=1"):

    fedinfo = h.helicsCreateFederateInfo()

    h.helicsFederateInfoSetCoreName(fedinfo, "Combination Federate A")
    # assert status == 0

    h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")
    # assert status == 0

    h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
    # assert status == 0

    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta,
                                        deltat)
    # assert status == 0

    # h.helicsFederateInfoSetLoggingLevel(fedinfo, 1)
    # assert status == 0

    fed = h.helicsCreateCombinationFederate("Combination Federate A", fedinfo)

    return fed
Пример #31
0
print("PI SENDER: Helics version = {}".format(helicsversion))

# Create broker #
print("Creating Broker")
broker = h.helicsCreateBroker("zmq", "", initstring)
print("Created Broker")

print("Checking if Broker is connected")
isconnected = h.helicsBrokerIsConnected(broker)
print("Checked if Broker is connected")

if isconnected == 1:
    print("Broker created and connected")

# Create Federate Info object that describes the federate properties #
fedinfo = h.helicsCreateFederateInfo()

# Set Federate name #
h.helicsFederateInfoSetCoreName(fedinfo, "TestA Federate")

# Set core type from string #
h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")

# Federate init string #
h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)

# Set the message interval (timedelta) for federate. Note th#
# HELICS minimum message time interval is 1 ns and by default
# it uses a time delta of 1 second. What is provided to the
# setTimedelta routine is a multiplier for the default timedelta.