Commit 6ed0710b authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Fixes for crashing tests

parent 4aacc7d9
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -716,11 +716,6 @@ class TestOverfitAPI(test_util.TensorFlowTestCase):
      evaluator = Evaluator(model, dataset, transformers, verbosity=verbosity)
      scores = evaluator.compute_model_performance([classification_metric])

    ############################################################ DEBUG
    print("scores")
    print(scores)
    ############################################################ DEBUG

    assert scores[classification_metric.name] > .9

  def test_attn_lstm_multitask_classification_overfit(self):
@@ -797,8 +792,6 @@ class TestOverfitAPI(test_util.TensorFlowTestCase):
                              classification_metric, n_trials=5,
                              n_pos=n_pos, n_neg=n_neg,
                              exclude_support=False, replace=False)
      print("scores")
      print(scores)

    # Measure performance on 0-th task.
    assert scores[0] > .9
+4 −4
Original line number Diff line number Diff line
@@ -42,8 +42,8 @@ class SequentialGraphModel(object):
    # For graphical layers, add connectivity placeholders 
    if type(layer).__name__ in ['GraphConv', 'GraphGather', 'GraphPool']:
      if (len(self.layers) > 0 and hasattr(self.layers[-1], "__name__")):
        assert (self.layers[-1].__name__ != "GraphGather",
                'Cannot use GraphConv or GraphGather layers after a GraphGather')
        assert self.layers[-1].__name__ != "GraphGather", \
                'Cannot use GraphConv or GraphGather layers after a GraphGather'
          
      self.output = layer(
          [self.output] + self.graph_topology.get_topology_placeholders())
@@ -71,7 +71,7 @@ class SequentialGraphModel(object):

class SequentialSupportGraphModel(object):
  """An analog of Keras Sequential model for test/support models."""
  def __init__(self, n_feat, max_atoms_per_mol=60):
  def __init__(self, n_feat):
    """
    Parameters
    ----------
@@ -99,7 +99,7 @@ class SequentialSupportGraphModel(object):

    # Update new value of x
    if type(layer).__name__ in ['GraphConv', 'GraphGather', 'GraphPool']:
      assert (self.bool_pre_gather, "Cannot apply graphical layers after gather.")
      assert self.bool_pre_gather, "Cannot apply graphical layers after gather."
          
      self.test = layer([self.test] + self.test_graph_topology.topology)
      self.support = layer([self.support] + self.support_graph_topology.topology)
+4 −5
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class TestGraphModels(test_util.TensorFlowTestCase):
    n_atoms = 5
    n_feat = 10
    batch_size = 3
    graph_model = SequentialGraphModel(n_atoms, n_feat, batch_size)
    graph_model = SequentialGraphModel(n_feat)
    assert len(graph_model.layers) == 0

  def test_sample_sequential_architecture(self):
@@ -40,7 +40,7 @@ class TestGraphModels(test_util.TensorFlowTestCase):
    n_atoms = 5
    n_feat = 10
    batch_size = 3
    graph_model = SequentialGraphModel(n_atoms, n_feat, batch_size)
    graph_model = SequentialGraphModel(n_feat)

    graph_model.add(GraphConv(64, activation='relu'))
    graph_model.add(BatchNormalization(epsilon=1e-5, mode=1))
@@ -60,10 +60,9 @@ class TestGraphModels(test_util.TensorFlowTestCase):
    n_test = 5
    n_support = 11 
    n_feat = 10
    nb_filter = 7
    batch_size = 3

    support_model = SequentialSupportGraphModel(n_test, n_support, n_feat)
    support_model = SequentialSupportGraphModel(n_feat)
    
    # Add layers
    support_model.add(GraphConv(64, activation='relu'))
@@ -74,7 +73,7 @@ class TestGraphModels(test_util.TensorFlowTestCase):
    support_model.add(GraphPool())

    # Apply an attention lstm layer
    support_model.join(AttnLSTMEmbedding(max_depth))
    support_model.join(AttnLSTMEmbedding(n_test, n_support, max_depth))

    # Gather Projection
    support_model.add(Dense(128, activation='relu'))
+4 −5
Original line number Diff line number Diff line
@@ -21,13 +21,12 @@ class TestGraphTopology(unittest.TestCase):
  def test_shapes(self):
    """Simple test that Graph topology placeholders have correct shapes."""
    n_atoms = 5
    n_atom_feat = 10
    n_feat = 10
    batch_size = 3
    max_deg = 6
    min_deg = 0
    topology = GraphTopology(n_atoms, n_atom_feat, batch_size)
    topology = GraphTopology(n_feat)

    assert topology.get_batch_size() == 3
    # Degrees from 1 to max_deg inclusive 
    # TODO(rbharath): Should this be 0 to max_deg inclusive?
    deg_adj_lists_placeholders = topology.get_deg_adjacency_lists_placeholders()
@@ -37,9 +36,9 @@ class TestGraphTopology(unittest.TestCase):
      # Should have shape (?, deg)
      assert deg_adj_list.get_shape()[1] == deg

    # Shape of atom_features should be (?, n_atom_feat)
    # Shape of atom_features should be (?, n_feat)
    atom_features = topology.get_atom_features_placeholder()
    assert atom_features.get_shape()[1] == n_atom_feat
    assert atom_features.get_shape()[1] == n_feat

    # Shape of deg_slice placeholder should be (max_deg+1-min_deg, 2)
    deg_slice = topology.get_deg_slice_placeholder()
+7 −7
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ class TestKerasLayers(test_util.TensorFlowTestCase):
    n_feat = 10
    nb_filter = 7
    with self.test_session() as sess:
      graph_topology = GraphTopology(n_atoms, n_feat)
      graph_topology = GraphTopology(n_feat)
      graph_conv_layer = GraphConv(nb_filter)

      X = graph_topology.get_input_placeholders()
@@ -50,7 +50,7 @@ class TestKerasLayers(test_util.TensorFlowTestCase):
    batch_size = 3
    nb_filter = 7
    with self.test_session() as sess:
      graph_topology = GraphTopology(n_atoms, n_feat)
      graph_topology = GraphTopology(n_feat)
      graph_gather_layer = GraphGather(batch_size)

      X = graph_topology.get_input_placeholders()
@@ -65,7 +65,7 @@ class TestKerasLayers(test_util.TensorFlowTestCase):
    batch_size = 3
    nb_filter = 7
    with self.test_session() as sess:
      graph_topology = GraphTopology(n_atoms, n_feat, batch_size)
      graph_topology = GraphTopology(n_feat)
      graph_pool_layer = GraphPool()

      X = graph_topology.get_input_placeholders()
@@ -85,16 +85,16 @@ class TestKerasLayers(test_util.TensorFlowTestCase):
    n_feat = 10
    nb_filter = 7
    with self.test_session() as sess:
      graph_topology_test = GraphTopology(n_test, n_feat)
      graph_topology_support = GraphTopology(n_support, n_feat)
      graph_topology_test = GraphTopology(n_feat)
      graph_topology_support = GraphTopology(n_feat)

      test = graph_topology_test.get_input_placeholders()[0]
      support = graph_topology_support.get_input_placeholders()[0]

      attn_embedding_layer = AttnLSTMEmbedding(max_depth)
      attn_embedding_layer = AttnLSTMEmbedding(n_test, n_support, max_depth)
      # Try concatenating the two lists of placeholders
      feed_dict = {test: np.zeros((n_test, n_feat)),
                   support: np.zeros((n_support, n_feat))}
      test_out, support_out = attn_embedding_layer([test, support])
      assert test_out.get_shape() == (n_test, n_feat)
      assert support_out.get_shape() == (n_support, n_feat)
      assert support_out.get_shape()[1] == (n_feat)