{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9e70e230-d5a7-4aea-bfd0-6cf0190d44bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "from pathlib import Path\n",
    "\n",
    "from fabrictestbed_extensions.fablib.fablib import FablibManager\n",
    "\n",
    "fablib = FablibManager()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "563e3c59-fecf-4409-b8ac-6a663f6df5f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "#SCRIPT_DIR = Path(__file__).resolve().parent\n",
    "TOOLS_DIR = \"tools\" #SCRIPT_DIR / \"tools\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "22a323d4-4eec-47a1-9c12-71d087183c76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "User: sankarang@renci.org bastion key is valid!\n",
      "Configuration is valid\n"
     ]
    }
   ],
   "source": [
    "my_slice = fablib.get_slice(\"sequence-experiment-lab\")\n",
    "node = my_slice.get_node(name=\"simulator\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "864cc396-b4c7-4e13-bd76-9d323f80268f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'success'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#node.execute(\"mkdir -p ~/tools/topologies\", quiet=True)\n",
    "node.upload_directory(str(TOOLS_DIR), \".\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0433acee-a800-4eb8-a260-bc314027b810",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "def _run_or_fail(node, command: str, step_msg: str) -> str:\n",
    "    print(step_msg)\n",
    "    stdout, stderr = node.execute(command, quiet=True)\n",
    "    if stderr.strip():\n",
    "        print(stderr.strip())\n",
    "    return stdout"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2b46ce35-8c63-4b65-b327-8b3c9becfe37",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "### PROGRESS: Step 4/5 - Installing SeQUeNCe and dependencies...\n",
      "  Installing Python runtime and SeQUeNCe package...\n",
      "Running kernel seems to be up-to-date.\n",
      "\n",
      "Restarting services...\n",
      " systemctl restart multipathd.service packagekit.service polkit.service\n",
      "\n",
      "Service restarts being deferred:\n",
      " /etc/needrestart/restart.d/dbus.service\n",
      " systemctl restart unattended-upgrades.service\n",
      "\n",
      "No containers need to be restarted.\n",
      "\n",
      "No user sessions are running outdated binaries.\n",
      "\n",
      "No VM guests are running outdated hypervisor (qemu) binaries on this host.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'(Reading database ... \\r(Reading database ... 5%\\r(Reading database ... 10%\\r(Reading database ... 15%\\r(Reading database ... 20%\\r(Reading database ... 25%\\r(Reading database ... 30%\\r(Reading database ... 35%\\r(Reading database ... 40%\\r(Reading database ... 45%\\r(Reading database ... 50%\\r(Reading database ... 55%\\r(Reading database ... 60%\\r(Reading database ... 65%\\r(Reading database ... 70%\\r(Reading database ... 75%\\r(Reading database ... 80%\\r(Reading database ... 85%\\r(Reading database ... 90%\\r(Reading database ... 95%\\r(Reading database ... 100%\\r(Reading database ... 74797 files and directories currently installed.)\\r\\nPreparing to unpack .../dpkg_1.22.6ubuntu6.6_amd64.deb ...\\r\\nUnpacking dpkg (1.22.6ubuntu6.6) over (1.22.6ubuntu6.1) ...\\r\\nSetting up dpkg (1.22.6ubuntu6.6) ...\\r\\n(Reading database ... \\r(Reading database ... 5%\\r(Reading database ... 10%\\r(Reading database ... 15%\\r(Reading database ... 20%\\r(Reading database ... 25%\\r(Reading database ... 30%\\r(Reading database ... 35%\\r(Reading database ... 40%\\r(Reading database ... 45%\\r(Reading database ... 50%\\r(Reading database ... 55%\\r(Reading database ... 60%\\r(Reading database ... 65%\\r(Reading database ... 70%\\r(Reading database ... 75%\\r(Reading database ... 80%\\r(Reading database ... 85%\\r(Reading database ... 90%\\r(Reading database ... 95%\\r(Reading database ... 100%\\r(Reading database ... 74797 files and directories currently installed.)\\r\\nPreparing to unpack .../python3-minimal_3.12.3-0ubuntu2.1_amd64.deb ...\\r\\nUnpacking python3-minimal (3.12.3-0ubuntu2.1) over (3.12.3-0ubuntu2) ...\\r\\nSetting up python3-minimal (3.12.3-0ubuntu2.1) ...\\r\\n(Reading database ... \\r(Reading database ... 5%\\r(Reading database ... 10%\\r(Reading database ... 15%\\r(Reading database ... 20%\\r(Reading database ... 25%\\r(Reading database ... 30%\\r(Reading database ... 35%\\r(Reading database ... 40%\\r(Reading database ... 45%\\r(Reading database ... 50%\\r(Reading database ... 55%\\r(Reading database ... 60%\\r(Reading database ... 65%\\r(Reading database ... 70%\\r(Reading database ... 75%\\r(Reading database ... 80%\\r(Reading database ... 85%\\r(Reading database ... 90%\\r(Reading database ... 95%\\r(Reading database ... 100%\\r(Reading database ... 74797 files and directories currently installed.)\\r\\nPreparing to unpack .../0-python3_3.12.3-0ubuntu2.1_amd64.deb ...\\r\\nUnpacking python3 (3.12.3-0ubuntu2.1) over (3.12.3-0ubuntu2) ...\\r\\nPreparing to unpack .../1-libexpat1_2.6.1-2ubuntu0.4_amd64.deb ...\\r\\nUnpacking libexpat1:amd64 (2.6.1-2ubuntu0.4) over (2.6.1-2ubuntu0.3) ...\\r\\nPreparing to unpack .../2-libpython3.12t64_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking libpython3.12t64:amd64 (3.12.3-1ubuntu0.13) over (3.12.3-1ubuntu0.7) ...\\r\\nPreparing to unpack .../3-python3.12_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking python3.12 (3.12.3-1ubuntu0.13) over (3.12.3-1ubuntu0.7) ...\\r\\nPreparing to unpack .../4-libpython3.12-stdlib_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking libpython3.12-stdlib:amd64 (3.12.3-1ubuntu0.13) over (3.12.3-1ubuntu0.7) ...\\r\\nPreparing to unpack .../5-python3.12-minimal_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking python3.12-minimal (3.12.3-1ubuntu0.13) over (3.12.3-1ubuntu0.7) ...\\r\\nPreparing to unpack .../6-libpython3.12-minimal_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking libpython3.12-minimal:amd64 (3.12.3-1ubuntu0.13) over (3.12.3-1ubuntu0.7) ...\\r\\nPreparing to unpack .../7-libpython3-stdlib_3.12.3-0ubuntu2.1_amd64.deb ...\\r\\nUnpacking libpython3-stdlib:amd64 (3.12.3-0ubuntu2.1) over (3.12.3-0ubuntu2) ...\\r\\nPreparing to unpack .../8-gcc-14-base_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking gcc-14-base:amd64 (14.2.0-4ubuntu2~24.04.1) over (14.2.0-4ubuntu2~24.04) ...\\r\\nSetting up gcc-14-base:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\n(Reading database ... \\r(Reading database ... 5%\\r(Reading database ... 10%\\r(Reading database ... 15%\\r(Reading database ... 20%\\r(Reading database ... 25%\\r(Reading database ... 30%\\r(Reading database ... 35%\\r(Reading database ... 40%\\r(Reading database ... 45%\\r(Reading database ... 50%\\r(Reading database ... 55%\\r(Reading database ... 60%\\r(Reading database ... 65%\\r(Reading database ... 70%\\r(Reading database ... 75%\\r(Reading database ... 80%\\r(Reading database ... 85%\\r(Reading database ... 90%\\r(Reading database ... 95%\\r(Reading database ... 100%\\r(Reading database ... 74797 files and directories currently installed.)\\r\\nPreparing to unpack .../libstdc++6_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libstdc++6:amd64 (14.2.0-4ubuntu2~24.04.1) over (14.2.0-4ubuntu2~24.04) ...\\r\\nSetting up libstdc++6:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\n(Reading database ... \\r(Reading database ... 5%\\r(Reading database ... 10%\\r(Reading database ... 15%\\r(Reading database ... 20%\\r(Reading database ... 25%\\r(Reading database ... 30%\\r(Reading database ... 35%\\r(Reading database ... 40%\\r(Reading database ... 45%\\r(Reading database ... 50%\\r(Reading database ... 55%\\r(Reading database ... 60%\\r(Reading database ... 65%\\r(Reading database ... 70%\\r(Reading database ... 75%\\r(Reading database ... 80%\\r(Reading database ... 85%\\r(Reading database ... 90%\\r(Reading database ... 95%\\r(Reading database ... 100%\\r(Reading database ... 74797 files and directories currently installed.)\\r\\nPreparing to unpack .../libgcc-s1_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libgcc-s1:amd64 (14.2.0-4ubuntu2~24.04.1) over (14.2.0-4ubuntu2~24.04) ...\\r\\nSetting up libgcc-s1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package binutils-common:amd64.\\r\\n(Reading database ... \\r(Reading database ... 5%\\r(Reading database ... 10%\\r(Reading database ... 15%\\r(Reading database ... 20%\\r(Reading database ... 25%\\r(Reading database ... 30%\\r(Reading database ... 35%\\r(Reading database ... 40%\\r(Reading database ... 45%\\r(Reading database ... 50%\\r(Reading database ... 55%\\r(Reading database ... 60%\\r(Reading database ... 65%\\r(Reading database ... 70%\\r(Reading database ... 75%\\r(Reading database ... 80%\\r(Reading database ... 85%\\r(Reading database ... 90%\\r(Reading database ... 95%\\r(Reading database ... 100%\\r(Reading database ... 74797 files and directories currently installed.)\\r\\nPreparing to unpack .../00-binutils-common_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking binutils-common:amd64 (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package libsframe1:amd64.\\r\\nPreparing to unpack .../01-libsframe1_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking libsframe1:amd64 (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package libbinutils:amd64.\\r\\nPreparing to unpack .../02-libbinutils_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking libbinutils:amd64 (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package libctf-nobfd0:amd64.\\r\\nPreparing to unpack .../03-libctf-nobfd0_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking libctf-nobfd0:amd64 (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package libctf0:amd64.\\r\\nPreparing to unpack .../04-libctf0_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking libctf0:amd64 (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package libgprofng0:amd64.\\r\\nPreparing to unpack .../05-libgprofng0_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking libgprofng0:amd64 (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package binutils-x86-64-linux-gnu.\\r\\nPreparing to unpack .../06-binutils-x86-64-linux-gnu_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking binutils-x86-64-linux-gnu (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package binutils.\\r\\nPreparing to unpack .../07-binutils_2.42-4ubuntu2.10_amd64.deb ...\\r\\nUnpacking binutils (2.42-4ubuntu2.10) ...\\r\\nSelecting previously unselected package gcc-13-base:amd64.\\r\\nPreparing to unpack .../08-gcc-13-base_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking gcc-13-base:amd64 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libisl23:amd64.\\r\\nPreparing to unpack .../09-libisl23_0.26-3build1.1_amd64.deb ...\\r\\nUnpacking libisl23:amd64 (0.26-3build1.1) ...\\r\\nSelecting previously unselected package libmpc3:amd64.\\r\\nPreparing to unpack .../10-libmpc3_1.3.1-1build1.1_amd64.deb ...\\r\\nUnpacking libmpc3:amd64 (1.3.1-1build1.1) ...\\r\\nSelecting previously unselected package cpp-13-x86-64-linux-gnu.\\r\\nPreparing to unpack .../11-cpp-13-x86-64-linux-gnu_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking cpp-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package cpp-13.\\r\\nPreparing to unpack .../12-cpp-13_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking cpp-13 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package cpp-x86-64-linux-gnu.\\r\\nPreparing to unpack .../13-cpp-x86-64-linux-gnu_4%3a13.2.0-7ubuntu1_amd64.deb ...\\r\\nUnpacking cpp-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...\\r\\nSelecting previously unselected package cpp.\\r\\nPreparing to unpack .../14-cpp_4%3a13.2.0-7ubuntu1_amd64.deb ...\\r\\nUnpacking cpp (4:13.2.0-7ubuntu1) ...\\r\\nSelecting previously unselected package libcc1-0:amd64.\\r\\nPreparing to unpack .../15-libcc1-0_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libcc1-0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libgomp1:amd64.\\r\\nPreparing to unpack .../16-libgomp1_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libgomp1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libitm1:amd64.\\r\\nPreparing to unpack .../17-libitm1_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libitm1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libatomic1:amd64.\\r\\nPreparing to unpack .../18-libatomic1_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libatomic1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libasan8:amd64.\\r\\nPreparing to unpack .../19-libasan8_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libasan8:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package liblsan0:amd64.\\r\\nPreparing to unpack .../20-liblsan0_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking liblsan0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libtsan2:amd64.\\r\\nPreparing to unpack .../21-libtsan2_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libtsan2:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libubsan1:amd64.\\r\\nPreparing to unpack .../22-libubsan1_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libubsan1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libhwasan0:amd64.\\r\\nPreparing to unpack .../23-libhwasan0_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libhwasan0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libquadmath0:amd64.\\r\\nPreparing to unpack .../24-libquadmath0_14.2.0-4ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libquadmath0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package libgcc-13-dev:amd64.\\r\\nPreparing to unpack .../25-libgcc-13-dev_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libgcc-13-dev:amd64 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package gcc-13-x86-64-linux-gnu.\\r\\nPreparing to unpack .../26-gcc-13-x86-64-linux-gnu_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking gcc-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package gcc-13.\\r\\nPreparing to unpack .../27-gcc-13_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking gcc-13 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package gcc-x86-64-linux-gnu.\\r\\nPreparing to unpack .../28-gcc-x86-64-linux-gnu_4%3a13.2.0-7ubuntu1_amd64.deb ...\\r\\nUnpacking gcc-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...\\r\\nSelecting previously unselected package gcc.\\r\\nPreparing to unpack .../29-gcc_4%3a13.2.0-7ubuntu1_amd64.deb ...\\r\\nUnpacking gcc (4:13.2.0-7ubuntu1) ...\\r\\nSelecting previously unselected package libstdc++-13-dev:amd64.\\r\\nPreparing to unpack .../30-libstdc++-13-dev_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking libstdc++-13-dev:amd64 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package g++-13-x86-64-linux-gnu.\\r\\nPreparing to unpack .../31-g++-13-x86-64-linux-gnu_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking g++-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package g++-13.\\r\\nPreparing to unpack .../32-g++-13_13.3.0-6ubuntu2~24.04.1_amd64.deb ...\\r\\nUnpacking g++-13 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSelecting previously unselected package g++-x86-64-linux-gnu.\\r\\nPreparing to unpack .../33-g++-x86-64-linux-gnu_4%3a13.2.0-7ubuntu1_amd64.deb ...\\r\\nUnpacking g++-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...\\r\\nSelecting previously unselected package g++.\\r\\nPreparing to unpack .../34-g++_4%3a13.2.0-7ubuntu1_amd64.deb ...\\r\\nUnpacking g++ (4:13.2.0-7ubuntu1) ...\\r\\nSelecting previously unselected package make.\\r\\nPreparing to unpack .../35-make_4.3-4.1build2_amd64.deb ...\\r\\nUnpacking make (4.3-4.1build2) ...\\r\\nSelecting previously unselected package libdpkg-perl.\\r\\nPreparing to unpack .../36-libdpkg-perl_1.22.6ubuntu6.6_all.deb ...\\r\\nUnpacking libdpkg-perl (1.22.6ubuntu6.6) ...\\r\\nSelecting previously unselected package bzip2.\\r\\nPreparing to unpack .../37-bzip2_1.0.8-5.1build0.1_amd64.deb ...\\r\\nUnpacking bzip2 (1.0.8-5.1build0.1) ...\\r\\nSelecting previously unselected package lto-disabled-list.\\r\\nPreparing to unpack .../38-lto-disabled-list_47_all.deb ...\\r\\nUnpacking lto-disabled-list (47) ...\\r\\nSelecting previously unselected package dpkg-dev.\\r\\nPreparing to unpack .../39-dpkg-dev_1.22.6ubuntu6.6_all.deb ...\\r\\nUnpacking dpkg-dev (1.22.6ubuntu6.6) ...\\r\\nSelecting previously unselected package build-essential.\\r\\nPreparing to unpack .../40-build-essential_12.10ubuntu1_amd64.deb ...\\r\\nUnpacking build-essential (12.10ubuntu1) ...\\r\\nSelecting previously unselected package libfakeroot:amd64.\\r\\nPreparing to unpack .../41-libfakeroot_1.33-1_amd64.deb ...\\r\\nUnpacking libfakeroot:amd64 (1.33-1) ...\\r\\nSelecting previously unselected package fakeroot.\\r\\nPreparing to unpack .../42-fakeroot_1.33-1_amd64.deb ...\\r\\nUnpacking fakeroot (1.33-1) ...\\r\\nSelecting previously unselected package javascript-common.\\r\\nPreparing to unpack .../43-javascript-common_11+nmu1_all.deb ...\\r\\nUnpacking javascript-common (11+nmu1) ...\\r\\nSelecting previously unselected package libalgorithm-diff-perl.\\r\\nPreparing to unpack .../44-libalgorithm-diff-perl_1.201-1_all.deb ...\\r\\nUnpacking libalgorithm-diff-perl (1.201-1) ...\\r\\nSelecting previously unselected package libalgorithm-diff-xs-perl:amd64.\\r\\nPreparing to unpack .../45-libalgorithm-diff-xs-perl_0.04-8build3_amd64.deb ...\\r\\nUnpacking libalgorithm-diff-xs-perl:amd64 (0.04-8build3) ...\\r\\nSelecting previously unselected package libalgorithm-merge-perl.\\r\\nPreparing to unpack .../46-libalgorithm-merge-perl_0.08-5_all.deb ...\\r\\nUnpacking libalgorithm-merge-perl (0.08-5) ...\\r\\nSelecting previously unselected package libexpat1-dev:amd64.\\r\\nPreparing to unpack .../47-libexpat1-dev_2.6.1-2ubuntu0.4_amd64.deb ...\\r\\nUnpacking libexpat1-dev:amd64 (2.6.1-2ubuntu0.4) ...\\r\\nSelecting previously unselected package libfile-fcntllock-perl.\\r\\nPreparing to unpack .../48-libfile-fcntllock-perl_0.22-4ubuntu5_amd64.deb ...\\r\\nUnpacking libfile-fcntllock-perl (0.22-4ubuntu5) ...\\r\\nSelecting previously unselected package libjs-jquery.\\r\\nPreparing to unpack .../49-libjs-jquery_3.6.1+dfsg+~3.5.14-1_all.deb ...\\r\\nUnpacking libjs-jquery (3.6.1+dfsg+~3.5.14-1) ...\\r\\nSelecting previously unselected package libjs-underscore.\\r\\nPreparing to unpack .../50-libjs-underscore_1.13.4~dfsg+~1.11.4-3_all.deb ...\\r\\nUnpacking libjs-underscore (1.13.4~dfsg+~1.11.4-3) ...\\r\\nSelecting previously unselected package libjs-sphinxdoc.\\r\\nPreparing to unpack .../51-libjs-sphinxdoc_7.2.6-6_all.deb ...\\r\\nUnpacking libjs-sphinxdoc (7.2.6-6) ...\\r\\nSelecting previously unselected package zlib1g-dev:amd64.\\r\\nPreparing to unpack .../52-zlib1g-dev_1%3a1.3.dfsg-3.1ubuntu2.1_amd64.deb ...\\r\\nUnpacking zlib1g-dev:amd64 (1:1.3.dfsg-3.1ubuntu2.1) ...\\r\\nSelecting previously unselected package libpython3.12-dev:amd64.\\r\\nPreparing to unpack .../53-libpython3.12-dev_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking libpython3.12-dev:amd64 (3.12.3-1ubuntu0.13) ...\\r\\nSelecting previously unselected package libpython3-dev:amd64.\\r\\nPreparing to unpack .../54-libpython3-dev_3.12.3-0ubuntu2.1_amd64.deb ...\\r\\nUnpacking libpython3-dev:amd64 (3.12.3-0ubuntu2.1) ...\\r\\nSelecting previously unselected package python3.12-dev.\\r\\nPreparing to unpack .../55-python3.12-dev_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking python3.12-dev (3.12.3-1ubuntu0.13) ...\\r\\nSelecting previously unselected package python3-dev.\\r\\nPreparing to unpack .../56-python3-dev_3.12.3-0ubuntu2.1_amd64.deb ...\\r\\nUnpacking python3-dev (3.12.3-0ubuntu2.1) ...\\r\\nSelecting previously unselected package python3-wheel.\\r\\nPreparing to unpack .../57-python3-wheel_0.42.0-2_all.deb ...\\r\\nUnpacking python3-wheel (0.42.0-2) ...\\r\\nSelecting previously unselected package python3-pip.\\r\\nPreparing to unpack .../58-python3-pip_24.0+dfsg-1ubuntu1.3_all.deb ...\\r\\nUnpacking python3-pip (24.0+dfsg-1ubuntu1.3) ...\\r\\nSelecting previously unselected package python3-pip-whl.\\r\\nPreparing to unpack .../59-python3-pip-whl_24.0+dfsg-1ubuntu1.3_all.deb ...\\r\\nUnpacking python3-pip-whl (24.0+dfsg-1ubuntu1.3) ...\\r\\nSelecting previously unselected package python3-setuptools-whl.\\r\\nPreparing to unpack .../60-python3-setuptools-whl_68.1.2-2ubuntu1.2_all.deb ...\\r\\nUnpacking python3-setuptools-whl (68.1.2-2ubuntu1.2) ...\\r\\nSelecting previously unselected package python3.12-venv.\\r\\nPreparing to unpack .../61-python3.12-venv_3.12.3-1ubuntu0.13_amd64.deb ...\\r\\nUnpacking python3.12-venv (3.12.3-1ubuntu0.13) ...\\r\\nSelecting previously unselected package python3-venv.\\r\\nPreparing to unpack .../62-python3-venv_3.12.3-0ubuntu2.1_amd64.deb ...\\r\\nUnpacking python3-venv (3.12.3-0ubuntu2.1) ...\\r\\nSetting up libexpat1:amd64 (2.6.1-2ubuntu0.4) ...\\r\\nSetting up javascript-common (11+nmu1) ...\\r\\nSetting up python3-setuptools-whl (68.1.2-2ubuntu1.2) ...\\r\\nSetting up lto-disabled-list (47) ...\\r\\nSetting up libfile-fcntllock-perl (0.22-4ubuntu5) ...\\r\\nSetting up python3-pip-whl (24.0+dfsg-1ubuntu1.3) ...\\r\\nSetting up libalgorithm-diff-perl (1.201-1) ...\\r\\nSetting up libpython3.12-minimal:amd64 (3.12.3-1ubuntu0.13) ...\\r\\nSetting up binutils-common:amd64 (2.42-4ubuntu2.10) ...\\r\\nSetting up libctf-nobfd0:amd64 (2.42-4ubuntu2.10) ...\\r\\nSetting up libgomp1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up bzip2 (1.0.8-5.1build0.1) ...\\r\\nSetting up libsframe1:amd64 (2.42-4ubuntu2.10) ...\\r\\nSetting up libfakeroot:amd64 (1.33-1) ...\\r\\nSetting up fakeroot (1.33-1) ...\\r\\nupdate-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode\\r\\nSetting up gcc-13-base:amd64 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up libexpat1-dev:amd64 (2.6.1-2ubuntu0.4) ...\\r\\nSetting up make (4.3-4.1build2) ...\\r\\nSetting up libquadmath0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up libmpc3:amd64 (1.3.1-1build1.1) ...\\r\\nSetting up libatomic1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up libdpkg-perl (1.22.6ubuntu6.6) ...\\r\\nSetting up libubsan1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up zlib1g-dev:amd64 (1:1.3.dfsg-3.1ubuntu2.1) ...\\r\\nSetting up libhwasan0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up libasan8:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up libtsan2:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up libjs-jquery (3.6.1+dfsg+~3.5.14-1) ...\\r\\nSetting up libbinutils:amd64 (2.42-4ubuntu2.10) ...\\r\\nSetting up libisl23:amd64 (0.26-3build1.1) ...\\r\\nSetting up libalgorithm-diff-xs-perl:amd64 (0.04-8build3) ...\\r\\nSetting up libcc1-0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up liblsan0:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up libitm1:amd64 (14.2.0-4ubuntu2~24.04.1) ...\\r\\nSetting up libjs-underscore (1.13.4~dfsg+~1.11.4-3) ...\\r\\nSetting up libalgorithm-merge-perl (0.08-5) ...\\r\\nSetting up libctf0:amd64 (2.42-4ubuntu2.10) ...\\r\\nSetting up python3.12-minimal (3.12.3-1ubuntu0.13) ...\\r\\nSetting up libpython3.12-stdlib:amd64 (3.12.3-1ubuntu0.13) ...\\r\\nSetting up cpp-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up python3.12 (3.12.3-1ubuntu0.13) ...\\r\\nSetting up libpython3.12t64:amd64 (3.12.3-1ubuntu0.13) ...\\r\\nSetting up libgprofng0:amd64 (2.42-4ubuntu2.10) ...\\r\\nSetting up libjs-sphinxdoc (7.2.6-6) ...\\r\\nSetting up libgcc-13-dev:amd64 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up libstdc++-13-dev:amd64 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up libpython3-stdlib:amd64 (3.12.3-0ubuntu2.1) ...\\r\\nSetting up binutils-x86-64-linux-gnu (2.42-4ubuntu2.10) ...\\r\\nSetting up cpp-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...\\r\\nSetting up cpp-13 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up python3.12-venv (3.12.3-1ubuntu0.13) ...\\r\\nSetting up gcc-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up python3 (3.12.3-0ubuntu2.1) ...\\r\\nSetting up libpython3.12-dev:amd64 (3.12.3-1ubuntu0.13) ...\\r\\nSetting up binutils (2.42-4ubuntu2.10) ...\\r\\nSetting up python3-wheel (0.42.0-2) ...\\r\\nSetting up dpkg-dev (1.22.6ubuntu6.6) ...\\r\\nSetting up python3-venv (3.12.3-0ubuntu2.1) ...\\r\\nSetting up gcc-13 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up python3.12-dev (3.12.3-1ubuntu0.13) ...\\r\\nSetting up python3-pip (24.0+dfsg-1ubuntu1.3) ...\\r\\nSetting up cpp (4:13.2.0-7ubuntu1) ...\\r\\nSetting up libpython3-dev:amd64 (3.12.3-0ubuntu2.1) ...\\r\\nSetting up g++-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up gcc-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...\\r\\nSetting up gcc (4:13.2.0-7ubuntu1) ...\\r\\nSetting up python3-dev (3.12.3-0ubuntu2.1) ...\\r\\nSetting up g++-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...\\r\\nSetting up g++-13 (13.3.0-6ubuntu2~24.04.1) ...\\r\\nSetting up g++ (4:13.2.0-7ubuntu1) ...\\r\\nupdate-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode\\r\\nSetting up build-essential (12.10ubuntu1) ...\\r\\nProcessing triggers for systemd (255.4-1ubuntu8.8) ...\\r\\nProcessing triggers for man-db (2.12.0-4build2) ...\\r\\nProcessing triggers for libc-bin (2.39-0ubuntu8.4) ...\\r\\n'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"### PROGRESS: Step 4/5 - Installing SeQUeNCe and dependencies...\")\n",
    "bootstrap_cmd = (\n",
    "    \"sudo apt-get update -qq && \"\n",
    "    \"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq python3-venv python3-pip && \"\n",
    "    \"python3 -m venv ~/sequence-venv && \"\n",
    "    \"~/sequence-venv/bin/python -m pip install -q --upgrade pip && \"\n",
    "    \"~/sequence-venv/bin/python -m pip install -q sequence\"\n",
    ")\n",
    "_run_or_fail(node, bootstrap_cmd, \"  Installing Python runtime and SeQUeNCe package...\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "367f2141-55f3-478a-8f0d-2e253f726d33",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "with open(\"weave.json\", 'r', encoding='utf-8') as file:\n",
    "    wv = json.load(file)\n",
    "osenviron = wv[\"active_run\"]['args']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b9bb3b23-7ca4-4dcc-bba4-60fabdfbea56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'SLICE_NAME': 'sequence-experiment-lab-izbb',\n",
       " 'EXPERIMENT': 'simple_request',\n",
       " 'TOPOLOGY': 'two_node',\n",
       " 'STOP_TIME_PS': '3000000000000',\n",
       " 'REQUEST_START_PS': '1000000000000',\n",
       " 'REQUEST_END_PS': '2500000000000',\n",
       " 'REQUEST_MEMORY': '1',\n",
       " 'REQUEST_FIDELITY': '0.8',\n",
       " 'RANDOM_REQUEST_COUNT': '3'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "osenviron"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0117d854-dc6d-4e64-bfa3-97ec9a1623b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "### PROGRESS: Step 5/5 - Running selected SeQUeNCe experiment...\n",
      "  Executing simulation now...\n",
      "RESULT: simple_request\n",
      "  initiator=router_0 responder=router_1\n",
      "  pair_count=105\n",
      "  throughput_pairs_per_sec=70.0\n"
     ]
    }
   ],
   "source": [
    "def _env_int(name: str, default: int) -> int:\n",
    "    value = osenviron.get(name)\n",
    "    return int(value) if value not in (None, \"\") else default\n",
    "\n",
    "\n",
    "DEFAULTS = {\n",
    "    \"EXPERIMENT\": \"simple_request\",\n",
    "    \"TOPOLOGY\": \"two_node\",\n",
    "    \"STOP_TIME_PS\": 3_000_000_000_000,\n",
    "    \"REQUEST_START_PS\": 1_000_000_000_000,\n",
    "    \"REQUEST_END_PS\": 2_500_000_000_000,\n",
    "    \"REQUEST_MEMORY\": 1,\n",
    "    \"REQUEST_FIDELITY\": 0.8,\n",
    "    \"RANDOM_REQUEST_COUNT\": 3,\n",
    "}\n",
    "\n",
    "SUPPORTED = {\n",
    "    \"simple_request\": {\"two_node\", \"star_network\"},\n",
    "    \"random_requests\": {\"two_node\", \"star_network\"},\n",
    "    \"teleport_demo\": {\"teleport_2node\"},\n",
    "}\n",
    "\n",
    "\n",
    "def _env_float(name: str, default: float) -> float:\n",
    "    value = osenviron.get(name)\n",
    "    return float(value) if value not in (None, \"\") else default\n",
    "\n",
    "def _read_settings() -> dict:\n",
    "    settings = {\n",
    "        \"experiment\": osenviron.get(\"EXPERIMENT\", DEFAULTS[\"EXPERIMENT\"]).strip(),\n",
    "        \"topology\": osenviron.get(\"TOPOLOGY\", DEFAULTS[\"TOPOLOGY\"]).strip(),\n",
    "        \"stop_time_ps\": _env_int(\"STOP_TIME_PS\", DEFAULTS[\"STOP_TIME_PS\"]),\n",
    "        \"request_start_ps\": _env_int(\"REQUEST_START_PS\", DEFAULTS[\"REQUEST_START_PS\"]),\n",
    "        \"request_end_ps\": _env_int(\"REQUEST_END_PS\", DEFAULTS[\"REQUEST_END_PS\"]),\n",
    "        \"request_memory\": _env_int(\"REQUEST_MEMORY\", DEFAULTS[\"REQUEST_MEMORY\"]),\n",
    "        \"request_fidelity\": _env_float(\"REQUEST_FIDELITY\", DEFAULTS[\"REQUEST_FIDELITY\"]),\n",
    "        \"random_request_count\": _env_int(\"RANDOM_REQUEST_COUNT\", DEFAULTS[\"RANDOM_REQUEST_COUNT\"]),\n",
    "    }\n",
    "    valid_topologies = SUPPORTED.get(settings[\"experiment\"])\n",
    "    if valid_topologies is None:\n",
    "        raise ValueError(\n",
    "            f\"Unsupported EXPERIMENT '{settings['experiment']}'. Supported: {', '.join(SUPPORTED)}\"\n",
    "        )\n",
    "    if settings[\"topology\"] not in valid_topologies:\n",
    "        allowed = \", \".join(sorted(valid_topologies))\n",
    "        raise ValueError(\n",
    "            f\"Topology '{settings['topology']}' is not valid for experiment '{settings['experiment']}'. \"\n",
    "            f\"Allowed: {allowed}\"\n",
    "        )\n",
    "    return settings\n",
    "\n",
    "\n",
    "settings = _read_settings()\n",
    "print(\"### PROGRESS: Step 5/5 - Running selected SeQUeNCe experiment...\")\n",
    "run_cmd = (\n",
    "    \"~/sequence-venv/bin/python ~/tools/run_sequence_experiment.py \"\n",
    "    f\"--experiment {settings['experiment']} \"\n",
    "    f\"--topology {settings['topology']} \"\n",
    "    f\"--stop-time {settings['stop_time_ps']} \"\n",
    "    f\"--request-start {settings['request_start_ps']} \"\n",
    "    f\"--request-end {settings['request_end_ps']} \"\n",
    "    f\"--request-memory {settings['request_memory']} \"\n",
    "    f\"--request-fidelity {settings['request_fidelity']} \"\n",
    "    f\"--random-request-count {settings['random_request_count']}\"\n",
    ")\n",
    "output = _run_or_fail(node, run_cmd, \"  Executing simulation now...\")\n",
    "print(output.strip())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a7439f4-643f-42fc-9015-be47d773689c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
