Metadata-Version: 2.4
Name: honet
Version: 0.1.0
Summary: Lightweight toolkit for modelling and analysing higher-order networks (hypergraphs).
Keywords: higher-order-networks,hypergraph,complex-systems,network-science,incidence-matrix
Author: DoctorDragon
Author-email: DoctorDragon <river_stream@petalmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Physics
Maintainer: DoctorDragon
Maintainer-email: DoctorDragon <river_stream@petalmail.com>
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/DoctorDragon/honet
Project-URL: Repository, https://github.com/DoctorDragon/honet
Project-URL: Documentation, https://github.com/DoctorDragon/honet/blob/main/README.md
Project-URL: Changelog, https://github.com/DoctorDragon/honet/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/DoctorDragon/honet/issues
Description-Content-Type: text/markdown

# honet

[![PyPI](https://img.shields.io/badge/PyPI-honet-blue)](https://pypi.org/project/honet/)
[![Python](https://img.shields.io/badge/python-3.12%2B-3776AB)](https://www.python.org/)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)

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

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

## 特性

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

## 安装

`honet` 使用 [uv](https://docs.astral.sh/uv/) 管理，所有操作都通过 uv 完成。

作为依赖加入你的项目：

```bash
uv add honet
```

在已有虚拟环境中同步依赖（不修改 `pyproject.toml`）：

```bash
uv sync
```

在临时环境中直接试用，不落盘安装：

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

## 快速开始

```python
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
```

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

```python
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 完成：

```bash
# 安装（含 dev 组：pytest、ruff）
uv sync

# 运行测试
uv run pytest

# 静态检查
uv run ruff check .

# 构建分发包（产物写入 dist/）
uv build
```

## 发布

构建用 uv，校验与上传用 twine（通过 `uvx` 临时执行，不装进项目依赖）：

```bash
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`](.pypirc.example)。版本三通道
（`X.Y.Z.devN` / `X.Y.ZrcN` / `X.Y.Z`）与索引的对应关系、分支与标签策略、
常见失败原因见 [`docs/PUBLISHING.md`](docs/PUBLISHING.md)。

## 许可证

[MIT](LICENSE)
