





"""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



UpperCAmelCase_							:					dict[str, float]		 =   {
    "joule": 1.0,
    "kilojoule": 1_000,
    "megajoule": 1_000_000,
    "gigajoule": 1_000_000_000,
    "wattsecond": 1.0,
    "watthour": 3_600,
    "kilowatthour": 3_600_000,
    "newtonmeter": 1.0,
    "calorie_nutr": 4_186.8,
    "kilocalorie_nutr": 4_186_800.00,
    "electronvolt": 1.6_0217_6634e-19,
    "britishthermalunit_it": 1_055.05_585,
    "footpound": 1.35_5818,
}
def 							__SCREAMING_SNAKE_CASE     (   a__    :   str			,a__    :   str			,a__    :   float       )					->				float:
	if to_type not in ENERGY_CONVERSION or from_type not in ENERGY_CONVERSION:
		__A :			Optional[int]		    =			(
		    f"""Incorrect 'from_type' or 'to_type' value: {from_type!r}, {to_type!r}\n"""
		    f"""Valid values are: {", ".join(a__       )}"""
		)
		raise ValueError(a__       )
	return value * ENERGY_CONVERSION[from_type] / ENERGY_CONVERSION[to_type]


if __name__ == "__main__":
			import doctest

			doctest.testmod()





