forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperation.qs
96 lines (73 loc) · 4.43 KB
/
Operation.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Chemistry.Samples {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Research.Chemistry;
open Microsoft.Quantum.Chemistry.JordanWigner;
open Microsoft.Quantum.Characterization;
open Microsoft.Quantum.Simulation;
//////////////////////////////////////////////////////////////////////////
// Using Trotterization //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// # Summary
/// We can now use Canon's phase estimation algorithms to
/// learn the ground state energy using the above simulation.
operation TrotterEstimateEnergy (qSharpData: JordanWignerEncodingData, nBitsPrecision : Int, trotterStepSize : Double) : (Double, Double) {
let (nSpinOrbitals, data, statePrepData, energyShift) = qSharpData!;
// Order of integrator
let trotterOrder = 1;
let (nQubits, (rescaleFactor, oracle)) = TrotterStepOracle(qSharpData, trotterStepSize, trotterOrder);
// Prepare ProductState
let statePrep = PrepareTrialState(statePrepData, _);
let phaseEstAlgorithm = RobustPhaseEstimation(nBitsPrecision, _, _);
let estPhase = EstimateEnergy(nQubits, statePrep, oracle, phaseEstAlgorithm);
let estEnergy = estPhase * rescaleFactor + energyShift;
return (estPhase, estEnergy);
}
//////////////////////////////////////////////////////////////////////////
// Using optimized Trotterization circuit ////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// # Summary
/// We can now use Canon's phase estimation algorithms to
/// learn the ground state energy using the above simulation.
operation OptimizedTrotterEstimateEnergy (qSharpData: JordanWignerEncodingData, nBitsPrecision : Int, trotterStepSize : Double) : (Double, Double) {
let (nSpinOrbitals, data, statePrepData, energyShift) = qSharpData!;
// Order of integrator
let trotterOrder = 1;
let (nQubits, (rescaleFactor, oracle)) = OptimizedTrotterStepOracle(qSharpData, trotterStepSize, trotterOrder);
// Prepare ProductState
let statePrep = PrepareTrialState(statePrepData, _);
let phaseEstAlgorithm = RobustPhaseEstimation(nBitsPrecision, _, _);
let estPhase = EstimateEnergy(nQubits, statePrep, oracle, phaseEstAlgorithm);
let estEnergy = estPhase * rescaleFactor + energyShift;
return (estPhase, estEnergy);
}
//////////////////////////////////////////////////////////////////////////
// Using Qubitization ////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// # Summary
// Instead of implementing real-time evolution e^{iHt} with a Product formula,
// we may encode e^{isin^{-1}{H}} in a quantum walk created using
// the `Qubitization` procedure.
/// # Summary
/// We can now use Canon's phase estimation algorithms to
/// learn the ground state energy using the above simulation.
operation QubitizationEstimateEnergy (qSharpData: JordanWignerEncodingData, nBitsPrecision : Int) : (Double, Double) {
let (nSpinOrbitals, data, statePrepData, energyShift) = qSharpData!;
let (nQubits, (l1Norm, oracle)) = QubitizationOracle(qSharpData);
let statePrep = PrepareTrialState(statePrepData, _);
let phaseEstAlgorithm = RobustPhaseEstimation(nBitsPrecision, _, _);
let estPhase = EstimateEnergy(nQubits, statePrep, oracle, phaseEstAlgorithm);
// Note that the quantum walk applies e^{isin^{-1}{H/oneNorm}}, in contrast to
// real-time evolution e^{iHt} by a Product formula.
// Thus We obtain the energy estimate by applying Sin(.) to the phase estimate
// then rescaling by the coefficient one-norm of the Hamiltonian.
// We also add the constant energy offset to the estimated energy.
let estEnergy = Sin(estPhase) * l1Norm + energyShift;
// We return both the estimated phase, and the estimated energy.
return (estPhase, estEnergy);
}
}