Optimize Batch Elution Process (Multi-Objective)
from CADETProcess.optimization import OptimizationProblem
optimization_problem = OptimizationProblem('batch_elution_multi')
from process import process
optimization_problem.add_evaluation_object(process)
optimization_problem.add_variable('cycle_time', lb=10, ub=600)
optimization_problem.add_variable('feed_duration.time', lb=10, ub=300)
optimization_problem.add_linear_constraint(
['feed_duration.time', 'cycle_time'], [1, -1]
)Setup Simulator¶
from CADETProcess.simulator import Cadet
process_simulator = Cadet()
process_simulator.evaluate_stationarity = True
optimization_problem.add_evaluator(process_simulator)Setup Fractionator¶
from CADETProcess.fractionation import FractionationOptimizer
frac_opt = FractionationOptimizer()
optimization_problem.add_evaluator(
frac_opt,
kwargs={
'purity_required': [0.95, 0.95],
'ignore_failed': False,
'allow_empty_fractions': False,
}
)Setup Objectives¶
from CADETProcess.performance import Productivity, Recovery, EluentConsumption
productivity = Productivity()
optimization_problem.add_objective(
productivity,
n_objectives=2,
requires=[process_simulator, frac_opt],
minimize=False,
)
recovery = Recovery()
optimization_problem.add_objective(
recovery,
n_objectives=2,
requires=[process_simulator, frac_opt],
minimize=False,
)
eluent_consumption = EluentConsumption()
optimization_problem.add_objective(
eluent_consumption,
n_objectives=2,
requires=[process_simulator, frac_opt],
minimize=False,
)Add callback for post-processing¶
def callback(fractionation, individual, evaluation_object, callbacks_dir):
fractionation.plot_fraction_signal(
file_name=f'{callbacks_dir}/{individual.id}_{evaluation_object}_fractionation.png',
)
optimization_problem.add_callback(
callback, requires=[process_simulator, frac_opt]
)Configure Optimizer¶
from CADETProcess.optimization import U_NSGA3
optimizer = U_NSGA3()
optimizer.n_max_gen = 3
optimizer.pop_size = 3
optimizer.n_cores = 3Run Optimization¶
if __name__ == '__main__':
optimization_results = optimizer.optimize(
optimization_problem,
use_checkpoint=True
)WARNING: pop_size=3 is less than the number of reference directions ref_dirs=56.
This might cause unwanted behavior of the algorithm.
Please make sure pop_size is equal or larger than the number of reference directions.
==========================================================
n_gen | n_eval | n_nds | eps | indicator
==========================================================
1 | 3 | 2 | - | -
2 | 6 | 2 | 1.0000000000 | ideal
3 | 9 | 2 | 0.3185710017 | ideal
Optimization Progress and Results¶
The OptimizationResults which are returned contain information about the progress of the optimization.
For example, the attributes x and f contain the final value(s) of parameters and the objective function.
print(optimization_results.x)
print(optimization_results.f)[[512.51326166 36.54762537]
[553.27593302 203.38731573]]
[[0.00840186 0.0085722 0.95941417 0.97886552 0.73669834 0.75163431]
[0.01215485 0.00980644 0.26924804 0.21722713 1.56511626 1.26272308]]
After optimization, several figures can be plotted to vizualize the results. For example, the convergence plot shows how the function value changes with the number of evaluations.
optimization_results.plot_convergence()(<Figure size 2125.98x236.22 with 6 Axes>,
array([<Axes: xlabel='$n_{Evaluations}$', ylabel='Productivity_0'>,
<Axes: xlabel='$n_{Evaluations}$', ylabel='Productivity_1'>,
<Axes: xlabel='$n_{Evaluations}$', ylabel='Recovery_0'>,
<Axes: xlabel='$n_{Evaluations}$', ylabel='Recovery_1'>,
<Axes: xlabel='$n_{Evaluations}$', ylabel='EluentConsumption_0'>,
<Axes: xlabel='$n_{Evaluations}$', ylabel='EluentConsumption_1'>],
dtype=object))




The plot_objectives method shows the objective function values of all evaluated individuals.
Here, lighter color represent later evaluations.
Note that by default the values are plotted on a log scale if they span many orders of magnitude.
To disable this, set autoscale=False.
optimization_results.plot_objectives()(<Figure size 708.661x2125.98 with 12 Axes>,
array([[<Axes: xlabel='cycle_time', ylabel='Productivity_0'>,
<Axes: xlabel='feed_duration.time', ylabel='Productivity_0'>],
[<Axes: xlabel='cycle_time', ylabel='Productivity_1'>,
<Axes: xlabel='feed_duration.time', ylabel='Productivity_1'>],
[<Axes: xlabel='cycle_time', ylabel='Recovery_0'>,
<Axes: xlabel='feed_duration.time', ylabel='Recovery_0'>],
[<Axes: xlabel='cycle_time', ylabel='Recovery_1'>,
<Axes: xlabel='feed_duration.time', ylabel='Recovery_1'>],
[<Axes: xlabel='cycle_time', ylabel='EluentConsumption_0'>,
<Axes: xlabel='feed_duration.time', ylabel='EluentConsumption_0'>],
[<Axes: xlabel='cycle_time', ylabel='EluentConsumption_1'>,
<Axes: xlabel='feed_duration.time', ylabel='EluentConsumption_1'>]],
dtype=object))
Note that more figures are created for constrained optimization, as well as single-objective optimization.
All figures are also saved automatically in the working_directory.
Moreover, results are stored in a .csv file.
The
results_all.csvfile contains information about all evaluated individuals.The
results_last.csvfile contains information about the last generation of evaluated individuals.The
results_pareto.csvfile contains only the best individual(s).