|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## 101 -- Developing Application with Anyscale \n", |
| 8 | + "\n", |
| 9 | + "### Introduction\n", |
| 10 | + "\n", |
| 11 | + "As introduced in the previous section, the Anyscale Workspace provides a feature rich development environment without the overhead of managing infrastructure. In this section, we’ll walk through a few different ways to develop applications within the Anyscale Workspace.\n", |
| 12 | + "\n", |
| 13 | + "- **Using the built-in VSCode Editor** to write and execute Ray applications directly in the browser \n", |
| 14 | + "- **Running interactive notebooks in JupyterLab** for exploration and rapid prototyping \n", |
| 15 | + "- **Connecting from a local IDE (e.g. VSCode, Cursor)** to develop locally while running code on remote Anyscale compute \n", |
| 16 | + "- **Using the Anyscale CLI** to sync code, submit scripts, and automate tasks \n" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "markdown", |
| 21 | + "metadata": {}, |
| 22 | + "source": [ |
| 23 | + "### VSCode\n", |
| 24 | + "\n", |
| 25 | + "One of the fastest ways to begin developing with Anyscale is to use the hosted Visual Studio Code Editor that is already running on your Anyscale Workspace. Create or open an existing **Anyscale Workspace**.\n", |
| 26 | + "\n", |
| 27 | + "\n", |
| 28 | + "After your Anyscale Workspace is started, click on the VSCode icon. This will load a new web browser window and you can start developing right away.\n", |
| 29 | + "\n", |
| 30 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development1.png\" width=\"600\"/>\n", |
| 31 | + "\n", |
| 32 | + "\n", |
| 33 | + "Create a new file: `hello_world.py`\n", |
| 34 | + "\n", |
| 35 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development2.png\" width=\"400\"/>\n", |
| 36 | + "\n", |
| 37 | + "\n", |
| 38 | + "Let’s add a simple Ray example, copy and paste the code snippet below to `hello_world.py` " |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "code", |
| 43 | + "execution_count": null, |
| 44 | + "metadata": {}, |
| 45 | + "outputs": [], |
| 46 | + "source": [ |
| 47 | + "import ray\n", |
| 48 | + "\n", |
| 49 | + "@ray.remote\n", |
| 50 | + "def hello_world():\n", |
| 51 | + " return \"Hello World!\"\n", |
| 52 | + "\n", |
| 53 | + "result = ray.get(hello_world.remote())\n", |
| 54 | + "print(result)" |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "cell_type": "markdown", |
| 59 | + "metadata": {}, |
| 60 | + "source": [ |
| 61 | + "To submit and run the Ray Application on the Anyscale Cluster, just click the Play icon in the upper-right corner of VSCode.\n", |
| 62 | + "\n", |
| 63 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development3.png\" width=\"800\"/>\n", |
| 64 | + "\n", |
| 65 | + "\n", |
| 66 | + "The Anyscale Workspace includes built-in tools to help you monitor, debug, and troubleshoot your application after it’s been submitted, including access to logs, metrics, and the Ray Dashboard. We’ll cover this in a later tutorial." |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "markdown", |
| 71 | + "metadata": {}, |
| 72 | + "source": [ |
| 73 | + "### Notebook\n", |
| 74 | + "\n", |
| 75 | + "In addition to VS Code, the **Anyscale Workspace** also includes a built-in JupyterLab environment for interactive development and data exploration.\n", |
| 76 | + "\n", |
| 77 | + "In the VSCode Tab, click the dropdown and select JupyterLab.\n", |
| 78 | + "\n", |
| 79 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development5.png\" width=\"600\"/>\n", |
| 80 | + "\n", |
| 81 | + "Once you have the JupyterLab notebook open, you can create a new file and start using Ray right away. Let’s create a `hello_world.ipynb` file by clicking on the new notebook button.\n", |
| 82 | + "\n", |
| 83 | + "- A Python notebook is an interactive document that lets you write and run code in cells, making it ideal for experimenting.\n", |
| 84 | + "\n", |
| 85 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development6.png\" width=\"600\"/>\n", |
| 86 | + "\n", |
| 87 | + "\n", |
| 88 | + "You can rename the file by right clicking on the filename `untitled.ipynb` in the left column of the screen.\n", |
| 89 | + "\n", |
| 90 | + "In a Notebook Cell, copy and Paste the code below. Run the Cell (Shift + Enter or Play Button)\n" |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + "cell_type": "code", |
| 95 | + "execution_count": null, |
| 96 | + "metadata": {}, |
| 97 | + "outputs": [], |
| 98 | + "source": [ |
| 99 | + "import ray\n", |
| 100 | + "\n", |
| 101 | + "@ray.remote\n", |
| 102 | + "def hello_world():\n", |
| 103 | + " return \"Hello World!\"\n", |
| 104 | + "\n", |
| 105 | + "result = ray.get(hello_world.remote())\n", |
| 106 | + "print(result)" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "markdown", |
| 111 | + "metadata": {}, |
| 112 | + "source": [ |
| 113 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development7.png\" width=\"800\"/>\n", |
| 114 | + "\n", |
| 115 | + "\n", |
| 116 | + "Now you can get instant feedback from your code, edit cells, re-run them, and quickly iterate as you experiment and explore." |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "markdown", |
| 121 | + "metadata": {}, |
| 122 | + "source": [ |
| 123 | + "### Local IDE (VSCode / Cursor)\n", |
| 124 | + "\n", |
| 125 | + "If you prefer to use an IDE other than VS Code or JupyterLab, you can still use Anyscale Workspaces as part of your local development workflow. Develop and test code locally in your preferred environment, then run it remotely. \n", |
| 126 | + "\n", |
| 127 | + "In this section, we’ll make extensive use of the Anyscale Workspace CLI. For a complete list of available commands and their capabilities, refer to the [official documentation](https://docs.anyscale.com/reference/workspaces).\n", |
| 128 | + "\n", |
| 129 | + "Navigate to the IDE Dropdown and choose to open remotely on **VSCode Desktop (Local).** You will then be prompted to install the **Workspaces Extension.**\n", |
| 130 | + "\n", |
| 131 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development8.png\" width=\"400\"/>\n", |
| 132 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development9.png\" width=\"600\"/>\n", |
| 133 | + "\n", |
| 134 | + "\n", |
| 135 | + "Additional Pre-reqs:\n", |
| 136 | + "\n", |
| 137 | + "- You will want to make sure that you have the latest Anyscale CLI installed locally. This can be done via `pip install anyscale --upgrade`\n", |
| 138 | + "- You will need to be [authenticated](https://docs.anyscale.com/administration/organization/user-auth/#platform-api-keys) to Anyscale from your terminal. This can be done by running `anyscale login`\n", |
| 139 | + "- You will need your Workspace in a Running state. You can start a Workspace from the Anyscale Console, or by running the following [Anyscale CLI command](https://docs.anyscale.com/reference/workspaces/#anyscale-workspace_v2-start).\n", |
| 140 | + "\n", |
| 141 | + "`anyscale workspace_v2 start --name my-workspace`\n", |
| 142 | + "\n", |
| 143 | + "\n", |
| 144 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development10.png\" width=\"800\"/>\n", |
| 145 | + "\n", |
| 146 | + "\n", |
| 147 | + "Replace my-workspace with the name of your Workspace. All the following commands will expect the Workspace to be Running.\n", |
| 148 | + "\n", |
| 149 | + "To begin developing locally, start by **pulling a Anyscale Workspace** to your machine. This command downloads the Workspace’s working directory by creating new files and overwriting any existing ones in the specified local folder.\n", |
| 150 | + "\n", |
| 151 | + "\n", |
| 152 | + "Run in command line, replace my-workspace with the name of your Workspace\n", |
| 153 | + "\n", |
| 154 | + "`anyscale workspace_v2 pull --name my-workspace`\n", |
| 155 | + "\n", |
| 156 | + "- [Pull Command Documentation](https://docs.anyscale.com/reference/workspaces#anyscale-workspace_v2-pull)\n", |
| 157 | + "\n", |
| 158 | + "When you're ready to execute your Python file (like the `hello_world.py` script created earlier) on the Workspace cluster, use the following command. Replace the placeholder python filename and workspace name. \n", |
| 159 | + "\n", |
| 160 | + "`anyscale workspace_v2 run_command --name my-workspace \"python script.py\"`\n", |
| 161 | + "\n", |
| 162 | + "<img src=\"https://lz-public-demo.s3.us-east-1.amazonaws.com/anyscale101/development11.png\" width=\"800\"/>\n", |
| 163 | + "\n", |
| 164 | + "Now your Python script is running on the cluster associated with the specified Anyscale Workspace. It will automatically push the files prior to running so there is no need to push the files beforehand. You do not need to install any dependencies locally because the execution of the command runs remotely on the cluster container." |
| 165 | + ] |
| 166 | + } |
| 167 | + ], |
| 168 | + "metadata": { |
| 169 | + "language_info": { |
| 170 | + "name": "python" |
| 171 | + } |
| 172 | + }, |
| 173 | + "nbformat": 4, |
| 174 | + "nbformat_minor": 2 |
| 175 | +} |
0 commit comments