26snd =
np.array([1, 2, 3, 4, 2, 3, 4, 3, 4, 4, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3], dtype=
"int64")
27rec =
np.array([0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 1, 2, 3, 4, 2, 3, 4, 3, 4, 4], dtype=
"int64")
41def get_graph_data_dict(num_nodes, num_edges, NODE_FEATURE_SIZE=2, EDGE_FEATURE_SIZE=2, GLOBAL_FEATURE_SIZE=1):
55 for _
in range(NUM_LAYERS):
57 num_inputs = LATENT_SIZE
65 def __init__(self, num_node_inputs, num_edge_inputs, num_global_inputs):
71 def forward(self, node_data, edge_data, global_data):
72 return self.node_fn(node_data), self.edge_fn(edge_data), self.global_fn(global_data)
80 def __init__(self, num_node_inputs, num_edge_inputs, num_global_inputs):
82 self.edge_fn =
make_mlp_model(num_edge_inputs + 2 * num_node_inputs + num_global_inputs,
True)
83 self.node_fn =
make_mlp_model(LATENT_SIZE + num_node_inputs + num_global_inputs,
True)
84 self.global_fn =
make_mlp_model(2 * LATENT_SIZE + num_global_inputs,
True)
86 def forward(self, node_data, edge_data, global_data, receivers, senders):
90 [edge_data, node_data[receivers], node_data[senders],
global_data.expand(n_edges, -1)], dim=1
92 edge_output = self.edge_fn(edge_input)
98 node_output = self.node_fn(node_input)
102 global_output = self.global_fn(global_input)
103 return node_output, edge_output, global_output
111 self._core =
MLPGraphNetwork(2 * LATENT_SIZE, 2 * LATENT_SIZE, 2 * LATENT_SIZE)
115 def forward(self, node_data, edge_data, global_data, receivers, senders, num_processing_steps):
116 latent = self._encoder(node_data, edge_data, global_data)
119 for _
in range(num_processing_steps):
121 latent = self._core(*core_input, receivers, senders)
122 decoded_op = self._decoder(*latent)
141 input_names = [
"node_data",
"edge_data",
"global_data"]
143 sample_input += sample_indices
144 input_names += [
"receivers",
"senders"]
149 input_names=input_names,
150 output_names=[
"node_output",
"edge_output",
"global_output"],
162for name
in [
"gnn_encoder",
"gnn_core",
"gnn_decoder",
"gnn_output_transform"]:
168gen_code =
"""#pragma cling optimize(2)
169#include "gnn_encoder.hxx"
170#include "gnn_core.hxx"
171#include "gnn_decoder.hxx"
172#include "gnn_output_transform.hxx"
194 def infer(self, graphData):
195 n_nodes =
len(graphData[
"nodes"])
196 n_edges =
len(graphData[
"edges"])
204 latent = self._as_arrays(
205 self.encoder_session.
infer(
c(graphData[
"nodes"]),
c(graphData[
"edges"]),
c(graphData[
"globals"])),
210 for _
in range(processing_steps):
212 latent = self._as_arrays(
213 self.core_session.
infer(
c(core_input[0]),
c(core_input[1]),
c(core_input[2]), receivers, senders),
216 decoded = self._as_arrays(
217 self.decoder_session.
infer(
c(latent[0]),
c(latent[1]),
c(latent[2])), n_nodes, n_edges
221 self.output_transform_session.
infer(
c(decoded[0]),
c(decoded[1]),
c(decoded[2])),
245hG =
ROOT.TH1D(
"hG",
"Result from PyTorch", 20, 1, 0)
247for i
in range(numevts):
253print(
"elapsed time for ", numevts,
"events = ", end - start)
256hS =
ROOT.TH1D(
"hS",
"Result from SOFIE", 20, 1, 0)
260print(
"time to create SOFIE GNN class", start - start0)
262for i
in range(numevts):
268print(
"elapsed time for ", numevts,
"events = ", end - start)
279hDn =
ROOT.TH1D(
"hDn",
"Difference for node data", 40, 1, 0)
280hDe =
ROOT.TH1D(
"hDe",
"Difference for edge data", 40, 1, 0)
281hDg =
ROOT.TH1D(
"hDg",
"Difference for global data", 40, 1, 0)
284for i
in range(numevts):
285 for hist, j
in [(hDn, 0), (hDe, 1), (hDg, 2)]:
286 difference = sofieOutput[i][1][j] - torchOutput[i][1][j]
289 maxDifference = max(maxDifference,
np.abs(difference).max())
291print(
"maximum difference between SOFIE and PyTorch = ", maxDifference)
292if maxDifference > 1e-4:
293 raise RuntimeError(
"SOFIE and PyTorch outputs disagree")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len