Skip to content

Commit

Permalink
Merge branch 'update.solver_module' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
aoymt committed Jun 2, 2024
2 parents 6b39cf2 + caa7801 commit 84d5bca
Show file tree
Hide file tree
Showing 122 changed files with 2,499 additions and 95 deletions.
674 changes: 674 additions & 0 deletions extra/leed/LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions extra/leed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# LEED solver module for Py2DMAT
36 changes: 36 additions & 0 deletions extra/leed/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[tool.poetry]
name = "leed"
version = "1.0-dev"
description = "LEED solver module for Py2DMAT: data-analysis software of quantum beam diffraction experiments for 2D material structure"
authors = ["2DMAT developers <[email protected]>"]
license = "GPL-3.0-or-later"

readme = "README.md"
repository = "https://github.com/issp-center-dev/py2dmat-leed"

packages = [
{ include = "leed", from = "src" }
]

[tool.poetry.dependencies]
python = ">=3.6.8"
numpy = "^1.14"
#mpi4py = {version = "^3", optional = true}
py2dmat = "^2"

#[tool.poetry.extras]
#min_search = ["scipy"]
#bayes = ["physbo"]
#exchange = ["mpi4py"]
#all = ["scipy", "mpi4py", "physbo"]

#[tool.poetry.dev-dependencies]
#black = "^22.3.0"
#pynvim = "^0.4.3"

[tool.poetry.scripts]
py2dmat-leed = "leed._main:main"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions extra/leed/src/leed/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .leed import Solver

__version__ = "1.0-dev"
68 changes: 68 additions & 0 deletions extra/leed/src/leed/_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 2DMAT -- Data-analysis software of quantum beam diffraction experiments for 2D material structure
# Copyright (C) 2020- The University of Tokyo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

from sys import exit

import py2dmat
import py2dmat.mpi
import py2dmat.util.toml

from leed import Solver

def main():
import argparse

parser = argparse.ArgumentParser(
description=(
"Data-analysis software of quantum beam "
"diffraction experiments for 2D material structure"
)
)
parser.add_argument("inputfile", help="input file with TOML format")
parser.add_argument("--version", action="version", version=py2dmat.__version__)

args = parser.parse_args()

file_name = args.inputfile
inp = {}
if py2dmat.mpi.rank() == 0:
inp = py2dmat.util.toml.load(file_name)
if py2dmat.mpi.size() > 1:
inp = py2dmat.mpi.comm().bcast(inp, root=0)
info = py2dmat.Info(inp)

algname = info.algorithm["name"]
if algname == "mapper":
from py2dmat.algorithm.mapper_mpi import Algorithm
elif algname == "minsearch":
from py2dmat.algorithm.min_search import Algorithm
elif algname == "exchange":
from py2dmat.algorithm.exchange import Algorithm
elif algname == "pamc":
from py2dmat.algorithm.pamc import Algorithm
elif algname == "bayes":
from py2dmat.algorithm.bayes import Algorithm
else:
print(f"ERROR: Unknown algorithm ({algname})")
exit(1)

solver = Solver(info)
runner = py2dmat.Runner(solver, info)
alg = Algorithm(info, runner)
alg.main()

if __name__ == "__main__":
main()
41 changes: 38 additions & 3 deletions src/py2dmat/solver/leed.py → extra/leed/src/leed/leed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,49 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

from typing import List
from typing import Dict, List
import itertools
import os
import os.path
import shutil
from distutils.dir_util import copy_tree
from pathlib import Path
import subprocess

import numpy as np

import py2dmat
from py2dmat import exception


class Solver(py2dmat.solver.SolverBase):
class Solver:
#-----
root_dir: Path
output_dir: Path
proc_dir: Path
work_dir: Path
_name: str
dimension: int
timer: Dict[str, Dict]
#-----
path_to_solver: Path

dimension: int

def __init__(self, info: py2dmat.Info):
super().__init__(info)
#-----
#super().__init__(info)
self.root_dir = info.base["root_dir"]
self.output_dir = info.base["output_dir"]
self.proc_dir = self.output_dir / str(py2dmat.mpi.rank())
self.work_dir = self.proc_dir
self._name = ""
self.timer = {"prepare": {}, "run": {}, "post": {}}
if "dimension" in info.solver:
self.dimension = info.solver["dimension"]
else:
self.dimension = info.base["dimension"]
#-----

self._name = "leed"
info_s = info.solver
Expand Down Expand Up @@ -80,6 +102,10 @@ def check_keywords(key, segment, registered_list):
)
self.input = Solver.Input(info)

@property
def name(self) -> str:
return self._name

def prepare(self, message: py2dmat.Message) -> None:
self.work_dir = self.proc_dir
for dir in [self.path_to_base_dir]:
Expand All @@ -89,6 +115,15 @@ def prepare(self, message: py2dmat.Message) -> None:
def run(self, nprocs: int = 1, nthreads: int = 1) -> None:
self._run_by_subprocess([str(self.path_to_solver)])

def _run_by_subprocess(self, command: List[str]) -> None:
with open("stdout", "w") as fi:
subprocess.run(
command,
stdout=fi,
stderr=subprocess.STDOUT,
check=True,
)

def get_results(self) -> float:
# Get R-factor
rfactor = -1.0
Expand Down
Empty file added extra/leed/tests/.placeholder
Empty file.
Loading

0 comments on commit 84d5bca

Please sign in to comment.