forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHubbardSimulation.qs
44 lines (34 loc) · 1.85 KB
/
HubbardSimulation.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Chemistry.Samples.Hubbard {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Characterization;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Chemistry.JordanWigner;
open Microsoft.Quantum.Simulation;
//////////////////////////////////////////////////////////////////////////
// Using Trotterization //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// # Summary
/// We define an initial state of the Hamiltonian here.
operation HubbardHalfFillingStatePrep (nFilling : Int, qubits : Qubit[]) : Unit {
ApplyToEachCA(X, qubits[0..(nFilling / 2 - 1)]);
}
/// # Summary
/// We can now use Canon's phase estimation algorithms to
/// learn the ground state energy using the above simulation.
operation GetEnergy (qSharpData : JordanWignerEncodingData, nBitsPrecision : Int, trotterStepSize : Double) : (Double, Double) {
let (nSpinOrbitals, data, notUsedInThisSample, energyShift) = qSharpData!;
// We use a Product formula, also known as `Trotterization` to
// simulate the Hamiltonian.
let trotterOrder = 1;
let (nQubits, (rescaleFactor, oracle)) = TrotterStepOracle(qSharpData, trotterStepSize, trotterOrder);
let statePrep = HubbardHalfFillingStatePrep(nQubits, _);
let phaseEstAlgorithm = RobustPhaseEstimation(nBitsPrecision, _, _);
let estPhase = EstimateEnergy(nQubits, statePrep, oracle, phaseEstAlgorithm);
let estEnergy = estPhase / trotterStepSize + energyShift;
return (estPhase, estEnergy);
}
}