Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate visualization code #11636

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions qiskit/visualization/circuit/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ def get_bit_register(circuit, bit):
return bit_loc.registers[0][0] if bit_loc.registers else None


@deprecate_arg("reverse_bits", since="0.22.0", package_name="qiskit-terra")
@deprecate_arg(
"reverse_bits",
since="0.22.0",
package_name="qiskit-terra",
removal_timeline="in the Qiskit 1.0 release",
)
def get_bit_reg_index(circuit, bit, reverse_bits=None):
"""Get the register for a bit if there is one, and the index of the bit
from the top of the circuit, or the index of the bit within a register.
Expand Down Expand Up @@ -285,7 +290,12 @@ def get_wire_label(drawer, register, index, layout=None, cregbundle=True):
return wire_label


@deprecate_arg("reverse_bits", since="0.22.0", package_name="qiskit-terra")
@deprecate_arg(
"reverse_bits",
since="0.22.0",
package_name="qiskit-terra",
removal_timeline="in the Qiskit 1.0 release",
)
def get_condition_label_val(condition, circuit, cregbundle, reverse_bits=None):
"""Get the label and value list to display a condition

Expand Down
2 changes: 1 addition & 1 deletion qiskit/visualization/counts_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _is_deprecated_data_format(data) -> bool:
since="0.22.0",
additional_msg="Instead, use ``plot_distribution()``.",
predicate=_is_deprecated_data_format,
pending=True,
pending=False,
package_name="qiskit-terra",
)
def plot_histogram(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

deprecations:
- |
Passing a :class:`.QuasiDistribution`,
:class:`.ProbDistribution`, or a distribution dictionary in for the ``data``
argument of the :func:`.plot_histogram` visualization function is now
deprecated. Support for doing this will be removed in the Qiskit 1.0 release.
If you would like to plot a histogram from a :class:`.QuasiDistribution`,
:class:`.ProbDistribution`, or a distribution dictionary you should
use the :func:`.plot_distribution` function instead.
129 changes: 69 additions & 60 deletions test/python/visualization/test_plot_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from collections import Counter

from qiskit.visualization import plot_histogram
from qiskit.result import QuasiDistribution, ProbDistribution
from qiskit.utils import optionals
from .visualization import QiskitVisualizationTestCase

Expand All @@ -33,19 +34,19 @@ class TestPlotHistogram(QiskitVisualizationTestCase):
def test_different_counts_lengths(self):
"""Test plotting two different length dists works"""
exact_dist = {
"000000": 0.015624999999999986,
"000001": 0.015624999999999986,
"000011": 0.031249999999999965,
"000111": 0.06249999999999992,
"100000": 0.015624999999999986,
"100001": 0.015624999999999986,
"100011": 0.031249999999999965,
"100111": 0.06249999999999992,
"110000": 0.031249999999999965,
"110001": 0.031249999999999965,
"110011": 0.06249999999999992,
"110111": 0.12499999999999982,
"111111": 0.4999999999999991,
"000000": 1,
"000001": 1,
"000011": 2,
"000111": 4,
"100000": 1,
"100001": 1,
"100011": 2,
"100111": 4,
"110000": 2,
"110001": 2,
"110011": 4,
"110111": 10,
"111111": 32,
}

raw_dist = {
Expand Down Expand Up @@ -131,72 +132,72 @@ def test_with_number_to_keep_multiple_executions(self):
def test_with_number_to_keep_multiple_executions_correct_image(self):
"""Test plotting using number_to_keep with multiple executions"""
data_noisy = {
"00000": 0.22,
"00001": 0.003,
"00010": 0.005,
"00011": 0.0,
"00100": 0.004,
"00101": 0.001,
"00110": 0.004,
"00111": 0.001,
"01000": 0.005,
"01001": 0.0,
"01010": 0.002,
"01011": 0.0,
"01100": 0.225,
"01101": 0.001,
"01110": 0.003,
"01111": 0.003,
"10000": 0.012,
"10001": 0.002,
"10010": 0.001,
"10011": 0.001,
"10100": 0.247,
"10101": 0.004,
"10110": 0.003,
"10111": 0.001,
"11000": 0.225,
"11001": 0.005,
"11010": 0.002,
"11011": 0.0,
"11100": 0.015,
"11101": 0.004,
"11110": 0.001,
"11111": 0.0,
"00000": 22,
"00001": 3,
"00010": 5,
"00011": 0,
"00100": 4,
"00101": 1,
"00110": 4,
"00111": 1,
"01000": 5,
"01001": 0,
"01010": 2,
"01011": 0,
"01100": 225,
"01101": 1,
"01110": 3,
"01111": 3,
"10000": 12,
"10001": 2,
"10010": 1,
"10011": 1,
"10100": 247,
"10101": 4,
"10110": 3,
"10111": 1,
"11000": 225,
"11001": 5,
"11010": 2,
"11011": 0,
"11100": 15,
"11101": 4,
"11110": 1,
"11111": 0,
}
data_ideal = {
"00000": 0.25,
"00000": 25,
"00001": 0,
"00010": 0,
"00011": 0,
"00100": 0,
"00101": 0,
"00110": 0,
"00111": 0.0,
"01000": 0.0,
"00111": 0,
"01000": 0,
"01001": 0,
"01010": 0.0,
"01011": 0.0,
"01100": 0.25,
"01010": 0,
"01011": 0,
"01100": 25,
"01101": 0,
"01110": 0,
"01111": 0,
"10000": 0,
"10001": 0,
"10010": 0.0,
"10011": 0.0,
"10100": 0.25,
"10010": 0,
"10011": 0,
"10100": 25,
"10101": 0,
"10110": 0,
"10111": 0,
"11000": 0.25,
"11000": 25,
"11001": 0,
"11010": 0,
"11011": 0,
"11100": 0.0,
"11100": 0,
"11101": 0,
"11110": 0,
"11111": 0.0,
"11111": 0,
}
data_ref_noisy = dict(Counter(data_noisy).most_common(5))
data_ref_noisy["rest"] = sum(data_noisy.values()) - sum(data_ref_noisy.values())
Expand All @@ -214,11 +215,10 @@ def test_with_number_to_keep_multiple_executions_correct_image(self):
mpl.pyplot.close(figure_ref)
mpl.pyplot.close(figure_truncated)

@unittest.skipUnless(optionals.HAS_MATPLOTLIB, "matplotlib not available.")
def test_number_of_items_in_legend_with_data_starting_with_zero(self):
"""Test legend if there's a 0 value at the first item of the dataset"""
dist_1 = {"0": 0.369, "1": 0.13975}
dist_2 = {"0": 0, "1": 0.48784}
dist_1 = {"0": 369, "1": 140}
dist_2 = {"0": 0, "1": 488}
legend = ["lengend_1", "lengend_2"]
plot = plot_histogram([dist_1, dist_2], legend=legend)
self.assertEqual(
Expand All @@ -227,6 +227,15 @@ def test_number_of_items_in_legend_with_data_starting_with_zero(self):
"Plot should have the same number of legend items as defined",
)

def test_deprecation(self):
"""Test that passing `QuasiDist`, `ProbDist` or a dict of floats is deprecated."""
with self.assertWarns(DeprecationWarning):
plot_histogram(QuasiDistribution({"00": 1.0}))
with self.assertWarns(DeprecationWarning):
plot_histogram(ProbDistribution({"00": 1.0}))
with self.assertWarns(DeprecationWarning):
plot_histogram({"00": 1.0})


if __name__ == "__main__":
unittest.main(verbosity=2)
Loading