qiskit-documentation/docs/api/qiskit/0.43/qiskit.tools.events.TextPro...

139 lines
3.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: TextProgressBar
description: API reference for qiskit.tools.events.TextProgressBar
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.tools.events.TextProgressBar
---
# TextProgressBar
<Class id="qiskit.tools.events.TextProgressBar" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.24/qiskit/tools/events/progressbar.py" signature="TextProgressBar(output_handler=None)" modifiers="class">
Bases: `BaseProgressBar`
A simple text-based progress bar.
**output\_handlerthe handler the progress bar should be written to, default**
is sys.stdout, another option is sys.stderr
**Examples**
The progress bar can be used to track the progress of a parallel\_map.
```python
import numpy as np
import qiskit.tools.jupyter
from qiskit.tools.parallel import parallel_map
from qiskit.tools.events import TextProgressBar
TextProgressBar()
%qiskit_progress_bar -t text
parallel_map(np.sin, np.linspace(0,10,100));
```
And it can also be used individually.
```python
from qiskit.tools.events import TextProgressBar
iterations = 100
t = TextProgressBar()
t.start(iterations=iterations)
for i in range(iterations):
# step i of heavy calculation ...
t.update(i + 1) # update progress bar
```
## Methods
<span id="qiskit-tools-events-textprogressbar-clear" />
### clear
<Function id="qiskit.tools.events.TextProgressBar.clear" signature="TextProgressBar.clear()">
Unsubscribe everything
</Function>
<span id="qiskit-tools-events-textprogressbar-finished" />
### finished
<Function id="qiskit.tools.events.TextProgressBar.finished" signature="TextProgressBar.finished()">
Run when progress bar has completed.
</Function>
<span id="qiskit-tools-events-textprogressbar-start" />
### start
<Function id="qiskit.tools.events.TextProgressBar.start" signature="TextProgressBar.start(iterations)">
Start the progress bar.
**Parameters**
**iterations** (*int*) Number of iterations.
</Function>
<span id="qiskit-tools-events-textprogressbar-subscribe" />
### subscribe
<Function id="qiskit.tools.events.TextProgressBar.subscribe" signature="TextProgressBar.subscribe(event, callback)">
Subscribes to an event, associating a callback function to that event, so when the event occurs, the callback will be called. This is a blocking call, so try to keep callbacks as lightweight as possible.
</Function>
<span id="qiskit-tools-events-textprogressbar-time-elapsed" />
### time\_elapsed
<Function id="qiskit.tools.events.TextProgressBar.time_elapsed" signature="TextProgressBar.time_elapsed()">
Return the time elapsed since start.
**Returns**
Time since progress bar started.
**Return type**
elapsed\_time
</Function>
<span id="qiskit-tools-events-textprogressbar-time-remaining-est" />
### time\_remaining\_est
<Function id="qiskit.tools.events.TextProgressBar.time_remaining_est" signature="TextProgressBar.time_remaining_est(completed_iter)">
Estimate the remaining time left.
**Parameters**
**completed\_iter** (*int*) Number of iterations completed.
**Returns**
Estimated time remaining.
**Return type**
est\_time
</Function>
<span id="qiskit-tools-events-textprogressbar-unsubscribe" />
### unsubscribe
<Function id="qiskit.tools.events.TextProgressBar.unsubscribe" signature="TextProgressBar.unsubscribe(event, callback)">
Unsubscribe a pair event-callback, so the callback will not be called anymore when the event occurs.
</Function>
<span id="qiskit-tools-events-textprogressbar-update" />
### update
<Function id="qiskit.tools.events.TextProgressBar.update" signature="TextProgressBar.update(n)">
Update status of progress bar.
</Function>
</Class>