From 87b0d76921fe7d506ddb158ab34e91eaae0a0c64 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Tue, 11 Oct 2022 10:11:05 +0100 Subject: [PATCH 01/11] Remove code duplication --- qiskit/visualization/array.py | 140 ++++++------------ qiskit/visualization/state_visualization.py | 94 +++++------- .../quantum_info/states/test_statevector.py | 9 +- test/python/visualization/test_utils.py | 7 +- 4 files changed, 93 insertions(+), 157 deletions(-) diff --git a/qiskit/visualization/array.py b/qiskit/visualization/array.py index b14457e9cb95..57955d66b4a3 100644 --- a/qiskit/visualization/array.py +++ b/qiskit/visualization/array.py @@ -13,117 +13,63 @@ Tools to create LaTeX arrays. """ -import math -from fractions import Fraction import numpy as np from qiskit.exceptions import MissingOptionalLibraryError -def _num_to_latex(num, precision=5): - """Takes a complex number as input and returns a latex representation +def _num_to_latex(raw_value, decimals=15, first_term=True, coefficient=False): + """Convert a complex number to latex code suitable for a ket expression Args: - num (numerical): The number to be converted to latex. - precision (int): If the real or imaginary parts of num are not close - to an integer, the number of decimal places to round to - + raw_value (complex): Value to convert. + decimals (int): Number of decimal places to round to (default 15). + coefficient (bool): Whether the number is to be used as a coefficient + of a ket. + first_term (bool): If a coefficient, whether this number is the first + coefficient in the expression. Returns: - str: Latex representation of num + str: latex code """ - # Result is combination of maximum 4 strings in the form: - # {common_facstring} ( {realstring} {operation} {imagstring}i ) - # common_facstring: A common factor between the real and imaginary part - # realstring: The real part (inc. a negative sign if applicable) - # operation: The operation between the real and imaginary parts ('+' or '-') - # imagstring: Absolute value of the imaginary parts (i.e. not inc. any negative sign). - # This function computes each of these strings and combines appropriately. - - r = np.real(num) - i = np.imag(num) - common_factor = None - - # try to factor out common terms in imaginary numbers - if np.isclose(abs(r), abs(i)) and not np.isclose(r, 0) and not np.isclose(i, 0): - common_factor = abs(r) - r = r / common_factor - i = i / common_factor - - common_terms = { - 1 / math.sqrt(2): "\\tfrac{1}{\\sqrt{2}}", - 1 / math.sqrt(3): "\\tfrac{1}{\\sqrt{3}}", - math.sqrt(2 / 3): "\\sqrt{\\tfrac{2}{3}}", - math.sqrt(3 / 4): "\\sqrt{\\tfrac{3}{4}}", - 1 / math.sqrt(8): "\\tfrac{1}{\\sqrt{8}}", - } - - def _proc_value(val): - # This function converts a real value to a latex string - # First, see if val is close to an integer: - val_mod = np.mod(val, 1) - if np.isclose(val_mod, 0) or np.isclose(val_mod, 1): - # If so, return that integer - return str(int(np.round(val))) - # Otherwise, see if it matches one of the common terms - for term, latex_str in common_terms.items(): - if np.isclose(abs(val), term): - if val > 0: - return latex_str - else: - return "-" + latex_str - # try to factorise val nicely - frac = Fraction(val).limit_denominator() - num, denom = frac.numerator, frac.denominator - if abs(num) + abs(denom) < 20: - # If fraction is 'nice' return - if val > 0: - return f"\\tfrac{{{abs(num)}}}{{{abs(denom)}}}" - else: - return f"-\\tfrac{{{abs(num)}}}{{{abs(denom)}}}" - else: - # Failing everything else, return val as a decimal - return "{:.{}f}".format(val, precision).rstrip("0") + import sympy # runtime import - # Get string (or None) for common factor between real and imag - if common_factor is None: - common_facstring = None - else: - common_facstring = _proc_value(common_factor) + raw_value = np.around(raw_value, decimals=decimals) + value = sympy.nsimplify(raw_value, rational=False) - # Get string for real part - realstring = _proc_value(r) + if isinstance(value, sympy.core.numbers.Rational) and value.denominator > 50: + # Avoid showing ugly fractions (e.g. 50498971964399/62500000000000) + value = value.evalf() # Display as float - # Get string for both imaginary part and operation between real and imaginary parts - if i > 0: - operation = "+" - imagstring = _proc_value(i) - else: - operation = "-" - imagstring = _proc_value(-i) - if imagstring == "1": - imagstring = "" # Don't want to return '1i', just 'i' - - # Now combine the strings appropriately: - if imagstring == "0": - return realstring # realstring already contains the negative sign (if needed) - if realstring == "0": - # imagstring needs the negative sign adding - if operation == "-": - return f"-{imagstring}i" - else: - return f"{imagstring}i" - if common_facstring is not None: - return f"{common_facstring}({realstring} {operation} {imagstring}i)" - else: - return f"{realstring} {operation} {imagstring}i" + if isinstance(value, sympy.core.numbers.Float): + value = round(value, decimals) + + element = sympy.latex(value, full_prec=False) + if not coefficient: + return element -def _matrix_to_latex(matrix, precision=5, prefix="", max_size=(8, 8)): + if isinstance(value, sympy.core.Add): + # element has two terms + element = f"({element})" + + if element == "1": + element = "" + + if element == "-1": + element = "-" + + if not first_term and not element.startswith("-"): + element = f"+{element}" + + return element + + +def _matrix_to_latex(matrix, decimals=10, prefix="", max_size=(8, 8)): """Latex representation of a complex numpy array (with maximum dimension 2) Args: matrix (ndarray): The matrix to be converted to latex, must have dimension 2. - precision (int): For numbers not close to integers, the number of decimal places + decimals (int): For numbers not close to integers, the number of decimal places to round to. prefix (str): Latex string to be prepended to the latex, intended for labels. max_size (list(```int```)): Indexable containing two integers: Maximum width and maximum @@ -149,7 +95,7 @@ def _elements_to_latex(elements): # string from it; Each element separated by `&` el_string = "" for el in elements: - num_string = _num_to_latex(el, precision=precision) + num_string = _num_to_latex(el, decimals=decimals) el_string += num_string + " & " el_string = el_string[:-2] # remove trailing ampersands return el_string @@ -197,7 +143,7 @@ def _rows_to_latex(rows, max_width): return out_string -def array_to_latex(array, precision=5, prefix="", source=False, max_size=8): +def array_to_latex(array, precision=10, prefix="", source=False, max_size=8): """Latex representation of a complex numpy array (with dimension 1 or 2) Args: @@ -239,10 +185,12 @@ def array_to_latex(array, precision=5, prefix="", source=False, max_size=8): if array.ndim <= 2: if isinstance(max_size, int): max_size = (max_size, max_size) - outstr = _matrix_to_latex(array, precision=precision, prefix=prefix, max_size=max_size) + outstr = _matrix_to_latex(array, decimals=precision, prefix=prefix, max_size=max_size) else: raise ValueError("array_to_latex can only convert numpy ndarrays of dimension 1 or 2") + outstr = _matrix_to_latex(array, decimals=precision, prefix=prefix, max_size=max_size) + if source is False: try: from IPython.display import Latex diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py index b847a7b0ec85..5ec3476774e6 100644 --- a/qiskit/visualization/state_visualization.py +++ b/qiskit/visualization/state_visualization.py @@ -21,6 +21,7 @@ from functools import reduce import colorsys import numpy as np +import warnings from qiskit import user_config from qiskit.quantum_info.states.statevector import Statevector from qiskit.quantum_info.operators.symplectic import PauliList, SparsePauliOp @@ -29,7 +30,7 @@ from qiskit.utils import optionals as _optionals from qiskit.circuit.tools.pi_check import pi_check -from .array import array_to_latex +from .array import _num_to_latex, array_to_latex from .utils import matplotlib_close_if_inline from .exceptions import VisualizationError @@ -1233,69 +1234,34 @@ def num_to_latex_ket(raw_value: complex, first_term: bool, decimals: int = 10) - Returns: String with latex code or None if no term is required """ - import sympy # runtime import - - if raw_value == 0: - value = 0 - real_value = 0 - imag_value = 0 - else: - raw_value = np.around(raw_value, decimals=decimals) - value = sympy.nsimplify(raw_value, constants=(sympy.pi,), rational=False) - real_value = float(sympy.re(value)) - imag_value = float(sympy.im(value)) - - element = "" - if np.abs(value) > 0: - latex_element = sympy.latex(value, full_prec=False) - two_term = real_value != 0 and imag_value != 0 - if isinstance(value, sympy.core.Add): - # can happen for expressions like 1 + sqrt(2) - two_term = True - if two_term: - if first_term: - element = f"({latex_element})" - else: - element = f"+ ({latex_element})" - else: - if first_term: - if np.isreal(complex(value)) and value > 0: - element = latex_element - else: - element = latex_element - if element == "1": - element = "" - elif element == "-1": - element = "-" - else: - - if imag_value == 0 and real_value > 0: - element = "+" + latex_element - elif real_value == 0 and imag_value > 0: - element = "+" + latex_element - else: - element = latex_element - if element == "+1": - element = "+" - elif element == "-1": - element = "-" - - return element - else: + warnings.warn( + "~qiskit.visualization.state_visualization.num_to_latex_ket " + "is deprecated as of 0.23.0 and will be removed no earlier than 3 months " + "after the release.", + category=DeprecationWarning, + stacklevel=2, + ) + 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) 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 """ + warnings.warn( + "~qiskit.visualization.state_visualization.num_to_latex_terms " + "is deprecated as of 0.23.0 and will be removed no earlier than 3 months " + "after the release.", + category=DeprecationWarning, + stacklevel=2, + ) first_term = True terms = [] for number in numbers: @@ -1306,6 +1272,26 @@ def numbers_to_latex_terms(numbers: List[complex], decimals: int = 10) -> List[s return terms +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(number, decimals=decimals, first_term=first_term, coefficient=True) + terms.append(term) + first_term = False + return terms + + def _state_to_latex_ket(data: List[complex], max_size: int = 12, prefix: str = "") -> str: """Convert state vector to latex representation @@ -1329,10 +1315,10 @@ def ket_name(i): nonzero_indices = ( nonzero_indices[: max_size // 2] + [0] + nonzero_indices[-max_size // 2 + 1 :] ) - latex_terms = numbers_to_latex_terms(data[nonzero_indices], max_size) + latex_terms = _numbers_to_latex_terms(data[nonzero_indices], max_size) nonzero_indices[max_size // 2] = None else: - latex_terms = numbers_to_latex_terms(data[nonzero_indices], max_size) + latex_terms = _numbers_to_latex_terms(data[nonzero_indices], max_size) latex_str = "" for idx, ket_idx in enumerate(nonzero_indices): diff --git a/test/python/quantum_info/states/test_statevector.py b/test/python/quantum_info/states/test_statevector.py index c7eec1faa38a..124edff2027b 100644 --- a/test/python/quantum_info/states/test_statevector.py +++ b/test/python/quantum_info/states/test_statevector.py @@ -1182,13 +1182,14 @@ def test_number_to_latex_terms(self): ([-1, 1j], ["-", "+i"]), ([1e-16 + 1j], ["i"]), ([-1 + 1e-16 * 1j], ["-"]), - ([-1, -1 - 1j], ["-", "+ (-1 - i)"]), + ([-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})"]), ] - for numbers, latex_terms in cases: - terms = numbers_to_latex_terms(numbers, 15) - self.assertListEqual(terms, latex_terms) + 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""" diff --git a/test/python/visualization/test_utils.py b/test/python/visualization/test_utils.py index 1112b757de1f..38bb1ba4d401 100644 --- a/test/python/visualization/test_utils.py +++ b/test/python/visualization/test_utils.py @@ -399,9 +399,10 @@ def test_array_to_latex(self): ] matrix = np.array(matrix) exp_str = ( - "\\begin{bmatrix}\\tfrac{1}{\\sqrt{2}}&\\tfrac{1}{16}&\\tfrac{1}{\\sqrt{8}}+3i&" - "\\tfrac{1}{2}(-1+i)\\\\\\tfrac{1}{3}(1+i)&\\tfrac{1}{\\sqrt{2}}i&34.321&" - "-\\tfrac{9}{2}\\\\\\end{bmatrix}" + "\\begin{bmatrix}\\frac{\\sqrt{2}}{2}&\\frac{1}{16}&" + "\\frac{\\sqrt{2}}{4}+3i&-\\frac{1}{2}+\\frac{i}{2}\\\\" + "\\frac{1}{3}+\\frac{i}{3}&\\frac{\\sqrt{2}i}{2}&34.321&-" + "\\frac{9}{2}\\\\\\end{bmatrix}" ) result = array_to_latex(matrix, source=True).replace(" ", "").replace("\n", "") self.assertEqual(exp_str, result) From 52050e5659ff9bef65cfb846d3cda5e02b1c6e00 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Tue, 11 Oct 2022 10:31:58 +0100 Subject: [PATCH 02/11] Revert default --- qiskit/visualization/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/visualization/array.py b/qiskit/visualization/array.py index 57955d66b4a3..4f578a9b4834 100644 --- a/qiskit/visualization/array.py +++ b/qiskit/visualization/array.py @@ -143,7 +143,7 @@ def _rows_to_latex(rows, max_width): return out_string -def array_to_latex(array, precision=10, prefix="", source=False, max_size=8): +def array_to_latex(array, precision=5, prefix="", source=False, max_size=8): """Latex representation of a complex numpy array (with dimension 1 or 2) Args: From 0aa293aa6511e09368b7adb2017de1f4fbeb8bb3 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Tue, 11 Oct 2022 10:35:54 +0100 Subject: [PATCH 03/11] Add releasenote --- .../notes/latex-refactor-0745471ddecac605.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 releasenotes/notes/latex-refactor-0745471ddecac605.yaml diff --git a/releasenotes/notes/latex-refactor-0745471ddecac605.yaml b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml new file mode 100644 index 000000000000..522ab11fe124 --- /dev/null +++ b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml @@ -0,0 +1,13 @@ +--- +deprecations: + - | + Deprecated two functions + (```~qiskit.visualization.state_visualization.num_to_latex_ket``` and + ```~qiskit.visualization.state_visualization.num_to_latex_terms```). +other: + - | + The latex array drawer (e.g. ```array_to_latex```, + ```Statevector.draw('latex')```) now uses the same sympy function as the + ket-convention drawer. This means it may render some numbers differently + (e.g. may identify new factors, or rationalize denominators where it did + not previously). From 9684c3fec8bd1576ddd14cab4d9a27990ea2390e Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Tue, 11 Oct 2022 10:43:20 +0100 Subject: [PATCH 04/11] un-revert default precision --- qiskit/visualization/array.py | 2 +- releasenotes/notes/latex-refactor-0745471ddecac605.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/visualization/array.py b/qiskit/visualization/array.py index 4f578a9b4834..57955d66b4a3 100644 --- a/qiskit/visualization/array.py +++ b/qiskit/visualization/array.py @@ -143,7 +143,7 @@ def _rows_to_latex(rows, max_width): return out_string -def array_to_latex(array, precision=5, prefix="", source=False, max_size=8): +def array_to_latex(array, precision=10, prefix="", source=False, max_size=8): """Latex representation of a complex numpy array (with dimension 1 or 2) Args: diff --git a/releasenotes/notes/latex-refactor-0745471ddecac605.yaml b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml index 522ab11fe124..a06cf0a39bab 100644 --- a/releasenotes/notes/latex-refactor-0745471ddecac605.yaml +++ b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml @@ -10,4 +10,4 @@ other: ```Statevector.draw('latex')```) now uses the same sympy function as the ket-convention drawer. This means it may render some numbers differently (e.g. may identify new factors, or rationalize denominators where it did - not previously). + not previously). The default ```precision``` has been changed from 5 to 10. From 18501f33eb7df59521b4413585b0a0932c2ffff8 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Tue, 11 Oct 2022 16:02:48 +0100 Subject: [PATCH 05/11] lint --- qiskit/visualization/state_visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py index 5ec3476774e6..c870dbe48b05 100644 --- a/qiskit/visualization/state_visualization.py +++ b/qiskit/visualization/state_visualization.py @@ -20,8 +20,8 @@ from typing import Optional, List, Union from functools import reduce import colorsys -import numpy as np import warnings +import numpy as np from qiskit import user_config from qiskit.quantum_info.states.statevector import Statevector from qiskit.quantum_info.operators.symplectic import PauliList, SparsePauliOp From 7798c47e4c8cbe688d9165c3d6fedb6685962651 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Wed, 16 Nov 2022 15:07:09 +0000 Subject: [PATCH 06/11] Update releasenotes/notes/latex-refactor-0745471ddecac605.yaml Co-authored-by: Ikko Hamamura --- releasenotes/notes/latex-refactor-0745471ddecac605.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/latex-refactor-0745471ddecac605.yaml b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml index a06cf0a39bab..3c2c881603ae 100644 --- a/releasenotes/notes/latex-refactor-0745471ddecac605.yaml +++ b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml @@ -4,7 +4,7 @@ deprecations: Deprecated two functions (```~qiskit.visualization.state_visualization.num_to_latex_ket``` and ```~qiskit.visualization.state_visualization.num_to_latex_terms```). -other: +upgrade: - | The latex array drawer (e.g. ```array_to_latex```, ```Statevector.draw('latex')```) now uses the same sympy function as the From 3e0ba1a4f9c04d3cdef1e092595cd074a3ab4457 Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Wed, 16 Nov 2022 15:26:57 +0000 Subject: [PATCH 07/11] Fix logic and neaten guard clauses --- qiskit/visualization/array.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/qiskit/visualization/array.py b/qiskit/visualization/array.py index 57955d66b4a3..a874c6b88fdd 100644 --- a/qiskit/visualization/array.py +++ b/qiskit/visualization/array.py @@ -182,24 +182,24 @@ def array_to_latex(array, precision=10, prefix="", source=False, max_size=8): or types that can be converted to such arrays""" ) from err - if array.ndim <= 2: - if isinstance(max_size, int): - max_size = (max_size, max_size) - outstr = _matrix_to_latex(array, decimals=precision, prefix=prefix, max_size=max_size) - else: + if array.ndim > 2: raise ValueError("array_to_latex can only convert numpy ndarrays of dimension 1 or 2") + if isinstance(max_size, int): + max_size = (max_size, max_size) + outstr = _matrix_to_latex(array, decimals=precision, prefix=prefix, max_size=max_size) - if source is False: - try: - from IPython.display import Latex - except ImportError as err: - raise MissingOptionalLibraryError( - libname="IPython", - name="array_to_latex", - pip_install="pip install ipython", - ) from err - return Latex(f"$${outstr}$$") - else: + if source is True: return outstr + + try: + from IPython.display import Latex + except ImportError as err: + raise MissingOptionalLibraryError( + libname="IPython", + name="array_to_latex", + pip_install="pip install ipython", + ) from err + return Latex(f"$${outstr}$$") + From 57f43ca4155defdc03f02eb645500912d0447fdf Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Wed, 16 Nov 2022 16:46:41 +0000 Subject: [PATCH 08/11] lint --- qiskit/visualization/array.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qiskit/visualization/array.py b/qiskit/visualization/array.py index a874c6b88fdd..b076e38b174d 100644 --- a/qiskit/visualization/array.py +++ b/qiskit/visualization/array.py @@ -202,4 +202,3 @@ def array_to_latex(array, precision=10, prefix="", source=False, max_size=8): pip_install="pip install ipython", ) from err return Latex(f"$${outstr}$$") - From 7487ae410bae4e354aba1dab0029a8e40697995d Mon Sep 17 00:00:00 2001 From: Frank Harkins Date: Thu, 17 Nov 2022 15:15:13 +0000 Subject: [PATCH 09/11] Point to sympy alternative in warning --- qiskit/visualization/state_visualization.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py index c870dbe48b05..88e592838533 100644 --- a/qiskit/visualization/state_visualization.py +++ b/qiskit/visualization/state_visualization.py @@ -1235,9 +1235,10 @@ def num_to_latex_ket(raw_value: complex, first_term: bool, decimals: int = 10) - String with latex code or None if no term is required """ warnings.warn( - "~qiskit.visualization.state_visualization.num_to_latex_ket " - "is deprecated as of 0.23.0 and will be removed no earlier than 3 months " - "after the release.", + "~qiskit.visualization.state_visualization.num_to_latex_ket is " + "deprecated as of 0.23.0 and will be removed no earlier than 3 months " + "after the release. For similar functionality, see sympy's `nsimplify` " + "and `latex` functions.", category=DeprecationWarning, stacklevel=2, ) @@ -1256,9 +1257,10 @@ def numbers_to_latex_terms(numbers: List[complex], decimals: int = 10) -> List[s List of formatted terms """ warnings.warn( - "~qiskit.visualization.state_visualization.num_to_latex_terms " - "is deprecated as of 0.23.0 and will be removed no earlier than 3 months " - "after the release.", + "~qiskit.visualization.state_visualization.num_to_latex_terms is " + "deprecated as of 0.23.0 and will be removed no earlier than 3 months " + "after the release. For similar functionality, see sympy's `nsimplify` " + "and `latex` functions.", category=DeprecationWarning, stacklevel=2, ) From 96d57b7f890d823aa3a0141acc9c694341f78380 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Tue, 17 Jan 2023 15:28:29 +0000 Subject: [PATCH 10/11] Fix deprecation messages --- qiskit/visualization/state_visualization.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py index 88e592838533..d60e9f19ec8b 100644 --- a/qiskit/visualization/state_visualization.py +++ b/qiskit/visualization/state_visualization.py @@ -1235,7 +1235,7 @@ def num_to_latex_ket(raw_value: complex, first_term: bool, decimals: int = 10) - String with latex code or None if no term is required """ warnings.warn( - "~qiskit.visualization.state_visualization.num_to_latex_ket is " + "qiskit.visualization.state_visualization.num_to_latex_ket is " "deprecated as of 0.23.0 and will be removed no earlier than 3 months " "after the release. For similar functionality, see sympy's `nsimplify` " "and `latex` functions.", @@ -1257,7 +1257,7 @@ def numbers_to_latex_terms(numbers: List[complex], decimals: int = 10) -> List[s List of formatted terms """ warnings.warn( - "~qiskit.visualization.state_visualization.num_to_latex_terms is " + "qiskit.visualization.state_visualization.num_to_latex_terms is " "deprecated as of 0.23.0 and will be removed no earlier than 3 months " "after the release. For similar functionality, see sympy's `nsimplify` " "and `latex` functions.", From 34dfee53fe811c21393834e83985a91e5bd05534 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Tue, 17 Jan 2023 15:31:19 +0000 Subject: [PATCH 11/11] Reword release note --- .../notes/latex-refactor-0745471ddecac605.yaml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/releasenotes/notes/latex-refactor-0745471ddecac605.yaml b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml index 3c2c881603ae..d32a2fd469d7 100644 --- a/releasenotes/notes/latex-refactor-0745471ddecac605.yaml +++ b/releasenotes/notes/latex-refactor-0745471ddecac605.yaml @@ -1,13 +1,17 @@ --- deprecations: - | - Deprecated two functions - (```~qiskit.visualization.state_visualization.num_to_latex_ket``` and - ```~qiskit.visualization.state_visualization.num_to_latex_terms```). + Two mostly internal functions in ``qiskit.visualization.state_visualization``, + ``num_to_latex_ket`` and ``num_to_latex_terms``, have been deprecated and will + be removed no sooner than Qiskit Terra 0.25. These were old internal worker + functions that are no longer used. For similar functionality, look at Sympy's + ``nsimplify`` and ``latex`` functions. upgrade: - | - The latex array drawer (e.g. ```array_to_latex```, - ```Statevector.draw('latex')```) now uses the same sympy function as the + The LaTeX array drawers (e.g. ``array_to_latex``, + ``Statevector.draw('latex')``) now use the same sympy function as the ket-convention drawer. This means it may render some numbers differently - (e.g. may identify new factors, or rationalize denominators where it did - not previously). The default ```precision``` has been changed from 5 to 10. + to previous releases, but will provide a more consistent experience. + For example, it may identify new factors, or rationalize denominators where + it did not previously. The default ``precision`` has been changed from 5 to + 10.