def test_solver_options(self):
		s = SolverCVXPY()
		if s is None:
			return
		s.init_problem(self.n, use_slack=False, use_2pass=False)

		# solve variants:

		self.anatomy['tumor'].constraints.clear()
		self.anatomy['oar'].constraints.clear()
		structure_list = self.anatomy.list
		structure_list[0].constraints += D('mean') >= 20 * Gy
		structure_list[0].constraints += D(10) >= 0.1 * Gy
		s.build(structure_list, exact=False)

		if module_installed('scs'):
			for INDIRECT in [True, False]:
				for GPU in [True, False]:
					solver_status = s.solve(
							solver=cvxpy.SCS, verbose=0,
							use_indirect=INDIRECT, use_gpu=GPU)
					self.assertTrue( solver_status )

		if module_installed('ecos'):
			solver_status = s.solve(
					solver=cvxpy.ECOS, verbose=0, use_indirect=INDIRECT)
			self.assertTrue( solver_status )
Exemple #2
0
    def test_problem_init(self):
        p = PlanningProblem()

        if module_installed('cvxpy'):
            self.assertIsNotNone(p.solver_cvxpy)
        else:
            self.assertIsNone(p.solver_cvxpy)

        if module_installed('optkit'):
            self.assertIsNotNone(p.solver_pogs)
        else:
            self.assertIsNone(p.solver_pogs)

        self.assertIsNone(p._PlanningProblem__solver)
        self.assertIsNotNone(p.solver)
Exemple #3
0
	def test_problem_init(self):
		p = PlanningProblem()

		if module_installed('cvxpy'):
			self.assertTrue( p.solver_cvxpy is not None )
		else:
			self.assertTrue( p.solver_cvxpy is None )

		if module_installed('optkit'):
			self.assertTrue( p.solver_pogs is not None )
		else:
			self.assertTrue( p.solver_pogs is None )

		self.assertTrue( p._PlanningProblem__solver is None )
		self.assertTrue( p.solver is not None )
Exemple #4
0
    def test_solver_options(self):
        s = SolverCVXPY()
        if s is None:
            return
        s.init_problem(self.n, use_slack=False, use_2pass=False)

        # solve variants:

        self.anatomy["tumor"].constraints.clear()
        self.anatomy["oar"].constraints.clear()
        structure_list = self.anatomy.list
        structure_list[0].constraints += D("mean") >= 20 * Gy
        structure_list[0].constraints += D(10) >= 0.1 * Gy
        s.build(structure_list, exact=False)

        if module_installed("scs"):
            for INDIRECT in [True, False]:
                for GPU in [True, False]:
                    solver_status = s.solve(solver=cvxpy.SCS, verbose=0, use_indirect=INDIRECT, use_gpu=GPU)
                    self.assertTrue(solver_status)

        if module_installed("ecos"):
            solver_status = s.solve(solver=cvxpy.ECOS, verbose=0, use_indirect=INDIRECT)
            self.assertTrue(solver_status)
Exemple #5
0
CONRAD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CONRAD.  If not, see <http://www.gnu.org/licenses/>.
"""
from conrad.compat import *

import os

from conrad.defs import module_installed

# allow for CONRAD use without plotting by making visualization types
# optional
PLOTTING_INSTALLED = False
DISPLAY_AVAILABLE = False
if module_installed('matplotlib'):
	PLOTTING_INSTALLED = True

	import matplotlib as mpl
	import matplotlib.lines
	import matplotlib.axes
	import matplotlib.figure
	import matplotlib.colors
	if os.getenv('DISPLAY') is None:
		mpl.use('Agg')
	else:
		DISPLAY_AVAILABLE = True
	import matplotlib.pyplot as plt
Exemple #6
0
You should have received a copy of the GNU General Public License
along with CONRAD.  If not, see <http://www.gnu.org/licenses/>.
"""
from conrad.compat import *

import time
import numpy as np

from conrad.defs import vec as conrad_vec, module_installed, println
from conrad.medicine.dose import Constraint, MeanConstraint, MinConstraint, \
         MaxConstraint, PercentileConstraint
from conrad.medicine.anatomy import Anatomy
from conrad.optimization.preprocessing import ObjectiveMethods
from conrad.optimization.solver_base import *

if module_installed('cvxpy'):
    import cvxpy

    if module_installed('scs'):
        SOLVER_DEFAULT = cvxpy.SCS
    else:
        SOLVER_DEFAULT = cvxpy.ECOS

    class SolverCVXPY(Solver):
        """
		Interface between :mod:`conrad` and :mod:`cvxpy` optimization library.

		:class:`SolverCVXPY` interprets :mod:`conrad` treatment planning
		problems (based on structures with attached objectives, dose
		constraints, and dose matrices) to build equivalent convex
		optimization problems using :mod:`cvxpy`'s syntax.
Exemple #7
0
import abc
import numpy as np
import operator as op
import cvxpy

from conrad.defs import vec, module_installed
from conrad.physics.units import Gy, DeliveredDose
from conrad.physics.string import dose_from_string

WEIGHT_PWL_UNDER_DEFAULT = 1.
WEIGHT_PWL_OVER_DEFAULT = 0.05
WEIGHT_HINGE_DEFAULT = 1.
WEIGHT_LIN_NONTARGET_DEFAULT = 0.03

OPTKIT_INSTALLED = module_installed('optkit')
if OPTKIT_INSTALLED:
    import optkit as ok


@add_metaclass(abc.ABCMeta)
class TreatmentObjective(object):
    def __init__(self, **dose_and_weight_params):
        self.global_scaling = 1.
        self.normalization = 1.
        self.__weights = {}
        self.__doses = {}
        self.__aliases = {}
        self.__structure = None
        alias_dict = dose_and_weight_params.pop('aliases', {})
        for k, v in dose_and_weight_params.items():
Exemple #8
0
along with CONRAD.  If not, see <http://www.gnu.org/licenses/>.
"""
from conrad.compat import *

from os import path
from math import ceil
from numpy import linspace
from os import getenv

from conrad.defs import module_installed
from conrad.optimization.history import RunRecord
from conrad.case import Case

# allow for CONRAD use without plotting by making visualization types
# optional
if module_installed('matplotlib'):
	PLOTTING_INSTALLED = True

	import matplotlib
	if getenv('DISPLAY') is not None:
		import matplotlib.pyplot as plt
		SHOW = plt.show
	else:
		matplotlib.use('Agg')
		import matplotlib.pyplot as plt
		SHOW = lambda : None

	from matplotlib.pyplot import get_cmap
	from matplotlib.colors import LinearSegmentedColormap
else:
	PLOTTING_INSTALLED = False
Exemple #9
0
You should have received a copy of the GNU General Public License
along with CONRAD.  If not, see <http://www.gnu.org/licenses/>.
"""
from conrad.compat import *

from time import clock
from numpy import copy as np_copy, inf, nan

from conrad.defs import vec as conrad_vec, module_installed, println
from conrad.medicine.dose import Constraint, MeanConstraint, MinConstraint, \
								 MaxConstraint, PercentileConstraint
from conrad.medicine.anatomy import Anatomy
from conrad.optimization.solver_base import *

if module_installed('cvxpy'):
	import cvxpy

	if module_installed('scs'):
		SOLVER_DEFAULT = cvxpy.SCS
	else:
		SOLVER_DEFAULT = cvxpy.ECOS

	class SolverCVXPY(Solver):
		"""
		Interface between :mod:`conrad` and :mod:`cvxpy` optimization library.

		:class:`SolverCVXPY` interprets :mod:`conrad` treatment planning
		problems (based on structures with attached objectives, dose
		constraints, and dose matrices) to build equivalent convex
		optimization problems using :mod:`cvxpy`'s syntax.
Exemple #10
0
CONRAD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CONRAD.  If not, see <http://www.gnu.org/licenses/>.
"""
from conrad.compat import *

from numpy import nan

from conrad.defs import module_installed
from conrad.optimization.solver_base import *

if module_installed('optkit'):
	import optkit as ok

	class SolverOptkit(Solver):
		r"""
		Interface between :mod:`conrad` and :mod:`optkit`'s POGS
		implementation.

		:class:`SolverOptkit` interprets :mod:`conrad`: treatment
		planning problems (based on structures with attached objectives,
		dose constraints, and dose matrices) to build equivalent convex
		optimization problems using POGS' syntax.

		The class provides an interface to modify, run, and retrieve
		solutions from optimization problems that can be executed on
		a CPU or GPU.
Exemple #11
0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CONRAD.  If not, see <http://www.gnu.org/licenses/>.
"""
from conrad.compat import *

import numpy as np

from conrad.defs import module_installed, CONRAD_DEBUG_PRINT
from conrad.medicine.anatomy import Anatomy
from conrad.optimization.preprocessing import ObjectiveMethods
from conrad.optimization.solver_base import *

if module_installed('optkit'):
    import optkit as ok

    class SolverOptkit(Solver):
        r"""
		Interface between :mod:`conrad` and :mod:`optkit`'s POGS
		implementation.

		:class:`SolverOptkit` interprets :mod:`conrad`: treatment
		planning problems (based on structures with attached objectives,
		dose constraints, and dose matrices) to build equivalent convex
		optimization problems using POGS' syntax.

		The class provides an interface to modify, run, and retrieve
		solutions from optimization problems that can be executed on
		a CPU or GPU.