Skip to content

Commit

Permalink
Merge branch 'main' into license
Browse files Browse the repository at this point in the history
  • Loading branch information
yomichi committed Oct 31, 2024
2 parents 6d6950f + 0a0b7a6 commit 015c7a3
Show file tree
Hide file tree
Showing 41 changed files with 1,832 additions and 211 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ jobs:
main:
strategy:
matrix:
# Python 3.6 is not supported on Ubuntu 22.04
os: ['ubuntu-22.04', 'ubuntu-20.04']
python-version: ['3.6', '3.9', '3.12']
# os: ['ubuntu-22.04']
python-version: ['3.9', '3.12']
sample: [mapper, minsearch, exchange, exchange_mesh, pamc, bayes, transform]
exclude:
- os: 'ubuntu-22.04'
python-version: '3.6'
- os: 'ubuntu-20.04'
python-version: '3.9'
- os: 'ubuntu-20.04'
python-version: '3.12'
fail-fast: false

name: ${{ matrix.sample }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
runs-on: 'ubuntu-22.04'
# runs-on: ${{ matrix.os }}
timeout-minutes: 10

steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It also offers a driver script to solve the problem with predefined optimization
### Prerequists

- Required
- python >= 3.6.8
- python >= 3.9
- numpy >= 1.14
- tomli >= 1.2.0
- Optional
Expand Down
4 changes: 2 additions & 2 deletions doc/en/source/start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Installation of ODAT-SE

Prerequisites
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Python3 (>=3.6.8)
- Python3 (>=3.9)

- The following Python packages are required.
- tomli >= 1.2
Expand All @@ -13,7 +13,7 @@ Prerequisites

- mpi4py (required for grid search)
- scipy (required for Nelder-Mead method)
- physbo (>=0.3, required for Baysian optimization)
- physbo (>=2.0, required for Baysian optimization)


How to download and install
Expand Down
4 changes: 2 additions & 2 deletions doc/ja/source/start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ODAT-SE のインストール

実行環境・必要なパッケージ
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- python 3.6.8 以上
- python 3.9 以上

- 必要なpythonパッケージ

Expand All @@ -14,7 +14,7 @@ ODAT-SE のインストール

- mpi4py (グリッド探索利用時)
- scipy (Nelder-Mead法利用時)
- physbo (ベイズ最適化利用時, ver. 0.3以上)
- physbo (ベイズ最適化利用時, ver. 2.0以上)

ダウンロード・インストール
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ packages = [
]

[tool.poetry.dependencies]
python = ">=3.6.8"
python = ">=3.9"
numpy = "^1.14"
tomli = ">=1.2"
scipy = {version = "^1", optional = true}
Expand Down
50 changes: 50 additions & 0 deletions src/odatse/_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,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 @@ -48,6 +73,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 @@ -57,6 +85,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 @@ -14,6 +14,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 @@ -26,21 +26,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 @@ -54,10 +64,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 @@ -72,7 +90,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 @@ -82,11 +100,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 @@ -96,4 +141,7 @@ def submit(
return result

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

0 comments on commit 015c7a3

Please sign in to comment.