|
| 1 | +.. _IsingModel: |
| 2 | + |
| 3 | +Transverse Field Ising Model |
| 4 | +============================ |
| 5 | + |
| 6 | +.. currentmodule:: qrisp |
| 7 | + |
| 8 | +In this example, we study Hamiltonian dynamics of the transverse field Ising model defined by the Hamiltonian |
| 9 | + |
| 10 | +$$H = -J\\sum_{(i,j)\\in E}Z_iZ_j + B\\sum_{i\\in V}X_i$$ |
| 11 | + |
| 12 | +for a lattice graph $G=(V,E)$ and real parameters $J, B$. We investigate the total magnetization of the system as it evolves under the Hamiltonian. |
| 13 | + |
| 14 | +Here, we consider an Ising chain. |
| 15 | + |
| 16 | +:: |
| 17 | + |
| 18 | + import matplotlib.pyplot as plt |
| 19 | + import networkx as nx |
| 20 | + import numpy as np |
| 21 | + |
| 22 | + def generate_chain_graph(N): |
| 23 | + coupling_list = [[k,k+1] for k in range(N-1)] |
| 24 | + G = nx.Graph() |
| 25 | + G.add_edges_from(coupling_list) |
| 26 | + return G |
| 27 | + |
| 28 | + G = generate_chain_graph(6) |
| 29 | + |
| 30 | +We implement methods for creating the Ising Hamiltonian and the total magnetization observable for a given graph. |
| 31 | + |
| 32 | +:: |
| 33 | + |
| 34 | + from qrisp import QuantumVariable |
| 35 | + from qrisp.operators.pauli import X, Y, Z |
| 36 | + |
| 37 | + def create_ising_hamiltonian(G, J, B): |
| 38 | + H = sum(-J*Z(i)*Z(j) for (i,j) in G.edges()) + sum(B*X(i) for i in G.nodes()) |
| 39 | + return H |
| 40 | + |
| 41 | + def create_magnetization(G): |
| 42 | + H = (1/G.number_of_nodes())*sum(Z(i) for i in G.nodes()) |
| 43 | + return H |
| 44 | + |
| 45 | +With all the necessary ingredients, we conduct the experiment: For varying evolution times $T$: |
| 46 | + |
| 47 | +- Prepare the $\ket{0}^{\otimes N}$ state. |
| 48 | + |
| 49 | +- Perform **Hamiltonian simulation** via Trotterization. |
| 50 | + |
| 51 | +- Measure the total magnetization. |
| 52 | + |
| 53 | +:: |
| 54 | + |
| 55 | + T_values = np.arange(0, 2.0, 0.05) |
| 56 | + M_values = [] |
| 57 | + |
| 58 | + M = create_magnetization(G) |
| 59 | + |
| 60 | + for T in T_values: |
| 61 | + H = create_ising_hamiltonian(G,1.0,1.0) |
| 62 | + U = H.trotterization() |
| 63 | + |
| 64 | + qv = QuantumVariable(G.number_of_nodes()) |
| 65 | + U(qv,t=-T,steps=5) |
| 66 | + M_values.append(M.get_measurement(qv,precision=0.005)) |
| 67 | + |
| 68 | +Finally, we visualize the results. As expected, the total magnetization decreases in the presence of a transverse field with increasing evolution time $T$. |
| 69 | + |
| 70 | +:: |
| 71 | + |
| 72 | + import matplotlib.pyplot as plt |
| 73 | + plt.scatter(T_values, M_values, color='#6929C4', marker="o", linestyle='solid', s=10, label='Magnetization') |
| 74 | + plt.xlabel("Time", fontsize=15, color="#444444") |
| 75 | + plt.ylabel("Magnetization", fontsize=15, color="#444444") |
| 76 | + plt.legend(fontsize=12, labelcolor="#444444") |
| 77 | + plt.tick_params(axis='both', labelsize=12) |
| 78 | + plt.grid() |
| 79 | + plt.show() |
| 80 | + |
| 81 | +.. figure:: /_static/Ising_chain_N=6.png |
| 82 | + :alt: Ising chain |
| 83 | + :align: center |
| 84 | + |
0 commit comments