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
SolverBase
defines 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
info
and save as instance variables.
default_run_scheme(self) -> str
Returns the default method to invoke the solver.
The followings are available:
subprocess
: run as a process viasubprocess.run
function
: run as a python function
In future, we plans to make a
Solver
support multiple way to invoke.
prepare(self, message: py2dmat.Message) -> None
This is called before the solver starts
message
includes 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) -> float
This 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.run
This method is nessesary when
default_run_scheme
returns"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_scheme
returns"function"