From d1bb2c1226daf59377088bd53a0bbf4c476eadbb Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 17 Aug 2022 13:24:37 +0200 Subject: [PATCH 01/22] add draft --- qiskit/visualization/__init__.py | 61 ++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 0ea3e9143828..7b88b4185432 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -20,16 +20,46 @@ Counts and State Visualizations =============================== +Install visualization optionals +------------------------------- +`pip install qiskit[visualization]` + +Common parameters +----------------- + +The figures created by counts and state visulizations functions (listed in the table below) are +genereted by `Matplotlib`. Some of the common parameters are listed here: + +- title (str): a text string to use for the plot title +- legend (list): a list of strings to use for labels of the data. +- figsize (tuple): figure size in inches +- color (str or list): string or lists of strings for plotting +- ax (Matplotlib.axes.Axes): An optional Axes object to be used for the visualization output. If + none is specified a new matplotlib Figure will be created and used. Additionally, if specified + there will be no returned Figure since it is redundant. +- filename (str) – file path to save image to. + +Use title and legend +-------------------- + +Change fig size +--------------- + +Change color +------------ + +Reuse axes +---------- + +Save figure to file +------------------- + + .. autosummary:: :toctree: ../stubs/ - plot_histogram - plot_bloch_vector - plot_bloch_multivector - plot_state_city - plot_state_hinton - plot_state_paulivec - plot_state_qsphere + plot_histogram plot_bloch_vector plot_bloch_multivector plot_state_city plot_state_hinton + plot_state_paulivec plot_state_qsphere Device Visualizations ===================== @@ -37,10 +67,7 @@ .. autosummary:: :toctree: ../stubs/ - plot_gate_map - plot_error_map - plot_circuit_layout - plot_coupling_map + plot_gate_map plot_error_map plot_circuit_layout plot_coupling_map Circuit Visualizations ====================== @@ -48,8 +75,7 @@ .. autosummary:: :toctree: ../stubs/ - circuit_drawer - ~qiskit.visualization.qcstyle.DefaultStyle + circuit_drawer ~qiskit.visualization.qcstyle.DefaultStyle DAG Visualizations ================== @@ -73,10 +99,8 @@ .. autosummary:: :toctree: ../stubs/ - ~qiskit.visualization.pulse_v2.draw - ~qiskit.visualization.pulse_v2.IQXStandard - ~qiskit.visualization.pulse_v2.IQXSimple - ~qiskit.visualization.pulse_v2.IQXDebugging + ~qiskit.visualization.pulse_v2.draw ~qiskit.visualization.pulse_v2.IQXStandard + ~qiskit.visualization.pulse_v2.IQXSimple ~qiskit.visualization.pulse_v2.IQXDebugging Timeline Visualizations ======================= @@ -84,8 +108,7 @@ .. autosummary:: :toctree: ../stubs/ - timeline_drawer - ~qiskit.visualization.timeline.draw + timeline_drawer ~qiskit.visualization.timeline.draw Single Qubit State Transition Visualizations ============================================ From 366534ad78866f66add3c94db825e9718d63c5a8 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Thu, 18 Aug 2022 13:48:35 +0200 Subject: [PATCH 02/22] revert unintended changes --- qiskit/visualization/__init__.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 7b88b4185432..dadd2372b1b7 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -58,8 +58,13 @@ .. autosummary:: :toctree: ../stubs/ - plot_histogram plot_bloch_vector plot_bloch_multivector plot_state_city plot_state_hinton - plot_state_paulivec plot_state_qsphere + plot_histogram + plot_bloch_vector + plot_bloch_multivector + plot_state_city + plot_state_hinton + plot_state_paulivec + plot_state_qsphere Device Visualizations ===================== @@ -67,7 +72,10 @@ .. autosummary:: :toctree: ../stubs/ - plot_gate_map plot_error_map plot_circuit_layout plot_coupling_map + plot_gate_map + plot_error_map + plot_circuit_layout + plot_coupling_map Circuit Visualizations ====================== @@ -99,8 +107,10 @@ .. autosummary:: :toctree: ../stubs/ - ~qiskit.visualization.pulse_v2.draw ~qiskit.visualization.pulse_v2.IQXStandard - ~qiskit.visualization.pulse_v2.IQXSimple ~qiskit.visualization.pulse_v2.IQXDebugging + ~qiskit.visualization.pulse_v2.draw + ~qiskit.visualization.pulse_v2.IQXStandard + ~qiskit.visualization.pulse_v2.IQXSimple + ~qiskit.visualization.pulse_v2.IQXDebugging Timeline Visualizations ======================= @@ -108,7 +118,8 @@ .. autosummary:: :toctree: ../stubs/ - timeline_drawer ~qiskit.visualization.timeline.draw + timeline_drawer + ~qiskit.visualization.timeline.draw Single Qubit State Transition Visualizations ============================================ From ac0a9965f7bf21e63c793f5b154487df2e374599 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Thu, 18 Aug 2022 13:48:48 +0200 Subject: [PATCH 03/22] revert unintended changes --- qiskit/visualization/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index dadd2372b1b7..24396be85498 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -83,7 +83,8 @@ .. autosummary:: :toctree: ../stubs/ - circuit_drawer ~qiskit.visualization.qcstyle.DefaultStyle + circuit_drawer + ~qiskit.visualization.qcstyle.DefaultStyle DAG Visualizations ================== From fe1918c1825240ed919973cf3f384de0f1819dfc Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 24 Aug 2022 12:34:07 +0200 Subject: [PATCH 04/22] add example usage --- qiskit/visualization/__init__.py | 134 +++++++++++++++++++++++++------ 1 file changed, 108 insertions(+), 26 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 24396be85498..cf08ef7dfd25 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2018. +# (C) Copyright IBM 2017, 2022. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -17,42 +17,124 @@ .. currentmodule:: qiskit.visualization + +Overview +======== + +The visualization module contain functions that visualizes measurement outcome counts, quantum +states, circuits, pulses, devices and more. + +Prerequisites +============= + +To use visualization functions, you are required to install visualization optionals to your +development environment: + +.. code-block:: bash + + pip install 'qiskit[visualization]' + Counts and State Visualizations =============================== -Install visualization optionals -------------------------------- -`pip install qiskit[visualization]` +This section contains functions that visualize measurement outcome counts and quantum states. + +Example Usage +------------- + +Here is an example of using :func:`plot_histogram` to visualize measurement outcome counts + +.. jupyter-execute:: + + from qiskit.tools.visualization import plot_histogram + + counts = {"00": 501, "11": 499} + plot_histogram(counts) + +The data can be a dictionary of bit string as key and counts as value or more commonly a +:class:`~qiskit.result.Counts` object obtained from :meth:`~qiskit.result.Result.get_counts`. + +Here is an example of using :func:`plot_state_city` to visualize a quantum state. + +.. jupyter-execute:: + + from qiskit.tools.visualization import plot_state_city + + state = [[0+1.0j, 0-1.0j], + [1-0.5j, 1+0.5j]] + plot_state_city(state) + +The state can be array-like list of list, numpy.array or more commonly +:class:`~qiskit.quantum_info.Statevector` or ~qiskit.quantum_info.DensityMatrix` objects obtained +from a circuit. + +.. jupyter-execute:: + + from qiskit import QuantumCircuit + from qiskit.quantum_info import Statevector, DensityMatrix + + qc = QuantumCircuit(2) + qc.h(0) + qc.cx(0,1) + + # plot using a Statevector + state = Statevector(qc) + plot_state_city(state) + +.. jupyter-execute:: + + # plot using a DensityMatrix + state = DensityMatrix(qc) + plot_state_city(state) + +.. + Common parameters + ----------------- + + The figures created by counts and state visulizations functions (listed in the table below) are + genereted by `Matplotlib`. Some of the common parameters are listed here: + + - title (str): a text string to use for the plot title + - legend (list): a list of strings to use for labels of the data. + - figsize (tuple): figure size in inches + - color (str or list): string or lists of strings for plotting + - ax (Matplotlib.axes.Axes): An optional Axes object to be used for the visualization output. If + none is specified a new matplotlib Figure will be created and used. Additionally, if specified + there will be no returned Figure since it is redundant. + - filename (str): file path to save image to. + + Use title and legend + -------------------- + + .. jupyter-execute:: + + from qiskit.tools.visualization import plot_histogram + + counts1 = {'00': 525, '11': 499} + counts2 = {'00': 511, '11': 514} -Common parameters ------------------ + data = [counts1, counts2] + plot_histogram(data) -The figures created by counts and state visulizations functions (listed in the table below) are -genereted by `Matplotlib`. Some of the common parameters are listed here: + You can specify `legend`, `title`, `figsize` and `color` by passing to the kwargs. -- title (str): a text string to use for the plot title -- legend (list): a list of strings to use for labels of the data. -- figsize (tuple): figure size in inches -- color (str or list): string or lists of strings for plotting -- ax (Matplotlib.axes.Axes): An optional Axes object to be used for the visualization output. If - none is specified a new matplotlib Figure will be created and used. Additionally, if specified - there will be no returned Figure since it is redundant. -- filename (str) – file path to save image to. + .. jupyter-execute:: -Use title and legend --------------------- + legend = ['First execution', 'Second execution'] + title = 'New histogram' + figsize = (10,10) + color=['crimson','midnightblue'] + plot_histogram(data, legend=legend, title=title, figsize=figsize, color=color) -Change fig size ---------------- + You can save the figure to file either by passing the file name to `filename` kwarg or use + `Matplotlib.Figure.savefig()` method. -Change color ------------- + .. jupyter-execute:: -Reuse axes ----------- + plot_histogram(data, filename='new_hist.png') -Save figure to file -------------------- + hist = plot_histogram(data) + hist.savefig('new_hist.png') .. autosummary:: From 34c832a636df1960a4f1e0153154d12981792db8 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 24 Aug 2022 18:39:02 +0200 Subject: [PATCH 05/22] add common keyword arguments section --- new_hist.png | Bin 0 -> 9830 bytes qiskit/visualization/__init__.py | 105 ++++++++++++++++--------------- 2 files changed, 56 insertions(+), 49 deletions(-) create mode 100644 new_hist.png diff --git a/new_hist.png b/new_hist.png new file mode 100644 index 0000000000000000000000000000000000000000..286c0bbc8fe69c03cfe646b520f2294c7556f03a GIT binary patch literal 9830 zcmdsdXIN8Pw{8j$k!EyDFYbV%fV4<&?rjhe0Tn5V6hVUY-lQamLKJ~5A`oc`0#byH z^d1#OArk4*BT}R$fIxsi?u_4e&pr2?^XHuN-23DFSWnio=329iImY{r@y^`8XlBH> zUvxhN0^u`0hq(-aKpEh=wT}xtX*8SD1wUGWhBko~KG?vJ8~!d3(;I=lo<4z|Zcayn zUHk*we7w<$YKp1~M{WfM`UYq#DS7?N3yMDeu1a$1Qih-tZr^iP10WE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VwJ$a zxVD3|H&w7D3J8grG$CJe+A*)2;{@=WPi%Z7)8_j&~*8s5sK3u`)Y%Cu+{%MtNX} zgx=-Rp0UF(g;sT{g`Vt~?Ox62nm6m`Wmw}SNOZxachPCXHnaKa+dfK3LJ|^abSomF ze9W@M0_9|nRR`Z+zQoA79B%0asOkU63FOTIvUeVXFsD9r#Sh4m2OE!&16NI@&A>w=ruyG=>q{A-J zts7^EX*$H<%I_Svhm>`Y5jx5R4QX*_UUaPL4WGER2mN-(eSX&KMP=F#Sxz_J7ZL$D9*GW0}2{;Ab3YF|2=Oepi z(ILUk#N@!!zCz7%xe-ctY@_2&j3rSO&L?e*L9g?UB9XE#GhGD2a>y$r=Ws!U#QU zS}mf;L(-F9{Bv0Rqc`hHj>7GqtR6Zq+ixdJ@z!q1#ox(v)6a{jqK zH-q2TA6vE~Uf1uauFZI#Fq^-Jays%CvA%liQ_N@dRCo^qs^_S|SdWH_l(7%<|groJ7|`au8gwO_-1o#ty@KXG|7q$|V@&@Z>TL ziBwD3c+mWm*oj_~QeC@A<)w0;zrm6Q{~n1Pvo5*~2ZpLz^?oZB&2wDuCRUxU>MKb{ z`MP2CMKh9JVg|MUXoNy(pBidX^qCJfs=CqR5(P^# zxvX>$=>rXBNZneB|0R%z34-kXpIZFClI8#Vw=9D%Pv*=bcU@J$f4(5bhGv+uKOOJ< EFCSZxm;e9( literal 0 HcmV?d00001 diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index cf08ef7dfd25..bfe24d371641 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -39,10 +39,28 @@ This section contains functions that visualize measurement outcome counts and quantum states. +APIs +---- + +.. autosummary:: + :toctree: ../stubs/ + + plot_histogram + plot_bloch_vector + plot_bloch_multivector + plot_state_city + plot_state_hinton + plot_state_paulivec + plot_state_qsphere + + Example Usage ------------- -Here is an example of using :func:`plot_histogram` to visualize measurement outcome counts +Counts Visualization +~~~~~~~~~~~~~~~~~~~~ + +Here is an example of using :func:`plot_histogram` to visualize measurement outcome counts: .. jupyter-execute:: @@ -54,7 +72,10 @@ The data can be a dictionary of bit string as key and counts as value or more commonly a :class:`~qiskit.result.Counts` object obtained from :meth:`~qiskit.result.Result.get_counts`. -Here is an example of using :func:`plot_state_city` to visualize a quantum state. +State Visualization +~~~~~~~~~~~~~~~~~~~ + +Here is an example of using :func:`plot_state_city` to visualize a quantum state: .. jupyter-execute:: @@ -64,9 +85,9 @@ [1-0.5j, 1+0.5j]] plot_state_city(state) -The state can be array-like list of list, numpy.array or more commonly -:class:`~qiskit.quantum_info.Statevector` or ~qiskit.quantum_info.DensityMatrix` objects obtained -from a circuit. +The state can be array-like list of lists, `numpy.array` or more commonly +:class:`~qiskit.quantum_info.Statevector` or :class:`~qiskit.quantum_info.DensityMatrix` objects +obtained from a :class:`~qiskit.QuantumCircuit`. .. jupyter-execute:: @@ -87,67 +108,53 @@ state = DensityMatrix(qc) plot_state_city(state) -.. - Common parameters - ----------------- - - The figures created by counts and state visulizations functions (listed in the table below) are - genereted by `Matplotlib`. Some of the common parameters are listed here: +Common Keyword Arguments +------------------------ - - title (str): a text string to use for the plot title - - legend (list): a list of strings to use for labels of the data. - - figsize (tuple): figure size in inches - - color (str or list): string or lists of strings for plotting - - ax (Matplotlib.axes.Axes): An optional Axes object to be used for the visualization output. If - none is specified a new matplotlib Figure will be created and used. Additionally, if specified - there will be no returned Figure since it is redundant. - - filename (str): file path to save image to. +The figures created by counts and state visualizations functions are mostly generated by +`Matplotlib `_. As a result there are keyargs inherited from +`Matplotlib` that are common to most functions, including: - Use title and legend - -------------------- +- `title` (`str`): a text string to use for the plot title +- `legend` (`list`): a list of strings to use for labels of the data. +- `figsize` (`tuple`): figure size in inches +- `color` (`str` or `list`): string or lists of strings for plotting +- `ax` (`Matplotlib.axes.Axes`): An optional Axes object to be used for the visualization output. If +none is specified a new `Matplotlib.Figure` will be created and used. Additionally, if specified +there will be no returned Figure since it is redundant. +- `filename` (`str`): file path to save image to. - .. jupyter-execute:: +.. jupyter-execute:: - from qiskit.tools.visualization import plot_histogram + from qiskit.tools.visualization import plot_histogram - counts1 = {'00': 525, '11': 499} - counts2 = {'00': 511, '11': 514} + counts1 = {'00': 525, '11': 499} + counts2 = {'00': 511, '11': 514} - data = [counts1, counts2] - plot_histogram(data) + data = [counts1, counts2] + plot_histogram(data) - You can specify `legend`, `title`, `figsize` and `color` by passing to the kwargs. +You can specify `legend`, `title`, `figsize` and `color` by passing to the kwargs. - .. jupyter-execute:: +.. jupyter-execute:: - legend = ['First execution', 'Second execution'] - title = 'New histogram' - figsize = (10,10) - color=['crimson','midnightblue'] - plot_histogram(data, legend=legend, title=title, figsize=figsize, color=color) + legend = ['First execution', 'Second execution'] + title = 'New histogram' + figsize = (10,10) + color=['crimson','midnightblue'] + plot_histogram(data, legend=legend, title=title, figsize=figsize, color=color) - You can save the figure to file either by passing the file name to `filename` kwarg or use - `Matplotlib.Figure.savefig()` method. +You can save the figure to file either by passing the file name to `filename` kwarg or use +`Matplotlib.Figure.savefig` method. - .. jupyter-execute:: +.. jupyter-execute:: - plot_histogram(data, filename='new_hist.png') + plot_histogram(data, filename='new_hist.png') hist = plot_histogram(data) hist.savefig('new_hist.png') -.. autosummary:: - :toctree: ../stubs/ - - plot_histogram - plot_bloch_vector - plot_bloch_multivector - plot_state_city - plot_state_hinton - plot_state_paulivec - plot_state_qsphere - Device Visualizations ===================== From a8202fd63d2efbcab22af46cb419f214c2fb2ad0 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 31 Aug 2022 11:13:33 +0200 Subject: [PATCH 06/22] add sections to apis --- qiskit/visualization/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index bfe24d371641..bc5ce255acdb 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -42,10 +42,20 @@ APIs ---- +Counts Visualization +~~~~~~~~~~~~~~~~~~~~ + .. autosummary:: :toctree: ../stubs/ plot_histogram + +State Visualization +~~~~~~~~~~~~~~~~~~~ + +.. autosummary:: + :toctree: ../stubs/ + plot_bloch_vector plot_bloch_multivector plot_state_city @@ -53,7 +63,6 @@ plot_state_paulivec plot_state_qsphere - Example Usage ------------- From b65d46a402bc90870804831e4923979d1698edbe Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 31 Aug 2022 12:34:35 +0200 Subject: [PATCH 07/22] fix internal links --- qiskit/visualization/__init__.py | 45 ++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index bc5ce255acdb..90403ebd4f4f 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -43,7 +43,7 @@ ---- Counts Visualization -~~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^^ .. autosummary:: :toctree: ../stubs/ @@ -51,7 +51,7 @@ plot_histogram State Visualization -~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^ .. autosummary:: :toctree: ../stubs/ @@ -67,7 +67,7 @@ ------------- Counts Visualization -~~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^^ Here is an example of using :func:`plot_histogram` to visualize measurement outcome counts: @@ -78,11 +78,11 @@ counts = {"00": 501, "11": 499} plot_histogram(counts) -The data can be a dictionary of bit string as key and counts as value or more commonly a +The data can be a dictionary with bit string as key and counts as value, or more commonly a :class:`~qiskit.result.Counts` object obtained from :meth:`~qiskit.result.Result.get_counts`. State Visualization -~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^ Here is an example of using :func:`plot_state_city` to visualize a quantum state: @@ -94,9 +94,9 @@ [1-0.5j, 1+0.5j]] plot_state_city(state) -The state can be array-like list of lists, `numpy.array` or more commonly +The state can be array-like list of lists, ``numpy.array``, or more commonly :class:`~qiskit.quantum_info.Statevector` or :class:`~qiskit.quantum_info.DensityMatrix` objects -obtained from a :class:`~qiskit.QuantumCircuit`. +obtained from a :class:`~qiskit.circuit.QuantumCircuit`: .. jupyter-execute:: @@ -117,21 +117,26 @@ state = DensityMatrix(qc) plot_state_city(state) +You can find code examples for each visualization functions on the individual function `API page +<#apis>`_. + Common Keyword Arguments ------------------------ The figures created by counts and state visualizations functions are mostly generated by `Matplotlib `_. As a result there are keyargs inherited from -`Matplotlib` that are common to most functions, including: +``Matplotlib`` that are common to most functions, including: + +* ``title`` (``str``): a text string to use for the plot title. +* ``legend`` (``list``): a list of strings to use for labels of the data. +* ``figsize`` (``tuple``): figure size in inches . +* ``color`` (``list``): a list of strings for plotting. +* ``ax`` (`Matplotlib.axes.Axes `_): An optional + ``Axes`` object to be used for the visualization output. If none is specified a new + `Matplotlib.figure.Figure `_ will be created + and used. Additionally, if specified there will be no returned ``Figure`` since it is redundant. +* ``filename`` (``str``): file path to save image to. -- `title` (`str`): a text string to use for the plot title -- `legend` (`list`): a list of strings to use for labels of the data. -- `figsize` (`tuple`): figure size in inches -- `color` (`str` or `list`): string or lists of strings for plotting -- `ax` (`Matplotlib.axes.Axes`): An optional Axes object to be used for the visualization output. If -none is specified a new `Matplotlib.Figure` will be created and used. Additionally, if specified -there will be no returned Figure since it is redundant. -- `filename` (`str`): file path to save image to. .. jupyter-execute:: @@ -143,7 +148,7 @@ data = [counts1, counts2] plot_histogram(data) -You can specify `legend`, `title`, `figsize` and `color` by passing to the kwargs. +You can specify ``legend``, ``title``, ``figsize`` and ``color`` by passing to the kwargs. .. jupyter-execute:: @@ -153,8 +158,10 @@ color=['crimson','midnightblue'] plot_histogram(data, legend=legend, title=title, figsize=figsize, color=color) -You can save the figure to file either by passing the file name to `filename` kwarg or use -`Matplotlib.Figure.savefig` method. +You can save the figure to file either by passing the file name to ``filename`` kwarg or use +`Matplotlib.figure.Figure.savefig +`_ method. + .. jupyter-execute:: From 479a5f2c29c97a3b87bdcbdbb1c5c15f68ffe4ba Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 31 Aug 2022 12:50:19 +0200 Subject: [PATCH 08/22] remove generated hist figure --- new_hist.png | Bin 9830 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 new_hist.png diff --git a/new_hist.png b/new_hist.png deleted file mode 100644 index 286c0bbc8fe69c03cfe646b520f2294c7556f03a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9830 zcmdsdXIN8Pw{8j$k!EyDFYbV%fV4<&?rjhe0Tn5V6hVUY-lQamLKJ~5A`oc`0#byH z^d1#OArk4*BT}R$fIxsi?u_4e&pr2?^XHuN-23DFSWnio=329iImY{r@y^`8XlBH> zUvxhN0^u`0hq(-aKpEh=wT}xtX*8SD1wUGWhBko~KG?vJ8~!d3(;I=lo<4z|Zcayn zUHk*we7w<$YKp1~M{WfM`UYq#DS7?N3yMDeu1a$1Qih-tZr^iP10WEdL+lF*d73E< zfgJ5M#{6+5G;?VTmpKrWMPs$|9E&=hi+}L;Vf^vX-vWPYS34Zt+cBKvQ)4B&P}N?V zXI1lb>vN!wn|tBt#)y@>i&u??;h2S0aG!-o&$W-a958wAs&gyS7?G@3%Oq?7XuH^UJC-#(E!_TWb!V$kGjsiCx;y;8A@qFOf4e${RcX zl3723tSD~uczL&&mYYP7M>!c{JQE08NWW$M?ag?CQtF`F1A@WXHp`RSO-iWLlr*LL z1fIrVc^TvRp<+=w(hupY<16ngO8K)WqFmw>M==#DAFA1r(k>m+_ko1*a2z|AH=k+ zAuAM6%LKw7pSLsnJJOSuTrLh83@QMJm3h;!6d*BK88az%sWj8xG@+j8yb8@5fSB+jCp+V)|| z=}^*-?mVrjzs}gy`Th=h7t7~7TIWa3)H;NJ`c(9oS?0$(oIGFa{G=g#e0-&Ljj8=5 z)^KGkS$KPsM#(jdhiI;TlortmR;a{&hCRcv_A-M8u7Z6@`kbKw_njfSt}@pspiLBF zrumIydt<3H`KSp*bN*$X=EhfNqF%T<1diaJBB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A<)w0;zrm6Q{~n1Pvo5*~2ZpLz^?oZB&2wDuCRUxU>MKb{ z`MP2CMKh9JVg|MUXoNy(pBidX^qCJfs=CqR5(P^# zxvX>$=>rXBNZneB|0R%z34-kXpIZFClI8#Vw=9D%Pv*=bcU@J$f4(5bhGv+uKOOJ< EFCSZxm;e9( From b17bfbfd7d428a88c86ae2ba056755487523ea4e Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 2 Sep 2022 13:32:32 +0200 Subject: [PATCH 09/22] lint --- qiskit/visualization/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 90403ebd4f4f..b0806bb0269d 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -22,7 +22,7 @@ ======== The visualization module contain functions that visualizes measurement outcome counts, quantum -states, circuits, pulses, devices and more. +states, circuits, pulses, devices and more. Prerequisites ============= From 46fa3e3ee9986133071f89a33074062509e34cfb Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Tue, 6 Sep 2022 12:15:37 +0200 Subject: [PATCH 10/22] use matplotlib instead of Matplotlib in class reference --- qiskit/visualization/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index b0806bb0269d..d715f8c8335f 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -131,9 +131,9 @@ * ``legend`` (``list``): a list of strings to use for labels of the data. * ``figsize`` (``tuple``): figure size in inches . * ``color`` (``list``): a list of strings for plotting. -* ``ax`` (`Matplotlib.axes.Axes `_): An optional +* ``ax`` (`matplotlib.axes.Axes `_): An optional ``Axes`` object to be used for the visualization output. If none is specified a new - `Matplotlib.figure.Figure `_ will be created + `matplotlib.figure.Figure `_ will be created and used. Additionally, if specified there will be no returned ``Figure`` since it is redundant. * ``filename`` (``str``): file path to save image to. @@ -159,7 +159,7 @@ plot_histogram(data, legend=legend, title=title, figsize=figsize, color=color) You can save the figure to file either by passing the file name to ``filename`` kwarg or use -`Matplotlib.figure.Figure.savefig +`matplotlib.figure.Figure.savefig `_ method. From 11e09e0b1a919df48a983ce9b5851cdddc39118c Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Tue, 6 Sep 2022 12:50:03 +0200 Subject: [PATCH 11/22] change to a valid denisty matrix in examples --- qiskit/visualization/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index d715f8c8335f..22902cb95dd7 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -90,8 +90,8 @@ from qiskit.tools.visualization import plot_state_city - state = [[0+1.0j, 0-1.0j], - [1-0.5j, 1+0.5j]] + state = [[ 0.75 , 0.433j], + [-0.433j, 0.25 ]] plot_state_city(state) The state can be array-like list of lists, ``numpy.array``, or more commonly From e9b96d98d473f2a24b47d200b13a02fc8b05a9b7 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 17:24:41 +0200 Subject: [PATCH 12/22] import from qiskit.visualization instead of qiskit.tools.visualization --- qiskit/visualization/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 22902cb95dd7..7dd479307568 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -73,7 +73,7 @@ .. jupyter-execute:: - from qiskit.tools.visualization import plot_histogram + from qiskit.visualization import plot_histogram counts = {"00": 501, "11": 499} plot_histogram(counts) @@ -88,7 +88,7 @@ .. jupyter-execute:: - from qiskit.tools.visualization import plot_state_city + from qiskit.visualization import plot_state_city state = [[ 0.75 , 0.433j], [-0.433j, 0.25 ]] @@ -140,7 +140,7 @@ .. jupyter-execute:: - from qiskit.tools.visualization import plot_histogram + from qiskit.visualization import plot_histogram counts1 = {'00': 525, '11': 499} counts2 = {'00': 511, '11': 514} @@ -235,7 +235,7 @@ visualize_transition -Array/Matrix Visualizations +Array/Matrix Visualizations21 =========================== .. autosummary:: From 7b1e00ea61fe1638e17c7561156ba743b7f438ff Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:06:45 +0200 Subject: [PATCH 13/22] remove unintended changes --- qiskit/visualization/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 7dd479307568..4aff4f2c3fb1 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -235,7 +235,7 @@ visualize_transition -Array/Matrix Visualizations21 +Array/Matrix Visualizations =========================== .. autosummary:: From 257d9a4461d14e39652336a53d0616546896ec0d Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:13:08 +0200 Subject: [PATCH 14/22] split counts and state visualizations --- qiskit/visualization/__init__.py | 46 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 4aff4f2c3fb1..e5b5fa0bffa0 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -34,41 +34,23 @@ pip install 'qiskit[visualization]' -Counts and State Visualizations -=============================== +Counts Visualizations +===================== -This section contains functions that visualize measurement outcome counts and quantum states. +This section contains functions that visualize measurement outcome counts. APIs ---- -Counts Visualization -^^^^^^^^^^^^^^^^^^^^ - .. autosummary:: :toctree: ../stubs/ plot_histogram -State Visualization -^^^^^^^^^^^^^^^^^^^ - -.. autosummary:: - :toctree: ../stubs/ - - plot_bloch_vector - plot_bloch_multivector - plot_state_city - plot_state_hinton - plot_state_paulivec - plot_state_qsphere Example Usage ------------- -Counts Visualization -^^^^^^^^^^^^^^^^^^^^ - Here is an example of using :func:`plot_histogram` to visualize measurement outcome counts: .. jupyter-execute:: @@ -81,8 +63,26 @@ The data can be a dictionary with bit string as key and counts as value, or more commonly a :class:`~qiskit.result.Counts` object obtained from :meth:`~qiskit.result.Result.get_counts`. -State Visualization -^^^^^^^^^^^^^^^^^^^ +State Visualizations +==================== + +This section contains functions that visualize quantum states. + +APIs +---- +.. autosummary:: + :toctree: ../stubs/ + + plot_bloch_vector + plot_bloch_multivector + plot_state_city + plot_state_hinton + plot_state_paulivec + plot_state_qsphere + + +Example Usage +------------- Here is an example of using :func:`plot_state_city` to visualize a quantum state: From 1c1c14a7d7909e8b7720d220be7b05c54e557446 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:14:28 +0200 Subject: [PATCH 15/22] remove overview and prerequisite headings --- qiskit/visualization/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index e5b5fa0bffa0..48752d57af8c 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -18,15 +18,9 @@ .. currentmodule:: qiskit.visualization -Overview -======== - The visualization module contain functions that visualizes measurement outcome counts, quantum states, circuits, pulses, devices and more. -Prerequisites -============= - To use visualization functions, you are required to install visualization optionals to your development environment: From 2df1bca572742b23dd8b667fcdc39774c1363709 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:23:38 +0200 Subject: [PATCH 16/22] move common kwargs sections to the top level --- qiskit/visualization/__init__.py | 99 ++++++++++++++++---------------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 48752d57af8c..92c1c870c6b3 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -28,6 +28,57 @@ pip install 'qiskit[visualization]' + +Common Keyword Arguments +======================== + +Many of the figures created by visualization functions in this module are created by `Matplotlib +`_ and accept a subset of the following common arguments. Consult the +individual documentation for exact details. + +* ``title`` (``str``): a text string to use for the plot title. +* ``legend`` (``list``): a list of strings to use for labels of the data. +* ``figsize`` (``tuple``): figure size in inches . +* ``color`` (``list``): a list of strings for plotting. +* ``ax`` (`matplotlib.axes.Axes `_): An optional + ``Axes`` object to be used for the visualization output. If none is specified a new + `matplotlib.figure.Figure `_ will be created + and used. Additionally, if specified there will be no returned ``Figure`` since it is redundant. +* ``filename`` (``str``): file path to save image to. + + +.. jupyter-execute:: + + from qiskit.visualization import plot_histogram + + counts1 = {'00': 525, '11': 499} + counts2 = {'00': 511, '11': 514} + + data = [counts1, counts2] + plot_histogram(data) + +You can specify ``legend``, ``title``, ``figsize`` and ``color`` by passing to the kwargs. + +.. jupyter-execute:: + + legend = ['First execution', 'Second execution'] + title = 'New histogram' + figsize = (10,10) + color=['crimson','midnightblue'] + plot_histogram(data, legend=legend, title=title, figsize=figsize, color=color) + +You can save the figure to file either by passing the file name to ``filename`` kwarg or use +`matplotlib.figure.Figure.savefig +`_ method. + + +.. jupyter-execute:: + + plot_histogram(data, filename='new_hist.png') + + hist = plot_histogram(data) + hist.savefig('new_hist.png') + Counts Visualizations ===================== @@ -114,55 +165,7 @@ You can find code examples for each visualization functions on the individual function `API page <#apis>`_. -Common Keyword Arguments ------------------------- - -The figures created by counts and state visualizations functions are mostly generated by -`Matplotlib `_. As a result there are keyargs inherited from -``Matplotlib`` that are common to most functions, including: -* ``title`` (``str``): a text string to use for the plot title. -* ``legend`` (``list``): a list of strings to use for labels of the data. -* ``figsize`` (``tuple``): figure size in inches . -* ``color`` (``list``): a list of strings for plotting. -* ``ax`` (`matplotlib.axes.Axes `_): An optional - ``Axes`` object to be used for the visualization output. If none is specified a new - `matplotlib.figure.Figure `_ will be created - and used. Additionally, if specified there will be no returned ``Figure`` since it is redundant. -* ``filename`` (``str``): file path to save image to. - - -.. jupyter-execute:: - - from qiskit.visualization import plot_histogram - - counts1 = {'00': 525, '11': 499} - counts2 = {'00': 511, '11': 514} - - data = [counts1, counts2] - plot_histogram(data) - -You can specify ``legend``, ``title``, ``figsize`` and ``color`` by passing to the kwargs. - -.. jupyter-execute:: - - legend = ['First execution', 'Second execution'] - title = 'New histogram' - figsize = (10,10) - color=['crimson','midnightblue'] - plot_histogram(data, legend=legend, title=title, figsize=figsize, color=color) - -You can save the figure to file either by passing the file name to ``filename`` kwarg or use -`matplotlib.figure.Figure.savefig -`_ method. - - -.. jupyter-execute:: - - plot_histogram(data, filename='new_hist.png') - - hist = plot_histogram(data) - hist.savefig('new_hist.png') Device Visualizations From 23957d78409c157a14139fe36cda2b61d320dba7 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:25:07 +0200 Subject: [PATCH 17/22] remove link to api table --- qiskit/visualization/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 92c1c870c6b3..91966603d66b 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -162,10 +162,7 @@ state = DensityMatrix(qc) plot_state_city(state) -You can find code examples for each visualization functions on the individual function `API page -<#apis>`_. - - +You can find code examples for each visualization functions on the individual function API page. Device Visualizations From d98e867a28ca368438d22a1e63ab53ca64f1dcca Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:44:53 +0200 Subject: [PATCH 18/22] remove apis headings --- qiskit/visualization/__init__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 91966603d66b..00e613eaaa79 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -84,9 +84,6 @@ This section contains functions that visualize measurement outcome counts. -APIs ----- - .. autosummary:: :toctree: ../stubs/ @@ -113,8 +110,6 @@ This section contains functions that visualize quantum states. -APIs ----- .. autosummary:: :toctree: ../stubs/ From 9d6f500af4ab40423fc51b42769d9fd2f0ac1ea2 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:48:52 +0200 Subject: [PATCH 19/22] remove extra blank lines --- qiskit/visualization/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 00e613eaaa79..646d9df040d6 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -17,7 +17,6 @@ .. currentmodule:: qiskit.visualization - The visualization module contain functions that visualizes measurement outcome counts, quantum states, circuits, pulses, devices and more. @@ -28,7 +27,6 @@ pip install 'qiskit[visualization]' - Common Keyword Arguments ======================== @@ -46,7 +44,6 @@ and used. Additionally, if specified there will be no returned ``Figure`` since it is redundant. * ``filename`` (``str``): file path to save image to. - .. jupyter-execute:: from qiskit.visualization import plot_histogram @@ -89,7 +86,6 @@ plot_histogram - Example Usage ------------- @@ -120,7 +116,6 @@ plot_state_paulivec plot_state_qsphere - Example Usage ------------- @@ -159,7 +154,6 @@ You can find code examples for each visualization functions on the individual function API page. - Device Visualizations ===================== From 2987132abb1e5e318f9ff770d22fc812c7bdca7d Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Wed, 7 Sep 2022 19:49:37 +0200 Subject: [PATCH 20/22] remove extra blank lines --- qiskit/visualization/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 646d9df040d6..c6baf84b8633 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -68,7 +68,6 @@ `matplotlib.figure.Figure.savefig `_ method. - .. jupyter-execute:: plot_histogram(data, filename='new_hist.png') From b96d97bffe24a105e0423f9d54cdcdd322fe45d8 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Thu, 8 Sep 2022 11:27:23 +0200 Subject: [PATCH 21/22] minor twig on the counts to make them 1000 shots in total --- qiskit/visualization/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 701328dc0322..6a2d64a922b9 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -48,8 +48,8 @@ from qiskit.visualization import plot_histogram - counts1 = {'00': 525, '11': 499} - counts2 = {'00': 511, '11': 514} + counts1 = {'00': 499, '11': 501} + counts2 = {'00': 511, '11': 489} data = [counts1, counts2] plot_histogram(data) From 8778f4b0529b051e88fbd4e7d65228a2cd717389 Mon Sep 17 00:00:00 2001 From: Junye Huang Date: Thu, 8 Sep 2022 11:30:56 +0200 Subject: [PATCH 22/22] add an intro sentence before the example for common kwargs --- qiskit/visualization/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qiskit/visualization/__init__.py b/qiskit/visualization/__init__.py index 6a2d64a922b9..1440dad9d6c5 100644 --- a/qiskit/visualization/__init__.py +++ b/qiskit/visualization/__init__.py @@ -44,6 +44,8 @@ and used. Additionally, if specified there will be no returned ``Figure`` since it is redundant. * ``filename`` (``str``): file path to save image to. +The following example demonstrates the common usage of these arguments: + .. jupyter-execute:: from qiskit.visualization import plot_histogram