BioSTEAMDevelopmentGroup / Bioindustrial-Park

BioSTEAM's Premier Repository for Biorefinery Models and Results
MIT License
38 stars 18 forks source link

corn stover ethanol model import error #69

Closed zasddsgg closed 1 year ago

zasddsgg commented 1 year ago

Hello, I installed the latest Bioindustrial-Park, BioSTEAM and thermosteam in github through git clone, but I encountered an error when importing the corn stover ethanol model: ReferenceError: underlying object has vanished, it seems that R201 has been changed. I tried to reinstall it, but this error still occurred. Could you please help to check it? Thanks for your help. Wish you a good day.

The code is as follows: from biorefineries import cellulosic import biosteam as bst bst.nbtutorial() cs = cellulosic.Biorefinery('corn stover ethanol')

The error message is as follows: KeyError Traceback (most recent call last) File D:\anaconda\envs\zzz\lib\site-packages\numba\core\caching.py:469, in IndexDataCacheFile.save(self, key, data) 467 try: 468 # If key already exists, we will overwrite the file --> 469 data_name = overloads[key] 470 except KeyError: 471 # Find an available name for the data file

KeyError: ((array(float64, 1d, C), array(float64, 1d, C), float64, float64, type(CPUDispatcher(<function gamma_modified_UNIFAC at 0x00000269F3889FC0>)), Tuple(array(float64, 3d, C), array(float64, 2d, C), array(bool, 2d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 1d, C), array(float64, 2d, C), array(float64, 2d, C), array(int64, 1d, C))), ('x86_64-pc-windows-msvc', 'haswell', '+64bit,-adx,+aes,-amx-bf16,-amx-int8,-amx-tile,+avx,+avx2,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,+bmi,+bmi2,-cldemote,-clflushopt,-clwb,-clzero,+cmov,+cx16,+cx8,-enqcmd,+f16c,+fma,-fma4,+fsgsbase,+fxsr,-gfni,+invpcid,-lwp,+lzcnt,+mmx,+movbe,-movdir64b,-movdiri,-mwaitx,+pclmul,-pconfig,-pku,+popcnt,-prefetchwt1,-prfchw,-ptwrite,-rdpid,+rdrnd,-rdseed,-rtm,+sahf,-serialize,-sgx,-sha,-shstk,+sse,+sse2,+sse3,+sse4.1,+sse4.2,-sse4a,+ssse3,-tbm,-tsxldtrk,-vaes,-vpclmulqdq,-waitpkg,-wbnoinvd,-xop,+xsave,-xsavec,+xsaveopt,-xsaves'), ('5e517ad88189fc4cae56b76167c1ff2b08dd439436b5035bc726c1327e9a68db', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'))

During handling of the above exception, another exception occurred:

ReferenceError Traceback (most recent call last) Cell In[1], line 4 2 import biosteam as bst 3 bst.nbtutorial() ----> 4 cs = cellulosic.Biorefinery('corn stover ethanol')

File D:\anaconda\envs\zzz\lib\site-packages\biorefineries\cellulosic\biorefinery.py:82, in Biorefinery.new(cls, name, cache, chemicals, include_blowdown_recycle, feedstock_kwargs, prices, GWP_CFs) 80 if e_CF: bst.PowerUtility.characterization_factors['GWP'] = e_CF 81 for ID, CF in GWP_CFs.items(): stream.search(ID).characterization_factors['GWP'] = CF ---> 82 sys.simulate() 83 u = F.unit 84 OSBL_units = (u.WWTC, u.CWP, u.CT, u.PWC, u.ADP, 85 u.T701, u.T702, u.P701, u.P702, u.M701, u.FWT, 86 u.CSL_storage, u.DAP_storage, u.BT)

File D:\anaconda\envs\zzz\lib\site-packages\biosteam_system.py:2176, in System.simulate(self, update_configuration, units, kwargs) 2157 def simulate(self, update_configuration: Optional[bool]=False, units=None, kwargs): 2158 """ 2159 If system is dynamic, run the system dynamically. Otherwise, converge 2160 the path of unit operations to steady state. After running/converging (...) 2174
2175 """ -> 2176 with self.flowsheet.temporary(): 2177 specifications = self._specifications 2178 if specifications and not self._running_specifications:

File D:\anaconda\envs\zzz\lib\site-packages\biosteam_flowsheet.py:36, in TemporaryFlowsheet.exit(self, type, exception, traceback) 34 def exit(self, type, exception, traceback): 35 main_flowsheet.set_flowsheet(self.original) ---> 36 if exception: raise exception

File D:\anaconda\envs\zzz\lib\site-packages\biosteam_system.py:2200, in System.simulate(self, update_configuration, units, kwargs) 2198 outputs = self.simulate(update_configuration=True, kwargs) 2199 else: -> 2200 raise error 2201 else: 2202 if (not update_configuration # Avoid infinite loop 2203 and self._connections != [i.get_connection() for i in self.streams]): 2204 # Connections has been updated within simulation.

File D:\anaconda\envs\zzz\lib\site-packages\biosteam_system.py:2191, in System.simulate(self, update_configuration, units, kwargs) 2189 else: 2190 try: -> 2191 outputs = self.converge(kwargs) 2192 self._summary() 2193 except Exception as error:

File D:\anaconda\envs\zzz\lib\site-packages\biosteam_system.py:1909, in System.converge(self, material_data, update_material_data) 1907 for i in range(self._N_runs): method() 1908 else: -> 1909 method() 1910 if update_material_data: 1911 if reset_material_data:

File D:\anaconda\envs\zzz\lib\site-packages\biosteam_system.py:1806, in System.run(self) 1804 f = try_method_with_object_stamp 1805 for i in self._path: -> 1806 if isa(i, Unit): f(i, i.run) 1807 elif isa(i, System): f(i, i.converge) 1808 else: i()

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\exceptions.py:90, in try_method_with_object_stamp(object, method, args) 88 raise StampedKeyError(message_with_object_stamp(object, repr(error.args[0]))) 89 except Exception as error: ---> 90 raise_error_with_object_stamp(object, error)

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\exceptions.py:80, in raise_error_with_object_stamp(object, error) 78 error.args = (message_with_object_stamp(object, msg), *args) 79 except: pass ---> 80 raise error

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\exceptions.py:84, in try_method_with_object_stamp(object, method, args) 82 def try_method_with_object_stamp(object, method, args=()): 83 try: ---> 84 return method(*args) 85 except StampedKeyError as error: 86 raise StampedKeyError(message_with_object_stamp(object, error.args[0]))

File D:\anaconda\envs\zzz\lib\site-packages\biosteam_unit.py:1269, in Unit.run(self) 1267 if self.run_after_specifications: self._run() 1268 else: -> 1269 self._run()

File D:\anaconda\envs\zzz\lib\site-packages\biorefineries\cellulosic\units.py:180, in PretreatmentReactorSystem._run(self) 178 ms = self._multistream 179 ms.copy_like(liquid) --> 180 ms.vle(T=self.T, H=ms.H) 181 vapor.mol[:] = ms.imol['g'] 182 liquid.mol[:] = ms.imol['l']

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\equilibrium\vle.py:361, in VLE.call(self, T, P, V, H, S, x, y) 359 thermal_condition.T = T 360 elif H_spec: --> 361 self.set_TH(T, H) 362 elif S_spec: 363 self.set_TS(T, S)

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\equilibrium\vle.py:777, in VLE.set_TH(self, T, H) 774 phase_data = self._phase_data 776 # Check if super heated vapor --> 777 P_dew, x_dew = self._dew_point.solve_Px(self._z, T) 778 if self._F_mol_heavy: P_dew = 0.5 P_dew + 0.5 self._bubble_point.Pmin 779 vapor_mol[index] = mol

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\equilibrium\dew_point.py:282, in DewPoint.solve_Px(self, z, T) 280 f = self._P_error 281 try: --> 282 P = flx.aitken_secant(f, P_guess, P_guess-10, self.P_tol, 5e-12, args, 283 checkiter=False) 284 except RuntimeError: 285 Pmin = self.Pmin

File D:\anaconda\envs\zzz\lib\site-packages\flexsolve\open_solvers.py:68, in aitkensecant(f, x0, x1, xtol, ytol, args, maxiter, checkroot, checkiter) 66 dx = -2 * xtol 67 abs = abs ---> 68 y0 = f(x0, *args) 69 if abs_(y0) < ytol: return x0 70 aitken_iter = utils.scalar_aitken_iter

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\equilibrium\dew_point.py:147, in DewPoint._P_error(self, P, T, z_norm, z_over_Psats, Psats, x) 145 if P <= 0: raise InfeasibleRegion('negative pressure') 146 x_gamma = z_over_Psats P self.phi(z_norm, T, P) / self.pcf(T, P, Psats) --> 147 x[:] = self._solve_x(x_gamma, T, P, x) 148 return 1 - x.sum()

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\equilibrium\dew_point.py:126, in DewPoint._solve_x(self, x_gamma, T, P, x) 124 def _solve_x(self, x_gamma, T, P, x): 125 gamma = self.gamma --> 126 return solve_x(x, x_gamma, T, P, gamma.f, gamma.args)

File D:\anaconda\envs\zzz\lib\site-packages\thermosteam\equilibrium\dew_point.py:42, in solve_x(x_guess, x_gamma, T, P, f_gamma, gamma_args) 40 def solve_x(x_guess, x_gamma, T, P, f_gamma, gamma_args): 41 args = (x_gamma, T, P, f_gamma, gamma_args) ---> 42 x = flx.wegstein(x_iter, x_guess, 1e-10, args=args, checkiter=False, 43 checkconvergence=False, convergenceiter=3) 44 return x

File D:\anaconda\envs\zzz\lib\site-packages\flexsolve\iterative_solvers.py:58, in wegstein(f, x, xtol, args, maxiter, checkiter, checkconvergence, convergenceiter) 56 errors = np.zeros(convergenceiter) 57 x0 = x ---> 58 x1 = g0 = f(x0, *args) 59 wegstein_iter = utils.wegstein_iter 60 fixedpoint_converged = utils.fixedpoint_converged

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\dispatcher.py:487, in _DispatcherBase._compile_for_args(self, *args, **kws) 485 e.patch_message('\n'.join((str(e).rstrip(), help_msg))) 486 # ignore the FULL_TRACEBACKS config, this needs reporting! --> 487 raise e 488 finally: 489 self._types_active_call = []

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\dispatcher.py:420, in _DispatcherBase._compile_for_args(self, *args, **kws) 418 return_val = None 419 try: --> 420 return_val = self.compile(tuple(argtypes)) 421 except errors.ForceLiteralArg as e: 422 # Received request for compiler re-entry with the list of arguments 423 # indicated by e.requested_args. 424 # First, check if any of these args are already Literal-ized 425 already_lit_pos = [i for i in e.requested_args 426 if isinstance(args[i], types.Literal)]

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\dispatcher.py:972, in Dispatcher.compile(self, sig) 970 raise e.bind_fold_arguments(folded) 971 self.add_overload(cres) --> 972 self._cache.save_overload(sig, cres) 973 return cres.entry_point

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\caching.py:652, in Cache.save_overload(self, sig, data) 648 """ 649 Save the data for the given signature in the cache. 650 """ 651 with self._guard_against_spurious_io_errors(): --> 652 self._save_overload(sig, data)

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\caching.py:662, in Cache._save_overload(self, sig, data) 660 key = self._index_key(sig, data.codegen) 661 data = self._impl.reduce(data) --> 662 self._cache_file.save(key, data)

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\caching.py:478, in IndexDataCacheFile.save(self, key, data) 476 break 477 overloads[key] = data_name --> 478 self._save_index(overloads) 479 self._save_data(data_name, data)

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\caching.py:522, in IndexDataCacheFile._save_index(self, overloads) 520 def _save_index(self, overloads): 521 data = self._source_stamp, overloads --> 522 data = self._dump(data) 523 with self._open_for_write(self._index_path) as f: 524 pickle.dump(self._version, f, protocol=-1)

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\caching.py:550, in IndexDataCacheFile._dump(self, obj) 549 def _dump(self, obj): --> 550 return dumps(obj)

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\serialize.py:57, in dumps(obj) 55 with io.BytesIO() as buf: 56 p = pickler(buf, protocol=4) ---> 57 p.dump(obj) 58 pickled = buf.getvalue() 60 return pickled

File D:\anaconda\envs\zzz\lib\site-packages\numba\cloudpickle\cloudpickle_fast.py:568, in CloudPickler.dump(self, obj) 566 def dump(self, obj): 567 try: --> 568 return Pickler.dump(self, obj) 569 except RuntimeError as e: 570 if "recursion" in e.args[0]:

File D:\anaconda\envs\zzz\lib\site-packages\numba\core\types\functions.py:486, in _PickleableWeakRef.getnewargs(self) 484 obj = self() 485 if obj is None: --> 486 raise ReferenceError("underlying object has vanished") 487 return (obj,)

ReferenceError: underlying object has vanished

yalinli2 commented 1 year ago

Interesting that others are seeing this as well, but @jiananf2 and I have seen this before. I feel like it's a numba issue, in the past I've temporarily resolved it by uninstalling and reinstalling numba:

pip uninstall numba # my current numba is 0.56.4
pip install numba==0.56.3 --no-cache-dir # if this still doesn't work, try uninstalling this 0.56.3 and reinstalling 0.56.4

Would be interested to know the root cause and a better fix!

zasddsgg commented 1 year ago

Thank you for your advice. I have tried according to your advice and have solved this problem. Thank you for your help.