




'''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 	snake_case_					(UpperCamelCase :						Any				,		UpperCamelCase :						List[Any]				,		UpperCamelCase :						Tuple				,		UpperCamelCase :						Optional[int]   ):





							'''simple docstring'''


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

							_a			  =       multiprocessing.Process(target=UpperCamelCase				,		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 	snake_case_					(UpperCamelCase :						Dict				,		UpperCamelCase :						int				,		UpperCamelCase :						List[str]   ):





							'''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(UpperCamelCase   ):
																																			exec(UpperCamelCase				,		UpperCamelCase   )
																					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 	snake_case_					(UpperCamelCase :						Optional[int]   ):





							'''simple docstring'''


							def signal_handler(UpperCamelCase :						Optional[Any]				,		UpperCamelCase :						Dict   ):
														raise TimeoutException('''Timed out!'''   )

							signal.setitimer(signal.ITIMER_REAL				,		UpperCamelCase   )
							signal.signal(signal.SIGALRM				,		UpperCamelCase   )
							try:
														yield
							finally:
														signal.setitimer(signal.ITIMER_REAL				,		0   )
@contextlib.contextmanager
def 	snake_case_					():





							'''simple docstring'''


							_a			  =       WriteOnlyStringIO()
							with contextlib.redirect_stdout(UpperCamelCase   ):
														with contextlib.redirect_stderr(UpperCamelCase   ):
																					with redirect_stdin(UpperCamelCase   ):
																												yield
@contextlib.contextmanager
def 	snake_case_					():





							'''simple docstring'''


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

class     A					(	_a					):
							pass



class     A					(	io.StringIO					):







							def      __lowerCAmelCase    (						self :						Union[str, Any]							,    *lowerCAmelCase_ :						Tuple							,    **lowerCAmelCase_ :						Optional[int]      )    ->							int:


														"""simple docstring"""


														raise OSError







							def      __lowerCAmelCase    (						self :						Optional[Any]							,    *lowerCAmelCase_ :						List[Any]							,    **lowerCAmelCase_ :						Optional[int]      )    ->							Optional[int]:


														"""simple docstring"""


														raise OSError







							def      __lowerCAmelCase    (						self :						Optional[int]							,    *lowerCAmelCase_ :						Dict							,    **lowerCAmelCase_ :						Optional[Any]      )    ->							Union[str, Any]:


														"""simple docstring"""


														raise OSError







							def      __lowerCAmelCase    (						self :						Optional[int]							,    *lowerCAmelCase_ :						Tuple							,    **lowerCAmelCase_ :						Dict      )    ->							List[Any]:


														"""simple docstring"""


														return False



class     A					(	contextlib._RedirectStream					):  # type: ignore
							lowercase_           =       'stdin'



@contextlib.contextmanager
def 	snake_case_					(UpperCamelCase :						List[Any]   ):





							'''simple docstring'''


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

def 	snake_case_					(UpperCamelCase :						List[str]=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







'''simple docstring'''


from ..utils import DummyObject, requires_backends

class     A					(	metaclass=_a					):
							lowercase_           =       ['torch', 'torchsde']







							def __init__(						self :						Optional[Any]							,    *lowerCAmelCase_ :						Any							,    **lowerCAmelCase_ :						Tuple      )    ->							Dict:


														"""simple docstring"""


														requires_backends(self							,    ['''torch''', '''torchsde''']      )







							@classmethod
							def      __lowerCAmelCase    (						cls :						Dict							,    *lowerCAmelCase_ :						Optional[int]							,    **lowerCAmelCase_ :						Optional[Any]      )    ->							int:


														"""simple docstring"""


														requires_backends(cls							,    ['''torch''', '''torchsde''']      )







							@classmethod
							def      __lowerCAmelCase    (						cls :						List[str]							,    *lowerCAmelCase_ :						str							,    **lowerCAmelCase_ :						Optional[Any]      )    ->							Any:


														"""simple docstring"""


														requires_backends(cls							,    ['''torch''', '''torchsde''']      )

