优化仿真求解性能并修复流量闭合问题(初版)
This commit is contained in:
1 parent
57b459bc72
commit
5332a788f3
55 files changed
+8973
-549
No files matched your search
@@ -58,21 +58,6 @@ def _load_factory_xml(specification: str) -> bytes:
|
||||
return build_reactflow_system_xml(value)
|
||||
|
||||
|
||||
def _clear_property_caches() -> None:
|
||||
from app.simulation.components.amesim.media.mediums import (
|
||||
AmesimHeliumPengRobinsonMedium,
|
||||
)
|
||||
|
||||
for method_name in (
|
||||
"temperature_from_pressure_enthalpy",
|
||||
"properties_from_mU",
|
||||
):
|
||||
method = getattr(AmesimHeliumPengRobinsonMedium, method_name)
|
||||
cache_clear = getattr(method, "cache_clear", None)
|
||||
if cache_clear is not None:
|
||||
cache_clear()
|
||||
|
||||
|
||||
def _serialize_result_event(result: dict[str, object]) -> bytes:
|
||||
"""Render the final NDJSON payload shape used by the streaming endpoint."""
|
||||
|
||||
@@ -98,15 +83,12 @@ def _run_case(
|
||||
warmups: int,
|
||||
runs: int,
|
||||
cancellable_path: bool,
|
||||
clear_property_cache: bool,
|
||||
allow_failures: bool,
|
||||
) -> dict[str, object]:
|
||||
from app.main import run_system_xml_simulation
|
||||
|
||||
cancel_check = (lambda: False) if cancellable_path else None
|
||||
for _ in range(warmups):
|
||||
if clear_property_cache:
|
||||
_clear_property_caches()
|
||||
result = run_system_xml_simulation(xml_bytes, cancel_check=cancel_check)
|
||||
if not bool(result.get("success")) and not allow_failures:
|
||||
raise RuntimeError(f"Warmup for {name!r} failed: {result.get('message')}")
|
||||
@@ -118,8 +100,6 @@ def _run_case(
|
||||
profiles: list[dict[str, object]] = []
|
||||
final_result: dict[str, object] | None = None
|
||||
for _ in range(runs):
|
||||
if clear_property_cache:
|
||||
_clear_property_caches()
|
||||
wall_start = perf_counter_ns()
|
||||
cpu_start = process_time_ns()
|
||||
result = run_system_xml_simulation(xml_bytes, cancel_check=cancel_check)
|
||||
@@ -190,9 +170,9 @@ def _parse_arguments(argv: list[str] | None = None) -> argparse.Namespace:
|
||||
help="Do not pass a cancel callback; use the one-shot SciPy path when eligible.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cold-property-cache",
|
||||
"--disable-property-cache",
|
||||
action="store_true",
|
||||
help="Clear the two helium property LRU caches before every warmup and measured run.",
|
||||
help="Disable the run-local exact property cache for an A/B comparison.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--allow-failures",
|
||||
@@ -213,6 +193,9 @@ def _parse_arguments(argv: list[str] | None = None) -> argparse.Namespace:
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
arguments = _parse_arguments(argv)
|
||||
os.environ["SIMULATIONAPP_PROFILE"] = arguments.mode
|
||||
os.environ["SIMULATIONAPP_PROPERTY_CACHE"] = (
|
||||
"off" if arguments.disable_property_cache else "on"
|
||||
)
|
||||
|
||||
cases: list[tuple[str, bytes]] = []
|
||||
for raw_case in arguments.xml:
|
||||
@@ -226,7 +209,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
"generatedAt": datetime.now(UTC).isoformat(),
|
||||
"profileMode": arguments.mode,
|
||||
"cancellableSolverPath": not arguments.direct_path,
|
||||
"coldPropertyCache": bool(arguments.cold_property_cache),
|
||||
"propertyCacheEnabled": not arguments.disable_property_cache,
|
||||
"allowFailures": bool(arguments.allow_failures),
|
||||
"warmups": arguments.warmups,
|
||||
"runs": arguments.runs,
|
||||
@@ -242,7 +225,6 @@ def main(argv: list[str] | None = None) -> int:
|
||||
warmups=arguments.warmups,
|
||||
runs=arguments.runs,
|
||||
cancellable_path=not arguments.direct_path,
|
||||
clear_property_cache=arguments.cold_property_cache,
|
||||
allow_failures=arguments.allow_failures,
|
||||
)
|
||||
for name, xml_bytes in cases
|
||||
|
||||
Reference in new issue
Block a user