{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# Kernel Check\n\nRun these cells to verify which Python runtime you're connected to — **Local (Pyodide/WASM)** or a **Remote Jupyter Kernel**.\n\nEach cell is self-contained — you can run them individually or all at once."
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "import sys\n",
    "import platform\n",
    "\n",
    "print(f\"Platform:        {sys.platform}\")\n",
    "print(f\"OS:              {platform.system()} {platform.release()}\")\n",
    "print(f\"Implementation:  {platform.python_implementation()}\")\n",
    "print(f\"Python version:  {platform.python_version()}\")\n",
    "print(f\"Executable:      {sys.executable or '(none — WASM)'}\")\n",
    "print()\n",
    "\n",
    "if sys.platform == \"emscripten\":\n",
    "    print(\">>> You are running on LOCAL Pyodide (WebAssembly)\")\n",
    "else:\n",
    "    print(f\">>> You are running on a REMOTE Jupyter kernel ({platform.system()})\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CPU & Memory"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import sys\nimport os\n\ncpu_count = os.cpu_count()\nprint(f\"CPU cores:  {cpu_count}\")\n\n# Memory info (remote only — Pyodide won't have /proc)\ntry:\n    import resource\n    mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss\n    # macOS reports in bytes, Linux in kilobytes\n    if sys.platform == \"darwin\":\n        print(f\"Peak memory: {mem / 1024 / 1024:.1f} MB\")\n    else:\n        print(f\"Peak memory: {mem / 1024:.1f} MB\")\nexcept Exception:\n    print(\"Peak memory: (not available on this platform)\")",
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Installed Packages"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "import importlib\n",
    "\n",
    "packages = [\"numpy\", \"pandas\", \"matplotlib\", \"scipy\", \"sklearn\", \"torch\", \"requests\"]\n",
    "\n",
    "for pkg in packages:\n",
    "    try:\n",
    "        mod = importlib.import_module(pkg)\n",
    "        ver = getattr(mod, \"__version__\", \"?\")\n",
    "        print(f\"  {pkg:15s} {ver}\")\n",
    "    except ImportError:\n",
    "        print(f\"  {pkg:15s} (not installed)\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Network Access (Remote Only)\n",
    "\n",
    "Remote kernels have real network access. Pyodide cannot make outbound connections."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "try:\n",
    "    import urllib.request\n",
    "    resp = urllib.request.urlopen(\"https://httpbin.org/ip\", timeout=5)\n",
    "    data = resp.read().decode()\n",
    "    print(f\"Network access: YES\")\n",
    "    print(f\"Response: {data.strip()}\")\n",
    "except Exception as e:\n",
    "    print(f\"Network access: NO ({type(e).__name__})\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Quick Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import sys\nimport time\n\n# Simple CPU benchmark — sum of squares\nn = 1_000_000\nstart = time.perf_counter()\ntotal = sum(i * i for i in range(n))\nelapsed = time.perf_counter() - start\n\nprint(f\"Sum of squares (n={n:,}): {elapsed:.3f}s\")\nprint(f\"Result: {total:,}\")\nprint()\n\nif sys.platform == \"emscripten\":\n    print(\"Tip: Remote kernels are typically 5-10x faster for CPU-bound work.\")\nelse:\n    print(\"Running on native Python — full CPU speed.\")",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}