Commit 9af12830 authored by nd-02110114's avatar nd-02110114
Browse files

💚 fix ci

parent 976d1c3a
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class GraphData:
  --------
  >>> import numpy as np
  >>> node_features = np.random.rand(5, 10)
  >>> edge_index = np.array([[0, 1, 2, 2, 3], [1, 2, 3, 3, 4]], dtype=np.int)
  >>> edge_index = np.array([[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]], dtype=np.int)
  >>> Graph(node_features=node_features, edge_index=edge_index)
  """

@@ -64,6 +64,8 @@ class GraphData:
      raise ValueError('edge_index.dtype must be np.int')
    elif edge_index.shape[0] != 2:
      raise ValueError('The shape of edge_index is [2, num_edges].')
    elif np.max(edge_index) >= len(node_features):
      raise ValueError('edge_index contains the invalid node number.')

    if edge_features is not None:
      if isinstance(edge_features, np.ndarray) is False:
@@ -92,6 +94,10 @@ class GraphData:
    -------
    torch_geometric.data.Data
      Graph data for PyTorch Geometric

    Notes
    -----
    This method requires PyTorch Geometric to be installed.
    """
    try:
      import torch
@@ -114,15 +120,20 @@ class GraphData:
    -------
    dgl.DGLGraph
      Graph data for PyTorch Geometric

    Notes
    -----
    This method requires DGL to be installed.
    """
    try:
      import torch
      from dgl import DGLGraph
    except ModuleNotFoundError:
      raise ValueError("This function requires DGL to be installed.")

    g = DGLGraph()
    g.add_nodes(self.num_nodes)
    g.add_edges(self.edge_index[0], self.edge_index[1])
    g.add_edges(torch.from_numpy(self.edge_index[0]), torch.from_numpy(self.edge_index[1]))
    g.ndata['x'] = torch.from_numpy(self.node_features)

    if self.edge_features is not None:
@@ -144,8 +155,8 @@ class BatchGraphData(GraphData):
  >>> import numpy as np
  >>> node_features_list = np.random.rand(2, 5, 10)
  >>> edge_index_list = np.array([
  ...    [[0, 1, 2, 2, 3], [1, 2, 3, 3, 4]],
  ...    [[0, 1, 2, 2, 3], [1, 2, 3, 3, 4]],
  ...    [[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]],
  ...    [[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]],
  ... ], dtype=np.int)
  >>> graphs = [Graph(node_features, edge_index) for node_features, edge_index
  ...           in zip(node_features_list, edge_index_list)]
+2 −2
Original line number Diff line number Diff line
@@ -40,8 +40,8 @@ class CGCNNFeaturizer(MaterialStructureFeaturizer):
  >>> featurizer = CGCNNFeaturizer()
  >>> features = featurizer.featurize([structure])

  Note
  ----
  Notes
  -----
  This class requires Pymatgen to be installed.
  """

+2 −2
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ class ElementPropertyFingerprint(MaterialCompositionFeaturizer):
  >>> featurizer = ElementPropertyFingerprint()
  >>> features = featurizer.featurize([comp])

  Note
  ----
  Notes
  -----
  This class requires matminer and Pymatgen to be installed.
  """

+2 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ class SineCoulombMatrix(MaterialStructureFeaturizer):
  >>> featurizer = SineCoulombMatrix(max_atoms=2)
  >>> features = featurizer.featurize([structure])

  Note
  ----
  Notes
  -----
  This class requires matminer and Pymatgen to be installed.
  """

+16 −5
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ from deepchem.feat.graph_data import GraphData, BatchGraphData
class TestGraph(unittest.TestCase):

  def test_graph_data(self):
    num_nodes, num_node_features = 4, 32
    num_nodes, num_node_features = 5, 32
    num_edges, num_edge_features = 6, 32
    node_features = np.random.random_sample((num_nodes, num_node_features))
    edge_features = np.random.random_sample((num_edges, num_edge_features))
@@ -33,13 +33,13 @@ class TestGraph(unittest.TestCase):
    from torch_geometric.data import Data
    assert isinstance(pyg_graph, Data)

    dgl_graph = graph.to_pyg_graph()
    dgl_graph = graph.to_dgl_graph()
    from dgl import DGLGraph
    assert isinstance(dgl_graph, DGLGraph)

  def test_invalid_graph_data(self):
    with pytest.raises(ValueError):
      invalid_node_features_type = list(np.random.random_sample((5, 5)))
      invalid_node_features_type = list(np.random.random_sample((5, 32)))
      edge_index = np.array([
          [0, 1, 2, 2, 3, 4],
          [1, 2, 0, 3, 4, 0],
@@ -49,6 +49,17 @@ class TestGraph(unittest.TestCase):
          edge_index=edge_index,
      )

    with pytest.raises(ValueError):
      node_features = np.random.random_sample((5, 32))
      invalid_edge_index_shape = np.array([
          [0, 1, 2, 2, 3, 4],
          [1, 2, 0, 3, 4, 5],
      ])
      _ = GraphData(
          node_features=node_features,
          edge_index=invalid_edge_index_shape,
      )

    with pytest.raises(ValueError):
      node_features = np.random.random_sample((5, 5))
      invalid_edge_index_shape = np.array([
@@ -62,7 +73,7 @@ class TestGraph(unittest.TestCase):
      )

    with pytest.raises(TypeError):
      node_features = np.random.random_sample((5, 5))
      node_features = np.random.random_sample((5, 32))
      _ = GraphData(node_features=node_features)

  def test_batch_graph_data(self):
@@ -71,7 +82,7 @@ class TestGraph(unittest.TestCase):
    edge_index_list = [
        np.array([[0, 1], [1, 2]]),
        np.array([[0, 1, 2, 3], [1, 2, 0, 2]]),
        np.array([[0, 1, 2, 3, 4], [1, 2, 3, 4, 5]])
        np.array([[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]])
    ]

    graphs = [
Loading