Solver¶
Solver is defined as a subclass of py2dmat.solver.SolverBase
import py2dmat
class Solver(py2dmat.solver.SolverBase):
...
The following methods should be defined.
__init__(self, info: py2dmat.Info)It is required to call the constructor of the base class.
super().__init__(info)
The constructor of
SolverBasedefines the following instance variables.self.root_dir: pathlib.Path: Root directoryuse
info.base["root_dir"]
self.output_dir: pathlib.Path: Output directoryuse
info.base["output_dir"]
self.proc_dir: pathlib.Path: Working directory for each MPI processas
self.output_dir / str(mpirank)
self.work_dir: pathlib.Path: Directory where the solver is invokedsame to
self.proc_dir
Read the input parameter
infoand save as instance variables.
default_run_scheme(self) -> strReturns the default method to invoke the solver.
The followings are available:
subprocess: run as a process viasubprocess.runfunction: run as a python function
In future, we plans to make a
Solversupport multiple way to invoke.
prepare(self, message: py2dmat.Message) -> NoneThis is called before the solver starts
messageincludes an input parameterx, convert it to something to be used by the solvere.g., to generate an input file of the solver
get_results(self) -> floatThis is called after the solver finishes
Returns the result of the solver
e.g., to retrieve the result from the output file of the solver
One of the following two method should be defined:
command(self) -> List[str]Returns a command to invoke the solver
The return value will be transferred to
subprocess.runThis method is nessesary when
default_run_schemereturns"subprocess"
function(self) -> Callable[[], None]Returns a python function to invoke the solver
The return value (function) will be called immediately.
This method is nessesary when
default_run_schemereturns"function"