<commit_before># This file is part of QuTiP.
#
#    QuTiP is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    QuTiP is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with QuTiP.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2011-2013, <NAME> & <NAME>
#
###########################################################################
"""
This module contains utility functions for using QuTiP with IPython notebooks.
"""

from IPython.parallel import Client
from IPython.display import HTML, Javascript, display

import matplotlib.pyplot as plt

import datetime
import uuid
import sys
import os
import time

import qutip
import numpy
import scipy
import Cython
import matplotlib
import IPython


def version_table():
    """
    Print an HTML-formatted table with version numbers for QuTiP and its
    dependencies. Use it in a IPython notebook to show which versions of
    different packages that were used to run the notebook. This should make it
    possible to reproduce the environment and the calculation later on.


    Returns
    --------
    version_table: string
        Return an HTML-formatted string containing version information for
        QuTiP dependencies.

    """

    html = "<table>"
    html += "<tr><th>Software</th><th>Version</th></tr>"

    packages = {"QuTiP": qutip.__version__,
                "Numpy": numpy.__version__,
                "SciPy": scipy.__version__,
                "matplotlib": matplotlib.__version__,
                "Cython": Cython.__version__,
                "Python": sys.version,
                "IPython": IPython.__version__,
                "OS": "%s [%s]" % (os.name, sys.platform)
                }

    for name in packages:
        html += "<tr><td>%s</td><td>%s</td></tr>" % (name, packages[name])

    html += "<tr><td colspan='2'>%s</td></tr>" % time.strftime(
        '%a %b %d %H:%M:%S %Y %Z')
    html += "</table>"

    return HTML(html)


class HTMLProgressBar():
    """
    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=0):
        self.N = float(iterations)
        self.divid = str(uuid.uuid4())
        self.pb = HTML("""\
<div style="border: 1px solid grey; width: 600px">
  <div id="%s" \
style="background-color: rgba(0,200,0,0.35); width:0%%">&nbsp;</div>
</div>
""" % self.divid)
        display(self.pb)

    def start(self, iterations=0, chunk_size=0):
        self.N = float(iterations)

    def update(self, n):
        p = (n / self.N) * 100.0
        display(Javascript("$('div#%s').width('%i%%')" % (self.divid, p)))

    def finished(self):
        pass

def _visualize_parfor_data(metadata):
    """
    Visalizing the task scheduling meta data collected from AsyncResults.
    """
    res = numpy.array(metadata)
    fig, ax = plt.subplots(figsize=(10, res.shape[1]))

    yticks = []
    yticklabels = []
    tmin = min(res[:, 1])<commit_msg>set HTMLProgressBar to 100% when finished() is called<commit_after># This file is part of QuTiP.
#
#    QuTiP is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    QuTiP is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with QuTiP.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2011-2013, <NAME> & <NAME>
#
###########################################################################
"""
This module contains utility functions for using QuTiP with IPython notebooks.
"""

from IPython.parallel import Client
from IPython.display import HTML, Javascript, display

import matplotlib.pyplot as plt

import datetime
import uuid
import sys
import os
import time

import qutip
import numpy
import scipy
import Cython
import matplotlib
import IPython


def version_table():
    """
    Print an HTML-formatted table with version numbers for QuTiP and its
    dependencies. Use it in a IPython notebook to show which versions of
    different packages that were used to run the notebook. This should make it
    possible to reproduce the environment and the calculation later on.


    Returns
    --------
    version_table: string
        Return an HTML-formatted string containing version information for
        QuTiP dependencies.

    """

    html = "<table>"
    html += "<tr><th>Software</th><th>Version</th></tr>"

    packages = {"QuTiP": qutip.__version__,
                "Numpy": numpy.__version__,
                "SciPy": scipy.__version__,
                "matplotlib": matplotlib.__version__,
                "Cython": Cython.__version__,
                "Python": sys.version,
                "IPython": IPython.__version__,
                "OS": "%s [%s]" % (os.name, sys.platform)
                }

    for name in packages:
        html += "<tr><td>%s</td><td>%s</td></tr>" % (name, packages[name])

    html += "<tr><td colspan='2'>%s</td></tr>" % time.strftime(
        '%a %b %d %H:%M:%S %Y %Z')
    html += "</table>"

    return HTML(html)


class HTMLProgressBar():
    """
    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=0):
        self.N = float(iterations)
        self.divid = str(uuid.uuid4())
        self.pb = HTML("""\
<div style="border: 1px solid grey; width: 600px">
  <div id="%s" \
style="background-color: rgba(0,200,0,0.35); width:0%%">&nbsp;</div>
</div>
""" % self.divid)
        display(self.pb)

    def start(self, iterations=0, chunk_size=0):
        self.N = float(iterations)

    def update(self, n):
        p = (n / self.N) * 100.0
        display(Javascript("$('div#%s').width('%i%%')" % (self.divid, p)))

    def finished(self):
        display(Javascript("$('div#%s').width('%i%%')" % (self.divid, 100.0)))

def _visualize_parfor_data(metadata):
    """
    Visalizing the task scheduling meta data collected from AsyncResults.
    """
    res = numpy.array(metadata)
    fig, ax = plt.subplots(figsize=(10, res.shape[1]))

    yticks = []
    yticklabels = []
    tmin = min(res[:, 1])
{'fraction_non_alphanumeric': 0.14098448368111288, 'fraction_numerical': 0.012172284644194757, 'mean_word_length': 2.8382956878850103, 'pattern_counts': {'":': 16, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5068643', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2234, 'n_words': 730}