# Utility functions

Common utility functions used in PyPDEVS

exception pypdevs.util.DEVSException(message='not specified in source')

  DEVS specific exceptions

  __init__(message='not specified in source')

    Constructor

    Parameters

      message – error message to print

exception pypdevs.util.QuickStopException

  An exception specifically to stop the simulation and perform a relocation ASAP

  __init__()

pypdevs.util.addDict(destination, source)

  Adds 2 dicts together in the first dictionary

  Parameters

    - destination – the destination dictionary to merge the source into

    - source – the dictionary to merge in

  Note

  the destination parameter will be modified and no return value is provided. The source parameter is not modified.

pypdevs.util.allZeroDict(source)

  Checks whether or not a dictionary contains only 0 items

  Parameters

    source – a dictionary to test

  Returns

    bool – whether or not all entries in the dictionary are equal to zero

pypdevs.util.broadcastCancel()

  Cancel the broadcast receiving in a nice way, to prevent MPI errors

pypdevs.util.broadcastModel(data, proxies, allow_reinit, scheduler_locations)

  Broadcast the model to simulate to the provided proxies

  Parameters

    - data – data to be broadcasted to everywhere

    - proxies – iterable containing all proxies

    - allowReinit – should reinitialisation be allowed

pypdevs.util.constructGraph(models)

  Construct a graph from the model, containing the weight (= number of messages) on a connection between two components.

  Parameters

    models – the root model to use for graph construction

  Returns

    dict – all from-to edges with their number of events

pypdevs.util.easyCommand(function, args)

  Easy wrapper to create a string representation of function calls

  Parameters

    - function – the function should be called

    - args – list of all the arguments for the function

  Returns

    str – string representation to be passed to exec

pypdevs.util.runTraceAtController(server, uid, model, args)

  Run a trace command on our version that is running at the constroller

  Parameters

    - server – the server to ask the proxy from

    - uid – the UID of the tracer (identical throughout the simulation)

    - model – the model that transitions

    - args – the arguments for the trace function

pypdevs.util.saveLocations(filename, model_locations, model_ids)

  Save an allocation specified by the parameter.

  Parameters

    - filename – filename to save the allocation to

    - modellocations – allocation to save to file

    - model_ids – all model_ids to model mappings

pypdevs.util.toStr(inp)

  Return a string representation of the input, enclosed with ‘ characters

  Parameters

    inp – the input value

  Returns

    string – input value, enclosed by ‘ characters