mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-16 03:53:12 +00:00
Targeted experiments for queuing mechanism gather series into dataframe put exp_id to the CSV path revert iterations back to num_nodes/2 add missing print and decrease msg_interval_sec change param sequence for readability use struct instead of pickle for fixed-size & faster serde include dtime series into dataframe optimize: choose optimized connection type according to latency setting add skip_sending_noise option optimize filling up the queue with noises move queue_type to the end of param set, and build CSV gradually row by row fix: consider num_senders when waiting until all messages are disseminated fix: sample senders without duplicate fix: build param combinations correctly add plot script initialize MinSizeMixQueue with noises define SessionParameterSet and add paramset for session2 improve topology connectivity check to avoid "maxmimum recursions depth exceeded" error fix: the correct parameter set constructor store individual series to separate CSV files reorganize files and draw plot automatically start series file id from 1 (not 0) add queue_type CLI argument for parallelization pretty format of elapsed time pretty format of elapsed time add merge CLI and draw multiple plots split functions do not draw plot for each session use concurrent.futures to utilize multiprocessing add from_paramset argument fix: count num of finished iterations correctly draw plots for num_sent_msgs and num_senders for specific experiments
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
from typing import Any, Awaitable, Coroutine, TypeVar
|
|
|
|
import usim
|
|
from usim._primitives.task import Task, TaskCancelled
|
|
|
|
from framework import framework
|
|
|
|
|
|
class Framework(framework.Framework):
|
|
"""
|
|
A usim implementation of the Framework for discrete-time simulation
|
|
"""
|
|
|
|
def __init__(self, scope: usim.Scope) -> None:
|
|
super().__init__()
|
|
|
|
# Scope is used to spawn concurrent simulation activities (coroutines).
|
|
# μSim waits until all activities spawned in the scope are done
|
|
# or until the timeout specified in the scope is reached.
|
|
# Because of the way μSim works, the scope must be created using `async with` syntax
|
|
# and be passed to this constructor.
|
|
self._scope = scope
|
|
self._tasks: list[Task] = []
|
|
|
|
def queue(self) -> framework.Queue:
|
|
return Queue()
|
|
|
|
async def sleep(self, seconds: float) -> None:
|
|
await (usim.time + seconds)
|
|
|
|
def now(self) -> float:
|
|
# Round to milliseconds to make analysis not too heavy
|
|
return int(usim.time.now * 1000) / 1000
|
|
|
|
def spawn(
|
|
self, coroutine: Coroutine[Any, Any, framework.RT]
|
|
) -> Awaitable[framework.RT]:
|
|
task = self._scope.do(coroutine)
|
|
self._tasks.append(task)
|
|
return task
|
|
|
|
def stop_tasks(self) -> None:
|
|
for task in self._tasks:
|
|
task.cancel()
|
|
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class Queue(framework.Queue[T]):
|
|
"""
|
|
A usim implementation of the Queue for discrete-time simulation
|
|
"""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self._queue = usim.Queue()
|
|
|
|
async def put(self, data: T) -> None:
|
|
await self._queue.put(data)
|
|
|
|
async def get(self) -> T:
|
|
return await self._queue
|
|
|
|
def empty(self) -> bool:
|
|
return len(self._queue._buffer) == 0
|