Skip to content

Commit 767faf1

Browse files
committed
add warnings
1 parent 704d63b commit 767faf1

File tree

4 files changed

+143
-68
lines changed

4 files changed

+143
-68
lines changed

biosteam/__init__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
"""
1515
from __future__ import annotations
16-
__version__ = '2.52.16'
16+
__version__ = '2.52.17'
1717

1818
#: Chemical engineering plant cost index (defaults to 567.5 at 2017).
1919
CE: float = 567.5
@@ -89,6 +89,7 @@ def njit(*args, **kwargs):
8989
)
9090

9191
def nbtutorial(dark=False):
92+
global print_error
9293
main_flowsheet.clear()
9394
preferences.reset()
9495
if dark:
@@ -108,3 +109,25 @@ def display_table_as_html(series):
108109
return display(series.to_frame())
109110

110111
pd.Series._ipython_display_ = display_table_as_html
112+
113+
try:
114+
from _pytest.python_api import RaisesContext
115+
except:
116+
class PrintError:
117+
def __enter__(self):
118+
return self
119+
120+
def __exit__(self, type, exception, traceback):
121+
if exception is not None: print(f"{colors.exception(type.__name__)}: {exception}")
122+
return None
123+
else:
124+
class PrintError(RaisesContext):
125+
def __init__(self):
126+
super().__init__(Exception, 'did not raise exception')
127+
128+
def __exit__(self, type, exception, traceback):
129+
if exception is not None: print(f"{colors.exception(type.__name__)}: {exception}")
130+
return super().__exit__(type, exception, traceback)
131+
132+
print_error = PrintError()
133+

docs/tutorial/Phase_equilibrium.ipynb

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"cell_type": "code",
3333
"execution_count": 1,
3434
"metadata": {
35+
"editable": true,
36+
"slideshow": {
37+
"slide_type": ""
38+
},
3539
"tags": [
3640
"nbval-ignore-output"
3741
]
@@ -51,6 +55,7 @@
5155
"source": [
5256
"import biosteam as bst\n",
5357
"import numpy as np\n",
58+
"bst.nbtutorial()\n",
5459
"chemicals = bst.Chemicals(['Water', 'Ethanol'])\n",
5560
"bst.settings.set_thermo(chemicals)\n",
5661
"\n",
@@ -473,29 +478,25 @@
473478
"cell_type": "code",
474479
"execution_count": 16,
475480
"metadata": {
481+
"editable": true,
482+
"slideshow": {
483+
"slide_type": ""
484+
},
476485
"tags": [
477486
"nbval-raises-exception"
478487
]
479488
},
480489
"outputs": [
481490
{
482-
"ename": "InfeasibleRegion",
483-
"evalue": "phase composition is infeasible",
484-
"output_type": "error",
485-
"traceback": [
486-
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
487-
"\u001b[1;31mInfeasibleRegion\u001b[0m Traceback (most recent call last)",
488-
"Cell \u001b[1;32mIn[16], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m vle(x\u001b[38;5;241m=\u001b[39mnp\u001b[38;5;241m.\u001b[39marray([\u001b[38;5;241m0.2\u001b[39m, \u001b[38;5;241m0.8\u001b[39m]), P\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m101325\u001b[39m)\n\u001b[0;32m 2\u001b[0m vle\n",
489-
"File \u001b[1;32m~\\code\\biosteam\\thermosteam\\thermosteam\\equilibrium\\vle.py:450\u001b[0m, in \u001b[0;36mVLE.__call__\u001b[1;34m(self, T, P, V, H, S, Q, B, x, y, gas_conversion, liquid_conversion)\u001b[0m\n\u001b[0;32m 448\u001b[0m thermal_condition\u001b[38;5;241m.\u001b[39mP \u001b[38;5;241m=\u001b[39m P\n\u001b[0;32m 449\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m x_spec:\n\u001b[1;32m--> 450\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mset_Px(P, np\u001b[38;5;241m.\u001b[39masarray(x))\n\u001b[0;32m 451\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m: \u001b[38;5;66;03m# y_spec\u001b[39;00m\n\u001b[0;32m 452\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mset_Py(P, np\u001b[38;5;241m.\u001b[39masarray(y))\n",
490-
"File \u001b[1;32m~\\code\\biosteam\\thermosteam\\thermosteam\\equilibrium\\vle.py:664\u001b[0m, in \u001b[0;36mVLE.set_Px\u001b[1;34m(self, P, x)\u001b[0m\n\u001b[0;32m 662\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_N \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mnumber of species in equilibrium must be 2 to specify x\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 663\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_thermal_condition\u001b[38;5;241m.\u001b[39mT, y \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_bubble_point\u001b[38;5;241m.\u001b[39msolve_Ty(x, P) \n\u001b[1;32m--> 664\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_lever_rule(x, y)\n",
491-
"File \u001b[1;32m~\\code\\biosteam\\thermosteam\\thermosteam\\equilibrium\\vle.py:646\u001b[0m, in \u001b[0;36mVLE._lever_rule\u001b[1;34m(self, x, y)\u001b[0m\n\u001b[0;32m 644\u001b[0m split_frac \u001b[38;5;241m=\u001b[39m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_z[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m-\u001b[39mx[\u001b[38;5;241m0\u001b[39m])\u001b[38;5;241m/\u001b[39m(y[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m-\u001b[39mx[\u001b[38;5;241m0\u001b[39m])\n\u001b[0;32m 645\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m0.00001\u001b[39m \u001b[38;5;241m<\u001b[39m split_frac \u001b[38;5;241m<\u001b[39m \u001b[38;5;241m1.00001\u001b[39m:\n\u001b[1;32m--> 646\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InfeasibleRegion(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mphase composition\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 647\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m split_frac \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m 648\u001b[0m split_frac \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n",
492-
"\u001b[1;31mInfeasibleRegion\u001b[0m: phase composition is infeasible"
491+
"name": "stdout",
492+
"output_type": "stream",
493+
"text": [
494+
"\u001b[31m\u001b[1mInfeasibleRegion\u001b[0m: phase composition is infeasible\n"
493495
]
494496
}
495497
],
496498
"source": [
497-
"vle(x=np.array([0.2, 0.8]), P=101325)\n",
498-
"vle"
499+
"with bst.print_error: vle(x=np.array([0.2, 0.8]), P=101325)"
499500
]
500501
},
501502
{
@@ -514,13 +515,27 @@
514515
},
515516
{
516517
"cell_type": "code",
517-
"execution_count": null,
518+
"execution_count": 17,
518519
"metadata": {
519520
"tags": [
520521
"nbval-skip"
521522
]
522523
},
523-
"outputs": [],
524+
"outputs": [
525+
{
526+
"data": {
527+
"text/plain": [
528+
"LLE(imol=MolarFlowIndexer(\n",
529+
" L=[('Water', 290.6), ('Octane', 0.02062), ('Butanol', 4.3)],\n",
530+
" l=[('Water', 13.35), ('Octane', 99.98), ('Butanol', 25.7)]),\n",
531+
" thermal_condition=ThermalCondition(T=360.00, P=101325))"
532+
]
533+
},
534+
"execution_count": 17,
535+
"metadata": {},
536+
"output_type": "execute_result"
537+
}
538+
],
524539
"source": [
525540
"bst.settings.set_thermo(['Water', 'Octane', 'Butanol'])\n",
526541
"lle = bst.equilibrium.LLE()\n",
@@ -552,7 +567,7 @@
552567
},
553568
{
554569
"cell_type": "code",
555-
"execution_count": 17,
570+
"execution_count": 18,
556571
"metadata": {},
557572
"outputs": [
558573
{
@@ -563,7 +578,7 @@
563578
" thermal_condition=ThermalCondition(T=298.15, P=101325))"
564579
]
565580
},
566-
"execution_count": 17,
581+
"execution_count": 18,
567582
"metadata": {},
568583
"output_type": "execute_result"
569584
}
@@ -596,7 +611,7 @@
596611
},
597612
{
598613
"cell_type": "code",
599-
"execution_count": 18,
614+
"execution_count": 19,
600615
"metadata": {},
601616
"outputs": [
602617
{
@@ -609,7 +624,7 @@
609624
" thermal_condition=ThermalCondition(T=355.00, P=101325))"
610625
]
611626
},
612-
"execution_count": 18,
627+
"execution_count": 19,
613628
"metadata": {},
614629
"output_type": "execute_result"
615630
}
@@ -621,7 +636,7 @@
621636
},
622637
{
623638
"cell_type": "code",
624-
"execution_count": 19,
639+
"execution_count": 20,
625640
"metadata": {},
626641
"outputs": [
627642
{
@@ -634,7 +649,7 @@
634649
" thermal_condition=ThermalCondition(T=355.00, P=101325))"
635650
]
636651
},
637-
"execution_count": 19,
652+
"execution_count": 20,
638653
"metadata": {},
639654
"output_type": "execute_result"
640655
}
@@ -647,8 +662,14 @@
647662
},
648663
{
649664
"cell_type": "code",
650-
"execution_count": 20,
651-
"metadata": {},
665+
"execution_count": 21,
666+
"metadata": {
667+
"editable": true,
668+
"slideshow": {
669+
"slide_type": ""
670+
},
671+
"tags": []
672+
},
652673
"outputs": [
653674
{
654675
"data": {
@@ -660,7 +681,7 @@
660681
" thermal_condition=ThermalCondition(T=358.76, P=101325))"
661682
]
662683
},
663-
"execution_count": 20,
684+
"execution_count": 21,
664685
"metadata": {},
665686
"output_type": "execute_result"
666687
}
@@ -669,6 +690,20 @@
669690
"vlle(V=0.5, P=101325)\n",
670691
"vlle"
671692
]
693+
},
694+
{
695+
"cell_type": "raw",
696+
"metadata": {
697+
"editable": true,
698+
"raw_mimetype": "text/restructuredtext",
699+
"slideshow": {
700+
"slide_type": ""
701+
},
702+
"tags": []
703+
},
704+
"source": [
705+
" .. warning:: VLLE is an experimental feature; results may not be accurate nor consistent. "
706+
]
672707
}
673708
],
674709
"metadata": {

0 commit comments

Comments
 (0)