System Executor

Author: Changbeom Choi (@cbchoi) Copyright (c) 2014-2020 Handong Global University Copyright (c) 2021-2024 Hanbat National University License: MIT. The full license text is available at: https://github.com/eventsim/pyjevsim/blob/main/LICENSE

This module includes SysExecutor, a simulation engine that manages models over time.

class pyjevsim.system_executor.SysExecutor(_time_resolution, _sim_name='default', ex_mode=ExecutionType.V_TIME, snapshot_manager=None)[source]

Bases: CoreModel

SysExecutor managing the execution of models in a simulation.(Simulation Engine)

EXTERNAL_DST = 'DST'
EXTERNAL_SRC = 'SRC'
coupling_relation(src_obj, out_port, dst_obj, in_port)[source]

Related Model’s input/output ports to each other. Related src_obj’s output port to dst_obj’s input port.

Parameters:
  • src_obj (BehaviorMdoel or StructuralModel) – Model to relate as output ports

  • out_port (str) – src_obj’s output port

  • dst_obj (CoreModel) – Model to relate as input ports

  • in_port (str) – dst_obj’s input port

create_entity()[source]

Creates entities that are scheduled for creation.

destory_entity(delete_lst)[source]

Destroys a list of entities.

Parameters:

delete_lst (list) – List of entities to delete

destroy_active_entity()[source]

Destroys active entities that are scheduled for destruction.

get_entity(model_name)[source]

Retrieves entities by model name.

Parameters:

model_name (str) – The name of the model

Returns:

List of entities

Return type:

list

get_generated_event()[source]

Returns the queue of generated events.

Returns:

The queue of generated events

Return type:

deque

get_global_time()[source]

Retrieves the current global time.(simulation time)

Returns:

The current global time

Return type:

float

get_model(name)[source]

Retrieve Model by name.

Parameters:

name (str) – The name of the model

Returns:

Model(BehaviorModel or StructuralModel)

Return type:

CoreModel

get_relation()[source]

Retrieves the current coupling relations.

Returns:

The relation map

Return type:

dict

handle_external_input_event()[source]

Handles external input events.

handle_external_output_event()[source]

Handles external output events and clears the output event queue.

Returns:

List of output events

Return type:

list

init_sim()[source]

Initializes the simulation.

insert_custom_external_event(_port, _bodylist, scheduled_time=0)[source]

Inserts a custom external event into the simulation.

Parameters:
  • _port (str) – The port name / 포트 이름

  • _bodylist (list) – The list of message bodies

  • scheduled_time (float, optional) – The scheduled time for the event

insert_external_event(_port, _msg, scheduled_time=0)[source]

Inserts an external event into the simulation.

Parameters:
  • _port (str) – port name

  • _msg (SysMessage or None) – Event message

  • scheduled_time (float, optional) – The scheduled time for the event

is_terminated()[source]

Checks if the simulation is terminated.

Returns:

True if terminated, False otherwise

Return type:

bool

output_handling(obj, msg_deliver)[source]

Handles output messages.

Parameters:
register_entity(entity, inst_t=0, dest_t=inf, ename='default')[source]

Register simulation entity(Model).

Parameters:
  • entity (BehaviorModel or StructuralModel) – The entity to register

  • inst_t (float, optional) – Instance creation time

  • dest_t (float, optional) – Destruction time

  • ename (str, optional) – SysExecutor name

remove_entity(model_name)[source]

Removes an entity by model name.

Parameters:

model_name (str) – The name of the model

remove_relation(src, out_port, dst, in_port)[source]

Removes a coupling relation.

Parameters:
  • src_obj (str) – BehaviorMdoel or StructuralModel name, Models that remove relationships as output port

  • out_port (str) – src_obj’s output port

  • dst_obj (CoreModel) – Models that remove relationships as input port

  • in_port (str) – dst_obj’s input port

reset_relation()[source]

Resets all coupling relations.

schedule()[source]

Schedules the next simulation event.

simulate(_time=inf, _tm=True)[source]

Runs the simulation for a given amount of time.

Parameters:
  • _time (float) – The simulation time

  • _tm (bool) – Whether to use the termination manager

simulation_stop()[source]

Stops the simulation and resets SysExecutor.

single_output_handling(obj, msg)[source]

Handles a single output message.

Parameters:
snapshot_simulation(name='', directory_path='.')[source]

Snapshot the model and its releases.

Args :

name(str) : Name of the simulation to be snapshot directory_path : Where the simulation will be snapshot

Raises:

ValueError – Snapshot manager is not set.

terminate_simulation()[source]

Executor Factory

Author: Changbeom Choi (@cbchoi) Copyright (c) 2014-2020 Handong Global University Copyright (c) 2021-2024 Hanbat National University License: MIT. The full license text is available at: https://github.com/eventsim/pyjevsim/blob/main/LICENSE

This module contains an ExecutorFactory that decorates an object of type Model into an Executor that is executable by a SysExecutor.

class pyjevsim.executor_factory.ExecutorFactory[source]

Bases: object

Factory class to create different types of executors.

create_behavior_executor(_, ins_t, des_t, en_name, model, parent)[source]

Create BehaviorModelexecutor

Parameters:
  • _ (float) – Unused global time

  • ins_t (float) – Instance creation time

  • des_t (float) – Destruction time

  • en_name (str) – SysExecutor name

  • model (BehaviorModel) – Behavior model to execute

Returns:

The created BehaviorModelexecutor

Return type:

BehaviorModelExecutor

create_executor(global_time, ins_t, des_t, en_name, model, parent)[source]

Creates an executor based on the model type.

Parameters:
  • global_time (float) – Global simulation time

  • ins_t (float) – Instance creation time

  • des_t (float) – Destruction time

  • en_name (str) – Engine name

  • model (ModelType.BEHAVIORAL of ModelType.STRUCTURAL) – The model to execute

Returns:

The created executor

Return type:

Executor

create_structural_executor(global_time, ins_t, des_t, en_name, model, parent)[source]

Create StructuralModelExecutor

Parameters:
  • global_time (float) – Global simulation time

  • ins_t (float) – Instance creation time

  • des_t (float) – Destruction time

  • en_name (str) – SysExecutor name

  • model (StructuralModel) – StructuralModel to execute

Returns:

created StructuralModelExecutor

Return type:

StructuralModelExecutor

Snapshot Factory

Author: Changbeom Choi (@cbchoi) Copyright (c) 2014-2020 Handong Global University Copyright (c) 2021-2024 Hanbat National University License: MIT. The full license text is available at: https://github.com/eventsim/pyjevsim/blob/main/LICENSE

class pyjevsim.snapshot_factory.SnapshotFactory(snapshot_map)[source]

Bases: ExecutorFactory

The SnapshotManager determines which model you want to take a snapshot of, and sets it to a SnapshotExecutor in a form that the SystemExecutor can execute. And for models that don’t take snapshots, it creates an Executor for each model’s type.

create_executor(global_time, ins_t, des_t, en_name, model, parent)[source]

Creates an executor based on the model type.

Parameters:
  • global_time (float) – Global simulation time

  • ins_t (float) – Instance creation time

  • des_t (float) – Destruction time

  • en_name (str) – Engine name

  • model (ModelType.BEHAVIORAL of ModelType.STRUCTURAL) – The model to execute

Returns:

The created executor

Return type:

Executor

create_snapshot_executor(model)[source]

Create a SnapshotExecutor for the model you want to snapshot.

Parameters:

model (BehaviorModel) – _description_

Returns:

_description_

Return type:

_type_

Message Catcher

Author: Changbeom Choi (@cbchoi) Copyright (c) 2014-2020 Handong Global University Copyright (c) 2021-2024 Hanbat National University License: MIT. The full license text is available at: https://github.com/eventsim/pyjevsim/blob/main/LICENSE

This module contains a default model, DefaultMessageCatcher, for catching uncaught messages.

class pyjevsim.default_message_catcher.DefaultMessageCatcher(_name)[source]

Bases: BehaviorModel

A default model for catching uncaught messages. Receiving and not processing uncaught messages.

ext_trans(port, msg)[source]

Received an uncaught message.

Parameters:
  • port (str) – The port name

  • msg (SysMessage) – The incoming message

int_trans()[source]

Defines the internal transition, to be implemented by subclasses

output(msg_deliver)[source]

Defines the output function, to be implemented by subclasses

Termination Manager

Author: Changbeom Choi (@cbchoi) Copyright (c) 2014-2020 Handong Global University Copyright (c) 2021-2024 Hanbat National University License: MIT. The full license text is available at: https://github.com/eventsim/pyjevsim/blob/main/LICENSE

This module contains the TerminatorManager, which manages the simulation termination of the SysExecutor.

class pyjevsim.termination_manager.TerminationManager[source]

Bases: object

static signal_handler(sig, frame)[source]