fly_ruler_std.runtime.record
本页由
fr-docs-dev gen-api从源码 docstring 生成,请勿手工编辑;重新生成执行just api。
记录子包:同步与异步记录器、数据加载器及列布局工具。
公开成员
| 名称 | 类型 | 定义位置 |
|---|---|---|
Recorder | 类 | 本页 |
AsyncRecorder | 类 | 本页 |
Loader | 类 | 本页 |
RecordSample | 类 | 本页 |
定义
Recorder
python
class Recorder(model: RuntimeInstance[ArrayT] | BatchModel[ArrayT], output_dir: Path | str = './results')把仿真样本规范化为扁平数组并写出 parquet 与元数据的记录器。
__init__
重载
| 调用形式 | 返回类型 |
|---|---|
__init__(model: BatchModel[ArrayT], output_dir: Path | str = './results') | None |
__init__(model: RuntimeInstance[ArrayT], output_dir: Path | str = './results') | None |
构造记录器并准备输出目录。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
model | BatchModel[ArrayT] | RuntimeInstance[ArrayT] | — | 提供单实例变量布局的标量或批量已编译模型。 |
output_dir | Path | str | './results' | parquet 与元数据的输出目录,默认 ./results。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:54
model
python
model = model用于规范化取值与生成列名的已编译模型。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:65
output_dir
python
output_dir = Path(output_dir)parquet 与元数据的输出目录,构造时创建。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:67
record
python
def record(step: int, time: float, x: RecordValue = None, xd: RecordValue = None, y: RecordValue = None, u: RecordValue = None, p: RecordValue = None, effect: RecordValue = None, batch_idx: int = 0) -> None记录一个仿真样本。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
step | int | — | 仿真步数索引。 |
time | float | — | 仿真时间,单位秒。 |
x | RecordValue | None | 连续状态,支持数组、序列或路径映射;None 表示不记录。 |
xd | RecordValue | None | 离散状态,取值形式同 x。 |
y | RecordValue | None | 输出,取值形式同 x。 |
u | RecordValue | None | 输入,取值形式同 x。 |
p | RecordValue | None | 参数,取值形式同 x。 |
effect | RecordValue | None | 效果或探测量,取值形式同 x。 |
batch_idx | int | 0 | 批次索引,默认 0。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:88
record_batch
python
def record_batch(times: ArrayLike, x: ArrayLike | None = None, xd: ArrayLike | None = None, y: ArrayLike | None = None, u: ArrayLike | None = None, p: ArrayLike | None = None, effect: ArrayLike | None = None) -> None记录成批仿真数据。
times 形状为 (steps,) 或 (batch, steps);其余数组形状为 (batch, steps, dim),而 p 也可为 (batch, dim) 并在各步重复。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
times | ArrayLike | — | 时间序列,形状 (steps,) 或 (batch, steps)。 |
x | ArrayLike | None | None | 连续状态,形状 (batch, steps, dim)。 |
xd | ArrayLike | None | None | 离散状态,形状 (batch, steps, dim)。 |
y | ArrayLike | None | None | 输出,形状 (batch, steps, dim)。 |
u | ArrayLike | None | None | 输入,形状 (batch, steps, dim)。 |
p | ArrayLike | None | None | 参数,形状 (batch, steps, dim) 或 (batch, dim)。 |
effect | ArrayLike | None | None | 效果或探测量,形状 (batch, steps, dim)。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | 数据批大小与绑定的批量模型视图不一致时抛出。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:124
clear
python
def clear() -> None清空已记录样本与活跃变量类别。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:181
save
python
def save(filename: str = 'simulation_data') -> None把已记录数据写为 parquet 与 JSON 元数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
filename | str | 'simulation_data' | 输出文件名(不含扩展名),默认 simulation_data。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:186
get_dataframe
python
def get_dataframe(batch_id: int | None = None) -> pl.DataFrame返回当前记录的列式快照,可显式筛选batch,无需保存文件。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
batch_id | int | None | None | 可选轨迹编号,None保留全部轨迹。 |
返回
| 类型 | 说明 |
|---|---|
pl.DataFrame | 与保存Parquet相同布局的Polars数据表。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:218
samples
python
samples: tuple[RecordSample, ...]已记录样本的不可变快照。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:235
metadata
python
metadata: JsonObject元数据字典的浅拷贝,含时间戳与编译模型信息。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:240
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/recorder.py:37
AsyncRecorder
python
class AsyncRecorder(model: RuntimeInstance[ArrayT] | BatchModel[ArrayT], output_dir: Path | str = './results', max_queue_size: int = 0, drop_policy: DropPolicy = 'raise')用 asyncio 队列包装 Recorder 的非阻塞异步记录器。
取值进入队列前已规范化并复制,工作协程只把扁平 numpy 数组转交 Recorder.record,parquet 写入仍在线程池中执行。
__init__
重载
| 调用形式 | 返回类型 |
|---|---|
__init__(model: BatchModel[ArrayT], output_dir: Path | str = './results', max_queue_size: int = 0, drop_policy: DropPolicy = 'raise') | None |
__init__(model: RuntimeInstance[ArrayT], output_dir: Path | str = './results', max_queue_size: int = 0, drop_policy: DropPolicy = 'raise') | None |
构造异步记录器。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
model | BatchModel[ArrayT] | RuntimeInstance[ArrayT] | — | 提供单实例变量布局的标量或批量已编译模型。 |
output_dir | Path | str | './results' | parquet 与元数据的输出目录,默认 ./results。 |
max_queue_size | int | 0 | 队列容量;0 表示无界。 |
drop_policy | DropPolicy | 'raise' | 队列满时的策略,raise、drop_newest 或 drop_oldest,默认 raise。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | max_queue_size 为负数或 drop_policy 不是允许值。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:70
recorder
python
recorder = cast(Recorder[ArrayT], Recorder(model, output_dir))底层同步记录器。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:95
drop_policy
python
drop_policy = drop_policy队列满时采用的丢弃策略。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:97
pending
python
pending: int当前队列中待处理样本的数量。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:106
start
python
def start() -> None启动后台工作协程,已启动则不重复创建。
异常
| 类型 | 说明 |
|---|---|
RuntimeError | 记录器已关闭。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:110
record
python
def record(step: int, time: float, x: RecordValue = None, xd: RecordValue = None, y: RecordValue = None, u: RecordValue = None, p: RecordValue = None, effect: RecordValue = None, batch_idx: int = 0) -> None把单个样本放入队列并在需要时启动工作协程。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
step | int | — | 仿真步数索引。 |
time | float | — | 仿真时间,单位秒。 |
x | RecordValue | None | 连续状态,支持数组、序列或路径映射;None 表示不记录。 |
xd | RecordValue | None | 离散状态,取值形式同 x。 |
y | RecordValue | None | 输出,取值形式同 x。 |
u | RecordValue | None | 输入,取值形式同 x。 |
p | RecordValue | None | 参数,取值形式同 x。 |
effect | RecordValue | None | 效果或探测量,取值形式同 x。 |
batch_idx | int | 0 | 批次索引,默认 0。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:122
record_nowait
python
def record_nowait(*, step: int, time: float, x: RecordValue = None, xd: RecordValue = None, y: RecordValue = None, u: RecordValue = None, p: RecordValue = None, effect: RecordValue = None, batch_idx: int = 0) -> bool尝试立即把单个样本放入队列,不等待队列腾出空间。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
step | int | — | 仿真步数索引。 |
time | float | — | 仿真时间,单位秒。 |
x | RecordValue | None | 连续状态,支持数组、序列或路径映射;None 表示不记录。 |
xd | RecordValue | None | 离散状态,取值形式同 x。 |
y | RecordValue | None | 输出,取值形式同 x。 |
u | RecordValue | None | 输入,取值形式同 x。 |
p | RecordValue | None | 参数,取值形式同 x。 |
effect | RecordValue | None | 效果或探测量,取值形式同 x。 |
batch_idx | int | 0 | 批次索引,默认 0。 |
返回
| 类型 | 说明 |
|---|---|
bool | True 表示已入队;策略丢弃或替换旧样本时返回 False。 |
异常
| 类型 | 说明 |
|---|---|
RuntimeError | 记录器已关闭。 |
asyncio.QueueFull | 队列已满且策略为 raise。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:162
flush
python
def flush() -> None等待队列中所有样本被处理完毕。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:223
save
python
def save(filename: str = 'simulation_data') -> None先清空队列,再在线程池中写出数据文件。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
filename | str | 'simulation_data' | 输出文件名(不含扩展名),默认 simulation_data。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:228
close
python
def close(*, save: bool = False, filename: str = 'simulation_data') -> None关闭记录器并回收后台工作协程,重复调用无副作用。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
save | bool | False | 关闭前是否写出数据文件,默认 False。 |
filename | str | 'simulation_data' | save 为 True 时使用的文件名。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:237
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/async_recorder.py:45
Loader
python
class Loader(data_dir: Path | str, filename: str = 'simulation_data', *, model: RuntimeInstance | BatchModel | None = None)读取 Recorder 写出的 parquet 与 JSON 元数据。
通过保存的 spaces 可独立按完整路径访问变量与元数据,支持索引、时间区间与批次过滤;也可显式提供匹配的 RuntimeInstance 解析模型路径。
python
loader = Loader("./results_step", model=compiled_model)
x_data = loader.get_x("Root.ss::x") # 全部步, 形状 (N, 2)
x0 = loader.get_x("Root.ss::x", index=0) # 只取第一个元素
subset = loader.get_x(time_range=(0.0, 1.0)) # 按时间过滤__init__
python
def __init__(data_dir: Path | str, filename: str = 'simulation_data', *, model: RuntimeInstance | BatchModel | None = None) -> None从输出目录加载 parquet 与元数据并建立路径索引。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
data_dir | Path | str | — | 存放 parquet 与元数据的目录。 |
filename | str | 'simulation_data' | 数据文件名(不含扩展名),默认 simulation_data。 |
model | RuntimeInstance | BatchModel | None | None | 可选匹配模型;提供时按其变量视图解析路径。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:51
get_dataframe
python
def get_dataframe(batch_id: int | None = None) -> pl.DataFrame返回底层数据表,可按批次过滤。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
batch_id | int | None | None | 批次索引;None 表示不按批次过滤。 |
返回
| 类型 | 说明 |
|---|---|
pl.DataFrame | 与 Recorder 相同列布局的 Polars DataFrame。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:279
get_x
python
def get_x(path: str | None = None, index: int | None = None, time_range: tuple[float, float] | None = None, *, batch_id: int | None = None) -> np.ndarray取连续状态数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path | str | None | None | 完整信号路径;None 表示该空间的全部列。 |
index | int | None | None | 非标量信号最后一维的索引;标量信号忽略。 |
time_range | tuple[float, float] | None | None | (起, 止) 时间区间,闭区间,单位秒。 |
batch_id | int | None | None | 批次索引;None 表示不按批次过滤。 |
返回
| 类型 | 说明 |
|---|---|
np.ndarray | 形状 (记录数, 维度) 的数组;对标量信号使用 index 时为一维。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:293
get_xd
python
def get_xd(path: str | None = None, index: int | None = None, time_range: tuple[float, float] | None = None, *, batch_id: int | None = None) -> np.ndarray取离散状态数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path | str | None | None | 完整信号路径;None 表示该空间的全部列。 |
index | int | None | None | 非标量信号最后一维的索引;标量信号忽略。 |
time_range | tuple[float, float] | None | None | (起, 止) 时间区间,闭区间,单位秒。 |
batch_id | int | None | None | 批次索引;None 表示不按批次过滤。 |
返回
| 类型 | 说明 |
|---|---|
np.ndarray | 形状 (记录数, 维度) 的数组;对标量信号使用 index 时为一维。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:314
get_y
python
def get_y(path: str | None = None, index: int | None = None, time_range: tuple[float, float] | None = None, *, batch_id: int | None = None) -> np.ndarray取输出数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path | str | None | None | 完整信号路径;None 表示该空间的全部列。 |
index | int | None | None | 非标量信号最后一维的索引;标量信号忽略。 |
time_range | tuple[float, float] | None | None | (起, 止) 时间区间,闭区间,单位秒。 |
batch_id | int | None | None | 批次索引;None 表示不按批次过滤。 |
返回
| 类型 | 说明 |
|---|---|
np.ndarray | 形状 (记录数, 维度) 的数组;对标量信号使用 index 时为一维。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:335
get_u
python
def get_u(path: str | None = None, index: int | None = None, time_range: tuple[float, float] | None = None, *, batch_id: int | None = None) -> np.ndarray取输入数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path | str | None | None | 完整信号路径;None 表示该空间的全部列。 |
index | int | None | None | 非标量信号最后一维的索引;标量信号忽略。 |
time_range | tuple[float, float] | None | None | (起, 止) 时间区间,闭区间,单位秒。 |
batch_id | int | None | None | 批次索引;None 表示不按批次过滤。 |
返回
| 类型 | 说明 |
|---|---|
np.ndarray | 形状 (记录数, 维度) 的数组;对标量信号使用 index 时为一维。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:356
get_p
python
def get_p(path: str | None = None, index: int | None = None, time_range: tuple[float, float] | None = None, *, batch_id: int | None = None) -> np.ndarray取参数数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path | str | None | None | 完整信号路径;None 表示该空间的全部列。 |
index | int | None | None | 非标量信号最后一维的索引;标量信号忽略。 |
time_range | tuple[float, float] | None | None | (起, 止) 时间区间,闭区间,单位秒。 |
batch_id | int | None | None | 批次索引;None 表示不按批次过滤。 |
返回
| 类型 | 说明 |
|---|---|
np.ndarray | 形状 (记录数, 维度) 的数组;对标量信号使用 index 时为一维。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:377
get_effect
python
def get_effect(path: str | None = None, index: int | None = None, time_range: tuple[float, float] | None = None, *, batch_id: int | None = None) -> np.ndarray取效果或探测数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path | str | None | None | 完整信号路径;None 表示该空间的全部列。 |
index | int | None | None | 非标量信号最后一维的索引;标量信号忽略。 |
time_range | tuple[float, float] | None | None | (起, 止) 时间区间,闭区间,单位秒。 |
batch_id | int | None | None | 批次索引;None 表示不按批次过滤。 |
返回
| 类型 | 说明 |
|---|---|
np.ndarray | 形状 (记录数, 维度) 的数组;对标量信号使用 index 时为一维。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:398
info
python
def info(kind: RecordKind, path: str) -> VariableInfo读取记录自身保存的变量元数据,不要求绑定原模型。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
kind | RecordKind | — | 记录空间 x/xd/y/u/p/effect;诊断量使用单数 effect。 |
path | str | — | 声明的完整公开路径,不使用短名推测身份。 |
返回
| 类型 | 说明 |
|---|---|
VariableInfo | 含逻辑 dtype、单位、说明、原始形状和扁平槽位的只读描述。 |
异常
| 类型 | 说明 |
|---|---|
KeyError | 记录未保存该变量元数据,包括不带 spaces 的旧记录。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:423
metadata
python
metadata: JsonObject从 JSON 加载的完整元数据字典。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:443
columns
python
columns: list[str]元数据中记录的列名列表。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:448
total_records
python
total_records: int记录总数。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:456
timestamp
python
timestamp: str | None最初记录时的时间戳。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:462
save_timestamp
python
save_timestamp: str | None数据保存时的时间戳。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:468
batches
python
batches: list[int]数据中出现过的批次索引,升序排列。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:474
time_range
python
time_range: tuple[float, float]数据中的最小与最大仿真时间,单位秒。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:479
compiled_model_info
python
compiled_model_info: JsonObject已保存的编译模型元数据;不存在时为空字典。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:487
dataframe
python
dataframe: pl.DataFrame底层原始 Polars DataFrame。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:493
model
python
model: RuntimeInstance | BatchModel | None用于路径解析的已编译模型。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:498
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/loader.py:34
RecordSample
python
class RecordSample(batch_idx: int, step: int, time: float, values: Mapping[RecordKind, RecordArray])一次记录调用的样本,含批次、步数与各变量空间的扁平值。
batch_idx
python
batch_idx: int批次索引,用于区分并行轨迹。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/layout.py:33
step
python
step: int仿真步数索引。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/layout.py:36
time
python
time: float仿真时间,单位秒。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/layout.py:39
values
python
values: Mapping[RecordKind, RecordArray]变量空间类别到扁平 float64 数组的映射,仅含本次提供的类别。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/layout.py:42
__init__
python
def __init__(batch_idx: int, step: int, time: float, values: Mapping[RecordKind, RecordArray]) -> None实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/layout.py
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/record/layout.py:29
签名类型说明
以下别名用于解释参数与返回值,不是本包的公开导出对象。
| 内部别名 | 类型定义 |
|---|---|
ArrayLike | type ArrayLike = np.ndarray | CasadiArray | JaxArray | Sequence[float] | Sequence[Sequence[float]] | float | int |
DropPolicy | type DropPolicy = Literal['raise', 'drop_newest', 'drop_oldest'] |
JsonObject | type JsonObject = dict[str, JsonValue] |
JsonValue | type JsonValue = str | int | float | bool | None | list['JsonValue'] | dict[str, 'JsonValue'] |
RecordArray | type RecordArray = NumpyArray |
RecordKind | type RecordKind = Literal['x', 'xd', 'y', 'u', 'p', 'effect'] |
RecordValue | type RecordValue = ArrayLike | Mapping[str, ArrayLike] | None |