{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "946af112",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2022-02-11 17:18:03.266800: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory\n",
      "2022-02-11 17:18:03.266820: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n"
     ]
    }
   ],
   "source": [
    "from library.analysis import testSets, runSpeedTestForConvGan\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d23e43a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from library.convGAN import ConvGAN\n",
    "from library.convGAN2 import ConvGAN2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ee7244ea",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "#def g(x):\n",
    "#    return ConvGAN(x,debug=False)\n",
    "#timesBase1 = runSpeedTestForConvGan(testSets[0], g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1b677ce1",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "#def g(x):\n",
    "#    return ConvGAN(x,debug=False)\n",
    "#timesBase2 = runSpeedTestForConvGan(testSets[0], g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1e46258d",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "///////////////////////////////////////////\n",
      "// Running speed test for convGAN on folding_abalone_17_vs_7_8_9_10\n",
      "///////////////////////////////////////////\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2022-02-11 17:18:04.570823: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory\n",
      "2022-02-11 17:18:04.570841: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)\n",
      "2022-02-11 17:18:04.570856: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (sbi-klabautermann): /proc/driver/nvidia/version does not exist\n",
      "2022-02-11 17:18:04.571014: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA\n",
      "To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23356 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 20008 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23508 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22444 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21080 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23840 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23728 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26292 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 25276 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Time: 434.62331461906433\n",
      "Preparation Time: 0.06078600883483887\n",
      "Test Time: 434.5625286102295\n"
     ]
    }
   ],
   "source": [
    "def g(x):\n",
    "    return ConvGAN2(x,debug=False)\n",
    "timesOptimized, gan = runSpeedTestForConvGan(testSets[0], g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f1974726",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(453.59352374076843, 0.061972618103027344, 453.5315511226654)\n",
      "(468.4801619052887, 0.054076433181762695, 468.42608547210693)\n",
      "(451.06674337387085, 0.053739309310913086, 451.01300406455994)\n",
      "(18, 0.005702018737792969)\n",
      "(6492, 3.859421491622925)\n",
      "(434.62331461906433, 0.06078600883483887, 434.5625286102295)\n",
      "(9, 0.09975528717041016)\n",
      "(6492, 0.07375073432922363)\n"
     ]
    }
   ],
   "source": [
    "#print(timesBase1)\n",
    "#print(timesBase2)\n",
    "print((453.59352374076843, 0.061972618103027344, 453.5315511226654))\n",
    "print((468.4801619052887, 0.054076433181762695, 468.42608547210693))\n",
    "print((451.06674337387085, 0.053739309310913086, 451.01300406455994))\n",
    "\n",
    "print((18, 0.005702018737792969))\n",
    "print((6492, 3.859421491622925))\n",
    "\n",
    "print(timesOptimized)\n",
    "print((gan.nNbhFit, gan.tNbhFit))\n",
    "print((gan.nNbhSearch, gan.tNbhSearch))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2aa2d6ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reset: #9 0.9882s\n",
      "train: #9 337.9557s\n",
      "create points: #9 88.2087s\n",
      "NMB: #6501 1.7672s\n",
      "BMB: #3480 0.2709s\n",
      "_generate_data_for_min_point: #348 88.1943s\n",
      "predict: #3012 87.3975s\n",
      "NN_fit_all: #9 0.0997s\n",
      "NN_fit_chained_init: #9 0.0023s\n",
      "NN_fit_chained_toList: #9 0.0973s\n"
     ]
    }
   ],
   "source": [
    "for k in gan.timing.keys():\n",
    "    print(gan.timing[k])"
   ]
  }
 ],
 "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.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
