This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathOperations.qs
More file actions
106 lines (94 loc) · 3.01 KB
/
Copy pathOperations.qs
File metadata and controls
106 lines (94 loc) · 3.01 KB
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
97
98
99
100
101
102
103
104
105
106
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
/// Q# code should be in one or more .qs files that live
/// in the same directory as the python classical driver.
///
namespace Microsoft.Quantum.SanityTests {
open Microsoft.Quantum.Intrinsic;
/// # Summary
/// The simplest program. Just generate a debug Message on the console.
operation HelloQ() : Unit {
Message($"Hello from quantum world!");
}
/// # Summary
/// A more sophisticated program that shows how to
/// specify parameters, instantiate qubits, and return values.
operation HelloAgain(count : Int, name : String) : Result[] {
Message($"Hello {name} again!");
mutable r = new Result[count];
using (q = Qubit()) {
for (i in 1..count) {
if (i == 2) { X(q); }
set r w/= i-1 <- M(q);
Reset(q);
}
}
return r;
}
/// # Summary
/// Checks that built-in complex types can be used as arguments.
operation IndexIntoTuple(count : Int, tuples : (Result, String)[]) : (Result, String) {
return tuples[count];
}
/// # Summary
/// Checks that nested arrays can be used as arguments.
operation IndexIntoNestedArray(index1 : Int, index2 : Int, nestedArray : Int[][]) : Int {
return nestedArray[index1][index2];
}
/// # Summary
/// Checks that Result-type arguments are handled correctly.
operation EchoResult(input : Result) : Result {
return input;
}
/// # Summary
/// Checks that Pauli-type and arrays of Pauli-type arguments are handled correctly.
operation SwapFirstPauli(paulis : Pauli[], pauliToSwap : Pauli) : (Pauli[], Pauli) {
return (paulis w/ 0 <- pauliToSwap, paulis[0]);
}
/// # Summary
/// Checks that a 10-tuple can be round-tripped correctly.
operation EchoTenTuple(tenTuple : (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)) : (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) {
return tenTuple;
}
/// # Summary
/// Checks that a 10-tuple is processed correctly.
operation IndexIntoTenTuple(index : Int, tenTuple : (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)) : Int {
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = tenTuple;
if (index == 0) {
return x0;
}
if (index == 1) {
return x1;
}
if (index == 2) {
return x2;
}
if (index == 3) {
return x3;
}
if (index == 4) {
return x4;
}
if (index == 5) {
return x5;
}
if (index == 6) {
return x6;
}
if (index == 7) {
return x7;
}
if (index == 8) {
return x8;
}
if (index == 9) {
return x9;
}
return -1;
}
operation MeasureOne() : Result {
use q = Qubit();
X(q);
return MResetZ(q);
}
}