Amp.load for tensorflow and tests

Issue #64 resolved
andrew_peterson repo owner created an issue

Amp.load needs to be implemented for tfAmpNN. I think it now works with the Model keyword like

from amp import Amp
from amp.model.tfAmpNN import tfAmpNN
calc = Amp.load(filename='calc.amp', Model=tfAmpNN

So it would just need to be put into the importhelper to make this automatic without specifying the model.

However, it seems like there's also some bug in loading the descriptor currently:

    135 
    136         # Instantiate the descriptor and model.
--> 137         descriptor = Descriptor(**p['descriptor'])
    138         # ** sends all the key-value pairs at once.
    139         model = Model(**p['model'])

TypeError: __init__() got an unexpected keyword argument 'cutofffn'

So perhaps we need a rigorous test too.

Comments (2)

  1. Muammar El Khatib

    I think this issue was fixed in https://bitbucket.org/andrewpeterson/amp/commits/0162f31ba533. I have tested as follows:

    I modified test_gaussian_tflow.py to load the created calc.amp after training:

    diff --git a/tests/test_gaussian_tflow.py b/tests/test_gaussian_tflow.py
    index b315d22..b541717 100644
    --- a/tests/test_gaussian_tflow.py
    +++ b/tests/test_gaussian_tflow.py
    @@ -57,6 +57,11 @@ def train_test():
             print "energy =", calc.get_potential_energy(image)
             print "forces =", calc.get_forces(image)
    
    +    newtest = Amp.load('train_test/calc.amp')
    +    for image in train_images:
    +        print "new test energy =", newtest.get_potential_energy(image)
    +        print "new test forces =", newtest.get_forces(image)
    +
    
     if __name__ == '__main__':
         train_test()
    

    Then, I run the script that gives me back these:

    muammar@zarathustra
    ~/quimica_pura/posgrado/Postdoc/brown/git/amp/tests [master *]
    ± % python test_gaussian_tflow.py
    
         !10054
    
    /home/muammar/quimica_pura/posgrado/Postdoc/brown/git/ase/ase/lattice/surface.py:17:
    UserWarning: Moved to ase.build
    warnings.warn(Moved to ase.build)
    /home/muammar/.local/lib/python2.7/site-packages/tensorflow/python/ops/gradients.py:90:
    UserWarning: Converting sparse IndexedSlices to a dense Tensor of
    unknown shape. This may consume a large amount of memory.
    Converting sparse IndexedSlices to a dense Tensor of unknown shape. 
    /home/muammar/.local/lib/python2.7/site-packages/tensorflow/contrib/opt/python/training/external_optimizer.py:321:
    OptimizeWarning: Unknown solver options: factr
    result = scipy.optimize.minimize(minimize_args, *minimize_kwargs)
    energy = [ 9.07736111]
    forces = [[ -3.83176492e-04 2.14781889e-04 -1.20790582e-02]
    [ 3.83176492e-04 2.14781889e-04 -1.20790582e-02]
    [ -3.83176492e-04 -2.14781889e-04 -1.20790582e-02]
    [ 3.83176492e-04 -2.14781889e-04 -1.20790582e-02]
    [ -1.99303482e-18 -4.12424933e-18 1.17729669e-02]
    [ 2.12067127e-18 -4.67854719e-18 2.07901914e-02]
    [ -3.44518223e-18 1.83540438e-18 1.20575540e-02]
    [ 1.16546801e-18 1.04033317e-18 5.18448986e-02]
    [ 4.03904635e-20 1.60146600e-19 -4.57363166e-02]
    [ 7.39047573e-24 -5.97099550e-20 -2.41306680e-03]]
    energy = [ 9.08667946]
    forces = [[ -9.91454930e-04 -3.35907505e-04 -1.20226545e-02]
    [ 6.73661416e-04 6.72647962e-04 -1.21484203e-02]
    [ -7.65916542e-04 -2.61796755e-04 -1.20778298e-02]
    [ 3.18927050e-04 -5.30618534e-04 -1.18174432e-02]
    [ 5.42997557e-04 4.94477223e-04 1.16151422e-02]
    [ -3.48906207e-04 1.05016137e-04 1.86742935e-02]
    [ 1.18912186e-03 2.72823272e-05 1.14532392e-02]
    [ -1.09401008e-03 -2.02630654e-05 3.65402102e-02]
    [ 5.03157149e-04 -1.73501947e-04 -2.77943667e-02]
    [ -2.75795464e-05 2.26611483e-05 -2.42217351e-03]]
    new test energy = [ 9.07736111]
    new test forces = [[ -3.83176259e-04 2.14782354e-04 -1.20790573e-02]
    [ 3.83176259e-04 2.14782354e-04 -1.20790573e-02]
    [ -3.83176259e-04 -2.14782354e-04 -1.20790573e-02]
    [ 3.83176259e-04 -2.14782354e-04 -1.20790573e-02]
    [ -1.99303482e-18 -4.12424933e-18 1.17729669e-02]
    [ 2.12067106e-18 -4.67854719e-18 2.07901914e-02]
    [ -3.44518161e-18 1.83540438e-18 1.20575540e-02]
    [ 1.16546874e-18 1.04033306e-18 5.18448986e-02]
    [ 4.03904635e-20 1.60146664e-19 -4.57363166e-02]
    [ 7.39047573e-24 -5.97099550e-20 -2.41306680e-03]]
    new test energy = [ 9.08667946]
    new test forces = [[ -9.91454232e-04 -3.35906923e-04 -1.20226545e-02]
    [ 6.73661241e-04 6.72647962e-04 -1.21484213e-02]
    [ -7.65916542e-04 -2.61796755e-04 -1.20778298e-02]
    [ 3.18925740e-04 -5.30618534e-04 -1.18174432e-02]
    [ 5.42998372e-04 4.94476815e-04 1.16151432e-02]
    [ -3.48906964e-04 1.05015984e-04 1.86742954e-02]
    [ 1.18912233e-03 2.72827838e-05 1.14532392e-02]
    [ -1.09401101e-03 -2.02623032e-05 3.65402102e-02]
    [ 5.03157207e-04 -1.73501918e-04 -2.77943686e-02]
    [ -2.75795464e-05 2.26611573e-05 -2.42217351e-03]]
    

    which loads the parameters stored in calc.amp without issues.

  2. Log in to comment