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.
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
run(self, nprocs: int = 1, nthreads: int = 1) -> NoneRun the solver
Result should be saved to somewhere in order to be read by
get_resultslatere.g., save f(x) as an instance variable
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