Skip to content

Commit e17979a

Browse files
committed
Cleanup README IA, Improve OPM Flow compatibility and versions
1 parent 1390577 commit e17979a

4 files changed

Lines changed: 134 additions & 56 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ The goal of `hyopml` is to provide fast, deterministic, dependency-free inferenc
99

1010
## Features
1111

12-
- 🧠 **Lightweight MLP inference engine** (pure NumPy, no ML framework required)
13-
- 🔁 **Converters** from:
12+
- **Lightweight MLP inference engine** (pure NumPy, no ML framework required)
13+
- **Converters** from:
1414
- TensorFlow / Keras
1515
- PyTorch
1616
- JAX
17-
- 📦 **Export tools** for OPM Flow (`kerasify`-like format)
18-
- 🚀 **Improved Newton initial guesses**, reducing convergence difficulties
19-
- 🔧 Ready-to-use in OPM Flow 2025.10+
17+
- **Export tools** for OPM Flow (`kerasify`-like format)
18+
- **Improved Newton initial guesses**, reducing convergence difficulties
19+
- Ready-to-use in OPM Flow 2025.10+
2020

2121
---
2222

examples/SPE1.ipynb

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"import subprocess\n",
5454
"import numpy as np \n",
5555
"\n",
56-
"from hyopml.utils import extract_newtit_from_file, plot_newton_iterations\n",
56+
"from hyopml.utils import extract_newtit_from_file, plot_newton_iterations, detect_flow_flags\n",
5757
"from hyopml.data import collect_input_features, compute_output_vars, extract_unrst_variables\n",
5858
"from hyopml.neural_networks import Dense, Sequential\n",
5959
"from hyopml.write_config import write_config\n",
@@ -73,7 +73,7 @@
7373
},
7474
{
7575
"cell_type": "code",
76-
"execution_count": 21,
76+
"execution_count": 2,
7777
"id": "05d2b37e",
7878
"metadata": {},
7979
"outputs": [
@@ -83,7 +83,7 @@
8383
"text": [
8484
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
8585
" Dload Upload Total Spent Left Speed\n",
86-
"100 12201 100 12201 0 0 186k 0 --:--:-- --:--:-- --:--:-- 189k\n"
86+
"100 12201 100 12201 0 0 189k 0 --:--:-- --:--:-- --:--:-- 192k\n"
8787
]
8888
}
8989
],
@@ -96,7 +96,7 @@
9696
},
9797
{
9898
"cell_type": "code",
99-
"execution_count": null,
99+
"execution_count": 3,
100100
"id": "a2838659",
101101
"metadata": {},
102102
"outputs": [],
@@ -109,6 +109,27 @@
109109
"output_dir = \"SPE1_tutorial\""
110110
]
111111
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": 4,
115+
"id": "2dbc2051",
116+
"metadata": {},
117+
"outputs": [
118+
{
119+
"name": "stdout",
120+
"output_type": "stream",
121+
"text": [
122+
"{'version': '2025.10', 'version_num': 2025.1, 'flags': {'use_hybrid': '--use-hy-ne', 'config_file': '--hy-ne-config-file'}}\n"
123+
]
124+
}
125+
],
126+
"source": [
127+
"infos = detect_flow_flags(flow_path)\n",
128+
"print(infos)\n",
129+
"USE_HYBRID_FLAG = infos['flags']['use_hybrid']\n",
130+
"HYBRID_CONFIG_FILE_FLAG = infos['flags']['config_file']"
131+
]
132+
},
112133
{
113134
"cell_type": "markdown",
114135
"id": "136ced9c",
@@ -119,34 +140,16 @@
119140
},
120141
{
121142
"cell_type": "code",
122-
"execution_count": 23,
143+
"execution_count": 5,
123144
"id": "d4e0387e",
124145
"metadata": {},
125146
"outputs": [
126147
{
127148
"name": "stdout",
128149
"output_type": "stream",
129150
"text": [
130-
"Running baseline simulation... \n"
131-
]
132-
},
133-
{
134-
"name": "stderr",
135-
"output_type": "stream",
136-
"text": [
137-
"Exception received: Cannot find input case 'decks/SPE1CASE1b/SPE1CASE1'. Try '--help' for a usage description.\n"
138-
]
139-
},
140-
{
141-
"ename": "CalledProcessError",
142-
"evalue": "Command '['../build/opm-simulators/bin/flow', 'decks/SPE1CASE1b/SPE1CASE1', '--output-extra-convergence-info=steps,iterations', '--newton-min-iterations=0', '--output-dir=SPE1_tutorial', '--full-time-step-initially=true']' returned non-zero exit status 1.",
143-
"output_type": "error",
144-
"traceback": [
145-
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
146-
"\u001b[31mCalledProcessError\u001b[39m Traceback (most recent call last)",
147-
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[23]\u001b[39m\u001b[32m, line 11\u001b[39m\n\u001b[32m 1\u001b[39m baseline_cmd = [\n\u001b[32m 2\u001b[39m flow_path,\n\u001b[32m 3\u001b[39m deck_path,\n\u001b[32m (...)\u001b[39m\u001b[32m 7\u001b[39m \u001b[33m\"\u001b[39m\u001b[33m--full-time-step-initially=true\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 8\u001b[39m ]\n\u001b[32m 10\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mRunning baseline simulation... \u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m---> \u001b[39m\u001b[32m11\u001b[39m \u001b[43msubprocess\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbaseline_cmd\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstdout\u001b[49m\u001b[43m=\u001b[49m\u001b[43msubprocess\u001b[49m\u001b[43m.\u001b[49m\u001b[43mDEVNULL\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcheck\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[32m 12\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mBaseline simulation finished\u001b[39m\u001b[33m\"\u001b[39m)\n",
148-
"\u001b[36mFile \u001b[39m\u001b[32m/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py:571\u001b[39m, in \u001b[36mrun\u001b[39m\u001b[34m(input, capture_output, timeout, check, *popenargs, **kwargs)\u001b[39m\n\u001b[32m 569\u001b[39m retcode = process.poll()\n\u001b[32m 570\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m check \u001b[38;5;129;01mand\u001b[39;00m retcode:\n\u001b[32m--> \u001b[39m\u001b[32m571\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m CalledProcessError(retcode, process.args,\n\u001b[32m 572\u001b[39m output=stdout, stderr=stderr)\n\u001b[32m 573\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m CompletedProcess(process.args, retcode, stdout, stderr)\n",
149-
"\u001b[31mCalledProcessError\u001b[39m: Command '['../build/opm-simulators/bin/flow', 'decks/SPE1CASE1b/SPE1CASE1', '--output-extra-convergence-info=steps,iterations', '--newton-min-iterations=0', '--output-dir=SPE1_tutorial', '--full-time-step-initially=true']' returned non-zero exit status 1."
151+
"Running baseline simulation... \n",
152+
"Baseline simulation finished\n"
150153
]
151154
}
152155
],
@@ -167,7 +170,7 @@
167170
},
168171
{
169172
"cell_type": "code",
170-
"execution_count": 4,
173+
"execution_count": 6,
171174
"id": "dfbb9861",
172175
"metadata": {},
173176
"outputs": [],
@@ -181,7 +184,7 @@
181184
},
182185
{
183186
"cell_type": "code",
184-
"execution_count": 5,
187+
"execution_count": 7,
185188
"id": "cb611a32",
186189
"metadata": {},
187190
"outputs": [
@@ -224,7 +227,7 @@
224227
},
225228
{
226229
"cell_type": "code",
227-
"execution_count": 6,
230+
"execution_count": 8,
228231
"id": "c0c76d02",
229232
"metadata": {},
230233
"outputs": [],
@@ -249,7 +252,7 @@
249252
},
250253
{
251254
"cell_type": "code",
252-
"execution_count": 7,
255+
"execution_count": 9,
253256
"id": "0e70afd6",
254257
"metadata": {},
255258
"outputs": [],
@@ -275,7 +278,7 @@
275278
},
276279
{
277280
"cell_type": "code",
278-
"execution_count": 8,
281+
"execution_count": 10,
279282
"id": "d502fd70",
280283
"metadata": {},
281284
"outputs": [],
@@ -331,7 +334,7 @@
331334
},
332335
{
333336
"cell_type": "code",
334-
"execution_count": 9,
337+
"execution_count": 11,
335338
"id": "ac73a4e3",
336339
"metadata": {},
337340
"outputs": [],
@@ -373,7 +376,7 @@
373376
},
374377
{
375378
"cell_type": "code",
376-
"execution_count": 10,
379+
"execution_count": 12,
377380
"id": "12d5051e",
378381
"metadata": {},
379382
"outputs": [],
@@ -400,7 +403,7 @@
400403
},
401404
{
402405
"cell_type": "code",
403-
"execution_count": 11,
406+
"execution_count": 13,
404407
"id": "ee32e6eb",
405408
"metadata": {},
406409
"outputs": [],
@@ -443,7 +446,7 @@
443446
},
444447
{
445448
"cell_type": "code",
446-
"execution_count": 12,
449+
"execution_count": 14,
447450
"id": "b02ead61",
448451
"metadata": {},
449452
"outputs": [],
@@ -453,7 +456,7 @@
453456
},
454457
{
455458
"cell_type": "code",
456-
"execution_count": 13,
459+
"execution_count": 15,
457460
"id": "3db29cd9",
458461
"metadata": {},
459462
"outputs": [
@@ -470,8 +473,8 @@
470473
"hybrid_cmd = [\n",
471474
" flow_path,\n",
472475
" deck_path,\n",
473-
" f\"--hy-ne-config-file={ml_model_config_path}\",\n",
474-
" \"--use-hy-ne=true\",\n",
476+
" f\"{HYBRID_CONFIG_FILE_FLAG}={ml_model_config_path}\",\n",
477+
" f\"{USE_HYBRID_FLAG}=true\",\n",
475478
" \"--output-extra-convergence-info=steps,iterations\",\n",
476479
" \"--newton-min-iterations=0\",\n",
477480
" f\"--output-dir={output_dir}/hybrid_newton\",\n",
@@ -485,7 +488,7 @@
485488
},
486489
{
487490
"cell_type": "code",
488-
"execution_count": 14,
491+
"execution_count": 16,
489492
"id": "01fcb6bb",
490493
"metadata": {},
491494
"outputs": [
@@ -525,7 +528,7 @@
525528
},
526529
{
527530
"cell_type": "code",
528-
"execution_count": 15,
531+
"execution_count": 17,
529532
"id": "bd7f7408",
530533
"metadata": {},
531534
"outputs": [],
@@ -549,7 +552,7 @@
549552
},
550553
{
551554
"cell_type": "code",
552-
"execution_count": 16,
555+
"execution_count": 18,
553556
"id": "4b9570c7",
554557
"metadata": {},
555558
"outputs": [
@@ -567,8 +570,8 @@
567570
"hybrid_cmd = [\n",
568571
" flow_path,\n",
569572
" deck_path,\n",
570-
" f\"--hy-ne-config-file={ml_model_config_path}\",\n",
571-
" \"--use-hy-ne=true\",\n",
573+
" f\"{HYBRID_CONFIG_FILE_FLAG}={ml_model_config_path}\",\n",
574+
" f\"{USE_HYBRID_FLAG}=true\",\n",
572575
" \"--output-extra-convergence-info=steps,iterations\",\n",
573576
" \"--newton-min-iterations=0\",\n",
574577
" f\"--output-dir={output_dir}/hybrid_newton_zeros\",\n",
@@ -589,7 +592,7 @@
589592
},
590593
{
591594
"cell_type": "code",
592-
"execution_count": 17,
595+
"execution_count": 19,
593596
"id": "2738f2b4",
594597
"metadata": {},
595598
"outputs": [
@@ -680,7 +683,7 @@
680683
},
681684
{
682685
"cell_type": "code",
683-
"execution_count": 18,
686+
"execution_count": 20,
684687
"id": "6681ebba",
685688
"metadata": {},
686689
"outputs": [
@@ -717,8 +720,8 @@
717720
" \"--full-time-step-initially=true\",\n",
718721
" f\"--tolerance-mb={tol_mb}\",\n",
719722
" f\"--tolerance-mb-relaxed={tol_mb}\",\n",
720-
" f\"--tolerance-cnv=1e-1\",\n",
721-
" f\"--tolerance-cnv-relaxed=1e-1\",\n",
723+
" \"--tolerance-cnv=1e-1\",\n",
724+
" \"--tolerance-cnv-relaxed=1e-1\",\n",
722725
"]\n",
723726
"subprocess.run(baseline_cmd, stdout=subprocess.DEVNULL, check=True)\n",
724727
"baseline_output_path = f\"{output_dir}/baseline_tol_{tol_mb}/{deck_name}\"\n",
@@ -730,16 +733,16 @@
730733
"hybrid_cmd = [\n",
731734
" flow_path,\n",
732735
" deck_path,\n",
733-
" f\"--hy-ne-config-file={ml_model_config_path}\",\n",
734-
" \"--use-hy-ne=true\",\n",
736+
" f\"{HYBRID_CONFIG_FILE_FLAG}={ml_model_config_path}\",\n",
737+
" f\"{USE_HYBRID_FLAG}=true\",\n",
735738
" \"--output-extra-convergence-info=steps,iterations\",\n",
736739
" \"--newton-min-iterations=0\",\n",
737740
" f\"--output-dir={output_dir}/hybrid_tol_{tol_mb}\",\n",
738741
" \"--full-time-step-initially=true\",\n",
739742
" f\"--tolerance-mb={tol_mb}\",\n",
740743
" f\"--tolerance-mb-relaxed={tol_mb}\",\n",
741-
" f\"--tolerance-cnv=1e-1\",\n",
742-
" f\"--tolerance-cnv-relaxed=1e-1\",\n",
744+
" \"--tolerance-cnv=1e-1\",\n",
745+
" \"--tolerance-cnv-relaxed=1e-1\",\n",
743746
"]\n",
744747
"subprocess.run(hybrid_cmd, stdout=subprocess.DEVNULL, check=True)\n",
745748
"hybrid_output_path = f\"{output_dir}/hybrid_tol_{tol_mb}/{deck_name}\"\n",
@@ -750,7 +753,7 @@
750753
},
751754
{
752755
"cell_type": "code",
753-
"execution_count": 19,
756+
"execution_count": 21,
754757
"id": "6d84c10e",
755758
"metadata": {},
756759
"outputs": [

hyopml/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from importlib.metadata import version, PackageNotFoundError
2+
3+
try:
4+
__version__ = version("hyopml")
5+
except PackageNotFoundError:
6+
# Package not installed (e.g. running from source)
7+
__version__ = "0.0.0"

0 commit comments

Comments
 (0)