Optimize Batch Elution Process (Single Objective)
from CADETProcess.optimization import OptimizationProblem
optimization_problem = OptimizationProblem('batch_elution_single')
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,
}
)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]
)Setup Objectives¶
from CADETProcess.performance import PerformanceProduct
ranking = [1, 1]
performance = PerformanceProduct(ranking=ranking)
optimization_problem.add_objective(
performance, requires=[process_simulator, frac_opt], minimize=False,
)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¶
optimization_results = optimizer.optimize(
optimization_problem,
use_checkpoint=False )==========================================================
n_gen | n_eval | n_nds | eps | indicator
==========================================================
1 | 3 | 1 | - | -
2 | 6 | 1 | 0.0008150780 | f
3 | 9 | 1 | 0.0018897861 | f
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)[[465.9217766 136.87256513]]
[[0.00687963]]
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 354.331x236.22 with 1 Axes>,
array([<Axes: xlabel='$n_{Evaluations}$', ylabel='PerformanceProduct'>],
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.661x354.331 with 2 Axes>,
array([[<Axes: xlabel='cycle_time', ylabel='PerformanceProduct'>,
<Axes: xlabel='feed_duration.time', ylabel='PerformanceProduct'>]],
dtype=object))
Note that more figures are created for constrained optimization, as well as multi-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).