コード例 #1
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)
コード例 #2
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()
コード例 #3
0
def mFed():
    import helics as h

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

    helicsversion = 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.helicsFederateInfoCreate()

    # Set Federate name #
    status = h.helicsFederateInfoSetFederateName(fedinfo, "TestA Federate")

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

    # Federate init string #
    status = 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 #
    status = h.helicsFederateInfoSetTimeDelta(fedinfo, deltat)

    status = h.helicsFederateInfoSetLoggingLevel(fedinfo, 1)

    mFed = h.helicsCreateMessageFederate(fedinfo)

    yield mFed

    status = h.helicsFederateFinalize(mFed)

    status, state = h.helicsFederateGetState(mFed)
    assert state == 3

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

    h.helicsFederateFree(mFed)
    h.helicsCloseLibrary()
コード例 #4
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()
コード例 #5
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()
コード例 #6
0
def createBroker(number=1):
    initstring = f"-f {number} --name=mainbroker"
    # @test_throws h.HELICSErrorInvalidArgument broker = h.helicsCreateBroker("mq", "", initstring)
    broker = h.helicsCreateBroker("zmq", "", initstring)
    # assert broker is h.Broker
    assert h.helicsBrokerIsConnected(broker) is True
    return broker
コード例 #7
0
def destroy_federate(fed, broker=None):
    status = h.helicsFederateFinalize(fed)
    state = h.helicsFederateGetState(fed)
    assert state == 3
    while (h.helicsBrokerIsConnected(broker)):
        time.sleep(1)
    h.helicsFederateFree(fed)
    h.helicsCloseLibrary()
コード例 #8
0
def create_broker():
    initstring = "--federates=2 --name=mainbroker"
    broker = h.helicsCreateBroker("zmq", "", initstring)
    isconnected = h.helicsBrokerIsConnected(broker)

    if isconnected == 1:
        pass

    return broker
コード例 #9
0
def create_broker():
    initstring = "-f 2"
    broker = h.helicsCreateBroker("zmq", "", initstring)
    isconnected = h.helicsBrokerIsConnected(broker)

    if isconnected == 1:
        pass

    return broker
コード例 #10
0
def destroyFederate(fed, fedinfo, broker=None):
    h.helicsFederateFinalize(fed)
    _ = h.helicsFederateGetState(fed)
    if broker is not None:
        while h.helicsBrokerIsConnected(broker):
            time.sleep(1)
    h.helicsFederateInfoFree(fedinfo)
    h.helicsFederateFree(fed)
    if broker is not None:
        destroyBroker(broker)
コード例 #11
0
def destroy_value_federate(fed, broker):
    h.helicsFederateFinalize(fed)

    state = h.helicsFederateGetState(fed)

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

    h.helicsFederateFree(fed)

    h.helicsCloseLibrary()
コード例 #12
0
ファイル: test_api.py プロジェクト: wfvining/pyhelics
def test_broker_api():
    assert h.helicsIsCoreTypeAvailable("zmq") == 1
    broker1 = h.helicsCreateBroker("zmq", "broker1",
                                   "--federates 3 --loglevel 1")
    broker2 = h.helicsBrokerClone(broker1)
    address_string = h.helicsBrokerGetAddress(broker1)
    assert "tcp://127.0.0.1:23404" in address_string
    assert "broker1" in h.helicsBrokerGetIdentifier(broker1)
    err = h.helicsErrorInitialize()
    h.helicsErrorClear(err)
    assert err.error_code == 0
    assert h.ffi.string(err.message).decode() == ""
    assert h.helicsBrokerIsValid(broker1) == 1
    assert h.helicsBrokerIsConnected(broker1) == 1
    h.helicsBrokerDisconnect(broker1)
    assert h.helicsBrokerIsConnected(broker1) == 0
    h.helicsBrokerDisconnect(broker2)
    h.helicsBrokerFree(broker1)
    h.helicsBrokerFree(broker2)
    h.helicsCloseLibrary()
コード例 #13
0
def destroy_federate(fed):
    h.helicsFederateFinalize(fed)

    #    status, state = h.helicsFederateGetState(fed)
    #    assert state == 3

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

    h.helicsFederateFree(fed)
    h.helicsCloseLibrary()
コード例 #14
0
def AddBroker(core_type="zmq", number_of_federates=1):

    initstring = "{} --name=mainbroker".format(number_of_federates)
    deltat = 0.01

    helicsversion = h.helicsGetVersion()

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

    isconnected = h.helicsBrokerIsConnected(broker)

    if isconnected == 1:
        pass

    return broker
コード例 #15
0
def AddBroker(core_type="zmq", number_of_federates=1):

    initstring = "-f {} --name=mainbroker".format(number_of_federates)

    helicsversion = h.helicsGetVersion()
    print("HELICS version = {}".format(helicsversion))

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

    isconnected = h.helicsBrokerIsConnected(broker)

    if isconnected == 1:
        pass

    return broker
コード例 #16
0
def test_system_broker_global_value():
    brk = h.helicsCreateBroker("ipc", "gbrokerc", "--root")
    globalVal = "this is a string constant that functions as a global"
    globalVal2 = "this is a second string constant that functions as a global"
    h.helicsBrokerSetGlobal(brk, "testglobal", globalVal)
    q = h.helicsCreateQuery("global", "testglobal")
    res = h.helicsQueryBrokerExecute(q, brk)
    assert res == globalVal
    h.helicsBrokerSetGlobal(brk, "testglobal2", globalVal2)
    h.helicsQueryFree(q)
    q = h.helicsCreateQuery("global", "testglobal2")
    res = h.helicsQueryBrokerExecute(q, brk)
    assert res == globalVal2
    h.helicsBrokerDisconnect(brk)
    h.helicsQueryFree(q)
    assert h.helicsBrokerIsConnected(brk) is False
    h.helicsBrokerFree(brk)
コード例 #17
0
def helicsBroker():
    initstring = "-f 1 --name=mainbroker"
    # 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

    yield broker

    h.helicsBrokerFree(broker)
    h.helicsCloseLibrary()
コード例 #18
0
def test_system_test_core_global_value1():

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

    globalVal = "this is a string constant that functions as a global"
    _ = "this is a second string constant that functions as a global"

    h.helicsCoreSetGlobal(cr, "testglobal", globalVal)

    # q = h.helicsCreateQuery("global", "testglobal")
    # TODO: This hangs on core execute
    # res = h.helicsQueryCoreExecute(q, cr)
    # assert res == globalVal
    # h.helicsQueryFree(q)
    # @test_broken False

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

    assert h.helicsBrokerIsConnected(brk) is False
    h.helicsCloseLibrary()
コード例 #19
0
def test_system_test_core_global_value2():
    brk = h.helicsCreateBroker("zmq", "gbrokerc", "--root")

    cr = h.helicsCreateCore("zmq", "gcore", "--broker=gbrokerc")
    connected = h.helicsCoreConnect(cr)
    assert connected == True
    assert h.helicsCoreIsConnected(cr) == True
    globalVal = "this is a string constant that functions as a global"
    globalVal2 = "this is a second string constant that functions as a global"
    h.helicsCoreSetGlobal(cr, "testglobal", globalVal)
    q = h.helicsCreateQuery("global", "testglobal")
    res = h.helicsQueryCoreExecute(q, cr)
    assert res == globalVal
    h.helicsCoreSetGlobal(cr, "testglobal2", globalVal2)
    h.helicsQueryFree(q)
    q = h.helicsCreateQuery("global", "testglobal2")
    res = h.helicsQueryCoreExecute(q, cr)
    assert res == globalVal2
    h.helicsBrokerDisconnect(brk)
    h.helicsCoreDisconnect(cr)

    h.helicsQueryFree(q)
    assert h.helicsBrokerIsConnected(brk) == False
コード例 #20
0
# -*- coding: utf-8 -*-
import os
import helics as h
from math import pi
import time

initstring = "-f 2 --loglevel=7"
broker = h.helicsCreateBroker("zmq", "", initstring)
assert h.helicsBrokerIsConnected(broker) is True

fedinfo = h.helicsCreateFederateInfo()
h.helicsFederateInfoSetCoreType(fedinfo, h.helics_core_type_zmq)
h.helicsFederateInfoSetCoreInitString(fedinfo, "--loglevel=7")
h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta, 1.0)
fed = h.helicsCreateCombinationFederate("sender", fedinfo,)
topicA = h.helicsFederateRegisterGlobalPublication(
    fed, "topicA", h.helics_data_type_double, ""
)

h.helicsFederateEnterExecutingMode(fed)

currenttime = 0

for t in range(5, 10 + 1):
    while currenttime < t:
        currenttime = h.helicsFederateRequestTime(fed, t)
    print(f"Sending value = {pi} at time = {currenttime}")
    h.helicsPublicationPublishDouble(topicA, pi)

h.helicsFederateFinalize(fed)
h.helicsFederateFree(fed)
コード例 #21
0
ファイル: pisender.py プロジェクト: jeffdaily/HELICS-src
initstring = "2 --name=mainbroker"
fedinitstring = "--broker=mainbroker --federates=1"
deltat = 0.01

helicsversion = h.helicsGetVersion()

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.helicsFederateInfoCreate()

# Set Federate name #
status = h.helicsFederateInfoSetFederateName(fedinfo, "TestA Federate")

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

# Federate init string #
コード例 #22
0
def broker():
    brk = h.helicsCreateBroker("zmq", "gbrokertest", "--root")
    yield brk
    h.helicsBrokerDisconnect(brk)
    assert h.helicsBrokerIsConnected(brk) == False
    h.helicsCloseLibrary()
コード例 #23
0
ファイル: pisender.py プロジェクト: dpinney/omf
initstring = "-f 2 --name=mainbroker"
fedinitstring = "--broker=mainbroker --federates=1"
deltat = 0.01

helicsversion = h.helicsGetVersion()

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 #
コード例 #24
0
# -*- coding: utf-8 -*-
import time
import helics as h

# Create broker #
broker = h.helicsCreateBroker("zmq", "", "-f 2 --name=BeamBroker")
isConnected = h.helicsBrokerIsConnected(broker)
if isConnected == 1:
    print("Broker created and connected")
fedInfo = h.helicsCreateFederateInfo()
fedName = "BeamFederateReader"
h.helicsFederateInfoSetCoreName(fedInfo, fedName)
h.helicsFederateInfoSetCoreTypeFromString(fedInfo, "zmq")
h.helicsFederateInfoSetCoreInitString(fedInfo, "--federates=1")
# deltat is multiplied for default timedelta of 1 second
h.helicsFederateInfoSetTimeProperty(fedInfo, h.helics_property_time_delta, 1.0)
cfed = h.helicsCreateCombinationFederate(fedName, fedInfo)

print("Subscribing...")
subs_chargingPlugIn = h.helicsFederateRegisterSubscription(
    cfed, "BeamFederate/chargingPlugIn", "string")
subs_chargingPlugOut = h.helicsFederateRegisterSubscription(
    cfed, "BeamFederate/chargingPlugOut", "string")

print("Waiting Execution Mode...")
h.helicsFederateEnterInitializingMode(cfed)
h.helicsFederateEnterExecutingMode(cfed)

# start execution loop #
timebin = 300
currenttime = 0