How to create a DataSet of 1000 graphs in python
I need to create a dataset of 1000 graphs. I used the following code:
data_list = []
ngraphs = 1000
for i in range(ngraphs):
      num_nodes = randint(10,500)
      num_edges = randint(10,num_nodes*(num_nodes - 1))
      f1 = np.random.randint(10, size=(num_nodes))
      f2 = np.random.randint(10,20, size=(num_nodes))
      f3 = np.random.randint(20,30, size=(num_nodes))
      f_final = np.stack((f1,f2,f3), axis=1)
      capital = 2*f1 + f2 - f3
      f1_t = torch.from_numpy(f1)
      f2_t = torch.from_numpy(f2)
      f3_t =  torch.from_numpy(f3)   
      capital_t =  torch.from_numpy(capital)
      capital_t = capital_t.type(torch.LongTensor)
      x = torch.from_numpy(f_final)
      x = x.type(torch.LongTensor)
      edge_index = torch.randint(low=0, high=num_nodes, size=(num_edges,2), dtype=torch.long)
      edge_attr  = torch.randint(low=0, high=50, size=(num_edges,1), dtype=torch.long)
      data = Data(x = x, edge_index = edge_index.t().contiguous(), y = capital_t, edge_attr=edge_attr )
      data_list.append(data)

This works. But when I run my training function as follows:
for epoch in range(1, 500):
    loss = train()
    print(f'Loss: {loss:.4f}')

I keep getting the following error:

RuntimeError                              Traceback (most recent call
last)  in ()
1 for epoch in range(1, 500):
----&gt; 2     loss = train()
3     print(f'Loss: {loss:.4f}')
5 frames /usr/local/lib/python3.7/dist-packages/torch/nn/functional.py
in linear(input, weight, bias)    1845     if
has_torch_function_variadic(input, weight):    1846         return
handle_torch_function(linear, (input, weight), input, weight,
bias=bias)
-&gt; 1847     return torch._C._nn.linear(input, weight, bias)    1848     1849
RuntimeError: expected scalar type Float but found Long

Can someone help me troubleshoot this. Or make a 1000 graph dataset that doesn't throw this error.

Change your x and y tensor into FloatTensor, since Linear layer in python only accept FloatTensor inputs
