跳到主内容

v0.32.0 版本说明

EnerOS v0.32.0

发布日期:2026-02-08
版本代号:ML
Git Tag:v0.32.0
支持状态:稳定(Stable)
Crate 总数:60(新增 6 个)
测试用例数:7900+(新增 700)

概述

EnerOS v0.32.0「ML」是智能化阶段的机器学习集成版本,将机器学习能力从「调用外部 LLM」扩展为「内核原生 ML 运行时」。本版本使 EnerOS 能够在内核侧直接运行负荷预测、异常检测、状态估计等电力领域经典 ML 任务,无需依赖外部 Python 服务或离线训练流水线。

ML 版本的核心设计哲学是「电力原生 ML」——模型训练、注册、版本管理、在线推理全部内置于操作系统,与拓扑、潮流、约束、时序等内核一等公民深度耦合。这意味着模型可以订阅拓扑变更事件自动重训练,可以绑定到电气节点随拓扑漂移而迁移,可以在约束引擎内被强制校验输出范围。

本版本引入五大核心能力:机器学习运行时负荷预测模型异常检测引擎模型注册表在线推理服务。所有 ML 能力均通过 eneros-mleneros-ml-forecasteneros-ml-anomalyeneros-ml-registryeneros-ml-serving 五个新 crate 实现。

关键数据

指标数值说明
在线推理延迟 P998msLSTM 模型
负荷预测准确率97.2%日级 MAPE
异常检测召回率94.5%含误报率 2.1%
模型加载时间120ms50MB 模型
新增 Crate6ML 相关
新增测试700+含 90 个端到端

新特性

1. 机器学习运行时

新增 eneros-ml crate,提供统一的 ML 运行时,支持多种模型格式与推理后端。运行时与内核时序引擎深度集成,可直接订阅 PMU/RTU 数据流进行流式推理。

推理后端

后端模型格式适用场景加速
candlesafetensors纯 Rust、嵌入式CPU
ONNX Runtimeonnx通用、跨平台CPU/GPU
TensorFlow Litetflite边缘设备Edge TPU
TensorRTengineGPU 高性能NVIDIA GPU

统一推理接口

use eneros_ml::{MlRuntime, Model, InferRequest};

let runtime = MlRuntime::new()
    .backend(Backend::Candle)
    .device(Device::Cpu)
    .build()?;

// 加载模型(从模型注册表)
let model = runtime.load_model("load-forecast-lstm", Version::Latest).await?;

// 构造推理请求
let input = timeseries.query()
    .point("bus_5_load")
    .range(now() - Duration::hours(24), now())
    .resolution(Duration::minutes(15))
    .fetch().await?;

let request = InferRequest::new()
    .input("history", input.into_tensor())
    .input("temperature", tensor!{24.5})
    .input("is_holiday", tensor!{false});

// 在线推理
let output = model.infer(request).await?;
let forecast: Vec<f64> = output.get("forecast")?.try_into()?;

println!("未来 24 小时负荷预测: {:?}", forecast);

流式推理

// 订阅 PMU 数据流,实时推理
let mut stream = runtime.subscribe_pmu_stream(bus_id, Duration::milliseconds(20));
while let Some(sample) = stream.next().await {
    let anomaly_score = anomaly_model.infer(sample).await?;
    if anomaly_score > threshold {
        ctx.emit(AnomalyDetected { bus: bus_id, score: anomaly_score });
    }
}

2. 负荷预测模型

新增 eneros-ml-forecast crate,内置多种负荷预测模型,覆盖短期、超短期、中长期三个时间尺度。

预测模型矩阵

模型时间尺度精度(MAPE)适用场景
LSTM超短期(15min-4h)1.8%实时调度
Transformer短期(4h-24h)2.3%日前计划
Prophet中期(1-7 天)3.5%周计划
XGBoost长期(7-30 天)4.8%月规划
N-BEATS超长期(30-365 天)6.2%年规划

预测 API

use eneros_ml_forecast::{ForecastEngine, ForecastHorizon, ForecastConfig};

let engine = ForecastEngine::new(&ctx)
    .model("load-forecast-lstm")
    .config(ForecastConfig {
        horizon: ForecastHorizon::ShortTerm(Duration::hours(24)),
        resolution: Duration::minutes(15),
        confidence_interval: 0.95,
        features: vec![
            Feature::HistoricalLoad { window: Duration::hours(168) },
            Feature::Weather { forecast: true },
            Feature::Calendar { holidays: true },
            Feature::TopologyEvent { sensitive: true },
        ],
    })
    .build().await?;

// 执行预测
let forecast = engine.forecast(BusId::from(5)).await?;

// 预测结果包含:点预测、置信区间、特征贡献度
println!("预测点数: {}", forecast.points.len());
println!("95% 置信区间: [{}, {}]",
    forecast.lower_bound[0],
    forecast.upper_bound[0]);

拓扑感知重训练

当电网拓扑发生变更时,模型自动触发重训练:

// 模型订阅拓扑变更事件
forecast_engine.bind_to_topology(&network)?;

network.on_event(TopologyEvent::BusAdded(bus_id), |_| {
    // 新母线加入,自动初始化预测模型
    forecast_engine.init_model_for(bus_id);
});

network.on_event(TopologyEvent::SwitchReconfigured, |_| {
    // 拓扑重构,标记模型需重训练
    forecast_engine.schedule_retrain(Reason::TopologyChange);
});

预测准确率基准

场景LSTMTransformerXGBoost
工作日1.5%2.0%3.2%
周末2.1%2.5%4.1%
节假日3.8%3.2%5.5%
极端天气4.5%3.8%6.8%

3. 异常检测引擎

新增 eneros-ml-anomaly crate,提供多维异常检测能力,覆盖点异常、上下文异常、集合异常三种模式。

检测算法

算法类型适用场景计算开销
Isolation Forest点异常通用
Autoencoder上下文异常时序
DBSCAN集合异常聚类
Statistical (Z-score)点异常快速极低
LSTM-AE上下文异常复杂时序

异常检测 API

use eneros_ml_anomaly::{AnomalyDetector, DetectorConfig, Algorithm};

let detector = AnomalyDetector::new()
    .algorithm(Algorithm::IsolationForest {
        n_trees: 100,
        contamination: 0.02,
    })
    .features(vec![
        "voltage_pu", "current_a", "power_mw", "frequency_hz",
        "temperature_c", "harmonic_thd",
    ])
    .window(Duration::minutes(15))
    .build().await?;

// 实时检测
let detector_handle = detector.run_on_stream(pmu_stream, |anomaly| {
    ctx.emit(AnomalyEvent {
        bus: anomaly.bus_id,
        score: anomaly.score,
        features: anomaly.contributing_features,
        timestamp: anomaly.timestamp,
    });
}).await?;

异常分级

// 根据异常分数与电气影响分级
match anomaly.score {
    s if s > 0.9 => Severity::Critical,  // 立即告警
    s if s > 0.7 => Severity::High,      // 5 分钟内告警
    s if s > 0.5 => Severity::Medium,    // 工单流转
    s if s > 0.3 => Severity::Low,       // 记录观察
    _ => Severity::Info,
}

4. 模型注册表

新增 eneros-ml-registry crate,提供模型的全生命周期管理:版本控制、A/B 测试、灰度发布、回滚。

模型生命周期

阶段状态说明
训练完成staging待评估
评估通过ready待发布
灰度发布canary小流量验证
全量发布production生产环境
归档archived历史版本

注册表 API

use eneros_ml_registry::{ModelRegistry, ModelVersion, Stage};

let registry = ModelRegistry::new(&storage);

// 注册新模型版本
let version = registry.register(ModelVersion::new()
    .name("load-forecast-lstm")
    .version("2.3.0")
    .artifact("/models/lstm-2.3.0.safetensors")
    .metrics(ModelMetrics {
        mape: 1.8,
        rmse: 12.5,
        latency_p99: 8.0,
    })
    .stage(Stage::Staging))?;

// 评估通过后发布
registry.promote("load-forecast-lstm", "2.3.0", Stage::Production).await?;

// 灰度发布(10% 流量)
registry.canary("load-forecast-lstm", "2.3.0", 0.1).await?;

// 回滚到上一版本
registry.rollback("load-forecast-lstm").await?;

模型血缘

// 查看模型血缘关系
let lineage = registry.lineage("load-forecast-lstm", "2.3.0")?;
// 包含:训练数据集、超参数、父模型、衍生模型

5. 在线推理服务

新增 eneros-ml-serving crate,提供高可用的在线推理服务,支持批量推理、缓存、熔断。

服务配置

use eneros_ml_serving::{InferenceServer, ServerConfig};

let server = InferenceServer::new()
    .config(ServerConfig {
        max_concurrent: 256,
        batch_size: 32,
        batch_timeout: Duration::milliseconds(10),
        cache_enabled: true,
        cache_ttl: Duration::minutes(5),
        circuit_breaker: CircuitBreaker {
            failure_threshold: 10,
            recovery_time: Duration::seconds(30),
        },
    })
    .model("load-forecast-lstm", Version::Latest)
    .model("anomaly-detector", Version::Latest)
    .build().await?;

server.serve("0.0.0.0:8080").await?;

批量推理优化

模式延迟 P99吞吐适用场景
单条推理8ms125 QPS实时
批量推理(32)25ms3200 QPS高吞吐
缓存命中0.5ms50000 QPS重复查询

改进

  • 时序引擎eneros-timeseries 新增列式存储压缩,存储空间减少 60%
  • 模型加载:模型文件改用 mmap 加载,启动时间从 2s 降至 120ms
  • GPU 支持:candle 后端新增 CUDA 支持,推理速度提升 8 倍
  • 特征工程:内置 30+ 电力领域特征提取器(谐波、三相不平衡、闪变)
  • 可观测性:ML 推理链路接入 OpenTelemetry,支持全链路追踪

Bug 修复

  • 修复 eneros-ml 在 GPU 推理时显存泄漏的问题(#3205)
  • 修复 eneros-ml-forecast 节假日特征在农历计算上的错误(#3210)
  • 修复 eneros-ml-anomaly Isolation Forest 在高维数据下性能退化的问题(#3218)
  • 修复 eneros-ml-registry 并发注册时版本号冲突的问题(#3222)
  • 修复 eneros-ml-serving 批量推理超时后未清理请求队列的问题(#3228)

破坏性变更

  • MlRuntime::infer:返回类型从 Result<Tensor> 改为 Result<InferResponse>
  • ForecastEngine::forecast:参数从 BusId 改为 &ForecastTarget 枚举
  • AnomalyDetector::algorithm:枚举值重命名,IForest 改为 IsolationForest

升级指南

  1. 更新 Cargo.toml 中的 eneros 依赖至 0.32.0
  2. 安装 ML 运行时依赖:cargo install eneros-ml-cli
  3. eneros.toml 中配置 ML 后端与模型存储路径
  4. 运行 eneros ml migrate 迁移现有模型至注册表

致谢

感谢 25 位贡献者提交的 380+ 个 commit,以及 ML 社区提供的开源模型与算法实现。