Repository: Qiskit/qiskit-terra (python)

Issue:
Calling `synth(registerless=False)` on a classical function synth labels the qubits wrongly
### Environment

- **Qiskit Terra version**:  0.23.0.dev0+dcd7bea
- **Python version**:  3.9

### What is happening?

In https://github.com/Qiskit/qiskit-terra/pull/9337#discussion_r1067055542 @Cryoris noticed that `classical_function` synthesis labels the qubits in the reversed order.

### How can we reproduce the issue?

:

```python
from qiskit.circuit.classicalfunction import classical_function
from qiskit.circuit.classicalfunction.types import Int1

@classical_function
def grover_oracle(a: Int1, b: Int1, c: Int1) -> Int1:
    return (a and b and not c)

quantum_circuit = grover_oracle.synth(registerless=False)
print(quantum_circuit.draw())
```
```
     c: ──■──
          │  
     b: ──■──
          │  
     a: ──o──
        ┌─┴─┐
return: ┤ X ├
        └───┘
```

### What should happen?

in that example, the open control is on `c`, not on `a`.

### Any suggestions?

_No response_

Pull request description:
Fix classical-synthesis label ordering with `registerless=False`
Fixes #9363

```python
from qiskit.circuit.classicalfunction import classical_function
from qiskit.circuit.classicalfunction.types import Int1

@classical_function
def grover_oracle(a: Int1, b: Int1, c: Int1) -> Int1:
    return (a and b and not c)

quantum_circuit = grover_oracle.synth(registerless=False)
print(quantum_circuit.draw())
```
```
     a: ──■──
          │  
     b: ──■──
          │  
     c: ──o──
        ┌─┴─┐
return: ┤ X ├
        └───┘
```

Patch:
diff --git a/.github/workflows/docs_deploy.yml b/.github/workflows/docs_deploy.yml
index d437dfe2f..835ddf93d 100644
--- a/.github/workflows/docs_deploy.yml
+++ b/.github/workflows/docs_deploy.yml
@@ -23,7 +23,7 @@ on:
 
 jobs:
   build:
-    if: github.repository_owner == "Qiskit"
+    if: github.repository_owner == 'Qiskit'
     name: Build
     runs-on: ubuntu-latest
 
diff --git a/Cargo.lock b/Cargo.lock
index bf69635ab..e6cd8796c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,17 +2,6 @@
 # It is not intended for manual editing.
 version = 3
 
-[[package]]
-name = "ahash"
-version = "0.7.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
-dependencies = [
- "getrandom",
- "once_cell",
- "version_check",
-]
-
 [[package]]
 name = "ahash"
 version = "0.8.3"
@@ -25,6 +14,12 @@ dependencies = [
  "version_check",
 ]
 
+[[package]]
+name = "allocator-api2"
+version = "0.2.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
+
 [[package]]
 name = "autocfg"
 version = "1.1.0"
@@ -92,6 +87,12 @@ version = "1.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
 
+[[package]]
+name = "equivalent"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
+
 [[package]]
 name = "fixedbitset"
 version = "0.4.2"
@@ -114,8 +115,15 @@ name = "hashbrown"
 version = "0.12.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+
+[[package]]
+name = "hashbrown"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
 dependencies = [
- "ahash 0.7.6",
+ "ahash",
+ "allocator-api2",
  "rayon",
 ]
 
@@ -132,7 +140,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
 dependencies = [
  "autocfg",
- "hashbrown",
+ "hashbrown 0.12.3",
+]
+
+[[package]]
+name = "indexmap"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
+dependencies = [
+ "equivalent",
+ "hashbrown 0.14.0",
  "rayon",
 ]
 
@@ -307,7 +325,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4"
 dependencies = [
  "fixedbitset",
- "indexmap",
+ "indexmap 1.9.3",
 ]
 
 [[package]]
@@ -323,7 +341,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fff39edfcaec0d64e8d0da38564fad195d2d51b680940295fcc307366e101e61"
 dependencies = [
  "autocfg",
- "indexmap",
+ "indexmap 1.9.3",
 ]
 
 [[package]]
@@ -342,8 +360,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e681a6cfdc4adcc93b4d3cf993749a4552018ee0a9b65fc0ccfad74352c72a38"
 dependencies = [
  "cfg-if",
- "hashbrown",
- "indexmap",
+ "hashbrown 0.14.0",
+ "indexmap 2.0.0",
  "indoc",
  "libc",
  "memoffset",
@@ -403,7 +421,7 @@ dependencies = [
 name = "qiskit-qasm2"
 version = "0.45.0"
 dependencies = [
- "hashbrown",
+ "hashbrown 0.14.0",
  "pyo3",
 ]
 
@@ -411,9 +429,9 @@ dependencies = [
 name = "qiskit_accelerate"
 version = "0.45.0"
 dependencies = [
- "ahash 0.8.3",
- "hashbrown",
- "indexmap",
+ "ahash",
+ "hashbrown 0.14.0",
+ "indexmap 2.0.0",
  "ndarray",
  "num-bigint",
  "num-complex",
@@ -544,10 +562,10 @@ version = "0.13.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "34932d9b2a5d67da9f166a70009fc742075a5844671c5f000b89dec578e0f024"
 dependencies = [
- "ahash 0.8.3",
+ "ahash",
  "fixedbitset",
- "hashbrown",
- "indexmap",
+ "hashbrown 0.14.0",
+ "indexmap 2.0.0",
  "num-traits",
  "petgraph",
  "priority-queue",
@@ -612,9 +630,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
 
 [[package]]
 name = "windows-targets"
-version = "0.48.1"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
+checksum = "d1eeca1c172a285ee6c2c84c341ccea837e7c01b12fbb2d0fe3c9e550ce49ec8"
 dependencies = [
  "windows_aarch64_gnullvm",
  "windows_aarch64_msvc",
@@ -627,42 +645,42 @@ dependencies = [
 
 [[package]]
 name = "windows_aarch64_gnullvm"
-version = "0.48.0"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
+checksum = "b10d0c968ba7f6166195e13d593af609ec2e3d24f916f081690695cf5eaffb2f"
 
 [[package]]
 name = "windows_aarch64_msvc"
-version = "0.48.0"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
+checksum = "571d8d4e62f26d4932099a9efe89660e8bd5087775a2ab5cdd8b747b811f1058"
 
 [[package]]
 name = "windows_i686_gnu"
-version = "0.48.0"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
+checksum = "2229ad223e178db5fbbc8bd8d3835e51e566b8474bfca58d2e6150c48bb723cd"
 
 [[package]]
 name = "windows_i686_msvc"
-version = "0.48.0"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
+checksum = "600956e2d840c194eedfc5d18f8242bc2e17c7775b6684488af3a9fff6fe3287"
 
 [[package]]
 name = "windows_x86_64_gnu"
-version = "0.48.0"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
+checksum = "ea99ff3f8b49fb7a8e0d305e5aec485bd068c2ba691b6e277d29eaeac945868a"
 
 [[package]]
 name = "windows_x86_64_gnullvm"
-version = "0.48.0"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
+checksum = "8f1a05a1ece9a7a0d5a7ccf30ba2c33e3a61a30e042ffd247567d1de1d94120d"
 
 [[package]]
 name = "windows_x86_64_msvc"
-version = "0.48.0"
+version = "0.48.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
+checksum = "d419259aba16b663966e29e6d7c6ecfa0bb8425818bb96f6f1f3c3eb71a6e7b9"
diff --git a/crates/accelerate/Cargo.toml b/crates/accelerate/Cargo.toml
index 784b5d555..f2e57cf89 100644
--- a/crates/accelerate/Cargo.toml
+++ b/crates/accelerate/Cargo.toml
@@ -29,9 +29,9 @@ version = "^0.15.6"
 features = ["rayon"]
 
 [dependencies.hashbrown]
-version = "0.12.3"
+version = "0.14.0"
 features = ["rayon"]
 
 [dependencies.indexmap]
-version = "1.9"
+version = "2.0.0"
 features = ["rayon"]
diff --git a/crates/qasm2/Cargo.toml b/crates/qasm2/Cargo.toml
index 21614a546..3d89bb1b1 100644
--- a/crates/qasm2/Cargo.toml
+++ b/crates/qasm2/Cargo.toml
@@ -10,5 +10,5 @@ name = "qiskit_qasm2"
 crate-type = ["cdylib"]
 
 [dependencies]
-hashbrown = "0.12.3"
+hashbrown = "0.14.0"
 pyo3.workspace = true
diff --git a/qiskit/circuit/classicalfunction/classicalfunction.py b/qiskit/circuit/classicalfunction/classicalfunction.py
index eaa37e4c4..8ce9fc041 100644
--- a/qiskit/circuit/classicalfunction/classicalfunction.py
+++ b/qiskit/circuit/classicalfunction/classicalfunction.py
@@ -168,7 +168,6 @@ class ClassicalFunction(ClassicalElement):
     def qregs(self):
         """The list of qregs used by the classicalfunction"""
         qregs = [QuantumRegister(1, name=arg) for arg in self.args if self.types[0][arg] == "Int1"]
-        qregs.reverse()
         if self.types[0]["return"] == "Int1":
             qregs.append(QuantumRegister(1, name="return"))
         return qregs
diff --git a/qiskit/circuit/classicalfunction/utils.py b/qiskit/circuit/classicalfunction/utils.py
index 1ef523cae..237a8b838 100644
--- a/qiskit/circuit/classicalfunction/utils.py
+++ b/qiskit/circuit/classicalfunction/utils.py
@@ -75,8 +75,7 @@ def tweedledum2qiskit(tweedledum_circuit, name=None, qregs=None):
         QuantumCircuit: The Tweedledum circuit converted to a Qiskit circuit.
 
     Raises:
-        ClassicalFunctionCompilerError: If there a gate in the Tweedledum circuit has no Qiskit
-        equivalent.
+        ClassicalFunctionCompilerError: If a gate in the Tweedledum circuit has no Qiskit equivalent.
     """
     if qregs:
         qiskit_qc = QuantumCircuit(*qregs, name=name)
diff --git a/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py b/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py
index 95162ebe2..cee530004 100644
--- a/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py
+++ b/qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py
@@ -235,6 +235,14 @@ class SparsePauliOp(LinearOp):
     def paulis(self, value):
         if not isinstance(value, PauliList):
             value = PauliList(value)
+        if value.num_qubits != self.num_qubits:
+            raise ValueError(
+                f"incorrect number of qubits: expected {self.num_qubits}, got {value.num_qubits}"
+            )
+        if len(value) != len(self.paulis):
+            raise ValueError(
+                f"incorrect number of operators: expected {len(self.paulis)}, got {len(value)}"
+            )
         self._pauli_list = value
 
     @property
diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py
index 3f9d85131..25c6b8f3d 100644
--- a/qiskit/visualization/state_visualization.py
+++ b/qiskit/visualization/state_visualization.py
@@ -627,14 +627,17 @@ def plot_state_city(
 def plot_state_paulivec(
     state, title="", figsize=None, color=None, ax=None, *, rho=None, filename=None
 ):
-    r"""Plot the paulivec representation of a quantum state.
+    r"""Plot the Pauli-vector representation of a quantum state as bar graph.
 
-    Plot a bargraph of the density matrix of a quantum state using as a basis all
-    possible tensor products of Pauli operators and identities, that is,
-    :math:`\{\bigotimes_{i=0}^{N-1}P_i\}_{P_i\in \{I,X,Y,Z\}}`, where
-    :math:`N` is the number of qubits.
+    The Pauli-vector of a density matrix :math:`\rho` is defined by the expectation of each
+    possible tensor product of single-qubit Pauli operators (including the identity), that is
 
+    .. math ::
 
+        \rho = \frac{1}{2^n} \sum_{\sigma \in \{I, X, Y, Z\}^{\otimes n}}
+               \mathrm{Tr}(\sigma \rho) \sigma.
+
+    This function plots the coefficients :math:`\mathrm{Tr}(\sigma\rho)` as bar graph.
 
     Args:
         state (Statevector or DensityMatrix or ndarray): an N-qubit quantum state.
@@ -1574,4 +1577,4 @@ def _paulivec_data(state):
     rho = SparsePauliOp.from_operator(DensityMatrix(state))
     if rho.num_qubits is None:
         raise VisualizationError("Input is not a multi-qubit quantum state.")
-    return rho.paulis.to_labels(), np.real(rho.coeffs)
+    return rho.paulis.to_labels(), np.real(rho.coeffs * 2**rho.num_qubits)
diff --git a/releasenotes/notes/fix_9363-445db8fde1244e57.yaml b/releasenotes/notes/fix_9363-445db8fde1244e57.yaml
new file mode 100644
index 000000000..ef0e6f01f
--- /dev/null
+++ b/releasenotes/notes/fix_9363-445db8fde1244e57.yaml
@@ -0,0 +1,40 @@
+---
+fixes:
+  - |
+    Fixed `#9363 <https://github.com/Qiskit/qiskit-terra/issues/9363>`__.
+    by labeling the non-registerless synthesis in the order that Tweedledum
+    returns. For example, compare this example before and after the fix::
+
+      from qiskit.circuit import QuantumCircuit
+      from qiskit.circuit.classicalfunction import BooleanExpression
+
+      boolean_exp = BooleanExpression.from_dimacs_file("simple_v3_c2.cnf")
+      circuit = QuantumCircuit(boolean_exp.num_qubits)
+      circuit.append(boolean_exp, range(boolean_exp.num_qubits))
+      circuit.draw("text")
+
+      from qiskit.circuit.classicalfunction import classical_function
+      from qiskit.circuit.classicalfunction.types import Int1
+
+      @classical_function
+      def grover_oracle(a: Int1, b: Int1, c: Int1) -> Int1:
+          return (a and b and not c)
+
+      quantum_circuit = grover_oracle.synth(registerless=False)
+      print(quantum_circuit.draw())
+
+    Which would print
+
+    .. parsed-literal::
+
+           Before             After
+
+           c: ──■──           a: ──■──
+                │                  │
+           b: ──■──           b: ──■──
+                │                  │
+           a: ──o──           c: ──o──
+              ┌─┴─┐              ┌─┴─┐
+      return: ┤ X ├      return: ┤ X ├
+              └───┘              └───┘
+
diff --git a/releasenotes/notes/paulivecplot-normalization-5dd3cf3393c75afb.yaml b/releasenotes/notes/paulivecplot-normalization-5dd3cf3393c75afb.yaml
new file mode 100644
index 000000000..a22e2a3ab
--- /dev/null
+++ b/releasenotes/notes/paulivecplot-normalization-5dd3cf3393c75afb.yaml
@@ -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.
diff --git a/releasenotes/notes/sparse-pauli-op-constraint-pauli-setter-52f6f89627d1937c.yaml b/releasenotes/notes/sparse-pauli-op-constraint-pauli-setter-52f6f89627d1937c.yaml
new file mode 100644
index 000000000..86d4b552f
--- /dev/null
+++ b/releasenotes/notes/sparse-pauli-op-constraint-pauli-setter-52f6f89627d1937c.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+  - |
+    The setter for :attr:`.SparsePauliOp.paulis` will now correctly reject attempts to set the
+    attribute with incorrectly shaped data, rather than silently allowing an invalid object to be
+    created.  See `#10384 <https://github.com/Qiskit/qiskit-terra/issues/10384>`__.


Test patch:
diff --git a/test/python/classical_function_compiler/test_synthesis.py b/test/python/classical_function_compiler/test_synthesis.py
index 33a5da6c9..76daba7d9 100644
--- a/test/python/classical_function_compiler/test_synthesis.py
+++ b/test/python/classical_function_compiler/test_synthesis.py
@@ -49,10 +49,10 @@ class TestSynthesis(QiskitTestCase):
         qr_c = QuantumRegister(1, "c")
         qr_d = QuantumRegister(1, "d")
         qr_return = QuantumRegister(1, "return")
-        expected = QuantumCircuit(qr_d, qr_c, qr_b, qr_a, qr_return)
+        expected = QuantumCircuit(qr_a, qr_b, qr_c, qr_d, qr_return)
         expected.append(
             XGate().control(4, ctrl_state="1010"),
-            [qr_d[0], qr_c[0], qr_b[0], qr_a[0], qr_return[0]],
+            [qr_a[0], qr_b[0], qr_c[0], qr_d[0], qr_return[0]],
         )
 
         self.assertEqual(quantum_circuit.name, "grover_oracle")
diff --git a/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py b/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py
index be066453a..767153e23 100644
--- a/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py
+++ b/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py
@@ -1015,6 +1015,14 @@ class TestSparsePauliOpMethods(QiskitTestCase):
         with self.subTest(msg="fully bound"):
             self.assertTrue(np.allclose(bound.coeffs.astype(complex), [1, 3, 6]))
 
+    def test_paulis_setter_rejects_bad_inputs(self):
+        """Test that the setter for `paulis` rejects different-sized inputs."""
+        op = SparsePauliOp(["XY", "ZX"], coeffs=[1, 1j])
+        with self.assertRaisesRegex(ValueError, "incorrect number of qubits"):
+            op.paulis = PauliList([Pauli("X"), Pauli("Y")])
+        with self.assertRaisesRegex(ValueError, "incorrect number of operators"):
+            op.paulis = PauliList([Pauli("XY"), Pauli("ZX"), Pauli("YZ")])
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/test/python/visualization/test_circuit_text_drawer.py b/test/python/visualization/test_circuit_text_drawer.py
index e5d4f5437..1f880b4de 100644
--- a/test/python/visualization/test_circuit_text_drawer.py
+++ b/test/python/visualization/test_circuit_text_drawer.py
@@ -48,8 +48,13 @@ from qiskit.circuit.library import (
     CPhaseGate,
 )
 from qiskit.transpiler.passes import ApplyLayout
+from qiskit.utils.optionals import HAS_TWEEDLEDUM
 from .visualization import path_to_diagram_reference, QiskitVisualizationTestCase
 
+if HAS_TWEEDLEDUM:
+    from qiskit.circuit.classicalfunction import classical_function
+    from qiskit.circuit.classicalfunction.types import Int1
+
 
 class TestTextDrawerElement(QiskitTestCase):
     """Draw each element"""
@@ -1216,6 +1221,31 @@ class TestTextDrawerGatesInCircuit(QiskitTestCase):
         circuit.rz(11111, qr[2])
         self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
 
+    @unittest.skipUnless(HAS_TWEEDLEDUM, "Tweedledum is required for these tests.")
+    def test_text_synth_no_registerless(self):
+        """Test synthesis's label when registerless=False.
+        See https://github.com/Qiskit/qiskit-terra/issues/9363"""
+        expected = "\n".join(
+            [
+                "                ",
+                "     a: |0>──■──",
+                "             │  ",
+                "     b: |0>──■──",
+                "             │  ",
+                "     c: |0>──o──",
+                "           ┌─┴─┐",
+                "return: |0>┤ X ├",
+                "           └───┘",
+            ]
+        )
+
+        @classical_function
+        def grover_oracle(a: Int1, b: Int1, c: Int1) -> Int1:
+            return a and b and not c
+
+        circuit = grover_oracle.synth(registerless=False)
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
 
 class TestTextDrawerLabels(QiskitTestCase):
     """Gates with labels."""
diff --git a/test/python/visualization/test_state_plot_tools.py b/test/python/visualization/test_state_plot_tools.py
new file mode 100644
index 000000000..028835980
--- /dev/null
+++ b/test/python/visualization/test_state_plot_tools.py
@@ -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)