You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/advance.rst
+130-5Lines changed: 130 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,17 +5,65 @@ Advanced Usage
5
5
MPS Simulator
6
6
----------------
7
7
8
-
(Still experimental support)
9
-
10
-
Very simple, we provide the same set of API for ``MPSCircuit`` as ``Circuit``,
8
+
Very straightforward to use, we provide the same set of API for ``MPSCircuit`` as ``Circuit``,
11
9
the only new line is to set the bond dimension for the new simulator.
12
10
13
11
.. code-block:: python
14
12
15
13
c = tc.MPSCircuit(n)
16
14
c.set_split_rules({"max_singular_values": 50})
17
15
18
-
The larger bond dimension we set, the better approximation ratio (of course the more computational cost we pay)
16
+
The larger bond dimension we set, the better approximation ratio (of course the more computational cost we pay).
17
+
18
+
19
+
Stacked gates
20
+
----------------
21
+
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.
@@ -45,15 +93,92 @@ The two-qubit gates applied on the circuit can be decomposed via SVD, which may
45
93
46
94
Note ``max_singular_values`` must be specified to make the whole procedure static and thus jittable.
47
95
96
+
Analog circuit simulation
97
+
-----------------------------
98
+
99
+
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.
100
+
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
+
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
+
.. Note::
105
+
106
+
``evol_global`` use sparse Hamiltonian while ``evol_local`` use dense Hamiltonian.
107
+
108
+
109
+
.. code-block:: python
110
+
111
+
# in this demo, we build a jittable and differentiable simulation function `hybrid_evol`
112
+
# with both digital gates and local/global analog Hamiltonian evolutions
113
+
114
+
import optax
115
+
import tensorcircuit as tc
116
+
from tensorcircuit.experimental import evol_global, evol_local
117
+
118
+
K = tc.set_backend("jax")
119
+
120
+
121
+
defh_fun(t, b):
122
+
return b * tc.gates.x().tensor
123
+
124
+
125
+
hy = tc.quantum.PauliStringSum2COO([[2, 0]])
126
+
127
+
128
+
defh_fun2(t, b):
129
+
return b[2] * K.cos(b[0] * t + b[1]) * hy
130
+
131
+
132
+
@K.jit
133
+
@K.value_and_grad
134
+
defhybrid_evol(params):
135
+
c = tc.Circuit(2)
136
+
c.x([0, 1])
137
+
c = evol_local(c, [1], h_fun, 1.0, params[0])
138
+
c.cx(1, 0)
139
+
c.h(0)
140
+
c = evol_global(c, h_fun2, 1.0, params[1:])
141
+
return K.real(c.expectation_ps(z=[0, 1]))
142
+
143
+
144
+
b = K.implicit_randn([4])
145
+
v, gs = hybrid_evol(b)
146
+
147
+
48
148
49
149
Jitted Function Save/Load
50
150
-----------------------------
51
151
52
152
To reuse the jitted function, we can save it on the disk via support from the TensorFlow `SavedModel <https://www.tensorflow.org/guide/saved_model>`_. That is to say, only jitted quantum function on the TensorFlow backend can be saved on the disk.
53
153
154
+
We wrap the tf-backend `SavedModel` as very easy-to-use function :py:meth:`tensorcircuit.keras.save_func` and :py:meth:`tensorcircuit.keras.load_func`.
155
+
54
156
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>`_.
55
157
56
-
We wrap the tf-backend `SavedModel` as very easy-to-use function :py:meth:`tensorcircuit.keras.save_func` and :py:meth:`tensorcircuit.keras.load_func`.
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>_`.
159
+
160
+
We wrape the jax function export capability in ``experimental`` module and can be used as follows
Copy file name to clipboardExpand all lines: docs/source/quickstart.rst
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,10 +29,8 @@ For more details on docker setup, please refer to `docker readme <https://github
29
29
30
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>`_.
31
31
32
-
- For MacOS, please refer to `TC on Mac <contribs/development_Mac.html>`_.
33
-
34
-
Overall, the installation of TensorCircuit is simple, since it is purely in Python and hence very portable.
35
-
As long as the users can take care of the installation of ML frameworks on the corresponding system, TensorCircuit will work as expected.
32
+
Overall, the installation of TensorCircuit-NG is simple, since it is purely in Python and hence very portable.
33
+
As long as the users can take care of the installation of ML frameworks on the corresponding system, TensorCircuit-NG will work as expected.
36
34
37
35
To debug the installation issue or report bugs, please check the environment information by ``tc.about()``.
0 commit comments