From d4e22ccbf2b731aa683d0c4f76c65687b8d7ddeb Mon Sep 17 00:00:00 2001 From: Ryan Lovett Date: Mon, 7 Oct 2024 22:08:07 -0700 Subject: [PATCH] Convert code cells to markdown code-cells. This lets us hide input and only show the calculator. --- workflow/calculate-compute-cost.ipynb | 111 +++++++++++++------------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/workflow/calculate-compute-cost.ipynb b/workflow/calculate-compute-cost.ipynb index 3b7480d..e11f659 100644 --- a/workflow/calculate-compute-cost.ipynb +++ b/workflow/calculate-compute-cost.ipynb @@ -2,65 +2,75 @@ "cells": [ { "cell_type": "markdown", - "id": "d3e5b963-b7e9-4ee1-8732-a56da4dc8149", + "id": "0d5aa25a-939c-44b3-9781-9ac9161ea629", "metadata": {}, "source": [ - "# GCP cloud cost simulator widget\n", - "\n", - "\n", - "This interactive widget allows you to calculate the cost for running CPU heavy workloads in standard virtual machine vs CPU optimized machine" + "---\n", + "title: GCP cloud cost simulator widget\n", + "---" ] }, { - "cell_type": "code", - "execution_count": 1, - "id": "92feae99-edd5-4d23-bbac-0693a4e77087", + "cell_type": "markdown", + "id": "8e1ab363-88e7-49a5-9690-b2625e955d0c", "metadata": {}, - "outputs": [], "source": [ + "Enable computation on this page ⏻, then execute it ►, to display an interactive calculator. It can show you the cost for running CPU heavy workloads in standard virtual machines versus CPU optimized machines." + ] + }, + { + "cell_type": "markdown", + "id": "f7ef6b11-dfb6-402c-b439-b753b647aa70", + "metadata": {}, + "source": [ + "```{code-cell} python\n", + ":tags: remove-input\n", "import sys\n", "\n", "# Check if running inside JupyterLite (Pyodide)\n", "if \"pyodide\" in sys.modules:\n", " import micropip\n", " # Install ipywidgets in JupyterLite\n", - " await micropip.install(\"ipywidgets\")" + " await micropip.install(\"ipywidgets\")\n", + "```" ] }, { - "cell_type": "code", - "execution_count": 2, - "id": "aeeb8fae-5f5f-4d2e-b344-f6e4d2ab0140", + "cell_type": "markdown", + "id": "33edc772-b562-4f23-baf6-58b492df5cfd", "metadata": {}, - "outputs": [], "source": [ + "```{code-cell} python\n", + ":tags: remove-input\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", - "from ipywidgets import Layout" + "from ipywidgets import Layout\n", + "```" ] }, { - "cell_type": "code", - "execution_count": 3, - "id": "46998d91-adbd-4ddf-b7ef-478db83ab347", + "cell_type": "markdown", + "id": "f052e711-5bc5-4b30-9fad-78d04dad882c", "metadata": {}, - "outputs": [], "source": [ + "```{code-cell} python\n", + ":tags: remove-input\n", "# Pricing data for the latest instance costs in the Iowa Central region (us-central1)\n", "NODE_PRICING = {\n", " 'n2-highcpu-32': 27.93, # Latest price for n2-highcpu-32\n", " 'n2-highcpu-96': 83.73, # Latest price for n2-highcpu-96\n", " 'n2-highmem-32': 50.31, # Latest price for n2-highmem-32\n", - "}" + "}\n", + "```" ] }, { - "cell_type": "code", - "execution_count": 4, - "id": "63660908-e767-484c-80e6-aadd8dd20f9c", + "cell_type": "markdown", + "id": "2bb13dc7-d842-4e6a-8a4a-7e26acfa3048", "metadata": {}, - "outputs": [], "source": [ + "```{code-cell} python\n", + ":tags: remove-input\n", "# Function to calculate the total number of nodes and total cost\n", "def calculate_total_cost(node_type, num_cpus, num_students, num_days):\n", " # Extract the number of CPUs in the node from the node type (e.g., 32 or 96)\n", @@ -91,16 +101,17 @@ " total_nodes, total_cost = calculate_total_cost(node_type, num_cpus, num_students, num_days)\n", " \n", " # Show result in text box\n", - " result_text.value = f\"Total nodes allocated: {total_nodes:.2f}\\nTotal cost for {num_days} days: ${total_cost:.2f}\"" + " result_text.value = f\"Total nodes allocated: {total_nodes:.2f}\\nTotal cost for {num_days} days: ${total_cost:.2f}\"\n", + "```" ] }, { - "cell_type": "code", - "execution_count": 5, - "id": "d4ea709b-8bc3-437b-8aee-09a4fdbc815c", + "cell_type": "markdown", + "id": "7fab467f-78c3-44f8-81e0-24882de1e969", "metadata": {}, - "outputs": [], "source": [ + "```{code-cell} python\n", + ":tags: remove-input\n", "# Widget elements\n", "node_type_dropdown = widgets.Dropdown(\n", " options=['n2-highcpu-32', 'n2-highcpu-96', 'n2-highmem-32'],\n", @@ -130,16 +141,17 @@ " description='Number of Days:',\n", " style={'description_width': 'auto'},\n", " layout=Layout(width='50%', padding='1em')\n", - ")" + ")\n", + "```" ] }, { - "cell_type": "code", - "execution_count": 6, - "id": "851f2d83-ad88-46fc-b74e-d390b627398e", + "cell_type": "markdown", + "id": "1ae0d62f-694d-4bca-9623-fc8031c27679", "metadata": {}, - "outputs": [], "source": [ + "```{code-cell} python\n", + ":tags: remove-input\n", "calculate_button = widgets.Button(\n", " description='Calculate Total Cost',\n", " button_style='success',\n", @@ -166,33 +178,20 @@ " input_columns,\n", " #calculate_button,\n", " result_text\n", - "], layout=Layout(padding='1em'))" + "], layout=Layout(padding='1em'))\n", + "```" ] }, { - "cell_type": "code", - "execution_count": 7, - "id": "77d7aee6-3179-4557-928c-18186b40ce18", + "cell_type": "markdown", + "id": "36f11156-c283-429e-98b0-a641912425ff", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "3c3c8eddd397422faf311f576d5ceadd", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "VBox(children=(VBox(children=(Dropdown(description='Node Type:', layout=Layout(padding='1em', width='50%'), op…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], "source": [ + "```{code-cell} python\n", + ":tags: remove-input\n", "# Display the entire widget setup\n", - "display(final_layout)" + "display(final_layout)\n", + "```" ] }, { @@ -220,7 +219,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.6" } }, "nbformat": 4,