Skip to content

Commit

Permalink
Reintegrate nprocs_for_ntasks in relax_scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Nov 30, 2023
1 parent 674ad48 commit e203ce4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 32 deletions.
21 changes: 4 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ in the `anaconda howto <http://abinit.github.io/abipy/installation#anaconda-howt
Developmental version
---------------------

Getting the developmental version of AbiPy is easy.
To install the developmental version of AbiPy with pip, use::

pip install git+https://github.com/abinit/abipy.git@develop

Clone the `github repository <https://github.com/abinit/abipy>`_ with::

git clone https://github.com/abinit/abipy
Expand Down Expand Up @@ -143,22 +146,6 @@ or alternately::
to install the package in developmental mode.
This is the recommended approach, especially if you are planning to implement new features.

Note, however, that the developmental version of AbiPy is kept in sync with the
developmental version of pymatgen thus ```python setup.py develop``` may
try to download new versions from the PyPi portal and then fail with e.g. the error message::

...
processing dependencies for abipy==0.6.0.dev0
error: scipy 1.0.0 is installed but scipy>=1.0.1 is required by {'pymatgen'}

due to inconsistent dependencies.
To solve the problem, use conda to update scipy to a version >= 1.0.1 with::

conda install "scipy>=1.0.1"

then issue again python setup.py develop. If this fails, supposing you were upgrading abipy inside
an already existing conda environment, try to restart by creating from scratch a fresh conda environment, see above.

Also note that the BLAS/Lapack libraries provided by conda have multithreading support activated by default.
Each process will try to use all of the cores on your machine, which quickly overloads things
if there are multiple processes running.
Expand Down
8 changes: 0 additions & 8 deletions abipy/ml/ml_phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
Phonopy = None



def cprint_traceback(color="red") -> None:
"""Print traceback."""
import traceback
Expand Down Expand Up @@ -110,9 +109,6 @@ def __init__(self, ddb_filepath,
prefix: Prefix for workdir
supercell: with supercell dimensions. None to use the supercell from the DDB file.
"""
# Store args for reconstruction
#self.init_kwargs = {k: v for k, v in locals().items() if k not in ["self", "__class__", "kwargs"]}

super().__init__(workdir, prefix)

self.distance = float(distance)
Expand Down Expand Up @@ -284,7 +280,6 @@ def _run_nn_name(self, nn_name: str) -> None:
for q_list, w_list, eig_list in zip(bands_dict['qpoints'], bands_dict['frequencies'], bands_dict['eigenvectors']):
nqpt += len(q_list)
py_phfreqs.extend(w_list)
#print(eig_list)
py_displ_cart.extend(eig_list)

py_phfreqs = np.reshape(py_phfreqs, (nqpt, 3*natom)) / abu.eV_to_THz
Expand Down Expand Up @@ -347,9 +342,6 @@ def __init__(self, structure, supercell,
workdir: Working directory, None to generate temporary directory automatically.
prefix: Prefix for workdir.
"""
# Store args for reconstruction
#self.init_kwargs = {k: v for k, v in locals().items() if k not in ["self", "__class__", "kwargs"]}

super().__init__(workdir, prefix)

self.initial_atoms = structure.to_ase_atoms()
Expand Down
22 changes: 21 additions & 1 deletion abipy/ml/relax_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,27 @@
from abipy.tools.serialization import HasPickleIO
from abipy.tools.printing import print_dataframe
from abipy.ml.aseml import (relax_atoms, get_atoms, as_calculator, ase_optimizer_cls, RX_MODE, fix_atoms,
MlNeb, MlGsList, CalcBuilder, make_ase_neb, nprocs_for_ntasks)
MlNeb, MlGsList, CalcBuilder, make_ase_neb)



def nprocs_for_ntasks(nprocs, ntasks, title=None) -> int:
"""
Return the number of procs to be used in a multiprocessing Pool.
If negative or None, use all procs in the system.
"""
import os
if nprocs is None or nprocs <= 0:
nprocs = max(1, os.cpu_count())
else:
nprocs = int(nprocs)

nprocs = min(nprocs, ntasks)
if title is not None:
print(title)
print(f"Using multiprocessing pool with {nprocs=} for {ntasks=} ...")
return nprocs



@dataclasses.dataclass
Expand Down
15 changes: 9 additions & 6 deletions abipy/scripts/abiml.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,15 +692,18 @@ def compare(ctx, filepath, nn_names,
@click.pass_context
@click.argument("filepath", type=str)
@add_nn_name_opt
@click.option('--config', default='abiml_magmoms.yml', type=click.Path(), callback=set_default, is_eager=True, expose_value=False)
def magmoms(ctx, filepath, nn_name):
@click.option('--config', default='abiml_gs.yml', type=click.Path(), callback=set_default, is_eager=True, expose_value=False)
def gs(ctx, filepath, nn_name):
"""
Compute magnetic moments with ML potential.
Compute grounde-state properties and magnetic moments with ML potential.
"""
atoms = _get_atoms_from_filepath(filepath)
atoms.calc = aseml.CalcBuilder(nn_name).get_calculator()
magmoms = atoms.get_magnetic_moments()
for ia, (atom, magmoms) in enumerate(zip(atoms, magmoms)):
calc = aseml.CalcBuilder(nn_name).get_calculator()
#magmoms = atoms.get_magnetic_moments()
from abipy.ml.aseml import AseResults
res = AseResults.from_atoms(atoms, calc=calc)

for ia, (atom, magmoms) in enumerate(zip(res.atoms, res.magmoms)):
print(atom, magmoms)

return 0
Expand Down
12 changes: 12 additions & 0 deletions abipy/scripts/abiopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ def show_examples_and_exit(err_msg=None, error_code=1):
if options.filepath.endswith(".json"):
return handle_json(options)

if options.filepath.endswith(".traj"):
return handle_ase_traj(options)

if os.path.basename(options.filepath) == "flows.db":
from abipy.flowtk.launcher import print_flowsdb_file
return print_flowsdb_file(options.filepath)
Expand Down Expand Up @@ -328,6 +331,15 @@ def show_examples_and_exit(err_msg=None, error_code=1):
return 0


def handle_ase_traj(options):
"""Handle ASE trajectory file."""
from ase.io import read
traj = read(options.filepath, index=":")
print(f"ASE trajectory with {len(traj)} configurations")
from abipy.ml.aseml import AseResults
first, last = AseResults(traj[0]), AseResults(traj[-1])


def handle_json(options):
"""Handle JSON file."""

Expand Down

0 comments on commit e203ce4

Please sign in to comment.