This notebook illustrates the progressbar class specific to be used inside a notebook.
Note: If you implement a simulator inheritting from SimulationRunner
then you already get a progressbar. Set the value of update_progress_function_style
property in your __init__
method to "ipython"
to use the notebook specific progressbar.
In [1]:
from time import sleep
import numpy as np
from IPython.display import clear_output, display
from pyphysim.simulations.progressbar import *
from pyphysim.simulations.results import *
from pyphysim.simulations.runner import *
In [2]:
bar = ProgressBarIPython(20, 'Simulating $a+2^2$')
bar.progress(2)
In [3]:
bar.progress(10)
In [4]:
from ipywidgets.widgets import IntProgress, FloatProgress, Text, HBox, VBox
In [5]:
bar2 = IntProgress(description='lala')
In [6]:
bar2.value=50.5
bar.prog_bar.value=50.5
In [7]:
p = FloatProgress()
p.value = 30
t = Text()
t.value = ''
t.visible = True
container = HBox()
container.children = [p, t]
container2 = VBox()
container2.children = [p, t]
display(container)
display(container2)
In [8]:
class MyRunner(SimulationRunner):
def __init__(self):
SimulationRunner.__init__(self, read_command_line_args=False)
self.rep_max = 50
self.update_progress_function_style = 'ipython' #'ipython'
def _run_simulation(self, current_parameters):
sleep(0.1)
return SimulationResults()
runner = MyRunner()
runner.simulate()
In [9]:
rep_max = 30
barra = ProgressBarIPython(rep_max, 'This is the message')
# barra.side_message.set_css({
# 'margin-left': '10pt',
# #'margin-bottom': '20pt',
# })
for i in range(rep_max+1):
sleep(0.1)
barra.progress(i)