Graphviz works with minimal example, but not in Biosteam #158
-
I have the following code from Biosteam tutorial. The last snippet from Graphviz works, so I assume it is correctly installed, but I do not get any diagram from Biosteam. Could you please help? Thank you. import biosteam as bst
import os
from biosteam import settings
path_variable = os.environ.get('PATH')
print(path_variable)
bst.nbtutorial() # Light-mode html diagrams and filter warnings
settings.set_thermo(['Water', 'Methanol'])
feed = bst.Stream(Water=50, Methanol=20)
feed.show()
feed.price = 0.15 # USD/kg
feed.cost # USD/hr
settings.CEPCI # Default year is 2017
settings.CEPCI = 603.1 # To year 2018
settings.electricity_price # Default price (USD/kWhr)
settings.electricity_price = 0.065 # Adjust price
settings.cooling_agents # All available cooling agents
cooling_water = settings.get_cooling_agent('cooling_water')
cooling_water.show() # A UtilityAgent
# Price of regenerating the utility in USD/kmol
cooling_water.regeneration_price
# Other utilities may be priced for amount of heat transfered in USD/kJ
chilled_water = settings.get_cooling_agent('chilled_water')
chilled_water.heat_transfer_price
cooling_water.T = 302 # Change the temperature of cooling water (K)
settings.heating_agents # All available heating agents
lps = settings.get_heating_agent('low_pressure_steam') # A UtilityAgent
lps.show() # Note that because utility changes phase, T_limit is None
lps.regeneration_price = 0.20 # Adjust price (USD/kmol)
from biosteam import units
# Specify vapor fraction and isobaric conditions
F1 = units.Flash('F1', V=0.1, P=101325)
F1.show()
F1.ins
F1.outs
F1.ins[0] = feed
F1.show()
F1.simulate()
F1.show()
print(F1.results()) # Default returns DataFrame object with units
F1.net_duty # Duty [kJ / hr]
F1.net_power # Electricity consumption [kW]
[F1.feed, F1.vapor, F1.liquid] # Inlet feed and vapor and liquid outlets
M1 = units.Mixer('M1')
S1 = units.Splitter('S1', outs=('liquid_recycle', 'liquid_product'),
split=0.5) # Split to 0th output stream
F1.outs[0].ID = 'vapor_product'
F1.outs[1].ID = 'liquid'
bst.main_flowsheet.diagram()
# Note that empty streams are dashed and the
# width of streams depend on their flow rates (by mass)
feed = bst.Stream('feed', Methanol=100, Water=450)
# Broken down -pipe- notation
[S1-0, feed]-M1 # M1.ins[:] = [S1.outs[0], feed]
M1-F1 # F1.ins[:] = M1.outs
F1-1-S1 # S1.ins[:] = [F1.outs[1]]
# All together
[S1-0, feed]-M1-F1-1-S1;
#NONE OF THIS WORKS
bst.main_flowsheet.diagram()
bst.F.diagram()
# THIS WORKS
import graphviz
g = graphviz.Digraph('G', filename='hello.gv')
g.edge ('Hello', 'World')
g.view() |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Are there objectives on your Can you try an established system: from biorefineries import cornstover as cs
cs.load()
cs.cornstover_sys.diagram() If you can see a figure, then everything is fine, if there are problems with graphviz, you should get a warning message mentioning graphviz installation issues, and you may get more information by firstly letting biosteam raise the error: bst.preferences.raise_exception = True
# then repeat whatever needed to reproduce the problem, will be super helpful if you post the warning/error messages with full traceback |
Beta Was this translation helpful? Give feedback.
-
Yeah, @Scheideba used PyCharm and had this same problem. The issue was he was running his code through the terminal and not through the ipython console. If this is the issue, maybe the following thread can help: Alternatively, if you prefer to use the terminal (not ipython), you can view diagrams through the graphviz view command (which saves a file and then opens it externally) as follows: from biorefineries import cornstover as cs
cs.load()
f = cs.cornstover_sys.diagram(
# Do not display in IPython console and return a graphviz.graphs.Digraph object
display=False
)
f.view('filename') For additional details on making diagrams (such as saving them directly), check out https://biosteam.readthedocs.io/en/latest/API/System.html#biosteam.System.diagram I hope this helps, |
Beta Was this translation helpful? Give feedback.
@zorzansi, @yalinli2
Yeah, @Scheideba used PyCharm and had this same problem. The issue was he was running his code through the terminal and not through the ipython console. If this is the issue, maybe the following thread can help:
https://stackoverflow.com/questions/47765237/cant-use-ipython-console-in-pycharm
Alternatively, if you prefer to use the terminal (not ipython), you can view diagrams through the graphviz view command (which saves a file and then opens it externally) as follows: