Utility functions

Common utility functions used in PyPDEVS

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

DEVS specific exceptions

__init__(message='not specified in source')[source]

Constructor

Parameters:message – error message to print
exception util.QuickStopException[source]

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

__init__()[source]
util.addDict(destination, source)[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.

util.allZeroDict(source)[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
util.broadcastCancel()[source]

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

util.broadcastModel(data, proxies, allow_reinit, scheduler_locations)[source]

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
util.constructGraph(models)[source]

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
util.easyCommand(function, args)[source]

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

util.runTraceAtController(server, uid, model, args)[source]

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
util.saveLocations(filename, model_locations, model_ids)[source]

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
util.toStr(inp)[source]

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

Parameters:inp – the input value
Returns:string – input value, enclosed by ‘ characters