Weird behavior corresponding to parallel comuting

Issue #37 resolved
Alireza Khorshidi created an issue

If we use a single core (cores=1), then I would expect that the method calculate_loss at Line 276 of model/init.py:

https://bitbucket.org/andrewpeterson/amp/src/089fb53e893123bccff32ebdaf905449d1a30202/model/init.py?at=master&fileviewer=file-view-default#init.py-276

is run only once. However, I am seeing that in the version v0.5 it is running eight times instead(!!), which leads to incorrect calculation of loss function and derivatives during training.

This issue seems crucial; without this being fixed, I cannot do further developments of v0.5.

Comments (4)

  1. Alireza Khorshidi reporter

    If you run the test_gaussian_neural.py (also given below), I expect that it goes through calculate_loss twice for each step of optimization, but it is going several times:

    #!/usr/bin/env python
    """Simple test of the Amp calculator, using Gaussian descriptors and neural
    network model. Randomly generates data with the EMT potential in MD
    simulations."""
    
    from ase.calculators.emt import EMT
    from ase.lattice.surface import fcc110
    from ase import Atoms, Atom
    from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
    from ase import units
    from ase.md import VelocityVerlet
    from ase.constraints import FixAtoms
    
    from amp import Amp
    from amp.descriptor.gaussian import Gaussian
    from amp.model.neuralnetwork import NeuralNetwork
    
    
    def generate_data(count):
        """Generates test or training data with a simple MD simulation."""
        atoms = fcc110('Pt', (2, 2, 1), vacuum=7.)
        adsorbate = Atoms([Atom('Cu', atoms[3].position + (0., 0., 2.5)),
                           Atom('Cu', atoms[3].position + (0., 0., 5.))])
        atoms.extend(adsorbate)
        atoms.set_constraint(FixAtoms(indices=[0, 2]))
        atoms.set_calculator(EMT())
        MaxwellBoltzmannDistribution(atoms, 300. * units.kB)
        dyn = VelocityVerlet(atoms, dt=1. * units.fs)
        newatoms = atoms.copy()
        newatoms.set_calculator(EMT())
        newatoms.get_potential_energy()
        images = [newatoms]
        for step in range(count):
            dyn.run(5)
            newatoms = atoms.copy()
            newatoms.set_calculator(EMT())
            newatoms.get_potential_energy()
            images.append(newatoms)
        return images
    
    
    def train_test():
        label = 'train_test/calc'
        train_images = generate_data(2)
    
        calc = Amp(descriptor=Gaussian(),
                   model=NeuralNetwork(),
                   label=label,
                   cores=1)
    
        calc.train(images=train_images, energy_tol=10.**10., force_tol=None)
        for image in train_images[0:2]:
            print "energy =", calc.get_potential_energy(image)
            print "forces =", calc.get_forces(image)
    
    
    if __name__ == '__main__':
        train_test()
    
  2. Alireza Khorshidi reporter

    This was my mistake. It was taking multiple steps of optimization, and not running on multiple processes.

  3. Log in to comment