胡言乱语
- 作者仓库星标 3,367
- 许可证 MIT
- 作者仓库 atopile
- 领域
- 通用
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @atopile · MIT
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- macOS · Linux · Windows
- 运行环境要求
- Node.js · Python
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 命令执行
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
import faebryk.core.faebrykpy as fbrk
import faebryk.core.graph as graph
import faebryk.core.node as fabll
g = graph.GraphView.create()
tg = fbrk.TypeGraph.create(g=g)
class _App(fabll.Node):
pass
app = _App.bind_typegraph(tg=tg).create_instance(g=g)
# FabLL (Fabric Low Level) Module
`fabll` (primarily `src/faebryk/core/node.py`) is the high-level Python API for defining and working with hardware components. It bridges the gap between Python classes and the underlying `TypeGraph` and instance graph.
## Quick Start
```python
import faebryk.core.faebrykpy as fbrk
import faebryk.core.graph as graph
import faebryk.core.node as fabll
g = graph.GraphView.create()
tg = fbrk.TypeGraph.create(g=g)
class _App(fabll.Node):
pass
app = _App.bind_typegraph(tg=tg).create_instance(g=g)
```
## Relevant Files
- `src/faebryk/core/node.py` (Node/Traits/fields, type registration, binding/instantiation helpers)
- `src/faebryk/core/faebrykpy.py` (edge types used by FabLL under the hood)
- `src/faebryk/core/graph.py` (GraphView wrapper used by instances)
## Dependants (Call Sites)
- **Library (`src/faebryk/library/`)**: Every component (Resistor, Capacitor, etc.) inherits from `Node`.
- **Compiler**: Generates `Node` subclasses dynamically from `ato` files.
- **Solvers**: Operate on `Node` instances to extract parameters and constraints.
## How to Work With / Develop / Test
### Core Concepts
- **Nodes are wrappers over graph instances**: a `fabll.Node` is constructed with a `graph.BoundNode`.
- **Declaration via class attributes**:
- structural children: `SomeType.MakeChild(...)`
- trait attachments: `Traits.MakeEdge(SomeTrait.MakeChild().put_on_type())` (or similar)
- **Binding**:
- type binding: `MyType.bind_typegraph(tg)`
- instance creation: `.create_instance(g)`
- **Type identifiers**:
- library types (`faebryk.library.*`) intentionally have short identifiers (class name) for ato imports
- non-library types include a module-derived suffix; type IDs must be unique (enforced in `Node._register_type`)
### Development Workflow
1) Prefer adding behavior as a Trait rather than deepening class hierarchies.
2) If you need a new structural relation/field kind, it lives in `src/faebryk/core/node.py` (field system).
3) Keep an eye on invariants enforced at class creation time (metaclass + `__init_subclass__`).
### Testing
- Core tests: `ato dev test --llm test/core/test_node.py -q` and `ato dev test --llm test/library/test_traits.py -q`
## Best Practices
- **Prefer Traits**: Don't add methods to `Node` subclasses if they can be a Trait. This allows them to be applied to different component families.
- **Avoid deep inheritance**: FabLL enforces single-level subclassing for node types (`Node.__init_subclass__`).
- **Type-safe traversal**: when you must traverse trait edges manually, prefer `EdgeTrait.traverse(trait_type=...)`.
## Internals & Runtime Behavior
### Instantiation & Lifecycle
- **Don’t call `MyNode()` with no args**: instances are created from a bound type via `bind_typegraph(...).create_instance(...)`.
- **TypeGraph context is required**:
```python
import faebryk.core.graph as graph
import faebryk.core.faebrykpy as fbrk
g = graph.GraphView.create()
tg = fbrk.TypeGraph.create(g=g)
inst = MyNode.bind_typegraph(tg).create_instance(g=g)
```
- **Single-level subclassing invariant**: `Node.__init_subclass__` forbids “deeper than one level” inheritance for node types.
### Trait Implementation
- **Traits are Nodes**: Traits are not just Python mixins; they are `Node` subclasses that typically contain an `ImplementsTrait` edge.
- **Trait Definition**:
```python
class MyTrait(Node):
is_trait = Traits.MakeEdge(ImplementsTrait.MakeChild().put_on_type())
```
- **Resolution**: Use `node_instance.get_trait(TraitType)` to retrieve a trait instance. This performs a graph traversal.
### Performance & Memory
- **Type Creation**: Creating a type involves significant overhead (executing fields, resolving dependencies). Once created, instantiating instances is faster but still involves allocation in the Zig backend.
- **Tree Structure**: Nodes are linked via `EdgeComposition`. `add_child` creates this edge. Large trees (10k+ nodes) should be constructed carefully to avoid Python loop overhead; the underlying graph is efficient, but Python interactions cost time.
章节与文件索引
按说明文件中的顺序排列。
相关文件
家属(呼叫站点)
核心概念
开发流程
测试
文件/命令 -> fabll · src/faebryk/core/node.py · TypeGraph · src/faebryk/core/faebrykpy.py · src/faebryk/core/graph.py · src/faebryk/library/ · Node · ato
内容校验值 -> 082d2390334e
当前原文的自动摘译,尚未人工审校。
相关文件
src/faebryk/core/node.py(节点/特征/字段、类型注册、绑定/实例化助手)src/faebryk/core/faebrykpy.py(FabLL 在底层使用的边缘类型)src/faebryk/core/graph.py(实例使用的 GraphView 包装器)家属(呼叫站点)
库(
src/faebryk/library/):每个组件(电阻、电容等)都继承自Node。编译器:从ato文件动态生成Node子类。求解器:对Node实例进行操作以提取参数和约束。核心概念
节点是图实例的包装器:
fabll.Node是用graph.BoundNode构造的。通过类属性声明:结构子项:SomeType.MakeChild(...)特征附件:Traits.MakeEdge(SomeTrait.MakeChild().put_on_type())(或类似)绑定:开发流程
更喜欢将行为添加为特质,而不是加深阶级层次结构。如果您需要新的结构关系/字段类型,它位于
src/faebryk/core/node.py(字段系统)中。密切关注在类创建时强制执行的不变量(元类 +__init_subclass__)。测试
核心测试:
ato dev test --llm test/core/test_node.py -q和ato dev test --llm test/library/test_traits.py -q