|
26 | 26 | :func:`abs2`
|
27 | 27 | Absolute value squared
|
28 | 28 | :func:`get_indices_from_identifiers`
|
29 |
| - The the indices of a subset of identifiers within a list of |
30 |
| - identifiers. |
| 29 | + The indices of a subset of identifiers within a list of identifiers. |
31 | 30 | :func:`tensor`
|
32 | 31 | Fast, flexible tensor product of an arbitrary number of inputs using
|
33 | 32 | :func:`~numpy.einsum`
|
|
70 | 69 | import functools
|
71 | 70 | import inspect
|
72 | 71 | import operator
|
| 72 | +import os |
73 | 73 | import string
|
74 | 74 | from itertools import zip_longest
|
75 | 75 | from typing import Callable, Iterable, List, Optional, Sequence, Tuple, Union
|
|
79 | 79 |
|
80 | 80 | from .types import Operator, State
|
81 | 81 |
|
82 |
| -try: |
83 |
| - import ipynbname |
84 |
| - _NOTEBOOK_NAME = ipynbname.name() |
85 |
| -except (ImportError, IndexError, FileNotFoundError): |
86 |
| - _NOTEBOOK_NAME = '' |
87 | 82 |
|
88 |
| -if _NOTEBOOK_NAME: |
89 |
| - from tqdm.notebook import tqdm as _tqdm |
| 83 | +def _in_notebook_kernel(): |
| 84 | + # https://github.com/jupyterlab/jupyterlab/issues/16282 |
| 85 | + return 'JPY_SESSION_NAME' in os.environ and os.environ['JPY_SESSION_NAME'].endswith('.ipynb') |
| 86 | + |
| 87 | + |
| 88 | +def _in_jupyter_kernel(): |
| 89 | + # https://discourse.jupyter.org/t/how-to-know-from-python-script-if-we-are-in-jupyterlab/23993 |
| 90 | + return 'JPY_PARENT_PID' in os.environ |
| 91 | + |
| 92 | + |
| 93 | +if not _in_notebook_kernel(): |
| 94 | + if _in_jupyter_kernel(): |
| 95 | + # (10/24) Autonotebook gets confused in jupyter consoles |
| 96 | + from tqdm.std import tqdm |
| 97 | + else: |
| 98 | + from tqdm.autonotebook import tqdm |
90 | 99 | else:
|
91 |
| - # Either not running notebook or not able to determine |
92 |
| - from tqdm import tqdm as _tqdm |
| 100 | + from tqdm.notebook import tqdm |
93 | 101 |
|
94 | 102 | __all__ = ['paulis', 'abs2', 'all_array_equal', 'dot_HS', 'get_sample_frequencies',
|
95 | 103 | 'hash_array_along_axis', 'mdot', 'oper_equiv', 'progressbar', 'remove_float_errors',
|
@@ -1067,7 +1075,7 @@ def progressbar(iterable: Iterable, *args, **kwargs):
|
1067 | 1075 | for i in progressbar(range(10)):
|
1068 | 1076 | do_something()
|
1069 | 1077 | """
|
1070 |
| - return _tqdm(iterable, *args, **kwargs) |
| 1078 | + return tqdm(iterable, *args, **kwargs) |
1071 | 1079 |
|
1072 | 1080 |
|
1073 | 1081 | def progressbar_range(*args, show_progressbar: bool = True, **kwargs):
|
|
0 commit comments