Skip to content

Commit 090a896

Browse files
committed
visualise intermediate params in json
1 parent c6e143e commit 090a896

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

examples/sparging_standard.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
dispersion_on=True,
4141
)
4242

43+
standard_input.to_json(FOLDER / "intermediate_params.json")
44+
breakpoint()
4345
if __name__ == "__main__":
4446
# my_simulation.exports = ["pressure", "J_T2"]
4547
output = my_simulation.solve(fast_solve=True)

src/sparging/inputs.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22
from dataclasses import dataclass, replace
3+
from datetime import datetime
4+
from sparging import helpers
35
from sparging.correlations import Correlation, all_correlations
46
import pint
57
from typing import List
@@ -201,15 +203,29 @@ def __post_init__(self):
201203
def to_json(self, path: str):
202204
import json
203205

206+
output = {
207+
"metadata": {
208+
"git_commit": helpers.get_git_hash(),
209+
"date": datetime.now().isoformat(),
210+
},
211+
}
212+
213+
output["intermediate parameters"] = {}
214+
for node in self.graph.nodes:
215+
output["intermediate parameters"][node] = {
216+
"value": str(self.graph.nodes[node]["value"]),
217+
"origin": self.graph.nodes[node]["origin"],
218+
}
204219
with open(path, "w") as f:
205220
json.dump(
206-
{
207-
key: str(value)
208-
for key, value in self.__dict__.items()
209-
if isinstance(value, pint.Quantity)
210-
},
221+
output,
222+
# {
223+
# key: str(value)
224+
# for key, value in self.__dict__.items()
225+
# if isinstance(value, pint.Quantity)
226+
# },
211227
f,
212-
indent=2,
228+
indent=4,
213229
)
214230

215231
@classmethod

0 commit comments

Comments
 (0)