forked from microsoft/QuantumKatas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.qs
70 lines (57 loc) · 2.31 KB
/
Tests.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
//////////////////////////////////////////////////////////////////////
// This file contains testing harness for all tasks.
// You should not modify anything in this file.
//////////////////////////////////////////////////////////////////////
namespace Quantum.Kata.MultiQubitGates {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
@Test("QuantumSimulator")
operation T1_CompoundGate () : Unit {
AssertOperationsEqualReferenced(3, CompoundGate, CompoundGate_Reference);
}
operation AssertEqualOnZeroState (testImpl : (Qubit[] => Unit), refImpl : (Qubit[] => Unit is Adj)) : Unit {
use qs = Qubit[2];
// apply operation that needs to be tested
testImpl(qs);
// apply adjoint reference operation
Adjoint refImpl(qs);
// assert that all qubits end up in |0⟩ state
AssertAllZero(qs);
}
@Test("QuantumSimulator")
operation T2_BellState () : Unit {
AssertEqualOnZeroState(BellState, BellState_Reference);
}
@Test("QuantumSimulator")
operation T3_QubitSwap () : Unit {
for N in 2 .. 5 {
for j in 0 .. N-2 {
for k in j+1 .. N-1 {
AssertOperationsEqualReferenced(N, QubitSwap(_, j, k), QubitSwap_Reference(_, j, k));
}
}
}
}
@Test("QuantumSimulator")
operation T4_ControlledRotation () : Unit {
for i in 0 .. 20 {
let angle = IntAsDouble(i) / 10.0;
AssertOperationsEqualReferenced(2, ControlledRotation(_, angle), ControlledRotation_Reference(_,angle));
}
}
operation ArrayControlledOperationWrapper (op : ((Qubit[], Qubit) => Unit is Adj), qs : Qubit[]) : Unit is Adj {
op(Most(qs), Tail(qs));
}
@Test("QuantumSimulator")
operation T5_MultiControls () : Unit {
for i in 0 .. (2 ^ 4) - 1 {
let bits = IntAsBoolArray(i, 4);
AssertOperationsEqualReferenced(5, ArrayControlledOperationWrapper(MultiControls(_, _, bits), _), ArrayControlledOperationWrapper(MultiControls_Reference(_, _, bits), _));
}
}
}