This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathProgram.qs
77 lines (65 loc) · 3.16 KB
/
Program.qs
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Samples.Ising {
open Microsoft.Quantum.Intrinsic;
@EntryPoint()
operation RunGenerators() : Unit {
// Let us represent an Ising Hamiltonian with uniform single-site X coupling, uniform
// two-site nearest neighbour ZZ coupling, and open boundary conditions.
let nSites = 7;
// Here we choose the coefficients of the coupling terms.
let hAmplitude = 1.23;
let jAmplitude = 4.56;
RunIsingGenerator(nSites, hAmplitude, jAmplitude);
RunHeisenbergGenerator(nSites, hAmplitude, jAmplitude);
}
internal operation RunIsingGenerator(nSites : Int, hAmplitude : Double, jAmplitude : Double) : Unit {
// For diagnostic purposes, before we proceed to the next step, we'll print out a
// description of the parameters for the Ising model generator.
Message(
"Ising model generators:\n" +
$"\t{nSites} sites\n" +
$"\t{hAmplitude} transverse field amplitude\n" +
$"\t{jAmplitude} coupling amplitude.\n"
);
// The number of terms in this Hamiltonian is as follows.
let nTerms = nSites * 2;
// Let us print out the terms specified by the Ising model generator system to verify that
// they match expectations. Let us recall that the Paulis IXYZ are represented by integers
// 0123.
for idxHamiltonian in 0 .. nTerms - 1 {
let generatorIndex = Uniform1DIsingGeneratorIndex(nSites, hAmplitude, jAmplitude, idxHamiltonian);
let ((idxPauliString, coefficients), idxQubits) = generatorIndex!;
Message(
$"idxHamiltonian {idxHamiltonian} " +
$"has Pauli string {idxPauliString} " +
$"acting on qubits {idxQubits} " +
$"with coefficient {coefficients[0]}."
);
}
}
internal operation RunHeisenbergGenerator(nSites : Int, hAmplitude : Double, jAmplitude : Double) : Unit {
// For diagnostic purposes, before we proceed to the next step, we'll print out a
// description of the parameters for the Heisenberg model generator.
Message(
"\nHeisenberg model generators:\n" +
$"\t{nSites} sites\n" +
$"\t{hAmplitude} transverse field amplitude\n" +
$"\t{jAmplitude} coupling amplitude.\n"
);
// The number of terms in this Hamiltonian is as follows.
let nTerms = nSites * 4;
// Let us print out the terms specified by the Heisenberg Model generator system to verify
// that they match expectations.
for idxHamiltonian in 0 .. nTerms - 1 {
let generatorIndex = HeisenbergXXZGeneratorIndex(nSites, hAmplitude, jAmplitude, idxHamiltonian);
let ((idxPauliString, coefficients), idxQubits) = generatorIndex!;
Message(
$"idxHamiltonian {idxHamiltonian} " +
$"has Pauli string {idxPauliString} " +
$"acting on qubits {idxQubits} " +
$"with coefficient {coefficients[0]}."
);
}
}
}