



# 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__						(							_SCREAMING_SNAKE_CASE       :			Dict				,     _SCREAMING_SNAKE_CASE       :			int				,     _SCREAMING_SNAKE_CASE       :			Any				,     _SCREAMING_SNAKE_CASE       :			List[Any]    ):
				"""simple docstring"""







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

				__a       =		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   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			int				,     _SCREAMING_SNAKE_CASE       :			List[str]				,     _SCREAMING_SNAKE_CASE       :			Dict    ):
				"""simple docstring"""







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

								__a       =		shutil.rmtree
								__a       =		os.rmdir
								__a       =		os.chdir

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

								# Run program.
								try:
												__a       =		{}
												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.
								__a       =		rmtree
								__a       =		rmdir
								__a       =		chdir

@contextlib.contextmanager
def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			Dict    ):
				"""simple docstring"""







				def signal_handler(_SCREAMING_SNAKE_CASE       :			int				,     _SCREAMING_SNAKE_CASE       :			str    ):
								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   lowerCAmelCase__						(							):
				"""simple docstring"""







				__a       =		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   lowerCAmelCase__						(							):
				"""simple docstring"""







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






class    SCREAMING_SNAKE_CASE			(							lowerCamelCase__					):
							pass






class    SCREAMING_SNAKE_CASE			(							io.StringIO					):





							def 						UpperCamelCase_					(   self		:		Optional[Any]      ,				*__lowercase		:		List[str]      ,				**__lowercase		:		List[str]	):

											'''simple docstring'''
											raise OSError





							def 						UpperCamelCase_					(   self		:		Optional[Any]      ,				*__lowercase		:		Union[str, Any]      ,				**__lowercase		:		List[str]	):

											'''simple docstring'''
											raise OSError





							def 						UpperCamelCase_					(   self		:		Dict      ,				*__lowercase		:		int      ,				**__lowercase		:		str	):

											'''simple docstring'''
											raise OSError







							def 						UpperCamelCase_					(   self		:		Dict      ,				*__lowercase		:		Union[str, Any]      ,				**__lowercase		:		Tuple	):

											'''simple docstring'''
											return False






class    SCREAMING_SNAKE_CASE			(							contextlib._RedirectStream					):  # type: ignore
							__lowerCamelCase	:	Optional[int]    ='stdin'



@contextlib.contextmanager
def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			List[Any]    ):
				"""simple docstring"""







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

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			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

				__a       =		None
				__a       =		None

				import os

				__a       =		"""1"""

				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None

				import shutil

				__a       =		None
				__a       =		None
				__a       =		None

				import subprocess

				__a       =		None  # type: ignore

				__a       =		None

				import sys

				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None
				__a       =		None





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCamelCase__			= {"""configuration_mbart""": ["""MBART_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MBartConfig""", """MBartOnnxConfig"""]}

try:
						if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			= ["""MBartTokenizer"""]

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			= ["""MBartTokenizerFast"""]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			= [
						    """MBART_PRETRAINED_MODEL_ARCHIVE_LIST""",
						    """MBartForCausalLM""",
						    """MBartForConditionalGeneration""",
						    """MBartForQuestionAnswering""",
						    """MBartForSequenceClassification""",
						    """MBartModel""",
						    """MBartPreTrainedModel""",
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			= [
						    """TFMBartForConditionalGeneration""",
						    """TFMBartModel""",
						    """TFMBartPreTrainedModel""",
						]

try:
						if not is_flax_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			= [
						    """FlaxMBartForConditionalGeneration""",
						    """FlaxMBartForQuestionAnswering""",
						    """FlaxMBartForSequenceClassification""",
						    """FlaxMBartModel""",
						    """FlaxMBartPreTrainedModel""",
						]


if TYPE_CHECKING:
						from .configuration_mbart import MBART_PRETRAINED_CONFIG_ARCHIVE_MAP, MBartConfig, MBartOnnxConfig

						try:
												if not is_sentencepiece_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_mbart import MBartTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_mbart_fast import MBartTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_mbart import (
												    MBART_PRETRAINED_MODEL_ARCHIVE_LIST,
												    MBartForCausalLM,
												    MBartForConditionalGeneration,
												    MBartForQuestionAnswering,
												    MBartForSequenceClassification,
												    MBartModel,
												    MBartPreTrainedModel,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_mbart import TFMBartForConditionalGeneration, TFMBartModel, TFMBartPreTrainedModel

						try:
												if not is_flax_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_flax_mbart import (
												    FlaxMBartForConditionalGeneration,
												    FlaxMBartForQuestionAnswering,
												    FlaxMBartForSequenceClassification,
												    FlaxMBartModel,
												    FlaxMBartPreTrainedModel,
												)

else:
						import sys

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