class_docstr: Unit testing for MolGAN basic layers
class_docstr_tok: ["Unit","testing","for","MolGAN","basic","layers"]
docstr: Check training of the basicMolGANmodel on small number of compounds.
  Due to training instability try a few times and see if it worked at least once.
  Typically it fails between 1-3 times of 10.
  This is something that needs to be addressed in future releases.
docstr_tok: ["Check","training","of","the","basicMolGANmodel","on","small","number","of","compounds",".","Due","to","training","instability","try","a","few","times","and","see","if","it","worked","at","least","once",".","Typically","it","fails","between","1-3","times","of","10",".","This","is","something","that","needs","to","be","addressed","in","future","releases","."]
code: def test_training(self):
      """
      Check training of the basicMolGANmodel on small number of compounds.
      Due to training instability try a few times and see if it worked at least once.
      Typically it fails between 1-3 times of 10.
      This is something that needs to be addressed in future releases.
      """
  
      input_file = os.path.join(
          self.current_dir, "assets/molgan_example.csv"
      )
      data = pd.read_csv(input_file)
      molecules = list(data["Molecule"])
      feat = MolGanFeaturizer()
      featurized = feat.featurize(molecules)
      dataset = NumpyDataset(
          [x.adjacency_matrix for x in featurized],
          [x.node_features for x in featurized],
      )
  
      # True will be assigned up successful training attempt
      success = False
  
      for _ in range(self.training_attempts):
          # force clear tensor flow backend
          keras_clear_session()
          # create new model
          gan = MolGAN(learning_rate=ExponentialDecay(0.001, 0.9, 5000))
  
          # to avoid flake8 E125/yapf incompatibility
          s = gan.batch_size
  
          # generate input
          def iterbatches(epochs):
              for __ in range(epochs):
                  for batch in dataset.iterbatches(
                      batch_size=s, pad_batches=True
                  ):
                      adjacency_tensor = one_hot(batch[0], gan.edges)
                      node_tesor = one_hot(batch[1], gan.nodes)
  
                      yield {
                          gan.data_inputs[0]: adjacency_tensor,
                          gan.data_inputs[1]: node_tesor,
                      }
  
          # train model
          gan.fit_gan(
              iterbatches(1000),
              generator_steps=0.2,
              checkpoint_interval=0,
          )
  
          # generate sample
          g = gan.predict_gan_generator(1000)
  
          # check how many valid molecules were created and add to list
          generated_molecules = feat.defeaturize(g)
          valid_molecules_count = len(
              list(filter(lambda x: x is not None, generated_molecules))
          )
          print(valid_molecules_count)
          if valid_molecules_count:
              success = True
              break
  
      # finally test if there was at least one valid training session
      # as the model structure improves this should become more and more strict
      assert success
  
file_path: deepchem/deepchem/models/tests/test_molgan_model.py
imports: import os
  import unittest
  import pytest
  import pandas
  from deepchem.data import NumpyDataset
  from deepchem.feat.molecule_featurizers import MolGanFeaturizer
  from deepchem.models.optimizers import ExponentialDecay
label_desc: Use image node_id 4 for calling the test_molgan_model obj's underlying member method code with example usage: obj.test_training() without return types