Skip to content

Commit

Permalink
Merge branch 'update.algorithm.restart' into update.algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
aoymt committed Sep 1, 2024
2 parents 71b5982 + 9ef1756 commit 39169ba
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 35 deletions.
4 changes: 2 additions & 2 deletions doc/en/source/algorithm/bayes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ At each step of the optimization process, the values of the parameters and the c
Restart
~~~~~~~~~~~~~~~~~~~~~~
The execution mode is specified by the ``run_mode`` parameter to the ``Algorithm.main()`` method.
The execution mode is specified by the ``run_mode`` parameter to the constructor.
The operation of each mode is described as follows.
The parameter values correspond to ``--init``, ``--resume``, and ``--cont`` options of ``py2dmat`` command, respectively.

- ``"initialize"`` (default)
- ``"initial"`` (default)

The program is started from the initial state.
First, it performs the random sampling for the number of times specified by ``random_max_num_probes`` parameter.
Expand Down
4 changes: 2 additions & 2 deletions doc/en/source/algorithm/exchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ The remaining columns are the coordinates.
Restart
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The execution mode is specified by the ``run_mode`` parameter to the ``Algorithm.main()`` method.
The execution mode is specified by the ``run_mode`` parameter to the constructor.
The operation of each mode is described as follows.
The parameter values correspond to ``--init``, ``--resume``, and ``--cont`` options of ``py2dmat`` command, respectively.

- ``"initialize"`` (default)
- ``"initial"`` (default)

The program is started from the initialized state.
If the checkpointing is enabled, the intermediate states will be stored at the folloing occasions:
Expand Down
4 changes: 2 additions & 2 deletions doc/en/source/algorithm/mapper_mpi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ Below, output example is shown.
Restart
~~~~~~~~~~~~~~~~~~~~~~
The execution mode is specified by the ``run_mode`` parameter to the ``Algorithm.main()`` method.
The execution mode is specified by the ``run_mode`` parameter to the constructor.
The operation of each mode is described as follows.
The parameter values correspond to ``--init``, ``--resume``, and ``--cont`` options of ``py2dmat`` command, respectively.

- ``"initialize"`` (default)
- ``"initial"`` (default)

The program is started from the initial state.
If the checkpointing is enabled, the intermediate states will be stored at the folloing occasions:
Expand Down
4 changes: 2 additions & 2 deletions doc/en/source/algorithm/pamc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ The sixth column is the acceptance ratio of MC updates.
Restart
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The execution mode is specified by the ``run_mode`` parameter to the ``Algorithm.main()`` method.
The execution mode is specified by the ``run_mode`` parameter to the constructor.
The operation of each mode is described as follows.
The parameter values correspond to ``--init``, ``--resume``, and ``--cont`` options of ``py2dmat`` command, respectively.

- ``"initialize"`` (default)
- ``"initial"`` (default)

The program is started from the initialized state.
If the checkpointing is enabled, the intermediate states will be stored at the folloing occasions:
Expand Down
4 changes: 2 additions & 2 deletions doc/ja/source/algorithm/bayes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@
リスタート
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``Algorithm.main()`` メソッドの引数 ``run_mode`` に実行モードを指定します。
コンストラクタの引数 ``run_mode`` に実行モードを指定します。
以下はそれぞれ ``py2dmat`` コマンドの引数の ``--init``, ``--resume``, ``--cont`` に対応します。
各モードの動作は次のとおりです。

- ``"initialize"`` (デフォルト)
- ``"initial"`` (デフォルト)

初期化して実行します。
まず、ランダムサンプリングを ``random_max_num_probes`` に指定した回数だけ行います。
Expand Down
4 changes: 2 additions & 2 deletions doc/ja/source/algorithm/exchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ MPI並列を利用する場合は、あらかじめ `mpi4py <https://mpi4py.read
リスタート
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``Algorithm.main()`` メソッドの引数 ``run_mode`` に実行モードを指定します。
コンストラクタの引数 ``run_mode`` に実行モードを指定します。
以下はそれぞれ ``py2dmat`` コマンドの引数の ``--init``, ``--resume``, ``--cont`` に対応します。
各モードの動作は次のとおりです。

- ``"initialize"`` (デフォルト)
- ``"initial"`` (デフォルト)

初期化して実行します。
チェックポイント機能が有効な場合、以下のタイミングで実行時の状態をファイルに出力します。
Expand Down
4 changes: 2 additions & 2 deletions doc/ja/source/algorithm/mapper_mpi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ MPI 並列を行う場合は、 `mpi4py <https://mpi4py.readthedocs.io/en/stable
リスタート
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``Algorithm.main()`` メソッドの引数 ``run_mode`` に実行モードを指定します。
コンストラクタの引数 ``run_mode`` に実行モードを指定します。
以下はそれぞれ ``py2dmat`` コマンドの引数の ``--init``, ``--resume``, ``--cont`` に対応します。
各モードの動作は次のとおりです。

- ``"initialize"`` (デフォルト)
- ``"initial"`` (デフォルト)

初期化して実行します。
チェックポイント機能が有効な場合、以下のタイミングで実行時の状態をファイルに出力します。
Expand Down
4 changes: 2 additions & 2 deletions doc/ja/source/algorithm/pamc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ MPI 並列をする場合にはあらかじめ `mpi4py <https://mpi4py.readthedo
リスタート
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``Algorithm.main()`` メソッドの引数 ``run_mode`` に実行モードを指定します。
コンストラクタの引数 ``run_mode`` に実行モードを指定します。
以下はそれぞれ ``py2dmat`` コマンドの引数の ``--init``, ``--resume``, ``--cont`` に対応します。
各モードの動作は次のとおりです。

- ``"initialize"`` (デフォルト)
- ``"initial"`` (デフォルト)

初期化して実行します。
チェックポイント機能が有効な場合、以下のタイミングで実行時の状態をファイルに出力します。
Expand Down
4 changes: 2 additions & 2 deletions src/py2dmat/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ def main():

solver = Solver(info)
runner = py2dmat.Runner(solver, info)
alg = Algorithm(info, runner)
alg.main(run_mode=run_mode)
alg = Algorithm(info, runner, run_mode=run_mode)
result = alg.main()
11 changes: 6 additions & 5 deletions src/py2dmat/algorithm/_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ class AlgorithmBase(metaclass=ABCMeta):

@abstractmethod
def __init__(
self, info: py2dmat.Info, runner: Optional[py2dmat.Runner] = None
self,
info: py2dmat.Info,
runner: Optional[py2dmat.Runner] = None,
run_mode: str = "initial"
) -> None:
self.mpicomm = mpi.comm()
self.mpisize = mpi.size()
self.mpirank = mpi.rank()
self.timer = {"init": {}, "prepare": {}, "run": {}, "post": {}}
self.timer["init"]["total"] = 0.0
self.status = AlgorithmStatus.INIT
self.mode = None
self.mode = run_mode.lower()

# keep copy of parameters
self.info = copy.deepcopy(info.algorithm)
Expand Down Expand Up @@ -168,9 +171,7 @@ def post(self) -> Dict:
def _post(self) -> Dict:
pass

def main(self, run_mode: str = "initialize"):
self.mode = run_mode.lower()

def main(self):
time_sta = time.perf_counter()
self.prepare()
time_end = time.perf_counter()
Expand Down
6 changes: 4 additions & 2 deletions src/py2dmat/algorithm/bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class Algorithm(py2dmat.algorithm.AlgorithmBase):

def __init__(self, info: py2dmat.Info,
runner: py2dmat.Runner = None,
domain = None) -> None:
super().__init__(info=info, runner=runner)
domain = None,
run_mode: str = "initial"
) -> None:
super().__init__(info=info, runner=runner, run_mode=run_mode)

info_param = info.algorithm.get("param", {})
info_bayes = info.algorithm.get("bayes", {})
Expand Down
8 changes: 6 additions & 2 deletions src/py2dmat/algorithm/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ class Algorithm(py2dmat.algorithm.montecarlo.AlgorithmBase):

exchange_direction: bool

def __init__(self, info: py2dmat.Info, runner: py2dmat.Runner = None) -> None:
def __init__(self,
info: py2dmat.Info,
runner: py2dmat.Runner = None,
run_mode: str = "initial"
) -> None:
time_sta = time.perf_counter()

info_exchange = info.algorithm["exchange"]
nwalkers = info_exchange.get("nreplica_per_proc", 1)

super().__init__(info=info, runner=runner, nwalkers=nwalkers)
super().__init__(info=info, runner=runner, nwalkers=nwalkers, run_mode=run_mode)

self.nreplica = self.mpisize * self.nwalkers
self.input_as_beta, self.betas = read_Ts(info_exchange, numT=self.nreplica)
Expand Down
6 changes: 4 additions & 2 deletions src/py2dmat/algorithm/mapper_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class Algorithm(py2dmat.algorithm.AlgorithmBase):

def __init__(self, info: py2dmat.Info,
runner: py2dmat.Runner = None,
domain = None) -> None:
super().__init__(info=info, runner=runner)
domain = None,
run_mode: str = "initial"
) -> None:
super().__init__(info=info, runner=runner, run_mode=run_mode)

if domain and isinstance(domain, py2dmat.domain.MeshGrid):
self.domain = domain
Expand Down
6 changes: 4 additions & 2 deletions src/py2dmat/algorithm/min_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class Algorithm(py2dmat.algorithm.AlgorithmBase):

def __init__(self, info: py2dmat.Info,
runner: py2dmat.Runner = None,
domain = None) -> None:
super().__init__(info=info, runner=runner)
domain = None,
run_mode: str = "initial"
) -> None:
super().__init__(info=info, runner=runner, run_mode=run_mode)

if domain and isinstance(domain, py2dmat.domain.Region):
self.domain = domain
Expand Down
5 changes: 3 additions & 2 deletions src/py2dmat/algorithm/montecarlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ class AlgorithmBase(py2dmat.algorithm.AlgorithmBase):
def __init__(self, info: py2dmat.Info,
runner: py2dmat.Runner = None,
domain = None,
nwalkers: int = 1
nwalkers: int = 1,
run_mode: str = "initial"
) -> None:
time_sta = time.perf_counter()
super().__init__(info=info, runner=runner)
super().__init__(info=info, runner=runner, run_mode=run_mode)
self.nwalkers = nwalkers

if domain:
Expand Down
8 changes: 6 additions & 2 deletions src/py2dmat/algorithm/pamc.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ class Algorithm(py2dmat.algorithm.montecarlo.AlgorithmBase):
Fmeans: np.ndarray
Ferrs: np.ndarray

def __init__(self, info: py2dmat.Info, runner: py2dmat.Runner = None) -> None:
def __init__(self,
info: py2dmat.Info,
runner: py2dmat.Runner = None,
run_mode: str = "initial"
) -> None:
time_sta = time.perf_counter()

info_pamc = info.algorithm["pamc"]
nwalkers = info_pamc.get("nreplica_per_proc", 1)

super().__init__(info=info, runner=runner, nwalkers=nwalkers)
super().__init__(info=info, runner=runner, nwalkers=nwalkers, run_mode=run_mode)

self.verbose = True and self.mpirank == 0

Expand Down

0 comments on commit 39169ba

Please sign in to comment.