File: tensorflow.rst

package info (click to toggle)
amp 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 8,396 kB
  • sloc: python: 9,629; f90: 3,195; makefile: 58
file content (106 lines) | stat: -rw-r--r-- 3,706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
.. _TensorFlow:

==================================
TensorFlow
==================================

Google has released an open-source version of its machine-learning software named Tensorflow, which can allow for efficient backpropagation of neural networks and utilization of GPUs for extra speed.

We have incorporated an experimental module that uses a tensorflow back-end, which may provide an acceleration particularly through access to GPU systems.
As of this writing, the tensorflow code is in flux (with version 1.0 anticipated shortly).


Dependencies
---------------------------------

This package requires google's TensorFlow 0.11.0. You can install it as shown
below for Linux::

    export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
    pip install -U --upgrade $TF_BINARY_URL

or macOS::

    export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py2-none-any.whl
    pip install -U --upgrade $TF_BINARY_URL

If you want more information, please see `tensorflow's website <https://www.tensorflow.org/versions/r0.11/get_started/os_setup#pip_installation>`_ for instructions
for installation on your system.

Example
---------------------------------

.. code-block:: python

 #!/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.tflow import NeuralNetwork


 def generate_data(count):
     """Generates test or training data with a simple MD simulation."""
     atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)
     adsorbate = Atoms([Atom('Cu', atoms[7].position + (0., 0., 2.5)),
                        Atom('Cu', atoms[7].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 - 1):
         dyn.run(50)
         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)
     convergence = {
             'energy_rmse': 0.02,
             'force_rmse': 0.02
             }

     calc = Amp(descriptor=Gaussian(),
                model=NeuralNetwork(hiddenlayers=(3, 3), convergenceCriteria=convergence),
                label=label,
                cores=1)

     calc.train(images=train_images,)
     for image in train_images:
         print "energy =", calc.get_potential_energy(image)
         print "forces =", calc.get_forces(image)


 if __name__ == '__main__':
     train_test()

Known issues
---------------------------------
- `tflow` module does not work for versions different from 0.11.0.

About
---------------------------------

This module was contributed by Zachary Ulissi (Department of Chemical Engineering, Stanford University, zulissi@gmail.com) with help, testing, and discussions from Andrew Doyle (Stanford) and the Amp development team.