class_docstr: Represents a stack of images to run through.
  
  Each element of the stack contains a list of the workers who have seen the given
  image for a given model. The stack ensures that no worker will see the same image
  twice.
class_docstr_tok: ["Represents","a","stack","of","images","to","run","through",".","Each","element","of","the","stack","contains","a","list","of","the","workers","who","have","seen","the","given","image","for","a","given","model",".","The","stack","ensures","that","no","worker","will","see","the","same","image","twice","."]
docstr: "Stretch" the stack to handle the current set of models.
  
  The goal is to preserve as many existing stack entries as possible while
  matching the set of models in the stack with the new set of models in
  self.models:
  - (1) All stack entries belonging to models that are still in self.models will
  be kept
  - (2) All models not in self.models will be removed from the stack
  - (3) All models in self.models not in the stack will be added to the stack
  
  Return the new pointer value.
docstr_tok: ["``","Stretch","''","the","stack","to","handle","the","current","set","of","models",".","The","goal","is","to","preserve","as","many","existing","stack","entries","as","possible","while","matching","the","set","of","models","in","the","stack","with","the","new","set","of","models","in","self.models",":","-","(","1",")","All","stack","entries","belonging","to","models","that","are","still","in","self.models","will","be","kept","-","(","2",")","All","models","not","in","self.models","will","be","removed","from","the","stack","-","(","3",")","All","models","in","self.models","not","in","the","stack","will","be","added","to","the","stack","Return","the","new","pointer","value","."]
code: def stretch_stack(self) -> int:
      """
      "Stretch" the stack to handle the current set of models.
  
      The goal is to preserve as many existing stack entries as possible while
      matching the set of models in the stack with the new set of models in
      self.models:
      - (1) All stack entries belonging to models that are still in self.models will
      be kept
      - (2) All models not in self.models will be removed from the stack
      - (3) All models in self.models not in the stack will be added to the stack
  
      Return the new pointer value.
      """
  
      # Stretch the stack
      existing_models = set(self.stack[0].keys())
      new_models = set(self.models)
      models_to_add = new_models.difference(existing_models)
      models_to_remove = existing_models.difference(new_models)
      print("\nStarting to stretch the stack.")
      print("Models to add: ", models_to_add)
      print("Models to remove: ", models_to_remove)
      models_to_add_list = sorted(list(models_to_add))
      for stack_idx, orig_workers_by_model in enumerate(self.stack):
          surviving_workers_by_model = {
              model: workers
              for model, workers in orig_workers_by_model.items()
              if model in new_models
          }
          new_workers_by_model = {
              model: [] for model in models_to_add_list
          }
          self.stack[stack_idx] = {
              **surviving_workers_by_model,
              **new_workers_by_model,
          }
          assert set(self.stack[stack_idx]) == new_models
  
      pointer = self.get_pointer()
  
      return pointer
  
imports: import base64
  import datetime
  import json
  import os
  import random
  import threading
  import time
  import unittest
  from io import BytesIO
  from typing import Any, Dict, Optional, Tuple
  from PIL import Image
  from parlai.core.message import Message
  from parlai.core.metrics import Metric
  from parlai.core.params import ParlaiParser
  from parlai.core.loader import load_task_module
  from parlai.crowdsourcing.utils.tests import AbstractParlAIChatTest
  from parlai.tasks.blended_skill_talk.agents import ContextGenerator
label_desc: Use image node_id 4 for calling the ImageStack obj's underlying member method code with example usage: obj.stretch_stack() and returns: pointer