Skip to content

Commit 5305620

Browse files
authored
Add qubit number pre-check to Grover (#912)
Because the Grover's algorithm sample does a bit shift by the number of qubits, we should verify that the sample does not use more than 63 qubits since that would cause a somewhat arcane error in the bitwise operation.
1 parent 0a2e0c4 commit 5305620

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

samples/algorithms/Grover.qs

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ namespace Sample {
5959
/// Returns the optimal number of Grover iterations needed to find a marked
6060
/// item, given the number of qubits in a register.
6161
function CalculateOptimalIterations(nQubits : Int) : Int {
62+
if nQubits > 63 {
63+
fail "This sample supports at most 63 qubits.";
64+
}
6265
let nItems = 1 <<< nQubits; // 2^nQubits
6366
let angle = ArcSin(1. / Sqrt(IntAsDouble(nItems)));
6467
let iterations = Round(0.25 * PI() / angle - 0.5);

0 commit comments

Comments
 (0)