Skip to content

Commit

Permalink
#633 added test for klu and skip if KLU not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmar93 committed Oct 10, 2019
1 parent 5fad697 commit 6a94ec1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 598 deletions.
2 changes: 1 addition & 1 deletion pybamm/__init__.py
Expand Up @@ -237,7 +237,7 @@ def version(formatted=False):
from .solvers.scikits_ode_solver import ScikitsOdeSolver
from .solvers.scikits_ode_solver import have_scikits_odes
from .solvers.algebraic_solver import AlgebraicSolver
from .solvers.klu_sparse_solver import KLU
from .solvers.klu_sparse_solver import KLU, have_klu


#
Expand Down
16 changes: 13 additions & 3 deletions pybamm/solvers/klu_sparse_solver.py
Expand Up @@ -2,12 +2,20 @@
# Solver class using sundials with the KLU sparse linear solver
#
import pybamm

import numpy as np

import klu
import scipy.sparse as sparse

import importlib

klu_spec = importlib.util.find_spec("klu")
if klu_spec is not None:
klu = importlib.util.module_from_spec(klu_spec)
klu_spec.loader.exec_module(klu)


def have_klu():
return klu_spec is None


class KLU(pybamm.DaeSolver):
"""Solve a discretised model, using sundials with the KLU sparse linear solver.
Expand All @@ -31,6 +39,8 @@ class KLU(pybamm.DaeSolver):
def __init__(
self, method="ida", tol=1e-8, root_method="lm", root_tol=1e-6, max_steps=1000
):
if klu_spec is None:
raise ImportError("KLU is not installed")

super().__init__(method, tol, root_method, root_tol, max_steps)

Expand Down
2 changes: 1 addition & 1 deletion pybamm/solvers/scikits_ode_solver.py
Expand Up @@ -134,7 +134,7 @@ def jac_times_setupfn(t, y, fy, userdata):
np.transpose(sol.values.y),
sol.roots.t,
np.transpose(sol.roots.y),
termination
termination,
)
else:
raise pybamm.SolverError(sol.message)

0 comments on commit 6a94ec1

Please sign in to comment.