-
Notifications
You must be signed in to change notification settings - Fork 17
/
QromTest.qs
62 lines (54 loc) · 2.28 KB
/
QromTest.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
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 for single-bit data
@Test("QuantumSimulator")
operation QROMOracleSingleBitSingleLookupMatchResults() : Unit {
let data = SingleBitData();
for i in 0..7 {
CreateQueryMeasureOneAddressQROM(data, i);
}
}
// Basic lookup with all addresses checked for multi-bit data
@Test("QuantumSimulator")
operation QROMOracleMultiBitSingleLookupMatchResults() : Unit {
let data = MultiBitData();
for i in 0..7 {
CreateQueryMeasureOneAddressQROM(data, i);
}
}
internal operation CreateQueryMeasureOneAddressQROM(
data : MemoryBank,
queryAddress : Int
)
: Unit {
// Get the data value you expect to find at queryAddress
let expectedValue = DataAtAddress(data, queryAddress);
// Setup the var to hold the result of the measurement
mutable result = new Bool[0];
// Create the new Qrom oracle
let memory = QromOracle(data::DataSet);
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[].
set 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}.");
}
}