opentps.core.processing.planOptimization.solvers package
Submodules
opentps.core.processing.planOptimization.solvers.beamletFree module
- class BLFree(**kwargs)
Bases:
object
Beamlet free solver class. The beamlet free opitmization is done by the mcSquareDoseCalculator and thereby done directly in the mcSquare C code. This module is juste the interface between python and the C code.
!! THIS CLASS IS NOT FULLY IMPLEMENTED YET !! To use the beamlet free solver, you need to call it via the mcSquareDoseCalculator.optimizeBeamletFree() method.
- solve()
Solve the beamlet free optimization problem.
opentps.core.processing.planOptimization.solvers.bfgs module
- class BFGS(accel=<opentps.core.processing.planOptimization.acceleration.linesearch.LineSearch object>, **kwargs)
Bases:
GradientDescent
Broyden–Fletcher–Goldfarb–Shanno algorithm. This algorithm solves unconstrained nonlinear planOptimization problems. The BFGS method belongs to quasi-Newton methods, a class of hill-climbing planOptimization techniques that seek a stationary point of a (preferably twice continuously differentiable) function.
- class LBFGS(m=10, accel=<opentps.core.processing.planOptimization.acceleration.linesearch.LineSearch object>, **kwargs)
Bases:
BFGS
Limited-memory Broyden–Fletcher–Goldfarb–Shanno algorithm (L-BFGS). It approximates BFGS using a limited amount of computer memory. Like the original BFGS, L-BFGS uses an estimate of the inverse Hessian matrix to steer its search through variable space, but where BFGS stores a dense n × n approximation to the inverse Hessian (n being the number of variables in the problem), L-BFGS stores only a few vectors that represent the approximation implicitly
- getHg(H0, g)
This function returns the approximate inverse Hessian multiplied by the gradient, H*g
- Parameters:
H0 (ndarray) – Initial guess for the inverse Hessian
g (ndarray) – Gradient of the objective function
- class ScipyOpt(meth='L-BFGS', **kwargs)
Bases:
object
ScipyOpt is a wrapper for the scipy.optimize.minimize function.
- Variables:
meth (str (default: 'L-BFGS')) – The name of the scipy.optimize.minimize method to be used.
Nfeval (int) – The number of function evaluations.
params (dict) –
The parameters for the scipy.optimize.minimize function. The paremeters are:
- ftolfloat (default: 1e-06)
Tolerance for termination by the change of the cost function.
- gtolfloat (default: 1e-05)
Tolerance for termination by the norm of the gradient.
- maxitint (default: 1000)
Maximum number of iterations.
- outputstr (default: None)
The name of the output file.
name (str) – The name of the solver.
- solve(func, x0, bounds=None)
Solves the planOptimization problem using the scipy.optimize.minimize function.
- Parameters:
func (list of functions) – The functions to be optimized.
x0 (list) – The initial guess.
bounds (list of Bounds (default: None)) – The bounds on the variables for scipy.optimize.minimize. By default, no bounds are set. Machine delivery constraints can (and should) be enforced by setting the bounds.
- Returns:
result – The result of the planOptimization. The keys are:
- sollist
The solution.
- critstr
The termination criterion.
- niterint
The number of iterations.
- timefloat
The time of the planOptimization.
- objectivelist
The value of the objective function at each iteration.
- Return type:
dict
opentps.core.processing.planOptimization.solvers.fista module
- class FISTA(accel=<opentps.core.processing.planOptimization.acceleration.fistaAccel.FistaAccel object>, indicator=None, lambda_=1, **kwargs)
Bases:
ConvexSolver
Fast Iterative Shrinkage-Thresholding Algorithm (FISTA) solver class for convex problems. Inherit from ConvexSolver. This part of the code comes from the EPFL LTS2 convex optimization toolbox.
- Variables:
meth (str (default: 'ForwardBackward')) – The name of the FISTA method to be used.
indicator (Indicator (default: None)) – The indicator function.
projection (Projection (default: None)) – The projection function.
lambda (float (default: 1)) – The lambda parameter.
z (ndarray) – The z variable.
- solveForwardBackward()
Forward-backward proximal splitting algorithm (ISTA and FISTA). Can be used for problems composed of the sum of a smooth and a non-smooth function. For details about the algorithm, see A. Beck and M. Teboulle, “A fast iterative shrinkage-thresholding algorithm for linear inverse problems”, SIAM Journal on Imaging Sciences, vol. 2, no. 1, pp. 183–202, 2009.
- solveGeneralizedForwardBackward()
Generalized forward-backward proximal splitting algorithm. Can be used for problems composed of the sum of any number of smooth and non-smooth functions. For details about the algorithm, see H. Raguet, “A Generalized Forward-Backward Splitting”, SIAM Journal on Imaging Sciences, vol. 6, no. 13, pp 1199-1226, 2013.
opentps.core.processing.planOptimization.solvers.gradientDescent module
- class GradientDescent(**kwargs)
Bases:
ConvexSolver
class for gradient descent solver. Inherits from ConvexSolver. This part of the code comes from the EPFL LTS2 convex optimization toolbox.
opentps.core.processing.planOptimization.solvers.localSearch module
- class LS(**kwargs)
Bases:
object
Local search solver base class.
!! This class is not implemented yet !!
opentps.core.processing.planOptimization.solvers.lp module
- class LP(plan: RTPlan, **kwargs)
Bases:
object
LP is a wrapper for the Gurobi linear optimizer.
- Variables:
plan (RTPlan) – The plan to be optimized.
solStruct (WeightStructure) – The structure of the solution.
xVars (list) – The list of the variables.
fidWeight (float (default: 1)) – The weight for the dose fidelity term.
LNSNIter (int (default: 0)) – The number of LNS iterations.
LNSPercentLayers (float (default: -1)) – The percentage of layers to be optimized in each LNS iteration.
completeAfterLNS (bool (default: True)) – If True, the optimization is completed after the LNS iterations.
LNSPercentLayersInc (float (default: 0)) – The increment of the percentage of layers to be optimized in each LNS iteration.
groupSpotsInit (int (default: 0)) – The number of spots to be grouped in the first iteration.
groupSpotsIter (int (default: 0)) – The number of iterations for the spot grouping.
completeAfterGroup (bool (default: True)) – If True, the optimization is completed after the spot grouping iterations.
groupSpots (bool (default: False)) – If True, the spots are grouped.
M (int (default: 20)) – The maximum number of MU per spot.
timeLimit (int (default: 300)) – The time limit for the optimization.
inputf (str (default: None)) – The name of the input file.
solFile (str (default: None)) – The name of the solution file.
- createModel(name='LP')
Creates the Gurobi model.
- Parameters:
name (str (default: “LP”)) – The name of the model.
- Returns:
model – The Gurobi model.
- Return type:
Gurobi model
- solve(func, x0, **kwargs)
Solves the planOptimization problem using the Gurobi linear optimizer.
- Parameters:
func (list of functions) – The functions to be optimized.
x0 (list) – The initial guess.
kwargs (dict) – The parameters for the Gurobi linear optimizer.
- Returns:
result – The result of the planOptimization. The keys are:
- sollist
The solution.
- critstr
The termination criterion.
- niterint
The number of iterations.
- timefloat
The time.
- objectivefloat
The objective function value.
- Return type:
dict
opentps.core.processing.planOptimization.solvers.mip module
- class MIP(plan: RTPlan, **kwargs)
Bases:
LP
Mixed Integer Programming solver for the sequencing problem. The solver is based on the Gurobi solver. Inherit from LP.
- Parameters:
plan (RTPlan) – The plan to be optimized
**kwargs – Additional parameters for the solver. Arguments are: - max_switch_ups : int
Maximum number of energy layer switches. If -1, the number of switches is not limited
- EL_costbool
If True, the energy layer switch costs are taken into account
- ES_up_weightfloat
Weight of the energy layer switch costs in the objective function
max_switch_ups (int (default: -1)) – Maximum number of energy layer switches. If -1, the number of switches is not limited
no_EL_cost (bool (default: False)) – If True, the energy layer switch costs are not taken into account
machine (bool (default: False)) – If True, the energy layer switch costs are calculated based on the machine
time_weight (float (default: -1)) – Weight of the energy layer switch costs in the objective function
- createModel(name='MIP')
Create the model for the MIP solver. Inherit from LP.createModel().
- Parameters:
name (str (default: “MIP”)) – Name of the model
- Returns:
model – The model for the MIP solver
- Return type:
gurobipy.Model
opentps.core.processing.planOptimization.solvers.solver module
- class ConvexSolver(step=0.1, accel=None, **kwargs)
Bases:
object
ConvexSolver is the base class for all convex solvers. This part of the code comes from the EPFL LTS2 convex optimization toolbox.
- Variables:
step (float (default: 0.1)) – The step size.
accel (Accel (default: None)) – The acceleration scheme.
params (dict) –
The parameters for the solver. The paremeters are:
- dtolfloat (default: None)
Tolerance for termination by the change of the cost function.
- xtolfloat (default: None)
Tolerance for termination by the change of the solution.
- atolfloat (default: None)
Tolerance for termination by the cost function.
- ftolfloat (default: 1e-03)
Tolerance for termination by the relative change of the cost function.
non_smooth_funs (list) – The list of non-smooth functions.
smooth_funs (list) – The list of smooth functions.
fid_cost (list) – The list of the cost function values.
sol (ndarray) – The solution.
- algo(objective, niter)
Call the solver iterative algorithm and the provided acceleration scheme
- Parameters:
objective (list) – The value of the objective function at each iteration.
niter (int) – The number of iterations.
- objective(x)
Return the objective function at x. Necessitate solver._pre(…) to be run first.
- Parameters:
x (ndarray) – The point at which the objective function is evaluated.
- Returns:
obj – The value of the objective function at x.
- Return type:
list
- post()
Solver-specific post-processing. Mainly used to delete references added during initialization so that the garbage collector can free the memory.
- pre(functions, x0)
Solver-specific pre-processing; functions split in two lists: - self.smoothFuns : functions involved in gradient steps - self.nonSmoothFuns : functions involved in proximal steps
- Parameters:
functions (list) – list of convex functions to minimize
x0 (ndarray) – initial weight vector
- solve(functions, x0)
Solve an planOptimization problem whose objective function is the sum of some convex functions.
- Parameters:
functions (list) – list of convex functions to minimize (objects must implement the “pyopti.functions.func.eval” and/or pyopti.functions.func.prox methods, required by some solvers).
x0 (ndarray) – initial weight vector
- Returns:
result – The result of the planOptimization. The keys are:
- sollist
The solution.
- solverstr
The name of the solver.
- critstr
The termination criterion.
- niterint
The number of iterations.
- timefloat
The time of the planOptimization.
- objectivelist
The value of the objective function at each iteration.
- Return type:
dict
opentps.core.processing.planOptimization.solvers.sparcling module
- class SPArCling(plan, arcStart, arcStop, maxNSplitting, finalAngleStep, mode='BLBased', coreOptimizer='Scipy-LBFGS', **kwargs)
Bases:
object
SPArCling is a solver for the spot-scanning Poron Arc Therapy (SPArC) problem.
- Variables:
plan (Plan) – The plan to be optimized.
arcStart (float) – The start angle of the arc.
arcStop (float) – The stop angle of the arc.
maxNSplitting (int) – The maximum number of splitting steps.
finalAngleStep (float) – The final angle step.
mode (str (default: 'BLBased')) – The mode of the solver.
coreOptimizer (str (default: 'Scipy-LBFGS')) – The core optimizer to be used.
M (int (default: 2)) – The number of beams to be used.
angularStep (float) – The angular step.
theta1 (float) – The first theta.
theta2 (float) – The second theta.
minTheta (float) – The minimum theta.
theta0 (float) –
- removeBeams()
- removeLayers()
- solve(func, x0, **kwargs)
Solves the SPArCling problem.
!!! This function is not finished yet !!!
- Parameters:
func (function) – The function to be optimized.
x0 (ndarray) – The initial guess.
kwargs (dict) – Additional keyword arguments.
- splitBeams()