Skip to main content

honet

PyPI Python License

面向复杂系统的**高阶网络(higher-order networks)**建模工具包。

成对网络(pairwise network)只能描述“两个个体之间的连接”,而真实系统里大量交互是 多元的:一篇论文有多位作者、一个反应需要多种反应物、一次会议有多方参与。 honet 用超边(hyperedge)刻画这类高阶交互,并提供构造、查询与常用度量。

特性

  • Hypergraph / Hyperedge:轻量、无第三方运行时依赖,结点可为任意可哈希对象;
  • 保序存储:结点与超边均按插入顺序返回,复现结果稳定;
  • 自动维护一致性:添加超边时自动补建结点,重复超边显式报错而非静默覆盖;
  • 常用度量:关联矩阵、高阶度序列、团投影(高阶 → 成对网络);
  • 完整类型标注(随包分发 py.typed),可直接被 mypy / pyright 消费。

安装

honet 使用 uv 管理,所有操作都通过 uv 完成。

作为依赖加入你的项目:

uv add honet

在已有虚拟环境中同步依赖(不修改 pyproject.toml):

uv sync

在临时环境中直接试用,不落盘安装:

uv run --with honet python -c "import honet; print(honet.__version__)"

快速开始

import honet

# 三元高阶交互 {a, b, c} 与二元交互 {c, d}
hg = honet.Hypergraph(
    nodes=["a", "b", "c", "d"],
    edges=[["a", "b", "c"], ["c", "d"]],
)

print(hg.num_nodes, hg.num_edges)        # 4 2
print(hg.degree("c"))                    # 2:c 参与了两条超边
print(hg.neighbors("a"))                 # frozenset({'b', 'c'})
print(hg.is_uniform)                     # False:边大小 3 与 2 不一致

print(honet.degree_sequence(hg))         # [2, 1, 1, 1]
print(honet.incidence_matrix(hg))        # [[1, 0], [1, 0], [1, 1], [0, 1]]
print(honet.clique_projection(hg)["c"])  # frozenset({'a', 'b', 'd'})

# 导出子超图(原图不受影响)
sub = hg.subhypergraph(["a", "b", "c"])
print(sub.num_edges)                     # 1

带标签的超边可区分“同一批成员、不同语义”的高阶交互:

from honet import Hyperedge, Hypergraph

hg = Hypergraph()
hg.add_edge(["alice", "bob"], label="paper-2023")
hg.add_edge(["alice", "bob"], label="paper-2024")   # 合法:标签不同
print(hg.num_edges)                                 # 2

API 概览

名字 说明
honet.Hypergraph 超图容器:add_node / add_edge / remove_node / subhypergraph
honet.Hyperedge 不可变超边:members、label、size
honet.incidence_matrix(hg) 关联矩阵 B,形状 num_nodes × num_edges
honet.degree_sequence(hg) 高阶度序列,降序
honet.clique_projection(hg) 团投影:dict[node, frozenset[neighbor]]
honet.Node 结点类型别名(Hashable)

开发

依赖与打包元数据只来自 pyproject.toml,一切用 uv 完成:

# 安装(含 dev 组:pytest、ruff)
uv sync

# 运行测试
uv run pytest

# 静态检查
uv run ruff check .

# 构建分发包(产物写入 dist/)
uv build

发布

构建用 uv,校验与上传用 twine(通过 uvx 临时执行,不装进项目依赖):

uv build                                   # 1. 构建 sdist + wheel
uvx twine check dist/*                     # 2. 校验元数据与 README 渲染,必须全 PASSED
uvx twine upload --repository testpypi dist/*   # 3a. dev / rc 版本 → TestPyPI
uvx twine upload dist/*                    # 3b. stable 版本 → PyPI

凭据通过环境变量注入(TWINE_USERNAME=__token__、TWINE_PASSWORD=<API token>), 仓库配置见 .pypirc.example。版本三通道 (X.Y.Z.devN / X.Y.ZrcN / X.Y.Z)与索引的对应关系、分支与标签策略、 常见失败原因见 docs/PUBLISHING.md。

许可证

MIT

Metadata

Release files for honet 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for honet 0.1.0
File Size Uploaded Provenance Actions
honet-0.1.0.tar.gz 12.8 kB Without provenance Details for honet-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for honet 0.1.0
File Interpreter ABI Platform Actions
honet-0.1.0-py3-none-any.whl Python 3 none any Details for honet-0.1.0-py3-none-any.whl

Total release size: 26.6 kB

Release files / honet-0.1.0.tar.gz

Download URL honet-0.1.0.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d9913a882de9f146d4b7d7025b4b971cdb9e1c245c9d0fd3d76dce76960895cf
BLAKE2b-256 checksum
How to use checksums
2721921f0808b8757e9b30cc9a773f882be40b1cd692132dd0072de6146270dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / honet-0.1.0-py3-none-any.whl

Download URL honet-0.1.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b74e48eea1917f37eaab49c49b59f27fb1084c3fc99798a7dc8a7b92f2d12d8d
BLAKE2b-256 checksum
How to use checksums
57fadd62761e0aaa9eeb7c0f7a42948e6d557f710610e0ba40fe3ceac68379cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for honet 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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