Skip to content

Commit 0d84ddd

Browse files
committed
Time evolution realized by Trotter decomposition
1 parent a0f1a09 commit 0d84ddd

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

examples/timeevolution_trotter.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Time evolution of Heisenberg model realized by Trotter decomposition
3+
"""
4+
5+
import numpy as np
6+
import tensorcircuit as tc
7+
8+
K = tc.set_backend("tensorflow")
9+
tc.set_dtype("complex128")
10+
11+
xx = tc.gates._xx_matrix
12+
yy = tc.gates._yy_matrix
13+
zz = tc.gates._zz_matrix
14+
15+
nqubit = 4
16+
t = 1.0
17+
tau = 0.1
18+
19+
20+
def Trotter_step_unitary(input_state, tau, nqubit):
21+
c = tc.Circuit(nqubit, inputs=input_state)
22+
for i in range(nqubit - 1): ### U_zz
23+
c.exp1(i, i + 1, theta=tau, unitary=zz)
24+
for i in range(nqubit - 1): ### U_yy
25+
c.exp1(i, i + 1, theta=tau, unitary=yy)
26+
for i in range(nqubit - 1): ### U_xx
27+
c.exp1(i, i + 1, theta=tau, unitary=xx)
28+
TSUstate = c.state() ### return state U(τ)|ψ_i>
29+
z0 = c.expectation_ps(z=[0])
30+
return TSUstate, z0
31+
32+
33+
TSU_vmap = tc.backend.jit(
34+
tc.backend.vmap(
35+
Trotter_step_unitary,
36+
vectorized_argnums=0,
37+
)
38+
)
39+
40+
ninput = 2
41+
input_state = np.zeros((ninput, 2 ** nqubit))
42+
input_state[0, 0] = 1.0
43+
input_state[1, -1] = 1.0
44+
45+
for _ in range(int(t / tau)):
46+
input_state, z0 = TSU_vmap(input_state, tau, nqubit)
47+
print("z: ", z0)

0 commit comments

Comments
 (0)