forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
129 lines (103 loc) · 5.92 KB
/
Program.cs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
namespace Microsoft.Quantum.Samples.Ising
{
class Program
{
static void Main(string[] args)
{
#region Basic Definitions
// We start by loading the simulator that we will use to run our Q# operations.
var qsim = new QuantumSimulator();
// Each site of the Ising model is simulated using a single qubit.
var nSites = 9;
// In all the following, we use this coefficient for coupling to the transverse
// field.
var hxCoeff = 1.0;
// For now, we also use this coefficient for coupling between sites.
var jCCoeff = 1.0;
// As we are using a Trotter–Suzuki decomposition as our simulation algorithm,
// we will need to pick a timestep for the simulation, and the order of the
// integrator. The optimal timestep needs to be determined empirically, and
// we find that the following choice works well enough.
var trotterStepSize = 0.1;
var trotterOrder = 2;
// Let us now simulate time-evolution by interpolating between the initial
// Hamiltonian with the |+〉 product state as the ground state, and the target
// Hamiltonian. For the uniform Ising model, the ground state of the target
// Hamiltonian should have all spins pointing in the same direction. If we
// interpolate between these Hamiltonians slowly enough, the initial ground
// state will continuously deform into the ground state of the target
// Hamiltonian
// Let us consider the situation where we interpolate between these Hamiltonians
// too quickly.
var adiabaticTime = 0.1;
#endregion
#region Ising model simulations
// For diagnostic purposes, before we proceed to the next step, we'll print
// out a description of the parameters we just defined.
Console.WriteLine("\nIsing model parameters:");
Console.WriteLine(
$"\t{nSites} sites\n" +
$"\t{hxCoeff} transverse field coefficient\n" +
$"\t{jCCoeff} two-site coupling coefficient\n" +
$"\t{adiabaticTime} time-interval of interpolation\n" +
$"\t{trotterStepSize} simulation time step \n" +
$"\t{trotterOrder} order of integrator\n");
Console.WriteLine("Let us consider the results of fast non-adiabatic evolution from the transverse Hamiltonian to the coupling Hamiltonian. Observe that the zeros and one occur almost randomly.");
// We measure each site after this time-dependent simulation, and repeat
// 10 times as the output is probabilistic.
for (int rep = 0; rep < 10; rep++)
{
// We call the Q# operation we wrote in the .qs file and return its results as a C# array.
var data = Ising1DAdiabaticAndMeasureManual.Run(qsim, nSites, hxCoeff, jCCoeff, adiabaticTime, trotterStepSize, trotterOrder).Result.ToArray();
// We now print the results of measurement.
Console.Write($"State: {string.Join(", ", data.Select(x=>x.ToString()).ToArray())} \n");
}
// Let now interpolate between these Hamiltonians more slowly.
adiabaticTime = 10.0;
Console.WriteLine("\nIsing model parameters:");
Console.WriteLine(
$"\t{nSites} sites\n" +
$"\t{hxCoeff} transverse field coefficient\n" +
$"\t{jCCoeff} two-site coupling coefficient\n" +
$"\t{adiabaticTime} time-interval of interpolation\n" +
$"\t{trotterStepSize} simulation time step \n" +
$"\t{trotterOrder} order of integrator\n");
Console.WriteLine("Let us now slow down the evolution. Observe that there is now a stronger correlation in the measurement results on neighbouring sites.");
for (int rep = 0; rep < 10; rep++)
{
var data = Ising1DAdiabaticAndMeasureManual.Run(qsim, nSites, hxCoeff, jCCoeff, adiabaticTime, trotterStepSize, trotterOrder).Result.ToArray();
Console.Write($"State: {string.Join(", ", data.Select(x => x.ToString()).ToArray())} \n");
}
// We may also study anti-ferromagnetic coupling by changing the sign of jCCoeff.
jCCoeff = -1.0;
Console.WriteLine("\nIsing model parameters:");
Console.WriteLine(
$"\t{nSites} sites\n" +
$"\t{hxCoeff} transverse field coefficient\n" +
$"\t{jCCoeff} two-site coupling coefficient\n" +
$"\t{adiabaticTime} time-interval of interpolation\n" +
$"\t{trotterStepSize} simulation time step \n" +
$"\t{trotterOrder} order of integrator\n");
Console.WriteLine("Observe that there is now a strong anti-correlation in the measurement results on neighbouring sites.");
// Let us use this opportunity to test the adiabatic evolution as written using
// more library functions.
for (int rep = 0; rep < 10; rep++)
{
var data = Ising1DAdiabaticAndMeasureBuiltIn.Run(qsim, nSites, hxCoeff, jCCoeff, adiabaticTime, trotterStepSize, trotterOrder).Result.ToArray();
Console.Write($"State: {string.Join(", ", data.Select(x => x.ToString()).ToArray())} \n");
}
Console.WriteLine("Press Enter to continue...");
Console.ReadLine();
#endregion
}
}
}