Controller

Controller used as a specific simulation kernel

class pypdevs.controller.Controller(name, model, server)[source]

The controller class, which is a special kind of normal simulation kernel. This should always run on the node labeled 0. It contains some functions that are only required to be ran on a single node, such as GVT initiation

GVTdone()[source]

Notify this simulation kernel that the GVT calculation is finished

__init__(name, model, server)[source]

Constructor

Parameters
  • name – name of the controller

  • model – model to host at the kernel

  • server – the server to make requests on

checkForTemporaryIrreversible()[source]

Checks if one node is hosting all the models. If this is the case, this node will gain ‘temporary irreversibility’, allowing it to skip state saving and thus avoiding the main overhead associated with time warp.

dsConnectPorts(p1, p2)[source]

Connect two ports

Parameters
  • p1 – source port

  • p2 – target port

dsDisconnectPorts(p1, p2)[source]

Disconnect two ports

Parameters
  • p1 – source port

  • p2 – target port

dsRemovePort(port)[source]

Remove a port from the simulation

Parameters

port – the port to remove

dsScheduleModel(model)[source]

Dynamic Structure change: create a new model

Parameters

model – the model to add

dsUnscheduleModel(model)[source]

Dynamic Structure change: remove an existing model

Parameters

model – the model to remove

findAndPerformRelocations(gvt, activities, horizon)[source]

First requests the relocator for relocations to perform, and afterwards actually perform them.

Parameters
  • gvt – the current GVT

  • activities – list containing all activities of all nodes

  • horizon – the horizon used in this activity tracking

gameLoop()[source]

Perform all computations up to the current time. Only applicable for the game loop realtime backend.

getEventGraph()[source]

Fetch a graph containing all connections and the number of events between the nodes. This is only useful when an initial allocator is chosen.

Returns

dict – containing source and destination, it will return the amount of events passed between them

getInitialAllocations()[source]

Get a list of all initial allocations. Will call the allocator to get the result.

Returns

list – containing all nodes and the models they host

getVCDVariables()[source]

Generate a list of all variables that exist in the current scope

Returns

list – all VCD variables in the current scope

isFinished(running)[source]

Checks if all kernels have indicated that they have finished simulation. If each kernel has indicated this, a final (expensive) check happens to prevent premature termination.

Parameters

running – the number of kernels that is simulating

Returns

bool – whether or not simulation is already finished

notifyLocked(remote)[source]

Notify this kernel that the model is locked

Parameters

remote – the node that is locked

performRelocationsInit(relocate)[source]

Perform the relocations specified in the parameter. Split of from the ‘findAndPerformRelocations’, to make it possible for other parts of the code to perform relocations too.

Parameters

relocate – dictionary containing the model_id as key and the value is the node to send it to

realtimeInterrupt(string)[source]

Create an interrupt from other Python code instead of using stdin or the file

Parameters

string – the value to inject

runAllocator()[source]

Actually extract the graph of exchanged messages and run the allocator with this information.

Results are cached.

Returns

tuple – the event graph and the allocations

setActivityTracking(at)[source]

Sets the use of activity tracking, which will simply output the activity of all models at the end of the simulation

Parameters

at – whether or not to enable activity tracking

setAllocator(initial_allocator)[source]

Sets the use of an initial relocator.

Parameters

initial_allocator – whether or not to use an initial allocator

setCellLocationTracer(x, y, location_cell_view)[source]

Sets the Location tracer and all its configuration parameters

Parameters
  • x – the horizontal size of the grid

  • y – the vertical size of the grid

  • location_cell_view – whether or not to enable it

setClassicDEVS(classic_DEVS)[source]

Sets the use of Classic DEVS instead of Parallel DEVS.

Parameters

classicDEVS – whether or not to use Classic DEVS

setDSDEVS(dsdevs)[source]

Whether or not to check for DSDEVS events

Parameters

dsdevs – dsdevs boolean

setRealTime(subsystem, generator_file, ports, scale, listeners, args=[])[source]

Set the use of realtime simulation

Parameters
  • subsystem – defines the subsystem to use

  • generator_file – filename to use for generating external inputs

  • ports – input port references

  • scale – the scale factor for realtime simulation

  • listeners – the ports on which we should listen for output

  • args – additional arguments for the realtime backend

setRealtime(input_references)[source]

Sets the use of realtime simulation.

Parameters

input_references – dictionary containing the string to port mapping

setRelocator(relocator)[source]

Sets the relocator to the one provided by the user

Parameters

relocator – the relocator to use

setTerminationCondition(termination_condition)[source]

Sets the termination condition of this simulation kernel.

As soon as the condition is valid, it willl signal all nodes that they have to stop simulation as soon as they have progressed up to this simulation time.

Parameters

termination_condition – a function that accepts two parameters: time and model. Function returns whether or not to halt simulation

simulate()[source]

Run the actual simulation on the controller. This will simply ‘intercept’ the call to the original simulate and perform location visualisation when necessary.

simulate_sync()[source]

Synchronous simulation call, identical to the normal call, with the exception that it will be a blocking call as only “simulate” is marked as oneway.

startGVTThread(gvt_interval)[source]

Start the GVT thread

Parameters

gvt_interval – the interval between two successive GVT runs

stateChange(model_id, variable, value)[source]

Notification function for when a variable’s value is altered. It will notify the node that is responsible for simulation of this model AND also notify the tracers of the event.

Parameters
  • model_id – the model_id of the model whose variable was changed

  • variable – the name of the variable that was changed (as a string)

  • value – the new value of the variable

threadGVT(freq)[source]

Run the GVT algorithm, this method should be called in its own thread, because it will block

Parameters

freq – the time to sleep between two GVT calculations

waitFinish(running)[source]

Wait until the specified number of kernels have all told that simulation finished.

Parameters

running – the number of kernels that is simulating