This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ResultArrayAsInt
override to target packages (#1055)
This adds a `ResultArrayAsInt` implementation that is compatible with QIR hardware compilation to the target packages. This will allow it to act as an override for the libraries definition while still supporting calculation of the integer value on platforms that can support it.
- Loading branch information
Showing
7 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/Simulation/TargetDefinitions/Decompositions/ResultArrayAsInt.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Microsoft.Quantum.Convert { | ||
open Microsoft.Quantum.Arrays; | ||
|
||
/// # Summary | ||
/// Produces a non-negative integer from a string of Results in little endian format. | ||
/// | ||
/// # Input | ||
/// ## results | ||
/// Results in binary representation of number. | ||
function ResultArrayAsInt(results : Result[]) : Int { | ||
mutable val = 0; | ||
for i in IndexRange(results) { | ||
set val += results[i] == One ? 2 ^ i | 0; | ||
} | ||
return val; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace UtilitiesTests { | ||
open Microsoft.Quantum.Convert; | ||
open Microsoft.Quantum.Diagnostics; | ||
|
||
@Test("SparseSimulator") | ||
operation VerifyResultArrayAsInt() : Unit { | ||
Fact(ResultArrayAsInt([Zero, Zero, Zero]) == 0, "ResultArrayAsInt of 0 value should work"); | ||
Fact(ResultArrayAsInt([One, Zero, Zero]) == 1, "ResultArrayAsInt of 1 value should work"); | ||
Fact(ResultArrayAsInt([Zero, One, Zero]) == 2, "ResultArrayAsInt of 2 value should work"); | ||
Fact(ResultArrayAsInt([One, One, Zero]) == 3, "ResultArrayAsInt of 3 value should work"); | ||
Fact(ResultArrayAsInt([Zero, Zero, One]) == 4, "ResultArrayAsInt of 4 value should work"); | ||
Fact(ResultArrayAsInt([One, Zero, One]) == 5, "ResultArrayAsInt of 5 value should work"); | ||
Fact(ResultArrayAsInt([Zero, One, One]) == 6, "ResultArrayAsInt of 6 value should work"); | ||
Fact(ResultArrayAsInt([One, One, One]) == 7, "ResultArrayAsInt of 7 value should work"); | ||
} | ||
} |