{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "98d7c620",
   "metadata": {},
   "source": [
    "# Logging results and uploading models to Comet ML\n",
    "In this example, we train a simple XGBoost model and log the training\n",
    "results to Comet ML. We also save the resulting model checkpoints\n",
    "as artifacts."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6e66577",
   "metadata": {},
   "source": [
    "Let's start with installing our dependencies:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6d6297ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install -qU \"ray[tune]\" sklearn xgboost_ray comet_ml"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2e21446",
   "metadata": {},
   "source": [
    "Then we need some imports:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dffff484",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ray\n",
    "\n",
    "from ray.air.config import RunConfig, ScalingConfig\n",
    "from ray.air.result import Result\n",
    "from ray.train.xgboost import XGBoostTrainer\n",
    "from ray.air.callbacks.comet import CometLoggerCallback"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29fcd93b",
   "metadata": {},
   "source": [
    "We define a simple function that returns our training dataset as a Ray Dataset:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cf830706",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_train_dataset() -> ray.data.Dataset:\n",
    "    dataset = ray.data.read_csv(\"s3://anonymous@air-example-data/breast_cancer.csv\")\n",
    "    return dataset"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f48f948",
   "metadata": {},
   "source": [
    "Now we define a simple training function. All the magic happens within the `CometLoggerCallback`:\n",
    "\n",
    "```python\n",
    "CometLoggerCallback(\n",
    "    project_name=comet_project,\n",
    "    save_checkpoints=True,\n",
    ")\n",
    "```\n",
    "\n",
    "It will automatically log all results to Comet ML and upload the checkpoints as artifacts. It assumes you're logged in into Comet via an API key or your `~./.comet.config`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "230f23a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def train_model(train_dataset: ray.data.Dataset, comet_project: str) -> Result:\n",
    "    \"\"\"Train a simple XGBoost model and return the result.\"\"\"\n",
    "    trainer = XGBoostTrainer(\n",
    "        scaling_config=ScalingConfig(num_workers=2),\n",
    "        params={\"tree_method\": \"auto\"},\n",
    "        label_column=\"target\",\n",
    "        datasets={\"train\": train_dataset},\n",
    "        num_boost_round=10,\n",
    "        run_config=RunConfig(\n",
    "            callbacks=[\n",
    "                # This is the part needed to enable logging to Comet ML.\n",
    "                # It assumes Comet ML can find a valid API (e.g. by setting\n",
    "                # the ``COMET_API_KEY`` environment variable).\n",
    "                CometLoggerCallback(\n",
    "                    project_name=comet_project,\n",
    "                    save_checkpoints=True,\n",
    "                )\n",
    "            ]\n",
    "        ),\n",
    "    )\n",
    "    result = trainer.fit()\n",
    "    return result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "711b1d7d",
   "metadata": {},
   "source": [
    "Let's kick off a run:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9bfd9a8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2022-05-19 15:19:17,237\tINFO services.py:1483 -- View the Ray dashboard at \u001b[1m\u001b[32mhttp://127.0.0.1:8265\u001b[39m\u001b[22m\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "== Status ==<br>Current time: 2022-05-19 15:19:35 (running for 00:00:14.95)<br>Memory usage on this node: 10.2/16.0 GiB<br>Using FIFO scheduling algorithm.<br>Resources requested: 0/16 CPUs, 0/0 GPUs, 0.0/5.12 GiB heap, 0.0/2.0 GiB objects<br>Result logdir: /Users/kai/ray_results/XGBoostTrainer_2022-05-19_15-19-19<br>Number of trials: 1/1 (1 TERMINATED)<br><table>\n",
       "<thead>\n",
       "<tr><th>Trial name                </th><th>status    </th><th>loc            </th><th style=\"text-align: right;\">  iter</th><th style=\"text-align: right;\">  total time (s)</th><th style=\"text-align: right;\">  train-rmse</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr><td>XGBoostTrainer_ac544_00000</td><td>TERMINATED</td><td>127.0.0.1:19852</td><td style=\"text-align: right;\">    10</td><td style=\"text-align: right;\">          9.7203</td><td style=\"text-align: right;\">    0.030717</td></tr>\n",
       "</tbody>\n",
       "</table><br><br>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "COMET WARNING: As you are running in a Jupyter environment, you will need to call `experiment.end()` when finished to ensure all metrics and code are logged before exiting.\n",
      "\u001b[2m\u001b[33m(raylet)\u001b[0m 2022-05-19 15:19:21,584\tINFO context.py:70 -- Exec'ing worker with command: exec /Users/kai/.pyenv/versions/3.7.7/bin/python3.7 /Users/kai/coding/ray/python/ray/workers/default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=61222 --object-store-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/plasma_store --raylet-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/raylet --redis-address=None --storage=None --temp-dir=/tmp/ray --metrics-agent-port=62873 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:61938 --redis-password=5241590000000000 --startup-token=16 --runtime-env-hash=-2010331134\n",
      "COMET INFO: Experiment is live on comet.ml https://www.comet.ml/krfricke/ray-air-example/ecd3726ca127497ba7386003a249fad6\n",
      "\n",
      "COMET WARNING: Failed to add tag(s) None to the experiment\n",
      "\n",
      "COMET WARNING: Empty mapping given to log_params({}); ignoring\n",
      "\u001b[2m\u001b[36m(GBDTTrainable pid=19852)\u001b[0m UserWarning: Dataset 'train' has 1 blocks, which is less than the `num_workers` 2. This dataset will be automatically repartitioned to 2 blocks.\n",
      "\u001b[2m\u001b[33m(raylet)\u001b[0m 2022-05-19 15:19:24,628\tINFO context.py:70 -- Exec'ing worker with command: exec /Users/kai/.pyenv/versions/3.7.7/bin/python3.7 /Users/kai/coding/ray/python/ray/workers/default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=61222 --object-store-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/plasma_store --raylet-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/raylet --redis-address=None --storage=None --temp-dir=/tmp/ray --metrics-agent-port=62873 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:61938 --redis-password=5241590000000000 --startup-token=17 --runtime-env-hash=-2010331069\n",
      "\u001b[2m\u001b[36m(GBDTTrainable pid=19852)\u001b[0m 2022-05-19 15:19:25,961\tINFO main.py:980 -- [RayXGBoost] Created 2 new actors (2 total actors). Waiting until actors are ready for training.\n",
      "\u001b[2m\u001b[33m(raylet)\u001b[0m 2022-05-19 15:19:26,830\tINFO context.py:70 -- Exec'ing worker with command: exec /Users/kai/.pyenv/versions/3.7.7/bin/python3.7 /Users/kai/coding/ray/python/ray/workers/default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=61222 --object-store-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/plasma_store --raylet-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/raylet --redis-address=None --storage=None --temp-dir=/tmp/ray --metrics-agent-port=62873 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:61938 --redis-password=5241590000000000 --startup-token=18 --runtime-env-hash=-2010331069\n",
      "\u001b[2m\u001b[33m(raylet)\u001b[0m 2022-05-19 15:19:26,918\tINFO context.py:70 -- Exec'ing worker with command: exec /Users/kai/.pyenv/versions/3.7.7/bin/python3.7 /Users/kai/coding/ray/python/ray/workers/default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=61222 --object-store-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/plasma_store --raylet-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/raylet --redis-address=None --storage=None --temp-dir=/tmp/ray --metrics-agent-port=62873 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:61938 --redis-password=5241590000000000 --startup-token=20 --runtime-env-hash=-2010331134\n",
      "\u001b[2m\u001b[33m(raylet)\u001b[0m 2022-05-19 15:19:26,922\tINFO context.py:70 -- Exec'ing worker with command: exec /Users/kai/.pyenv/versions/3.7.7/bin/python3.7 /Users/kai/coding/ray/python/ray/workers/default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=61222 --object-store-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/plasma_store --raylet-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/raylet --redis-address=None --storage=None --temp-dir=/tmp/ray --metrics-agent-port=62873 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:61938 --redis-password=5241590000000000 --startup-token=21 --runtime-env-hash=-2010331134\n",
      "\u001b[2m\u001b[33m(raylet)\u001b[0m 2022-05-19 15:19:26,922\tINFO context.py:70 -- Exec'ing worker with command: exec /Users/kai/.pyenv/versions/3.7.7/bin/python3.7 /Users/kai/coding/ray/python/ray/workers/default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=61222 --object-store-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/plasma_store --raylet-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/raylet --redis-address=None --storage=None --temp-dir=/tmp/ray --metrics-agent-port=62873 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:61938 --redis-password=5241590000000000 --startup-token=22 --runtime-env-hash=-2010331134\n",
      "\u001b[2m\u001b[33m(raylet)\u001b[0m 2022-05-19 15:19:26,923\tINFO context.py:70 -- Exec'ing worker with command: exec /Users/kai/.pyenv/versions/3.7.7/bin/python3.7 /Users/kai/coding/ray/python/ray/workers/default_worker.py --node-ip-address=127.0.0.1 --node-manager-port=61222 --object-store-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/plasma_store --raylet-name=/tmp/ray/session_2022-05-19_15-19-14_632568_19778/sockets/raylet --redis-address=None --storage=None --temp-dir=/tmp/ray --metrics-agent-port=62873 --logging-rotate-bytes=536870912 --logging-rotate-backup-count=5 --gcs-address=127.0.0.1:61938 --redis-password=5241590000000000 --startup-token=19 --runtime-env-hash=-2010331134\n",
      "\u001b[2m\u001b[36m(GBDTTrainable pid=19852)\u001b[0m 2022-05-19 15:19:29,272\tINFO main.py:1025 -- [RayXGBoost] Starting XGBoost training.\n",
      "\u001b[2m\u001b[36m(_RemoteRayXGBoostActor pid=19876)\u001b[0m [15:19:29] task [xgboost.ray]:4505889744 got new rank 1\n",
      "\u001b[2m\u001b[36m(_RemoteRayXGBoostActor pid=19875)\u001b[0m [15:19:29] task [xgboost.ray]:6941849424 got new rank 0\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 1.0.0 created\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Result for XGBoostTrainer_ac544_00000:\n",
      "  date: 2022-05-19_15-19-30\n",
      "  done: false\n",
      "  experiment_id: d3007bd6a2734b328fd90385485c5a8d\n",
      "  hostname: Kais-MacBook-Pro.local\n",
      "  iterations_since_restore: 1\n",
      "  node_ip: 127.0.0.1\n",
      "  pid: 19852\n",
      "  should_checkpoint: true\n",
      "  time_since_restore: 6.529659032821655\n",
      "  time_this_iter_s: 6.529659032821655\n",
      "  time_total_s: 6.529659032821655\n",
      "  timestamp: 1652969970\n",
      "  timesteps_since_restore: 0\n",
      "  train-rmse: 0.357284\n",
      "  training_iteration: 1\n",
      "  trial_id: ac544_00000\n",
      "  warmup_time: 0.003961086273193359\n",
      "  \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "COMET INFO: Scheduling the upload of 3 assets for a size of 2.48 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:1.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 2.0.0 created (previous was: 1.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 3.86 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:2.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 3.0.0 created (previous was: 2.0.0)\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:1.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 5.31 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:3.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 4.0.0 created (previous was: 3.0.0)\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:2.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 6.76 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:4.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 5.0.0 created (previous was: 4.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 8.21 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:3.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:5.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:4.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 6.0.0 created (previous was: 5.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 9.87 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:6.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:5.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 7.0.0 created (previous was: 6.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 11.46 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:7.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:6.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 8.0.0 created (previous was: 7.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 12.84 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:8.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:7.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 9.0.0 created (previous was: 8.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 14.36 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:9.0.0' has started uploading asynchronously\n",
      "COMET WARNING: The given value of the metric episodes_total was None; ignoring\n",
      "COMET WARNING: The given value of the metric timesteps_total was None; ignoring\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:8.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 10.0.0 created (previous was: 9.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 16.37 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:10.0.0' has started uploading asynchronously\n",
      "\u001b[2m\u001b[36m(GBDTTrainable pid=19852)\u001b[0m 2022-05-19 15:19:33,890\tINFO main.py:1519 -- [RayXGBoost] Finished XGBoost training on training data with total N=569 in 7.96 seconds (4.61 pure XGBoost training time).\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:9.0.0' has been fully uploaded successfully\n",
      "COMET INFO: Artifact 'checkpoint_XGBoostTrainer_ac544_00000' version 11.0.0 created (previous was: 10.0.0)\n",
      "COMET INFO: Scheduling the upload of 3 assets for a size of 16.39 KB, this can take some time\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:11.0.0' has started uploading asynchronously\n",
      "COMET INFO: ---------------------------\n",
      "COMET INFO: Comet.ml Experiment Summary\n",
      "COMET INFO: ---------------------------\n",
      "COMET INFO:   Data:\n",
      "COMET INFO:     display_summary_level : 1\n",
      "COMET INFO:     url                   : https://www.comet.ml/krfricke/ray-air-example/ecd3726ca127497ba7386003a249fad6\n",
      "COMET INFO:   Metrics [count] (min, max):\n",
      "COMET INFO:     iterations_since_restore [10] : (1, 10)\n",
      "COMET INFO:     time_since_restore [10]       : (6.529659032821655, 9.720295906066895)\n",
      "COMET INFO:     time_this_iter_s [10]         : (0.3124058246612549, 6.529659032821655)\n",
      "COMET INFO:     time_total_s [10]             : (6.529659032821655, 9.720295906066895)\n",
      "COMET INFO:     timestamp [10]                : (1652969970, 1652969973)\n",
      "COMET INFO:     timesteps_since_restore       : 0\n",
      "COMET INFO:     train-rmse [10]               : (0.030717, 0.357284)\n",
      "COMET INFO:     training_iteration [10]       : (1, 10)\n",
      "COMET INFO:     warmup_time                   : 0.003961086273193359\n",
      "COMET INFO:   Others:\n",
      "COMET INFO:     Created from  : Ray\n",
      "COMET INFO:     Name          : XGBoostTrainer_ac544_00000\n",
      "COMET INFO:     experiment_id : d3007bd6a2734b328fd90385485c5a8d\n",
      "COMET INFO:     trial_id      : ac544_00000\n",
      "COMET INFO:   System Information:\n",
      "COMET INFO:     date     : 2022-05-19_15-19-33\n",
      "COMET INFO:     hostname : Kais-MacBook-Pro.local\n",
      "COMET INFO:     node_ip  : 127.0.0.1\n",
      "COMET INFO:     pid      : 19852\n",
      "COMET INFO:   Uploads:\n",
      "COMET INFO:     artifact assets     : 33 (107.92 KB)\n",
      "COMET INFO:     artifacts           : 11\n",
      "COMET INFO:     environment details : 1\n",
      "COMET INFO:     filename            : 1\n",
      "COMET INFO:     installed packages  : 1\n",
      "COMET INFO:     notebook            : 1\n",
      "COMET INFO:     source_code         : 1\n",
      "COMET INFO: ---------------------------\n",
      "COMET INFO: Uploading metrics, params, and assets to Comet before program termination (may take several seconds)\n",
      "COMET INFO: The Python SDK has 3600 seconds to finish before aborting...\n",
      "COMET INFO: Waiting for completion of the file uploads (may take several seconds)\n",
      "COMET INFO: The Python SDK has 10800 seconds to finish before aborting...\n",
      "COMET INFO: Still uploading 6 file(s), remaining 21.05 KB/116.69 KB\n",
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:10.0.0' has been fully uploaded successfully\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "COMET INFO: Artifact 'krfricke/checkpoint_XGBoostTrainer_ac544_00000:11.0.0' has been fully uploaded successfully\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Result for XGBoostTrainer_ac544_00000:\n",
      "  date: 2022-05-19_15-19-33\n",
      "  done: true\n",
      "  experiment_id: d3007bd6a2734b328fd90385485c5a8d\n",
      "  experiment_tag: '0'\n",
      "  hostname: Kais-MacBook-Pro.local\n",
      "  iterations_since_restore: 10\n",
      "  node_ip: 127.0.0.1\n",
      "  pid: 19852\n",
      "  should_checkpoint: true\n",
      "  time_since_restore: 9.720295906066895\n",
      "  time_this_iter_s: 0.39761900901794434\n",
      "  time_total_s: 9.720295906066895\n",
      "  timestamp: 1652969973\n",
      "  timesteps_since_restore: 0\n",
      "  train-rmse: 0.030717\n",
      "  training_iteration: 10\n",
      "  trial_id: ac544_00000\n",
      "  warmup_time: 0.003961086273193359\n",
      "  \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2022-05-19 15:19:35,621\tINFO tune.py:753 -- Total run time: 15.75 seconds (14.94 seconds for the tuning loop).\n"
     ]
    }
   ],
   "source": [
    "comet_project = \"ray_air_example\"\n",
    "\n",
    "train_dataset = get_train_dataset()\n",
    "result = train_model(train_dataset=train_dataset, comet_project=comet_project)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be28bdd3",
   "metadata": {},
   "source": [
    "Check out your [Comet ML](https://www.comet.ml/) project to see the results!"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}