class_docstr: The evaluation interface for semi-supervised learning and transfer learning for 
  graph-level tasks with pretraining and finetuning datasets. You can refer to `the benchmark 
  code <https://github.com/divelab/DIG/tree/dig/benchmarks/sslgraph>`_ for examples of usage.
  
  Args:
      dataset (torch_geometric.data.Dataset): The graph dataset for finetuning and evaluation.
      dataset_pretrain (torch_geometric.data.Dataset): The graph dataset for pretraining.
      label_rate (float, optional): Ratio of labels to use in finetuning dataset.
          (default: :obj:`1`)
      epoch_select (string, optional): :obj:`"test_max"` or :obj:`"val_max"`.
          (default: :obj:`"test_max"`)
      n_folds (int, optional): Number of folds for evaluation. (default: :obj:`10`)
      device (int, or torch.device, optional): Device for computation. (default: :obj:`None`)
      **kwargs (optional): Training and evaluation configs in :meth:`setup_train_config`.
      
  Examples
  --------
  >>> dataset, pretrain_dataset = get_dataset("NCI1", "semisupervised")
  >>> evaluator = GraphSemisupervised(dataset, pretrain_dataset, device=0)
  >>> evaluator.evaluate(model, encoder) # semi-supervised learning
  
  >>> dataset = MoleculeNet("./transfer_data", "HIV")
  >>> pretrain_dataset = ZINC("./transfer_data")
  >>> evaluator = GraphSemisupervised(dataset, pretrain_dataset, device=0)
  >>> evaluator.evaluate(model, encoder) # transfer learning for molecule classification
  
  Note
  ----
  When using :obj:`torch_geometric.data.Dataset` without our provided :obj:`get_dataset`
  function, you may need to manually add self-loops before input to evaluator if some view 
  function requires them, such as diffusion.
class_docstr_tok: ["The","evaluation","interface","for","semi-supervised","learning","and","transfer","learning","for","graph-level","tasks","with","pretraining","and","finetuning","datasets",".","You","can","refer","to","`","the","benchmark","code","<","https",":","\/\/github.com\/divelab\/DIG\/tree\/dig\/benchmarks\/sslgraph",">","`","_","for","examples","of","usage",".","Args",":","dataset","(","torch_geometric.data.Dataset",")",":","The","graph","dataset","for","finetuning","and","evaluation",".","dataset_pretrain","(","torch_geometric.data.Dataset",")",":","The","graph","dataset","for","pretraining",".","label_rate","(","float",",","optional",")",":","Ratio","of","labels","to","use","in","finetuning","dataset",".","(","default",":",":","obj",":","`","1","`",")","epoch_select","(","string",",","optional",")",":",":","obj",":","`","``","test_max","''","`","or",":","obj",":","`","``","val_max","''","`",".","(","default",":",":","obj",":","`","``","test_max","''","`",")","n_folds","(","int",",","optional",")",":","Number","of","folds","for","evaluation",".","(","default",":",":","obj",":","`","10","`",")","device","(","int",",","or","torch.device",",","optional",")",":","Device","for","computation",".","(","default",":",":","obj",":","`","None","`",")","*","*","kwargs","(","optional",")",":","Training","and","evaluation","configs","in",":","meth",":","`","setup_train_config","`",".","Examples","--","--","--","--",">",">",">","dataset",",","pretrain_dataset","=","get_dataset","(","``","NCI1","''",",","``","semisupervised","''",")",">",">",">","evaluator","=","GraphSemisupervised","(","dataset",",","pretrain_dataset",",","device=0",")",">",">",">","evaluator.evaluate","(","model",",","encoder",")","#","semi-supervised","learning",">",">",">","dataset","=","MoleculeNet","(","``",".\/transfer_data","''",",","``","HIV","''",")",">",">",">","pretrain_dataset","=","ZINC","(","``",".\/transfer_data","''",")",">",">",">","evaluator","=","GraphSemisupervised","(","dataset",",","pretrain_dataset",",","device=0",")",">",">",">","evaluator.evaluate","(","model",",","encoder",")","#","transfer","learning","for","molecule","classification","Note","--","--","When","using",":","obj",":","`","torch_geometric.data.Dataset","`","without","our","provided",":","obj",":","`","get_dataset","`","function",",","you","may","need","to","manually","add","self-loops","before","input","to","evaluator","if","some","view","function","requires","them",",","such","as","diffusion","."]
docstr: Perform grid search on learning rate and epochs in pretraining.
  
  Args:
      learning_model: An object of a contrastive model (sslgraph.method.Contrastive) 
          or a predictive model.
      encoder (torch.nn.Module): Trainable pytorch model or list of models.
      pred_head (torch.nn.Module, optional): Prediction head. If None, will use linear 
          projection. (default: :obj:`None`)
      p_lr_lst (list, optional): List of learning rate candidates.
      p_epoch_lst (list, optional): List of epochs number candidates.
  
  :rtype: (float, float, (float, int))
code: def grid_search(
      self,
      learning_model,
      encoder,
      pred_head=None,
      fold_seed=12345,
      p_lr_lst=[0.1, 0.01, 0.001, 0.0001],
      p_epoch_lst=[20, 40, 60, 80, 100],
  ):
      r"""Perform grid search on learning rate and epochs in pretraining.
  
      Args:
          learning_model: An object of a contrastive model (sslgraph.method.Contrastive)
              or a predictive model.
          encoder (torch.nn.Module): Trainable pytorch model or list of models.
          pred_head (torch.nn.Module, optional): Prediction head. If None, will use linear
              projection. (default: :obj:`None`)
          p_lr_lst (list, optional): List of learning rate candidates.
          p_epoch_lst (list, optional): List of epochs number candidates.
  
      :rtype: (float, float, (float, int))
      """
  
      acc_m_lst = []
      acc_sd_lst = []
      paras = []
      for p_lr in p_lr_lst:
          for p_epoch in p_epoch_lst:
              self.setup_train_config(p_lr=p_lr, p_epoch=p_epoch)
              acc_m, acc_sd = self.evaluate(
                  learning_model, encoder, pred_head, fold_seed
              )
              acc_m_lst.append(acc_m)
              acc_sd_lst.append(acc_sd)
              paras.append((p_lr, p_epoch))
      idx = np.argmax(acc_m_lst)
      print(
          "Best paras: %d epoch, lr=%f, acc=%.4f"
          % (paras[idx][1], paras[idx][0], acc_m_lst[idx])
      )
  
      return acc_m_lst[idx], acc_sd_lst[idx], paras[idx]
  
imports: import copy
  import torch
  import numpy
  import torch.nn
  from tqdm import trange
  from sklearn.model_selection import StratifiedKFold
  from torch_geometric.loader import DataLoader
  from sklearn.svm import SVC
  from sklearn import preprocessing
  from sklearn.metrics import accuracy_score
  from sklearn.model_selection import GridSearchCV
label_desc: Use image node_id 4 for calling the GraphSemisupervised obj's underlying member method code with example usage: obj.grid_search(learning_model, encoder, pred_head, fold_seed, p_lr_lst, p_epoch_lst) and returns: acc_m_lst,  acc_sd_lst,  paras