{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Welcome to the Graviton SDK\n", "This notebook demonstrates the professional workflow for the Graviton Supercomputing Platform.\n", "\n", "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/CodeZeroLabs/graviton-examples/blob/master/graviton_sdk_example.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 1. Install the Graviton SDK\n", "!pip install graviton-sdk" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sympy as sp\n", "import graviton as gv\n", "\n", "# 2. Authenticate (Use the public evaluation key for prototyping)\n", "gv.login(\"a-little-more-art-than-science\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interactive Evaluation\n", "Define a complex mathematical model and evaluate it to see cost and processing time estimates." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x, y = sp.symbols('x y')\n", "f = sp.sin(x)**2 + sp.exp(-y) * sp.cos(x)\n", "\n", "gv.evaluate(f, options={\"inputs\": {\"x\": 1.0, \"y\": 2.5}})\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Programmatic Workflow\n", "For advanced integrations, you can use the same `evaluate()` method with options to get structured JSON data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 1. Evaluate with JSON response format\n", "eval_data = gv.evaluate(f, options={\"type\": \"JSON\", \"inputs\": {\"x\": 1.0, \"y\": 2.5}})\n", "\n", "# 2. Use flattened access for cost and ID\n", "cost = eval_data[\"cost\"]\n", "job_id = eval_data[\"id\"]\n", "\n", "print(f\"Estimated Cost: {cost:.2f} credits\")\n", "print(f\"Available Credits: {gv.session.get_status().get(\"credits\", 0):.2f}\")\n", "\n", "# 3. Compute using the ID directly\n", "if cost > gv.session.get_status().get(\"credits\", 0):\n", " # Note: auto_charge requires a payment method configured in your dashboard\n", " job = gv.compute(job_id, options={\"auto_charge\": True})\n", "else:\n", " job = gv.compute(job_id)\n", "\n", "print(f\"Job ID: {job.job_id}\")\n", "print(f\"Result: {job.wait()}\")" ] } ], "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", "nbformat_minor": 4, "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 4 }