跳转到主要内容

基于事件的设备仿真框架

项目描述

Code CI Docs CI Test Coverage Latest PyPI version Apache License

一个基于事件的、多设备仿真框架,提供复杂多设备仿真的配置和编排。

PyPI

pip install tickit

源代码

https://github.com/dls-controls/tickit

文档

https://dls-controls.github.io/tickit

版本

https://github.com/dls-controls/tickit/releases

一个示例仿真包括一个简单的计数器和接收器。计数器增加一个给定值,然后将这个值传递给接收器。

仿真使用yaml文件定义,其中指定了所需组件的图示。该文件定义了一个名为 counterCounter 设备和一个名为 counter_sinkSink 设备。 counter 的输出 _value 连接到 counter_sink 的输入。

- type: examples.devices.counter.Counter
  name: counter
  inputs: {}
- type: tickit.devices.sink.Sink
  name: counter_sink
  inputs:
    input:
      component: counter
      port: _value

执行此文件以运行仿真。

python -m tickit all examples/configs/counter.yaml

仿真将输出描述计数器增加的日志。

DEBUG:examples.devices.counter:Counter initialized with value => 0
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:tickit.core.management.ticker:Doing tick @ 0
DEBUG:tickit.core.components.component:counter got Input(target='counter', time=0, changes=immutables.Map({}))
DEBUG:examples.devices.counter:Counter incremented to 1
DEBUG:tickit.core.management.schedulers.base:Scheduler got Output(source='counter', time=0, changes=immutables.Map({'value': 1}), call_at=1000000000)
DEBUG:tickit.core.management.schedulers.base:Scheduling counter for wakeup at 1000000000
DEBUG:tickit.core.components.component:counter_sink got Input(target='counter_sink', time=0, changes=immutables.Map({}))
DEBUG:tickit.devices.sink:Sunk {}
DEBUG:tickit.core.management.schedulers.base:Scheduler got Output(source='counter_sink', time=0, changes=immutables.Map({}), call_at=None)
DEBUG:tickit.core.management.ticker:Doing tick @ 1000000000
DEBUG:tickit.core.components.component:counter got Input(target='counter', time=1000000000, changes=immutables.Map({}))
DEBUG:examples.devices.counter:Counter incremented to 2
DEBUG:tickit.core.management.schedulers.base:Scheduler got Output(source='counter', time=1000000000, changes=immutables.Map({'value': 2}), call_at=2000000000)

计数器设备如下定义。它增加一个给定值,并在增加时记录。

@dataclass
class Counter(ComponentConfig):
    """Simple counting device."""

    def __call__(self) -> Component:  # noqa: D102
        return DeviceComponent(
            name=self.name,
            device=CounterDevice(),
            )

class CounterDevice(Device):
    """A simple device which increments a value."""

    class Inputs(TypedDict):
        ...

    class Outputs(TypedDict):
        value: int

    def __init__(self, initial_value: int = 0, callback_period: int = int(1e9)) -> None:
        self._value = initial_value
        self.callback_period = SimTime(callback_period)
        LOGGER.debug(f"Counter initialized with value => {self._value}")

    def update(self, time: SimTime, inputs: Inputs) -> DeviceUpdate[Outputs]:
        self._value = self._value + 1
        LOGGER.debug(f"Counter incremented to {self._value}")
        return DeviceUpdate(
            CounterDevice.Outputs(value=self._value),
            SimTime(time + self.callback_period),
        )

有关更详细的文档,请参阅 https://dls-controls.github.io/tickit

项目详细信息


下载文件

下载适合您平台文件的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

tickit-0.4.3.tar.gz (234.9 kB 查看哈希值)

上传时间 源代码

构建分发

tickit-0.4.3-py3-none-any.whl (59.7 kB 查看哈希值)

上传时间 Python 3

由以下支持