forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperations.qs
32 lines (28 loc) · 1.3 KB
/
Operations.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Samples.SimulatorWithOverrides {
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Intrinsic;
/// # Summary
/// Run a series of experiments that on a perfect state simulator produce matching measurement results.
/// If executed on a simulator which introduces errors in measurements,
/// a certain percentage of experiments will produce mismatched results.
operation DoCorrelatedMeasurements () : Unit {
let nRuns = 100;
mutable nSame = 0;
for (i in 1 .. nRuns) {
using ((q1, q2) = (Qubit(), Qubit())) {
// Prepare a Bell pair (in this state the measurement results on two qubits should be the same)
H(q1);
CNOT(q1, q2);
// Measure both qubits; if there is an error introduced during one of the measurements (but not both), the results will diverge
if (M(q1) == M(q2)) {
set nSame += 1;
}
// Make sure to return the qubits to 0 state
ResetAll([q1, q2]);
}
}
Message($"{nSame} runs out of {nRuns} produced the same results.");
}
}