Skip to content

Commit

Permalink
Add .is_processing() (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLaudatQM authored Jul 18, 2022
1 parent 8cc90d9 commit 4480430
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]
### Added
- Calibrations - a new package with an API to perform basic single qubit calibration protocols.
- Results.fetching_tool - Add the `.is_processing()` method.
### Fixed
- Loops - Fixed qua_logspace() and from_array() for logarithmic increments with integers.

Expand Down
23 changes: 14 additions & 9 deletions qualang_tools/results/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ These values must correspond to results saved in the stream processing. A flag i
- `mode="wait_for_all"` will wait until all values were processed for all named results before fetching.
- `mode="live"` will fetch data one by one for all named results for live plotting purposes.

### Usage example
Then the results can be fetched with the `.fetch_all()` method while the program is processing, as shown in the code snippet below.

### Usage example

```python
from qualang_tools.results import fetching_tool

n_avg = 1000
with program as prog:
# QUA program with n_avg averaging iterations

qmm = QuantumMachinesManager(host="127.0.0.1", port="80")
qm = qmm.open_qm(config)
job = qm.execute(qua_program)
job = qm.execute(prog)

my_results = fetching_tool(job, data_list=["I", "Q", "Ie", "Qe", "Ig", "Qg"], mode="live")

fig = plt.figure(figsize=(15, 15))
fig = plt.figure()

while job.result_handles.is_processing():
while my_results.is_processing():
# Live plotting
I, Q, Ie, Qe, Ig, Qg = my_results.fetch_all()
...
Expand All @@ -42,7 +47,7 @@ Several flags are available to customize the progress bar:
### Usage example

```python
from qualang_tools.results import result_tool, progress_counter
from qualang_tools.results import fetching_tool, progress_counter
import time

n_avg = 1000
Expand All @@ -52,14 +57,14 @@ with program as prog:

qmm = QuantumMachinesManager()
qm = qmm.open_qm(config)
job = qm.execute(cryoscope)
job = qm.execute(prog)

my_results = result_tool(job, data_list=["iteration", "I", "Q", "Ie", "Qe", "Ig", "Qg"], flag="live")
my_results = fetching_tool(job, data_list=["iteration", "I", "Q", "Ie", "Qe", "Ig", "Qg"], mode="live")

fig = plt.figure(figsize=(15, 15))
fig = plt.figure()

t0 = time.time()
while job.result_handles.is_processing():
while my_results.is_processing():
# Live plotting
iteration, I, Q, Ie, Qe, Ig, Qg = my_results.fetch_all()
progress_counter(iteration, n_avg, start_time=t0)
Expand Down
9 changes: 9 additions & 0 deletions qualang_tools/results/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def __init__(self, job, data_list, mode="wait_for_all"):
else:
raise Warning(f"{data} is not saved in the stream processing.")

def is_processing(self):
"""
Returns True while the program is processing. Used for live plotting.
**Example**: while my_results.is_processing():
:return: boolean flag which is True while the program is processing.
"""
return self.res_handles.is_processing()

def _format(self, data):
if type(data) == np.ndarray:
if type(data[0]) == np.void:
Expand Down

0 comments on commit 4480430

Please sign in to comment.