5
5
JordanWignerClusterOperatorEvolutionSet ,
6
6
JordanWignerClusterOperatorGeneratorSystem ;
7
7
8
- import JordanWigner .Utils .JordanWignerInputState ;
9
8
import Std .Arrays .IndexRange ;
10
9
import Std .Math .Max ;
11
10
import Std .Math .Min ;
11
+
12
+ import JordanWigner .Utils .JordanWignerInputState ;
12
13
import Utils .GeneratorIndex ;
13
14
import Utils .GeneratorSystem ;
14
15
@@ -28,19 +29,20 @@ import Utils.GeneratorSystem;
28
29
///
29
30
/// # Example
30
31
/// ```qsharp
31
- /// let bitString = ComputeJordanWignerBitString(6 , [0,1,2,6 ]) ;
32
- /// // bitString is [false, false, false , true, true, true , false].
32
+ /// let bitString = ComputeJordanWignerBitString(5 , [0, 3 ]) ;
33
+ /// // bitString is [false, true, true, false , false].
33
34
/// ```
34
35
function ComputeJordanWignerBitString (nFermions : Int , idxFermions : Int []) : Bool [] {
35
36
if Length (idxFermions ) % 2 != 0 {
36
37
fail $"ComputeJordanWignerString failed. `idxFermions` must contain an even number of terms." ;
37
38
}
38
39
39
- mutable zString = [ false , size = nFermions ] ;
40
+ mutable zString = Repeated ( false , nFermions ) ;
40
41
for fermionIdx in idxFermions {
41
42
if fermionIdx >= nFermions {
42
43
fail $"ComputeJordanWignerString failed. fermionIdx {fermionIdx} out of range." ;
43
44
}
45
+ // NOTE: This could be optimized
44
46
for idx in 0 .. fermionIdx {
45
47
zString w/= idx <- not zString [idx ];
46
48
}
@@ -67,7 +69,12 @@ function ComputeJordanWignerPauliZString(nFermions : Int, idxFermions : Int[]) :
67
69
68
70
// Identical to `ComputeJordanWignerPauliZString`, except that some
69
71
// specified elements are substituted.
70
- function ComputeJordanWignerPauliString (nFermions : Int , idxFermions : Int [], pauliReplacements : Pauli []) : Pauli [] {
72
+ function ComputeJordanWignerPauliString (
73
+ nFermions : Int ,
74
+ idxFermions : Int [],
75
+ pauliReplacements : Pauli []
76
+ ) : Pauli [] {
77
+
71
78
mutable pauliString = ComputeJordanWignerPauliZString (nFermions , idxFermions );
72
79
73
80
for idx in IndexRange (idxFermions ) {
@@ -89,8 +96,14 @@ function ComputeJordanWignerPauliString(nFermions : Int, idxFermions : Int[], pa
89
96
/// Duration of time-evolution.
90
97
/// ## qubits
91
98
/// Qubits of Hamiltonian.
92
- operation ApplyJordanWignerClusterOperatorPQTerm (term : GeneratorIndex , stepSize : Double , qubits : Qubit []) : Unit is Adj + Ctl {
93
- let ((idxTermType , coeff ), idxFermions ) = term ! ;
99
+ operation ApplyJordanWignerClusterOperatorPQTerm (
100
+ term : GeneratorIndex ,
101
+ stepSize : Double ,
102
+ qubits : Qubit []
103
+ ) : Unit is Adj + Ctl {
104
+
105
+ let (_ , coeff ) = term .Term ;
106
+ let idxFermions = term .Subsystem ;
94
107
let p = idxFermions [0 ];
95
108
let q = idxFermions [1 ];
96
109
if p == q {
@@ -117,8 +130,14 @@ operation ApplyJordanWignerClusterOperatorPQTerm(term : GeneratorIndex, stepSize
117
130
/// Duration of time-evolution.
118
131
/// ## qubits
119
132
/// Qubits of Hamiltonian.
120
- operation ApplyJordanWignerClusterOperatorPQRSTerm (term : GeneratorIndex , stepSize : Double , qubits : Qubit []) : Unit is Adj + Ctl {
121
- let ((idxTermType , coeff ), idxFermions ) = term ! ;
133
+ operation ApplyJordanWignerClusterOperatorPQRSTerm (
134
+ term : GeneratorIndex ,
135
+ stepSize : Double ,
136
+ qubits : Qubit []
137
+ ) : Unit is Adj + Ctl {
138
+
139
+ let (_ , coeff ) = term .Term ;
140
+ let idxFermions = term .Subsystem ;
122
141
let p = idxFermions [0 ];
123
142
let q = idxFermions [1 ];
124
143
let r = idxFermions [2 ];
@@ -146,8 +165,8 @@ function JordanWignerClusterOperatorPQRSTermSigns(indices : Int[]) : (Int[], Dou
146
165
let q = indices [1 ];
147
166
let r = indices [2 ];
148
167
let s = indices [3 ];
149
- mutable sorted = [0 , size = 4 ];
150
- mutable signs = [0.0 , size = 8 ];
168
+ mutable sorted = [0 , 0 , 0 , 0 ];
169
+ mutable signs = [0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ];
151
170
mutable sign = 1.0 ;
152
171
153
172
if (p > q ) {
@@ -199,12 +218,18 @@ function JordanWignerClusterOperatorPQRSTermSigns(indices : Int[]) : (Int[], Dou
199
218
///
200
219
/// # Output
201
220
/// Representation of Hamiltonian as `GeneratorSystem`.
202
- function JordanWignerClusterOperatorGeneratorSystem (data : JordanWignerInputState []) : GeneratorSystem {
203
- new GeneratorSystem { NumEntries = Length (data ), EntryAt = JordanWignerStateAsGeneratorIndex (data , _ ) }
221
+ function JordanWignerClusterOperatorGeneratorSystem (
222
+ data : JordanWignerInputState []
223
+ ) : GeneratorSystem {
224
+ new GeneratorSystem {
225
+ NumEntries = Length (data ),
226
+ EntryAt = JordanWignerStateAsGeneratorIndex (data , _ )
227
+ }
204
228
}
205
229
206
230
function JordanWignerStateAsGeneratorIndex (data : JordanWignerInputState [], idx : Int ) : GeneratorIndex {
207
- let ((real , imaginary ), idxFermions ) = data [idx ]! ;
231
+ let real = data [idx ].Amplitude .Real ;
232
+ let idxFermions = data [idx ].FermionIndices ;
208
233
209
234
if Length (idxFermions ) == 2 {
210
235
// PQ term
@@ -229,8 +254,13 @@ function JordanWignerStateAsGeneratorIndex(data : JordanWignerInputState[], idx
229
254
/// Dummy variable to match signature of simulation algorithms.
230
255
/// ## qubits
231
256
/// Register acted upon by time-evolution operator.
232
- operation JordanWignerClusterOperatorImpl (generatorIndex : GeneratorIndex , stepSize : Double , qubits : Qubit []) : Unit is Adj + Ctl {
233
- let ((idxTermType , idxDoubles ), idxFermions ) = generatorIndex ! ;
257
+ operation JordanWignerClusterOperatorImpl (
258
+ generatorIndex : GeneratorIndex ,
259
+ stepSize : Double ,
260
+ qubits : Qubit []
261
+ ) : Unit is Adj + Ctl {
262
+
263
+ let (idxTermType , _ ) = generatorIndex .Term ;
234
264
let termType = idxTermType [0 ];
235
265
236
266
if termType == 0 {
0 commit comments