{"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":10934030,"sourceType":"competition"},{"sourceId":218890054,"sourceType":"kernelVersion"},{"sourceId":219188266,"sourceType":"kernelVersion"},{"sourceId":224573565,"sourceType":"kernelVersion"},{"sourceId":224600803,"sourceType":"kernelVersion"},{"sourceId":162855,"sourceType":"modelInstanceVersion","modelInstanceId":138488,"modelId":161088},{"sourceId":238929,"sourceType":"modelInstanceVersion","modelInstanceId":204059,"modelId":225262},{"sourceId":276775,"sourceType":"modelInstanceVersion","modelInstanceId":237010,"modelId":258700}],"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, timedelta\n\n\nos.environ['TZ'] = 'Asia/Kolkata'\ntime.tzset()\nprint('Starting')\nstart_time = datetime.now()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:25:24.307261Z","iopub.execute_input":"2025-02-26T11:25:24.307697Z","iopub.status.idle":"2025-02-26T11:25:24.320466Z","shell.execute_reply.started":"2025-02-26T11:25:24.307647Z","shell.execute_reply":"2025-02-26T11:25:24.3182Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nis_interactive = os.environ.get('KAGGLE_KERNEL_RUN_TYPE') == 'Interactive'\nis_non_interactive = not is_interactive\nis_rerun = os.getenv('KAGGLE_IS_COMPETITION_RERUN')\nhide_output_and_error=\"2>&- >&-\" if is_non_interactive else \"\" \nhide_output_and_error2=\"2>&- >&-\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:25:24.321693Z","iopub.execute_input":"2025-02-26T11:25:24.322154Z","iopub.status.idle":"2025-02-26T11:25:24.364794Z","shell.execute_reply.started":"2025-02-26T11:25:24.322109Z","shell.execute_reply":"2025-02-26T11:25:24.363383Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if is_interactive:\n    # https://www.kaggle.com/discussions/product-feedback/554027\n    import socket\n    REMOTE_SERVER = \"one.one.one.one\"\n    def is_connected(hostname):\n      try:\n        # See if we can resolve the host name - tells us if there is\n        # A DNS listening\n        host = socket.gethostbyname(hostname)\n        # Connect to the host - tells us if the host is actually reachable\n        s = socket.create_connection((host, 80), 2)\n        s.close()\n        return True\n      except Exception:\n         pass # We ignore any errors, returning False\n      return False\n    print('Internet :',is_connected(REMOTE_SERVER))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:25:24.366039Z","iopub.execute_input":"2025-02-26T11:25:24.366427Z","iopub.status.idle":"2025-02-26T11:25:56.408892Z","shell.execute_reply.started":"2025-02-26T11:25:24.366384Z","shell.execute_reply":"2025-02-26T11:25:56.40766Z"}},"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(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:25:56.410501Z","iopub.execute_input":"2025-02-26T11:25:56.410888Z","iopub.status.idle":"2025-02-26T11:25:56.53708Z","shell.execute_reply.started":"2025-02-26T11:25:56.410852Z","shell.execute_reply":"2025-02-26T11:25:56.535672Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import io\nimport shutil\nimport subprocess\nimport traceback\n\nimport pandas as pd\n# import 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-02-26T11:25:56.538619Z","iopub.execute_input":"2025-02-26T11:25:56.539128Z","iopub.status.idle":"2025-02-26T11:26:08.447786Z","shell.execute_reply.started":"2025-02-26T11:25:56.539049Z","shell.execute_reply":"2025-02-26T11:26:08.446652Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if is_interactive:\n    !python3.10 -m pip install  /kaggle/input/browser-notifications-in-a-kaggle-kernel/*.whl\n    !python3.10 -m pip install jupyter -q --no-index --find-links=/kaggle/input/browser-notifications-in-a-kaggle-kernel/\n    !python3.10 -m pip install -q /kaggle/input/browser-notifications-in-a-kaggle-kernel/jupyter-notify/dist/jupyternotify-0.1.15-py2.py3-none-any.whl --no-index\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:26:08.450559Z","iopub.execute_input":"2025-02-26T11:26:08.451552Z","iopub.status.idle":"2025-02-26T11:26:19.613246Z","shell.execute_reply.started":"2025-02-26T11:26:08.451514Z","shell.execute_reply":"2025-02-26T11:26:19.611689Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if is_interactive:\n    %reload_ext jupyternotify\nelse:\n    from IPython.core.magic import register_cell_magic\n\n    @register_cell_magic\n    def notify(line, cell):\n        exec(cell, globals())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:26:19.615913Z","iopub.execute_input":"2025-02-26T11:26:19.616241Z","iopub.status.idle":"2025-02-26T11:26:19.872563Z","shell.execute_reply.started":"2025-02-26T11:26:19.616214Z","shell.execute_reply":"2025-02-26T11:26:19.87144Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"SERVE=is_non_interactive","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:26:19.873812Z","iopub.execute_input":"2025-02-26T11:26:19.874108Z","iopub.status.idle":"2025-02-26T11:26:19.879026Z","shell.execute_reply.started":"2025-02-26T11:26:19.874083Z","shell.execute_reply":"2025-02-26T11:26:19.877621Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def start_server():\n    !python3.10 -m pip install vllm --find-links /kaggle/input/vllm-nb -q  2>&- >&-\n    !python3.10 -m pip install triton --find-links /kaggle/input/vllm-nb \n    !python3.10 -m pip uninstall pynvml -y\n    \n    import subprocess\n    log_file = open(\"/kaggle/working/vllm_output.log\", \"w\")\n    \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.99\",\n        \"--enforce_eager\",\n        \"--enable_prefix_caching\",\n        # \"--rope-scaling\", '{\"factor\": 4.0, \"original_max_position_embeddings\": 32768, \"rope_type\": \"yarn\"}',\n        # \"--max_model_len\", \"64000\",\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-02-26T11:26:19.880136Z","iopub.execute_input":"2025-02-26T11:26:19.8805Z","iopub.status.idle":"2025-02-26T11:26:19.894803Z","shell.execute_reply.started":"2025-02-26T11:26:19.88047Z","shell.execute_reply":"2025-02-26T11:26:19.893761Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"setup_done = False\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\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:26:19.895862Z","iopub.execute_input":"2025-02-26T11:26:19.896217Z","iopub.status.idle":"2025-02-26T11:26:26.730885Z","shell.execute_reply.started":"2025-02-26T11:26:19.89618Z","shell.execute_reply":"2025-02-26T11:26:26.72927Z"}},"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# %env NO_INTERNET=1\n\nos.environ['PYTHONPATH'] = '/kaggle/working/Kevin:' + os.environ['PYTHONPATH']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:26:26.732244Z","iopub.execute_input":"2025-02-26T11:26:26.732557Z","iopub.status.idle":"2025-02-26T11:26:26.753998Z","shell.execute_reply.started":"2025-02-26T11:26:26.732529Z","shell.execute_reply":"2025-02-26T11:26:26.752909Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"use_groq = is_interactive and 0\nif use_groq:\n    from kaggle_secrets import UserSecretsClient\n    user_secrets = UserSecretsClient()\n    \n    os.environ['GROQ_API_KEY'] = user_secrets.get_secret(\"LLM_API_KEY\")\n\nos.environ['LLM_USE_GROUP'] = 'groq' if use_groq else ''\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:26:26.755066Z","iopub.execute_input":"2025-02-26T11:26:26.755423Z","iopub.status.idle":"2025-02-26T11:26:26.773243Z","shell.execute_reply.started":"2025-02-26T11:26:26.755384Z","shell.execute_reply":"2025-02-26T11:26:26.771967Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_path1 = '/kaggle/input/qwen2.5-coder/transformers/32b-instruct/1'\nmodel_path2 = \"/kaggle/input/deepseek-r1/transformers/deepseek-r1-distill-qwen-32b/1\"\nmodel_path3 = '/kaggle/input/qwq-32b/transformers/qwq-32b/1'\nmodel_path = model_path1 if is_non_interactive else 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 = 30_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-02-26T13:41:51.457457Z","iopub.execute_input":"2025-02-26T13:41:51.457968Z","iopub.status.idle":"2025-02-26T13:41:51.466179Z","shell.execute_reply.started":"2025-02-26T13:41:51.457929Z","shell.execute_reply":"2025-02-26T13:41:51.464935Z"}},"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-02-26T11:26:26.793597Z","iopub.execute_input":"2025-02-26T11:26:26.793945Z","iopub.status.idle":"2025-02-26T11:26:26.808994Z","shell.execute_reply.started":"2025-02-26T11:26:26.793915Z","shell.execute_reply":"2025-02-26T11:26:26.807945Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"setup_done = 0\nkaggle_setup()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T13:28:27.122928Z","iopub.execute_input":"2025-02-26T13:28:27.123309Z","iopub.status.idle":"2025-02-26T13:28:48.39388Z","shell.execute_reply.started":"2025-02-26T13:28:27.123279Z","shell.execute_reply":"2025-02-26T13:28:48.391842Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Predict function","metadata":{}},{"cell_type":"code","source":"# !ln -sf /testbed/.venv/bin/python3.11 /usr/local/bin/python\n# !ln -sf /testbed/.venv/bin/python3.11 /usr/local/bin/python3.11\n# !ln -sf /testbed/.venv/bin/python3.11 /usr/bin/python3\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:28:42.691072Z","iopub.execute_input":"2025-02-26T11:28:42.691527Z","iopub.status.idle":"2025-02-26T11:28:42.696647Z","shell.execute_reply.started":"2025-02-26T11:28:42.691481Z","shell.execute_reply":"2025-02-26T11:28:42.695348Z"}},"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-02-26T11:28:42.697811Z","iopub.execute_input":"2025-02-26T11:28:42.698175Z","iopub.status.idle":"2025-02-26T11:28:42.779301Z","shell.execute_reply.started":"2025-02-26T11:28:42.698147Z","shell.execute_reply":"2025-02-26T11:28:42.778024Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# rm -r /testbed","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:28:42.780821Z","iopub.execute_input":"2025-02-26T11:28:42.781254Z","iopub.status.idle":"2025-02-26T11:28:42.796246Z","shell.execute_reply.started":"2025-02-26T11:28:42.781219Z","shell.execute_reply":"2025-02-26T11:28:42.795035Z"}},"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)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:28:42.797345Z","iopub.execute_input":"2025-02-26T11:28:42.797705Z","iopub.status.idle":"2025-02-26T11:28:42.836976Z","shell.execute_reply.started":"2025-02-26T11:28:42.797675Z","shell.execute_reply":"2025-02-26T11:28:42.835888Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%env PIP_FIND_LINKS=/kaggle/input/wheels-for-kprize-instances\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:29:29.945789Z","iopub.execute_input":"2025-02-26T11:29:29.946172Z","iopub.status.idle":"2025-02-26T11:29:29.952831Z","shell.execute_reply.started":"2025-02-26T11:29:29.946142Z","shell.execute_reply":"2025-02-26T11:29:29.951373Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%env POETRY_ALIAS=python3.10 -m poetry","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:28:42.850732Z","iopub.execute_input":"2025-02-26T11:28:42.851077Z","iopub.status.idle":"2025-02-26T11:28:42.866286Z","shell.execute_reply.started":"2025-02-26T11:28:42.85104Z","shell.execute_reply":"2025-02-26T11:28:42.865126Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"count=0\n\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    try:\n        global first_prediction, count\n        if datetime.now() - start_time > timedelta(hours=8, minutes=30):\n            return\n        count +=1\n        print(count,problem_statement.splitlines()[0])\n        if count not in [1,6] and not is_rerun:\n            return None  # Skip issue.\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        # uv run will build the dependencies; should run in a git dir\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            \n        )\n        if result.returncode != 0:\n            raise Exception(f\"Failed to setup environment:\\n{result.stderr}\\n{result.stdout}\\n{result.returncode}\\n{env_setup_cmds}\")\n\n        # print(env_setup_cmds)\n        \n        \n        \n        \n        instruction = (\n            f'Please address the following GitHub issue for the repository, where the source code is available in the {repo_path} directory, which you have access to.\\n'\n            '# Title\\n'\n            f'{problem_statement}\\n\\n'\n            '\\n$ pwd\\n'\n            f'{repo_path}\\n'\n        )\n        if 1:\n            NEW_MRE = {\n            'QTable cannot take `dimensionless_unscaled` when creating table from `data`' : '''\nfrom astropy import units as u\ntry:\n    u.Unit(0) # Unit with scale 0 is meaningless.\n    print(\"Error should have been raised.\")\nexcept Exception as e:\n    print(f\"Successfully got the exception as expected.\")\n        '''.strip()\n        }\n            title = problem_statement.split('\\n')[0]\n            code = NEW_MRE.get(title)\n            if code:\n                instruction = fr'# Create the following test code and make it pass (Don\\'t modify the test code itself). Library code is installed in /testbed directory.\\n```python\\n{code}\\n```\\n\\n'\n            if title == 'Provide a way to make a copy of a model with different parameter values, or be more flexible with parameter shape':\n                instruction = fr''' Just only add the following function to the library code.\nin astropy/modeling/core.py in Model's class add after line 2530\ndef _reset_parameters(self, *args, **kwargs):\n        \\\"\"\"\n        Reset parameters on the models to those specified.\n        Parameters can be specified either as positional arguments or keyword\n        arguments, as in the model initializer. Any parameters not specified\n        will be reset to their default values.\n        \\\"\"\"\n        self._initialize_parameters(args, kwargs)\n        self._initialize_slices()\n\\n\nAdd exactly without any error handling\n'''\n            numbered_instructions = [\n                # f'The best solution is to just raise an error for Unit(0).',\n                # f'Reproduce the MRE by creating test.py (add traceback.print_exc(limit=-2) if there is many lines of traceback) in a file and run it using bash. (You should not modify the test code itself.)',\n                f'Create and run the MRE in bash.',\n                f'If no traceback, locate the actual relevant library file that raised this error in {repo_path} using `search_class()` or `search_function()` python skill.',\n                'Inspect the function using `show_function_at_line()` or `show_function()` skill.',\n                'Correctly fix the library source code using try-except, ensuring proper handling of exceptions (TypeError, ValueError) without altering the intended logic.',\n                'Test the fix.',\n                'Apply the same changes to other relevant classes in the file.'\n                'Check for similar issues that might be related to the current issue.'\n            ]\n            for k, inst in enumerate(numbered_instructions):\n                instruction += f'Step {k + 1}: {inst}\\n\\n'\n            important_instructions = [\n                'Add your thoughts inside <think></think>. Think well before act.'\n                'You should not modify the test code itself.'\n                'Instead of a simple workaround mentioned in the issue, identify the root cause of the issue in the library source code and fix it.'\n                'Response Guides: Escape triple double quotes properly.',\n                'Inspect the metaclass __call__() if any.',\n                'If KeyError is raised for a config dictionary, it must be that config is not passed correctly in the previous call. Don\\'t simply add a check for the key in the config dictionary. Use show_function_at_line() to inspect the function definition of the previous call.',\n                'If you update min function, update max function too.',\n                'Add your valuable thoughts to every action you take.',\n                'Only use one skill at a time.',\n                'On exceptions, raise Error instead of giving wrong values.',\n                'For replace_lines_content, you can specify same line number for both start_line_number and end_line_number',\n                'The traceback must be read from bottom to top, with the final entry showing where the error occurred.',\n                'Wrap the code with triple backticks if it is a multi-line code block.',\n                'Internet is disabled.',\n                'Carefully verify the line numbers and range to ensure accurate code modification.',\n                'Very Very Important: Humanity is at stake. Earlier, you only solved one issue out of 71. So, please be mindful. Do not give any workaround. Please fix the issue directly with atmost sincerity 🙏🙏🙏.'\n            ]\n            instruction += '\\nImportant Instructions:\\n\\n'\n            for k,inst in enumerate(important_instructions):\n                instruction += f'{k + 1}: {inst}\\n\\n'\n        os.environ['OPENHANDS_TASK'] = instruction\n        diff = None\n        try:\n            %cd /kaggle/working/Kevin/\n            cmd = 'python3.10 -m poetry run python -m openhands.core.main'\n            subprocess.run(cmd, shell=True, timeout=25*60)\n           \n        except KeyboardInterrupt as e:\n            print(e)\n        except Exception as e:\n            print(e)\n\n        %cd $repo_path\n        diff = subprocess.getoutput(\"git --no-pager diff\")\n        print(diff)\n        #test\n        # test file may also change. so old tests are not correct.\n        # import os, subprocess\n        # cmd = 'git diff --name-only'\n        # output = subprocess.check_output(cmd, shell=True).decode('utf-8')\n        # for line in output.splitlines():\n        #     file_name = line.split('/')[-1]\n        #     cmd = f'find . -name test_{file_name}'\n        #     output = subprocess.check_output(cmd, shell=True).decode('utf-8').strip()\n        #     if output:\n        #         cmd = f'pytest -x {output}'\n        #         print('Running:', cmd)\n        #         return_code = subprocess.run(cmd, shell=True).returncode\n        #         if return_code != 0:\n        #             return None\n        # for submission file\n        %cd /kaggle/working\n        return diff or None\n    except Exception as e:\n        print(e)\n        traceback.print_exc()","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-02-26T14:27:18.669816Z","iopub.execute_input":"2025-02-26T14:27:18.670193Z","iopub.status.idle":"2025-02-26T14:27:18.75306Z","shell.execute_reply.started":"2025-02-26T14:27:18.670166Z","shell.execute_reply":"2025-02-26T14:27:18.75185Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if is_interactive and 0:\n    %cd /kaggle/working/Kevin\n    # !git st\n    # !git clean -d -f .\n    # !git reset --hard HEAD~50\n    !git pull\n    # pass","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:28:42.944992Z","iopub.execute_input":"2025-02-26T11:28:42.945304Z","iopub.status.idle":"2025-02-26T11:28:42.965906Z","shell.execute_reply.started":"2025-02-26T11:28:42.945275Z","shell.execute_reply":"2025-02-26T11:28:42.964587Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# !ps -ef | grep poetry | awk '{print $2}' | xargs kill -9 ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:29:23.194323Z","iopub.execute_input":"2025-02-26T11:29:23.19471Z","iopub.status.idle":"2025-02-26T11:29:23.339255Z","shell.execute_reply.started":"2025-02-26T11:29:23.194677Z","shell.execute_reply":"2025-02-26T11:29:23.337867Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# %cd /kaggle/working/Kevin\n\n# !DEBUG=0 timeout 19m python3.10 -m poetry run python -m openhands.core.main -t \"python3 /testbed/test_model.py\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:28:42.988732Z","iopub.execute_input":"2025-02-26T11:28:42.989097Z","iopub.status.idle":"2025-02-26T11:28:43.004414Z","shell.execute_reply.started":"2025-02-26T11:28:42.989069Z","shell.execute_reply":"2025-02-26T11:28:43.00324Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%notify\ntry:\n    first_prediction = True   \n    count = 0\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-02-26T14:27:23.01025Z","iopub.execute_input":"2025-02-26T14:27:23.010639Z","iopub.status.idle":"2025-02-26T14:38:23.171112Z","shell.execute_reply.started":"2025-02-26T14:27:23.010606Z","shell.execute_reply":"2025-02-26T14:38:23.169887Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"try:\n    %cd $repo_path\n    !git diff\nexcept Exception as e:\n    print(e)    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T14:26:43.210562Z","iopub.execute_input":"2025-02-26T14:26:43.210979Z","iopub.status.idle":"2025-02-26T14:26:43.371059Z","shell.execute_reply.started":"2025-02-26T14:26:43.210946Z","shell.execute_reply":"2025-02-26T14:26:43.369146Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from collections import Counter\ntry:\n    import pandas as pd\n    file = '/kaggle/working/submission.csv'\n    df = pd.read_csv(file)\n    output = df['unit_test_outcome']\n    print(Counter(output))\n    output = df['predict_outcome']\n    print(Counter(output))\n    from IPython.display import display\n    # print(df.iloc[6]['test_output'])\n    df.head(10)\nexcept Exception as e:\n    print(e)    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T14:39:27.760463Z","iopub.execute_input":"2025-02-26T14:39:27.760943Z","iopub.status.idle":"2025-02-26T14:39:27.78688Z","shell.execute_reply.started":"2025-02-26T14:39:27.760905Z","shell.execute_reply":"2025-02-26T14:39:27.785723Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"use_from_ssh = is_interactive and 0\nif use_from_ssh:\n    !mkdir ~/.ssh/\n    !ssh-keygen -f ~/.ssh/id_rsa -P \"\"\n    !cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys\n    !ls ~/.ssh","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:29:10.068216Z","iopub.execute_input":"2025-02-26T11:29:10.068529Z","iopub.status.idle":"2025-02-26T11:29:10.080949Z","shell.execute_reply.started":"2025-02-26T11:29:10.068501Z","shell.execute_reply":"2025-02-26T11:29:10.079648Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if use_from_ssh:\n    from kaggle_secrets import UserSecretsClient\n    user_secrets = UserSecretsClient()\n    secret_value_0 = user_secrets.get_secret(\"ngrok_auth_key\")\n    \n    import os\n    \n    # Install and start ssh-server\n    !sudo apt install -y openssh-server\n    !sudo service ssh status\n    !sudo service ssh start\n    !sudo service ssh status\n    \n    # Install ngrok\n    !curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo \"deb https://ngrok-agent.s3.amazonaws.com buster main\" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update -y && sudo apt install -y ngrok\n    \n    # Reset terminal color\n    !echo -e \"\\033[0m\"\n    \n    # Add Ngrok token to config\n    os.system(\"ngrok config add-authtoken \"+ f\"{secret_value_0}\")\n    \n    !sed '1d;$d' ~/.ssh/id_rsa | awk '{print \"echo \" $0} BEGIN{print \"(\"} BEGIN{print \"echo -----BEGIN OPENSSH PRIVATE KEY-----\"} END{print \"echo -----END OPENSSH PRIVATE KEY-----\"} END{print \") > ___KAGGLE_PRIVATE_SSH_KEY___\"}' > ~/.ssh/cmd_storage\n    !echo \"!!!!!!!!    RUN THE BELOW CODE IN YOUR LOCAL TERMINAL    !!!!!!!!\"\n    !cat ~/.ssh/cmd_storage & ngrok tcp 22 --log=stdout | tee ./ngrok.log | grep --line-buffered -oE 'tcp://[^:]*:[0-9]+' | sed -u 's/tcp\\:\\/\\//ssh \\-i ___KAGGLE_PRIVATE_SSH_KEY___ root\\@/' | sed -u 's/\\:/ \\-p /' | sed 's/$/ -o ServerAliveInterval=60/'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:29:10.082117Z","iopub.execute_input":"2025-02-26T11:29:10.082538Z","iopub.status.idle":"2025-02-26T11:29:10.107539Z","shell.execute_reply.started":"2025-02-26T11:29:10.082507Z","shell.execute_reply":"2025-02-26T11:29:10.106062Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if use_from_ssh:\n    !sed '1d;$d' ~/.ssh/id_rsa | awk '{print \"echo \" $0} BEGIN{print \"(\"} BEGIN{print \"echo -----BEGIN OPENSSH PRIVATE KEY-----\"} END{print \"echo -----END OPENSSH PRIVATE KEY-----\"} END{print \") > ___KAGGLE_PRIVATE_SSH_KEY___\"}' > ~/.ssh/cmd_storage\n    !echo \"!!!!!!!!    RUN THE BELOW CODE IN YOUR LOCAL TERMINAL    !!!!!!!!\"\n    !cat ~/.ssh/cmd_storage & ngrok tcp 22 --log=stdout | tee ./ngrok.log | grep --line-buffered -oE 'tcp://[^:]*:[0-9]+' | sed -u 's/tcp\\:\\/\\//ssh \\-i ___KAGGLE_PRIVATE_SSH_KEY___ root\\@/' | sed -u 's/\\:/ \\-p /' | sed 's/$/ -o ServerAliveInterval=60/'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:29:10.108845Z","iopub.execute_input":"2025-02-26T11:29:10.109218Z","iopub.status.idle":"2025-02-26T11:29:10.12351Z","shell.execute_reply.started":"2025-02-26T11:29:10.109186Z","shell.execute_reply":"2025-02-26T11:29:10.12237Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if is_non_interactive:\n    try:\n        import shutil\n        shutil.rmtree('/kaggle/working/Kevin')\n    except Exception as e:\n        print(e)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-26T11:29:10.124923Z","iopub.execute_input":"2025-02-26T11:29:10.12534Z","iopub.status.idle":"2025-02-26T11:29:10.144775Z","shell.execute_reply.started":"2025-02-26T11:29:10.1253Z","shell.execute_reply":"2025-02-26T11:29:10.143401Z"}},"outputs":[],"execution_count":null}]}