code: def create_cache(params):
      if "folder" not in params:
          raise Exception('Please define "folder" in "raw_data"')
      folder = params["folder"] if "folder" in params else ""
      if len(folder) == 0:
          folder = os.getcwd()
      cache_folder = (
          params["cache_folder"] if "cache_folder" in params else folder
      )
      if len(cache_folder) == 0:
          cache_folder = folder
      source_file = (
          params["source_file"] if "source_file" in params else ""
      )
      if len(source_file) == 0:
          raise Exception('"source_file" not defined!')
      total_days = (
          params["total_days"] if "total_days" in params else 27
      )
      text_file = os.path.join(folder, source_file)
      logging.info(f"loading {text_file}")
      if not os.access(text_file, os.R_OK):
          logging.warning(f"{text_file} cannot be accessed.")
          return
      for d in range(1, total_days + 1):
          pickle_file = os.path.join(
              cache_folder, f"{source_file}_{d:02}.pickle"
          )
          logging.info(f"creating cache for day {d:02}: {pickle_file}")
          queries = []
          st = time.process_time()
          with open(text_file, "r") as f:
              curr_sess = None
              curr_user = -1
              num_sess = 0
              last_click = None
              for line in f:
                  tokens = line.strip().split()
                  tlen = len(tokens)
                  if tlen == 4 and tokens[1] == "M":
                      if last_click is not None:
                          query = curr_sess[2][last_click[0]]
                          query.click(last_click[1], 10000)
                          last_click = None
                      day = int(tokens[2])
                      if day != d:
                          continue
                      num_sess += 1
                      if num_sess % 100000 == 0:
                          logging.info(
                              f"  {num_sess} session processed..."
                          )
                      if curr_sess is not None:
                          qids = set()
                          for q in curr_sess[2].values():
                              if len(q.clicks) > 0:
                                  queries.append(q)
                              elif q.query_id not in qids:
                                  queries.append(q)
                                  qids.add(q.query_id)
                          del qids
                      curr_sess = (int(tokens[0]), int(tokens[2]), {})
                      curr_user = int(tokens[3])
                  elif (
                      curr_sess is not None
                      and tlen > 4
                      and int(tokens[0]) == curr_sess[0]
                  ):
                      t = int(tokens[1])
                      if last_click is not None:
                          query = curr_sess[2][last_click[0]]
                          query.click(last_click[1], t - last_click[2])
                          last_click = None
                      if tokens[2] == "Q":
                          serp_id = int(tokens[3])
                          query_id = int(tokens[4])
                          query_terms = tuple(
                              [int(s) for s in tokens[5].split(",")]
                          )
                          results = []
                          for r in tokens[6:]:
                              rs = r.split(",")
                              results.append((int(rs[0]), int(rs[1])))
                          query = LoggedQuery(
                              curr_user, query_id, query_terms, results
                          )
                          curr_sess[2][serp_id] = query
                      elif tokens[2] == "C":
                          last_click = (
                              int(tokens[3]),
                              int(tokens[4]),
                              t,
                          )
                      else:
                          logging.warning(
                              f"unknown record type: {tokens[2]}"
                          )
          logging.info(f"  loading time: {time.process_time() - st}")
          st = time.process_time()
          try:
              with open(pickle_file, "wb") as f:
                  pickle.dump(
                      queries, f, protocol=pickle.HIGHEST_PROTOCOL
                  )
          except Exception:
              logging.error(f"{pickle_file} cannot be accessed.")
          logging.info(f"  saving time: {time.process_time() - st}")
  
imports: import argparse
  import json
  import logging
  import os
  import pickle
  import random
  import sys
  import time
  from typing import Iterable, List, Mapping, MutableMapping, Optional, Sequence, Tuple
  import numpy
  import torch
  import torch.multiprocessing
  from reagent.ope.estimators.estimator import Evaluator
  from reagent.ope.estimators.slate_estimators import DCGSlateMetric, ERRSlateMetric, FrechetDistribution, IPSEstimator, LogSample, NDCGSlateMetric, PBMEstimator, PseudoInverseEstimator, RankingDistribution, RewardDistribution, SlateContext, SlateEstimator, SlateEstimatorInput, SlateItemValues, SlateModel, SlateQuery, SlateSlots, SlateSlotValues
  from reagent.ope.utils import RunningAverage
label_desc: Use image node_id 2 for calling a global function with example usage: create_cache(params) without return types