




# 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 					lowerCamelCase__       (						A__       :					Any  ,			A__       :					Any  ,			A__       :					Optional[Any]  ,			A__       :					Dict	):





       '''simple docstring'''



       __lowerCamelCase   =						multiprocessing.Manager()
       __lowerCamelCase   =						manager.list()

       __lowerCamelCase   =						multiprocessing.Process(target=A__  ,			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 					lowerCamelCase__       (						A__       :					str  ,			A__       :					int  ,			A__       :					Optional[Any]	):





       '''simple docstring'''



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

              __lowerCamelCase   =						shutil.rmtree
              __lowerCamelCase   =						os.rmdir
              __lowerCamelCase   =						os.chdir

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

              # Run program.
              try:
                     __lowerCamelCase   =						{}
                     with swallow_io():
                            with time_limit(A__	):
                                   exec(A__  ,			A__	)
                     result.append("""passed"""	)
              except TimeoutException:
                     result.append("""timed out"""	)
              except BaseException as e:
                     result.append(f'failed: {e}'	)

              # Needed for cleaning up.
              __lowerCamelCase   =						rmtree
              __lowerCamelCase   =						rmdir
              __lowerCamelCase   =						chdir




@contextlib.contextmanager
def 					lowerCamelCase__       (						A__       :					Optional[int]	):





       '''simple docstring'''



       def signal_handler(A__       :					Tuple  ,			A__       :					Optional[Any]	):
              raise TimeoutException("""Timed out!"""	)

       signal.setitimer(signal.ITIMER_REAL  ,			A__	)
       signal.signal(signal.SIGALRM  ,			A__	)
       try:
              yield
       finally:
              signal.setitimer(signal.ITIMER_REAL  ,			0	)




@contextlib.contextmanager
def 					lowerCamelCase__       (						):





       '''simple docstring'''



       __lowerCamelCase   =						WriteOnlyStringIO()
       with contextlib.redirect_stdout(A__	):
              with contextlib.redirect_stderr(A__	):
                     with redirect_stdin(A__	):
                            yield




@contextlib.contextmanager
def 					lowerCamelCase__       (						):





       '''simple docstring'''



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





class     lowerCamelCase__(					__lowerCamelCase):
      pass





class     lowerCamelCase__(					io.StringIO):
      def 			lowerCAmelCase__						(				self: Tuple    ,       *UpperCamelCase_: List[str]    ,       **UpperCamelCase_: Union[str, Any]   ):
             raise OSError
      def 			lowerCAmelCase__						(				self: str    ,       *UpperCamelCase_: Tuple    ,       **UpperCamelCase_: Tuple   ):
             raise OSError
      def 			lowerCAmelCase__						(				self: Any    ,       *UpperCamelCase_: Optional[int]    ,       **UpperCamelCase_: List[str]   ):
             raise OSError




      def 			lowerCAmelCase__						(				self: int    ,       *UpperCamelCase_: List[str]    ,       **UpperCamelCase_: Optional[int]   ):
             return False





class     lowerCamelCase__(					contextlib._RedirectStream):  # type: ignore
      UpperCAmelCase__      :	Dict    		=   'stdin'




@contextlib.contextmanager
def 					lowerCamelCase__       (						A__       :					List[str]	):





       '''simple docstring'''



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




def 					lowerCamelCase__       (						A__       :					Optional[Any]=None	):





       '''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   =						None
       __lowerCamelCase   =						None

       import os

       __lowerCamelCase   =						"""1"""

       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None

       import shutil

       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None

       import subprocess

       __lowerCamelCase   =						None  # type: ignore

       __lowerCamelCase   =						None

       import sys

       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None
       __lowerCamelCase   =						None








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__A									=				{"configuration_ibert": ["IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "IBertConfig", "IBertOnnxConfig"]}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __A									=				[
         "IBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
         "IBertForMaskedLM",
         "IBertForMultipleChoice",
         "IBertForQuestionAnswering",
         "IBertForSequenceClassification",
         "IBertForTokenClassification",
         "IBertModel",
         "IBertPreTrainedModel",
     ]

if TYPE_CHECKING:
     from .configuration_ibert import IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, IBertConfig, IBertOnnxConfig

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_ibert import (
              IBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              IBertForMaskedLM,
              IBertForMultipleChoice,
              IBertForQuestionAnswering,
              IBertForSequenceClassification,
              IBertForTokenClassification,
              IBertModel,
              IBertPreTrainedModel,
          )

else:
     import sys

     __A									=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

