!pip install tensorflow==2.9
!pip install git+https://github.com/Teoroo-CMC/PiNN
!wget -nv -nc https://raw.githubusercontent.com/Teoroo-CMC/PiNN_lab/master/resources/qm9_train.{yml,tfr}
Loading data
For the purpose of testing we download a subset of the QM9 dataset used in PiNN_lab.
from pinn.io import load_tfrecord, sparse_batch
dataset = load_tfrecord("qm9_train.yml").apply(sparse_batch(10))
for datum in dataset:
print({k: v.shape for k, v in datum.items()})
break
Using PiNN Layers
PiNN networks and layers are Keras Layers and Models.
To use them, you create an instance of layer, after that, the layer object can be used as a function. Each layer is initialized with different parameters and requires different input tensors, see their individual documentation for the details.
from pinn.layers import CellListNL
from pinn.networks.pinet import PILayer, PiNet
nl = CellListNL(rc=5)
for datum in dataset:
nl(datum)
break
The definition of a layer needs three parts:
__init__
defines the layer object;build
creates the necessary variables or sub-layers;call
defines how the input tensors are processed.
The build()
method is only called once when the layer is used for the first tiem (e.g. in a loop).
See below for an example definition for the PILayer
??PILayer
Using PiNN Networks
network
(Keras Models) are defined similarly, but they can be directly used to perform regression task.
By default, network
produces per-atom predictions, this can be changed by the out_pool
parameter to
get some simple per-structure predictions. In that case, the network object can be used to perform trainig directly.
def label_data(data):
# defines the label to train on
x = data
y = data['lumo']
return x, y
train = dataset.map(label_data)
pinet = PiNet(out_pool='min')
pinet.compile(optimizer='Adam', loss='MAE')
pinet.fit(train, epochs=3)
Further benchmarks
For more advanced usage you are recommended to use the Model
API to define the trainig loss, derived predicates.
For traininig potential energy surfaces, you are recommended to use pinn.models.potential_model
in combination with the command line interface (CLI).
Alternatively, see the Trainig Tips notebook to see how to run the tranining interactively in a notebook.