processforge 0.3.5__tar.gz → 0.3.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {processforge-0.3.5/src/processforge.egg-info → processforge-0.3.9}/PKG-INFO +4 -1
- {processforge-0.3.5 → processforge-0.3.9}/flowsheets/openmc/msre_eigenvalue.json +5 -5
- {processforge-0.3.5 → processforge-0.3.9}/pyproject.toml +5 -1
- processforge-0.3.9/src/processforge/api/serve.py +94 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/__init__.py +1 -1
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/apply.py +2 -1
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/common.py +45 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/display.py +55 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/init.py +100 -16
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/plan.py +11 -3
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/run.py +2 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/compose.py +20 -8
- processforge-0.3.9/src/processforge/lock.py +74 -0
- processforge-0.3.9/src/processforge/utils/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9/src/processforge.egg-info}/PKG-INFO +4 -1
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge.egg-info/SOURCES.txt +2 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge.egg-info/requires.txt +4 -0
- {processforge-0.3.5 → processforge-0.3.9}/tests/test_cli.py +42 -0
- {processforge-0.3.5 → processforge-0.3.9}/tests/test_init.py +32 -14
- processforge-0.3.5/src/processforge/lock.py +0 -41
- {processforge-0.3.5 → processforge-0.3.9}/LICENSE +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/MANIFEST.in +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/README.md +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/flowsheets/closed-loop-chain.json +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/flowsheets/custom/crimson/MUWS_HB.json +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/flowsheets/custom/simple_hyrdaulic_scheme.json +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/flowsheets/festim/hydrogen_transport_1d.json +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/flowsheets/hydraulic-chain.json +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/setup.cfg +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/__main__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/_schema.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/analysis/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/analysis/dof.py +0 -0
- {processforge-0.3.5/src/processforge/utils → processforge-0.3.9/src/processforge/api}/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/diagram.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/export_fmu.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/export_modelica.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/cli/validate.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/backends/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/backends/base.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/backends/casadi_backend.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/backends/pyomo_backend.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/backends/scipy_backend.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/flowsheet.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/jacobian.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/mixin.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/solver.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/stream_var.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/units/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/units/flash_eo.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/units/heater_eo.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/units/pipes_eo.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/units/pump_eo.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/units/strainer_eo.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/eo/units/valve_eo.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/flowsheet.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/fmu/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/fmu/_fmi_vars.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/fmu/builder.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/fmu/slave_template.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/modelica/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/modelica/mo_writer.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/modelica/omc_runner.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/modelica/transpiler.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/modelica/unit_equations.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/pcl/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/pcl/compiler.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/pcl/namespace.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/provenance.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/base.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/base_jacobian_mixin.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/cantera_jacobian.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/cantera_provider.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/container_client.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/coolprop_provider.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/festim_provider.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/jacobian_contributor.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/manager.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/modelica_jacobian.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/modelica_provider.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/openmc_provider.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/reference_state_registry.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/providers/registry.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/result.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/result_schema.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/schemas/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/schemas/flowsheet_schema.json +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/schemas/openmc/openmc_model.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/simulate.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/solver.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/state.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/thermo.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/types.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/__init__.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/base.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/cstr.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/flash.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/heater.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/pfr.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/pipes.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/pump.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/registry.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/solver_unit.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/strainer.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/tank.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/units/valve.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/utils/flowsheet_diagram.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/utils/mermaid_diagram.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/utils/topology.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/utils/unit_consistency.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/utils/validate_flowsheet.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge/utils/validation.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge.egg-info/dependency_links.txt +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge.egg-info/entry_points.txt +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/src/processforge.egg-info/top_level.txt +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/tests/test_festim_provider.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/tests/test_providers.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/tests/test_state.py +0 -0
- {processforge-0.3.5 → processforge-0.3.9}/tests/test_types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: processforge
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.9
|
|
4
4
|
Summary: A Python-based process simulation framework for chemical engineering applications.
|
|
5
5
|
Author-email: Processforge Team <team@processforge.dev>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -30,6 +30,9 @@ Requires-Dist: pandas>=2.2
|
|
|
30
30
|
Requires-Dist: zarr>=3.0
|
|
31
31
|
Requires-Dist: coolprop>=7.2.0
|
|
32
32
|
Requires-Dist: typer>=0.12
|
|
33
|
+
Provides-Extra: api
|
|
34
|
+
Requires-Dist: fastapi>=0.110; extra == "api"
|
|
35
|
+
Requires-Dist: uvicorn>=0.29; extra == "api"
|
|
33
36
|
Provides-Extra: eo
|
|
34
37
|
Requires-Dist: pyomo>=6.7; extra == "eo"
|
|
35
38
|
Provides-Extra: eo-casadi
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"id": 1,
|
|
18
18
|
"density": 2.26,
|
|
19
19
|
"density_units": "g/cm3",
|
|
20
|
-
"temperature":
|
|
20
|
+
"temperature": 300.0,
|
|
21
21
|
"elements": [
|
|
22
22
|
{ "element": "C", "percent": 1.0, "percent_type": "ao" }
|
|
23
23
|
]
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"id": 2,
|
|
27
27
|
"density": 9.0,
|
|
28
28
|
"density_units": "g/cm3",
|
|
29
|
-
"temperature":
|
|
29
|
+
"temperature": 400.0,
|
|
30
30
|
"elements": [
|
|
31
31
|
{ "element": "Ni", "percent": 0.72, "percent_type": "wo" },
|
|
32
32
|
{ "element": "Mo", "percent": 0.16, "percent_type": "wo" },
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"id": 3,
|
|
39
39
|
"density": 2.2,
|
|
40
40
|
"density_units": "g/cm3",
|
|
41
|
-
"temperature":
|
|
41
|
+
"temperature": 300.0,
|
|
42
42
|
"depletable": true,
|
|
43
43
|
"nuclides": [
|
|
44
44
|
{ "name": "Li7", "percent": 0.335000, "percent_type": "ao" },
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"id": 4,
|
|
56
56
|
"density": 8.9,
|
|
57
57
|
"density_units": "g/cm3",
|
|
58
|
-
"temperature":
|
|
58
|
+
"temperature": 300.0,
|
|
59
59
|
"elements": [
|
|
60
60
|
{ "element": "Ni", "percent": 0.72, "percent_type": "ao" },
|
|
61
61
|
{ "element": "Cr", "percent": 0.20, "percent_type": "ao" },
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"id": 5,
|
|
67
67
|
"density": 1.0e-4,
|
|
68
68
|
"density_units": "g/cm3",
|
|
69
|
-
"temperature":
|
|
69
|
+
"temperature": 300.0,
|
|
70
70
|
"nuclides": [
|
|
71
71
|
{ "name": "He4", "percent": 1.0, "percent_type": "ao" }
|
|
72
72
|
]
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "processforge"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.9"
|
|
8
8
|
description = "A Python-based process simulation framework for chemical engineering applications."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "BSD-3-Clause"
|
|
@@ -39,6 +39,10 @@ dependencies = [
|
|
|
39
39
|
]
|
|
40
40
|
|
|
41
41
|
[project.optional-dependencies]
|
|
42
|
+
api = [
|
|
43
|
+
"fastapi>=0.110",
|
|
44
|
+
"uvicorn>=0.29",
|
|
45
|
+
]
|
|
42
46
|
eo = [
|
|
43
47
|
"pyomo>=6.7",
|
|
44
48
|
]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Processforge provider HTTP API.
|
|
2
|
+
|
|
3
|
+
Run as a module so deployment platforms that execute
|
|
4
|
+
``python -m processforge.api.serve`` can boot the server directly::
|
|
5
|
+
|
|
6
|
+
python -m processforge.api.serve
|
|
7
|
+
|
|
8
|
+
The listen port is taken from the ``PORT`` environment variable
|
|
9
|
+
(default ``9000``), and the provider type from ``PROVIDER_TYPE``.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import traceback
|
|
16
|
+
|
|
17
|
+
from fastapi import FastAPI, HTTPException
|
|
18
|
+
|
|
19
|
+
app = FastAPI(title="Processforge Provider")
|
|
20
|
+
|
|
21
|
+
PROVIDER_TYPE = os.environ.get("PROVIDER_TYPE", "")
|
|
22
|
+
DEFAULT_PORT = int(os.environ.get("PORT", "9000"))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@app.get("/health")
|
|
26
|
+
def health():
|
|
27
|
+
return {
|
|
28
|
+
"status": "ready",
|
|
29
|
+
"provider_type": PROVIDER_TYPE,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@app.post("/run")
|
|
34
|
+
def run(body: dict):
|
|
35
|
+
from processforge.types import UnitConfig, MaterialDef
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
unit_cfg = UnitConfig.from_dict(body["unit_config"])
|
|
39
|
+
except Exception as exc:
|
|
40
|
+
raise HTTPException(status_code=400, detail=f"Invalid unit_config: {exc}") from exc
|
|
41
|
+
|
|
42
|
+
materials_raw = body.get("materials", {})
|
|
43
|
+
materials = {
|
|
44
|
+
name: MaterialDef.from_dict(mat)
|
|
45
|
+
for name, mat in materials_raw.items()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
from processforge.providers.registry import get_provider_class
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
provider_cls = get_provider_class(PROVIDER_TYPE)
|
|
52
|
+
except ValueError as exc:
|
|
53
|
+
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
54
|
+
|
|
55
|
+
provider = provider_cls()
|
|
56
|
+
|
|
57
|
+
# Build the provider config for initialize(). Prefer the real config the
|
|
58
|
+
# CLI serialised into the request body (carries cross_sections, output_dir,
|
|
59
|
+
# url, …); fall back to a minimal container-default config otherwise.
|
|
60
|
+
provider_config_raw = body.get("provider_config")
|
|
61
|
+
if provider_config_raw:
|
|
62
|
+
from processforge.types import provider_config_from_dict
|
|
63
|
+
|
|
64
|
+
provider_config = provider_config_from_dict(provider_config_raw)
|
|
65
|
+
else:
|
|
66
|
+
provider_config = type("Cfg", (), {
|
|
67
|
+
"url": None,
|
|
68
|
+
"output_dir": os.environ.get("PROCESSFORGE_OUTPUT_DIR", "/data"),
|
|
69
|
+
"cross_sections": None,
|
|
70
|
+
"type": PROVIDER_TYPE,
|
|
71
|
+
})()
|
|
72
|
+
|
|
73
|
+
# Build a minimal flowsheet config holding materials.
|
|
74
|
+
flowsheet_config = type("FS", (), {"materials": materials})()
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
provider.initialize(provider_config, flowsheet_config)
|
|
78
|
+
result = provider.run_simulation(unit_cfg, body.get("inlet", {}))
|
|
79
|
+
return result.as_dict() | {"metadata": result.metadata}
|
|
80
|
+
except HTTPException:
|
|
81
|
+
raise
|
|
82
|
+
except Exception as exc:
|
|
83
|
+
raise HTTPException(
|
|
84
|
+
status_code=500,
|
|
85
|
+
detail=f"Simulation failed: {exc}\n{traceback.format_exc()}",
|
|
86
|
+
) from exc
|
|
87
|
+
finally:
|
|
88
|
+
provider.teardown()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
import uvicorn
|
|
93
|
+
|
|
94
|
+
uvicorn.run(app, host="0.0.0.0", port=DEFAULT_PORT)
|
|
@@ -31,7 +31,7 @@ def register_commands(app: typer.Typer) -> None:
|
|
|
31
31
|
)(apply)
|
|
32
32
|
app.command(
|
|
33
33
|
"plan",
|
|
34
|
-
help="Validate a flowsheet, run DOF analysis, structural diff, and generate a Mermaid diagram",
|
|
34
|
+
help="Validate a flowsheet, run DOF analysis, structural diff, container health check, and generate a Mermaid diagram",
|
|
35
35
|
)(plan)
|
|
36
36
|
app.command("diagram", help="Generate a flowsheet diagram")(diagram)
|
|
37
37
|
app.command(
|
|
@@ -17,6 +17,7 @@ from .common import (
|
|
|
17
17
|
build_divergence_report,
|
|
18
18
|
build_run_metadata,
|
|
19
19
|
check_providers,
|
|
20
|
+
display_backend,
|
|
20
21
|
flowsheet_basename,
|
|
21
22
|
load_state_manager,
|
|
22
23
|
log_residual_breakdown,
|
|
@@ -132,7 +133,7 @@ def apply(
|
|
|
132
133
|
logger.info(" Status : CONVERGED")
|
|
133
134
|
logger.info(f" Final ||F|| : {fs.solver_stats.get('final_norm', '?'):.3e}")
|
|
134
135
|
logger.info(f" Iterations : {fs.solver_stats.get('iterations', '?')}")
|
|
135
|
-
logger.info(f" Backend : {fs.backend}")
|
|
136
|
+
logger.info(f" Backend : {display_backend(config, fs.backend)}")
|
|
136
137
|
logger.info(f" Snapshot ID : {snapshot_id}")
|
|
137
138
|
logger.info(f" Results zarr : {zarr_path}")
|
|
138
139
|
logger.info(f" Elapsed (s) : {elapsed:.2f}")
|
|
@@ -98,6 +98,23 @@ def build_run_metadata(config: dict, solver_tol: float, solver_max_iter: int, ba
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
|
|
101
|
+
def display_backend(config: dict, eo_backend: str) -> str:
|
|
102
|
+
"""Resolve the backend label shown in run/apply summaries.
|
|
103
|
+
|
|
104
|
+
When a flowsheet delegates its computation to one or more providers
|
|
105
|
+
(e.g. ``openmc``, ``cantera``), the provider type is the engine that
|
|
106
|
+
actually ran the simulation — report that rather than the EO solver
|
|
107
|
+
backend (which is a no-op for provider-driven flowsheets). Falls back
|
|
108
|
+
to the EO solver backend when no providers are declared.
|
|
109
|
+
"""
|
|
110
|
+
provider_types = sorted(
|
|
111
|
+
{p.get("type") for p in config.get("providers", {}).values() if p.get("type")}
|
|
112
|
+
)
|
|
113
|
+
if provider_types:
|
|
114
|
+
return "+".join(provider_types)
|
|
115
|
+
return eo_backend
|
|
116
|
+
|
|
117
|
+
|
|
101
118
|
def extract_providers(flowsheet_path: str) -> dict:
|
|
102
119
|
"""Read flowsheet JSON and return the raw providers dict."""
|
|
103
120
|
try:
|
|
@@ -128,6 +145,21 @@ def load_state_manager(outputs_dir: str, base_name: str) -> tuple[StateManager,
|
|
|
128
145
|
# Provider checking
|
|
129
146
|
# ---------------------------------------------------------------------------
|
|
130
147
|
|
|
148
|
+
def is_local_provider_url(url: str | None) -> bool:
|
|
149
|
+
"""Return True if *url* points at a locally-managed provider.
|
|
150
|
+
|
|
151
|
+
A provider is considered local — and thus a candidate for ``pf init`` to
|
|
152
|
+
generate docker-compose and pull its image — when it has no explicit URL
|
|
153
|
+
or its URL points at localhost / 127.0.0.1 / 0.0.0.0. Any other URL is
|
|
154
|
+
treated as an externally-managed (cloud / remote) provider that
|
|
155
|
+
``pf init`` must not try to spin up or pull an image for.
|
|
156
|
+
"""
|
|
157
|
+
if not url:
|
|
158
|
+
return True
|
|
159
|
+
lowered = url.lower()
|
|
160
|
+
return any(token in lowered for token in ("localhost", "127.0.0.1", "0.0.0.0"))
|
|
161
|
+
|
|
162
|
+
|
|
131
163
|
def _resolve_provider_url(cfg: dict, ptype: str) -> str:
|
|
132
164
|
"""Build the provider URL, falling back to the default port."""
|
|
133
165
|
from ..providers.registry import get_provider_default_port
|
|
@@ -139,6 +171,19 @@ def _resolve_provider_url(cfg: dict, ptype: str) -> str:
|
|
|
139
171
|
return url
|
|
140
172
|
|
|
141
173
|
|
|
174
|
+
def _ping_provider_health(url: str, timeout: int = 5) -> tuple[bool, "dict | str"]:
|
|
175
|
+
"""GET ``{url}/health`` and return ``(ok, payload_or_error)``.
|
|
176
|
+
|
|
177
|
+
Returns the parsed JSON health payload on success, or the error string on
|
|
178
|
+
failure (unreachable service, timeout, or non-JSON response).
|
|
179
|
+
"""
|
|
180
|
+
try:
|
|
181
|
+
with urllib.request.urlopen(f"{url.rstrip('/')}/health", timeout=timeout) as resp:
|
|
182
|
+
return True, json.loads(resp.read().decode())
|
|
183
|
+
except (urllib.error.URLError, OSError, TimeoutError, ValueError) as exc:
|
|
184
|
+
return False, str(exc)
|
|
185
|
+
|
|
186
|
+
|
|
142
187
|
def check_providers(
|
|
143
188
|
config: dict,
|
|
144
189
|
flowsheet_path: str,
|
|
@@ -53,6 +53,61 @@ def print_unit_mismatches(mismatches: list[Any]) -> None:
|
|
|
53
53
|
logger.warning(f"Unit annotation — stream '{m.stream_name}'.{m.property_name}: {m.message}")
|
|
54
54
|
|
|
55
55
|
|
|
56
|
+
def print_provider_health(config: dict) -> list[str]:
|
|
57
|
+
"""Log per-provider reachability for flowsheets using Docker containers.
|
|
58
|
+
|
|
59
|
+
For each provider declared in *config*:
|
|
60
|
+
|
|
61
|
+
* containerized providers are probed via ``GET /health`` and reported with
|
|
62
|
+
their URL, ``status``, and ``provider_type`` from the health payload;
|
|
63
|
+
* pip-installable providers are reported as importable or not.
|
|
64
|
+
|
|
65
|
+
Returns a list of failure messages — one per unreachable containerized
|
|
66
|
+
provider (empty means every provider is healthy/available).
|
|
67
|
+
"""
|
|
68
|
+
import importlib
|
|
69
|
+
|
|
70
|
+
from ..providers.registry import is_containerized, _PROVIDER_CATALOG
|
|
71
|
+
|
|
72
|
+
providers = config.get("providers", {})
|
|
73
|
+
logger.info("=== Provider / Container Health ===")
|
|
74
|
+
failures: list[str] = []
|
|
75
|
+
if not providers:
|
|
76
|
+
logger.info(" No providers declared.")
|
|
77
|
+
return failures
|
|
78
|
+
|
|
79
|
+
for name, cfg in providers.items():
|
|
80
|
+
ptype = cfg.get("type", "")
|
|
81
|
+
if is_containerized(ptype):
|
|
82
|
+
from .common import _resolve_provider_url, _ping_provider_health
|
|
83
|
+
|
|
84
|
+
url = _resolve_provider_url(cfg, ptype)
|
|
85
|
+
ok, info = _ping_provider_health(url, timeout=5)
|
|
86
|
+
if ok:
|
|
87
|
+
payload = info if isinstance(info, dict) else {}
|
|
88
|
+
status = payload.get("status", "?")
|
|
89
|
+
provider_type = payload.get("provider_type", "?")
|
|
90
|
+
logger.info(
|
|
91
|
+
f" [OK] {name} [{ptype}] {url} — status={status} provider_type={provider_type}"
|
|
92
|
+
)
|
|
93
|
+
else:
|
|
94
|
+
msg = f" [ERR] {name} [{ptype}] {url} — unreachable: {info}"
|
|
95
|
+
logger.error(msg)
|
|
96
|
+
failures.append(f"Provider '{name}' unreachable at {url}: {info}")
|
|
97
|
+
else:
|
|
98
|
+
catalog = _PROVIDER_CATALOG.get(ptype, {})
|
|
99
|
+
module = catalog.get("module", "")
|
|
100
|
+
try:
|
|
101
|
+
importlib.util.find_spec(module)
|
|
102
|
+
logger.info(f" [OK] {name} [{ptype}] (pip — importable)")
|
|
103
|
+
except (ModuleNotFoundError, ValueError):
|
|
104
|
+
dep = catalog.get("optional_dep")
|
|
105
|
+
hint = f"pip install 'processforge[{dep}]'" if dep else "built-in"
|
|
106
|
+
logger.warning(f" [WARN] {name} [{ptype}] — not installed ({hint})")
|
|
107
|
+
|
|
108
|
+
return failures
|
|
109
|
+
|
|
110
|
+
|
|
56
111
|
def print_structural_diff(diff: dict) -> None:
|
|
57
112
|
"""Print a +/~/- structural diff of units."""
|
|
58
113
|
logger.info("=== Structural Diff vs. Saved State ===")
|
|
@@ -11,7 +11,56 @@ import subprocess
|
|
|
11
11
|
import typer
|
|
12
12
|
from loguru import logger
|
|
13
13
|
|
|
14
|
-
from .common import extract_providers
|
|
14
|
+
from .common import extract_providers, is_local_provider_url
|
|
15
|
+
from ..lock import flowsheet_env_dir, read_lock
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _migrate_legacy_env(pf_dir: str) -> None:
|
|
19
|
+
"""Move a legacy root-level lock.json / docker-compose.yml into a per-flowsheet dir.
|
|
20
|
+
|
|
21
|
+
Older processforge stored a single environment at ``.processforge/lock.json``
|
|
22
|
+
and ``.processforge/docker-compose.yml``. This relocates those into the hashed
|
|
23
|
+
env dir derived from the flowsheet recorded in the legacy lock, so an existing
|
|
24
|
+
repo keeps its provider environment after upgrading.
|
|
25
|
+
"""
|
|
26
|
+
legacy_lock = os.path.join(pf_dir, "lock.json")
|
|
27
|
+
legacy_compose = os.path.join(pf_dir, "docker-compose.yml")
|
|
28
|
+
if not (os.path.exists(legacy_lock) or os.path.exists(legacy_compose)):
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
recorded = None
|
|
32
|
+
if os.path.exists(legacy_lock):
|
|
33
|
+
try:
|
|
34
|
+
recorded = read_lock(pf_dir).get("flowsheet")
|
|
35
|
+
except Exception:
|
|
36
|
+
recorded = None
|
|
37
|
+
|
|
38
|
+
if recorded and os.path.exists(recorded):
|
|
39
|
+
env_dir = flowsheet_env_dir(pf_dir, recorded)
|
|
40
|
+
else:
|
|
41
|
+
base = os.path.splitext(os.path.basename(recorded or "legacy"))[0] or "legacy"
|
|
42
|
+
env_dir = os.path.join(pf_dir, base)
|
|
43
|
+
logger.warning(
|
|
44
|
+
"Migrating legacy .processforge/lock.json + docker-compose.yml into "
|
|
45
|
+
f"'{os.path.relpath(env_dir, pf_dir)}/' (recorded flowsheet not found on "
|
|
46
|
+
"disk — re-run `pf init <flowsheet.json>` to restore the correct env dir)."
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if os.path.exists(env_dir):
|
|
50
|
+
logger.warning(
|
|
51
|
+
f"Migration target {os.path.relpath(env_dir, pf_dir)}/ already exists — "
|
|
52
|
+
"skipping legacy migration."
|
|
53
|
+
)
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
os.makedirs(env_dir, exist_ok=True)
|
|
57
|
+
for src in (legacy_lock, legacy_compose):
|
|
58
|
+
if os.path.exists(src):
|
|
59
|
+
shutil.move(src, os.path.join(env_dir, os.path.basename(src)))
|
|
60
|
+
logger.info(
|
|
61
|
+
"Migrated legacy .processforge/ environment into per-flowsheet dir "
|
|
62
|
+
f"'{os.path.relpath(env_dir, pf_dir)}/'."
|
|
63
|
+
)
|
|
15
64
|
|
|
16
65
|
|
|
17
66
|
def init(
|
|
@@ -42,6 +91,11 @@ def init(
|
|
|
42
91
|
os.makedirs(pf_dir, exist_ok=True)
|
|
43
92
|
os.makedirs(outputs_dir, exist_ok=True)
|
|
44
93
|
|
|
94
|
+
# Migrate a legacy single-environment layout (.processforge/lock.json and
|
|
95
|
+
# .processforge/docker-compose.yml at the root) into a per-flowsheet env
|
|
96
|
+
# dir so existing repos aren't silently broken by the new structure.
|
|
97
|
+
_migrate_legacy_env(pf_dir)
|
|
98
|
+
|
|
45
99
|
# Remove stale .pfstate snapshot directories from outputs/
|
|
46
100
|
stale_count = 0
|
|
47
101
|
for entry in os.listdir(outputs_dir):
|
|
@@ -84,21 +138,32 @@ def init(
|
|
|
84
138
|
|
|
85
139
|
# Categorize providers
|
|
86
140
|
pip_providers: dict[str, dict] = {}
|
|
87
|
-
|
|
141
|
+
local_docker_providers: dict[str, dict] = {}
|
|
142
|
+
remote_docker_providers: dict[str, dict] = {}
|
|
88
143
|
for name, cfg in providers.items():
|
|
89
144
|
ptype = cfg.get("type", "")
|
|
90
145
|
if is_containerized(ptype):
|
|
91
146
|
url = cfg.get("url")
|
|
92
|
-
if
|
|
147
|
+
if is_local_provider_url(url):
|
|
93
148
|
port = get_provider_default_port(ptype) or 9000
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
149
|
+
if not url:
|
|
150
|
+
url = f"http://localhost:{port}"
|
|
151
|
+
local_docker_providers[name] = {
|
|
152
|
+
"type": ptype,
|
|
153
|
+
"url": url,
|
|
154
|
+
"docker_image": cfg.get("docker_image") or get_provider_docker_image(ptype),
|
|
155
|
+
"port": port,
|
|
156
|
+
}
|
|
157
|
+
logger.info(f" {name}: type={ptype}, url={url} (Docker, local)")
|
|
158
|
+
else:
|
|
159
|
+
remote_docker_providers[name] = {
|
|
160
|
+
"type": ptype,
|
|
161
|
+
"url": url,
|
|
162
|
+
"docker_image": cfg.get("docker_image") or get_provider_docker_image(ptype),
|
|
163
|
+
}
|
|
164
|
+
logger.info(
|
|
165
|
+
f" {name}: type={ptype}, url={url} (Docker, remote — skipping compose)"
|
|
166
|
+
)
|
|
102
167
|
else:
|
|
103
168
|
pip_providers[name] = {"type": ptype}
|
|
104
169
|
logger.info(f" {name}: type={ptype} (pip)")
|
|
@@ -116,15 +181,19 @@ def init(
|
|
|
116
181
|
hint = f"pip install 'processforge[{dep}]'" if dep else "built-in"
|
|
117
182
|
logger.warning(f" {name} — not installed. Install with: {hint}")
|
|
118
183
|
|
|
119
|
-
# Generate compose for Docker providers
|
|
120
|
-
|
|
121
|
-
|
|
184
|
+
# Generate compose + pull images only for locally-managed Docker providers.
|
|
185
|
+
# Providers with an explicit remote URL are assumed to be running elsewhere
|
|
186
|
+
# (e.g. a cloud deployment of the ghcr.io image) and are not touched here.
|
|
187
|
+
if local_docker_providers:
|
|
188
|
+
compose_path = os.path.join(
|
|
189
|
+
flowsheet_env_dir(pf_dir, flowsheet_path), "docker-compose.yml"
|
|
190
|
+
)
|
|
122
191
|
if os.path.exists(compose_path):
|
|
123
192
|
logger.warning(
|
|
124
193
|
f"Environment already initialized — reinitializing from {flowsheet_path}"
|
|
125
194
|
)
|
|
126
195
|
|
|
127
|
-
generate_compose(pf_dir,
|
|
196
|
+
generate_compose(pf_dir, local_docker_providers, outputs_dir, flowsheet=flowsheet_path)
|
|
128
197
|
logger.info(f"Generated {compose_path}")
|
|
129
198
|
|
|
130
199
|
# Attempt docker compose pull — stream progress live
|
|
@@ -155,6 +224,21 @@ def init(
|
|
|
155
224
|
)
|
|
156
225
|
except subprocess.TimeoutExpired:
|
|
157
226
|
logger.warning("docker compose pull timed out after 600s.")
|
|
227
|
+
|
|
228
|
+
logger.info(
|
|
229
|
+
"To start the containerized provider(s), run:\n"
|
|
230
|
+
f" docker compose -f {compose_path} up -d"
|
|
231
|
+
)
|
|
232
|
+
if any(info["type"] == "openmc" for info in local_docker_providers.values()):
|
|
233
|
+
logger.info(
|
|
234
|
+
"Running OpenMC — set OPENMC_DATA_ROOT to mount your OpenMC "
|
|
235
|
+
"data/workspace into the container (defaults to 'outputs'):\n"
|
|
236
|
+
f" OPENMC_DATA_ROOT=/path/to/data docker compose -f {compose_path} up -d"
|
|
237
|
+
)
|
|
238
|
+
elif remote_docker_providers:
|
|
239
|
+
logger.info(
|
|
240
|
+
"All containerized providers use remote URLs — skipping Docker setup."
|
|
241
|
+
)
|
|
158
242
|
else:
|
|
159
243
|
logger.info("No containerized providers — skipping Docker setup.")
|
|
160
244
|
|
|
@@ -177,5 +261,5 @@ def init(
|
|
|
177
261
|
from .. import __version__ as pf_version
|
|
178
262
|
|
|
179
263
|
write_lock(pf_dir, flowsheet_path, lock_providers, pf_version)
|
|
180
|
-
logger.info(f"Wrote {os.path.join(pf_dir, 'lock.json')}")
|
|
264
|
+
logger.info(f"Wrote {os.path.join(flowsheet_env_dir(pf_dir, flowsheet_path), 'lock.json')}")
|
|
181
265
|
logger.info(".processforge/ initialised successfully.")
|
|
@@ -18,7 +18,12 @@ from .common import (
|
|
|
18
18
|
require_existing_file,
|
|
19
19
|
validate_snapshot_config,
|
|
20
20
|
)
|
|
21
|
-
from .display import
|
|
21
|
+
from .display import (
|
|
22
|
+
print_dof_report,
|
|
23
|
+
print_provider_health,
|
|
24
|
+
print_structural_diff,
|
|
25
|
+
print_unit_mismatches,
|
|
26
|
+
)
|
|
22
27
|
|
|
23
28
|
|
|
24
29
|
def plan(
|
|
@@ -116,7 +121,10 @@ def plan(
|
|
|
116
121
|
logger.info(" Warm-start available : No snapshot found")
|
|
117
122
|
logger.info(" Homotopy eligible : No (cold start)")
|
|
118
123
|
|
|
119
|
-
# Step 7:
|
|
124
|
+
# Step 7: Provider / container health check
|
|
125
|
+
health_failures = print_provider_health(config)
|
|
126
|
+
|
|
127
|
+
# Step 8: Mermaid diagram
|
|
120
128
|
if not no_diagram:
|
|
121
129
|
diagram_output_dir = output_dir or "diagrams"
|
|
122
130
|
os.makedirs(diagram_output_dir, exist_ok=True)
|
|
@@ -129,5 +137,5 @@ def plan(
|
|
|
129
137
|
|
|
130
138
|
# Exit non-zero on hard errors
|
|
131
139
|
hard_errors = [m for m in mismatches if not m.compatible]
|
|
132
|
-
if hard_errors or report.system_dof < 0:
|
|
140
|
+
if hard_errors or report.system_dof < 0 or health_failures:
|
|
133
141
|
raise SystemExit(1)
|
|
@@ -14,6 +14,7 @@ from ..result import plot_results, plot_timeseries, save_results_zarr
|
|
|
14
14
|
from ..state import StateManager
|
|
15
15
|
from .common import (
|
|
16
16
|
check_providers,
|
|
17
|
+
display_backend,
|
|
17
18
|
flowsheet_basename,
|
|
18
19
|
output_root,
|
|
19
20
|
require_existing_file,
|
|
@@ -96,6 +97,7 @@ def run(
|
|
|
96
97
|
os.makedirs(outputs_dir, exist_ok=True)
|
|
97
98
|
zarr_path = os.path.join(outputs_dir, f"{base_name}_results.zarr")
|
|
98
99
|
save_results_zarr(results, zarr_path, run_info=run_info)
|
|
100
|
+
logger.info(f" Backend : {display_backend(config, getattr(fs, 'backend', 'dynamic'))}")
|
|
99
101
|
logger.info(f"Results saved to {zarr_path}")
|
|
100
102
|
|
|
101
103
|
if export_images:
|
|
@@ -5,6 +5,8 @@ import os
|
|
|
5
5
|
|
|
6
6
|
from loguru import logger
|
|
7
7
|
|
|
8
|
+
from .lock import flowsheet_env_dir
|
|
9
|
+
|
|
8
10
|
COMPOSE_FILENAME = "docker-compose.yml"
|
|
9
11
|
COMPOSE_HEADER = (
|
|
10
12
|
"# Auto-generated by pf init — do not edit manually.\n"
|
|
@@ -12,7 +14,9 @@ COMPOSE_HEADER = (
|
|
|
12
14
|
)
|
|
13
15
|
|
|
14
16
|
|
|
15
|
-
def _compose_path(pf_dir: str) -> str:
|
|
17
|
+
def _compose_path(pf_dir: str, flowsheet: str | None = None) -> str:
|
|
18
|
+
if flowsheet is not None:
|
|
19
|
+
return os.path.join(flowsheet_env_dir(pf_dir, flowsheet), COMPOSE_FILENAME)
|
|
16
20
|
return os.path.join(pf_dir, COMPOSE_FILENAME)
|
|
17
21
|
|
|
18
22
|
|
|
@@ -20,6 +24,7 @@ def generate_compose(
|
|
|
20
24
|
pf_dir: str,
|
|
21
25
|
containerized_providers: dict[str, dict],
|
|
22
26
|
outputs_dir: str = "outputs",
|
|
27
|
+
flowsheet: str | None = None,
|
|
23
28
|
) -> None:
|
|
24
29
|
"""Generate docker-compose.yml for providers that need Docker.
|
|
25
30
|
|
|
@@ -27,6 +32,9 @@ def generate_compose(
|
|
|
27
32
|
pf_dir: Path to .processforge/ directory.
|
|
28
33
|
containerized_providers: Dict of provider_name -> {"url": ..., "docker_image": ..., "port": ...}.
|
|
29
34
|
outputs_dir: Host directory to mount as /data in containers.
|
|
35
|
+
flowsheet: Flowsheet path. When given, the compose file is written into
|
|
36
|
+
that flowsheet's per-flowsheet environment directory; otherwise it
|
|
37
|
+
is written to the legacy root location.
|
|
30
38
|
"""
|
|
31
39
|
if not containerized_providers:
|
|
32
40
|
return
|
|
@@ -37,16 +45,20 @@ def generate_compose(
|
|
|
37
45
|
port = info.get("port") or 9000
|
|
38
46
|
lines.append(f" {name}:")
|
|
39
47
|
lines.append(f" image: {image}")
|
|
40
|
-
#
|
|
41
|
-
# http://localhost:<port
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
lines.append(f"
|
|
48
|
+
# Publish the provider's API-contract port (host:container) so the
|
|
49
|
+
# service is reachable at http://localhost:<port>, matching the
|
|
50
|
+
# PORT/EXPOSE declared in the provider Dockerfile.
|
|
51
|
+
lines.append(f" ports:")
|
|
52
|
+
lines.append(f' - "{port}:{port}"')
|
|
45
53
|
lines.append(f" volumes:")
|
|
46
54
|
lines.append(f' - "${{OPENMC_DATA_ROOT:-{outputs_dir}}}:/data"')
|
|
47
55
|
lines.append("")
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
if flowsheet is not None:
|
|
58
|
+
target_dir = flowsheet_env_dir(pf_dir, flowsheet)
|
|
59
|
+
else:
|
|
60
|
+
target_dir = pf_dir
|
|
61
|
+
os.makedirs(target_dir, exist_ok=True)
|
|
62
|
+
path = os.path.join(target_dir, COMPOSE_FILENAME)
|
|
51
63
|
with open(path, "w", encoding="utf-8") as f:
|
|
52
64
|
f.write("\n".join(lines))
|