Batch Elution Chromatography Example

Expected behavior.

Heelo! I am new to this and I’m trying to run the first example of CADET Process. I have created an environment (cadet_env) where I have installed the cadet core and the cadet process (all through conda). I have checked the presence of the files in the environment multiple times. It checks out. I am trying to run the Batch Elution Chromatography Example in jupyter (I open jupyter through the environment). When I run the simulation line

if __name__ == '__main__':
    from CADETProcess.simulator import Cadet
    process_simulator = Cadet(install_path=r"C:\Users\InesSilva\anaconda3\envs\cadet_env")

    simulation_results = process_simulator.simulate(process) 

it gives out an error

  File "C:\Users\InesSilva\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\cadetAdapter.py", line 292, in _run
    raise CADETProcessError(
CADETProcess.CADETProcessError.CADETProcessError: CADET Error: Simulation failed with 

Actual behavior

I dont know what Im doing wrong. I have tried multiple things at this point. Can you please help me?

How to produce bug (including a minimal reproducible example)

from cadet import Cadet
import numpy as np
import matplotlib.pyplot as plt

Cadet.cadet_path = r"C:\Users\InesSilva\anaconda3\envs\cadet_env"     ## IMPORTANT: use a version higher than 5.0.4 

(the whole code from the batch elution chromatography…)

if __name__ == '__main__':
    from CADETProcess.simulator import Cadet
    process_simulator = Cadet(install_path=r"C:\Users\InesSilva\anaconda3\envs\cadet_env")

    simulation_results = process_simulator.simulate(process)

File produced by conda env export > environment.yml

environment.yml (8.26 KB)

Hi Sasha and welcome to the Forum,

unfortunately, we need more information to properly help you. Please post a minimum reproducible example that contains all code (and not more) that is required to reproduce your issue, as well as the full error message.

from CADETProcess.processModel import ComponentSystem

component_system = ComponentSystem()
component_system.add_component('A')
component_system.add_component('B')

from CADETProcess.processModel import Langmuir

binding_model = Langmuir(component_system, name='langmuir')
binding_model.is_kinetic = False
binding_model.adsorption_rate = [0.02, 0.03]
binding_model.desorption_rate = [1, 1]
binding_model.capacity = [100, 100]

from CADETProcess.processModel import (
    Inlet, LumpedRateModelWithoutPores, Outlet
)
feed = Inlet(component_system, name='feed')
feed.c = [10, 10]

eluent = Inlet(component_system, name='eluent')
eluent.c = [0, 0]

column = LumpedRateModelWithoutPores(component_system, name='column')
column.binding_model = binding_model

column.length = 0.6
column.diameter = 0.024
column.axial_dispersion = 4.7e-7
column.total_porosity = 0.7

column.solution_recorder.write_solution_bulk = True

outlet = Outlet(component_system, name='outlet')

from CADETProcess.processModel import FlowSheet

flow_sheet = FlowSheet(component_system)

flow_sheet.add_unit(feed, feed_inlet=True)
flow_sheet.add_unit(eluent, eluent_inlet=True)
flow_sheet.add_unit(column)
flow_sheet.add_unit(outlet, product_outlet=True)

flow_sheet.add_connection(feed, column)
flow_sheet.add_connection(eluent, column)
flow_sheet.add_connection(column, outlet)

from CADETProcess.processModel import Process
process = Process(flow_sheet, 'batch elution')

Q = 60 / (60 * 1e6)
process.add_event('feed_on', 'flow_sheet.feed.flow_rate', Q)
process.add_event('feed_off', 'flow_sheet.feed.flow_rate', 0.0)

process.add_event('eluent_on', 'flow_sheet.eluent.flow_rate', Q)
process.add_event('eluent_off', 'flow_sheet.eluent.flow_rate', 0.0)

process.add_duration('feed_duration')

process.add_event_dependency('eluent_on', ['feed_off'])
process.add_event_dependency('eluent_off', ['feed_on'])
process.add_event_dependency('feed_off', ['feed_on', 'feed_duration'], [1, 1])

process.cycle_time = 600
process.feed_duration.time = 60

if __name__ == '__main__':
    from CADETProcess.simulator import Cadet
    process_simulator = Cadet(install_path=r"C:\Users\InesSilva\anaconda3\envs\cadet_env")

    simulation_results = process_simulator.simulate(process)

And the error

Simulation of batch elution with parameters {'parameters': {'feed_on': {'time': 0.0, 'state': 1e-06}, 'eluent_off': {'time': np.float64(0.0), 'state': 0.0}, 'feed_off': {'time': np.float64(60.0), 'state': 0.0}, 'eluent_on': {'time': np.float64(60.0), 'state': 1e-06}, 'feed_duration': {'time': 60}, 'cycle_time': 600.0, 'flow_sheet': {'feed': {'c': array([[10.,  0.,  0.,  0.],
       [10.,  0.,  0.,  0.]]), 'flow_rate': array([0., 0., 0., 0.])}, 'output_states': {'feed': [1.0], 'eluent': [1.0], 'column': [1.0], 'outlet': {}}, 'eluent': {'c': array([[0., 0., 0., 0.],
       [0., 0., 0., 0.]]), 'flow_rate': array([1.e-06, 0.e+00, 0.e+00, 0.e+00])}, 'column': {'total_porosity': 0.7, 'c': [0.0, 0.0], 'q': None, 'length': 0.6, 'diameter': 0.024, 'axial_dispersion': [4.7e-07, 4.7e-07], 'flow_direction': 1, 'binding_model': {'adsorption_rate': [0.02, 0.03], 'desorption_rate': [1, 1], 'capacity': [100, 100], 'is_kinetic': False}, 'discretization': {'ncol': 100, 'use_analytic_jacobian': True, 'reconstruction': 'WENO', 'weno': {'boundary_model': 0, 'weno_eps': 1e-10, 'weno_order': 3}, 'consistency_solver': {'solver_name': 'LEVMAR', 'init_damping': 0.01, 'min_damping': 0.0001, 'max_iterations': 50, 'subsolvers': 'LEVMAR'}, 'spatial_method': 'FV', 'nbound': [1, 1]}}, 'outlet': {}}}, 'initial_state': {'system_state': None, 'system_state_derivative': None, 'flow_sheet': {'feed': {}, 'eluent': {}, 'column': {'c': [0.0, 0.0], 'q': [0, 0]}, 'outlet': {}}}} failed.
There was an exception in simulate_n_cycles
Traceback (most recent call last):
  File "C:\Users\InesSilva\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\log.py", line 192, in wrapper
    return function(*args, **kwargs)
  File "C:\Users\InesSilva\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\simulator.py", line 334, in simulate_n_cycles
    return self._run(process, **kwargs)
  File "C:\Users\InesSilva\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\cadetAdapter.py", line 154, in wrapper
    results = func(self, process, *args, **kwargs)
  File "C:\Users\InesSilva\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\cadetAdapter.py", line 292, in _run
    raise CADETProcessError(
CADETProcess.CADETProcessError.CADETProcessError: CADET Error: Simulation failed with 
---------------------------------------------------------------------------
CADETProcessError                         Traceback (most recent call last)
Cell In[8], line 72
     69 from CADETProcess.simulator import Cadet
     70 process_simulator = Cadet(install_path=r"C:\Users\InesSilva\anaconda3\envs\cadet_env")
---> 72 simulation_results = process_simulator.simulate(process)

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\simulator.py:275, in SimulatorBase.simulate(self, process, previous_results, **kwargs)
    272     self.n_cycles_batch = self.n_cycles_max
    274 if not self.evaluate_stationarity:
--> 275     results = self.simulate_n_cycles(
    276         process, self.n_cycles, previous_results, **kwargs
    277     )
    278 else:
    279     results = self.simulate_to_stationarity(process, previous_results, **kwargs)

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\log.py:164, in log_time.<locals>.log_time_decorator.<locals>.wrapper(*args, **kwargs)
    161 @wraps(function)
    162 def wrapper(*args: Any, **kwargs: Any) -> Any:
    163     start = time.time()
--> 164     result = function(*args, **kwargs)
    165     elapsed = time.time() - start
    166     logger = get_logger(logger_name, level=None)

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\log.py:225, in log_results.<locals>.log_results_decorator.<locals>.wrapper(*args, **kwargs)
    222 logger = get_logger(logger_name, level=None)
    224 logger.debug("{} was called with {}, {}".format(function, *args, **kwargs))
--> 225 results = function(*args, **kwargs)
    226 logger.debug(f"Results: {results}")
    228 return results

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\log.py:200, in log_exceptions.<locals>.log_exception_decorator.<locals>.wrapper(*args, **kwargs)
    197 logger.exception(err)
    199 # re-raise the exception
--> 200 raise e

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\log.py:192, in log_exceptions.<locals>.log_exception_decorator.<locals>.wrapper(*args, **kwargs)
    190 logger = get_logger(logger_name, level=None)
    191 try:
--> 192     return function(*args, **kwargs)
    193 except Exception as e:
    194     # log the exception
    195     err = "There was an exception in "

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\simulator.py:334, in SimulatorBase.simulate_n_cycles(self, process, n_cyc, previous_results, **kwargs)
    331 if previous_results is not None:
    332     self.set_state_from_results(process, previous_results)
--> 334 return self._run(process, **kwargs)
    336 self.n_cycles = n_cyc_orig

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\cadetAdapter.py:154, in Cadet.locks_process.<locals>.wrapper(self, process, *args, **kwargs)
    151     process.lock = True
    152     locked_process = True
--> 154 results = func(self, process, *args, **kwargs)
    156 if locked_process:
    157     process.lock = False

File ~\anaconda3\envs\cadet_env\lib\site-packages\CADETProcess\simulator\cadetAdapter.py:292, in Cadet._run(self, process, cadet, file_path)
    288 if return_information.return_code != 0:
    289     self.logger.error(
    290         f"Simulation of {process.name} with parameters {process.config} failed."
    291     )
--> 292     raise CADETProcessError(
    293         f"CADET Error: Simulation failed with {return_information.error_message}"
    294     ) from None
    296 try:
    297     results = self.get_simulation_results(
    298         process, cadet, elapsed, return_information
    299     )

CADETProcessError: CADET Error: Simulation failed with

Dear Sasha,

Thank you for reporting your issue.

At the moment, I’m unable to reproduce the problem in my Python environment. However, I suspect the issue may stem from the following line:

process_simulator = Cadet(install_path=r"C:\Users\InesSilva\anaconda3\envs\cadet_env")

There are two potential problems here:

  1. The install_path argument expects the root directory of the CADET installation, i.e., the root of the folder that contains cadet-cli.exe. In your case, you’re passing the root of the entire environment, which may cause the issue.
  2. If your Python environment is set up properly and you’re running the script from within that environment, specifying the install_path is typically not necessary. CADET-Process can usually autodetect the CADET installation automatically.

Try removing the install_path argument from your code and running your code directly from your Python environment.
If this results in an error, it could indicate an issue with your environment setup or your system’s PATH variables.

All the best,
Hannah

Hey, thanks for your answer. I managed to fix it now, I think it was a problem with the setup of the environment! I did it again from the minimal environment that you suggested in one of the posts and then it worked

1 Like