Skip to content

Commit

Permalink
Merge pull request #3 from issp-center-dev/add_doc
Browse files Browse the repository at this point in the history
add docs
  • Loading branch information
yomichi authored Oct 31, 2024
2 parents 9f4bc9a + 50acb05 commit 0a0b7a6
Show file tree
Hide file tree
Showing 36 changed files with 1,822 additions and 194 deletions.
50 changes: 50 additions & 0 deletions src/odatse/_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,43 @@


class Info:
"""
A class to represent the information structure for the data-analysis software.
"""

base: dict
algorithm: dict
solver: dict
runner: dict

def __init__(self, d: Optional[MutableMapping] = None):
"""
Initialize the Info object.
Parameters
----------
d : MutableMapping (optional)
A dictionary to initialize the Info object.
"""
if d is not None:
self.from_dict(d)
else:
self._cleanup()

def from_dict(self, d: MutableMapping) -> None:
"""
Initialize the Info object from a dictionary.
Parameters
----------
d : MutableMapping
A dictionary containing the information to initialize the Info object.
Raises
------
exception.InputError
If any required section is missing in the input dictionary.
"""
for section in ["base", "algorithm", "solver"]:
if section not in d:
raise exception.InputError(
Expand All @@ -58,6 +83,9 @@ def from_dict(self, d: MutableMapping) -> None:
)

def _cleanup(self) -> None:
"""
Reset the Info object to its default state.
"""
self.base = {}
self.base["root_dir"] = Path(".").absolute()
self.base["output_dir"] = self.base["root_dir"]
Expand All @@ -67,6 +95,28 @@ def _cleanup(self) -> None:

@classmethod
def from_file(cls, file_name, fmt="", **kwargs):
"""
Create an Info object from a file.
Parameters
----------
file_name : str
The name of the file to load the information from.
fmt : str
The format of the file (default is "").
**kwargs
Additional keyword arguments.
Returns
-------
Info
An Info object initialized with the data from the file.
Raises
------
ValueError
If the file format is unsupported.
"""
if fmt == "toml" or fnmatch(file_name.lower(), "*.toml"):
inp = {}
if mpi.rank() == 0:
Expand Down
5 changes: 5 additions & 0 deletions src/odatse/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@


def main():
"""
Main function to run the data-analysis software for quantum beam diffraction experiments
on 2D material structures. It parses command-line arguments, loads the input file,
selects the appropriate algorithm and solver, and executes the analysis.
"""
import argparse

parser = argparse.ArgumentParser(
Expand Down
58 changes: 53 additions & 5 deletions src/odatse/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,31 @@
class Run(metaclass=ABCMeta):
def __init__(self, nprocs=None, nthreads=None, comm=None):
"""
Initialize the Run class.
Parameters
----------
nprocs : int
Number of process which one solver uses
Number of processes which one solver uses.
nthreads : int
Number of threads which one solver process uses
Number of threads which one solver process uses.
comm : MPI.Comm
MPI Communicator
MPI Communicator.
"""
self.nprocs = nprocs
self.nthreads = nthreads
self.comm = comm

@abstractmethod
def submit(self, solver):
"""
Abstract method to submit a solver.
Parameters
----------
solver : object
Solver object to be submitted.
"""
pass


Expand All @@ -64,10 +74,18 @@ def __init__(self,
mapping = None,
limitation = None) -> None:
"""
Initialize the Runner class.
Parameters
----------
Solver: odatse.solver.SolverBase object
solver : odatse.solver.SolverBase
Solver object.
info : Optional[odatse.Info]
Information object.
mapping : object, optional
Mapping object.
limitation : object, optional
Limitation object.
"""
self.solver = solver
self.solver_name = solver.name
Expand All @@ -82,7 +100,7 @@ def __init__(self,
else:
# trivial mapping
self.mapping = odatse.util.mapping.TrivialMapping()

if limitation is not None:
self.limitation = limitation
elif "limitation" in info.runner:
Expand All @@ -92,11 +110,38 @@ def __init__(self,
self.limitation = odatse.util.limitation.Unlimited()

def prepare(self, proc_dir: Path):
"""
Prepare the logger with the given process directory.
Parameters
----------
proc_dir : Path
Path to the process directory.
"""
self.logger.prepare(proc_dir)

def submit(
self, x: np.ndarray, args = (), nprocs: int = 1, nthreads: int = 1
) -> float:
"""
Submit the solver with the given parameters.
Parameters
----------
x : np.ndarray
Input array.
args : tuple, optional
Additional arguments.
nprocs : int, optional
Number of processes.
nthreads : int, optional
Number of threads.
Returns
-------
float
Result of the solver evaluation.
"""
if self.limitation.judge(x):
xp = self.mapping(x)
result = self.solver.evaluate(xp, args)
Expand All @@ -106,4 +151,7 @@ def submit(
return result

def post(self) -> None:
"""
Write the logger data.
"""
self.logger.write()
Loading

0 comments on commit 0a0b7a6

Please sign in to comment.