Skip to content

Commit

Permalink
Merge pull request #265 from nlesc-nano/PA-ARMC2
Browse files Browse the repository at this point in the history
BUG: Fix PA-ARMC not correctly reshaping the acceptance array
  • Loading branch information
BvB93 committed Jan 31, 2022
2 parents 8907845 + 789f459 commit 933242f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 14 additions & 14 deletions FOX/armc/armc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import os
from pathlib import Path
from collections import abc
from itertools import repeat
from typing import (
Tuple, TYPE_CHECKING, Any, Optional, Iterable, Mapping, Callable,
overload, Dict, List, ClassVar
overload, Dict, List, ClassVar, Collection
)

import h5py
Expand All @@ -47,7 +47,7 @@
PesMapping = Mapping[str, ArrayOrScalar]

MolList = List[MultiMolecule]
MolIter = Iterable[MultiMolecule]
MolCollection = Collection[MultiMolecule]

Key = Tuple[float, ...]

Expand Down Expand Up @@ -323,15 +323,15 @@ def _do_inner4(self, accept: bool, error_change: float, aux_new: np.ndarray,
self[key_old] = self.apply_phi(self[key_old])
return key_old

def _do_inner5(self, mol_list: Optional[MolIter], accept: bool,
def _do_inner5(self, mol_list: Optional[MolCollection], accept: bool,
aux_new: np.ndarray, aux_validation: np.ndarray,
pes_new: PesMapping, pes_validation: PesMapping,
kappa: int, omega: int) -> None:
"""Export the results to HDF5."""
self.to_hdf5(mol_list, accept, aux_new, aux_validation,
pes_new, pes_validation, kappa, omega)

not_accept = ~np.array(accept, ndmin=1, dtype=bool, copy=False)
not_accept = ~np.full_like(self.param.param_old.columns, accept, dtype=np.bool_)
self.param.param.loc[:, not_accept] = self.param.param_old.loc[:, not_accept]

@property
Expand Down Expand Up @@ -363,8 +363,8 @@ def _get_first_key(self, idx: int = 0) -> Key:
self.param.param_old[idx] = self.param.param[idx]
return key

def to_hdf5(self, mol_list: Optional[MolIter],
accept: bool, aux_new: np.ndarray, aux_validation: np.ndarray,
def to_hdf5(self, mol_list: Optional[MolCollection],
accept: np.bool_, aux_new: np.ndarray, aux_validation: np.ndarray,
pes_new: PesMapping, pes_validation: PesMapping,
kappa: int, omega: int) -> None:
r"""Construct a dictionary with the **hdf5_kwarg** and pass it to :func:`.to_hdf5`.
Expand Down Expand Up @@ -397,14 +397,14 @@ def to_hdf5(self, mol_list: Optional[MolIter],
self.logger.info(f"Exporting results to {os.path.basename(self.hdf5_file)!r}\n")

phi = self.phi.phi
if not isinstance(accept, abc.Iterable):
param_key: Literal['param', 'param_old'] = 'param' if accept else 'param_old'
aux_error_mod = np.append(getattr(self.param, param_key).values, phi)
if accept.size == 1:
iterator = repeat(('param' if accept else 'param_old'), len(self.param.param.columns))
else:
_aux_error_mod = [getattr(self.param, 'param' if acc else 'param_old')[i].values for
i, acc in enumerate(accept)]
aux_error_mod = np.append(_aux_error_mod, phi)
aux_error_mod.shape = len(self.phi), -1
iterator = ('param' if acc else 'param_old' for acc in accept)
_aux_error_mod = [getattr(self.param, n)[i].values for i, n in enumerate(iterator)]
aux_error_mod = np.empty((len(self.param.param.columns), 1 + len(_aux_error_mod[0])))
aux_error_mod[..., :-1] = _aux_error_mod
aux_error_mod[..., -1] = phi

hdf5_kwarg = {
'param': self.param.param.values.T,
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ markers = slow: A marker for slow tests requiring external quantum-chemical pack
filterwarnings =
ignore::pandas.errors.PerformanceWarning
ignore:numpy\.ufunc size changed, may indicate binary incompatibility\. Expected [0-9]+ from C header, got [0-9]+ from PyObject:RuntimeWarning
ignore::DeprecationWarning:numpy.distutils.*
ignore:elementwise comparison failed:FutureWarning:pandas

# Define `python setup.py build_sphinx`
[build_sphinx]
Expand Down

0 comments on commit 933242f

Please sign in to comment.