---
title: "Rust API"
description: "稳定 Auto 门面、低层算法模块、网络类型和执行函数之间的分层。"
eyebrow: "API Reference"
---

## 稳定 Auto 门面 {#facade}

| 类型 / 函数 | 用途 |
| --- | --- |
| AutoPreset::{Light, Heavy} | 公开预设；default 为 Heavy |
| SlicingMode::{Fixed, Dynamic} | 当前唯一公开切片模式 |
| auto\_path\_preset | 默认 objective、无切片 |
| auto\_path\_preset\_with\_objective | 显式 PlannerObjective |
| auto\_path\_preset\_to\_size | 默认 fixed slicing |
| auto\_path\_preset\_to\_size\_with\_mode\_and\_objective | 显式 mode、objective 与 rate\_enabled |

```rust
use arctn::{
    auto_path_preset_with_objective, AutoPreset,
    PlannerObjective, TensorNetwork,
};

let objective = PlannerObjective::new(1.0, 64.0)?;
let plan = auto_path_preset_with_objective(
    &net, AutoPreset::Heavy, 0, None, objective,
)?;
```

## 核心类型 {#core-types}

| 类型 | 含义 |
| --- | --- |
| TensorNetwork | 整数腿编号、输入张量、输出腿与维度 |
| SsaPath | 每一步引用当前 SSA 节点编号的二元收缩序列 |
| PathStats | 路径模型指标，不是硬件计数器 |
| PlannerObjective | FLOPs 与 read/write 的 per-call 加权 |
| AutoResult | 路径、统计、schedule report 与可选 SliceResult |
| ExecutionPlanNetwork | version 2 中保存的规范化整数标签网络 |
| LoadedExecutionPlan | 验证后的 SSA path、切片和 target 声明 |
| EmbeddedExecutionPlan | self-contained version 2 网络与执行字段 |
| DenseTensor\<T\> | native executor 的行主序稠密张量 |

## Rust execution-plan reader 与 writer {#execution-plan}

| 函数 | 用途 |
| --- | --- |
| complete\_execution\_plan\_v2 | 为 tnpath record 加入 embedded network、schema 和规范化 metadata，并完整验证 |
| parse\_embedded\_execution\_plan | 读取不依赖外部网络的 version 2 artifact |
| parse\_execution\_plan\_for\_network | 读取 version 1、version 2 或显式允许的 legacy artifact，并与调用方网络核对 |

version 1 只保存与外部网络绑定的 identity，因此读取时必须提供网络。version 2 内嵌规范化网络；schema-less legacy 文件仍需要显式 opt-in。

## 低层模块 {#modules}

| 模块 | 职责 | 调用条件 |
| --- | --- | --- |
| paths | greedy、optimal、bisect、budgeted、order DP | 高级用户按算法显式调用 |
| tree | contraction tree、rotation、reconfiguration、annealing、tempering | 必须理解初始路径与参数 |
| simplify | 确定性网络化简与路径 stitch | 可单独使用 |
| slice | 腿选择、slice-and-reconfigure 与 sliced execution | 公开 preset 优先走 Auto 门面 |
| contract / compiled | 一次执行与可复用编译执行 | 需要合法 SSA path |

> **API 分层**
>
> Rust 低层算法组件并不自动变成新的 Python `slicing_mode` 或 Auto preset。公开产品面与研究组件应分开理解。

## 固定路径切片与执行 {#sliced}

```rust
use arctn::{
    auto_path_preset_to_size, contract_network_sliced,
    AutoPreset,
};

let plan = auto_path_preset_to_size(
    &net, AutoPreset::Heavy, 0, None, 1 << 24,
)?;
let slice = plan.slice.as_ref().ok_or("missing slice plan")?;
let out = contract_network_sliced(
    &net, &tensors, &plan.path, &slice.legs,
)?;
```
