Created
April 13, 2020 02:44
-
-
Save zeph1yr/90bf1dd5f5221290dfc1b3e18d8cbe1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"'''\n", | |
" Here is a prototype of what a bootstrap approach would look like\n", | |
" for remaining time estimation.\n", | |
" Here a random scenario is created\n", | |
"'''" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"from math import *\n", | |
"\n", | |
"def bootstrap(simulation_till_now, completed):\n", | |
" sample_props = []\n", | |
" for _ in range(10000):\n", | |
" sample = np.random.choice(simulation_till_now, size=ceil(.1*len(simulation_till_now)))\n", | |
" sample_props.append(sample.mean())\n", | |
" # Upper bound is 95%, lower bound is 30%\n", | |
" upper, lower = np.percentile(sample_props, [30, 97.5]) \n", | |
" \n", | |
" # Remaining simulation / Progress speed\n", | |
" return (100.0-completed)/upper,(100.0-completed)/lower " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def _format_time(time_in_s):\n", | |
" '''\n", | |
" Helper function to format time in seconds, minutes, hours, days, depending\n", | |
" on the magnitude.\n", | |
" Examples\n", | |
" --------\n", | |
" >>> from brian2.core.network import _format_time\n", | |
" >>> _format_time(12345)\n", | |
" '3h 25m 45s'\n", | |
" >>> _format_time(123)\n", | |
" '2m 3s'\n", | |
" >>> _format_time(12.5)\n", | |
" '12s'\n", | |
" >>> _format_time(.5)\n", | |
" '< 1s'\n", | |
" '''\n", | |
" divisors = [24*60*60, 60*60, 60, 1]\n", | |
" letters = ['d', 'h', 'm', 's']\n", | |
" remaining = time_in_s\n", | |
" text = ''\n", | |
" for divisor, letter in zip(divisors, letters):\n", | |
" time_to_represent = int(remaining / divisor)\n", | |
" remaining -= time_to_represent * divisor\n", | |
" if time_to_represent > 0 or len(text):\n", | |
" if len(text):\n", | |
" text += ' '\n", | |
" text += '%d%s' % (time_to_represent, letter)\n", | |
"\n", | |
" # less than one second\n", | |
" if len(text) == 0:\n", | |
" text = '< 1s'\n", | |
"\n", | |
" return text" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Estimated time remaining- 2h 45m 29s-2m 21s while remaining time was 2m 16s\n", | |
"Estimated time remaining- 2h 44m 39s-2m 21s while remaining time was 2m 15s\n", | |
"Estimated time remaining- 4m 18s-2m 20s while remaining time was 2m 14s\n", | |
"Estimated time remaining- 4m 11s-32s while remaining time was 2m 13s\n", | |
"Estimated time remaining- 53m 0s-32s while remaining time was 2m 12s\n", | |
"Estimated time remaining- 4m 7s-31s while remaining time was 2m 11s\n", | |
"Estimated time remaining- 4m 5s-31s while remaining time was 2m 10s\n", | |
"Estimated time remaining- 4m 11s-31s while remaining time was 2m 9s\n", | |
"Estimated time remaining- 4m 2s-31s while remaining time was 2m 8s\n", | |
"Estimated time remaining- 3m 29s-48s while remaining time was 2m 7s\n", | |
"Estimated time remaining- 4m 3s-48s while remaining time was 2m 6s\n", | |
"Estimated time remaining- 3m 36s-41s while remaining time was 2m 5s\n", | |
"Estimated time remaining- 2m 45s-40s while remaining time was 2m 4s\n", | |
"Estimated time remaining- 2m 40s-39s while remaining time was 2m 3s\n", | |
"Estimated time remaining- 2m 19s-37s while remaining time was 2m 2s\n", | |
"Estimated time remaining- 2m 18s-37s while remaining time was 2m 1s\n", | |
"Estimated time remaining- 1m 55s-36s while remaining time was 2m 0s\n", | |
"Estimated time remaining- 2m 15s-36s while remaining time was 1m 59s\n", | |
"Estimated time remaining- 2m 17s-36s while remaining time was 1m 58s\n", | |
"Estimated time remaining- 2m 16s-41s while remaining time was 1m 57s\n", | |
"Estimated time remaining- 2m 12s-40s while remaining time was 1m 56s\n", | |
"Estimated time remaining- 2m 1s-36s while remaining time was 1m 55s\n", | |
"Estimated time remaining- 2m 0s-36s while remaining time was 1m 54s\n", | |
"Estimated time remaining- 2m 2s-37s while remaining time was 1m 53s\n", | |
"Estimated time remaining- 2m 8s-37s while remaining time was 1m 52s\n", | |
"Estimated time remaining- 2m 7s-37s while remaining time was 1m 51s\n", | |
"Estimated time remaining- 2m 11s-37s while remaining time was 1m 50s\n", | |
"Estimated time remaining- 2m 17s-38s while remaining time was 1m 49s\n", | |
"Estimated time remaining- 2m 29s-38s while remaining time was 1m 48s\n", | |
"Estimated time remaining- 2m 12s-41s while remaining time was 1m 47s\n", | |
"Estimated time remaining- 2m 15s-42s while remaining time was 1m 46s\n", | |
"Estimated time remaining- 2m 11s-42s while remaining time was 1m 45s\n", | |
"Estimated time remaining- 2m 10s-42s while remaining time was 1m 44s\n", | |
"Estimated time remaining- 2m 13s-43s while remaining time was 1m 43s\n", | |
"Estimated time remaining- 2m 12s-42s while remaining time was 1m 42s\n", | |
"Estimated time remaining- 2m 15s-42s while remaining time was 1m 41s\n", | |
"Estimated time remaining- 2m 16s-43s while remaining time was 1m 40s\n", | |
"Estimated time remaining- 2m 11s-42s while remaining time was 1m 39s\n", | |
"Estimated time remaining- 2m 14s-42s while remaining time was 1m 38s\n", | |
"Estimated time remaining- 2m 0s-43s while remaining time was 1m 37s\n", | |
"Estimated time remaining- 2m 3s-45s while remaining time was 1m 36s\n", | |
"Estimated time remaining- 2m 4s-44s while remaining time was 1m 35s\n", | |
"Estimated time remaining- 1m 55s-42s while remaining time was 1m 34s\n", | |
"Estimated time remaining- 1m 50s-41s while remaining time was 1m 33s\n", | |
"Estimated time remaining- 1m 50s-40s while remaining time was 1m 32s\n", | |
"Estimated time remaining- 1m 55s-41s while remaining time was 1m 31s\n", | |
"Estimated time remaining- 1m 55s-41s while remaining time was 1m 30s\n", | |
"Estimated time remaining- 1m 58s-41s while remaining time was 1m 29s\n", | |
"Estimated time remaining- 1m 56s-41s while remaining time was 1m 28s\n", | |
"Estimated time remaining- 1m 55s-44s while remaining time was 1m 27s\n", | |
"Estimated time remaining- 1m 49s-42s while remaining time was 1m 26s\n", | |
"Estimated time remaining- 1m 46s-42s while remaining time was 1m 25s\n", | |
"Estimated time remaining- 1m 48s-42s while remaining time was 1m 24s\n", | |
"Estimated time remaining- 1m 51s-42s while remaining time was 1m 23s\n", | |
"Estimated time remaining- 1m 51s-41s while remaining time was 1m 22s\n", | |
"Estimated time remaining- 1m 48s-42s while remaining time was 1m 21s\n", | |
"Estimated time remaining- 1m 50s-41s while remaining time was 1m 20s\n", | |
"Estimated time remaining- 1m 52s-42s while remaining time was 1m 19s\n", | |
"Estimated time remaining- 1m 55s-42s while remaining time was 1m 18s\n", | |
"Estimated time remaining- 1m 52s-44s while remaining time was 1m 17s\n", | |
"Estimated time remaining- 1m 46s-43s while remaining time was 1m 16s\n", | |
"Estimated time remaining- 1m 42s-41s while remaining time was 1m 15s\n", | |
"Estimated time remaining- 1m 43s-41s while remaining time was 1m 14s\n", | |
"Estimated time remaining- 1m 43s-41s while remaining time was 1m 13s\n", | |
"Estimated time remaining- 1m 46s-42s while remaining time was 1m 12s\n", | |
"Estimated time remaining- 1m 38s-40s while remaining time was 1m 11s\n", | |
"Estimated time remaining- 1m 42s-40s while remaining time was 1m 10s\n", | |
"Estimated time remaining- 1m 36s-38s while remaining time was 1m 9s\n", | |
"Estimated time remaining- 1m 37s-39s while remaining time was 1m 8s\n", | |
"Estimated time remaining- 1m 29s-39s while remaining time was 1m 7s\n", | |
"Estimated time remaining- 1m 32s-38s while remaining time was 1m 6s\n", | |
"Estimated time remaining- 1m 23s-35s while remaining time was 1m 5s\n", | |
"Estimated time remaining- 1m 22s-35s while remaining time was 1m 4s\n", | |
"Estimated time remaining- 1m 22s-34s while remaining time was 1m 3s\n", | |
"Estimated time remaining- 1m 21s-34s while remaining time was 1m 2s\n", | |
"Estimated time remaining- 1m 22s-34s while remaining time was 1m 1s\n", | |
"Estimated time remaining- 1m 22s-35s while remaining time was 1m 0s\n", | |
"Estimated time remaining- 1m 20s-34s while remaining time was 59s\n", | |
"Estimated time remaining- 1m 21s-34s while remaining time was 58s\n", | |
"Estimated time remaining- 1m 13s-32s while remaining time was 57s\n", | |
"Estimated time remaining- 1m 11s-32s while remaining time was 56s\n", | |
"Estimated time remaining- 1m 9s-31s while remaining time was 55s\n", | |
"Estimated time remaining- 1m 7s-30s while remaining time was 54s\n", | |
"Estimated time remaining- 1m 8s-30s while remaining time was 53s\n", | |
"Estimated time remaining- 1m 9s-31s while remaining time was 52s\n", | |
"Estimated time remaining- 1m 10s-31s while remaining time was 51s\n", | |
"Estimated time remaining- 1m 7s-30s while remaining time was 50s\n", | |
"Estimated time remaining- 1m 8s-30s while remaining time was 49s\n", | |
"Estimated time remaining- 1m 9s-31s while remaining time was 48s\n", | |
"Estimated time remaining- 1m 7s-31s while remaining time was 47s\n", | |
"Estimated time remaining- 1m 0s-27s while remaining time was 46s\n", | |
"Estimated time remaining- 55s-26s while remaining time was 45s\n", | |
"Estimated time remaining- 56s-26s while remaining time was 44s\n", | |
"Estimated time remaining- 57s-26s while remaining time was 43s\n", | |
"Estimated time remaining- 55s-25s while remaining time was 42s\n", | |
"Estimated time remaining- 56s-26s while remaining time was 41s\n", | |
"Estimated time remaining- 56s-25s while remaining time was 40s\n", | |
"Estimated time remaining- 55s-25s while remaining time was 39s\n", | |
"Estimated time remaining- 53s-24s while remaining time was 38s\n", | |
"Estimated time remaining- 51s-24s while remaining time was 37s\n", | |
"Estimated time remaining- 52s-24s while remaining time was 36s\n", | |
"Estimated time remaining- 48s-22s while remaining time was 35s\n", | |
"Estimated time remaining- 48s-23s while remaining time was 34s\n", | |
"Estimated time remaining- 47s-22s while remaining time was 33s\n", | |
"Estimated time remaining- 46s-22s while remaining time was 32s\n", | |
"Estimated time remaining- 40s-19s while remaining time was 31s\n", | |
"Estimated time remaining- 39s-18s while remaining time was 30s\n", | |
"Estimated time remaining- 38s-18s while remaining time was 29s\n", | |
"Estimated time remaining- 38s-18s while remaining time was 28s\n", | |
"Estimated time remaining- 38s-18s while remaining time was 27s\n", | |
"Estimated time remaining- 33s-16s while remaining time was 26s\n", | |
"Estimated time remaining- 34s-16s while remaining time was 25s\n", | |
"Estimated time remaining- 33s-16s while remaining time was 24s\n", | |
"Estimated time remaining- 33s-16s while remaining time was 23s\n", | |
"Estimated time remaining- 31s-15s while remaining time was 22s\n", | |
"Estimated time remaining- 26s-13s while remaining time was 21s\n", | |
"Estimated time remaining- 26s-13s while remaining time was 20s\n", | |
"Estimated time remaining- 24s-12s while remaining time was 19s\n", | |
"Estimated time remaining- 24s-11s while remaining time was 18s\n", | |
"Estimated time remaining- 23s-11s while remaining time was 17s\n", | |
"Estimated time remaining- 23s-11s while remaining time was 16s\n", | |
"Estimated time remaining- 23s-11s while remaining time was 15s\n", | |
"Estimated time remaining- 23s-11s while remaining time was 14s\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Estimated time remaining- 20s-10s while remaining time was 13s\n", | |
"Estimated time remaining- 21s-10s while remaining time was 12s\n", | |
"Estimated time remaining- 20s-10s while remaining time was 11s\n", | |
"Estimated time remaining- 21s-10s while remaining time was 10s\n", | |
"Estimated time remaining- 16s-7s while remaining time was 9s\n", | |
"Estimated time remaining- 15s-7s while remaining time was 8s\n", | |
"Estimated time remaining- 11s-5s while remaining time was 7s\n", | |
"Estimated time remaining- 11s-5s while remaining time was 6s\n", | |
"Estimated time remaining- 6s-3s while remaining time was 5s\n", | |
"Estimated time remaining- 6s-3s while remaining time was 4s\n", | |
"Estimated time remaining- 2s-1s while remaining time was 3s\n", | |
"Estimated time remaining- 2s-1s while remaining time was 2s\n", | |
"Estimated time remaining- < 1s-< 1s while remaining time was 1s\n" | |
] | |
} | |
], | |
"source": [ | |
"# simulation_progress stores progress updated every second for the simulation runtime\n", | |
"\n", | |
"simulation_progress = [ 0.01 , 0.71, 1.21, 1.59, 4.54, 4.57, 6. , 6.7 ,\n", | |
" 7.07, 7.88, 8.7 , 8.7 , 10.2 , 11.72, 13.19, 16.12,\n", | |
" 17.03, 18.44, 18.44, 18.76, 18.76, 19.83, 22.6 , 23.24,\n", | |
" 23.52, 23.52, 24.33, 24.6 , 24.6 , 24.6 , 25.55, 26. ,\n", | |
" 26.93, 27.7 , 27.7 , 28.36, 28.6 , 28.79, 30.08, 30.47,\n", | |
" 31.87, 32.21, 32.29, 34.43, 36.18, 36.18, 36.18, 36.61,\n", | |
" 36.61, 37.29, 37.29, 39.05, 39.79, 40.02, 40.02, 40.76,\n", | |
" 41.36, 41.48, 41.48, 41.48, 41.48, 43.44, 45.03, 45.03,\n", | |
" 45.03, 45.26, 46.9 , 47.06, 48.45, 48.77, 50.07, 50.07,\n", | |
" 52.86, 53.23, 53.97, 54.43, 54.73, 54.88, 55.58, 55.88,\n", | |
" 58.31, 59.06, 60. , 60.87, 60.87, 60.92, 60.92, 62.16,\n", | |
" 62.16, 62.19, 62.84, 65.6 , 67.39, 67.39, 67.39, 68.32,\n", | |
" 68.32, 68.37, 69.18, 70.09, 70.58, 70.72, 72.42, 72.51,\n", | |
" 73.02, 73.81, 76.73, 77.25, 77.92, 77.92, 77.92, 80.2 ,\n", | |
" 80.2 , 80.35, 80.71, 81.65, 84.35, 84.35, 85.43, 85.77,\n", | |
" 86.26, 86.26, 86.32, 86.34, 87.8 , 87.82, 88.04, 88.04,\n", | |
" 90.76, 90.88, 93.15, 93.23, 96.2 , 96.29, 98.23, 98.69,\n", | |
" 100. ]\n", | |
"\n", | |
"# simulation_progress_diff stores progress done per second during the simulation\n", | |
"\n", | |
"simulation_progress_diff = [0.01 , 0.71, 0.49, 0.38, 2.95, 0.03, 1.43, 0.69, 0.37, 0.81, 0.83,\n", | |
" 0. , 1.5 , 1.52, 1.47, 2.92, 0.91, 1.41, 0. , 0.32, 0. , 1.08,\n", | |
" 2.76, 0.65, 0.28, 0. , 0.81, 0.27, 0. , 0. , 0.95, 0.45, 0.93,\n", | |
" 0.76, 0. , 0.67, 0.23, 0.2 , 1.29, 0.39, 1.4 , 0.34, 0.08, 2.14,\n", | |
" 1.75, 0. , 0. , 0.43, 0. , 0.68, 0. , 1.75, 0.75, 0.23, 0. ,\n", | |
" 0.73, 0.6 , 0.12, 0. , 0. , 0. , 1.96, 1.59, 0. , 0. , 0.23,\n", | |
" 1.65, 0.16, 1.39, 0.32, 1.29, 0. , 2.79, 0.38, 0.74, 0.46, 0.3 ,\n", | |
" 0.15, 0.7 , 0.31, 2.43, 0.75, 0.94, 0.87, 0. , 0.04, 0. , 1.24,\n", | |
" 0. , 0.03, 0.65, 2.76, 1.79, 0. , 0. , 0.93, 0. , 0.05, 0.82,\n", | |
" 0.9 , 0.5 , 0.13, 1.71, 0.09, 0.51, 0.79, 2.92, 0.52, 0.67, 0. ,\n", | |
" 0. , 2.27, 0. , 0.15, 0.36, 0.94, 2.7 , 0. , 1.08, 0.34, 0.49,\n", | |
" 0. , 0.06, 0.02, 1.45, 0.02, 0.22, 0. , 2.72, 0.12, 2.27, 0.08,\n", | |
" 2.97, 0.09, 1.94, 0.45, 2.54]\n", | |
"\n", | |
"progress_per_second = []\n", | |
"progress_per_second.append(0.01)\n", | |
"\n", | |
"sim_duration = len(simulation_progress)\n", | |
"\n", | |
"# Computing estimated time remaining every second\n", | |
"\n", | |
"for i in range(1,len(simulation_progress),1):\n", | |
" #progress done per second till now\n", | |
" progress_per_second.append(simulation_progress[i] - simulation_progress[i-1]) \n", | |
" \n", | |
" # Upper and lower values are in seconds\n", | |
" u,l = bootstrap(progress_per_second,simulation_progress[i])\n", | |
" \n", | |
" upper = _format_time(int(u))\n", | |
" lower = _format_time(int(l))\n", | |
" \n", | |
" RemTime = _format_time(sim_duration - i) #Real remaining time for the simulation\n", | |
" \n", | |
" print('Estimated time remaining-',upper + '-'+ lower + ' while remaining time was '+RemTime)\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"'''\n", | |
"Calculated estimated time is within the range for every second\n", | |
"'''" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.6.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment