





"""simple docstring"""





# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile
def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )   ->str:





  """simple docstring"""


  lowerCAmelCase__     :Optional[Any]											=				multiprocessing.Manager()
  lowerCAmelCase__     :Optional[int]											=				manager.list()

  lowerCAmelCase__     :str											=				multiprocessing.Process(target=_SCREAMING_SNAKE_CASE	,  args=(check_program, result, timeout)     )
  p.start()
  p.join(timeout=timeout + 1     )
  if p.is_alive():
    p.kill()

  if not result:
    result.append('timed out'     )

  return {
      "task_id": task_id,
      "passed": result[0] == "passed",
      "result": result[0],
      "completion_id": completion_id,
  }
def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )   ->Any:





  """simple docstring"""


  with create_tempdir():
    # These system calls are needed when cleaning up tempdir.
    import os
    import shutil

    lowerCAmelCase__     :Any											=				shutil.rmtree
    lowerCAmelCase__     :Dict											=				os.rmdir
    lowerCAmelCase__     :int											=				os.chdir

    # Disable functionalities that can make destructive changes to the test.
    reliability_guard()

    # Run program.
    try:
      lowerCAmelCase__     :Optional[Any]											=				{}
      with swallow_io():
        with time_limit(_SCREAMING_SNAKE_CASE     ):
          exec(_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )
      result.append('passed'     )
    except TimeoutException:
      result.append('timed out'     )
    except BaseException as e:
      result.append(F"failed: {e}"     )

    # Needed for cleaning up.
    lowerCAmelCase__     :Optional[Any]											=				rmtree
    lowerCAmelCase__     :Union[str, Any]											=				rmdir
    lowerCAmelCase__     :Optional[int]											=				chdir
@contextlib.contextmanager
def 					__A  (_SCREAMING_SNAKE_CASE     )   ->List[str]:





  """simple docstring"""


  def signal_handler(_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     ):
    raise TimeoutException('Timed out!'     )

  signal.setitimer(signal.ITIMER_REAL	,  _SCREAMING_SNAKE_CASE     )
  signal.signal(signal.SIGALRM	,  _SCREAMING_SNAKE_CASE     )
  try:
    yield
  finally:
    signal.setitimer(signal.ITIMER_REAL	,  0     )
@contextlib.contextmanager
def 					__A  ()   ->int:





  """simple docstring"""


  lowerCAmelCase__     :Optional[Any]											=				WriteOnlyStringIO()
  with contextlib.redirect_stdout(_SCREAMING_SNAKE_CASE     ):
    with contextlib.redirect_stderr(_SCREAMING_SNAKE_CASE     ):
      with redirect_stdin(_SCREAMING_SNAKE_CASE     ):
        yield
@contextlib.contextmanager
def 					__A  ()   ->List[Any]:





  """simple docstring"""


  with tempfile.TemporaryDirectory() as dirname:
    with chdir(_SCREAMING_SNAKE_CASE     ):
      yield dirname






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       pass






class    _lowerCAmelCase  (	io.StringIO			):
       """simple docstring"""




       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         raise OSError






       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         raise OSError






       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         raise OSError






       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         return False






class    _lowerCAmelCase  (	contextlib._RedirectStream			):  # type: ignore
       """simple docstring"""




       __magic_name__	:List[Any]						    =   """stdin"""






@contextlib.contextmanager
def 					__A  (_SCREAMING_SNAKE_CASE     )   ->List[Any]:





  """simple docstring"""


  if root == ".":
    yield
    return
  lowerCAmelCase__     :Dict											=				os.getcwd()
  os.chdir(_SCREAMING_SNAKE_CASE     )
  try:
    yield
  except BaseException as exc:
    raise exc
  finally:
    os.chdir(_SCREAMING_SNAKE_CASE     )




def 					__A  (_SCREAMING_SNAKE_CASE=None     )   ->int:





  """simple docstring"""


  if maximum_memory_bytes is not None:
    import resource

    resource.setrlimit(resource.RLIMIT_AS	,  (maximum_memory_bytes, maximum_memory_bytes)     )
    resource.setrlimit(resource.RLIMIT_DATA	,  (maximum_memory_bytes, maximum_memory_bytes)     )
    if not platform.uname().system == "Darwin":
      resource.setrlimit(resource.RLIMIT_STACK	,  (maximum_memory_bytes, maximum_memory_bytes)     )

  faulthandler.disable()

  import builtins

  lowerCAmelCase__     :Union[str, Any]											=				None
  lowerCAmelCase__     :List[Any]											=				None

  import os

  lowerCAmelCase__     :Optional[Any]											=				'1'

  lowerCAmelCase__     :Optional[Any]											=				None
  lowerCAmelCase__     :List[Any]											=				None
  lowerCAmelCase__     :Optional[Any]											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :int											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :List[Any]											=				None
  lowerCAmelCase__     :Any											=				None
  lowerCAmelCase__     :Any											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :str											=				None
  lowerCAmelCase__     :str											=				None
  lowerCAmelCase__     :List[str]											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :int											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :Union[str, Any]											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Optional[int]											=				None

  import shutil

  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :str											=				None
  lowerCAmelCase__     :str											=				None

  import subprocess

  lowerCAmelCase__     :List[str]											=				None  # type: ignore

  lowerCAmelCase__     :int											=				None

  import sys

  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Union[str, Any]											=				None
  lowerCAmelCase__     :List[str]											=				None
  lowerCAmelCase__     :List[str]											=				None








'''simple docstring'''



import copy
import random

from transformers import CLIPTokenizer
class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):




      def __init__(	self			, *lowerCamelCase			, **lowerCamelCase   )				->Union[str, Any]:



         '''simple docstring'''
         super().__init__(*lowerCamelCase			, **lowerCamelCase   )
         __a					  =     {}




      def 			__UpperCamelCase				(	self			, lowerCamelCase			, *lowerCamelCase			, **lowerCamelCase   )				->Dict:



         '''simple docstring'''
         __a					  =     super().add_tokens(lowerCamelCase			, *lowerCamelCase			, **lowerCamelCase   )
         if num_added_tokens == 0:
            raise ValueError(
                F"""The tokenizer already contains the token {placeholder_token}. Please pass a different"""
                ' `placeholder_token` that is not already in the tokenizer.'   )




      def 			__UpperCamelCase				(	self			, lowerCamelCase			, *lowerCamelCase			, lowerCamelCase=1			, **lowerCamelCase   )				->List[str]:



         '''simple docstring'''
         __a					  =     []
         if num_vec_per_token == 1:
            self.try_adding_tokens(lowerCamelCase			, *lowerCamelCase			, **lowerCamelCase   )
            output.append(lowerCamelCase   )
         else:
            __a					  =     []
            for i in range(lowerCamelCase   ):
               __a					  =     placeholder_token + F"""_{i}"""
               self.try_adding_tokens(lowerCamelCase			, *lowerCamelCase			, **lowerCamelCase   )
               output.append(lowerCamelCase   )
        # handle cases where there is a new placeholder token that contains the current placeholder token but is larger
         for token in self.token_map:
            if token in placeholder_token:
               raise ValueError(
                   F"""The tokenizer already has placeholder token {token} that can get confused with"""
                   F""" {placeholder_token}keep placeholder tokens independent"""   )
         __a					  =     output




      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase=False			, lowerCamelCase=1.0   )				->int:



         '''simple docstring'''
         if isinstance(lowerCamelCase			, lowerCamelCase   ):
            __a					  =     []
            for i in range(len(lowerCamelCase   )   ):
               output.append(self.replace_placeholder_tokens_in_text(text[i]			, vector_shuffle=lowerCamelCase   )   )
            return output
         for placeholder_token in self.token_map:
            if placeholder_token in text:
               __a					  =     self.token_map[placeholder_token]
               __a					  =     tokens[: 1 + int(len(lowerCamelCase   ) * prop_tokens_to_load   )]
               if vector_shuffle:
                  __a					  =     copy.copy(lowerCamelCase   )
                  random.shuffle(lowerCamelCase   )
               __a					  =     text.replace(lowerCamelCase			, ' '.join(lowerCamelCase   )   )
         return text




      def __call__(	self			, lowerCamelCase			, *lowerCamelCase			, lowerCamelCase=False			, lowerCamelCase=1.0			, **lowerCamelCase   )				->Optional[int]:



         '''simple docstring'''
         return super().__call__(
             self.replace_placeholder_tokens_in_text(
                 lowerCamelCase			, vector_shuffle=lowerCamelCase			, prop_tokens_to_load=lowerCamelCase   )			, *lowerCamelCase			, **lowerCamelCase			, )






      def 			__UpperCamelCase				(	self			, lowerCamelCase			, *lowerCamelCase			, lowerCamelCase=False			, lowerCamelCase=1.0			, **lowerCamelCase   )				->List[Any]:



         '''simple docstring'''
         return super().encode(
             self.replace_placeholder_tokens_in_text(
                 lowerCamelCase			, vector_shuffle=lowerCamelCase			, prop_tokens_to_load=lowerCamelCase   )			, *lowerCamelCase			, **lowerCamelCase			, )