Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
pylint.txt

# Translations
*.mo
Expand Down Expand Up @@ -128,7 +129,11 @@ venv.bak/
# Documentation
docs/sphinx-errors.txt
docs/apidoc/
docs/reference_guides/core/util/structfs

# Mac OSX
.DS_Store

# Temp files by name convention
# files ending with '-'
*-
12 changes: 3 additions & 9 deletions docs/examples/structfs/flash_flowsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from idaes.models.unit_models import Flash
from idaes.core.util.structfs.fsrunner import FlowsheetRunner

FS = FlowsheetRunner()
FS = FlowsheetRunner(solver=SolverFactory("ipopt"))

# # Flash Unit Model
#
Expand Down Expand Up @@ -68,18 +68,12 @@ def init_model(ctx):
m.fs.flash.initialize(outlvl=idaeslog.INFO)


@FS.step("set_solver")
def set_solver(ctx):
"""Set the solver."""
ctx.solver = SolverFactory("ipopt")


@FS.step("solve_initial")
def solve(ctx):
"""Perform the initial model solve."""
ctx["results"] = ctx.solver.solve(ctx.model, tee=ctx["tee"])
ctx.solve()


@FS.step("solve_optimization")
def solve_o(ctx):
ctx["results"] = ctx.solver.solve(ctx.model, tee=ctx["tee"])
ctx.solve()
72 changes: 45 additions & 27 deletions docs/examples/structfs/flash_flowsheet_nb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "854989ae",
"metadata": {},
"outputs": [],
Expand All @@ -50,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "4f58d1b7",
"metadata": {},
"outputs": [
Expand All @@ -62,24 +62,30 @@
"build\n",
"set_operating_conditions\n",
"initialize\n",
"set_solver\n",
"solve_initial\n",
"solve_optimization\n",
"========================================\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 1 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 2 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 3 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 4 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 5 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 1 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 2 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 3 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 4 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 5 optimal - Optimal Solution Found.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_out: State Released.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume: Initialization Complete\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash.control_volume.properties_in: State Released.\n",
"2025-12-06 05:31:08 [INFO] idaes.init.fs.flash: Initialization Complete: optimal - Optimal Solution Found\n"
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 1 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 2 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 3 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 4 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_in: Initialization Step 5 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 1 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 2 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 3 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 4 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_out: Initialization Step 5 optimal - Optimal Solution Found.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_out: State Released.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume: Initialization Complete\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash.control_volume.properties_in: State Released.\n",
"2026-03-06 04:01:42 [INFO] idaes.init.fs.flash: Initialization Complete: optimal - Optimal Solution Found\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2026-03-06 04:01:43,983 [INFO] - Server is already running PID=89224\n"
]
}
],
Expand All @@ -101,7 +107,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 8,
"id": "02d7f383",
"metadata": {},
"outputs": [
Expand All @@ -115,15 +121,15 @@
" Upper bound: .inf\n",
" Number of objectives: 1\n",
" Number of constraints: 41\n",
" Number of variables: 41\n",
" Number of variables: 42\n",
" Sense: unknown\n",
"Solver: \n",
"- Status: ok\n",
" Message: Ipopt 3.13.2\\x3a Optimal Solution Found\n",
" Termination condition: optimal\n",
" Id: 0\n",
" Error rc: 0\n",
" Time: 0.005049467086791992\n",
" Time: 0.00626683235168457\n",
"Solution: \n",
"- number of solutions: 0\n",
" number of solutions displayed: 0\n",
Expand Down Expand Up @@ -155,13 +161,12 @@
"text": [
"Time per step:\n",
"\n",
" build : 0.022 14.5%\n",
" build : 0.018 12.4%\n",
" set_operating_conditions : 0.000 0.1%\n",
" initialize : 0.111 74.7%\n",
" set_solver : 0.000 0.0%\n",
" solve_initial : 0.016 10.7%\n",
" initialize : 0.108 75.0%\n",
" solve_initial : 0.018 12.5%\n",
"\n",
"Total time: 0.151 s\n",
"Total time: 0.145 s\n",
"\n"
]
}
Expand Down Expand Up @@ -236,7 +241,20 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Before: 368\n",
"Before: 368\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2026-03-06 04:01:46,069 [INFO] - Server is already running PID=89224\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"After : 368.85306111169916\n"
]
}
Expand Down Expand Up @@ -301,7 +319,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "idaes-py3.12",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
12 changes: 3 additions & 9 deletions docs/examples/structfs/hda_flowsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,11 @@ def init_function(unit):
seq.run(m, init_function)


@FS.step("set_solver")
def set_solver(ctx):
ctx.solver = SolverFactory("ipopt")


@FS.step("solve_initial")
def solve(ctx):
"""Perform the initial model solve."""
ctx["status"] = results = ctx.solver.solve(ctx.model, tee=ctx["tee"])
assert results.solver.termination_condition == TerminationCondition.optimal
ctx.solve()
assert ctx.results.solver.termination_condition == TerminationCondition.optimal


@FS.step("solve_optimization")
Expand Down Expand Up @@ -373,5 +368,4 @@ def solve_opt(ctx):

m.fs.product_purity = Constraint(expr=m.fs.purity >= 0.80)

results = ctx.solver.solve(ctx.model, tee=ctx["tee"])
ctx["results"] = results
ctx.solve()
Loading
Loading