Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
MLglideSolver.py
Go to the documentation of this file.
1import os
2os.environ["DGLBACKEND"] = "pytorch"
3import math
4import numpy as np
5import sys
6import torch
7import torch.nn as nn
8import torchvision
9import dgl
10import dgl.data
11import torch.nn.functional as F
12from dgl.nn import GraphConv
13import vtk
14
15# dglContainer Class
16# Linking a Machine Learning Model to the c++
17class GCN(nn.Module):
18 def __init__(self, in_feats, h_feats, num_classes):
19 super(GCN, self).__init__()
20 self.conv1 = GraphConv(in_feats, h_feats)
21 self.conv2 = GraphConv(h_feats, num_classes)
22
23 def forward(self, g, in_feat):
24 h = self.conv1(g, in_feat)
25 h = F.relu(h)
26 h = self.conv2(g, h)
27 return h
28
29 def passing(self):
30 src_ids = torch.tensor([1, 2, 3, 4]) # Source nodes for edges
31 dst_ids = torch.tensor([0, 1, 2, 3]) # Destination nodes for edges
32 g2 = dgl.graph((src_ids, dst_ids))
33 l = torch.randn(5,5)
34 g2 = dgl.add_self_loop(g2)
35 return self.forward(g2,l)
36
38 graph = GCN(5, 16, 2) #Create the model with given dimensions
39 return graph
40
41
42# MultContainer Class
43def mult(A,B):
44 result = np.matmul(A,B)
45 return result
46
forward(self, g, in_feat)
__init__(self, in_feats, h_feats, num_classes)