Optimization error while fiting parameters to data

Hi all

I’m trying to use CADET-Process to fit model parameters to my experimental data. I’m following this case study (which runs fine).

In my case, instead of fitting porosity and axial dispersion, I want to fit film difffusion, axial dispersion, and the linear isotherm adsorption rate.

When adding either film diffusion or the linear isotherm adsorption rate, I get the following error:

ValueError: Scalar parameters cannot have index slices.

Which appears to happen when adding variables in lists.

Here is what I am doing:

optimization_problem = OptimizationProblem('fit_param', use_diskcache=False)


    indices=0,      # <-- I've tried with and without this
    lb=1e-10, ub=1.0,

    lb=1e-10, ub=0.1, transform='auto'

The full error:

ValueError                                Traceback (most recent call last)
Cell In[14], line 5
      1 optimization_problem = OptimizationProblem('fit_param', use_diskcache=False)
      3 optimization_problem.add_evaluation_object(process)
----> 5 optimization_problem.add_variable(
      6     name='film_diffusion', 
      7     parameter_path='flow_sheet.column.film_diffusion',
      8     indices=0, 
      9     lb=1e-10, ub=1.0,
     10     transform='auto'
     11 )
     13 optimization_problem.add_variable(
     14     name='axial_dispersion', 
     15     parameter_path='flow_sheet.column.axial_dispersion',
     16     lb=1e-10, ub=0.1, transform='auto'
     17 )
     19 # optimization_problem.add_variable(
     20 #     name='isotherm_constant', 
     21 #     parameter_path='flow_sheet.column.binding_model.adsorption_rate',
     22 #     lb=1e-2, ub=10.0,
     23 #     transform='auto'
     24 # )

File ~\miniconda3\envs\cadet\lib\site-packages\CADETProcess\optimization\optimizationProblem.py:347, in OptimizationProblem.add_variable(self, name, evaluation_objects, parameter_path, lb, ub, transform, indices)
    342 if parameter_path is not None and len(evaluation_objects) == 0:
    343     raise ValueError(
    344         "Cannot set parameter_path for variable without evaluation object "
    345     )
--> 347 var = OptimizationVariable(
    348     name, evaluation_objects, parameter_path,
    349     lb=lb, ub=ub, transform=transform,
    350     indices=indices,
    351 )
    353 self._variables.append(var)
    355 with warnings.catch_warnings():

File ~\miniconda3\envs\cadet\lib\site-packages\CADETProcess\optimization\optimizationProblem.py:2962, in OptimizationVariable.__init__(self, name, evaluation_objects, parameter_path, lb, ub, transform, indices, precision)
   2960     self.evaluation_objects = evaluation_objects
   2961     self.parameter_path = parameter_path
-> 2962     self.indices = indices
   2963 else:
   2964     self.evaluation_objects = None

File ~\miniconda3\envs\cadet\lib\site-packages\CADETProcess\optimization\optimizationProblem.py:3169, in OptimizationVariable.indices(self, indices)
   3167     _ = self.indices
   3168 except (ValueError, TypeError) as e:
-> 3169     raise e

File ~\miniconda3\envs\cadet\lib\site-packages\CADETProcess\optimization\optimizationProblem.py:3167, in OptimizationVariable.indices(self, indices)
   3165 # Since indices are constructed on `get`, call the property here:
   3166 try:
-> 3167     _ = self.indices
   3168 except (ValueError, TypeError) as e:
   3169     raise e

File ~\miniconda3\envs\cadet\lib\site-packages\CADETProcess\optimization\optimizationProblem.py:3126, in OptimizationVariable.indices(self)
   3124 parameter_shape = self._get_parameter_shape(eval_obj)
   3125 if isinstance(parameter_shape, tuple):
-> 3126     eval_ind = generate_indices(parameter_shape, eval_ind)
   3127 else:
   3128     if not isinstance(eval_ind, list):

File ~\miniconda3\envs\cadet\lib\site-packages\CADETProcess\dynamicEvents\section.py:663, in generate_indices(shape, indices)
    661 size = np.prod(shape)
    662 if size == 1:
--> 663     raise ValueError("Scalar parameters cannot have index slices.")
    665 if indices is None:
    666     indices = np.s_[:]

ValueError: Scalar parameters cannot have index slices.

What am I missing?

If needed I can provide the full code but I think this is enough as I am using the code from the case study and just adding a binding model. Then choosing different optimization variables, as shown above.

Hi José,

thank you for bringing that to our attention. I can reproduce the issue.

Jo is on vacation right now. I’ve tried to create a little hot-fix, but I don’t know if my “fix” will create other issues in other places, so it’ll stay on a separate branch for now. Jo will have to look into that once he returns. But it does solve the parameter estimation issue.

You can install the modified version of CADET-Process with this command:

pip install git+https://github.com/fau-advanced-separations/CADET-Process.git@fix/scalar_parameter_index

Hi Ron. Thanks for the update.

Progress can now be tracked here.