-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Motivation
In developing a Simulation
class in SimPEG (simpeg/simpeg#672), I want to be able to readily serialize and deserialize an instance of a Simulation
, so we are injecting properties
throughout, which gives us serialization, deserialization and validation (thanks @fwkoch!!). Right now, the solvers are attached as the simulation as a class, and the solver_opts are attached to the simulation as a dict. We then instantiate a solver as needed in SimPEG
.
State the problem
There are a couple potential snags with this approach
- if your
solver_opts
are not valid, we won't find out until we try and use the solver - It is not readily clear how to serialize the
solver
class (aClass
property is one option New Class property seequent/properties#163, we could also think about serializing / deserializing the name of the class as a string)
Another approach?
We could instantiate the solver with its options and then call it to create Ainv. This would solve the serialization problem and also allow immediate validation of the solver options on its creation.
import pymatsolver
solver = pymatsolver.Pardiso(**opts)
Ainv = solver(A)
so the base class might look like:
class Base(properties.HasProperties):
check_accuracy = properties.Bool(
"check the accuracy of the solve?",
default = False
)
accuracy_tol = properties.Float(
"tolerance on the accuracy of the solver",
default=1e-6
)
def __init__(self, **kwargs):
super(Base, self).__init__(**kwargs)
def __call__(self, A):
self.A = A.tocsr()
There are a couple impacts of this within SimPEG. The one that comes to mind is:
- right now in the inversion, if a solver is not set for the data misfit, we use the same one as on the simulation, here we would likely want to make a copy of the instance, rather than re-use the same instance (so that factors are not cleared)