solve_sim_opt
Main module that contains OptimiSim class definition
- Module
solve_sim_opt.py
- Author
Lucas F. Santos <lfs.francisco.95@gmail.com>
- class dwsimopt.solve_sim_opt.OptimiSim(path2sim, path2dwsim='', savepath='', verbose=True, force_convergence=True, init_dwsim=True)
Bases:
dwsimopt.sim_opt.SimulationOptimizationClass that solves the DWSIM simulation optimization problem.
- Variables
path2sim – Absolute path to a DWSIM simulation (.dwxmz)
path2dwsim – Absolute path to the DWSIM installation
savepath – Absolute path to save the DWSIM simulation (.dwxmz)
verbose – Boolean that controls display messages during simulation calculation
x_val – Last simulated degrees of freedom values
f_val – Last simulated objective functions values
g_val – Last simulated constraints values
dof – Lambda function that assign the degrees of freedom of the DWSIM process simulation to be handled by the optimization solver
f – Lambda function that returns a numpy.array with objective functions values after converging the simulation
g – Lambda function that returns a numpy.array with constraints values after converging the simulation
n_dof – Number of degrees of freedom (size of optimization problem)
n_f – Number of objective functions (still unsupported for n_f>1, i.e. multi-objective problem)
n_g – Number of constraints
force_convergence – Boolean that controls if multiple simulation runs is allowed. It may be usefull for simulations that include python scripts. It is not recomended for those that take a long time to converge.
init_dwsim – Boolean that controls if DWSIM is initialized automatically with OptimiSim class
- AFSA(x0, pen_method='barrier', pen_factor=1000, pop=[], max_ite=[], verbose=True, plotting=True, max_try_num=100, step=0.5, visual=0.3, q=0.98, delta=0.5)
- DE(x0, xlb, xub, pen_method='barrier', pen_factor=1000, pop=[], max_ite=[], verbose=True, plotting=True)
Runs Differential Evolution to solve the simulation optimization problem defined in the OptimiSim
- Args:
x0 (numpy.array): Array of initial values for the degrees of freedom xlb (numpy.array): Array of lower bounds for the degrees of freedom xub (numpy.array): Array of upper bounds for the degrees of freedom pen_method (string): Penalization method (‘barrier’, ‘quad’, or ‘exp’) pen_factor (float): Penalization factor (default=1000) pop (int): population size (default=`2*n_dof`) max_ite (int): maximum number of iterations (default=`5*n_dof`) verbose (boolean): verbose (default=True) plotting(boolean): boolean for plotting or not (default=True)
- Returns:
result_DE (sko.DE.DE): sko object with the optimization results
- GA(x0, xlb, xub, pen_method='barrier', pen_factor=1000, pop=[], max_ite=[], prob_mut=[], verbose=True, plotting=True)
Runs Genetic Algorithm to solve the simulation optimization problem defined in the OptimiSim
- Args:
x0 (numpy.array): Array of initial values for the degrees of freedom xlb (numpy.array): Array of lower bounds for the degrees of freedom xub (numpy.array): Array of upper bounds for the degrees of freedom pen_method (string): Penalization method (‘barrier’, ‘quad’, or ‘exp’) pen_factor (float): Penalization factor (default=1000) pop (int): population size (default=`2*n_dof`) max_ite (int): maximum number of iterations (default=`5*n_dof`) prob_mut (float): probability of mutation from 0 to 1 (default=0.5) verbose (boolean): verbose (default=True) plotting(boolean): boolean for plotting or not (default=True)
- Returns:
result_GA (sko.GA.GA): sko object with the optimization results
- PSO(x0, xlb, xub, pen_method='barrier', pen_factor=1000, pop=[], max_ite=[], verbose=True, plotting=True)
Runs Particle Swarm Optimization to solve the simulation optimization problem defined in the OptimiSim
- Args:
x0 (numpy.array): Array of initial values for the degrees of freedom xlb (numpy.array): Array of lower bounds for the degrees of freedom xub (numpy.array): Array of upper bounds for the degrees of freedom pen_method (string): Penalization method (‘barrier’, ‘quad’, or ‘exp’) pen_factor (float): Penalization factor (default=1000) pop (int): population size (default=`2*n_dof`) max_ite (int): maximum number of iterations (default=`5*n_dof`) verbose (boolean): verbose (default=True) plotting(boolean): boolean for plotting or not (default=True)
- Returns:
result_pso (sko.PSO.PSO): sko object with the optimization results
sim_opt
Main module that contains SimulationOptimization class definition
- Module
sim_opt.py
- Author
Lucas F. Santos <lfs.francisco.95@gmail.com>
- class dwsimopt.sim_opt.SimulationOptimization(path2sim, path2dwsim='', savepath='', verbose=True, force_convergence=True)
Bases:
objectClass that defines DWSIM simulation optimization objects.
- Variables
path2sim – Absolute path to a DWSIM simulation (.dwxmz)
path2dwsim – Absolute path to the DWSIM installation
savepath – Absolute path to save the DWSIM simulation (.dwxmz)
verbose – Boolean that controls display messages during simulation calculation
x_val – Last simulated degrees of freedom values
f_val – Last simulated objective functions values
g_val – Last simulated constraints values
dof – Lambda function that assign the degrees of freedom of the DWSIM process simulation to be handled by the optimization solver
f – Lambda function that returns a numpy.array with objective functions values after converging the simulation
g – Lambda function that returns a numpy.array with constraints values after converging the simulation
n_dof – Number of degrees of freedom (size of optimization problem)
n_f – Number of objective functions (still unsupported for n_f>1, i.e. multi-objective problem)
n_g – Number of constraints
force_convergence – Boolean that controls if multiple simulation runs is allowed. It may be usefull for simulations that include python scripts. It is not recomended for those that take a long time to converge.
- GA(x0, xlb, xub, pen_method='barrier', pen_factor=1000, pop=[], max_ite=[], prob_mut=[], verbose=True, printing=True)
- PSO(x0, xlb, xub, pen_method='barrier', pen_factor=1000, pop=[], max_ite=[], verbose=True, printing=True)
- add_constraint(g_func, description=[None, None, None, None])
Append a new constraint to the SimulationOptimization object
- Args:
g_func (lambda function): Lambda function that returns a numpy.array with constraint value after converging the simulation
- add_dof(dof_new, description=[None, None, None, None])
Append a new degree of freedom to the SimulationOptimization object
- Args:
dof_new (lambda function): Lambda function that assign the appended degrees of freedom of the DWSIM process simulation
- add_fobj(func, description=[None, None, None, None])
Append a new objective function to the SimulationOptimization object
- Args:
func (lambda function): Lambda function that returns a numpy.array with objective function value after converging the simulation
- add_refs()
This method add reference in the proggraming environment to the DWSIM dlls, so they can be imported.
- calculate_optProblem(x)
Assign degrees of freedom values to the simulation if norm > 1e-10. Converge the simulation and return an array with objectives and constraints values.
- Args:
x (numpy.array): Array of degrees of freedom values to be simulated
- Returns:
numpy.array: Array of objectives and constraints values calculated at
x
- connect(interf)
This method uses the automation manager object to load the DWSIM flowsheet and store them into self.
- Args:
interf (DWSIM.Automation.Automation2): Automation manager object with methods to load, save, and create DWSIM flowsheet simulations.
- converge_simulation(x)
Converge the simulation with degrees of freedom values of
x- Args:
x (numpy.array): Array of degrees of freedom values to be simulated
- fpen_barrier(x, pen=1000)
Calculates a penalized objective function using barrier method and considering
fandg.- Args:
x (numpy.array): Array of degrees of freedom values to be simulated. pen (float, optional): Penalization parameter. Defaults to 1000.
- Returns:
float: Penalized objective function.
- fpen_exp(x, pen=1000)
Calculates a penalized objective function using exponential penalization method and considering
fandg.- Args:
x (numpy.array): Array of degrees of freedom values to be simulated. pen (float, optional): Penalization parameter. Defaults to 1000.
- Returns:
float: Penalized objective function.
- fpen_quad(x, pen=1000)
Calculates a penalized objective function using quadratic penalization method and considering
fandg.- Args:
x (numpy.array): Array of degrees of freedom values to be simulated. pen (float, optional): Penalization parameter. Defaults to 1000.
- Returns:
float: Penalized objective function.
- save_flowsheet()
py2dwsim
Module that contains functions for data exchange from-to python to-from dwsim
- Module
py2dwsim.py
- Author
Lucas F. Santos <lfs.francisco.95@gmail.com>
- dwsimopt.py2dwsim.assign_pddx(f, desc, sim, element='dof')
Assign pddx to sim object. This is useful for more complex objective/constaint functions. Basic use is to generate pddx getter functions to define a more complicated one and assign to sim.
- Args:
f (function): function (def or lambda) containing the definition of objective/constraint function. desc (list): list of string containing [‘dwsim object name as in the simulation’, ‘object attribute’,’phase or component name’, ‘unit’] sim (dwsimopt.SimulationOpimization): object of dwsimopt.SimulationOpimization element (str, optional): optimization problem element: ‘dof’, ‘fobj’, or ‘constraint’. Defaults to “dof”.
- dwsimopt.py2dwsim.create_pddx(desc, sim, element='dof', assign=True)
Main function from py2dwsim.py that creates a python-dwsim data exchange channel. It can return a np.array of getter or setter functions from/to the dwsim simulation. The default is to assing the data exchange hub to the SimulationOptimization object passed to this function.
- Args:
desc (list): list of string containing [‘dwsim object name as in the simulation’, ‘object attribute’,’phase or component name’, ‘unit’] sim (dwsimopt.OptimSim): object of dwsimopt.SimulationOpimization or that inherits from it element (str, optional): optimization problem element: ‘dof’, ‘fobj’, or ‘constraint’. Defaults to “dof”. assign (bool, optional): if True: assign the python-dwsim data exchange channel to the corresponding element in sim, else: return lambda function. Defaults to True.
- Returns:
numpy.array: np.array of getter or setter functions from/to the dwsim simulation if assign==False