Skip to content

Commit 872c957

Browse files
Merge branch 'master' into beta
2 parents f198248 + a7b663c commit 872c957

File tree

10 files changed

+85
-19
lines changed

10 files changed

+85
-19
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ disable=all
1313
enable=c-extension-no-member,
1414
bad-indentation,
1515
bare-except,
16-
broad-except,
16+
; broad-except,
1717
dangerous-default-value,
1818
function-redefined,
1919
len-as-condition,

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
- Add `circuit.to_openqasm_file` function for compatibility of qiskit>1
1010

11+
- Add `tc.cite()` to get citation information
12+
13+
### Fixed
14+
15+
- Fix customized jax eigh operator by noting the return is a namedtuple
16+
1117
## 1.0.2
1218

1319
### Added

docs/source/advance.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The larger bond dimension we set, the better approximation ratio (of course the
1919
Stacked gates
2020
----------------
2121

22-
Stacked gates is a simple grammar sugar to make constructing the circuit easily when multiple gate of the same type are applied on the different qubits, namely, the index for gate function can accept list of ints instead of one integer.
22+
Stacked-gate is a simple syntactic sugar rendering circuit construction easily when multiple gate of the same type are applied on different qubits, namely, the index for gate call can accept list of ints instead of one integer.
2323

2424
.. code-block:: python
2525
@@ -98,12 +98,14 @@ Analog circuit simulation
9898

9999
TensorCircuit-NG support digital-analog hybrid simulation (say cases in Rydberg atom arrays), where the analog part is simulated by the neural differential equation solver given the API to specify a time dependent Hamiltonian.
100100
The simulation is still differentiable and jittable. Only jax backend is supported for analog simulation as the neural ode engine is built on top of jax.
101+
101102
This utility is super helpful for optimizing quantum control or investigating digital-analog hybrid variational quantum schemes.
102-
We support two modes of analog simulation, where :py:meth:`tensorcircuit.experimentaql.evol_global` evolve the state via a Hamiltonian define on the whole system, and :py:meth:`tensorcircuit.experimentaql.evol_local` evolve the state via a Hamiltonian define on a local subsystem.
103+
104+
We support two modes of analog simulation, where :py:meth:`tensorcircuit.experimental.evol_global` evolve the state via a Hamiltonian define on the whole system, and :py:meth:`tensorcircuit.experimental.evol_local` evolve the state via a Hamiltonian define on a local subsystem.
103105

104106
.. Note::
105107

106-
``evol_global`` use sparse Hamiltonian while ``evol_local`` use dense Hamiltonian.
108+
``evol_global`` uses sparse Hamiltonian while ``evol_local`` uses dense Hamiltonian.
107109

108110

109111
.. code-block:: python
@@ -155,9 +157,9 @@ We wrap the tf-backend `SavedModel` as very easy-to-use function :py:meth:`tenso
155157

156158
For the JAX-backend quantum function, one can first transform them into the tf-backend function via JAX experimental support: `jax2tf <https://github.com/google/jax/tree/main/jax/experimental/jax2tf>`_.
157159

158-
**Updates**: jax now also support jitted function save/load via ``export`` module, see `jax documentation <https://jax.readthedocs.io/en/latest/export/export.html>_`.
160+
**Updates**: jax now also support jitted function save/load via ``export`` module, see `jax documentation <https://jax.readthedocs.io/en/latest/export/export.html>`_.
159161

160-
We wrape the jax function export capability in ``experimental`` module and can be used as follows
162+
We wrap the jax function export capability in ``experimental`` module and can be used as follows
161163

162164
.. code-block:: python
163165

docs/source/index.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ TensorCircuit Next Generation
77

88
**Welcome and congratulations! You have found TensorCircuit: the Next Generation.** 👏
99

10+
1011
Introduction
1112
---------------
1213

13-
TensorCircuit-NG is an open-source high-performance quantum computing software framework in Python.
14+
TensorCircuit-NG is an open-source high-performance quantum software framework in Python.
1415

1516
* It is built for humans. 👽
1617

@@ -22,16 +23,21 @@ TensorCircuit-NG is an open-source high-performance quantum computing software f
2223

2324
* It is implemented with industry-standard machine learning frameworks: TensorFlow, JAX, and PyTorch. 🤖
2425

26+
* It is flexible and powerful to build and simulate tensor networks, neural networks and quantum circuits together. 🧠
27+
2528
* It is compatible with machine learning engineering paradigms: automatic differentiation, just-in-time compilation, vectorized parallelism and GPU acceleration. 🛠
2629

27-
With the help of TensorCircuit-NG, now get ready to efficiently and elegantly solve interesting and challenging quantum computing problems: from academic research prototype to industry application deployment.
30+
With the help of TensorCircuit-NG, now get ready to efficiently and elegantly solve interesting and challenging quantum computing and quantum many-body problems: from academic research prototype to industry application deployment.
2831

32+
.. important::
33+
Please cite the `whitepaper <https://quantum-journal.org/papers/q-2023-02-02-912/>`_ when using TensorCircuit or TensorCircuit-NG in your research. The bibtex information is provided by ``tc.cite()``.
2934

3035

3136

32-
Relevant Links
37+
Useful Links
3338
--------------------
3439

40+
3541
TensorCircuit is created and now maintained as TensorCircuit-NG by `Shi-Xin Zhang <https://github.com/refraction-ray>`_.
3642

3743
The current core authors of TensorCircuit-NG are `Shi-Xin Zhang <https://github.com/refraction-ray>`_ and `Yu-Qin Chen <https://github.com/yutuer21>`_.
@@ -153,19 +159,19 @@ TensorCircuit-NG is unifying infrastructures and interfaces for quantum computin
153159
:columns: 12 6 3 3
154160
:shadow: md
155161

156-
ideal/noisy/approximate simulation
162+
ideal/noisy/approximate/analog simulation
157163

158164
.. grid-item-card:: Unified Representations
159165
:columns: 12 6 3 3
160166
:shadow: md
161167

162168
from/to_IR/qiskit/openqasm/json
163169

164-
.. grid-item-card:: Unified Pipelines
170+
.. grid-item-card:: Unified Objects
165171
:columns: 12 6 3 3
166172
:shadow: md
167173

168-
stateless functional programming/stateful ML models
174+
neural-net/tensor-net/quantum-circuit
169175

170176

171177

docs/source/quickstart.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Either pip from conda or other python env managers is fine.
1515
Since there are many optional packages for various features,
1616
the users may need to install more pip packages when required.
1717

18-
- For Linux with Nvidia GPU,
18+
For Nvidia GPU,
1919
please refer to the GPU aware installation guide of corresponding machine learning frameworks:
2020
`TensorFlow <https://www.tensorflow.org/install/gpu>`_,
2121
`Jax <https://github.com/google/jax#pip-installation-gpu-cuda>`_,
@@ -27,7 +27,6 @@ Docker is also recommended (especially Linux + Nvidia GPU setup):
2727

2828
For more details on docker setup, please refer to `docker readme <https://github.com/tensorcircuit/tensorcircuit-ng/tree/master/docker>`_.
2929

30-
- For Windows, due to the lack of support for Jax, we recommend to use docker or WSL, please refer to `TC via windows docker <contribs/development_windows.html>`_ or `TC via WSL <contribs/development_wsl2.html>`_.
3130

3231
Overall, the installation of TensorCircuit-NG is simple, since it is purely in Python and hence very portable.
3332
As long as the users can take care of the installation of ML frameworks on the corresponding system, TensorCircuit-NG will work as expected.
@@ -239,6 +238,7 @@ To learn more about the jit mechanism, one can refer to documentation or blogs o
239238

240239
Inputs, parameters, measurements, circuit structures, and Monte Carlo noise can all be evaluated in parallel.
241240
To learn more about vmap mechanism, one can refer to documentation or blogs on ``tf.vectorized_map`` or ``jax.vmap``.
241+
One can also refer to `tutorial <https://tensorcircuit-ng.readthedocs.io/en/latest/whitepaper/6-3-vmap.html>`_ for more details on the vmap usage in TensorCircuit-NG.
242242

243243

244244
Backend Agnosticism

tensorcircuit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
gpu_memory_share()
88

9-
from .about import about
9+
from .about import about, cite
1010
from .cons import (
1111
backend,
1212
set_backend,

tensorcircuit/about.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,26 @@ def about() -> None:
2323
print(f"Scipy version: {scipy.__version__}")
2424
except ModuleNotFoundError:
2525
print(f"Scipy is not installed")
26+
except Exception as e:
27+
print(f"Misconfiguration for Scipy: {e}")
2628

2729
try:
2830
import pandas
2931

3032
print(f"Pandas version: {pandas.__version__}")
3133
except ModuleNotFoundError:
3234
print(f"Pandas is not installed")
35+
except Exception as e:
36+
print(f"Misconfiguration for Pandas: {e}")
3337

3438
try:
3539
import tensornetwork as tn
3640

3741
print(f"TensorNetwork version: {tn.__version__}")
3842
except ModuleNotFoundError:
3943
print(f"TensorNetwork is not installed")
44+
except Exception as e:
45+
print(f"Misconfiguration for TensorNetwork: {e}")
4046

4147
try:
4248
import cotengra
@@ -47,6 +53,8 @@ def about() -> None:
4753
print(f"Cotengra: installed")
4854
except ModuleNotFoundError:
4955
print(f"Cotengra is not installed")
56+
except Exception as e:
57+
print(f"Misconfiguration for Cotengra: {e}")
5058

5159
try:
5260
import tensorflow as tf
@@ -56,6 +64,8 @@ def about() -> None:
5664
print(f"TensorFlow CUDA infos: {dict(tf.sysconfig.get_build_info())}")
5765
except ModuleNotFoundError:
5866
print(f"TensorFlow is not installed")
67+
except Exception as e:
68+
print(f"Misconfiguration for TensorFlow: {e}")
5969

6070
try:
6171
import jax
@@ -68,13 +78,17 @@ def about() -> None:
6878
print(f"Jax installation doesn't support GPU")
6979
except ModuleNotFoundError:
7080
print(f"Jax is not installed")
81+
except Exception as e:
82+
print(f"Misconfiguration for Jax: {e}")
7183

7284
try:
7385
import jaxlib
7486

7587
print(f"JaxLib version: {jaxlib.__version__}")
7688
except ModuleNotFoundError:
7789
print(f"JaxLib is not installed")
90+
except Exception as e:
91+
print(f"Misconfiguration for Jaxlib: {e}")
7892

7993
try:
8094
import torch
@@ -88,32 +102,64 @@ def about() -> None:
88102
print(f"Pytorch cuda version: {torch.version.cuda}")
89103
except ModuleNotFoundError:
90104
print(f"PyTorch is not installed")
105+
except Exception as e:
106+
print(f"Misconfiguration for Torch: {e}")
91107

92108
try:
93109
import cupy
94110

95111
print(f"Cupy version: {cupy.__version__}")
96112
except ModuleNotFoundError:
97113
print(f"Cupy is not installed")
114+
except Exception as e:
115+
print(f"Misconfiguration for Cupy: {e}")
98116

99117
try:
100118
import qiskit
101119

102120
print(f"Qiskit version: {qiskit.__version__}")
103121
except ModuleNotFoundError:
104122
print(f"Qiskit is not installed")
123+
except Exception as e:
124+
print(f"Misconfiguration for Qiskit: {e}")
105125

106126
try:
107127
import cirq
108128

109129
print(f"Cirq version: {cirq.__version__}")
110130
except ModuleNotFoundError:
111131
print(f"Cirq is not installed")
132+
except Exception as e:
133+
print(f"Misconfiguration for Cirq: {e}")
112134

113135
from tensorcircuit import __version__
114136

115137
print(f"TensorCircuit version {__version__}")
116138

117139

140+
def cite(format: str = "bib") -> str:
141+
"""
142+
Returns the citation information for tensorcircuit.
143+
Please cite our work if you use the package in your research.
144+
145+
:param format: format for bib, defaults to "bib"
146+
:type format: str, optional
147+
:return: the citation information
148+
:rtype: str
149+
"""
150+
if format == "bib":
151+
return """@article{Zhang_TensorCircuit_2023,
152+
author = {Zhang, Shi-Xin and Allcock, Jonathan and Wan, Zhou-Quan and Liu, Shuo and Sun, Jiace and Yu, Hao and Yang, Xing-Han and Qiu, Jiezhong and Ye, Zhaofeng and Chen, Yu-Qin and Lee, Chee-Kong and Zheng, Yi-Cong and Jian, Shao-Kai and Yao, Hong and Hsieh, Chang-Yu and Zhang, Shengyu},
153+
doi = {10.22331/q-2023-02-02-912},
154+
journal = {Quantum},
155+
month = feb,
156+
title = {{TensorCircuit: a Quantum Software Framework for the NISQ Era}},
157+
volume = {7},
158+
year = {2023}}"""
159+
elif format == "aps":
160+
return """S.-X. Zhang, J. Allcock, Z.-Q. Wan, S. Liu, J. Sun, H. Yu, X.-H. Yang, J. Qiu, Z. Ye, Y.-Q. Chen, C.-K. Lee, Y.-C. Zheng, S.-K. Jian, H. Yao, C.-Y. Hsieh, and S. Zhang, TensorCircuit: a Quantum Software Framework for the NISQ Era, Quantum 7, 912 (2023).""" # pylint: disable=line-too-long
161+
raise ValueError(f"Unsupported format: {format}")
162+
163+
118164
if __name__ == "__main__":
119165
about()

tensorcircuit/backends/jax_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def _QrGradSquareAndDeepMatrices(q: Array, r: Array, dq: Array, dr: Array) -> Ar
151151

152152
@jax.custom_vjp
153153
def adaware_eigh(A: Array) -> Array:
154-
return jnp.linalg.eigh(A)
154+
e, v = jnp.linalg.eigh(A)
155+
return e, v
155156

156157

157158
def jaxeigh_fwd(A: Array) -> Array:

tensorcircuit/experimental.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def jax_jitted_function_save(filename: str, f: Callable[..., Any], *args: Any) -
534534
:param args: example function arguments for ``f``
535535
"""
536536

537-
from jax import export
537+
from jax import export # type: ignore
538538

539539
f_export = export.export(f)(*args) # type: ignore
540540
barray = f_export.serialize()
@@ -555,14 +555,14 @@ def jax_jitted_function_load(filename: str) -> Callable[..., Any]:
555555
:return: the loaded function
556556
:rtype: _type_
557557
"""
558-
from jax import export
558+
from jax import export # type: ignore
559559

560560
with open(filename, "rb") as f:
561561
barray = f.read()
562562

563563
f_load = export.deserialize(barray) # type: ignore
564564

565-
return f_load.call
565+
return f_load.call # type: ignore
566566

567567

568568
jax_func_load = jax_jitted_function_load

tests/test_miscs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def test_about():
3636
print(tc.about())
3737

3838

39+
def test_cite():
40+
print(tc.cite())
41+
print(tc.cite("aps"))
42+
43+
3944
def test_ps2coo(tfb):
4045
for l, a in check_pairs:
4146
r1 = PauliString2COO(tf.constant(l, dtype=tf.int64))

0 commit comments

Comments
 (0)