IBM-Quantum-Technical-Enablement / quantum-enablement

IBM Quantum Engineering and Enabling Technologies
Apache License 2.0
28 stars 8 forks source link

docs(notebooks): add utility scaling demo #20

Closed pedrorrivero closed 6 months ago

pedrorrivero commented 7 months ago

Summary

Adds Utility Scaling demo notebook cleaned and updated to Qiskit 1.0.

Details and comments

Requires merging of the following PRs first:

All code plus notebook can be found in the scaling branch of this repository for ease of access and execution. This is the way it has been shared since it was ready with people that required early access (e.g. for preparation of Practitioner's Forum APAC).

This PR is meant to provide a place to review the notebook in isolation.

coveralls commented 7 months ago

Pull Request Test Coverage Report for Build 8489985288

Details


Totals Coverage Status
Change from base Build 8489909505: 0.0%
Covered Lines: 290
Relevant Lines: 290

💛 - Coveralls
pedrorrivero commented 7 months ago

Tests seem to fail due to the name of the file holding the cached results being invalid for Windows:

> Run actions/checkout@v3
Syncing repository: IBM-Quantum-Technical-Enablement/quantum-enablement
> Getting Git version info
Temporarily overriding HOME='D:\a\_temp\e528dd69-442a-4685-be32-65faa8c21fe5' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
"C:\Program Files\Git\bin\git.exe" config --global --add safe.directory D:\a\quantum-enablement\quantum-enablement
Deleting the contents of 'D:\a\quantum-enablement\quantum-enablement'
> Initializing the repository
> Disabling automatic garbage collection
> Setting up auth
> Fetching the repository
> Determining the checkout info
v Checking out the ref
  "C:\Program Files\Git\bin\git.exe" checkout --progress --force refs/remotes/pull/20/merge
  Error: error: invalid path 'docs/notebooks/scaling/12x12_2024-02-16T18:40:[14](https://github.com/IBM-Quantum-Technical-Enablement/quantum-enablement/actions/runs/8084536689/job/22090468670?pr=20#step:2:15).0352[19](https://github.com/IBM-Quantum-Technical-Enablement/quantum-enablement/actions/runs/8084536689/job/22090468670?pr=20#step:2:21)+00:00.json'
  Error: The process 'C:\Program Files\Git\bin\git.exe' failed with exit code 128
itoko commented 7 months ago

I've just found average_distributions function should handle the edge case where the count of all-zero state is 0. Current notebook sometimes fails with ValueError when plotting the "Readout probabilities at different noise levels" figure. An example of half-baked figure looks like below (xval label 1024 suggests all-zero state was not observed within the shots xval label 1024 suggests all-zero state does not have the largest counts).

ValueError: The number of FixedLocator locations (3), usually from a call to set_ticks, does not match the number of labels (2).

image

itoko commented 7 months ago

Another small comment is datetime.UTC seems not in Python 3.10. If we want to support 3.10 or earlier, we many need to use datetime.timezone.utc instead.

pedrorrivero commented 6 months ago

Thanks for the comments @itoko 🙇🏼‍♂️

Although we have chatted already I will include my responses here for transparency.

The ValueError that you report is merely for plotting, the rest of the notebook should run smoothly nonetheless. This code should be able to fix it thought:

from qiskit.visualization import plot_distribution
from copy import deepcopy
import matplotlib.pyplot as plt

plt.rcParams.update({"text.usetex": True, "font.family": "Helvetica"})
fig, ax = plt.subplots(dpi=200)

ACCURATE_READOUT = "0" * NUM_QUBITS
plots_dict = deepcopy(results_dict)
plots_dict = {
    nf: {"0": counts.pop(ACCURATE_READOUT), "1": sum(counts.values())}
    for nf, counts in plots_dict.items()
}

plot_distribution(
    [plots_dict.get(nf) for nf in NOISE_FACTORS], 
    legend=[f"Noise factor: {nf:.1f}" for nf in NOISE_FACTORS],
    color=['lightgray', 'gray', 'black'],
    title="Readout probabilities at different noise levels",
    ax=ax,
)
ax.set_xticklabels(['Accurate', 'Error'], rotation=0)
ax.legend(fontsize=11)

plt.show()
itoko commented 6 months ago

We need to change the file name 12x12_2024-03-12T21:18:13.498254+00:00.json not to use ":" in it for Windows users. Otherwise, windows users fail to install quantum-enablement module, i.e. they are not able to do pip install quantum-enablement@git+https://github.com/IBM-Quantum-Technical-Enablement/quantum-enablement. I heard it today from a windows user.