{"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":"code","source":"# Install local library just in case...\n# !pip install -q /kaggle/input/konwinski-prize/kprize_setup/kprize-1.0.0-py3-none-any.whl --no-index --find-links /kaggle/input/konwinski-prize/kprize_setup/pip_packages\n\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":"2025-01-09T20:19:48.534338Z","iopub.execute_input":"2025-01-09T20:19:48.534782Z","iopub.status.idle":"2025-01-09T20:19:58.78898Z","shell.execute_reply.started":"2025-01-09T20:19:48.534744Z","shell.execute_reply":"2025-01-09T20:19:58.787866Z"},"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 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":"2025-01-09T20:19:58.791272Z","iopub.execute_input":"2025-01-09T20:19:58.791668Z","iopub.status.idle":"2025-01-09T20:19:58.79878Z","shell.execute_reply.started":"2025-01-09T20:19:58.791633Z","shell.execute_reply":"2025-01-09T20:19:58.797053Z"},"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":"import astroid as local_astroid\nLOCAL_ASTROID_VERSION = local_astroid.__version__\nprint(LOCAL_ASTROID_VERSION)\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    import astroid\n    global LOCAL_ASTROID_VERSION\n\n    # If the astroid version in the env is different\n    # than this code is executing in the correct environment.\n    if LOCAL_ASTROID_VERSION==astroid.__version__:\n        return None\n    # Basically the more negative the score the more likely we have astroid\n    # examples and the env has been configured properly\n    else:\n        # Everytime we submit this we should get -0.01\n        return \"Hello World\"","metadata":{"execution":{"iopub.status.busy":"2024-12-11T08:17:30.400369Z","iopub.execute_input":"2024-12-11T08:17:30.400816Z","iopub.status.idle":"2024-12-11T08:17:30.407973Z","shell.execute_reply.started":"2024-12-11T08:17:30.400775Z","shell.execute_reply":"2024-12-11T08:17:30.406704Z"},"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-11T08:17:31.391291Z","iopub.execute_input":"2024-12-11T08:17:31.391727Z"},"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}]}