This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.qs
96 lines (91 loc) · 3.12 KB
/
test.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
namespace Final_Project
{
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Extensions.Diagnostics;
open Microsoft.Quantum.Extensions.Convert;
/// # Summary
/// Tests for all adders, comparators, and rotations
///
/// # Example
/// ```Q#
/// tests();
/// ```
operation tests () : Unit {
thorough_adder_test(4);
thorough_comp_test(4);
test_rzk();
}
/// # Summary
/// Tests Rz_k gate on single qubit for some rotation
///
/// # Example
/// ```Q#
/// test_rzk();
/// ```
operation test_rzk() : Unit {
using (A = Qubit()) {
X(A); // set A = 1 (or some value)
Rzk(A, 1.0); // rotate A by R1
DumpRegister("tests/rzk_test.txt", [A]);
Reset(A);
}
}
/// # Summary
/// Tests all possible additions for n-bit adder
///
/// # Example
/// ```Q#
/// thorough_adder_test(4);
/// ```
operation thorough_adder_test (n : Int) : Unit {
let N = PowI(2, n);
using (A = Qubit[n]) {
using (B = Qubit[n]) {
for (i in 0..N-1) {
for (j in 0..N-1) {
IntegerIncrementLE(i, BigEndianToLittleEndian(BigEndian(A))); // set A = i
IntegerIncrementLE(j, BigEndianToLittleEndian(BigEndian(B))); // set B = j
efficient_adder(A, B);
let r = ToStringI(MeasureIntegerBE(BigEndian(A))); // prints A+B
let b = ToStringI(MeasureIntegerBE(BigEndian(B))); // prints B
let a = ToStringI(i); // prints i (should be what A was)
Message(a + " + " + b + " = " + r);
ResetAll(A);
ResetAll(B);
}
}
}
}
}
/// # Summary
/// Tests all possible combinations for n-bit comparator
///
/// # Example
/// ```Q#
/// thorough_comp_test(4);
/// ```
operation thorough_comp_test (n : Int) : Unit {
let N = PowI(2, n);
using (A = Qubit[n]) {
using (B = Qubit[n]) {
using (c = Qubit()) {
for (i in 0..N-1) {
for (j in 0..N-1) {
IntegerIncrementLE(i, BigEndianToLittleEndian(BigEndian(A))); // set A = i
IntegerIncrementLE(j, BigEndianToLittleEndian(BigEndian(B))); // set B = j
efficient_TC_comparator(A, B, c);
let r = ToStringB((M(c) == One)); // prints if A > B
let b = ToStringI(MeasureIntegerBE(BigEndian(B))); // prints B
let a = ToStringI(MeasureIntegerBE(BigEndian(A))); // prints A
Message(a + " > " + b + " is " + r);
ResetAll(A);
ResetAll(B);
Reset(c);
}
}
}
}
}
}
}