-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing the tools for plotting Pauli vec (#10619)
* fixing the plot for pauli_vec to scaled to pm 1 * testing * linting * ref figure * Update docstring to define Paulivector * add reno --------- Co-authored-by: Julien Gacon <gaconju@gmail.com>
- Loading branch information
1 parent
61a3a43
commit 213580d
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
releasenotes/notes/paulivecplot-normalization-5dd3cf3393c75afb.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed :func:`plot_state_paulivec`, which previously damped the state coefficients by a factor of | ||
:math:`2^n`, where :math:`n` is the number of qubits. Now the bar graph correctly displays | ||
the coefficients as :math:`\mathrm{Tr}(\sigma\rho)`, where :math:`\rho` is the state to | ||
be plotted and :math:`\sigma` iterates over all possible tensor products of single-qubit Paulis. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 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 | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Tests for functions used in state visualization""" | ||
|
||
import unittest | ||
import numpy as np | ||
|
||
from qiskit.quantum_info import Statevector | ||
from qiskit.visualization.state_visualization import _paulivec_data | ||
from qiskit.test import QiskitTestCase | ||
|
||
|
||
class TestStatePlotTools(QiskitTestCase): | ||
"""State Plotting Tools""" | ||
|
||
def test_state_paulivec(self): | ||
"""Test paulivec.""" | ||
|
||
sv = Statevector.from_label("+-rl") | ||
output = _paulivec_data(sv) | ||
labels = [ | ||
"IIII", | ||
"IIIY", | ||
"IIYI", | ||
"IIYY", | ||
"IXII", | ||
"IXIY", | ||
"IXYI", | ||
"IXYY", | ||
"XIII", | ||
"XIIY", | ||
"XIYI", | ||
"XIYY", | ||
"XXII", | ||
"XXIY", | ||
"XXYI", | ||
"XXYY", | ||
] | ||
values = [1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1] | ||
self.assertEqual(output[0], labels) | ||
self.assertTrue(np.allclose(output[1], values)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.