Код: Выделить всё
import numpy as np
import matplotlib.pyplot as plt
from qutip import sigmax, sigmaz, qeye, tensor, Qobj, entropy_vn
def hamiltonian(N, lambd):
sx = sigmax()
sz = sigmaz()
si = qeye(2)
H = 0
for i in range(N):
H -= lambd * tensor([sx if j == i or j == (i+1)%N else si for j in range(N)])
H -= tensor([sz if j == i else si for j in range(N)])
return H
def reduced_density_matrix(psi, N):
rho = psi.ptrace(0) # Partial trace to get the reduced density matrix
return rho
def von_neumann_entropy(N, lambd):
H = hamiltonian(N, lambd)
eigvals, eigvecs = H.eigenstates()
ground_state = eigvecs[0]
rho_i = reduced_density_matrix(ground_state, N)
S_vn = entropy_vn(rho_i) # Compute the von Neumann entropy
return S_vn
# Plotting the von Neumann entropy for various values of N
Ns = range(2, 16) # Values of N from 2 to 15
lambd = 1.0 # Transverse field strength
entropies = []
for N in Ns:
S_vn = von_neumann_entropy(N, lambd)
entropies.append(S_vn)
plt.figure(figsize=(10, 6))
plt.plot(Ns, entropies, marker='o')
plt.xlabel('Number of Spins (N)')
plt.ylabel('Von Neumann Entropy')
plt.title('Von Neumann Entropy vs. Number of Spins for Transverse Field Ising Model')
plt.grid(True)
plt.show()
Код: Выделить всё
H.eigenstates(eigvals=1, sparse=True)
Подробнее здесь: https://stackoverflow.com/questions/788 ... sing-model