Skip to content

Commit

Permalink
fixed issue 11143 by removing deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
border-b committed Oct 31, 2023
1 parent 7c89b68 commit cff661f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 67 deletions.
45 changes: 1 addition & 44 deletions qiskit/visualization/state_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Visualization functions for quantum states.
"""

from typing import Optional, List, Union
from typing import List, Union
from functools import reduce
import colorsys

Expand All @@ -27,7 +27,6 @@
from qiskit.quantum_info.operators.operator import Operator
from qiskit.quantum_info.operators.symplectic import PauliList, SparsePauliOp
from qiskit.quantum_info.states.densitymatrix import DensityMatrix
from qiskit.utils.deprecation import deprecate_func
from qiskit.utils import optionals as _optionals
from qiskit.circuit.tools.pi_check import pi_check

Expand Down Expand Up @@ -1280,48 +1279,6 @@ def state_to_latex(
return prefix + latex_str + suffix


@deprecate_func(
additional_msg="For similar functionality, see sympy's ``nsimplify`` and ``latex`` functions.",
since="0.23.0",
)
def num_to_latex_ket(raw_value: complex, first_term: bool, decimals: int = 10) -> Optional[str]:
"""Convert a complex number to latex code suitable for a ket expression
Args:
raw_value: Value to convert
first_term: If True then generate latex code for the first term in an expression
decimals: Number of decimal places to round to (default: 10).
Returns:
String with latex code or None if no term is required
"""
if np.around(np.abs(raw_value), decimals=decimals) == 0:
return None
return _num_to_latex(raw_value, first_term=first_term, decimals=decimals, coefficient=True)


@deprecate_func(
additional_msg="For similar functionality, see sympy's ``nsimplify`` and ``latex`` functions.",
since="0.23.0",
)
def numbers_to_latex_terms(numbers: List[complex], decimals: int = 10) -> List[str]:
"""Convert a list of numbers to latex formatted terms
The first non-zero term is treated differently. For this term a leading + is suppressed.
Args:
numbers: List of numbers to format
decimals: Number of decimal places to round to (default: 10).
Returns:
List of formatted terms
"""
first_term = True
terms = []
for number in numbers:
term = num_to_latex_ket(number, first_term, decimals)
if term is not None:
first_term = False
terms.append(term)
return terms


def _numbers_to_latex_terms(numbers: List[complex], decimals: int = 10) -> List[str]:
"""Convert a list of numbers to latex formatted terms
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/fix_11143-d32a262538873a9d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
deprecations:
- |
The functions :func:`.num_to_latex_ket` and :func:`.numbers_to_latex_terms`
have been removed. For similar functionality, see sympy's
``nsimplify`` and ``latex`` functions.
24 changes: 1 addition & 23 deletions test/python/quantum_info/states/test_statevector.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from qiskit.quantum_info.operators.operator import Operator
from qiskit.quantum_info.operators.symplectic import Pauli, SparsePauliOp
from qiskit.quantum_info.operators.predicates import matrix_equal
from qiskit.visualization.state_visualization import numbers_to_latex_terms, state_to_latex
from qiskit.visualization.state_visualization import state_to_latex

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1320,28 +1320,6 @@ def test_state_to_latex_with_decimals_round(self):
"0.354 |000\\rangle+0.354 |001\\rangle- 0.354 i |110\\rangle+0.354 i |111\\rangle",
)

def test_number_to_latex_terms(self):
"""Test conversions of complex numbers to latex terms"""

cases = [
([1 - 8e-17, 0], ["", None]),
([0, -1], [None, "-"]),
([0, 1], [None, ""]),
([0, 1j], [None, "i"]),
([-1, 1], ["-", "+"]),
([0, 1j], [None, "i"]),
([-1, 1j], ["-", "+i"]),
([1e-16 + 1j], ["i"]),
([-1 + 1e-16 * 1j], ["-"]),
([-1, -1 - 1j], ["-", "+(-1 - i)"]),
([np.sqrt(2) / 2, np.sqrt(2) / 2], ["\\frac{\\sqrt{2}}{2}", "+\\frac{\\sqrt{2}}{2}"]),
([1 + np.sqrt(2)], ["(1 + \\sqrt{2})"]),
]
with self.assertWarns(DeprecationWarning):
for numbers, latex_terms in cases:
terms = numbers_to_latex_terms(numbers, 15)
self.assertListEqual(terms, latex_terms)

def test_statevector_draw_latex_regression(self):
"""Test numerical rounding errors are not printed"""
sv = Statevector(np.array([1 - 8e-17, 8.32667268e-17j]))
Expand Down

0 comments on commit cff661f

Please sign in to comment.