-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCommonTest.qs
69 lines (58 loc) · 2.56 KB
/
CommonTest.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
namespace Tests {
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Logical;
open Microsoft.Quantum.Random;
open QsharpCommunity.Qram;
// Hardcoded data set
internal function SingleBitData() : MemoryBank {
let data = [(5, [true]), (4, [true]), (1, [false]), (2, [false])];
return GeneratedMemoryBank(Mapped(MemoryCell, data));
}
// Hardcoded data set for a multi-bit output situation
internal function MultiBitData() : MemoryBank {
let numDataBits = 3;
let data = [
(5, IntAsBoolArray(3, numDataBits)),
(4, IntAsBoolArray(2, numDataBits)),
(0, IntAsBoolArray(0, numDataBits)),
(2, IntAsBoolArray(5, numDataBits))];
return GeneratedMemoryBank(Mapped(MemoryCell, data));
}
// TODO: parameterize data values as w
// QRAM where every memory cell contains a 0
internal function EmptyQRAM(addressSize : Int) : MemoryBank {
let addresses = SequenceI(0, 2^addressSize - 1);
let data = ConstantArray(2^addressSize, [false]);
return GeneratedMemoryBank(Mapped(MemoryCell,Zipped(addresses, data)));
}
// QRAM where every memory cell contains a 1
internal function FullQRAM(addressSize : Int) : MemoryBank {
let addresses = SequenceI(0, 2^addressSize - 1);
let data = ConstantArray(2^addressSize, [true]);
return GeneratedMemoryBank(Mapped(MemoryCell,Zipped(addresses, data)));
}
// QRAM where only the first memory cell contains a 1
internal function FirstCellFullQRAM() : MemoryBank {
return GeneratedMemoryBank([MemoryCell(0, [true])]);
}
// QRAM where only the second memory cell contains a 1
internal function SecondCellFullQRAM() : MemoryBank {
return GeneratedMemoryBank([MemoryCell(1, [true])]);
}
// QRAM where only the last memory cell contains a 1
internal function LastCellFullQRAM(addressSize : Int) : MemoryBank {
return GeneratedMemoryBank([MemoryCell(2^addressSize - 1, [true])]);
}
internal operation PrepareIntAddressRegister(address : Int, register : Qubit[])
: Unit is Adj + Ctl {
let queryAddressAsBoolArray = IntAsBoolArray(address, Length(register));
ApplyPauliFromBitString(PauliX, true, queryAddressAsBoolArray, register);
}
}