Uh oh!
There was an error while loading. Please reload this page.
forked from microsoft/Quantum
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
72 lines (57 loc) · 2.89 KB
/
Copy pathProgram.cs
File metadata and controls
72 lines (57 loc) · 2.89 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingMicrosoft.Quantum.Simulation.Core;
usingMicrosoft.Quantum.Simulation.Simulators;
namespaceMicrosoft.Quantum.Samples.H2Simulation
{
classProgram
{
staticvoidMain(string[]args)
{
// We begin by making an instance of the simulator that we will use to run our Q# code.
using(varqsim=newQuantumSimulator()){
#region Basic Definitions
// Next, we give C# names to each operation defined in Q#.
// In doing so, we ask the simulator to give us each operation
// so that it has an opportunity to override operation definitions.
varH2EstimateEnergyRPE=qsim.Get<H2EstimateEnergyRPE,H2EstimateEnergyRPE>();
varH2BondLengths=qsim.Get<H2BondLengths,H2BondLengths>();
#endregion
#region Calling into Q#
// To call a Q# operation that takes unit `()` as its input, we need to grab
// the QVoid.Instance value.
varbondLengths=H2BondLengths.Body.Invoke(QVoid.Instance);
// In Q#, we defined the operation that performs the actual estimation;
// we can call it here, giving a structure tuple that corresponds to the
// C# ValueTuple that it takes as its input. Since the Q# operation
// has type (idxBondLength : Int, nBitsPrecision : Int, trotterStepSize : Double) => (Double),
// we pass the index along with that we want six bits of precision and
// step size of 1.
//
// The result of calling H2EstimateEnergyRPE is a Double, so we can minimize over
// that to deal with the possibility that we accidently entered into the excited
// state instead of the ground state of interest.
Func<int,Double>estAtBondLength=(idx)=>Enumerable.Min(
fromidxRepinEnumerable.Range(0,3)
selectH2EstimateEnergyRPE.Body.Invoke((idx,6,1.0))
);
// We are now equipped to run the Q# simulation at each bond length
// and print the answers out to the console.
foreach(varidxBondinEnumerable.Range(0,54))
{
System.Console.WriteLine($"Estimating at bond length {bondLengths[idxBond]}:");
varest=estAtBondLength(idxBond);
System.Console.WriteLine($"\tEst: {est}\n");
}
#endregion
}
Console.WriteLine("Press Enter to continue...");
Console.ReadLine();
}
}
}