-
Notifications
You must be signed in to change notification settings - Fork 17
/
SelectSwapTest.qs
68 lines (59 loc) · 2.52 KB
/
SelectSwapTest.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
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 QsharpCommunity.Qram;
// Basic lookup with all addresses checked, all valid tradeoff parameters tested
// for single-bit data.
@Test("QuantumSimulator")
operation SelectSwapOracleSingleBitSingleLookupMatchResults() : Unit {
let data = SingleBitData();
for i in 0..2^data::AddressSize-1 {
for t in 1..data::AddressSize {
CreateQueryMeasureOneAddressSelectSwap(data, i, t);
}
}
}
// Basic lookup with all addresses checked, all valid tradeoff parameters tested
// for multi-bit data.
@Test("QuantumSimulator")
operation SelectSwapOracleMultiBitSingleLookupMatchResults() : Unit {
let data = MultiBitData();
for i in 0..2^data::AddressSize-1 {
for t in 1..data::AddressSize {
CreateQueryMeasureOneAddressSelectSwap(data, i, t);
}
}
}
internal operation CreateQueryMeasureOneAddressSelectSwap(
data : MemoryBank,
queryAddress : Int,
tradeoffParameter : Int
)
: Unit {
// Get the data value you expect to find at queryAddress
let expectedValue = DataAtAddress(data, queryAddress);
// Create the new Qrom oracle
let memory = SelectSwapQromOracle(data::DataSet, tradeoffParameter);
use (addressRegister, targetRegister) =
(Qubit[memory::AddressSize], Qubit[memory::DataSize]);
// Convert the address Int to a Bool[]
let queryAddressAsBool = IntAsBoolArray(queryAddress, BitSizeI(queryAddress));
// Prepare the address register
ApplyPauliFromBitString (PauliX, true, queryAddressAsBool, addressRegister);
// Perform the lookup
memory::Read(LittleEndian(addressRegister), targetRegister);
// Get results and make sure its the same format as the data provided i.e. Bool[].
let result = ResultArrayAsBoolArray(MultiM(targetRegister));
// Reset all the qubits before returning them
ResetAll(addressRegister+targetRegister);
AllEqualityFactB(result, expectedValue,
$"Expecting value {expectedValue} at address {queryAddress}, got {result}.");
}
}