{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaL4","dataSources":[{"sourceId":84795,"databundleVersionId":11281725,"sourceType":"competition"},{"sourceId":10998651,"sourceType":"datasetVersion","datasetId":6846725},{"sourceId":218890054,"sourceType":"kernelVersion"},{"sourceId":224573565,"sourceType":"kernelVersion"},{"sourceId":224600803,"sourceType":"kernelVersion"},{"sourceId":226912314,"sourceType":"kernelVersion"},{"sourceId":227170637,"sourceType":"kernelVersion"},{"sourceId":162952,"sourceType":"modelInstanceVersion","modelInstanceId":138579,"modelId":161088}],"dockerImageVersionId":30840,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true},"papermill":{"default_parameters":{},"duration":22.341371,"end_time":"2024-12-11T03:22:13.479076","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-12-11T03:21:51.137705","version":"2.6.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport time\nfrom datetime import datetime\n\nos.environ['TZ'] = 'Asia/Kolkata'\ntime.tzset()\nprint('Starting')\n\nTRUE_START_TIME = time.time()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:22.706224Z","iopub.execute_input":"2025-03-17T15:10:22.706534Z","iopub.status.idle":"2025-03-17T15:10:22.712909Z","shell.execute_reply.started":"2025-03-17T15:10:22.706509Z","shell.execute_reply":"2025-03-17T15:10:22.71223Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os \nis_interactive = False\nis_non_interactive = not is_interactive\nhide_output_and_error=\"2>&- >&-\" if is_non_interactive else \"\" \nhide_output_and_error2=\"2>&- >&-\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:22.713709Z","iopub.execute_input":"2025-03-17T15:10:22.713938Z","iopub.status.idle":"2025-03-17T15:10:22.72501Z","shell.execute_reply.started":"2025-03-17T15:10:22.713919Z","shell.execute_reply":"2025-03-17T15:10:22.724323Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!touch /kaggle/working/submission.csv\nprint('submission csv created')\nfrom time import sleep\nif is_non_interactive:sleep(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:22.726086Z","iopub.execute_input":"2025-03-17T15:10:22.726292Z","iopub.status.idle":"2025-03-17T15:10:27.853526Z","shell.execute_reply.started":"2025-03-17T15:10:22.726274Z","shell.execute_reply":"2025-03-17T15:10:27.852663Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import io\nimport shutil\nimport subprocess\nimport traceback\n\nimport pandas as pd\nimport polars as pl\n\nimport kaggle_evaluation.konwinski_prize_inference_server\n%env PIP_NO_INDEX=1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:27.854667Z","iopub.execute_input":"2025-03-17T15:10:27.854921Z","iopub.status.idle":"2025-03-17T15:10:36.28646Z","shell.execute_reply.started":"2025-03-17T15:10:27.854899Z","shell.execute_reply":"2025-03-17T15:10:36.285797Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from IPython.core.magic import register_cell_magic\n\n@register_cell_magic\ndef notify(line, cell):\n    exec(cell, globals())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:36.287189Z","iopub.execute_input":"2025-03-17T15:10:36.28782Z","iopub.status.idle":"2025-03-17T15:10:36.291137Z","shell.execute_reply.started":"2025-03-17T15:10:36.287788Z","shell.execute_reply":"2025-03-17T15:10:36.29051Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\"\"\"def start_server():\n    !python3.10 -m pip install vllm --find-links /kaggle/input/vllm-nb-na -q  2>&- >&-\n    !python3.10 -m pip install triton --find-links /kaggle/input/vllm-nb-na\n    !python3.10 -m pip uninstall pynvml -y\n    import subprocess\n    log_file = open(\"/kaggle/working/vllm_output.log\", \"w\")\n    \n    # background task\n    command = [\n        \"python3.10\", \n        \"-m\", \n        \"vllm.scripts\", \n        \"serve\",\n        model_path,\n        \"--tensor_parallel_size\", \"4\",\n        \"--gpu_memory_utilization\", \"0.9\",\n        \"--enforce_eager\",\n        \"--enable-chunked-prefill\",\n        \"--enable_prefix_caching\",\n        \"--max_model_len\", \"25000\"\n    ]\n    \n    process = subprocess.Popen(command, stdout=log_file, stderr=log_file, start_new_session=True)\n    \n    print(f\"Background process started with PID: {process.pid}\")\ndef start_server():\n    !python3.10 -m pip install lmdeploy --find-links /kaggle/input/lmdeploy-thingy -v\n    !python3.10 -m pip uninstall pynvml -y\n    \n    import subprocess\n    log_file = open(\"/kaggle/working/vllm_output.log\", \"w\")\n    \n    # background task\n    command = [\n        \"python3.10\", \n        \"-m\", \n        \"lmdeploy\", \n        \"serve\",\n        \"api_server\",\n        model_path,\n        \"--tp\", \"4\",\n        \"--server-port\", \"8000\",\n        \"--enable-prefix-caching\",\n        \"--cache-max-entry-count\", \"0.6\"\n    ]\n    \n    process = subprocess.Popen(command, stdout=log_file, stderr=log_file, start_new_session=True)\n    \n    print(f\"Background process started with PID: {process.pid}\")\"\"\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:36.291766Z","iopub.execute_input":"2025-03-17T15:10:36.291966Z","iopub.status.idle":"2025-03-17T15:10:36.310027Z","shell.execute_reply.started":"2025-03-17T15:10:36.291949Z","shell.execute_reply":"2025-03-17T15:10:36.309389Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\"\"\"setup_done = False\nSERVE = True\n!cp -r /kaggle/input/openhands-fork-offline-version/Kevin /kaggle/working\n\ndef kaggle_setup():\n    global setup_done\n    if setup_done: return\n    setup_done = True\n    \n    if SERVE: start_server()\n    \n    !dpkg -i  $(ls /kaggle/input/openhands-fork-offline-version/apt/*.deb) 2>&- >&-\n    \n    !python3.10 -m pip install poetry -q --no-index --find-links=/kaggle/input/openhands-fork-offline-version/pip \n    \n    %cd /kaggle/working/Kevin\n    \n    !python3.10 -m poetry env use python3.12\n    !python3.10 -m poetry run pip install -q setuptools --no-index --find-links /kaggle/input/openhands-fork-offline-version/poetry\n    !python3.10 -m poetry run pip install -q --no-build-isolation grpclib --no-index --find-links /kaggle/input/openhands-fork-offline-version/poetry \n    #!python3.10 -m poetry run pip install -q -r /kaggle/input/openhands-fork-offline-version/Kevin/requirements.txt --no-index --find-links /kaggle/input/openhands-fork-offline-version/poetry\n\n    if SERVE:\n        import requests\n        import time\n        try:\n            while True:\n                try:\n                    !tail -1 /kaggle/working/vllm_output.log\n                    requests.get('http://localhost:8000/v1/models')\n                    break\n                except Exception as e:\n                    print(end='.')\n                    time.sleep(30)\n        except KeyboardInterrupt:\n            print('KeyboardInterrupt')\n    \n    !git config --global init.defaultBranch main\"\"\"\nsetup_done = False\nSERVE = True\n!cp -r /kaggle/input/openhands-fork-offline-version/Kevin /kaggle/working\n\ndef kaggle_setup():\n    global setup_done\n    if setup_done: return\n    setup_done = True\n    \n    !python3.10 -m pip install lmdeploy --find-links /kaggle/input/lmdeploy-thingy -v\n    !python3.10 -m pip uninstall pynvml -y\n    \n    !dpkg -i  $(ls /kaggle/input/openhands-fork-offline-version/apt/*.deb) 2>&- >&-\n    \n    !python3.10 -m pip install poetry -q --no-index --find-links=/kaggle/input/openhands-fork-offline-version/pip \n    \n    %cd /kaggle/working/Kevin\n    \n    !python3.10 -m poetry env use python3.12\n    !python3.10 -m poetry run pip install -q setuptools --no-index --find-links /kaggle/input/openhands-fork-offline-version/poetry\n    !python3.10 -m poetry run pip install -q --no-build-isolation grpclib --no-index --find-links /kaggle/input/openhands-fork-offline-version/poetry \n    \n    !git config --global init.defaultBranch main","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:36.310642Z","iopub.execute_input":"2025-03-17T15:10:36.310843Z","iopub.status.idle":"2025-03-17T15:10:42.309606Z","shell.execute_reply.started":"2025-03-17T15:10:36.310825Z","shell.execute_reply":"2025-03-17T15:10:42.308736Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%env LOCAL_RUNTIME_MODE=1\n%env DISABLE_BROWSER=1\n%env USER=root\n%env OPENHANDS_REPO_PATH=/kaggle/working/Kevin\n%env POETRY_VIRTUALENVS_PATH=/root/.cache/pypoetry/virtualenvs\n%env POETRY_CACHE_DIR=/kaggle/working/poetry\n%env SKIP_DEPENDENCY_CHECK=1\n%env USE_PEXPECT=1\n%env DISABLE_METRICS=1\n%env SINGLE_LOG_FOLDER=1\n%env SWE_BENCH=1\n\nos.environ['PYTHONPATH'] = '/kaggle/working/Kevin:' + os.environ['PYTHONPATH']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:42.311734Z","iopub.execute_input":"2025-03-17T15:10:42.311983Z","iopub.status.idle":"2025-03-17T15:10:42.327864Z","shell.execute_reply.started":"2025-03-17T15:10:42.311961Z","shell.execute_reply":"2025-03-17T15:10:42.327215Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_path1 = '/kaggle/input/qwen2.5-coder/transformers/32b-instruct-awq/1'\nmodel_path2 = \"/kaggle/input/deepseek-r1/transformers/deepseek-r1-distill-qwen-32b/1\"\nmodel_path = model_path1\ntemperature = 0.5 if model_path == model_path2 else 0\nmodel = f'hosted_vllm/{model_path}'\nrepo_path = '/testbed'\nif is_non_interactive:\n    base_url='http://localhost:8000/v1'\n    max_iterations=100\nelse:\n    base_url='https://91fb-34-86-166-77.ngrok-free.app/v1'\n    max_iterations=25\n\nconfig=f'''\n[core]\nworkspace_base ='{repo_path}'\nruntime='local'\nmax_iterations={max_iterations}\n\n[llm]\nmodel='{model}'\nbase_url='{base_url}'\nmax_input_tokens = 62_000\ntemperature={temperature}\n# use_group='groq'\n\n[llm.groq]\nmodel='groq/deepseek-r1-distill-llama-70b'\n'''\nwith open('/kaggle/working/Kevin/config.toml', 'w') as f:\n    f.write(config)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:42.328816Z","iopub.execute_input":"2025-03-17T15:10:42.32903Z","iopub.status.idle":"2025-03-17T15:10:42.340611Z","shell.execute_reply.started":"2025-03-17T15:10:42.329012Z","shell.execute_reply":"2025-03-17T15:10:42.340014Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"instance_count = None\n\ndef get_number_of_instances(num_instances: int) -> None:\n    \"\"\" The very first message from the gateway will be the total number of instances to be served.\n    You don't need to edit this function.\n    \"\"\"\n    global instance_count\n    instance_count = num_instances","metadata":{"papermill":{"duration":0.011949,"end_time":"2024-12-11T03:22:08.838279","exception":false,"start_time":"2024-12-11T03:22:08.82633","status":"completed"},"tags":[],"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:42.341206Z","iopub.execute_input":"2025-03-17T15:10:42.341398Z","iopub.status.idle":"2025-03-17T15:10:42.352264Z","shell.execute_reply.started":"2025-03-17T15:10:42.34138Z","shell.execute_reply":"2025-03-17T15:10:42.351668Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"setup_done = 0\nkaggle_setup()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:10:42.352894Z","iopub.execute_input":"2025-03-17T15:10:42.353097Z","iopub.status.idle":"2025-03-17T15:11:19.75915Z","shell.execute_reply.started":"2025-03-17T15:10:42.353079Z","shell.execute_reply":"2025-03-17T15:11:19.758221Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.environ['PATH'] = '/testbed/.venv/bin:' + os.environ['PATH']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:11:19.759987Z","iopub.execute_input":"2025-03-17T15:11:19.760225Z","iopub.status.idle":"2025-03-17T15:11:19.763541Z","shell.execute_reply.started":"2025-03-17T15:11:19.760204Z","shell.execute_reply":"2025-03-17T15:11:19.762939Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tomlkit\ndef get_project_name():\n    try:\n        pyproject_file = '/testbed/pyproject.toml'\n    \n        with open(pyproject_file, 'r') as f:\n            pyproject = tomlkit.parse(f.read())\n    \n        project_name = pyproject['project']['name']\n        return project_name\n    except Exception as e:\n        print(e)\n        return ''\n    if not pyproject.get('tool',{}).get('uv'):\n        pyproject['tool']['uv'] = {\n            'override-dependencies': [project_name],\n            'sources': {\n                project_name: { 'workspace': True }\n            }\n        }\n\n    with open(pyproject_file, 'w') as f:\n        tomlkit.dump(pyproject, f)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:11:19.764129Z","iopub.execute_input":"2025-03-17T15:11:19.764329Z","iopub.status.idle":"2025-03-17T15:11:19.787054Z","shell.execute_reply.started":"2025-03-17T15:11:19.764311Z","shell.execute_reply":"2025-03-17T15:11:19.786488Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%env PIP_FIND_LINKS=/kaggle/input/wheels-for-kprize-instances","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:11:19.78775Z","iopub.execute_input":"2025-03-17T15:11:19.787945Z","iopub.status.idle":"2025-03-17T15:11:19.791529Z","shell.execute_reply.started":"2025-03-17T15:11:19.787928Z","shell.execute_reply":"2025-03-17T15:11:19.790923Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%env POETRY_ALIAS=python3.10 -m poetry","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:11:19.792106Z","iopub.execute_input":"2025-03-17T15:11:19.792304Z","iopub.status.idle":"2025-03-17T15:11:19.801786Z","shell.execute_reply.started":"2025-03-17T15:11:19.792287Z","shell.execute_reply":"2025-03-17T15:11:19.801172Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from lmdeploy import pipeline, GenerationConfig, TurbomindEngineConfig\nfrom lmdeploy.cli.utils import get_chat_template\n\nprint(\"Begin loading...\")\nbackend_config = TurbomindEngineConfig(tp=4, enable_prefix_caching=True, cache_max_entry_count = 0.7)\nllm = pipeline('/kaggle/input/qwen2.5-coder/transformers/32b-instruct-awq/1',\n                backend_config=backend_config)\nprint(\"Finished loading!\")\n\ngen_config_replication = GenerationConfig(do_sample=True,\n                              min_p=0.1,\n                              temperature=0.6,\n                              max_new_tokens=2500)\n\ngen_config = GenerationConfig(do_sample=True,\n                              min_p=0.1,\n                              temperature=0.6,\n                              max_new_tokens=2500)\n\ngen_config_coder = GenerationConfig(do_sample=True,\n                              min_p=0.1,\n                              temperature=0.8,\n                              max_new_tokens=2500)\ncoding_start_temp = 0.8\ncoding_temp_drop = 0.2\ncoding_end_temp = 0.2\ndef get_responses(pipeline, gen_config, oai_inputs):\n    responses = pipeline(oai_inputs, gen_config=gen_config)\n    return [response.text for response in responses]\n    \nprint(get_responses(llm, gen_config, [[{\"role\":\"user\", \"content\":\"What is 1+1*6\"}],\n                     [{\"role\":\"user\",\"content\":\"What is 7*12? Respond like a pirate?\"}],\n                     [{\"role\":\"user\",\"content\":\"Please get the weather using the get_weather tool, wrapped inside <tool> </tool> XML tool calling format.\"}]]))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:11:19.802428Z","iopub.execute_input":"2025-03-17T15:11:19.80263Z","iopub.status.idle":"2025-03-17T15:14:08.433607Z","shell.execute_reply.started":"2025-03-17T15:11:19.802613Z","shell.execute_reply":"2025-03-17T15:14:08.432873Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from collections import Counter\nimport os\nimport copy\nimport time\nimport random\nfrom typing import List\nfrom pathlib import Path\n\nfrom agent2.agent.agent import Agent\nfrom agent2.agent.tool import Tool\nfrom agent2.file import File\nfrom agent2.element import Element\nfrom agent2.utils.utils import load_project_files\nfrom agent2.utils.agent_utils import load_agent_from_json\nfrom agent2.agent.agent_state import AgentState\nfrom agent2.agent.tool_settings import ToolSettings\nimport ast\n\ndef get_n_most_common(lists, n):\n    counter = Counter()\n    for lst in lists:\n        # Since each list has no duplicates, we can safely update counts\n        for item in lst:\n            counter[item] += 1\n    # Get the n most common items, which are already unique\n    return [item for item, _ in counter.most_common(n)]\n\nsuper_secret_test_str = \"\"\nsuper_secret_project_dir = []\ndef run_test(state: AgentState, settings: ToolSettings, debug_message=\"Made edits, running code...\"):\n    \"\"\"\n    Run the issue replication script. Will error if the issue still persists, otherwise prints SUCCESS.\n    \n    Args:\n        None\n    \n    Returns:\n        The output of the issue replication script.\n    \n    Example:\n        Run the issue replication script.\n    Tool Call:\n        {\"name\": \"run_test\", \"arguments\": {}}\n    \"\"\"\n    print(debug_message)\n    # repo_path <- cwd\n    # super_secret_test_str <- the string to run\n    # super_secret_project_dir\n    for ffile in super_secret_project_dir:\n        if ffile.original_content != ffile.updated_content:\n            with open(ffile.path, 'w') as writefile:\n                writefile.write(ffile.updated_content)\n        else:\n            with open(ffile.path, 'w') as writefile:\n                writefile.write(ffile.original_content)\n    with open(\"super_special_python_file.py\", 'w') as writefile:\n        writefile.write(super_secret_test_str)\n    try:\n        result = subprocess.run(\n            \"python super_special_python_file.py\",\n            shell=True,\n            executable=\"/bin/bash\",\n            cwd=repo_path,\n            capture_output=True,\n            text=True,\n            timeout=15\n        )\n    except Exception as e:\n        return (f\"Error running code: {e}\", None, None)\n    return (\"```output\\n\" + \"\\n\".join((\"Stdout:\\n\" + result.stdout + \"\\nStderr:\\n\" + result.stderr).splitlines()[-100:])[-7000:] + \"\\n```\", None, None)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:14:08.434588Z","iopub.execute_input":"2025-03-17T15:14:08.435084Z","iopub.status.idle":"2025-03-17T15:14:22.669017Z","shell.execute_reply.started":"2025-03-17T15:14:08.435062Z","shell.execute_reply":"2025-03-17T15:14:22.668304Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"first_question = False\nalloted_time = 8*60*60\ncomp_time_alloted = 22*60*60\n\nstderr_count=0\npythonnotprint_count = 0\nnopassfail_count = 0\nallowed_fails=25\n\nsearch_turn_limit = 9 # 8\nsearch_batch = 3 # 3\n\nfail_to_fail_count = 4\n\nreplication_top_select = 8\nreplication_gurantee_refs = 3\nreplication_random_refs = 3\nreplication_batch = 25 # 25\nreplication_min_req = 8 # 8\n\nfixer_top_select = 6\nfixer_random_refs = 3\nfixer_turn_limit = 9 # 8 \nfixer_batch = 4 # 4\n\npass_to_pass_percent = 0.65\ndef predict(problem_statement: str, repo_archive: io.BytesIO, pip_packages_archive: io.BytesIO, env_setup_cmds_templates: list[str]) -> str:\n    \"\"\" Replace this function with your inference code.\n    Args:\n        problem_statement: The text of the git issue.\n        repo_path: A BytesIO buffer path with a .tar containing the codebase that must be patched. The gateway will make this directory available immediately before this function runs.\n        pip_packages_archive: A BytesIO buffer path with a .tar containing the wheel files necessary for running unit tests.\n        env_setup_cmds_templates: Commands necessary for installing the pip_packages_archive.\n    \"\"\"\n    global super_secret_test_str, super_secret_project_dir\n    global comp_time_alloted, alloted_time, stderr_count, pythonnotprint_count, nopassfail_count, first_question\n    global instance_count\n    if instance_count is not None and instance_count > 100:\n        print(instance_count)\n        alloted_time = comp_time_alloted\n    if first_question:\n        first_question = False\n        print(\"Skip first question.\")\n        return None\n    if time.time() > TRUE_START_TIME + alloted_time:\n        print(\"EARLY STOP!\")\n        return None\n    else:\n        print(time.time())\n        print(TRUE_START_TIME)\n        print(TRUE_START_TIME + alloted_time)\n\n    start_time = time.time()\n    print(f\"==== STARTING ISSUE at time {start_time} ====\")\n    print(problem_statement)\n    try:\n        print(\"==== BEGINNING ENV SETUP AND QUICK TESTING ====\")\n        \n        %cd /\n        # Unpack the codebase to be patched\n        with open('repo_archive.tar', 'wb') as f:\n            f.write(repo_archive.read())\n        if os.path.exists(repo_path):\n            shutil.rmtree(repo_path)\n        shutil.unpack_archive('repo_archive.tar', extract_dir=repo_path)\n        os.remove('repo_archive.tar')\n    \n        \"\"\"\n        Unpack pip_packages if you want to run unit tests on your patch.\n        Note that editing unit tests with your patch -- even to add valid tests -- can cause your submission to be flagged as a failure.\n        Most of the relevant repos use pytest for running tests. You will almost certainly need to run only a subset of the unit tests to avoid running out of inference time.\n        \"\"\"\n        with open('pip_packages_archive.tar', 'wb') as f:\n            f.write(pip_packages_archive.read())\n        pip_packages_path = '/path/to/pip_packages'\n        if os.path.exists(pip_packages_path):\n            shutil.rmtree(pip_packages_path)\n        shutil.unpack_archive('pip_packages_archive.tar', extract_dir=pip_packages_path)\n        os.remove('pip_packages_archive.tar')\n    \n        # Get env setup cmds by setting the pip_packages_path\n        env_setup_cmds = [cmd.format(pip_packages_path=pip_packages_path).replace('uv pip','pip').replace(' --link-mode=symlink','') for cmd in env_setup_cmds_templates[2:]]\n        project_name=get_project_name()\n        %cd $repo_path\n        !uv venv --python python3.11\n        !python -m ensurepip\n        !git init\n        !git add .\n        if project_name=='astroid':\n            !pip install pylint\n        # Run env setup for the repo\n        env_setup_cmds = \"\\n\".join(env_setup_cmds)\n        result = subprocess.run(\n            env_setup_cmds,\n            shell=True,\n            executable=\"/bin/bash\",\n            cwd=repo_path,\n            capture_output=True,\n            text=True\n            \n        )\n        print(f\"Setup environment results:\\n{result.stderr}\\n{result.stdout}\\n{result.returncode}\\n{env_setup_cmds}\")\n        if result.returncode != 0 or \"failed to build\" in result.stderr.lower() or \"importerror\" in result.stderr.lower():\n            print(\"NOTEBOOK FAILED TO SETUP\")\n            print(stderr_count)\n            stderr_count += 1\n            return None\n        python_content = \"\"\"\ntry:\n    import astropy\nexcept Exception as e:\n    print(e)\ntry:\n    import astroid\nexcept Exception as e:\n    print(e)\nprint(\\\"SUCCESS!\\\")\"\"\"\n        with open(\"super_special_python_file.py\", \"w\") as f:\n            f.write(python_content)\n        \n        test_content = \"\"\"\ndef test_assert_right_1():\n    assert 1 == 1\ndef test_assert_wrong_1():\n    assert 2+2==5\ndef test_assert_right_2():\n    assert 1-1==0\ndef test_assert_wrong_2():\n    assert 5+5==10\"\"\"\n    \n        with open(\"super_special_test_file.py\", 'w') as f:\n            f.write(test_content)\n\n        print(\"==== CHECKING IF PYTHON FILES WORK ====\")\n        !ls\n        result = subprocess.run(\n            \"set -e\\npython super_special_python_file.py\",\n            shell=True,\n            executable=\"/bin/bash\",\n            cwd=repo_path,\n            capture_output=True,\n            text=True\n        )\n        if result.returncode != 0:\n            print(f\"Failed to run python file!\\nstderr:\\n{result.stderr}\\nSetup stdout:\\n{result.stdout}\\nSetup returncode\\n{result.returncode}\")\n            pythonnotprint_count += 1\n            print(pythonnotprint_count)\n            return None\n        else:\n            print(f\"Successfully ran python file!!\\nstderr:\\n{result.stderr}\\nSetup stdout:\\n{result.stdout}\\nSetup returncode\\n{result.returncode}\")\n    \n        print(\"==== PYTEST INSTALLATION CHECK ====\")\n        result = subprocess.run(\n            \"set -e\\npytest --version\",\n            shell=True,\n            cwd=repo_path,\n            capture_output=True,\n            text=True\n        )\n        print(\"Stdout:\", result.stdout)\n        print(\"Stderr:\", result.stderr)\n        print(\"Result code:\", result.returncode)\n        \n        print(\"==== CHECKING IF PYTEST WORKS ====\")\n        result = subprocess.run(\n            \"set -e\\npytest --color=no --ff -rA -q --tb=no super_special_test_file.py 2>&1\",\n            shell=True,\n            cwd=repo_path,\n            capture_output=True,\n            text=True\n        )\n        print(\"Stdout:\", result.stdout)\n        print(\"Stderr:\", result.stderr) \n        print(\"Result code:\", result.returncode)\n        if (\"passed\" not in result.stdout.lower() and \"failed\" not in result.stdout.lower()) or (result.returncode != 0 and result.returncode != 1):\n            print(\"NO TESTS WORKED!\")\n            nopassfail_count += 1\n            print(nopassfail_count)\n            return None\n        else:\n            print(\"SUCCESS!\")\n\n        print(\"*** LOADING FILES ***\")\n        original_project_files = load_project_files(\".\")\n        print(original_project_files[0].path)\n        \n        print(\"==== FINISH SETUP! ====\")\n        search_agents = []\n        test_agents = []\n        search_chats = []\n        search_start_time = time.time()\n        print(\"Loading agents...\")\n        for i in range(0, search_batch):\n            new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/search_codeact_agent.json\")\n            search_chats += [new_agent.start(task=problem_statement, files=original_project_files).openai_completion]\n            search_agents += [new_agent]\n        for i in range(0, search_batch):\n            new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/search_md_agent.json\")\n            search_chats += [new_agent.start(task=problem_statement, files=original_project_files).openai_completion]\n            search_agents += [new_agent]\n        print(\"Loading test search agents...\")\n        \n        new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/md_agent_tests.json\")\n        search_chats += [new_agent.start(task=problem_statement, files=original_project_files).openai_completion]\n        search_agents += [new_agent]\n        test_agents += [new_agent]\n        new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/codeact_agent_tests.json\")\n        search_chats += [new_agent.start(task=problem_statement, files=original_project_files).openai_completion]\n        search_agents += [new_agent]\n        test_agents += [new_agent]\n        \n            \n        print(f\"==== DEPLOYING {len(search_agents)} SEARCH AGENTS ====\")\n        turn_counter = 0\n        while len(search_chats) > 0 and turn_counter < search_turn_limit:\n            print(f\"==== TURN {turn_counter} ====\")\n            responses = get_responses(llm, gen_config, search_chats)\n            agent_counter = 0\n            new_chats = []\n            for x in search_agents:\n                if x.frozen == False:                \n                    resp = x.step(responses[agent_counter])\n                    if resp.done == None:\n                        print(\"Continue...\")\n                        new_chats += [resp.openai_completion]\n                    else:\n                        print(\"Frozen agent...\")\n                        x.frozen = True\n                    agent_counter += 1\n            if (time.time() - start_time)/60 > 50:\n                print(\"!!!!!! EMERGENCY ERROR; RAN OUT OF TIME !!!!!!\")\n                return None\n            search_chats = new_chats\n            turn_counter += 1\n        print(f\"Time taken to search for relevant elements: {(time.time() - search_start_time)/60} minutes\")\n        print(f\"==== COLLECTING RESULTS! ====\")\n        reference_elements = []\n        for a in search_agents:\n            \"\"\"\n            if a in test_agents:\n                continue\n            \"\"\"\n            reference_elements += [a.cached_state.saved_elements]\n        \n        fail_to_fail_tests = []\n        pytest_run_commands = []\n        for t in test_agents:\n            for testtorun in t.cached_state.saved_elements:\n                file_path = testtorun[0]\n                element_id = testtorun[1]\n                file = next((f for f in original_project_files if f.path.lower() == file_path.lower()), None)\n                if not file:\n                    continue\n                all_elements = []\n                stack = list(file.elements)\n                while stack:\n                    element = stack.pop()\n                    all_elements.append(element)\n                    stack.extend(element.elements)\n                \n                element = next((e for e in all_elements if e.identifier.lower() == element_id.lower()), None)\n                if not element:\n                    continue\n                if len(element.elements) > 2:\n                    continue\n                test_cmd_final = testtorun[0] + \"::\" + testtorun[1].replace(\".\", \"::\")\n                if \"test\" in testtorun[0] and \"test\" in testtorun[1].lower() and test_cmd_final not in pytest_run_commands:\n                    print(\"Got test:\", test_cmd_final)\n                    pytest_run_commands += [test_cmd_final]\n                else:\n                    print(\"Not test\")\n        if len(pytest_run_commands) < 3:\n            print(\"NO TESTS FOUND\")\n        pytest_run_commands = pytest_run_commands[0:fail_to_fail_count]\n        pytest_run_commands = \" \".join(pytest_run_commands)\n        print(pytest_run_commands)\n        try:\n            result = subprocess.run(\n                f\"pytest --color=no --ff -rA -q --tb=no {pytest_run_commands} 2>&1\",\n                shell=True,\n                cwd=repo_path,\n                capture_output=True,\n                text=True,\n                timeout=10\n            )\n        except Exception as e:\n            print(\"TIMEOUT\")\n            return None\n        print(\"Stdout:\", result.stdout)\n        print(\"Stderr:\", result.stderr) \n        print(\"Result code:\", result.returncode)\n        if \"passed\" not in result.stdout.lower() and \"failed\" not in result.stdout.lower():\n            # Tests didnt work\n            print(\"Test fail!\")\n            return None\n        \n        if len(reference_elements) < 4:\n            print(\"Not enough references found...\")\n            return None\n        print(f\"*** All references: ***\\n{reference_elements}\")\n        sorted_refs = get_n_most_common(reference_elements, replication_top_select + replication_gurantee_refs + 2)\n        # Discard classes\n        new_sorted_refs = []\n        for ref in sorted_refs:\n            file_path = ref[0]\n            element_id = ref[1]\n            file = next((f for f in original_project_files if f.path.lower() == file_path.lower()), None)\n            if not file:\n                continue\n            all_elements = []\n            stack = list(file.elements)\n            while stack:\n                element = stack.pop()\n                all_elements.append(element)\n                stack.extend(element.elements)\n            \n            element = next((e for e in all_elements if e.identifier.lower() == element_id.lower()), None)\n            if not element:\n                continue\n            if len(element.elements) < 7:\n                new_sorted_refs += [ref]\n        sorted_refs = new_sorted_refs\n        print(f\"*** FILTERED: ***\\n{sorted_refs}\")\n        replication_gurantee_refs_picked = sorted_refs[0:replication_gurantee_refs]\n        replication_random_refs_picked = sorted_refs[replication_gurantee_refs:]\n        fixer_random_refs_picked = sorted_refs[0:fixer_top_select]\n        print(f\"*** Replication guranteed references: ***\\n{replication_gurantee_refs_picked}\")\n        print(f\"*** Replication random references: ***\\n{replication_random_refs_picked}\")\n        print(f\"*** Replication mixed references: ***\\n{fixer_random_refs_picked}\")\n\n        print(\"==== GENERATING REPLICATIONS ====\")\n        replication_start_time = time.time()\n        all_replication_chats = []\n        for x in range(0, replication_batch):\n            new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/replication_maker.json\")\n            new_agent.get_import_block_saved = True\n            rep_references = random.sample(replication_random_refs_picked, min(replication_random_refs, len(replication_random_refs_picked))) + replication_gurantee_refs_picked\n            all_replication_chats += [new_agent.start(task=problem_statement, files=original_project_files, copy_saved_elements=rep_references).openai_completion]\n        responses = get_responses(llm, gen_config_replication, all_replication_chats)\n        if (time.time() - start_time)/60 > 50:\n            print(\"!!!!!! EMERGENCY ERROR; RAN OUT OF TIME !!!!!!\")\n            return None\n        for x in range(0, len(responses)):\n            resp = responses[x]\n            all_replication_chats[x].append({\"role\":\"assistant\", \"content\":resp})\n            print(resp)\n            if resp.count(\"```\") < 2:\n                all_replication_chats[x].append({\"role\":\"user\", \"content\":\"No code block found... Please output your replication code wrapped in code blocks.\"})\n                print(\"No replication found.\")\n                continue\n            code_block_segments = resp.split(\"```\")\n            last_section = code_block_segments[-2]\n            # Remove excess newline at the start\n            last_section = last_section[last_section.find(\"\\n\"):].strip()\n            code_block = last_section\n            try:\n                ast.parse(code_block)\n                print(\"GOT CODE BLOCK\")\n                \n                # Try to run replication\n                with open(\"super_special_python_file.py\", \"w\") as f:\n                    f.write(code_block)\n                try:\n                    result = subprocess.run(\n                        \"python super_special_python_file.py\",\n                        shell=True,\n                        executable=\"/bin/bash\",\n                        cwd=repo_path,\n                        capture_output=True,\n                        text=True,\n                        timeout=10\n                    )\n                except Exception as e:\n                    all_replication_chats[x].append({\"role\":\"user\", \"content\":\"Replication script timed out... Please fix it.\"})\n                    print(\"TIMEOUT\")\n                    continue\n                print(result.stdout + result.stderr)                \n                all_replication_chats[x].append({\"role\":\"user\", \"content\":\"```output\\n\" + \"\\n\".join((result.stdout + result.stderr).splitlines()[-100:])[-7000:] + \"\\n```\\nBased on the output of your replication block, output a new and improved replication wrapped within code blocks. Fix any issues that occured, and add debug print statements if necessary. After you output your code block, do not output anything else, you should only have one code block in your output.\"})\n                continue\n            except Exception:\n                print(\"CODE BLOCK FAILED TO PARSE\")\n                all_replication_chats[x].append({\"role\":\"user\", \"content\":\"Replication script failed to parse... Please fix it.\"})\n                continue\n        responses = get_responses(llm, gen_config, all_replication_chats)\n        true_replication_chats = []\n        real_replications = []\n        # Grab functional replications\n        for x in range(0, len(responses)):\n            resp = responses[x]\n            print(resp)\n            if resp.count(\"```\") < 2:\n                real_replications += [None]\n                print(\"No test block found.\")\n                continue\n            code_block_segments = resp.split(\"```\")\n            last_section = code_block_segments[-2]\n            # Remove excess newline at the start\n            last_section = last_section[last_section.find(\"\\n\"):].strip()\n            code_block = last_section\n            try:\n                ast.parse(code_block)\n                print(\"GOT CODE BLOCK\")\n                \n                # Try to run replication\n                with open(\"super_special_python_file.py\", \"w\") as f:\n                    f.write(code_block)\n                try:\n                    result = subprocess.run(\n                        \"python super_special_python_file.py\",\n                        shell=True,\n                        executable=\"/bin/bash\",\n                        cwd=repo_path,\n                        capture_output=True,\n                        text=True,\n                        timeout=10\n                    )\n                except Exception as e:\n                    real_replications += [None]\n                    print(\"TIMEOUT\")\n                    continue\n                print(result.stdout + result.stderr)\n                if \"SUCCESS\" in result.stdout or \"SUCCESS\" in result.stderr:\n                    print(\"Found success...\")\n                    real_replications += [None]\n                    continue\n                else:\n                    real_replications += [code_block]\n                    all_replication_chats[x].append({\"role\":\"assistant\", \"content\":responses[x]})\n                    all_replication_chats[x].append({\"role\":\"user\", \"content\":\"```output\\n\" + \"\\n\".join((result.stdout + result.stderr).splitlines()[-100:])[-7000:] + \"\\n```\\nFirst review and output a quick analysis of the output of running your code. After that, determine if the replication was successful or not. If it was, output REPLICATION SUCCESS, otherwise output REPLICATION FAILURE. End your output after that, do not output anything else. Begin your analysis.\"})\n                    true_replication_chats.append(all_replication_chats[x])\n                    continue\n            except Exception:\n                print(\"CODE BLOCK FAILED TO PARSE\")\n                real_replications += [None]\n                continue\n        \n        # Check which replications are actually successful\n        print(\"==== ASSESSING REPLICATION SUCCESS ====\")\n        responses = get_responses(llm, gen_config, true_replication_chats)\n        if (time.time() - start_time)/60 > 50:\n            print(\"!!!!!! EMERGENCY ERROR; RAN OUT OF TIME !!!!!!\")\n            return None\n        counter = 0\n        verified_replications = []\n        for x in range(0, len(real_replications)):\n            if real_replications[x] == None:\n                continue\n            resp = responses[counter]\n            print(resp)\n            if \"REPLICATION SUCCESS\" in resp and \"REPLICATION FAILURE\" not in resp:\n                print(\"GOOD!\")\n                verified_replications += [real_replications[x]]\n            counter += 1\n        print(\"SUCCESSFUL REPLICATIONS:\", len(verified_replications))\n\n        if len(verified_replications) < replication_min_req:\n            print(\"NOT ENOUGH REPLICATIONS, QUITTING...\")\n            return None\n        verified_replications = verified_replications[0:9]\n        print(f\"Time taken to create replications: {(time.time() - replication_start_time)/60} minutes\")\n        coding_start_time = time.time()\n        code_agents = []\n        code_agents_chats = []\n        code_agents_replication_files = []\n        replication_id = 0\n        for j in range(0, fixer_batch):\n            chosen_rep = verified_replications[replication_id]\n            with open(\"super_special_python_file.py\", 'w') as writefile:\n                writefile.write(chosen_rep)\n            try:\n                result = subprocess.run(\n                    \"python super_special_python_file.py\",\n                    shell=True,\n                    executable=\"/bin/bash\",\n                    cwd=repo_path,\n                    capture_output=True,\n                    text=True,\n                    timeout=20\n                )\n                resultout = \"\\n\".join((\"Stdout:\\n\" + result.stdout + \"\\nStderr:\\n\" + result.stderr).splitlines()[-100:])[-7000:]\n            except Exception as e:\n                print(\"TIMEOUT\")\n                resultout = \"The replication script timed out when running for some reason...\"\n            fix_references = random.sample(fixer_random_refs_picked, min(replication_random_refs, len(fixer_random_refs_picked)))\n            new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/codeact_agent_fixer.json\")\n            new_agent.tools_list += [Tool(run_test)]\n            new_agent.init_message = new_agent.init_message.replace(\"{{replication_script}}\", f\"```python\\n{chosen_rep}\\n```\")\n            new_agent.init_message = new_agent.init_message.replace(\"{{replication_output}}\", f\"```output\\n{resultout}\\n```\")\n            code_agents_chats += [new_agent.start(task=problem_statement, files=copy.deepcopy(original_project_files), copy_saved_elements=fix_references).openai_completion]\n            code_agents_replication_files += [chosen_rep]\n            code_agents += [new_agent]\n            \n            replication_id += 1\n            if replication_id == len(verified_replications):\n                replication_id = 0\n        for j in range(0, fixer_batch):\n            chosen_rep = verified_replications[replication_id]\n            with open(\"super_special_python_file.py\", 'w') as writefile:\n                writefile.write(chosen_rep)\n            try:\n                result = subprocess.run(\n                    \"python super_special_python_file.py\",\n                    shell=True,\n                    executable=\"/bin/bash\",\n                    cwd=repo_path,\n                    capture_output=True,\n                    text=True,\n                    timeout=20\n                )\n                resultout = \"\\n\".join((\"Stdout:\\n\" + result.stdout + \"\\nStderr:\\n\" + result.stderr).splitlines()[-100:])[-7000:]\n            except Exception as e:\n                print(\"TIMEOUT\")\n                resultout = \"The replication script timed out when running for some reason...\"\n            fix_references = random.sample(fixer_random_refs_picked, min(replication_random_refs, len(fixer_random_refs_picked)))\n            new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/md_agent_fixer.json\")\n            new_agent.tools_list += [Tool(run_test)]\n            new_agent.init_message = new_agent.init_message.replace(\"{{replication_script}}\", f\"```python\\n{chosen_rep}\\n```\")\n            new_agent.init_message = new_agent.init_message.replace(\"{{replication_output}}\", f\"```output\\n{resultout}\\n```\")\n            code_agents_chats += [new_agent.start(task=problem_statement, files=copy.deepcopy(original_project_files), copy_saved_elements=fix_references).openai_completion]\n            code_agents_replication_files += [chosen_rep]\n            code_agents += [new_agent]\n            \n            replication_id += 1\n            if replication_id == len(verified_replications):\n                replication_id = 0\n        for j in range(0, fixer_batch):\n            chosen_rep = verified_replications[replication_id]\n            with open(\"super_special_python_file.py\", 'w') as writefile:\n                writefile.write(chosen_rep)\n            try:\n                result = subprocess.run(\n                    \"python super_special_python_file.py\",\n                    shell=True,\n                    executable=\"/bin/bash\",\n                    cwd=repo_path,\n                    capture_output=True,\n                    text=True,\n                    timeout=20\n                )\n                resultout = \"\\n\".join((\"Stdout:\\n\" + result.stdout + \"\\nStderr:\\n\" + result.stderr).splitlines()[-100:])[-7000:]\n            except Exception as e:\n                print(\"TIMEOUT\")\n                resultout = \"The replication script timed out when running for some reason...\"\n            fix_references = random.sample(fixer_random_refs_picked, min(replication_random_refs, len(fixer_random_refs_picked)))\n            new_agent = load_agent_from_json(\"/kaggle/input/new-agent2-agents/xml_agent_fixer.json\")\n            new_agent.tools_list += [Tool(run_test)]\n            new_agent.init_message = new_agent.init_message.replace(\"{{replication_script}}\", f\"```python\\n{chosen_rep}\\n```\")\n            new_agent.init_message = new_agent.init_message.replace(\"{{replication_output}}\", f\"```output\\n{resultout}\\n```\")\n            code_agents_chats += [new_agent.start(task=problem_statement, files=copy.deepcopy(original_project_files), copy_saved_elements=fix_references).openai_completion]\n            code_agents_replication_files += [chosen_rep]\n            code_agents += [new_agent]\n            \n            replication_id += 1\n            if replication_id == len(verified_replications):\n                replication_id = 0\n        print(f\"==== DEPLOYING {len(code_agents_chats)} CODER AGENTS ====\")\n        turn_counter = 0\n        current_temperature = coding_start_temp\n        while len(code_agents_chats) > 0 and turn_counter < fixer_turn_limit:\n            print(f\"==== TURN {turn_counter} ====\")\n            gen_config_coder.temperature = current_temperature\n            current_temperature -= coding_temp_drop\n            if current_temperature < coding_end_temp:\n                current_temperature = coding_end_temp\n            responses = get_responses(llm, gen_config_coder, code_agents_chats)\n            agent_counter = 0\n            new_chats = []\n            for x in range (0, len(code_agents)):\n                curagent = code_agents[x]\n                super_secret_test_str = code_agents_replication_files[x]\n                super_secret_project_dir = curagent.cached_state.workspace\n                if curagent.frozen == False:                \n                    resp = curagent.step(responses[agent_counter])\n                    if resp.done == None:\n                        print(\"Continue...\")\n                        new_chats += [resp.openai_completion]\n                    else:\n                        print(\"Frozen agent...\")\n                        curagent.frozen = True\n                    agent_counter += 1\n            if (time.time() - start_time)/60 > 50:\n                print(\"!!!!!! EMERGENCY ERROR; RAN OUT OF TIME !!!!!!\")\n                return None\n            code_agents_chats = new_chats\n            turn_counter += 1\n        print(f\"Time taken to generate solutions: {(time.time() - coding_start_time)/60} minutes\")\n        print(f\"==== COLLECTING SOLUTIONS! ====\")\n        solutions = []\n        solutions_sources = []\n        for a in code_agents:\n            diffs = []\n            failed = False\n            for f in a.cached_state.workspace:\n                if f.original_content != f.updated_content:\n                    diffs += [f.diff(None)]\n                    try:\n                        ast.parse(f.updated_content)\n                    except Exception:\n                        failed = True\n            if len(diffs) == 0 or failed:\n                print(\"Discarded broken solution\")\n                continue\n            else:\n                print(\"Working solution got\")\n                solutions += [\"\\n\".join(diffs)]\n                solutions_sources += [a.cached_state.workspace]\n        print(f\"==== CHECKING SOLUTIONS! ====\")\n        best_solution = None\n        best_solution_score = pass_to_pass_percent\n        for xx in range(0, len(solutions)):\n            sol = solutions[xx]\n            print(sol)\n            sol_source = solutions_sources[xx]\n            for ffile in sol_source:\n                if ffile.original_content != ffile.updated_content:\n                    with open(ffile.path, 'w') as writefile:\n                        writefile.write(ffile.updated_content)\n                else:\n                    with open(ffile.path, 'w') as writefile:\n                        writefile.write(ffile.original_content)\n            correct = 0\n            total = len(verified_replications)\n            \n            try:\n                result = subprocess.run(\n                    f\"pytest --color=no --ff -rA -q --tb=no {pytest_run_commands} 2>&1\",\n                    shell=True,\n                    cwd=repo_path,\n                    capture_output=True,\n                    text=True,\n                    timeout=10\n                )\n            except Exception as e:\n                print(\"TIMEOUT\")\n                continue\n            print(result.stdout)\n            print(result.stderr)\n            print(result.returncode)\n            if \"failed\" in result.stdout.lower() or \"passed\" not in result.stdout.lower():\n                print(\"FAILED TESTS\")\n                continue\n            \n            for yy in verified_replications:\n                with open(\"super_special_python_file.py\", 'w') as writefile:\n                    writefile.write(yy)\n                try:\n                    result = subprocess.run(\n                        \"python super_special_python_file.py\",\n                        shell=True,\n                        executable=\"/bin/bash\",\n                        cwd=repo_path,\n                        capture_output=True,\n                        text=True,\n                        timeout=10\n                    )\n                    print(\"STDOUT:\\n\" + result.stdout + \"STDERR:\\n\" + result.stderr)\n                except Exception as e:\n                    print(\"TIMEOUT\")\n                    continue\n                if \"SUCCESS\" in result.stdout or \"SUCCESS\" in result.stderr:\n                    print(\"Get point\")\n                    correct += 1\n            score = float(correct) / float(total)\n            print(\"Score:\", score)\n            if score > best_solution_score:\n                best_solution_score = score\n                best_solution = sol\n                print(\"IS NEW BEST\")\n\n        # Clear files:\n        file_path = Path(f'super_special_python_file.py')\n        if file_path.exists():\n            file_path.unlink()\n            print(f\"File {file_path} has been deleted.\")\n        else:\n            print(f\"File {file_path} does not exist.\")\n\n        file_path = Path(f'super_special_test_file.py')\n        if file_path.exists():\n            file_path.unlink()\n            print(f\"File {file_path} has been deleted.\")\n        else:\n            print(f\"File {file_path} does not exist.\")\n\n        for ffile in original_project_files:\n            with open(ffile.path, 'w') as writefile:\n                writefile.write(ffile.original_content)\n        print(f\"TOTAL TIME TAKEN: {(time.time() - start_time)/60} minutes\")\n        if best_solution != None:\n            print(\"Got best solution!\")\n            print(\"Score:\", best_solution_score)\n            print(best_solution)\n            return best_solution\n        return None\n    except Exception as e:\n        print(e)\n        traceback.print_exc()\n        return None","metadata":{"papermill":{"duration":0.011382,"end_time":"2024-12-11T03:22:08.852112","exception":false,"start_time":"2024-12-11T03:22:08.84073","status":"completed"},"tags":[],"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:14:22.669913Z","iopub.execute_input":"2025-03-17T15:14:22.670517Z","iopub.status.idle":"2025-03-17T15:14:23.001379Z","shell.execute_reply.started":"2025-03-17T15:14:22.670492Z","shell.execute_reply":"2025-03-17T15:14:23.000667Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%notify\ntry:\n    inference_server = kaggle_evaluation.konwinski_prize_inference_server.KPrizeInferenceServer(\n        get_number_of_instances,   \n        predict\n    )\n    if os.getenv('KAGGLE_IS_COMPETITION_RERUN'):\n        inference_server.serve()\n    else:\n        inference_server.run_local_gateway(\n            data_paths=(\n                '/kaggle/input/konwinski-prize/',  # Path to the entire competition dataset\n                '/kaggle/tmp/konwinski-prize/',   # Path to a scratch directory for unpacking data.a_zip.\n            ),\n            use_concurrency=True,  # This can safely be disabled for purposes of local testing if necessary.\n        )\nexcept KeyboardInterrupt:\n    print('KeyboardInterrupt')\nexcept Exception as e:\n    print(e)\n    traceback.print_exc()\nfinally:\n    print('Inference done')","metadata":{"papermill":{"duration":3.790202,"end_time":"2024-12-11T03:22:12.648591","exception":false,"start_time":"2024-12-11T03:22:08.858389","status":"completed"},"tags":[],"trusted":true,"execution":{"iopub.status.busy":"2025-03-17T15:14:23.002052Z","iopub.execute_input":"2025-03-17T15:14:23.002263Z","execution_failed":"2025-03-17T15:50:08.282Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}