This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplyMultiControlledTests.qs
44 lines (36 loc) · 1.84 KB
/
ApplyMultiControlledTests.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Tests {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Extensions.Testing;
/// # Summary
/// Tests multiply controlled not implementation that uses
/// ApplyMultiControlledCA against multiply controlled version of
/// the Microsoft.Quantum.Primitive.X
operation ApplyMultiControlledTest () : () {
body {
let twoQubitOp = CNOT;
// this gives us operation ( controls : Qubit[], targets : Qubit[] ) => ()
// where we expect targets to have length 2
let multiControlledCNOT = Controlled(ApplyToFirstTwoQubitsCA(twoQubitOp,_));
// this gives up operation ( qubits : Qubit[] ) => ()
// where first qubit in qubits is control and the rest are target for
// twoQubitOp
let singlyControlledCNOT = ApplyToPartitionCA(multiControlledCNOT,1,_);
// Construct multiply controlled op using its singly controlled version
// with the help of ApplyMultiControlledCA
let canonMultiNot =
ApplyMultiControlledCA( singlyControlledCNOT, CCNOTop(CCNOT), _, _ );
for( numberOfcontrols in 1 .. 5 )
{
Message($"Checking the equality with {numberOfcontrols} controls");
// construct actual and expected with desired number of controls
let actual = ApplyToPartitionCA(canonMultiNot,numberOfcontrols,_);
let expected = ApplyToPartitionCA(multiControlledCNOT,numberOfcontrols,_);
// check equality
AssertOperationsEqualReferenced(actual,expected,numberOfcontrols+2);
}
}
}
}