torchdrug
torchdrug copied to clipboard
[Bug] IndexError: index 0 is out of bounds for dimension 0 with size 0
In the retrosynthesis tutorial
from torchdrug.utils import plot
for i in range(2):
sample = reaction_dataset[i]
reactant, product = sample["graph"]
reactants = reactant.connected_components()[0]
products = product.connected_components()[0]
plot.reaction(reactants, products)
gives below error
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Input In [14], in <cell line: 5>()
8 reactants = reactant.connected_components()[0]
9 products = product.connected_components()[0]
---> 10 plot.reaction(reactants, products)
File /usr/local/lib/python3.9/dist-packages/torchdrug/utils/plot.py:26, in reaction(reactants, products, save_file, figure_size, atom_map)
14 """
15 Visualize a chemical reaction.
16
(...)
23 atom_map (bool, optional): visualize atom mapping or not
24 """
25 rxn = AllChem.ChemicalReaction()
---> 26 for reactant in reactants:
27 mol = reactant.to_molecule()
28 if not atom_map:
File /usr/local/lib/python3.9/dist-packages/torchdrug/data/graph.py:1159, in PackedGraph.__next__(self)
1157 def __next__(self):
1158 if self._iter_index < self.batch_size:
-> 1159 item = self[self._iter_index]
1160 self._iter_index += 1
1161 return item
File /usr/local/lib/python3.9/dist-packages/torchdrug/data/graph.py:1458, in PackedGraph.__getitem__(self, index)
1455 index = (index,)
1457 if isinstance(index[0], int):
-> 1458 item = self.get_item(index[0])
1459 if len(index) > 1:
1460 item = item[index[1:]]
File /usr/local/lib/python3.9/dist-packages/torchdrug/data/graph.py:1378, in PackedGraph.get_item(self, index)
1376 edge_list = self.edge_list[edge_index].clone()
1377 edge_list[:, :2] -= self._offsets[edge_index].unsqueeze(-1)
-> 1378 data_dict, meta_dict = self.data_mask(node_index, edge_index, graph_index=graph_index)
1380 return self.unpacked_type(edge_list, edge_weight=self.edge_weight[edge_index], num_node=self.num_nodes[index],
1381 num_relation=self.num_relation, meta_dict=meta_dict, **data_dict)
File /usr/local/lib/python3.9/dist-packages/torchdrug/data/graph.py:1433, in PackedGraph.data_mask(self, node_index, edge_index, graph_index, include, exclude)
1431 v = v[edge_index]
1432 elif type == "graph" and graph_index is not None:
-> 1433 v = v[graph_index]
1434 elif type == "node reference" and node_index is not None:
1435 if node_mapping is None:
IndexError: index 0 is out of bounds for dimension 0 with size 0
Hi! Thanks for pointing out this issue. This bug is caused by a typo in the commit https://github.com/DeepGraphLearning/torchdrug/commit/f8d2de6fc91c1ff60a62b0279d61d1be8e1638ff, which slightly modified the data.Graph.split()
method. I've fixed this typo in the commit https://github.com/DeepGraphLearning/torchdrug/commit/5e07dd36b6f7b58532315cbd99fd2e015d12d808 and it should work now.
Thanks, @KiddoZhu, This issue is resolved with the latest commit