Hello everyone, how to solve the following problems encountered when modeling with CADET:
CompletedProcess(args=[PosixPath(‘/home/chenkangnan/anaconda3/envs/cadet/bin/cadet-cli’), ‘liraglutide_reference.h5’], returncode=3, stdout=b"[Error: idasErrorHandler::200] In function ‘IDASolve’ of module ‘IDAS’, error code ‘IDA_ILL_INPUT’:\nAt t = 600, , mxstep steps taken before reaching tout.\n[Error: integrate::1367] IDASolve returned IDA_TOO_MUCH_WORK at t = 600\n", stderr=b’SOLVER ERROR: Error in IDASolve: IDA_TOO_MUCH_WORK at t = 600.000000\n’)
Hi, could you please post the code that causes this issue?
import shutil
import os
import platform
from pathlib import Path
from cadet import Cadet
from scipy.integrate import simps
import matplotlib.pyplot as plt
import csv
import json
import numpy as np
import tempfile
tempfile.tempdir = os.path.join(Path.home())
install_path = None
executable = ‘cadet-cli’
if install_path is None:
try:
if platform.system() == ‘Windows’:
executable += ‘.exe’
executable_path = Path(shutil.which(executable))
except TypeError:
raise FileNotFoundError(
“CADET could not be found. Please set an install path”
)
install_path = executable_path.parent.parent
install_path = Path(install_path)
print(install_path)
cadet_bin_path = install_path / “bin” / executable
print(cadet_bin_path)
if cadet_bin_path.exists():
Cadet.cadet_path = cadet_bin_path
else:
raise FileNotFoundError(
“CADET could not be found. Please check the path”
)
cadet_lib_path = install_path / “lib”
try:
if cadet_lib_path.as_posix() not in os.environ[‘LD_LIBRARY_PATH’]:
os.environ[‘LD_LIBRARY_PATH’] =
cadet_lib_path.as_posix()
+ os.pathsep
+ os.environ[‘LD_LIBRARY_PATH’]
except KeyError:
os.environ[‘LD_LIBRARY_PATH’] = cadet_lib_path.as_posix()
lwe_executable = ‘createLWE’
if platform.system() == ‘Windows’:
lwe_executable += ‘.exe’
lwe_path = install_path / “bin” / lwe_executable
print(lwe_path)
def get_cadet_template(n_units=3, split_components_data=False):
cadet_template = Cadet()
cadet_template.root.input.model.nunits = n_units
# Store solution
cadet_template.root.input['return'].split_components_data = split_components_data
cadet_template.root.input['return'].split_ports_data = 0
cadet_template.root.input['return'].unit_000.write_solution_inlet = 1
cadet_template.root.input['return'].unit_000.write_solution_outlet = 1
cadet_template.root.input['return'].unit_000.write_solution_bulk = 1
cadet_template.root.input['return'].unit_000.write_solution_particle = 1
cadet_template.root.input['return'].unit_000.write_solution_solid = 1
cadet_template.root.input['return'].unit_000.write_solution_flux = 1
cadet_template.root.input['return'].unit_000.write_solution_volume = 1
cadet_template.root.input['return'].unit_000.write_coordinates = 1
cadet_template.root.input['return'].unit_000.write_sens_outlet = 1
for unit in range(n_units):
cadet_template.root.input['return']['unit_{0:03d}'.format(unit)] = cadet_template.root.input['return'].unit_000
# Tolerances for the time integrator
cadet_template.root.input.solver.time_integrator.abstol = 1e-6
cadet_template.root.input.solver.time_integrator.algtol = 1e-10
cadet_template.root.input.solver.time_integrator.reltol = 1e-6
cadet_template.root.input.solver.time_integrator.init_step_size = 1e-6
cadet_template.root.input.solver.time_integrator.max_steps = 1000000
# Solver settings
cadet_template.root.input.model.solver.gs_type = 1
cadet_template.root.input.model.solver.max_krylov = 0
cadet_template.root.input.model.solver.max_restarts = 10
cadet_template.root.input.model.solver.schur_safety = 1e-8
# Run the simulation on single thread
cadet_template.root.input.solver.nthreads = 6
return cadet_template
def set_discretization(model, n_bound=None, n_col=20, n_par_types=1):
columns = {‘GENERAL_RATE_MODEL’, ‘LUMPED_RATE_MODEL_WITH_PORES’, ‘LUMPED_RATE_MODEL_WITHOUT_PORES’}
for unit_name, unit in model.root.input.model.items():
if 'unit_' in unit_name and unit.unit_type in columns:
unit.discretization.ncol = n_col
unit.discretization.npar = 5
unit.discretization.npartype = n_par_types
if n_bound is None:
n_bound = unit.ncomp * [0]
unit.discretization.nbound = n_bound
unit.discretization.par_disc_type = 'EQUIDISTANT_PAR'
unit.discretization.use_analytic_jacobian = 1
unit.discretization.reconstruction = 'WENO'
unit.discretization.gs_type = 1
unit.discretization.max_krylov = 0
unit.discretization.max_restarts = 10
unit.discretization.schur_safety = 1.0e-8
unit.discretization.weno.boundary_model = 0
unit.discretization.weno.weno_eps = 1e-10
unit.discretization.weno.weno_order = 3
def create_liraglutide_model():
liraglutide_model = get_cadet_template(n_units=3, split_components_data=True)
# INLET
liraglutide_model.root.input.model.unit_000.unit_type = 'INLET'
liraglutide_model.root.input.model.unit_000.ncomp = 2
liraglutide_model.root.input.model.unit_000.inlet_type = 'PIECEWISE_CUBIC_POLY'
# Column
liraglutide_model.root.input.model.unit_001.unit_type = 'LUMPED_RATE_MODEL_WITHOUT_PORES'
liraglutide_model.root.input.model.unit_001.ncomp = 2
liraglutide_model.root.input.model.unit_001.col_length = 0.25
liraglutide_model.root.input.model.unit_001.cross_section_area = 0.0023*0.0023*3.14
liraglutide_model.root.input.model.unit_001.TOTAL_POROSITY = 0.384
liraglutide_model.root.input.model.unit_001.col_dispersion = 2.0e-7
#吸附模型
liraglutide_model.root.input.model.unit_001.adsorption_model = 'MOBILE_PHASE_MODULATOR'
liraglutide_model.root.input.model.unit_001.adsorption.is_kinetic = True
liraglutide_model.root.input.model.unit_001.adsorption.MPM_KA = [0,2.5]
liraglutide_model.root.input.model.unit_001.adsorption.MPM_KD = [0,0.1]
liraglutide_model.root.input.model.unit_001.adsorption.MPM_QMAX = [0,1000]
liraglutide_model.root.input.model.unit_001.adsorption.MPM_BETA = [0,1]
liraglutide_model.root.input.model.unit_001.adsorption.MPM_GAMMA = [0,1]
liraglutide_model.root.input.model.unit_001.init_c = [72,0]
liraglutide_model.root.input.model.unit_001.init_q = [0.0,0]
set_discretization(liraglutide_model, n_col=100)
## Outlet
liraglutide_model.root.input.model.unit_002.ncomp = 2
liraglutide_model.root.input.model.unit_002.unit_type = 'OUTLET'
# Sections and connections
liraglutide_model.root.input.solver.sections.nsec = 4
liraglutide_model.root.input.solver.sections.section_times = [0.0, 1, 600, 4500, 5100]
liraglutide_model.root.input.solver.sections.section_continuity = [0, ]
## Inlet Profile
liraglutide_model.root.input.model.unit_000.sec_000.const_coeff = [72,1]
liraglutide_model.root.input.model.unit_000.sec_001.const_coeff = [72,0]
liraglutide_model.root.input.model.unit_000.sec_002.const_coeff = [46.8,0]
liraglutide_model.root.input.model.unit_000.sec_002.lin_coeff = [-1/4875, 0]
liraglutide_model.root.input.model.unit_000.sec_003.const_coeff = [24, 0]
## Switches
liraglutide_model.root.input.model.connections.nswitches = 1
liraglutide_model.root.input.model.connections.switch_000.section = 0
liraglutide_model.root.input.model.connections.switch_000.connections = [
0, 1, -1, -1, 1.167e-8,
1, 2, -1, -1, 1.167e-8,
]
# set the times that the simulator writes out data for
liraglutide_model.root.input.solver.user_solution_times = np.linspace(0, 5100, 5101)
return liraglutide_model
def run_simulation(cadet, file_name=None):
if file_name is None:
f = next(tempfile._get_candidate_names())
cadet.filename = os.path.join(tempfile.tempdir, f + ‘.h5’)
else:
cadet.filename = file_name
# save the simulation
cadet.save()
# run the simulation and load results
data = cadet.run()
cadet.load()
# Remove files
if file_name is None:
os.remove(os.path.join(tempfile.tempdir, f + '.h5'))
# Raise error if simulation fails
if data.returncode == 0:
print("Simulation completed successfully")
else:
print(data)
raise Exception("Simulation failed")
#以下代码供修改
from addict import Dict
base_dir = Path(‘./’).absolute()
match_config = Dict()
match_config.CADETPath = ‘/home/chenkangnan/anaconda3/envs/cadet/bin/cadet-cli’
match_config.baseDir = base_dir.as_posix()
match_config.resultsDir = ‘liraglutide_results’
#模拟设置
liraglutide_model = create_liraglutide_model()
#模拟并生成一个基本的模拟文件
run_simulation(liraglutide_model, ‘liraglutide_reference.h5’)
#为每个参数创建一个Dict
parameter1 = Dict()
#指定模型中参数的路径
parameter1.location = ‘/input/model/unit_001/COL_DISPERSION’
#最小值
parameter1.min = 1e-10
#最大值
parameter1.max = 1e-6
#-1 means the parameter is independent of components.
parameter1.component = -1
#-1 means the paramter is indepdent of bound states.
parameter1.bound = -1
parameter1.transform = ‘null’
parameter2 = Dict()
parameter2.location = ‘/input/model/unit_001/COL_POROSITY’
parameter2.min = 0.2
parameter2.max = 0.7
parameter2.component = 0
parameter2.bound = 0
parameter2.transform = ‘null’
parameter3 = Dict()
parameter3.location = ‘/input/model/unit_001/adsorption/MPM_KA’
parameter3.min = 1
parameter3.max = 10000
parameter3.component = 1
parameter3.bound = 0
parameter3.transform = ‘auto’
parameter4 = Dict()
parameter4.location = ‘/input/model/unit_001/adsorption/MPM_KD’
parameter4.min = 0.01
parameter4.max = 100
parameter4.component = 1
parameter4.bound = 0
parameter4.transform = ‘auto’
parameter5 = Dict()
parameter5.location = ‘/input/model/unit_001/adsorption/QMAX’
parameter5.min = 1
parameter5.max = 1000
parameter5.component = 1
parameter5.bound = 0
parameter5.transform = ‘auto’
#将参数添加到match对象的参数列表
match_config.parameters = [parameter1, parameter2,parameter3,parameter4,parameter5,]
#为每个实验创建另一个Dict并指定所需的数据
experiment1 = Dict()
#实验命名
experiment1.name = ‘liraglutide_10CV2.5g’
#实验数据导入,在本示例中,数据可以在/resources/dextran_experiment.csv下找到。
experiment1.csv = ‘/10CV2.5g.csv’
#提供包含基本模拟的.h5文件的路径
experiment1.HDF5 = ‘liraglutide_10CV2.5g.h5’
#指定在Cadet模型中要与实验数据匹配的数据的路径
experiment1.output_path = ‘/output/solution/unit_002/SOLUTION_OUTLET_COMP_001’
#将实验添加到match的实验列表
match_config.experiments = [experiment1,]
#指标设定
feature1 = Dict()
feature1.name = “Pulse”
feature1.type = ‘SSE’
experiment1.features = [feature1,]
#搜索方法设定
match_config.searchMethod = ‘NSGA3’
match_config.population = 12
match_config.stallGenerations = 10
match_config.finalGradRefinement = True
match_config.gradVector = True
from CADETMatch.jupyter import Match
match_config_file = base_dir / ‘liraglutide.json’
with open(match_config_file.as_posix(), ‘w’) as json_file:
json.dump(match_config.to_dict(), json_file, indent=‘\t’)
match = Match(match_config_file)
match.start_sim()
match.plot_corner()
match.plot_best()
plt.show()
Hello, please help me check if there may be many issues with the code I post
Thanks for the code, please try to simplify to get a minimum reproducible error. I.e. remove as much code as possible s.t. the error still persists. Otherwise, it will be almost impossible for us to start debugging.
In addition, try to remove every reference to other files (e.g. raw data) to which we do not have access to. Use synthetic data if necessary.
Finally, I would like to note that we are no longer developing CADET-Match. The future is CADET-Process. It offers a much better interface for modelling processes and is more flexible for setting up optimization problems. Moreover, since the developer of CADET-Match no longer works for us, we cannot really help with fixing any issues there.
Thank you very much for your reply. My issue has been resolved and I will continue to learn CADET-PROCESS