From c91c531fda65c2c7ba84269aac5b4579d41bc000 Mon Sep 17 00:00:00 2001 From: Kakodkar Date: Mon, 17 Nov 2025 17:44:49 -0600 Subject: [PATCH 1/5] del random print statement --- docs/examples/design_scheduling.ipynb | 114 ++++++++++---------- src/energia/modeling/constraints/balance.py | 8 -- 2 files changed, 57 insertions(+), 65 deletions(-) diff --git a/docs/examples/design_scheduling.ipynb b/docs/examples/design_scheduling.ipynb index f7a086e3..5eb5564a 100644 --- a/docs/examples/design_scheduling.ipynb +++ b/docs/examples/design_scheduling.ipynb @@ -85,11 +85,11 @@ "output_type": "stream", "text": [ "⚖ Initiated solar balance in (l0, q) ⏱ 0.0002 s\n", - "🔗 Bound [≤] solar consume in (l0, q) ⏱ 0.0012 s\n", + "🔗 Bound [≤] solar consume in (l0, q) ⏱ 0.0009 s\n", "⚖ Initiated wind balance in (l0, y) ⏱ 0.0001 s\n", - "🔗 Bound [≤] wind consume in (l0, y) ⏱ 0.0007 s\n", + "🔗 Bound [≤] wind consume in (l0, y) ⏱ 0.0006 s\n", "⚖ Initiated power balance in (l0, q) ⏱ 0.0001 s\n", - "🔗 Bound [≥] power release in (l0, q) ⏱ 0.0011 s\n" + "🔗 Bound [≥] power release in (l0, q) ⏱ 0.0007 s\n" ] } ], @@ -129,8 +129,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "🔗 Bound [≤] wf capacity in (l0, y) ⏱ 0.0003 s\n", - "🔗 Bound [≥] wf capacity in (l0, y) ⏱ 0.0002 s\n" + "🔗 Bound [≤] wf capacity in (l0, y) ⏱ 0.0002 s\n", + "🔗 Bound [≥] wf capacity in (l0, y) ⏱ 0.0003 s\n" ] }, { @@ -186,10 +186,10 @@ "name": "stderr", "output_type": "stream", "text": [ - "🔗 Bound [≤] wf operate in (l0, q) ⏱ 0.0004 s\n", - "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0003 s\n", + "🔗 Bound [≤] wf operate in (l0, q) ⏱ 0.0003 s\n", + "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0002 s\n", "🧭 Mapped time for operate (wf, l0, q) ⟺ (wf, l0, y) ⏱ 0.0002 s\n", - "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0004 s\n" + "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0003 s\n" ] }, { @@ -207,7 +207,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [20]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{0}}}} - 1.0 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" + "$\\displaystyle [26]\\text{ }{\\mathbf{spend}}_{{usd},{l0},{{{y}_{0}}},{\\mathbf{{opr}}},{wf}} - 49.0 \\cdot {\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}}} = 0$" ], "text/plain": [ "" @@ -219,7 +219,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [21]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{1}}}} - 0.888888888888889 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" + "$\\displaystyle [20]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{0}}}} - 1.0 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" ], "text/plain": [ "" @@ -231,7 +231,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [22]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{2}}}} - 0.5555555555555556 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" + "$\\displaystyle [21]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{1}}}} - 0.888888888888889 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" ], "text/plain": [ "" @@ -243,7 +243,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [23]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{3}}}} - 0.7777777777777777 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" + "$\\displaystyle [22]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{2}}}} - 0.5555555555555556 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" ], "text/plain": [ "" @@ -255,7 +255,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [26]\\text{ }{\\mathbf{spend}}_{{usd},{l0},{{{y}_{0}}},{\\mathbf{{opr}}},{wf}} - 49.0 \\cdot {\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}}} = 0$" + "$\\displaystyle [23]\\text{ }{\\mathbf{{opr}}}_{{wf},{l0},{{{y}_{0}}},{{{q}_{3}}}} - 0.7777777777777777 \\cdot {\\mathbf{{cap}}}_{{wf},{l0},{{{y}_{0}}}} \\leq 0$" ], "text/plain": [ "" @@ -282,12 +282,12 @@ "name": "stderr", "output_type": "stream", "text": [ - "🔗 Bound [≤] pv capacity in (l0, y) ⏱ 0.0005 s\n", + "🔗 Bound [≤] pv capacity in (l0, y) ⏱ 0.0004 s\n", "🔗 Bound [≥] pv capacity in (l0, y) ⏱ 0.0002 s\n", - "🔗 Bound [≤] pv operate in (l0, q) ⏱ 0.0004 s\n", - "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0003 s\n", + "🔗 Bound [≤] pv operate in (l0, q) ⏱ 0.0003 s\n", + "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0002 s\n", "🧭 Mapped time for operate (pv, l0, q) ⟺ (pv, l0, y) ⏱ 0.0002 s\n", - "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0003 s\n" + "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0002 s\n" ] } ], @@ -333,7 +333,7 @@ "🔗 Bound [≤] lii.stored invcapacity in (l0, y) ⏱ 0.0003 s\n", "🔗 Bound [≥] lii.stored invcapacity in (l0, y) ⏱ 0.0002 s\n", "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0003 s\n", - "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0006 s\n" + "🔗 Bound [=] usd spend in (l0, y) ⏱ 0.0004 s\n" ] } ], @@ -376,51 +376,51 @@ "text": [ "💡 Assumed pv capacity unbounded in (l0, y) ⏱ 0.0001 s\n", "💡 Assumed pv operate bounded by capacity in (l0, q) ⏱ 0.0001 s\n", - "⚖ Updated power balance with produce(power, l0, q, operate, pv) ⏱ 0.0002 s\n", - "🔗 Bound [=] power produce in (l0, q) ⏱ 0.0011 s\n", + "⚖ Updated power balance with produce(power, l0, q, operate, pv) ⏱ 0.0001 s\n", + "🔗 Bound [=] power produce in (l0, q) ⏱ 0.0010 s\n", "⚖ Updated solar balance with expend(solar, l0, q, operate, pv) ⏱ 0.0001 s\n", - "🔗 Bound [=] solar expend in (l0, q) ⏱ 0.0010 s\n", - "🏭 Operating streams introduced for pv in l0 ⏱ 0.0032 s\n", + "🔗 Bound [=] solar expend in (l0, q) ⏱ 0.0008 s\n", + "🏭 Operating streams introduced for pv in l0 ⏱ 0.0028 s\n", "🏗 Construction streams introduced for pv in l0 ⏱ 0.0000 s\n", - "🌍 Located pv in l0 ⏱ 0.0050 s\n", + "🌍 Located pv in l0 ⏱ 0.0044 s\n", "💡 Assumed wf capacity unbounded in (l0, y) ⏱ 0.0001 s\n", "💡 Assumed wf operate bounded by capacity in (l0, q) ⏱ 0.0001 s\n", - "⚖ Updated power balance with produce(power, l0, q, operate, wf) ⏱ 0.0002 s\n", + "⚖ Updated power balance with produce(power, l0, q, operate, wf) ⏱ 0.0001 s\n", "🔗 Bound [=] power produce in (l0, q) ⏱ 0.0009 s\n", "⚖ Updated wind balance with expend(wind, l0, y, operate, wf) ⏱ 0.0001 s\n", "🔗 Bound [=] wind expend in (l0, y) ⏱ 0.0009 s\n", - "🏭 Operating streams introduced for wf in l0 ⏱ 0.0027 s\n", + "🏭 Operating streams introduced for wf in l0 ⏱ 0.0031 s\n", "🏗 Construction streams introduced for wf in l0 ⏱ 0.0000 s\n", - "🌍 Located wf in l0 ⏱ 0.0044 s\n", + "🌍 Located wf in l0 ⏱ 0.0045 s\n", "💡 Assumed lii capacity unbounded in (l0, y) ⏱ 0.0001 s\n", "🧭 Mapped time for inventory (lii.stored, l0, q) ⟺ (lii.stored, l0, y) ⏱ 0.0002 s\n", "⚖ Initiated lii.stored balance in (l0, q) ⏱ 0.0003 s\n", - "🔗 Bound [≤] lii.stored inventory in (l0, q) ⏱ 0.0018 s\n", - "💡 Assumed lii inventory bounded by capacity in (l0, q) ⏱ 0.0021 s\n", + "🔗 Bound [≤] lii.stored inventory in (l0, q) ⏱ 0.0016 s\n", + "💡 Assumed lii inventory bounded by capacity in (l0, q) ⏱ 0.0019 s\n", "💡 Assumed lii.charge capacity unbounded in (l0, y) ⏱ 0.0002 s\n", "🔗 Bound [≤] lii.charge operate in (l0, y) ⏱ 0.0003 s\n", - "💡 Assumed lii.charge operate bounded by capacity in (l0, y) ⏱ 0.0005 s\n", - "🧭 Mapped time for operate (lii.charge, l0, q) ⟺ (lii.charge, l0, y) ⏱ 0.0002 s\n", - "⚖ Updated lii.stored balance with produce(lii.stored, l0, q, operate, lii.charge) ⏱ 0.0002 s\n", - "🔗 Bound [=] lii.stored produce in (l0, q) ⏱ 0.0011 s\n", - "⚖ Updated power balance with expend(power, l0, q, operate, lii.charge) ⏱ 0.0002 s\n", - "🔗 Bound [=] power expend in (l0, q) ⏱ 0.0029 s\n", - "🏭 Operating streams introduced for lii.charge in l0 ⏱ 0.0055 s\n", + "💡 Assumed lii.charge operate bounded by capacity in (l0, y) ⏱ 0.0006 s\n", + "🧭 Mapped time for operate (lii.charge, l0, q) ⟺ (lii.charge, l0, y) ⏱ 0.0001 s\n", + "⚖ Updated lii.stored balance with produce(lii.stored, l0, q, operate, lii.charge) ⏱ 0.0001 s\n", + "🔗 Bound [=] lii.stored produce in (l0, q) ⏱ 0.0008 s\n", + "⚖ Updated power balance with expend(power, l0, q, operate, lii.charge) ⏱ 0.0001 s\n", + "🔗 Bound [=] power expend in (l0, q) ⏱ 0.0009 s\n", + "🏭 Operating streams introduced for lii.charge in l0 ⏱ 0.0030 s\n", "🏗 Construction streams introduced for lii.charge in l0 ⏱ 0.0000 s\n", - "🌍 Located lii.charge in l0 ⏱ 0.0074 s\n", + "🌍 Located lii.charge in l0 ⏱ 0.0048 s\n", "💡 Assumed lii.discharge capacity unbounded in (l0, y) ⏱ 0.0002 s\n", "🔗 Bound [≤] lii.discharge operate in (l0, y) ⏱ 0.0003 s\n", "💡 Assumed lii.discharge operate bounded by capacity in (l0, y) ⏱ 0.0006 s\n", "🧭 Mapped time for operate (lii.discharge, l0, q) ⟺ (lii.discharge, l0, y) ⏱ 0.0002 s\n", "⚖ Updated power balance with produce(power, l0, q, operate, lii.discharge) ⏱ 0.0001 s\n", - "🔗 Bound [=] power produce in (l0, q) ⏱ 0.0009 s\n", - "⚖ Updated lii.stored balance with expend(lii.stored, l0, q, operate, lii.discharge) ⏱ 0.0001 s\n", - "🔗 Bound [=] lii.stored expend in (l0, q) ⏱ 0.0009 s\n", - "🏭 Operating streams introduced for lii.discharge in l0 ⏱ 0.0035 s\n", + "🔗 Bound [=] power produce in (l0, q) ⏱ 0.0008 s\n", + "⚖ Updated lii.stored balance with expend(lii.stored, l0, q, operate, lii.discharge) ⏱ 0.0003 s\n", + "🔗 Bound [=] lii.stored expend in (l0, q) ⏱ 0.0012 s\n", + "🏭 Operating streams introduced for lii.discharge in l0 ⏱ 0.0036 s\n", "🏗 Construction streams introduced for lii.discharge in l0 ⏱ 0.0000 s\n", - "🌍 Located lii.discharge in l0 ⏱ 0.0054 s\n", + "🌍 Located lii.discharge in l0 ⏱ 0.0055 s\n", "🏗 Construction streams introduced for lii in l0 ⏱ 0.0000 s\n", - "🌍 Located lii in l0 ⏱ 0.0162 s\n" + "🌍 Located lii in l0 ⏱ 0.0134 s\n" ] } ], @@ -448,7 +448,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [21]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}_{{usd},{l0},{y},{\\mathbf{{inv}}},{lii.stored}} - 2000 \\cdot {\\mathbf{{\\mathbf{{inv}}}}}_{{lii.stored},{l0},{y}} = 0$" + "$\\displaystyle [27]\\text{ }-{\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}}}_{{lii.stored},{l0},{y},{q}} + {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}}}_{{lii.stored},{l0},{y},{{q}-1}} + {\\mathbf{{\\mathbf{{\\mathbf{prod}}}}}}_{{lii.stored},{l0},{y},{q},{\\mathbf{{opr}}},{lii.charge}} - {\\mathbf{{\\mathbf{{\\mathbf{{expd}}}}}}}_{{lii.stored},{l0},{y},{q},{\\mathbf{{opr}}},{lii.discharge}} = 0$" ], "text/plain": [ "" @@ -460,7 +460,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [26]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}_{{lii.stored},{l0},{y}} - \\sum_{i \\in {q}} {\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}_{{lii.stored}, {l0}, {y}, i} = 0$" + "$\\displaystyle [28]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}_{{lii.stored},{l0},{y},{q}} - {\\mathbf{{\\mathbf{{icap}}}}}_{{lii.stored},{l0},{y}} \\leq 0$" ], "text/plain": [ "" @@ -472,7 +472,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [27]\\text{ }-{\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}}}_{{lii.stored},{l0},{y},{q}} + {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}}}_{{lii.stored},{l0},{y},{{q}-1}} + {\\mathbf{{\\mathbf{{\\mathbf{prod}}}}}}_{{lii.stored},{l0},{y},{q},{\\mathbf{{opr}}},{lii.charge}} - {\\mathbf{{\\mathbf{{\\mathbf{{expd}}}}}}}_{{lii.stored},{l0},{y},{q},{\\mathbf{{opr}}},{lii.discharge}} = 0$" + "$\\displaystyle [21]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}_{{usd},{l0},{y},{\\mathbf{{inv}}},{lii.stored}} - 2000 \\cdot {\\mathbf{{\\mathbf{{inv}}}}}_{{lii.stored},{l0},{y}} = 0$" ], "text/plain": [ "" @@ -484,7 +484,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [28]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}_{{lii.stored},{l0},{y},{q}} - {\\mathbf{{\\mathbf{{icap}}}}}_{{lii.stored},{l0},{y}} \\leq 0$" + "$\\displaystyle [26]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}_{{lii.stored},{l0},{y}} - \\sum_{i \\in {q}} {\\mathbf{{\\mathbf{{\\mathbf{{inv}}}}}}}_{{lii.stored}, {l0}, {y}, i} = 0$" ], "text/plain": [ "" @@ -516,13 +516,13 @@ "name": "stderr", "output_type": "stream", "text": [ - "🧭 Mapped samples for spend (usd, l0, y, capacity, wf) ⟺ (usd, l0, y) ⏱ 0.0002 s\n", + "🧭 Mapped samples for spend (usd, l0, y, capacity, wf) ⟺ (usd, l0, y) ⏱ 0.0001 s\n", "🧭 Mapped samples for spend (usd, l0, y, operate, wf) ⟺ (usd, l0, y) ⏱ 0.0002 s\n", - "🧭 Mapped samples for spend (usd, l0, y, capacity, pv) ⟺ (usd, l0, y) ⏱ 0.0002 s\n", - "🧭 Mapped samples for spend (usd, l0, y, operate, pv) ⟺ (usd, l0, y) ⏱ 0.0004 s\n", + "🧭 Mapped samples for spend (usd, l0, y, capacity, pv) ⟺ (usd, l0, y) ⏱ 0.0003 s\n", + "🧭 Mapped samples for spend (usd, l0, y, operate, pv) ⟺ (usd, l0, y) ⏱ 0.0002 s\n", "🧭 Mapped samples for spend (usd, l0, y, invcapacity, lii.stored) ⟺ (usd, l0, y) ⏱ 0.0002 s\n", "🧭 Mapped samples for spend (usd, l0, y, inventory, lii.stored) ⟺ (usd, l0, y) ⏱ 0.0002 s\n", - "📝 Generated Program(scheduling).mps ⏱ 0.0039 s\n" + "📝 Generated Program(scheduling).mps ⏱ 0.0032 s\n" ] }, { @@ -540,7 +540,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "📝 Generated gurobipy model. See .formulation ⏱ 0.0086 s\n" + "📝 Generated gurobipy model. See .formulation ⏱ 0.0070 s\n" ] }, { @@ -585,8 +585,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "📝 Generated Solution object for Program(scheduling). See .solution ⏱ 0.0007 s\n", - "✅ Program(scheduling) optimized using gurobi. Display using .output() ⏱ 0.0218 s\n" + "📝 Generated Solution object for Program(scheduling). See .solution ⏱ 0.0006 s\n", + "✅ Program(scheduling) optimized using gurobi. Display using .output() ⏱ 0.0168 s\n" ] } ], @@ -2165,7 +2165,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [37]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}_{{usd},{l0},{y}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{cap}}},{wf}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{opr}}},{wf}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{cap}}},{pv}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{opr}}},{pv}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{icap}}},{lii.stored}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{inv}}},{lii.stored}} = 0$" + "$\\displaystyle [13]\\text{ }10 \\cdot {\\mathbf{{\\mathbf{{\\mathbf{{\\breve{{cap}}}}}}}}}_{{pv},{l0},{y}} - {\\mathbf{{\\mathbf{{\\mathbf{{cap}}}}}}}_{{pv},{l0},{y}} \\leq 0$" ], "text/plain": [ "" @@ -2177,7 +2177,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [15]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}_{{usd},{l0},{y},{\\mathbf{{cap}}},{pv}} - 1439046 \\cdot {\\mathbf{{\\mathbf{{\\mathbf{{cap}}}}}}}_{{pv},{l0},{y}} = 0$" + "$\\displaystyle [12]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{{cap}}}}}}}_{{pv},{l0},{y}} - 100 \\cdot {\\mathbf{{\\mathbf{{\\mathbf{{\\breve{{cap}}}}}}}}}_{{pv},{l0},{y}} \\leq 0$" ], "text/plain": [ "" @@ -2189,7 +2189,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [12]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{{cap}}}}}}}_{{pv},{l0},{y}} - 100 \\cdot {\\mathbf{{\\mathbf{{\\mathbf{{\\breve{{cap}}}}}}}}}_{{pv},{l0},{y}} \\leq 0$" + "$\\displaystyle [37]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}_{{usd},{l0},{y}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{cap}}},{wf}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{opr}}},{wf}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{cap}}},{pv}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{opr}}},{pv}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{icap}}},{lii.stored}} - {\\mathbf{{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}}}_{{usd},{l0},{y},{\\mathbf{{inv}}},{lii.stored}} = 0$" ], "text/plain": [ "" @@ -2201,7 +2201,7 @@ { "data": { "text/latex": [ - "$\\displaystyle [13]\\text{ }10 \\cdot {\\mathbf{{\\mathbf{{\\mathbf{{\\breve{{cap}}}}}}}}}_{{pv},{l0},{y}} - {\\mathbf{{\\mathbf{{\\mathbf{{cap}}}}}}}_{{pv},{l0},{y}} \\leq 0$" + "$\\displaystyle [15]\\text{ }{\\mathbf{{\\mathbf{{\\mathbf{spend}}}}}}_{{usd},{l0},{y},{\\mathbf{{cap}}},{pv}} - 1439046 \\cdot {\\mathbf{{\\mathbf{{\\mathbf{{cap}}}}}}}_{{pv},{l0},{y}} = 0$" ], "text/plain": [ "" diff --git a/src/energia/modeling/constraints/balance.py b/src/energia/modeling/constraints/balance.py index 3949964b..d7cdd13e 100644 --- a/src/energia/modeling/constraints/balance.py +++ b/src/energia/modeling/constraints/balance.py @@ -104,20 +104,12 @@ def existing_aspects(self): @cached_property def updated_part(self) -> V | F | int: """Returns the part of the constraint that is new""" - if self.stored and self.aspect == "inventory": # if inventory is being add to GRB - if len(self.time) == 1: # cannot lag a single time period return 0 - print( - self.aspect, - self.aspect.domains, - self.domain.I, - self.domain.edit({"lag": -1 * self.time, "periods": None}).I, - ) return ( self(*self.domain).V() - self(*self.domain.edit({"lag": -1 * self.time, "periods": None})).V() From fbebf1f57633c21d621bd51b8d2548fd9e68611c Mon Sep 17 00:00:00 2001 From: Kakodkar Date: Mon, 17 Nov 2025 17:58:42 -0600 Subject: [PATCH 2/5] non None construction check --- docs/examples/design_scheduling.ipynb | 2 +- src/energia/components/operations/operation.py | 4 ++-- src/energia/components/operations/storage.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/examples/design_scheduling.ipynb b/docs/examples/design_scheduling.ipynb index 5eb5564a..76f76104 100644 --- a/docs/examples/design_scheduling.ipynb +++ b/docs/examples/design_scheduling.ipynb @@ -2232,7 +2232,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.9" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/src/energia/components/operations/operation.py b/src/energia/components/operations/operation.py index b73d55a5..c5eccd53 100644 --- a/src/energia/components/operations/operation.py +++ b/src/energia/components/operations/operation.py @@ -180,7 +180,7 @@ def _check_operate_bound(self, space: Location | Linkage): def _update_space_times( self, space: Location | Linkage, - space_times: list[tuple[Periods, Location | Linkage]], + space_times: list[tuple[Location | Linkage, Periods]], ): """Update space times for the operation""" @@ -212,7 +212,7 @@ def locate(self, *spaces: Location | Linkage): self.write_primary_conversion(space_times) - if self.construction is not None: + if self.construction: self.write_construction(self.space_times) return self, spaces diff --git a/src/energia/components/operations/storage.py b/src/energia/components/operations/storage.py index b21c71a5..d05af477 100644 --- a/src/energia/components/operations/storage.py +++ b/src/energia/components/operations/storage.py @@ -275,7 +275,7 @@ def locate(self, *spaces: Location): self.charge.locate(*spaces) self.discharge.locate(*spaces) - if self.construction is not None: + if self.construction: self.write_construction(self.space_times) return self, spaces From 97aa9207e3090f3f462de4d387336e4160d0c0d2 Mon Sep 17 00:00:00 2001 From: Kakodkar Date: Mon, 17 Nov 2025 18:26:16 -0600 Subject: [PATCH 3/5] retry writing inventory --- src/energia/components/operations/storage.py | 15 ++++++++++++- src/energia/utils/modeling.py | 23 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/energia/utils/modeling.py diff --git a/src/energia/components/operations/storage.py b/src/energia/components/operations/storage.py index d05af477..991ba43d 100644 --- a/src/energia/components/operations/storage.py +++ b/src/energia/components/operations/storage.py @@ -10,6 +10,7 @@ from ...modeling.parameters.conversion import Conversion from ...modeling.parameters.conversions import Construction from ...utils.decorators import timer +from ...utils.modeling import retry from ..commodities.resource import Resource from .process import Process @@ -238,8 +239,16 @@ def _check_inventory_bound( time = self._filter_time(self._get_times(space)) + #! FIXME: not entirely sure why retry is needed here # if not just write opr_{pro, loc, horizon} <= capacity_{pro, loc, horizon} - _ = self.inventory(space, time) <= 1 + # _ = self.inventory(space, time) <= 1 + + _ = retry( + lambda: self.inventory(space, time) <= 1, + attempts=2, + exceptions=KeyError, + ) + return self, space, time return False @@ -265,6 +274,10 @@ def locate(self, *spaces: Location): # update the locations at which the storage exists # get location, time tuples where operation is defined + + if not spaces: + spaces = (self.network,) + for space in spaces: self._check_capacity_bound(space) diff --git a/src/energia/utils/modeling.py b/src/energia/utils/modeling.py new file mode 100644 index 00000000..17e252fe --- /dev/null +++ b/src/energia/utils/modeling.py @@ -0,0 +1,23 @@ +"""Utilities for modeling""" + + +def retry(func, attempts: int = 2, exceptions=(Exception,)): + """ + Retry a function a number of times if it raises specified exceptions. + + :param func: The function to retry. + :type func: callable + :param attempts: Number of attempts. + :type attempts: int + :param exceptions: Exceptions to catch and retry on. + :type exceptions: tuple[Exception] + + :return: The result of the function if successful. + """ + last_exception = None + for _ in range(attempts): + try: + return func() + except exceptions as e: + last_exception = e + raise last_exception From ab6bac63d88fe348a19c932d7474f938c4e7327d Mon Sep 17 00:00:00 2001 From: Kakodkar Date: Mon, 17 Nov 2025 18:36:45 -0600 Subject: [PATCH 4/5] getattr for Storage --- src/energia/components/operations/storage.py | 39 ++++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/energia/components/operations/storage.py b/src/energia/components/operations/storage.py index 991ba43d..47f76305 100644 --- a/src/energia/components/operations/storage.py +++ b/src/energia/components/operations/storage.py @@ -140,26 +140,6 @@ def inventory_aspect(self) -> Aspect: """Reports inventory as aspect""" return getattr(self.model, 'inventory') - @property - def capacity(self) -> Sample: - """Reports invcapacity as capacity""" - return self.stored.invcapacity - - @property - def setup(self) -> Sample: - """Reports invsetup as setup""" - return self.stored.invsetup - - @property - def dismantle(self) -> Sample: - """Reports invdismantle as dismantle""" - return self.stored.invdismantle - - @property - def inventory(self) -> Sample: - """Inventory of the stored resource""" - return self.stored.inventory - @property def basis(self) -> Resource: """Base resource""" @@ -393,6 +373,25 @@ def __setattr__(self, name, value): super().__setattr__(name, value) + def __getattr__(self, name): + + # for Storage to make a distinction + # these are called inv + aspect name + # for e.g.: capacity -> invcapacity + # secondly, these are all defined based on the stored resource + if name in [ + "capacity", + "setup", + "dismantle", + ]: + return getattr(self.stored, "inv" + name) + + # these are directly defined based on the stored resource + if name in ["inventory"]: + return getattr(self.stored, name) + + return super().__getattr__(name) + def __call__(self, resource: Stored | Conversion): """Conversion is called with a Resource to be converted""" From 17c706ffa1e86649dde526551218c7b6d172429e Mon Sep 17 00:00:00 2001 From: Kakodkar Date: Mon, 17 Nov 2025 18:40:05 -0600 Subject: [PATCH 5/5] changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 728de82f..ad211fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.1.7] - Unreleased + +### Changed +- getattr dunder to pull attrs from constituents in Storage + +### Fixed +- retry to fix strange variable index bug when writing inventory bound + + + ## [2.1.6] - 2025-11-17 ### Changed