# Buggy code
def iterbatches(self, batch_size=None, epoch=0, deterministic=False, pad_batches=False):
    """Get an object that iterates over minibatches from the dataset.

    Each minibatch is returned as a tuple of four numpy arrays: (X, y,
    w, ids).

    Parameters
    ----------
    batch_size: int, optional
      Number of elements in each batch
    epoch: int, optional
      Number of epochs to walk over dataset
    deterministic: bool, optional
      If True, follow deterministic order.
    pad_batches: bool, optional
      If True, pad each batch to `batch_size`.

    Returns
    -------
    Generator which yields tuples of four numpy arrays `(X, y, w, ids)`
    """

    def iterate(dataset, batch_size, deterministic, pad_batches):
        n_samples = dataset._X.shape[0]
        if not deterministic:
            sample_perm = np.random.permutation(n_samples)
        else:
            sample_perm = np.arange(n_samples)
        if batch_size is None:
            batch_size = n_samples
        batch_idx = 0
        num_batches = np.math.ceil(n_samples / batch_size)
        while batch_idx < num_batches:
            start = batch_idx * batch_size
            end = min(n_samples, (batch_idx + 1) * batch_size)
            indices = range(start, end)
            perm_indices = sample_perm[indices]
            X_batch = dataset._X[perm_indices]
            y_batch = dataset._y[perm_indices]
            w_batch = dataset._w[perm_indices]
            ids_batch = dataset._ids[perm_indices]
            if pad_batches:
                (X_batch, y_batch, w_batch, ids_batch) = pad_batch(
                    batch_size, X_batch, y_batch, w_batch, ids_batch
                )
            batch_idx += 1
            yield (X_batch, y_batch, w_batch, ids_batch)

    return iterate(self, batch_size, deterministic, pad_batches)


# Traceback (AttributeError)
Traceback (most recent call last):
File "test_fit_on_batch.py", line 23, in <module>
model.fit_on_batch(X, y, w)
File "/Users/bharath/Code/deepchem/deepchem/models/keras_model.py", line 428, in fit_on_batch
if not self.built:
AttributeError: 'GraphConvModel' object has no attribute 'built'

# Fixed code
def iterbatches(
    self, batch_size=None, epochs=1, deterministic=False, pad_batches=False
):
    """Get an object that iterates over minibatches from the dataset.

    Each minibatch is returned as a tuple of four numpy arrays: (X, y,
    w, ids).

    Parameters
    ----------
    batch_size: int, optional
      Number of elements in each batch
    epochs: int, optional
      Number of epochs to walk over dataset
    deterministic: bool, optional
      If True, follow deterministic order.
    pad_batches: bool, optional
      If True, pad each batch to `batch_size`.

    Returns
    -------
    Generator which yields tuples of four numpy arrays `(X, y, w, ids)`
    """

    def iterate(dataset, batch_size, epochs, deterministic, pad_batches):
        n_samples = dataset._X.shape[0]
        if deterministic:
            sample_perm = np.arange(n_samples)
        if batch_size is None:
            batch_size = n_samples
        for epoch in range(epochs):
            if not deterministic:
                sample_perm = np.random.permutation(n_samples)
            batch_idx = 0
            num_batches = np.math.ceil(n_samples / batch_size)
            while batch_idx < num_batches:
                start = batch_idx * batch_size
                end = min(n_samples, (batch_idx + 1) * batch_size)
                indices = range(start, end)
                perm_indices = sample_perm[indices]
                X_batch = dataset._X[perm_indices]
                y_batch = dataset._y[perm_indices]
                w_batch = dataset._w[perm_indices]
                ids_batch = dataset._ids[perm_indices]
                if pad_batches:
                    (X_batch, y_batch, w_batch, ids_batch) = pad_batch(
                        batch_size, X_batch, y_batch, w_batch, ids_batch
                    )
                batch_idx += 1
                yield (X_batch, y_batch, w_batch, ids_batch)

    return iterate(self, batch_size, epochs, deterministic, pad_batches)