microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.18.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/algorithms/Ising/Simple1dIsingOrder1.qs

79lines · modeblame

3f3bde67DmitryVasilevsky1 years ago1/// # Sample
2/// Simulation of a simple Ising model evolution
3/// on a 1D grid with first-order Trotterization.
4///
5/// # Description
6/// This sample demonstrates simulation of an Ising model Hamiltonian
7/// on 1D grid of size N using a first-order Trotter-Suzuki approximation.
8/// This sample can be easily simulated classically with the grid of size 9
9/// and 1000 shots. This sample is suitable for Base Profile.
10/// For the purpose of simplicity this sample intentionally doesn't
11/// post-process results or perform eigenvalue estimation.
12operation Main() : Result[] {
13// The size of a 1D grid is N
14let N : Int = 9;
15
16// Total evolution time
17let evolutionTime : Double = 4.0;
18// Number of steps
19let numberOfSteps : Int = 7;
20
21// Coefficient for 2-qubit interactions between neighboring qubits
22let J : Double = 1.0;
23// Coefficient for external field interaction for individual qubits
24let g : Double = 0.7;
25
26IsingModel1DEvolution(N, J, g, evolutionTime, numberOfSteps)
27}
28
29/// # Summary
30/// Simulate simple Ising model evolution
31///
32/// # Description
33/// Simulates state |𝜓⟩ evolution to find |𝜓(t)⟩=U(t)|𝜓(0)⟩.
34/// |𝜓(0)⟩ is taken to be |0...0⟩.
35/// U(t)=e⁻ⁱᴴᵗ, where H is an Ising model Hamiltonian H = -J·Σ'ᵢⱼZᵢZⱼ + g·ΣᵢXᵢ
36/// Here Σ' is taken over all pairs of neighboring qubits <i,j>.
37/// Simulation is done by performing K steps assuming U(t)≈(U(t/K))ᴷ.
38operation IsingModel1DEvolution(
39N : Int,
40J : Double,
41g : Double,
42evolutionTime : Double,
43numberOfSteps : Int
44) : Result[] {
45
46// Allocate qubit grid
47use qubits = Qubit[N];
48
71ade5dcDmitryVasilevsky1 years ago49// Compute the time step
50let dt : Double = evolutionTime / Std.Convert.IntAsDouble(numberOfSteps);
3f3bde67DmitryVasilevsky1 years ago51
71ade5dcDmitryVasilevsky1 years ago52let theta_x = - g * dt;
53let theta_zz = J * dt;
3f3bde67DmitryVasilevsky1 years ago54
55// Perform K steps
56for i in 1..numberOfSteps {
57
58// Single-qubit interaction with external field
59for q in qubits {
60Rx(2.0 * theta_x, q);
61}
62
63// All of the following Rzz gates commute. So we apply them between "even"
64// pairs first and then between "odd" pairs to reduce the algorithm depth.
65
66// Interactions between "even" pairs
71ade5dcDmitryVasilevsky1 years ago67for j in 0..2..N-2 {
68Rzz(2.0 * theta_zz, qubits[j], qubits[j + 1]);
3f3bde67DmitryVasilevsky1 years ago69}
70
71// Interactions between "odd" pairs
71ade5dcDmitryVasilevsky1 years ago72for j in 1..2..N-2 {
73Rzz(2.0 * theta_zz, qubits[j], qubits[j + 1]);
3f3bde67DmitryVasilevsky1 years ago74}
75
76}
77
78MResetEachZ(qubits)
79}