Repository: qutip/qutip

Issue:
Allow solvers to use `HTMLProgressBar`
### Describe the Issue!

Most of our progress bars are in `qutip/ui/progressbar.py`, with the exception of `HTMLProgressBar` which is in `qutip/ipynbtools.py`. It is not available by the solvers.

It should be moved with the other and added it to the `progess_bars` dictionary so it's usable with `mesolve`, etc.


Discussion:
@Ericgig I would like to take up this issue. Can you please assign it to me?

Resolving patch:
diff --git a/qutip/ipynbtools.py b/qutip/ipynbtools.py
--- a/qutip/ipynbtools.py
+++ b/qutip/ipynbtools.py
@@ -1,7 +1,7 @@
 """
 This module contains utility functions for using QuTiP with IPython notebooks.
 """
-from qutip.ui.progressbar import BaseProgressBar
+from qutip.ui.progressbar import BaseProgressBar, HTMLProgressBar
 from .settings import _blas_info, available_cpu_count
 import IPython
 
@@ -11,16 +11,16 @@
     try:
         from ipyparallel import Client
         __all__ = ['version_table', 'plot_animation',
-                    'parallel_map', 'HTMLProgressBar']
+                    'parallel_map']
     except:
-         __all__ = ['version_table', 'plot_animation', 'HTMLProgressBar']
+         __all__ = ['version_table', 'plot_animation']
 else:
     try:
         from IPython.parallel import Client
         __all__ = ['version_table', 'plot_animation',
-                    'parallel_map', 'HTMLProgressBar']
+                    'parallel_map']
     except:
-         __all__ = ['version_table', 'plot_animation', 'HTMLProgressBar']
+         __all__ = ['version_table', 'plot_animation']
 
 
 from IPython.display import HTML, Javascript, display
@@ -97,57 +97,6 @@ def version_table(verbose=False):
     return HTML(html)
 
 
-class HTMLProgressBar(BaseProgressBar):
-    """
-    A simple HTML progress bar for using in IPython notebooks. Based on
-    IPython ProgressBar demo notebook:
-    https://github.com/ipython/ipython/tree/master/examples/notebooks
-
-    Example usage:
-
-        n_vec = linspace(0, 10, 100)
-        pbar = HTMLProgressBar(len(n_vec))
-        for n in n_vec:
-            pbar.update(n)
-            compute_with_n(n)
-    """
-
-    def __init__(self, iterations=0, chunk_size=1.0):
-        self.divid = str(uuid.uuid4())
-        self.textid = str(uuid.uuid4())
-        self.pb = HTML("""\
-<div style="border: 2px solid grey; width: 600px">
-  <div id="%s" \
-style="background-color: rgba(121,195,106,0.75); width:0%%">&nbsp;</div>
-</div>
-<p id="%s"></p>
-""" % (self.divid, self.textid))
-        display(self.pb)
-        super(HTMLProgressBar, self).start(iterations, chunk_size)
-
-    def start(self, iterations=0, chunk_size=1.0):
-        super(HTMLProgressBar, self).start(iterations, chunk_size)
-
-    def update(self, n):
-        p = (n / self.N) * 100.0
-        if p >= self.p_chunk:
-            lbl = ("Elapsed time: %s. " % self.time_elapsed() +
-                   "Est. remaining time: %s." % self.time_remaining_est(p))
-            js_code = ("$('div#%s').width('%i%%');" % (self.divid, p) +
-                       "$('p#%s').text('%s');" % (self.textid, lbl))
-            display(Javascript(js_code))
-            # display(Javascript("$('div#%s').width('%i%%')" % (self.divid,
-            # p)))
-            self.p_chunk += self.p_chunk_size
-
-    def finished(self):
-        self.t_done = time.time()
-        lbl = "Elapsed time: %s" % self.time_elapsed()
-        js_code = ("$('div#%s').width('%i%%');" % (self.divid, 100.0) +
-                   "$('p#%s').text('%s');" % (self.textid, lbl))
-        display(Javascript(js_code))
-
-
 def _visualize_parfor_data(metadata):
     """
     Visualizing the task scheduling meta data collected from AsyncResults.
diff --git a/qutip/ui/progressbar.py b/qutip/ui/progressbar.py
--- a/qutip/ui/progressbar.py
+++ b/qutip/ui/progressbar.py
@@ -1,6 +1,6 @@
 __all__ = ['BaseProgressBar', 'TextProgressBar',
            'EnhancedTextProgressBar', 'TqdmProgressBar',
-           'progess_bars']
+           'HTMLProgressBar', 'progess_bars']
 
 import time
 import datetime
@@ -145,6 +145,57 @@ def finished(self):
         self.t_done = time.time()
 
 
+class HTMLProgressBar(BaseProgressBar):
+    """
+    A simple HTML progress bar for using in IPython notebooks. Based on
+    IPython ProgressBar demo notebook:
+    https://github.com/ipython/ipython/tree/master/examples/notebooks
+
+    Example usage:
+
+        n_vec = linspace(0, 10, 100)
+        pbar = HTMLProgressBar(len(n_vec))
+        for n in n_vec:
+            pbar.update(n)
+            compute_with_n(n)
+    """
+
+    def __init__(self, iterations=0, chunk_size=1.0):
+        self.divid = str(uuid.uuid4())
+        self.textid = str(uuid.uuid4())
+        self.pb = HTML("""\
+<div style="border: 2px solid grey; width: 600px">
+  <div id="%s" \
+style="background-color: rgba(121,195,106,0.75); width:0%%">&nbsp;</div>
+</div>
+<p id="%s"></p>
+""" % (self.divid, self.textid))
+        display(self.pb)
+        super(HTMLProgressBar, self).start(iterations, chunk_size)
+
+    def start(self, iterations=0, chunk_size=1.0):
+        super(HTMLProgressBar, self).start(iterations, chunk_size)
+
+    def update(self, n):
+        p = (n / self.N) * 100.0
+        if p >= self.p_chunk:
+            lbl = ("Elapsed time: %s. " % self.time_elapsed() +
+                   "Est. remaining time: %s." % self.time_remaining_est(p))
+            js_code = ("$('div#%s').width('%i%%');" % (self.divid, p) +
+                       "$('p#%s').text('%s');" % (self.textid, lbl))
+            display(Javascript(js_code))
+            # display(Javascript("$('div#%s').width('%i%%')" % (self.divid,
+            # p)))
+            self.p_chunk += self.p_chunk_size
+
+    def finished(self):
+        self.t_done = time.time()
+        lbl = "Elapsed time: %s" % self.time_elapsed()
+        js_code = ("$('div#%s').width('%i%%');" % (self.divid, 100.0) +
+                   "$('p#%s').text('%s');" % (self.textid, lbl))
+        display(Javascript(js_code))
+
+
 progess_bars = {
     "Enhanced": EnhancedTextProgressBar,
     "enhanced": EnhancedTextProgressBar,
@@ -153,6 +204,8 @@ def finished(self):
     True: TextProgressBar,
     "Tqdm": TqdmProgressBar,
     "tqdm": TqdmProgressBar,
+    "Html": HTMLProgressBar,
+    "html": HTMLProgressBar,
     "": BaseProgressBar,
     False: BaseProgressBar,
     None: BaseProgressBar,


Test patch: