I have been trying to use the BFGS optimizer in ASE with LAMMPS as a calculator to optimize a structure. The BFGS optimizer works fine when using a single processor (“ASE_LAMMPSRUN_COMMAND” =“mpirun -np 1 lmp_mpi”) but fails to do so (i.e., producing weird forces and energies in the optimization steps which never stop) when using multiple processor (i.e., “ASE_LAMMPSRUN_COMMAND” =“mpirun -np 2 lmp_mpi” . However, LAMMPS can calculate just the energy well using multiple processors when BFGS optimizer is not called. The LAMMPS executable are downloaded from the conda-forge channel. How can I successfully use multiple processors when performing BFGS optimization. I have provided below a snippet of the code that can reproduce what I said above.
import numpy as np
import ase
import os
from ase import Atom, Atoms
from ase import build
from ase.build import bulk
from ase.calculators.lammpsrun import LAMMPS
from ase.optimize import BFGS
os.environ["ASE_LAMMPSRUN_COMMAND"]="mpirun -np 2 lmp_mpi"
parameters = {'pair_style': 'eam/alloy',
'pair_coeff': ['* * NiAlH_jea.eam.alloy H Ni']}
files = ['NiAlH_jea.eam.alloy']
Ni = bulk('Ni', cubic=True)
#Applying small perturbation to H away from the diagonal
H = Atom('H', position=Ni.cell.diagonal()/2 + 0.001)
NiH = Ni + H
multiplier = np.identity(3) * 2
NiH_sc=ase.build.make_supercell(NiH, multiplier)
lammps = LAMMPS(parameters=parameters, files=files)
#relax the supercell
fmax=0.001
NiH_sc.calc = lammps
mininimizer=BFGS(NiH_sc)
mininimizer.run(fmax=fmax)
print("Energy ", NiH_sc.get_potential_energy())