{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/data/projects/great_ai/.env/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "from great_ai.utilities import parallel_map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[38;5;39m2022-06-29 09:11:18,070 |     INFO | Parallel map: configured ✅\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:18,071 |     INFO |   ⚙️  concurrency: 200\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:18,071 |     INFO |   ⚙️  chunk length: 1\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:18,071 |     INFO |   ⚙️  chunk count: 1000\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:18,072 |     INFO |   ⚙️  function size: 0 kB\u001b[0m\n",
      "Parallel map: 100%|██████████| 1000/1000 [00:00<00:00, 1345.90it/s]\n"
     ]
    }
   ],
   "source": [
    "from time import sleep\n",
    "\n",
    "parallel_map(lambda x: sleep(0.1), range(int(1000)), concurrency=200)\n",
    "None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[38;5;39m2022-06-29 09:11:20,399 |     INFO | Parallel map: configured ✅\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:20,401 |     INFO |   ⚙️  concurrency: 12\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:20,401 |     INFO |   ⚙️  chunk length: 1\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:20,402 |     INFO |   ⚙️  chunk count: unknown\u001b[0m\n",
      "\u001b[38;5;39m2022-06-29 09:11:20,403 |     INFO |   ⚙️  function size: 0 kB\u001b[0m\n",
      "Parallel map: 10it [00:02,  4.93it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from time import sleep\n",
    "\n",
    "\n",
    "def my_generator():\n",
    "    for i in range(10):\n",
    "        yield i\n",
    "        sleep(0.2)\n",
    "\n",
    "\n",
    "parallel_map(lambda x: x**3, my_generator(), chunk_length=1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 ('.env': venv)",
   "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.10.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "d88b0dd276e3f918f7798b7e97af2e3c2f843817b9e5b55a9df0a682ffd80f44"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
