-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscratch.py
81 lines (68 loc) · 2.64 KB
/
scratch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import unittest
import numpy as np
from xmps.spin import spins
from xmps.iMPS import iMPS
from scipy.linalg import expm
from qmps.represent import FullStateTensor, FullEnvironment
from qmps.tools import environment_to_unitary, tensor_to_unitary, unitary_to_tensor
from qmps.time_evolve import MPSTimeEvolve
import matplotlib.pyplot as plt
from xmps.spin import U4
import cirq
Sx, Sy, Sz = spins(0.5)
Sx, Sy, Sz = 2*Sx, 2*Sy, 2*Sz
As = [iMPS().random(2, 2).mixed() for _ in range(3)]
def test_time_evolve():
for AL, AR, C in [As[0]]:
J, g = -1, 0.5
H = np.array([[J, g / 2, g / 2, 0],
[g / 2, -J, 0, g / 2],
[g / 2, 0, -J, g / 2],
[0, g / 2, g / 2, J]])
T = np.linspace(0, 0.1, 100)
dt = T[1] - T[0]
evs = []
es = []
################ CIRQ BIT ######################
counter = 0
bloch_sphere_results = []
U = FullStateTensor(tensor_to_unitary(AL.data[0]))
V = FullEnvironment(environment_to_unitary(C))
hamiltonian = FullStateTensor(expm(-1j * H * dt))
# hamiltonian = FullStateTensor(np.identity(4))
# hamiltonian = FullStateTensor(expm(-1j * H * dt))
evolver = MPSTimeEvolve(u_initial=U, hamiltonian=hamiltonian, v_initial=V, settings={
'method': 'Powell',
'maxiter': 100,
'verbose': True
})
# initial classical value
A = AL
evs.append(iMPS([A.data[0]]).Es([Sx, Sy, Sz]))
# initial unitary value
results, qubits = evolver.simulate_state()
bloch_sphere = results.bloch_vector_of(qubits[1])
bloch_sphere_results.append(bloch_sphere)
for _ in T:
print(counter)
dA = A.dA_dt([H]) * dt
es.append(A.e)
A = (A + dA).left_canonicalise()
evs.append(A.Es([Sx, Sy, Sz]))
'''
Below is the cirq time evolution. Gate is made using scipy.expm(H) * dt which is put into a Tensor, and
and this is the hamiltonian.
'''
evolver.evolve_single_step()
results, qubits = evolver.simulate_state()
bloch_sphere = results.bloch_vector_of(qubits[1])
bloch_sphere_results.append(bloch_sphere)
counter += 1
fig, ax = plt.subplots(2, 1, sharex=True, sharey=True)
ax[0].plot(np.array(evs), c='r')
ax[0].plot(np.array(bloch_sphere_results), c='b')
ax[1].plot(es)
plt.show()
fig.savefig('longTimeEvo2.png')
return np.array(evs), np.array(bloch_sphere_results)
analytic, unitary = test_time_evolve()