# Controller

Controller used as a specific simulation kernel

class pypdevs.controller.Controller(name, model, server)

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

    Notify this simulation kernel that the GVT calculation is finished

  __init__(name, model, server)

    Constructor

    Parameters

      - name – name of the controller

      - model – model to host at the kernel

      - server – the server to make requests on

  checkForTemporaryIrreversible()

    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)

    Connect two ports

    Parameters

      - p1 – source port

      - p2 – target port

  dsDisconnectPorts(p1, p2)

    Disconnect two ports

    Parameters

      - p1 – source port

      - p2 – target port

  dsRemovePort(port)

    Remove a port from the simulation

    Parameters

      port – the port to remove

  dsScheduleModel(model)

    Dynamic Structure change: create a new model

    Parameters

      model – the model to add

  dsUnscheduleModel(model)

    Dynamic Structure change: remove an existing model

    Parameters

      model – the model to remove

  findAndPerformRelocations(gvt, activities, horizon)

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

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

  getEventGraph()

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

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

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

    Returns

      list – all VCD variables in the current scope

  isFinished(running)

    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)

    Notify this kernel that the model is locked

    Parameters

      remote – the node that is locked

  performRelocationsInit(relocate)

    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)

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

    Parameters

      string – the value to inject

  runAllocator()

    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)

    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)

    Sets the use of an initial relocator.

    Parameters

      initial_allocator – whether or not to use an initial allocator

  setCellLocationTracer(x, y, location_cell_view)

    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)

    Sets the use of Classic DEVS instead of Parallel DEVS.

    Parameters

      classicDEVS – whether or not to use Classic DEVS

  setDSDEVS(dsdevs)

    Whether or not to check for DSDEVS events

    Parameters

      dsdevs – dsdevs boolean

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

    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)

    Sets the use of realtime simulation.

    Parameters

      input_references – dictionary containing the string to port mapping

  setRelocator(relocator)

    Sets the relocator to the one provided by the user

    Parameters

      relocator – the relocator to use

  setTerminationCondition(termination_condition)

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

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

    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)

    Start the GVT thread

    Parameters

      gvt_interval – the interval between two successive GVT runs

  stateChange(model_id, variable, value)

    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)

    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)

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

    Parameters

      running – the number of kernels that is simulating