Import Error while importing Cadet-process module function

Hi Everyone,

I have tried using cadet-process (being a new user to cadet hence more user friendly), but i am unable to import source and sink post installing cadet-process and am facing import error.

Below is the code used:

from CADETProcess.processModel import ComponentSystem
from CADETProcess.processModel import StericMassAction
from CADETProcess.processModel import Source, GeneralRateModel, Sink
from CADETProcess.processModel import FlowSheet
from CADETProcess.processModel import Process

Below is the Error reverted with:
ImportError: cannot import name 'Source' from 'CADETProcess.processModel' (/usr/local/lib/python3.10/dist-packages/CADETProcess/processModel/__init__.py)

PS: I am using google Colab as interface for code and have pip installed latest version of CADET-process

I am not facing error in importing any other function but only for source and sink, so if we can bypass these functions in below code, things should be fine


import numpy as np

from CADETProcess.processModel import ComponentSystem
from CADETProcess.processModel import StericMassAction
from CADETProcess.processModel import Source, GeneralRateModel, Sink
from CADETProcess.processModel import FlowSheet
from CADETProcess.processModel import Process

# Input Model
c_salt_low = 84.105
c_salt_high = 288.58
c_protein = 0.029



# Component System
component_system = ComponentSystem()
component_system.add_component('Salt')
component_system.add_component('Protein')

# Binding Model
binding_model = StericMassAction(component_system, name='SMA')
binding_model.is_kinetic = True
binding_model.adsorption_rate = [0.0, 4.35E-31]
binding_model.desorption_rate = [0.0, 1.00E-22]
binding_model.characteristic_charge = [0.0, 14.000]
binding_model.steric_factor = [0.0, 261.000]
binding_model.capacity = 710

# Unit Operations
inlet = Source(component_system, name='inlet')
inlet.flow_rate = 2.83e-9


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

column.length = 0.05
column.diameter = 0.15e-2*2
column.bed_porosity = 0.47
column.particle_radius = 3.25E-05
column.particle_porosity = 0.23
column.axial_dispersion = 3.9e-7
column.film_diffusion = [2.0e-5, 1.0e-5]
column.pore_diffusion = [7e-5, 5.5e-12]
column.surface_diffusion = [0.0, 1.38E-15]

column.c = [c_salt_low, 0]
column.q = [binding_model.capacity, 0]

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

# flow sheet
flow_sheet = FlowSheet(component_system)

flow_sheet.add_unit(inlet)
flow_sheet.add_unit(column)
flow_sheet.add_unit(outlet, chromatogram_sink=True)

flow_sheet.add_connection(inlet, column)
flow_sheet.add_connection(column, outlet)

# Process
process = Process(flow_sheet, 'lwe')
process.cycle_time = 9898.902

## Create Events and Durations
wash_start = 4232.598
gradient_start = 7407.137
concentration_difference = np.array([c_salt_high, 0.0]) - np.array([c_salt_low, 0.0])
gradient_duration = process.cycle_time - gradient_start
gradient_slope = concentration_difference/gradient_duration

process.add_event('load', 'flow_sheet.inlet.c', [c_salt_low, c_protein])
process.add_event('wash', 'flow_sheet.inlet.c', [c_salt_low, 0.0], wash_start)
process.add_event(
    'grad_start',
    'flow_sheet.inlet.c',
    [[c_salt_low, gradient_slope[0]], [0, gradient_slope[1]]],
    gradient_start
)

process.plot_events()

from CADETProcess.simulator import Cadet
process_simulator = Cadet()

simulation_results = process_simulator.simulate(process)

from CADETProcess.plotting import SecondaryAxis
sec = SecondaryAxis()
sec.component_indices = [0]
sec.y_label = '$c_{salt}$'

simulation_results.solution.column.outlet.plot(secondary_axis=sec)

Hey Omparv,

you can use Inlet instead of Source and Outlet instead of Sink and things should work.

Hi Ronald,
Appreciate your quick response, the solution you provided did work for substitution of source and sink.

Additionally, i have encountered a ā€˜file not found error’ while plotting simulation results where it requires importing cadet from cadet_process module in the same code.

The respective code is as follows:

from CADETProcess.simulator import Cadet
process_simulator = Cadet()

The error:
FileNotFoundError: Could not autodetect CADET installation. Please provide path.

For which, i uploaded the cadet files on colab and provided respective path as follows:

from CADETProcess.simulator import Cadet
process_simulator = Cadet('/content/sample_data/CADET-0.10-py3-none-any.whl')

still the process persists even with other .tar.gz file

I am getting a plot as output even with this error


which is far from desired plot as follows produced by @l.thiel in one of his replies which was
image

Below is code provided by him with changes as suggested by you

import numpy as np

from CADETProcess.processModel import ComponentSystem
from CADETProcess.processModel import StericMassAction
from CADETProcess.processModel import Inlet, GeneralRateModel, Outlet
from CADETProcess.processModel import FlowSheet
from CADETProcess.processModel import Process

# Input Model
c_salt_low = 84.105
c_salt_high = 288.58
c_protein = 0.029



# Component System
component_system = ComponentSystem()
component_system.add_component('Salt')
component_system.add_component('Protein')

# Binding Model
binding_model = StericMassAction(component_system, name='SMA')
binding_model.is_kinetic = True
binding_model.adsorption_rate = [0.0, 4.35E-31]
binding_model.desorption_rate = [0.0, 1.00E-22]
binding_model.characteristic_charge = [0.0, 14.000]
binding_model.steric_factor = [0.0, 261.000]
binding_model.capacity = 710

# Unit Operations
inlet = Inlet(component_system, name='inlet')
inlet.flow_rate = 2.83e-9


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

column.length = 0.05
column.diameter = 0.15e-2*2
column.bed_porosity = 0.47
column.particle_radius = 3.25E-05
column.particle_porosity = 0.23
column.axial_dispersion = 3.9e-7
column.film_diffusion = [2.0e-5, 1.0e-5]
column.pore_diffusion = [7e-5, 5.5e-12]
column.surface_diffusion = [0.0, 1.38E-15]

column.c = [c_salt_low, 0]
column.q = [binding_model.capacity, 0]

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

# flow sheet
flow_sheet = FlowSheet(component_system)

flow_sheet.add_unit(inlet)
flow_sheet.add_unit(column)
flow_sheet.add_unit(outlet)

flow_sheet.add_connection(inlet, column)
flow_sheet.add_connection(column, outlet)

# Process
process = Process(flow_sheet, 'lwe')
process.cycle_time = 9898.902

## Create Events and Durations
wash_start = 4232.598
gradient_start = 7407.137
concentration_difference = np.array([c_salt_high, 0.0]) - np.array([c_salt_low, 0.0])
gradient_duration = process.cycle_time - gradient_start
gradient_slope = concentration_difference/gradient_duration

process.add_event('load', 'flow_sheet.inlet.c', [c_salt_low, c_protein])
process.add_event('wash', 'flow_sheet.inlet.c', [c_salt_low, 0.0], wash_start)
process.add_event(
    'grad_start',
    'flow_sheet.inlet.c',
    [[c_salt_low, gradient_slope[0]], [0, gradient_slope[1]]],
    gradient_start
)

process.plot_events()

from CADETProcess.simulator import Cadet
process_simulator = Cadet('/cl')

simulation_results = process_simulator.simulate(process)

from CADETProcess.plotting import SecondaryAxis
sec = SecondaryAxis()
sec.component_indices = [0]
sec.y_label = '$c_{salt}$'

simulation_results.solution.column.outlet.plot(secondary_axis=sec)

That’s a surprising error which should not happen. Did you install CADET with conda or compile CADET yourself?
To clarify: CADET-Process is the front-end / user interface for the CADET core simulator. CADET-Process can be installed with pip but the CADET core simulator needs to be installed withconda or compiled yourself?
Then, if you have a CADET installation with conda in the same python environment that you are using for your scripts, CADET-Process will auto detect CADET. If it doesn’t you can link against cadet-cli.exe on windows or cadet-cli on Linux. It can be found at e.g.
C:\Users\username\anaconda\envs\environment_name\bin\cadet-cli.exe

I am facing the same issue of ā€œCould not autodetect CADET installation. Please provide path.ā€ I installed the CADET core and CADET-Process from the sources you mentioned but it still gives the same issue. I did found the path at which cadet-cli.exe exists. But since I’m a newbie I don’t know how to link against cadet-cli.exe on windows in a python script. Please guide.

The code I’m trying to run is as follows:

from CADETProcess.simulator import Cadet

# Initialize the simulator
simulator = Cadet()

# Check if CADET-Core is accessible
if simulator.check_cadet():
    print("CADET-Core is accessible.")
else:
    print("CADET-Core is not accessible.")

The whole Traceback is as follows:

runfile('C:/Users/modia/OneDrive - IIT Delhi/Desktop/cadet_test.py', wdir='C:/Users/modia/OneDrive - IIT Delhi/Desktop')
Traceback (most recent call last):

  File ~\anaconda3\envs\cadet-env\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\modia\onedrive - iit delhi\desktop\cadet_test.py:4
    simulator = Cadet()

  File ~\anaconda3\envs\cadet-env\lib\site-packages\CADETProcess\simulator\cadetAdapter.py:98 in __init__
    self.install_path = CadetAPI.autodetect_cadet()

  File ~\anaconda3\envs\cadet-env\lib\site-packages\cadet\cadet.py:369 in autodetect_cadet
    raise FileNotFoundError(

FileNotFoundError: Could not autodetect CADET installation. Please provide path.

Hello 101abhinav,

welcome to the CADET Forum!

To use a specific cadet-cli path, you can hand the path over to the Cadet class during instantiation:
simulator = Cadet(install_path='/path/to/cadet/cadet-cli.exe')

If that does not work, you can send us the output of conda list and pip list and we can look further into it.

Hello Ronald, thanks for quick reply the code did work with an error message beside it.
C:\Users\modia\anaconda3\envs\cadet-env\lib\site-packages\cadet\cadet.py:59: UserWarning: The specified install_path is not the root of the CADET installation. It has been inferred from the file path.
warnings.warn(
C:\Users\modia\anaconda3\envs\cadet-env\lib\site-packages\cadet\cadet.py:569: FutureWarning: Cadet.run() will be removed in a future release.
Please use Cadet.run_simulation()
warnings.warn(
Test simulation completed successfully
CADET-Core is accessible.

The system cannot find the path specified.

Do you still need conda list and pip list??

Glad to hear it. The last The system cannot find the path specified. seems to be a new error. Please open a new Topic to address this issue and supply the full code there. Thank you.

1 Like