Package mystic :: Module abstract_nested_solver

Module abstract_nested_solver

source code

This module contains the base class for launching several mystic solvers instances -- utilizing a parallel "map" function to enable parallel computing. This module describes the nested solver interface. As with the AbstractSolver, the "Solve" method must be overwritte with the derived solver's optimization algorithm. Similar to AbstractMapSolver, a call to is required. In many cases, a minimal function call interface for a derived solver is provided along with the derived class. See the following for an example.

The default map API settings are provided within mystic, while distributed and high-performance computing mappers and launchers can be obtained within the "pathos" package, found here:



A typical call to a 'nested' solver will roughly follow this example:

>>> # the function to be minimized and the initial values
>>> from mystic.models import rosen
>>> lb = [0.0, 0.0, 0.0]
>>> ub = [2.0, 2.0, 2.0]
>>> # get monitors and termination condition objects
>>> from import Sow
>>> stepmon = Sow()
>>> from mystic.termination import CandidateRelativeTolerance as CRT
>>> # select the parallel launch configuration
>>> from pyina.launchers import mpirun_launcher
>>> from pyina.ez_map import ez_map2
>>> NNODES = 4
>>> nbins = [4,4,4]
>>> # instantiate and configure the solver
>>> from mystic.scipy_optimize import NelderMeadSimplexSolver
>>> from mystic.nested import BatchGridSolver
>>> solver = BatchGridSolver(len(nbins), nbins)
>>> solver.SetNestedSolver(NelderMeadSimplexSolver)
>>> solver.SetStrictRanges(lb, ub)
>>> solver.SetMapper(ez_map2)
>>> solver.SetLauncher(mpirun_launcher, NNODES)
>>> solver.Solve(rosen, CRT(), StepMonitor=stepmon)
>>> # obtain the solution
>>> solution = solver.Solution()


All solvers packaged with mystic include a signal handler that provides the following options:

   sol: Print current best solution.
   cont: Continue calculation.
   call: Executes sigint_callback, if provided.
   exit: Exits with current best solution.

Handlers are enabled with the 'enable_signal_handler' method, and are configured through the solver's 'Solve' method. Handlers trigger when a signal interrupt (usually, Ctrl-C) is given while the solver is running. ***NOTE: The handler currently is disabled when the solver has been launched in parallel.***

AbstractNestedSolver base class for mystic optimizers that are nested within a parallel map.