{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# SPL Framework cold start\n",
        "\n",
        "This notebook is intentionally small. It verifies that `spl-framework` imports, builds a local SPL pipeline, runs it in-process, and then optionally checks the local daemon connection."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 1. Import Framework primitives"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "from spl.core.common import Deployment, lift\n",
        "from spl.core.entities.function import DFunction, METADATA_DUNDER_NAME\n",
        "from spl.core.entities.node import InputPort, OutputPort\n",
        "\n",
        "print(\"spl-framework import ok\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 2. Define a tiny function and attach SPL metadata\n",
        "\n",
        "The explicit metadata keeps the example stable in notebook runtimes where Python source inspection can behave differently."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "def add(a: int, b: int) -> int:\n",
        "    return a + b\n",
        "\n",
        "setattr(\n",
        "    add,\n",
        "    METADATA_DUNDER_NAME,\n",
        "    DFunction(\n",
        "        name=\"add\",\n",
        "        body=\"return a + b\",\n",
        "        inputs=[InputPort(\"a\", \"int\", None), InputPort(\"b\", \"int\", None)],\n",
        "        outputs=[OutputPort(\"default\", \"int\")],\n",
        "    ),\n",
        ")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 3. Build and run a local pipeline"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "pipeline = lift(add).bind(a=40, b=2).alias(\"answer\").render(\"demo_answer\")\n",
        "answer_node = pipeline.get_node_by_alias(\"answer\")\n",
        "\n",
        "run = Deployment(pipeline).run()\n",
        "result = run[answer_node]\n",
        "result"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 4. Optional: check the local daemon\n",
        "\n",
        "Run this after installing and starting `spl-daemon`. If the daemon is not running yet, the cell explains that instead of failing the whole notebook."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "try:\n",
        "    from spl.client import SPLClient\n",
        "\n",
        "    client = SPLClient()\n",
        "    print(client._daemon.health())\n",
        "except Exception as exc:\n",
        "    print(\"Daemon is not reachable yet:\", exc)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "pygments_lexer": "ipython3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
