{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6030f079-fac6-470b-b19d-a8c6800c3ed0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import math\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.patches as patches\n",
    "import glob\n",
    "from scipy import ndimage, signal, interpolate\n",
    "from time import sleep\n",
    "#from ennemi import estimate_corr, pairwise_corr, pairwise_mi\n",
    "from matplotlib import ticker, colormaps, colors\n",
    "from datetime import datetime, timedelta\n",
    "from matplotlib import colors as mpl\n",
    "from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
    "import torch\n",
    "import psutil\n",
    "from botorch.models import SingleTaskGP\n",
    "from botorch.models.transforms import Standardize\n",
    "from botorch.acquisition import UpperConfidenceBound\n",
    "from botorch.fit import fit_gpytorch_mll\n",
    "from botorch.optim import optimize_acqf\n",
    "from gpytorch.mlls import ExactMarginalLogLikelihood\n",
    "from torch.utils.data import DataLoader, TensorDataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38fce03c-2588-4fb3-9424-eaa28902df0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_palette = ['#001524','#15616D','#FF7D00', '#78290F',\"#8F971F\",'#FFECD1']\n",
    "jurjen_palette = mpl.LinearSegmentedColormap.from_list(\"\", [\"white\",\"midnightblue\",\"orangered\", \"gold\", \"Lemonchiffon\"])\n",
    "hzdr_palette=['#005AA0','#F0781E','#64A70B', '#5A696E']\n",
    "my_palette_1 = ['#0A1128','#034078','#1282A2','#819EBA','#0E4A65']\n",
    "my_palette_2 = ['#372E4E','#5F0F40','#9A031E','#E36414','#F38B24', '#44524A','#0F4C5C']\n",
    "my_palette_3 = ['#14342B','#3A6444', '#688A78', '#60935D', '#BAB700', '#CCA441', '#B4718C']\n",
    "jurjen5 = jurjen_palette(np.linspace(0.25,0.8,5))\n",
    "jurjen10 = jurjen_palette(np.linspace(0,1,10))\n",
    "cut_jurjen = mpl.LinearSegmentedColormap.from_list(\"\", [\"midnightblue\",\"orangered\", \"gold\"])\n",
    "plt.rc('text', usetex=False)\n",
    "pd.set_option('display.max_columns',None)\n",
    "sns.set_theme(style='ticks', context='poster')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0dd449aa-f1af-4b9d-ac3c-5860f051cfbb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00f8f007-0490-4025-b8d2-cc91f9aeff85",
   "metadata": {},
   "source": [
    "# Train Gaussian process surrogate model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80190210-521e-4109-8e1e-6a9d5d40e9cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load data\n",
    "allpoints = pd.read_excel('./allpoints_with_noise_for_training.xlsx')\n",
    "allpoints"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2969fec-a46c-4623-ba2c-a70ffe8212b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "col = \"FF Com Position y [µm]\"\n",
    "allpoints.loc[0:1192, \"Pointing\"] = (allpoints.loc[0:1192, col] - allpoints.loc[0:1192, col].mean())\n",
    "allpoints.loc[1192:, \"Pointing\"] = (allpoints.loc[1192:, col] - allpoints.loc[1192:, col].mean())\n",
    "\n",
    "sets_final = allpoints.pivot_table(index='Set number', values=['Laser Energy [J]', 'real_gvd', 'real_tod', 'Z pos real', 'Pointing'], aggfunc=['mean','std'])\n",
    "sets_final.columns = sets_final.columns.to_flat_index().str.join('_')\n",
    "\n",
    "defoc_max = 1.671\n",
    "defoc_min = -1.671\n",
    "gvd_max = 825\n",
    "gvd_min = -825\n",
    "tod_max = 26256\n",
    "tod_min = -26256\n",
    "energy_max = 2.5\n",
    "energy_min = 1.5\n",
    "height_max = 2.0\n",
    "height_min = 1.5\n",
    "\n",
    "allpoints_filt=allpoints.loc[(allpoints['Z pos real']<defoc_max)&(allpoints['Z pos real']>defoc_min)&(allpoints['real_gvd']>gvd_min)&\n",
    "(allpoints['real_gvd']<gvd_max)&(allpoints['real_tod']>tod_min)&(allpoints['real_tod']<tod_max)&(allpoints['Laser height']>height_min)&(allpoints['Laser height']<height_max)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4cd2d606-1db2-432d-a759-c9cff8aec283",
   "metadata": {},
   "outputs": [],
   "source": [
    "def norm_el(a, a_min, a_max):\n",
    "    return (a-a_min)/(a_max-a_min)\n",
    "def rerange(a_norm, a_min, a_max):\n",
    "    return a_min + a_norm*(a_max-a_min)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d65bdd7-1df2-4349-a086-4a171aef2273",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train_all = allpoints_filt\n",
    "x_train_all = x_train_all[['real_tod','Laser Energy [J]','real_gvd','Laser height', 'Z pos real']]\n",
    "x_train_all['real_tod'] = norm_el(x_train_all['real_tod'],tod_min,tod_max)\n",
    "x_train_all['Laser Energy [J]']=norm_el(x_train_all['Laser Energy [J]'], energy_min, energy_max)\n",
    "x_train_all['real_gvd']=norm_el(x_train_all['real_gvd'], gvd_min, gvd_max)\n",
    "x_train_all['Laser height']=norm_el(x_train_all['Laser height'], height_min, height_max)\n",
    "x_train_all['Z pos real']=norm_el(x_train_all['Z pos real'], defoc_min, defoc_max)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f0a2725-6934-4f11-91b1-a696043f2c95",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train_all = allpoints_filt['slice 1 charge']\n",
    "y_train_all = y_train_all/200\n",
    "x_train_all = torch.tensor(x_train_all.values)\n",
    "y_train_all = torch.tensor(y_train_all.values)\n",
    "y_train_all = y_train_all.unsqueeze(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "727cf0c0-19ca-4d90-8bd1-19518158a7fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "params_list = [r'Laser TOD [$fs^3$]',r'Laser energy [$J$]', r'Laser GVD [$fs^2$]', r'Nozzle height [$mm$]', r'Focus position [$mm$]']\n",
    "min_values = [-26256, 1.5, -825, 1.5, -1.671]\n",
    "max_values = [26265, 2.5, 825, 2.0, 1.671]\n",
    "batch_size = 8192\n",
    "\n",
    "model = SingleTaskGP(x_train_all, y_train_all)\n",
    "mll = ExactMarginalLogLikelihood(model.likelihood, model)\n",
    "fit_gpytorch_mll(mll)\n",
    "\n",
    "model.eval()\n",
    "model.likelihood.eval()\n",
    "\n",
    "xi, xj, xk, xl, xm = torch.linspace(0,1, 20, dtype=torch.float64), torch.linspace(0,1, 20, dtype=torch.float64), torch.linspace(0,1,20, dtype=torch.float64), torch.linspace(0,1, 20, dtype=torch.float64), torch.linspace(0,1,20, dtype=torch.float64)\n",
    "X_grid_5d = torch.stack(torch.meshgrid(xi, xj, xk, xl, xm, indexing='ij'), dim=-1)\n",
    "X_5d = X_grid_5d.reshape(-1, 5)\n",
    "print(X_5d.shape)\n",
    "\n",
    "dataset = TensorDataset(X_5d)\n",
    "loader = DataLoader(dataset, batch_size=batch_size, shuffle=False)\n",
    "posterior_mean = []\n",
    "posterior_var = []\n",
    "\n",
    "for batch in loader:\n",
    "    X_batch = batch[0]\n",
    "    posterior = model.posterior(X_batch)\n",
    "    posterior_mean.append(posterior.mean.detach())\n",
    "    posterior_var.append(posterior.variance.detach())\n",
    "\n",
    "posterior_mean = torch.cat(posterior_mean)\n",
    "posterior_var = torch.cat(posterior_var)\n",
    "\n",
    "mean_5d = posterior_mean.reshape(20,20,20,20,20).detach().cpu().numpy()\n",
    "lower, upper = posterior.confidence_region()\n",
    "\n",
    "norm = np.sum(mean_5d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4938171-a60e-4971-a3e6-ddd93833d7f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots(5,5, figsize=(20.5, 21))\n",
    "rm_axis = [ax[0,1], ax[0,2],ax[0,3], ax[0,4], ax[1,2], ax[1,3], ax[2,3], ax[1,4],ax[2,4], ax[3,4]]\n",
    "for axs in rm_axis:\n",
    "    fig.delaxes(axs)\n",
    "\n",
    "for i in range(0,5):\n",
    "    for j in range(0,i+1):\n",
    "      if i==j:\n",
    "          prodim = (0,1,2,3,4)\n",
    "          prodim = list(prodim)\n",
    "          prodim.remove(i)\n",
    "          prodim = tuple(int(x) for x in prodim)\n",
    "          projection = np.sum(mean_5d, axis=prodim)/norm\n",
    "          xi_v = rerange(xi, min_values[i], max_values[i])\n",
    "          ax[i,j].plot(xi_v, projection, color=jurjen5[0])\n",
    "          ax[i,j].set_ylim(0,0.15)\n",
    "          ax[i,j].yaxis.set_ticks_position('right')\n",
    "          ax[i,j].tick_params(labelbottom=False,labelleft=False,labelright=True)\n",
    "      else:\n",
    "        prodim = (0,1,2,3,4)\n",
    "        prodim = list(prodim)\n",
    "        prodim.remove(i)\n",
    "        prodim.remove(j)\n",
    "        prodim = tuple(int(x) for x in prodim)\n",
    "        projection = np.sum(mean_5d, axis=prodim)/norm\n",
    "          \n",
    "        xi_v = rerange(xi, min_values[i], max_values[i])\n",
    "        xj_v = rerange(xj, min_values[j], max_values[j])\n",
    "\n",
    "        x_train_iv = rerange(x_train_all[:, i], min_values[i], max_values[i])\n",
    "        x_train_jv = rerange(x_train_all[:, j], min_values[j], max_values[j])\n",
    "\n",
    "        left, bottom = 0.25, 0.2\n",
    "        width, height = 0.45, 0.6\n",
    "        im = ax[i,j].pcolormesh(xj_v, xi_v, projection.T, shading='auto', cmap=jurjen_palette, alpha=1.0, vmin=0.0000, vmax=0.011)\n",
    "        ax[i,j].scatter(x_train_jv, x_train_iv, c='k', edgecolors='k', s=4, label='Observed points', marker='D')\n",
    "        #plt.colorbar(im, ax=ax[i,j], label='Charge in energy slice [pC]')\n",
    "        \n",
    "        if i == 4:\n",
    "            ax[i,j].set_xlabel(params_list[j])\n",
    "        else:\n",
    "            ax[i,j].tick_params(labelbottom=False)\n",
    "        if j==0:\n",
    "            ax[i,j].set_ylabel(params_list[i])\n",
    "        else:\n",
    "            ax[i,j].tick_params(labelleft=False)\n",
    "\n",
    "cbar_ax = fig.add_axes([0.67,0.425,0.01,0.14])\n",
    "fig.colorbar(im,cax=cbar_ax)\n",
    "#plt.xlim(1.5,2.0)\n",
    "#plt.savefig('/bigdata/hplsim/production/LWFA_GP_STII_fmh/'+params_list[i]+'_'+params_list[j]+'.png')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ab94ac5-f60e-4854-b27c-1a699e99424b",
   "metadata": {},
   "source": [
    "# Method drawing sample from Gaussian process"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4cb75ae0-8cbc-4e9b-bd25-0143d77b3d93",
   "metadata": {},
   "outputs": [],
   "source": [
    "def rerange(a_norm, a_min, a_max):\n",
    "    a_min = np.asarray(a_min, dtype=float)\n",
    "    a_max = np.asarray(a_max, dtype=float)\n",
    "    a_norm = np.asarray(a_norm, dtype=float)\n",
    "\n",
    "    return a_min + a_norm * (a_max - a_min)\n",
    "\n",
    "def norm_el(a, a_min, a_max):\n",
    "    a = np.asarray(a, dtype=float)\n",
    "    a_min = np.asarray(a_min, dtype=float)\n",
    "    a_max = np.asarray(a_max, dtype=float)\n",
    "\n",
    "    return (a - a_min) / (a_max - a_min)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b46d17b-c84c-4c01-b91b-e9ab45aeecf4",
   "metadata": {},
   "outputs": [],
   "source": [
    "mean_5d_t = torch.from_numpy(mean_5d)\n",
    "params = [r'Laser TOD [$fs^3$]',r'Laser energy [$J$]', r'Laser GVD [$fs^2$]', r'Nozzle height [$mm$]', r'Focus position [$mm$]']\n",
    "noise = [6256, 0.025, 251, 0.005, 0.171]\n",
    "shot_index = 0\n",
    "pre_len = 0\n",
    "counter = 0\n",
    "setsize = 10\n",
    "\n",
    "for model_nr in range(100):\n",
    "    records = []\n",
    "    for set in range(5):\n",
    "        set_measured = np.empty(setsize)\n",
    "        norm_setpoint = np.random.rand(5)\n",
    "        physical_setpoint = rerange(norm_setpoint, min_values, max_values)\n",
    "    \n",
    "        for shotnr in range(setsize):\n",
    "            # Add measurement/control noise in physical units\n",
    "            noise_point = (np.random.rand(5) * 2 - 1) * noise\n",
    "            noisy_setpoint = physical_setpoint + noise_point\n",
    "        \n",
    "            # Convert back to normalized coordinates and enforce bounds\n",
    "            norm_setpoint_n = norm_el(noisy_setpoint, min_values, max_values)\n",
    "        \n",
    "            # Convert normalized coordinate to grid index\n",
    "            ind = np.round(norm_setpoint_n * 19).astype(int)\n",
    "            ind = np.clip(ind, 0, 19)\n",
    "            ind_list.append(ind)\n",
    "        \n",
    "            # Retrieve scalar from 5-D lookup table\n",
    "            measured = mean_5d_t[ind[0], ind[1], ind[2], ind[3], ind[4]]\n",
    "            measured_list.append(measured)\n",
    "            set_measured[shotnr]=measured\n",
    "        \n",
    "        measured_outcome_n = np.array([np.mean(set_measured)])\n",
    "        measured_outcome = measured_outcome_n*200\n",
    "        measured_outcome_n = torch.from_numpy(measured_outcome_n)\n",
    "        measured_outcome = torch.from_numpy(measured_outcome)\n",
    "        measured_outcome_n = measured_outcome_n.unsqueeze(1)\n",
    "        measured_outcome = measured_outcome.unsqueeze(1)\n",
    "        \n",
    "        if set == 0:\n",
    "            x_train = torch.tensor([norm_setpoint])\n",
    "            y_train = measured_outcome_n\n",
    "            x_scale = torch.tensor([physical_setpoint])\n",
    "            y_scale = measured_outcome\n",
    "        else:\n",
    "            x_train = torch.cat([x_train, torch.tensor([norm_setpoint])])\n",
    "            y_train = torch.cat([y_train, measured_outcome_n])\n",
    "            x_scale = torch.cat([x_scale, torch.tensor([physical_setpoint])])\n",
    "            y_scale = torch.cat([y_scale, measured_outcome])\n",
    "            \n",
    "            \"\"\"\n",
    "            best_charge_ind = np.argmax(y_scale)\n",
    "            best_charge = y_scale[best_charge_ind]\n",
    "            print(best_charge)\n",
    "            \"\"\"\n",
    "\n",
    "        records.append({\n",
    "            \"shot\": shotnr,\n",
    "            \"candidate_norm_0\": candidate_np[0],\n",
    "            \"candidate_norm_1\": candidate_np[1],\n",
    "            \"candidate_norm_2\": candidate_np[2],\n",
    "            \"candidate_norm_3\": candidate_np[3],\n",
    "            \"candidate_norm_4\": candidate_np[4],\n",
    "            \"physical_setpoint_0\": float(physical_setpoint[0]),\n",
    "            \"physical_setpoint_1\": float(physical_setpoint[1]),\n",
    "            \"physical_setpoint_2\": float(physical_setpoint[2]),\n",
    "            \"physical_setpoint_3\": float(physical_setpoint[3]),\n",
    "            \"physical_setpoint_4\": float(physical_setpoint[4]),\n",
    "            \"noisy_setpoint_0\": float(noisy_setpoint[0]),\n",
    "            \"noisy_setpoint_1\": float(noisy_setpoint[1]),\n",
    "            \"noisy_setpoint_2\": float(noisy_setpoint[2]),\n",
    "            \"noisy_setpoint_3\": float(noisy_setpoint[3]),\n",
    "            \"noisy_setpoint_4\": float(noisy_setpoint[4]),\n",
    "            \"norm_setpoint_0\": float(norm_setpoint_n[0]),\n",
    "            \"norm_setpoint_1\": float(norm_setpoint_n[1]),\n",
    "            \"norm_setpoint_2\": float(norm_setpoint_n[2]),\n",
    "            \"norm_setpoint_3\": float(norm_setpoint_n[3]),\n",
    "            \"norm_setpoint_4\": float(norm_setpoint_n[4]),\n",
    "            \"index_0\": int(ind[0]),\n",
    "            \"index_1\": int(ind[1]),\n",
    "            \"index_2\": int(ind[2]),\n",
    "            \"index_3\": int(ind[3]),\n",
    "            \"index_4\": int(ind[4]),\n",
    "            \"measured\": float(measured),\n",
    "            \"Modelnr\": model_nr,\n",
    "        })\n",
    "    \n",
    "    for iteration in range(20):\n",
    "        model = SingleTaskGP(x_train, y_train)\n",
    "        mll = ExactMarginalLogLikelihood(model.likelihood, model)\n",
    "        fit_gpytorch_mll(mll)\n",
    "    \n",
    "        set_measured = np.empty(setsize)\n",
    "        acqf = UpperConfidenceBound(model, beta=7)\n",
    "        candidate, _ = optimize_acqf(acqf, bounds = torch.tensor([[0., 1.],[0., 1.],[0., 1.],[0., 1.],[0., 1.]]).T, q=1, num_restarts=20, raw_samples=512)\n",
    "        candidate_np = candidate.detach().cpu().numpy().squeeze()\n",
    "        physical_setpoint = rerange(candidate_np, min_values, max_values)\n",
    "        \n",
    "        for shotnr in range(setsize):\n",
    "            # Add measurement/control noise in physical units\n",
    "            noise_point = (np.random.rand(5) * 2 - 1) * noise\n",
    "            noisy_setpoint = physical_setpoint + noise_point\n",
    "        \n",
    "            # Convert back to normalized coordinates and enforce bounds\n",
    "            norm_setpoint_n = norm_el(noisy_setpoint, min_values, max_values)\n",
    "        \n",
    "            # Convert normalized coordinate to grid index\n",
    "            ind = np.round(norm_setpoint_n * 19).astype(int)\n",
    "            ind = np.clip(ind, 0, 19)\n",
    "            ind_list.append(ind)\n",
    "        \n",
    "            # Retrieve scalar from 5-D lookup table\n",
    "            measured = mean_5d_t[ind[0], ind[1], ind[2], ind[3], ind[4]]\n",
    "            measured_list.append(measured)\n",
    "            set_measured[shotnr]=measured\n",
    "    \n",
    "        measured_outcome_n = np.array([np.mean(set_measured)])\n",
    "        measured_outcome = measured_outcome_n*200\n",
    "        measured_outcome_n = torch.from_numpy(measured_outcome_n)\n",
    "        measured_outcome = torch.from_numpy(measured_outcome)\n",
    "        measured_outcome_n = measured_outcome_n.unsqueeze(1)\n",
    "        measured_outcome = measured_outcome.unsqueeze(1)\n",
    "    \n",
    "        x_train = torch.cat([x_train, torch.tensor([candidate_np])])\n",
    "        y_train = torch.cat([y_train, measured_outcome_n])\n",
    "        x_scale = torch.cat([x_scale, torch.tensor([physical_setpoint])])\n",
    "        y_scale = torch.cat([y_scale, measured_outcome])\n",
    "\n",
    "        \"\"\"\n",
    "        best_charge_ind = np.argmax(y_scale)\n",
    "        best_charge = y_scale[best_charge_ind]\n",
    "        print(best_charge)\n",
    "        \"\"\"\n",
    "\n",
    "        records.append({\n",
    "            \"shot\": shotnr,\n",
    "            \"candidate_norm_0\": candidate_np[0],\n",
    "            \"candidate_norm_1\": candidate_np[1],\n",
    "            \"candidate_norm_2\": candidate_np[2],\n",
    "            \"candidate_norm_3\": candidate_np[3],\n",
    "            \"candidate_norm_4\": candidate_np[4],\n",
    "            \"physical_setpoint_0\": float(physical_setpoint[0]),\n",
    "            \"physical_setpoint_1\": float(physical_setpoint[1]),\n",
    "            \"physical_setpoint_2\": float(physical_setpoint[2]),\n",
    "            \"physical_setpoint_3\": float(physical_setpoint[3]),\n",
    "            \"physical_setpoint_4\": float(physical_setpoint[4]),\n",
    "            \"noisy_setpoint_0\": float(noisy_setpoint[0]),\n",
    "            \"noisy_setpoint_1\": float(noisy_setpoint[1]),\n",
    "            \"noisy_setpoint_2\": float(noisy_setpoint[2]),\n",
    "            \"noisy_setpoint_3\": float(noisy_setpoint[3]),\n",
    "            \"noisy_setpoint_4\": float(noisy_setpoint[4]),\n",
    "            \"norm_setpoint_0\": float(norm_setpoint_n[0]),\n",
    "            \"norm_setpoint_1\": float(norm_setpoint_n[1]),\n",
    "            \"norm_setpoint_2\": float(norm_setpoint_n[2]),\n",
    "            \"norm_setpoint_3\": float(norm_setpoint_n[3]),\n",
    "            \"norm_setpoint_4\": float(norm_setpoint_n[4]),\n",
    "            \"index_0\": int(ind[0]),\n",
    "            \"index_1\": int(ind[1]),\n",
    "            \"index_2\": int(ind[2]),\n",
    "            \"index_3\": int(ind[3]),\n",
    "            \"index_4\": int(ind[4]),\n",
    "            \"measured\": float(measured),\n",
    "            \"Modelnr\": model_nr,\n",
    "        })\n",
    "\n",
    "    print(\"Model \"+str(model_nr)+\" done\")\n",
    "    \n",
    "results_df = pd.DataFrame(records)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b4b65fc-3368-4d23-adb8-5b72e5dabeeb",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"mean_5d_t shape:\", mean_5d_t.shape)\n",
    "print(\"ind shape:\", ind.shape)\n",
    "print(\"ind:\", ind)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (gpenv)",
   "language": "python",
   "name": "gpenv"
  },
  "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.12.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
