{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.14"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84795,"databundleVersionId":10462807,"sourceType":"competition"}],"dockerImageVersionId":30804,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false},"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":"markdown","source":"# Opening note\n\nThe goal of this competition is to train an AI that has the potential to solve real-world issues on Github repos. Basically, we have 3 months to build an AI capable enough to solve the SWE-bench by using only open source models, a feat that no one has ever achieved. Good luck to all:)\" />","metadata":{}},{"cell_type":"markdown","source":"<img src=\"https://i.imgflip.com/9dkyk4.jpg\" \n        alt=\"Meme\" \n        width=\"600\" \n        height=\"400\" \n        style=\"display: block; margin: 0 auto\" />","metadata":{}},{"cell_type":"markdown","source":"# Evaluation criteria\nSubmissions are scored using a simple metric that incentivizes skipping an issue over submitting a bad patch.\r\n$$ score = \\frac{a-b}{a+b+c} $$\n\nwhere a, b, and c are respectively the number of correctly resolved issues, the number of failing issues, and the number of skipped issues.ssues.","metadata":{}},{"cell_type":"markdown","source":"# Imports","metadata":{}},{"cell_type":"code","source":"# Basic imports\nimport io\nimport os\nimport shutil\n\nimport pandas as pd\nimport polars as pl\n\nimport kaggle_evaluation.konwinski_prize_inference_server","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.status.busy":"2024-12-14T12:13:04.730557Z","iopub.execute_input":"2024-12-14T12:13:04.731054Z","iopub.status.idle":"2024-12-14T12:13:20.649268Z","shell.execute_reply.started":"2024-12-14T12:13:04.731005Z","shell.execute_reply":"2024-12-14T12:13:20.64815Z"},"papermill":{"duration":14.873526,"end_time":"2024-12-11T03:22:08.818755","exception":false,"start_time":"2024-12-11T03:21:53.945229","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"The evaluation API requires that you set up a server which will respond to inference requests. We have already defined the server; you just need to write the predict function. When we evaluate your submission on the hidden test set the client defined in `konwinski_prize_gateway` will run in a different container with direct access to the hidden test set and hand off the data.\n\nYour code will always have access to the published copies of the files.","metadata":{"papermill":{"duration":0.002032,"end_time":"2024-12-11T03:22:08.823897","exception":false,"start_time":"2024-12-11T03:22:08.821865","status":"completed"},"tags":[]}},{"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":{"execution":{"iopub.status.busy":"2024-12-14T12:13:32.368832Z","iopub.execute_input":"2024-12-14T12:13:32.370094Z","iopub.status.idle":"2024-12-14T12:13:32.375243Z","shell.execute_reply.started":"2024-12-14T12:13:32.370048Z","shell.execute_reply":"2024-12-14T12:13:32.37414Z"},"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},"outputs":[],"execution_count":null},{"cell_type":"code","source":"first_prediction = True\n\n\ndef predict(problem_statement: str, repo_archive: io.BytesIO) -> 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    \"\"\"\n    # global first_prediction\n    # if not first_prediction:\n    #     return None  # Skip issue.\n\n    # # Unpack\n    # with open('repo_archive.tar', 'wb') as f:\n    #     f.write(repo_archive.read())\n    # repo_path = 'repo'\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    # first_prediction = False\n    # # Instead of a valid diff, let's just submit a generic string. This will definitely fail.\n    # return \"Hey Andy, how you doing?\"\n\n    return None","metadata":{"execution":{"iopub.status.busy":"2024-12-14T12:14:05.983551Z","iopub.execute_input":"2024-12-14T12:14:05.983994Z","iopub.status.idle":"2024-12-14T12:14:05.990432Z","shell.execute_reply.started":"2024-12-14T12:14:05.983943Z","shell.execute_reply":"2024-12-14T12:14:05.989073Z"},"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},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"When your notebook is run on the hidden test set, inference_server.serve must be called within 15 minutes of the notebook starting or the gateway will throw an error. If you need more than 15 minutes to load your model you can do so during the very first predict call, which does not have the usual 30 minute response deadline.","metadata":{"papermill":{"duration":0.001889,"end_time":"2024-12-11T03:22:08.856283","exception":false,"start_time":"2024-12-11T03:22:08.854394","status":"completed"},"tags":[]}},{"cell_type":"code","source":"inference_server = kaggle_evaluation.konwinski_prize_inference_server.KPrizeInferenceServer(\n    get_number_of_instances,   \n    predict\n)\n\nif os.getenv('KAGGLE_IS_COMPETITION_RERUN'):\n    inference_server.serve()\nelse:\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    )","metadata":{"execution":{"iopub.status.busy":"2024-12-14T12:14:09.675858Z","iopub.execute_input":"2024-12-14T12:14:09.676311Z","iopub.status.idle":"2024-12-14T12:14:17.781856Z","shell.execute_reply.started":"2024-12-14T12:14:09.67627Z","shell.execute_reply":"2024-12-14T12:14:17.780736Z"},"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},"outputs":[],"execution_count":null}]}