{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# {{ experiment_name | replace('_', ' ') | title }}\n",
    "\n",
    "{{ experiment_description }}\n",
    "\n",
    "Generated by: `madsci new experiment --modality notebook`\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "Import dependencies and create the experiment instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from madsci.common.types.experiment_types import ExperimentDesign\n",
    "from madsci.experiment_application import ExperimentNotebook\n",
    "\n",
    "\n",
    "class {{ experiment_name | pascal_case }}Experiment(ExperimentNotebook):\n",
    "    \"\"\"{{ experiment_description }}\"\"\"\n",
    "\n",
    "    experiment_design = ExperimentDesign(\n",
    "        experiment_name=\"{{ experiment_name | replace('_', ' ') | title }}\",\n",
    "        experiment_description=\"{{ experiment_description }}\",\n",
    "    )\n",
    "\n",
    "\n",
    "# Create the experiment instance\n",
    "exp = {{ experiment_name | pascal_case }}Experiment(\n",
    "    lab_server_url=\"{{ lab_server_url }}\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Start Experiment\n",
    "\n",
    "Start the experiment run. This registers the experiment with the server."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "exp.start(run_name=\"Initial Run\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Experiment Steps\n",
    "\n",
    "Add your experiment logic in the cells below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example: Run a workflow\n",
    "# result = exp.run_workflow(\n",
    "#     workflow_name=\"my_workflow\",\n",
    "#     parameters={\"param1\": \"value1\"},\n",
    "# )\n",
    "\n",
    "# Example: Log an event\n",
    "exp.logger.info(\"Executing experiment step 1\")\n",
    "\n",
    "# Your experiment logic here\n",
    "result = {\"status\": \"success\", \"message\": \"Step 1 complete\"}\n",
    "\n",
    "# Display the result\n",
    "exp.display(result, title=\"Step 1 Result\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add more experiment steps as needed\n",
    "exp.logger.info(\"Executing experiment step 2\")\n",
    "\n",
    "# Your additional experiment logic here\n",
    "final_result = {\"status\": \"completed\", \"data\": {}}\n",
    "\n",
    "exp.display(final_result, title=\"Final Result\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## End Experiment\n",
    "\n",
    "End the experiment run. This finalizes the experiment record on the server."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "exp.end()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Alternative: Context Manager Pattern\n",
    "\n",
    "For simpler experiments, you can use the context manager pattern\n",
    "which automatically handles start/end:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Alternative pattern using context manager\n",
    "# with {{ experiment_name | pascal_case }}Experiment() as exp:\n",
    "#     result = exp.run_workflow(\"my_workflow\")\n",
    "#     exp.display(result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.10.0"
  },
  "madsci": {
   "experiment_name": "{{ experiment_name }}",
   "template_version": "{{ template_version }}"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
