Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyTimeTag

Coverage badge

量子光学实验里常用 时间标签(time tagging) 记录单光子到达时刻与通道;PyTimeTag 提供 Python 库与命令行工具,覆盖时间戳的接收、分块(DataBlock)、序列化/落盘、简单监控与在线处理(含可选 DuckDB 落库)。已内置 Swabian Instruments Time TaggerSeruTek HSPCL6 接入;无硬件时可用 仿真--source simulator)。


文档结构(Sphinx)

完整文档在仓库 docs/source/,中英双语。建议阅读顺序:

章节 中文 English
1. 简介 zh_CN/introduction.rst en/introduction.rst
2. 快速使用 zh_CN/quickstart.rst en/quickstart.rst
3. CLI 详细手册 zh_CN/cli.rst en/cli.rst
4. 数据离线处理 zh_CN/offline_processing.rst en/offline_processing.rst
5. 自行扩展 zh_CN/extending.rst en/extending.rst
6. DataBlock 存储格式 zh_CN/datablock_format.rst en/datablock_format.rst

本地构建 HTML(需 requirements-docs.txt):

make -C docs html-en
make -C docs html-zh

输出目录:docs/build/html/en/docs/build/html/zh_CN/。说明见 docs/README.md


环境要求

  • Python:3.9 及以上。
  • 依赖:NumPy、msgpack、numba、rich、duckdb 等(见 setup.py)。

安装

python -m pip install -U pytimetag

4.0 测试版不会被普通安装命令自动选中。显式安装当前 beta:

python -m pip install "pytimetag==4.0.0b1"

若希望在 4.x 的后续预发布版本之间升级:

python -m pip install -U "pytimetag>=4.0.0b1,<5"

Swabian 硬件(可选):

python -m pip install -U "pytimetag[swabian]"

SeruTek HSPCL6 使用 Python 标准库 ctypes,无需额外 Python 包;运行环境需要 Windows、厂商 USB 驱动和 Tdc_Libusb_Dll.dll。DLL 默认从厂商安装目录加载,也可用 --driver-path 或环境变量 SERUTEK_TDC_DLL 指定。

从源码:

git clone https://github.com/hwaipy/PyTimeTag.git
cd PyTimeTag
python -m pip install -e ".[swabian]"

入口命令:pytimetagpython -m pytimetag若命令行在程序名后无任何参数,只打印帮助、不启动采集。


命令行速览

pytimetag --help

常用示例:

pytimetag --source simulator
pytimetag --source serutek --save --output-dir ./serutek_data
pytimetag --save --output-dir ./my_data
pytimetag --save --storage-db ./analytics/run.duckdb

参数说明(含在线处理开关 --post-process / --storage-db--datablock-dir、切分模式、硬件选项等)见上文 CLI 详细手册 链接。


Web GUI(Vue + Quasar)

已提供内置 GUI 服务端(FastAPI + WebSocket + Celery)与前端工程骨架(webui/)。

启动 API + GUI(默认仅监听本机 127.0.0.1:8787):

pytimetag gui --host 127.0.0.1 --port 8787

在连接 HSPCL6 的 Windows 主机上启动 SeruTek GUI,并允许局域网访问:

pytimetag gui --device serutek --host 0.0.0.0 --port 8787

SeruTek 默认使用 USB0、6 个通道、4194304 事件缓冲和 0.2 秒轮询。GUI 的设备页支持实时查看计数率、调整阈值以及启用/屏蔽通道;HSPCL6 不支持通用的六通道 dead-time 设置。

离线任务使用 Celery,需单独启动 worker(默认 Redis):

celery -A pytimetag.gui.worker:celery_app worker --loglevel=INFO

若控制台出现 No supported WebSocket library detected,请补装:

python -m pip install websockets wsproto

前端源码在 webui/(Quasar):

cd webui
npm install
npm run dev
npm run build

推荐开发调试(前后端分离,支持热更新):

# 终端1:Python 后端(API + WS,代码变更自动重载,不托管静态前端)
pytimetag gui --host 127.0.0.1 --port 8787 --reload --no-web

# 终端2:Node 前端(Vite/Quasar HMR)
cd webui
npm run dev

调试时访问 http://127.0.0.1:5173。前端 devServer 已配置将 /api/ws 代理到 127.0.0.1:8787

也可以在仓库根目录一键启动:

make dev

可单独启动:

make dev-backend
make dev-frontend

npm run build 产物将输出到 pytimetag/gui/webui_dist/,并可随 pip 安装包一起发布。

关键接口:

  • GET /api/v1/meta
  • GET /api/v1/sources
  • GET /api/v1/session/status
  • POST /api/v1/session/start
  • POST /api/v1/session/stop
  • GET /api/v1/analyzers
  • PUT /api/v1/analyzers/{name}
  • GET /api/v1/settings
  • PUT /api/v1/settings
  • GET /api/v1/datablocks
  • POST /api/v1/offline/process
  • GET /api/v1/jobs
  • GET /api/v1/jobs/{job_id}
  • GET /api/v1/logs
  • WS /ws/metrics
  • WS /ws/logs
  • GET /healthz
  • GET /readyz

Docker 一键启动(Redis + API + Worker):

docker compose up --build

默认访问:http://127.0.0.1:8787


作为库使用

安装后可 import pytimetag,使用 DataBlockdevice_type_managerTimeTagSimulator 等。硬件设备类需从子模块导入(不会随 import pytimetag.device 自动加载):

from pytimetag.device.SwabianTimeTag import SwabianTimeTag
from pytimetag.device.SerutekTimeTag import SerutekTimeTag

API 由 Sphinx AutoAPI 生成,见各语言文档中的 API 参考 章节。


开发与测试

python -m pip install -e ".[swabian]"
python -m unittest discover -s tests -p 'test*.py'

CI 见 .github/workflows/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytimetag-4.0.0b1.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytimetag-4.0.0b1-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file pytimetag-4.0.0b1.tar.gz.

File metadata

  • Download URL: pytimetag-4.0.0b1.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for pytimetag-4.0.0b1.tar.gz
Algorithm Hash digest
SHA256 179edd686f58c8d34d16916b14e80dfd277af377c041ae400cb2884ea36e9469
MD5 93913d50475d95f5739678b58cf0f576
BLAKE2b-256 8ffa8f715f6d15fb99e4d7d593c545e3ca3898cc1f7164ccd3a32d20c57ea353

See more details on using hashes here.

File details

Details for the file pytimetag-4.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: pytimetag-4.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for pytimetag-4.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 2faba5f8eb3f366bed99e59f9423446dbce21a21fbce2fbc3f0a8efcf9b82638
MD5 fc2036c2258ab9e6ffda7ff34c6b53c9
BLAKE2b-256 6bccce8676ea84bfdf137d6c823e24216524270fab39b66e4c96dc1a493e583d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

4.0.0b1 This release

2 files

3.0.6

2 files

3.0.5

2 files

3.0.4

2 files

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.2.1

2 files

2.2.0

2 files

2.1.4

2 files

2.1.3

2 files

2.1.2

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.0.1

2 files

1.0.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page