From 9eafec489597bedd59cc4fc496df9d0dff70490a Mon Sep 17 00:00:00 2001 From: rowanc1 Date: Tue, 26 Nov 2013 20:23:40 -0800 Subject: [PATCH] Added options to the solver class that are dynamic based on your environment. If not available, they will fall back to ones that are. --- SimPEG/utils/Solver.py | 30 ++++++++++++++++-------------- docs/index.rst | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/SimPEG/utils/Solver.py b/SimPEG/utils/Solver.py index 5861c146..c5151837 100644 --- a/SimPEG/utils/Solver.py +++ b/SimPEG/utils/Solver.py @@ -4,23 +4,19 @@ import scipy.sparse.linalg as linalg from SimPEG.utils import mkvc, sdiag import warnings -DEFAULTS = {'direct':'scipy', 'iter':'scipy', 'forward':'fortran', 'backward':'fortran', 'diagonal':'python'} +DEFAULTS = {'direct':'scipy', 'iter':'scipy', 'triangular':'fortran', 'diagonal':'python'} +OPTIONS = {'direct':['scipy'], 'iter':['scipy'], 'triangular':['python'], 'diagonal':['python']} try: import TriSolve + OPTIONS['triangular'].append('fortran') except Exception, e: - try: - import os - # Note: this may not work from SublimeText, if that is the case, just run the command in your shell. - os.system('f2py -c TriSolve.f -m TriSolve') - import TriSolve - except Exception, e: - print 'Warning: Python backend is being used for solver. Run setup.py from the command line.' - DEFAULTS['forward'] = 'python' - DEFAULTS['backward'] = 'python' + print 'Warning: Python backend is being used for solver. Run setup.py from the command line.' + DEFAULTS['triangular'] = 'python' try: import mumps + OPTIONS['direct'].append('mumps') except Exception, e: print 'Warning: mumps solver not available.' @@ -183,7 +179,7 @@ class Solver(object): :param bool factorize: if you want to factorize and store factors :rtype: numpy.ndarray :return: x - """ + """ if factorize and self.dsolve is None: self.mctx = mumps.DMumpsContext() self.mctx.set_icntl(14, 60) @@ -214,7 +210,7 @@ class Solver(object): X[:,i] = self.dsolve(b[:,i]) else: X[:,i] = mumps.spsolve(self.A,b[:,i]) - + return X def solveIter(self, b, backend=None, M=None, iterSolver='CG', tol=1e-6, maxIter=50): @@ -242,7 +238,10 @@ class Solver(object): :rtype: numpy.ndarray :return: x """ - if backend is None: backend = DEFAULTS['backward'] + if backend is None: backend = DEFAULTS['triangular'] + if backend not in OPTIONS['triangular']: + print 'Warning: %s-backend not being used, %s-default will be used instead.'%(backend,DEFAULTS['triangular']) + backend = DEFAULTS['triangular'] if type(self.A) is not sp.csr.csr_matrix: self.A = sp.csr_matrix(self.A) vals = self.A.data @@ -273,7 +272,10 @@ class Solver(object): :rtype: numpy.ndarray :return: x """ - if backend is None: backend = DEFAULTS['forward'] + if backend is None: backend = DEFAULTS['triangular'] + if backend not in OPTIONS['triangular']: + print 'Warning: %s-backend not being used, %s-default will be used instead.'%(backend,DEFAULTS['triangular']) + backend = DEFAULTS['triangular'] if type(self.A) is not sp.csr.csr_matrix: from scipy.sparse import csr_matrix self.A = csr_matrix(self.A) diff --git a/docs/index.rst b/docs/index.rst index 792f3be9..b008e963 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -51,6 +51,21 @@ Testing SimPEG api_Tests api_TestResults +Build Results +============= + +* Master Branch +.. image:: https://travis-ci.org/simpeg/simpeg.png?branch=master + :target: https://travis-ci.org/simpeg/simpeg + :alt: Master Branch + :align: center + +* Develop Branch +.. image:: https://travis-ci.org/simpeg/simpeg.png?branch=develop + :target: https://travis-ci.org/simpeg/simpeg + :alt: Develop Branch + :align: center + Utility Codes =============