forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperation.qs
84 lines (63 loc) · 3.15 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
// 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.Chemistry.JordanWigner;
//////////////////////////////////////////////////////////////////////////
// Using Trotterization //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// # Summary
/// This allocates qubits and applies a single Trotter step.
operation RunTrotterStep (qSharpData: JordanWignerEncodingData) : Unit {
// The data describing the Hamiltonian for all these steps is contained in
// `qSharpData`
// We use a Product formula, also known as `Trotterization` to
// simulate the Hamiltonian.
// The integrator step size does not affect the gate cost of a single step.
let trotterStepSize = 1.0;
// Order of integrator
let trotterOrder = 1;
let (nQubits, (rescaleFactor, oracle)) = TrotterStepOracle(qSharpData, trotterStepSize, trotterOrder);
// We not allocate qubits an run a single step.
using (qubits = Qubit[nQubits]) {
oracle(qubits);
ResetAll(qubits);
}
}
//////////////////////////////////////////////////////////////////////////
// Using Qubitization ////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// # Summary
/// This allocates qubits and applies a single qubitization step.
operation RunQubitizationStep (qSharpData: JordanWignerEncodingData) : Double {
// The data describing the Hamiltonian for all these steps is contained in
// `qSharpData`
let (nQubits, (l1Norm, oracle)) = QubitizationOracle(qSharpData);
// We now allocate qubits and run a single step.
using (qubits = Qubit[nQubits]) {
oracle(qubits);
ResetAll(qubits);
}
return l1Norm;
}
//////////////////////////////////////////////////////////////////////////
// Using T-count optimized Qubitization //////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// # Summary
/// We can now use Canon's phase estimation algorithms to
/// learn the ground state energy using the above simulation.
operation RunOptimizedQubitizationStep (qSharpData: JordanWignerEncodingData, targetError : Double) : Double {
// The data describing the Hamiltonian for all these steps is contained in
// `qSharpData`
let (nQubits, (l1Norm, oracle)) = OptimizedQubitizationOracle(qSharpData, targetError);
// We now allocate qubits and run a single step.
using (qubits = Qubit[nQubits]) {
oracle(qubits);
ResetAll(qubits);
}
return l1Norm;
}
}