Files
SystemSimulationApp/app/simulation/backends.py
T
lujingze 3bc4be3c06 优化原生结果编码传输与浏览器缓存,记录八路性能基线
原生结果series通过字节索引直传,C端使用Ryu精确回读编码和64 KiB批量写出;网页采用Float64缓存和CSV工作线程,减少结果处理与保存等待。

补充八路AME曲线核查、全流程分阶段计时、独立编码基准和复现工具,固定后续优化采用修正八路及rtol=1e-8。C写出1.1808→0.1638 s,点击到可查看8.0100→6.9756 s。

验证:最终10项编码专项、29项相关后端回归通过;8份原生结果逐位一致,16次网页结果/CSV/刷新恢复通过。前端构建及缓存/CSV专项在本轮结果处理工作中通过。环境、原始大结果与临时构建不纳入Git。
2026-09-11 15:09:15 +00:00

39 lines
1.6 KiB
Python

"""One execution boundary shared by XML API and native validation tools."""
from __future__ import annotations
import os
from app.simulation.config import SolveIVPConfig
DEFAULT_NUMERIC_ENGINE = "native"
def numeric_engine_name(backend: str | None = None) -> str:
configured = backend or os.environ.get("SIMULATION_NUMERIC_ENGINE", "")
selected = configured.strip().lower() or DEFAULT_NUMERIC_ENGINE
if selected == "native-c":
return "native"
if selected == "native":
return selected
if selected == "python":
raise ValueError("The Python numerical backend has been removed. Use SIMULATION_NUMERIC_ENGINE=native.")
raise ValueError(f"Unknown simulation engine: {selected}.")
def simulation_config(simulation) -> SolveIVPConfig:
# Match the validated native pipe/chamber accuracy. Per-state SI absolute
# floors are emitted by native_codegen.tolerances; XML tolerance fields
# remain a separate protocol change.
return SolveIVPConfig(t_start=simulation.t_start, t_stop=simulation.t_stop,
method=simulation.method, rtol=1e-8, max_step=simulation.max_step)
def simulate_network(network, simulation, *, progress_callback=None,
cancel_check=None, activity_tracker=None, backend=None, raw_series=False):
numeric_engine_name(backend)
config = simulation_config(simulation)
from app.simulation.native_codegen.runner import simulate_native
return simulate_native(network, config, sample_step=simulation.sample_step, progress_callback=progress_callback,
cancel_check=cancel_check, activity_tracker=activity_tracker, raw_series=raw_series)