qns.simulator package

Submodules

qns.simulator.event module

class qns.simulator.event.Event(t: Time | None = None, name: str | None = None, by: Any | None = None)[source]

Bases: object

Basic event class in simulator

cancel() None[source]

Cancel this event

invoke() None[source]

Invoke the event, should be implemented

property is_canceled: bool

Returns: whether this event has been canceled

qns.simulator.event.func_to_event(t: Time, fn, name: str | None = None, by: Any | None = None, *args, **kwargs)[source]

Convert a function to an event, the function fn will be called at t. It is a simple method to wrap a function to an event.

Parameters:
  • t (Time) – the function will be called at t

  • fn (Callable) – the function

  • by – the entity or application that will causes this event

  • *args – the function’s parameters

  • **kwargs – the function’s parameters

qns.simulator.pool module

class qns.simulator.pool.DefaultEventPool(ts: Time, te: Time)[source]

Bases: object

The default implement of the event pool

add_event(event: Event) bool[source]

Insert an event into the pool

Parameters:

event (Event) – The inserting event

Returns:

if the event is inserted successfully

property current_time: Time

Get the current time

next_event() Event[source]

Get the next event to be executed

Returns:

The next event to be executed

qns.simulator.pool module

class qns.simulator.pool.DefaultEventPool(ts: Time, te: Time)[source]

Bases: object

The default implement of the event pool

add_event(event: Event) bool[source]

Insert an event into the pool

Parameters:

event (Event) – The inserting event

Returns:

if the event is inserted successfully

property current_time: Time

Get the current time

next_event() Event[source]

Get the next event to be executed

Returns:

The next event to be executed

qns.simulator.simulator module

class qns.simulator.simulator.Simulator(start_second: float = 0.0, end_second: float = 60.0, accuracy: int = 1000000)[source]

Bases: object

The discrete-event driven simulator core

add_event(event: Event) None[source]

Add an event into simulator event pool. :param event: the inserting event

property current_time: Time

Get the current time of the simulation

Returns:

(Time) the current time

run() None[source]

Run the simulate

property tc: Time

The alias of current_time

time(time_slot: int | None = None, sec: float | None = None) Time[source]

Produce a Time using time_slot or sec

Parameters:
  • time_slot (Optional[int]) – the time slot

  • sec (Optional[float]) – the second

Returns:

the produced Time object

qns.simulator.ts module

class qns.simulator.ts.Time(time_slot: int = 0, sec: float = 0.0, accuracy: int = 1000000)[source]

Bases: object

property sec: float

Returns: the timestamp in second

qns.simulator.ts.set_default_accuracy(time_slots: int)[source]

set the default simulation accuracy

Parameters:

time_slots (int) – the time slots per second.

qns.simulator.ts module

class qns.simulator.ts.Time(time_slot: int = 0, sec: float = 0.0, accuracy: int = 1000000)[source]

Bases: object

property sec: float

Returns: the timestamp in second

qns.simulator.ts.set_default_accuracy(time_slots: int)[source]

set the default simulation accuracy

Parameters:

time_slots (int) – the time slots per second.

Module contents

class qns.simulator.Event(t: Time | None = None, name: str | None = None, by: Any | None = None)[source]

Bases: object

Basic event class in simulator

cancel() None[source]

Cancel this event

invoke() None[source]

Invoke the event, should be implemented

property is_canceled: bool

Returns: whether this event has been canceled

class qns.simulator.Simulator(start_second: float = 0.0, end_second: float = 60.0, accuracy: int = 1000000)[source]

Bases: object

The discrete-event driven simulator core

add_event(event: Event) None[source]

Add an event into simulator event pool. :param event: the inserting event

property current_time: Time

Get the current time of the simulation

Returns:

(Time) the current time

run() None[source]

Run the simulate

property tc: Time

The alias of current_time

time(time_slot: int | None = None, sec: float | None = None) Time[source]

Produce a Time using time_slot or sec

Parameters:
  • time_slot (Optional[int]) – the time slot

  • sec (Optional[float]) – the second

Returns:

the produced Time object

class qns.simulator.Time(time_slot: int = 0, sec: float = 0.0, accuracy: int = 1000000)[source]

Bases: object

property sec: float

Returns: the timestamp in second

qns.simulator.func_to_event(t: Time, fn, name: str | None = None, by: Any | None = None, *args, **kwargs)[source]

Convert a function to an event, the function fn will be called at t. It is a simple method to wrap a function to an event.

Parameters:
  • t (Time) – the function will be called at t

  • fn (Callable) – the function

  • by – the entity or application that will causes this event

  • *args – the function’s parameters

  • **kwargs – the function’s parameters

qns.simulator.set_default_accuracy(time_slots: int)[source]

set the default simulation accuracy

Parameters:

time_slots (int) – the time slots per second.