Open om11kar opened 1 year ago
@om11kar, I will let @yalinli2 take the first look at this issue (whenever she gets a chance... she may be busy). In the mean while, could you please update your issue with the following guidelines?
load_system('SSCF')
Thanks
Hi @om11kar , yes following Yoel's suggestions would make it much easier for us to debug. But by looking at your script, it seems that you were trying to run the old analysis codes, the module has been updated updated, the easiest way to create a model would be:
from biorefineries import lactic as la
model = la.create_model()
sys = model.system # accessing the system
flowsheet = sys.flowsheet
I have been working on the Fermentation of Lactic Acid and tried to use the Fermentation code given in the Bioindustrial-Park/biorefineries. The code is as follows: -
import numpy as np import pandas as pd import biosteam as bst from warnings import warn from biosteam.utils import TicToc from biorefineries.lactic import _load_system, SSCF_flowsheet, SSCF_funcs, SHF_flowsheet, SHF_funcs from biorefineries.lactic._chemicals import sugars from biorefineries.lactic.utils import set_yield
_load_system('SSCF') _load_system('SHF')
Initiate a timer
timer = TicToc('timer') timer.tic() run_number = 0 sugar_concs = [[], []] lactics ={'target yield': [], 'target titer': [], 'actual yield': [], 'actual titer': []} MPSPs = {0.89: [], 0.18: [], 1.92: []} NPVs = {0.89: [], 0.18: [], 1.92: []} GWPs = {0.89: [], 0.18: [], 1.92: []} FECs = {0.89: [], 0.18: [], 1.92: []}
def compute_sugar_conc(stream): return stream.imass[sugars].sum()/stream.F_vol
def solve_TEA(lactic_acid, lactic_tea): lactic_acid.price = 0 for i in range(3): MPSP = lactic_acid.price = lactic_tea.solve_price(lactic_acid) return MPSP
def update_productivity(R301,R302,productivity): R301.productivity = productivity R302.productivity = productivity * R302.ferm_ratio for unit in (R301, R302): unit._design() unit._cost()
def simulate_log_results(kind): kind = kind.upper() if 'SSCF' in kind: flowsheet = SSCF_flowsheet funcs = SHF_funcs bst.main_flowsheet.set_flowsheet(flowsheet) _load_system(kind)
def save_data_clear(): df = pd.DataFrame({ ('Lactic acid','Target Yield [g/g]'): lactics['target yield'], ('Lactic acid','Target Titer [g/L]'): lactics['target titer'], ('Lactic acid','Actual Yield [g/g]'): lactics['actual yield'], ('Lactic acid','Actual Titer [g/L]'): lactics['actual titer'], ('0.89 [g/L/hr]','MPSP [$/kg]'): MPSPs[0.89], ('0.89 [g/L/hr]','NPV [$]'): NPVs[0.89], ('0.89 [g/L/hr]', 'GWP [kg CO2-eq/kg]'): GWPs[0.89], ('0.89 [g/L/hr]', 'FEC [MJ/kg]'): FECs[0.89], ('0.18 [g/L/hr]', 'MPSP [$/kg]'): MPSPs[0.18], ('0.18 [g/L/hr]', 'NPV [$]'): NPVs[0.18], ('0.18 [g/L/hr]', 'GWP [kg CO2-eq/kg]'): GWPs[0.18], ('0.18 [g/L/hr]', 'FEC [MJ/kg]'): FECs[0.18], ('1.92 [g/L/hr]', 'MPSP [$/kg]'): MPSPs[1.92], ('1.92 [g/L/hr]', 'NPV [$]'): NPVs[1.92], ('1.92 [g/L/hr]', 'GWP [kg CO2-eq/kg]'): GWPs[1.92], ('1.92 [g/L/hr]', 'FEC [MJ/kg]'): FECs[1.92] }) for i in (lactics, MPSPs, NPVs, GWPs, FECs): for j in i.keys(): i[j] = [] return df
def run_TRY(yield_range, kind, mode, feed_freq, if_resistant, titer_range): bst.speed_up() if 'SSCF' in str(kind).upper(): flowsheet = SSCF_flowsheet elif 'SHF' in str(kind).upper(): flowsheet = SHF_flowsheet bst.main_flowsheet.set_flowsheet(flowsheet)
yield_range = np.arange(0.3,1.01,0.2) - 1e-6 yield_range = yield_range.tolist()
titer_range = np.arange(50,220,50) titer_range = titer_range.tolist()
print('\n---------- SSCF Regular Strain Batch Mode ----------') run_TRY(yield_range=yield_range, kind='SSCF', mode='batch', feed_freq=1, if_resistant=False, titer_range=titer_range) SSCF_reg_b = save_data_clear() SSCF_reg_b.to_excel('SSCF_reg_batch.xlsx')
for i in (1,): print(f'\n---------- SHF Regular Strain Batch Feed {i + 1} Times ----------') run_TRY(yield_range=yield_range, kind='SHF', mode='batch', feed_freq=i+1, if_resistant=False, titer_range=titer_range) SHF_reg_b = save_data_clear() SHF_reg_b.to_excel(f'SHF_reg_batch{i + 1}.xlsx')
print('\n---------- SHF Regular Strain Continuous ----------') run_TRY(yield_range=yield_range, kind='SHF', mode='continuous', feed_freq=1, if_resistant=False, titer_range=titer_range) SHF_reg_c = save_data_clear() SHF_reg_c.to_excel('SHF_reg_continuous.xlsx')
print('\n---------- SSCF Regular Strain Batch Mode ----------') run_TRY(yield_range=yield_range, kind='SSCF', mode='batch', feed_freq=1, if_resistant=True, titer_range=titer_range) SSCF_reg_b = save_data_clear() SSCF_reg_b.to_excel('SSCF_reg_batch.xlsx')
for i in (1,): print(f'\n---------- SHF Regular Strain Batch Feed {i} Times ----------') run_TRY(yield_range=yield_range, kind='SHF', mode='batch', feed_freq=i, if_resistant=True, titer_range=titer_range) SHF_reg_b = save_data_clear() SHF_reg_b.to_excel(f'SHF_reg_batch{i + 1}.xlsx')
print('\n---------- SHF Regular Strain Continuous ----------') run_TRY(yield_range=yield_range, kind='SHF', mode='continuous', feed_freq=1, if_resistant=True, titer_range=titer_range) SHF_reg_c = save_data_clear() SHF_reg_c.to_excel('SHF_reg_continuous.xlsx')
I'm getting the following errors (I have used Pycharm):-
C:\Users\oshet\pythonProject\Scripts\python.exe C:\Users\oshet\AppData\Roaming\JetBrains\PyCharmCE2023.2\scratches\Fermentation.py Traceback (most recent call last): File "C:\Users\oshet\AppData\Roaming\JetBrains\PyCharmCE2023.2\scratches\Fermentation.py", line 10, in
_load_system('SSCF')
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\biorefineries\lactic__init.py", line 76, in _load_system
bst.settings.set_thermo(_chemicals)
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\thermosteam_settings.py", line 137, in set_thermo
thermo = tmo.Thermo(thermo, mixture=mixture, cache=cache, skip_checks=skip_checks,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\thermosteam_thermo.py", line 139, in init
if not isinstance(chemicals, Chemicals): chemicals = Chemicals(chemicals, cache)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\oshet\AppData\Local\Programs\Python\Python311\Lib\site-packages\thermosteam_chemicals.py", line 123, in new__
chemicals = [i if isa(i, Chemical) else Chemical(i, cache=cache) for i in chemicals]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'module' object is not iterable
Unable to debug these errors.