-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import TestUtils.BinaryOp; | ||
import TestUtils.BinaryOpInPlace; | ||
import TestUtils.BinaryOpInPlaceExtraOut; | ||
import QuantumArithmetic.PG2012Test; | ||
import TestUtils; | ||
import QuantumArithmetic.JHHA2016; | ||
|
||
// For debugging, run with Ctrl+F5, | ||
operation Main() : Unit { | ||
let n = 3; | ||
let a = 5; | ||
let b = 4; | ||
//Message($"ans1={PG2012Test.TestFMAC_MOD2(n,a,a,7)}"); | ||
Message($"{a}^{b}={PG2012Test.TestEXP_MOD(n,a,b,7)}"); | ||
let n = 8; | ||
let a = 196; | ||
let ans = TestUtils.UnaryOpInPlace(n, a, JHHA2016.RotateRight); | ||
Message($"ans={ans}"); | ||
} |
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,35 @@ | ||
/// Implementation of the multiplier presented in paper: | ||
/// Ancilla-Input and Garbage-Output Optimized Design of a Reversible Quantum Integer Multiplier | ||
/// Jayashree HV, Himanshu Thapliyal, Hamid R. Arabnia, V K Agrawal, 2016. | ||
/// https://arxiv.org/abs/1608.01228 | ||
|
||
import Std.Diagnostics.Fact; | ||
import QuantumArithmetic.HigherRadixUtils.HigherRadix.HigherRadix; | ||
|
||
|
||
// Computes P+=Am*B. | ||
// Zcin must be prepared in zero state and is returned in zero state. | ||
operation AddNop(P:Qubit[], B:Qubit[], Zcin:Qubit, Am:Qubit) : Unit is Adj + Ctl { | ||
|
||
} | ||
|
||
// Rotates right bits of P. | ||
operation RotateRight(P: Qubit[]): Unit is Adj+Ctl { | ||
let k: Int = Length(P); | ||
let k1: Int = k/2; | ||
for i in 0..k1-1 { | ||
SWAP(P[i], P[k-1-i]); | ||
} | ||
for i in 0..k1-2+(k%2) { | ||
SWAP(P[i], P[k-2-i]); | ||
} | ||
} | ||
|
||
// Computes P+=A*B. | ||
operation Multiply(A: Qubit[], B: Qubit[], P: Qubit[]) : Unit is Adj + Ctl { | ||
let n : Int = Length(A); | ||
Fact(Length(B) == n, "Register sizes must match."); | ||
Fact(Length(P) == 2* n, "Register sizes must match."); | ||
|
||
|
||
} |
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,18 @@ | ||
import pytest | ||
from qsharp import init, eval | ||
import random | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def setup(): | ||
init(project_root='.') | ||
|
||
|
||
@pytest.mark.parametrize("n", [5, 8, 32, 62, 63]) | ||
def test_RotateRight(n: int): | ||
op = "QuantumArithmetic.JHHA2016.RotateRight" | ||
for _ in range(5): | ||
x = random.randint(0, 2**n-1) | ||
ans = eval(f"TestUtils.UnaryOpInPlace({n},{x},{op})") | ||
expected = (x>>1) + ((x%2) << (n-1)) | ||
assert ans == expected |