{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9af3fa50-d1ba-4ee2-901f-9a2831f6b34f",
   "metadata": {},
   "source": [
    "# Native interaction with remote objects\n",
    "\n",
    "Every object is clear, same as cli. Access any data from remote directly in the notebook. Soon directly launch remote entities from here.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "82c78d52-d80c-4999-958e-ee6413dc10e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import flyte\n",
    "import flyte.remote as remote"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bcc5c511-47db-4220-8622-6e81fc7cbf59",
   "metadata": {},
   "outputs": [],
   "source": [
    "flyte.init(\n",
    "    endpoint=\"https://union.example.com\",\n",
    "    org=\"example_org\",\n",
    "    project=\"example_project\",\n",
    "    domain=\"development\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ac3a9867-dcf5-44ae-a886-f312c21d81a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "runs = [x.name for x in remote.Run.listall()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "542af4d4-29b6-4b5b-80f0-bc98a2714dfb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['nl4jnrt2ztwxwb4f7w44',\n",
       " 'n4x2k8nhpmms5lqc28hj',\n",
       " 'bcc66wgj5k828vl6g7zf',\n",
       " 'v898zlcbwbxv7gq9xv8x',\n",
       " 'wn6qmm897qs8nb9tmhwc',\n",
       " 'wcp5p77bx9lkb72h5wmj',\n",
       " '97dnmqxq7drb78cvlckp',\n",
       " 'tfv8hv9zxbzlsmqffx2r',\n",
       " 'zb6brkrbgf6n5pkc46lc',\n",
       " 'l8p7cxcpkbczcg6pr75k',\n",
       " 'h4wgrrrwwjqfk8wvgjjt',\n",
       " '5rxrxbwn7hk2s2v9rrbq',\n",
       " '6jgbzwr8fldr5n69lxqx',\n",
       " 'b6fkjsw68wslvgb2qbv8']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "runs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "4beeeca6-eadd-43bb-bff5-1f3185560ada",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = remote.Run.get(name=runs[-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "50cd4650-f4b1-4cc9-9129-ff304583c325",
   "metadata": {},
   "outputs": [],
   "source": [
    "d = await r.details()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "918d0fef-0020-4f47-bd1c-50cb92fac534",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ActionDetails(\n",
       "    name='6jgbzwr8fldr5n69lxqx',\n",
       "    start_time='2025-05-30T02:34:59.909675+00:00',\n",
       "    end_time='2025-05-30T03:22:00+00:00',\n",
       "    run_time='2820 secs',\n",
       "    phase='PHASE_SUCCEEDED',\n",
       "    error='NA',\n",
       "    task='cancel.main',\n",
       "    task_type='python',\n",
       "    task_version='d5014bbfef8765d86e1eb003b914d053'\n",
       ")"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.action_details"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "737c9e96-0ff3-4546-a480-e90ce38aefaf",
   "metadata": {},
   "outputs": [],
   "source": [
    "o = await d.outputs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b7883b83-fc36-4e98-a83f-50a3c186daaa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'n': 30, 'f': 10.0}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await d.inputs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "ac202f81-8ac3-4f8f-b2f2-472230af7439",
   "metadata": {},
   "outputs": [],
   "source": [
    "actions = [a.name for a in remote.Action.listall(for_run_name=\"kevin2\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5f49e4be-b4c3-4b1b-87bc-95f8f5acb27a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "actions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "6a549855-c358-4681-9222-134b32ce7372",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b502a33b3e89483c8975a0e3f3a2c034",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Output()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Exception in callback PollerCompletionQueue._handle_events(&lt;_UnixSelecto...e debug=False&gt;)()\n",
       "handle: &lt;Handle PollerCompletionQueue._handle_events(&lt;_UnixSelecto...e debug=False&gt;)()&gt;\n",
       "Traceback (most recent call last):\n",
       "  File \n",
       "\"/Users/ketanumare/.local/share/uv/python/cpython-3.12.0-macos-aarch64-none/lib/python3.12/asyncio/events.py\", line\n",
       "84, in _run\n",
       "    self._context.run(self._callback, *self._args)\n",
       "  File \"src/python/grpcio/grpc/_cython/_cygrpc/aio/completion_queue.pyx.pxi\", line 147, in \n",
       "grpc._cython.cygrpc.PollerCompletionQueue._handle_events\n",
       "BlockingIOError: [Errno 35] Resource temporarily unavailable\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Exception in callback PollerCompletionQueue._handle_events(<_UnixSelecto...e debug=False>)()\n",
       "handle: <Handle PollerCompletionQueue._handle_events(<_UnixSelecto...e debug=False>)()>\n",
       "Traceback (most recent call last):\n",
       "  File \n",
       "\"/Users/ketanumare/.local/share/uv/python/cpython-3.12.0-macos-aarch64-none/lib/python3.12/asyncio/events.py\", line\n",
       "84, in _run\n",
       "    self._context.run(self._callback, *self._args)\n",
       "  File \"src/python/grpcio/grpc/_cython/_cygrpc/aio/completion_queue.pyx.pxi\", line 147, in \n",
       "grpc._cython.cygrpc.PollerCompletionQueue._handle_events\n",
       "BlockingIOError: [Errno 35] Resource temporarily unavailable\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Exception in callback PollerCompletionQueue._handle_events(&lt;_UnixSelecto...e debug=False&gt;)()\n",
       "handle: &lt;Handle PollerCompletionQueue._handle_events(&lt;_UnixSelecto...e debug=False&gt;)()&gt;\n",
       "Traceback (most recent call last):\n",
       "  File \n",
       "\"/Users/ketanumare/.local/share/uv/python/cpython-3.12.0-macos-aarch64-none/lib/python3.12/asyncio/events.py\", line\n",
       "84, in _run\n",
       "    self._context.run(self._callback, *self._args)\n",
       "  File \"src/python/grpcio/grpc/_cython/_cygrpc/aio/completion_queue.pyx.pxi\", line 147, in \n",
       "grpc._cython.cygrpc.PollerCompletionQueue._handle_events\n",
       "BlockingIOError: [Errno 35] Resource temporarily unavailable\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Exception in callback PollerCompletionQueue._handle_events(<_UnixSelecto...e debug=False>)()\n",
       "handle: <Handle PollerCompletionQueue._handle_events(<_UnixSelecto...e debug=False>)()>\n",
       "Traceback (most recent call last):\n",
       "  File \n",
       "\"/Users/ketanumare/.local/share/uv/python/cpython-3.12.0-macos-aarch64-none/lib/python3.12/asyncio/events.py\", line\n",
       "84, in _run\n",
       "    self._context.run(self._callback, *self._args)\n",
       "  File \"src/python/grpcio/grpc/_cython/_cygrpc/aio/completion_queue.pyx.pxi\", line 147, in \n",
       "grpc._cython.cygrpc.PollerCompletionQueue._handle_events\n",
       "BlockingIOError: [Errno 35] Resource temporarily unavailable\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Exception in callback PollerCompletionQueue._handle_events(&lt;_UnixSelecto...e debug=False&gt;)()\n",
       "handle: &lt;Handle PollerCompletionQueue._handle_events(&lt;_UnixSelecto...e debug=False&gt;)()&gt;\n",
       "Traceback (most recent call last):\n",
       "  File \n",
       "\"/Users/ketanumare/.local/share/uv/python/cpython-3.12.0-macos-aarch64-none/lib/python3.12/asyncio/events.py\", line\n",
       "84, in _run\n",
       "    self._context.run(self._callback, *self._args)\n",
       "  File \"src/python/grpcio/grpc/_cython/_cygrpc/aio/completion_queue.pyx.pxi\", line 147, in \n",
       "grpc._cython.cygrpc.PollerCompletionQueue._handle_events\n",
       "BlockingIOError: [Errno 35] Resource temporarily unavailable\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Exception in callback PollerCompletionQueue._handle_events(<_UnixSelecto...e debug=False>)()\n",
       "handle: <Handle PollerCompletionQueue._handle_events(<_UnixSelecto...e debug=False>)()>\n",
       "Traceback (most recent call last):\n",
       "  File \n",
       "\"/Users/ketanumare/.local/share/uv/python/cpython-3.12.0-macos-aarch64-none/lib/python3.12/asyncio/events.py\", line\n",
       "84, in _run\n",
       "    self._context.run(self._callback, *self._args)\n",
       "  File \"src/python/grpcio/grpc/_cython/_cygrpc/aio/completion_queue.pyx.pxi\", line 147, in \n",
       "grpc._cython.cygrpc.PollerCompletionQueue._handle_events\n",
       "BlockingIOError: [Errno 35] Resource temporarily unavailable\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Scrolled <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">441</span> lines of logs.\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Scrolled \u001b[1;36m441\u001b[0m lines of logs.\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "await r.show_logs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "065b2cbc-c477-4e6d-824d-367696fac1c5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "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.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
