Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Numerics/tests/FixedPointTests.qs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Numerics.ToffoliTests {
namespace Microsoft.Quantum.Tests {
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
Expand All @@ -10,6 +10,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Diagnostics;

@Test("ToffoliSimulator")
operation PrepareFxPTest() : Unit {
for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] {
use xs = Qubit[10];
Expand All @@ -27,6 +28,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
return MeasureFxP(fxp);
}

@Test("ToffoliSimulator")
operation MeasureFxPTest() : Unit {
use qs = Qubit[4];
let qsFxP = FixedPoint(2, qs);
Expand All @@ -49,6 +51,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
NearEqualityFactD(PrepareAsSignedAndMeasure(0b1111, qsFxP), -0.25);
}

@Test("ToffoliSimulator")
operation CompareGreaterThanFxPTest() : Unit {
for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] {
for b in [1.1, 3.95, 3.14259, -0.4, -4.6, -3.931, 0.1] {
Expand All @@ -69,6 +72,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation AddConstantFxPTest() : Unit {
for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] {
for b in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] {
Expand All @@ -82,6 +86,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation AddFxPTest() : Unit {
for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] {
for b in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] {
Expand All @@ -99,6 +104,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation MultiplyFxPTest() : Unit {
for pos in 5..8 {
for a in [1.2, 3.9, 3.14159, -0.6, -3.5, -3.1931, 0.0] {
Expand All @@ -123,6 +129,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation SquareFxPTest() : Unit {
for pos in 5..8 {
for a in [1.2, 3.9, 3.14159, -0.6, -3.5, -3.1931, 0.0] {
Expand All @@ -141,7 +148,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

function _computeReciprocal(a : Double, n : Int, pos : Int, pos2 : Int) : Double {
internal function ComputeReciprocal(a : Double, n : Int, pos : Int, pos2 : Int) : Double {
let p = pos;
let intA = a >= 0. ? Floor(AbsD(a) * IntAsDouble(2^(n-p)) + 0.5)
| Ceiling(AbsD(a) * IntAsDouble(2^(n-p)) - 0.5);
Expand All @@ -150,6 +157,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
return (a >= 0. ? 1. | -1.) * aReciprUnsigned;
}

@Test("ToffoliSimulator")
operation ComputeReciprocalFxPTest() : Unit {
for pos in 5..8 {
for pos2 in pos - 1..pos + 3 {
Expand All @@ -166,8 +174,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
let eps2 = 1./IntAsDouble(2^(n-pos2));
let aEpsLarger = a + (a>=0. ? eps | -eps);
let aEpsSmaller = a - (a>=0. ? eps | -eps);
let res1 = _computeReciprocal(a+eps,n,pos,pos2);
let res2 = _computeReciprocal(a-eps,n,pos,pos2);
let res1 = ComputeReciprocal(a+eps,n,pos,pos2);
let res2 = ComputeReciprocal(a-eps,n,pos,pos2);
let minRes = MinD(res1, res2) - eps2;
let maxRes = MaxD(res1, res2) + eps2;
let isWithinTol = minRes <= measured and
Expand All @@ -180,6 +188,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation SquareFxPCtrlTest() : Unit {
for ctrl in 0..3 {
for pos in 5..8 {
Expand Down Expand Up @@ -210,6 +219,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation MultiplyFxPCtrlTest() : Unit {
for ctrl in 0..3 {
for pos in 5..8 {
Expand Down Expand Up @@ -244,6 +254,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation EvaluatePolynomialFxPTest() : Unit {
for pos in 4..5 {
for coeffs in [[1.3, -2.4, 1.9],
Expand Down Expand Up @@ -278,6 +289,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation EvaluatePolynomialFxPCtrlTest() : Unit {
for ctrl in 0..3 {
for pos in 4..5 {
Expand Down Expand Up @@ -323,6 +335,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation EvaluateOddPolynomialFxPTest() : Unit {
for pos in 4..5 {
for coeffs in [[1.3, -2.4, 1.9],
Expand Down Expand Up @@ -360,6 +373,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

@Test("ToffoliSimulator")
operation EvaluateOddPolynomialFxPCtrlTest() : Unit {
for ctrl in 0..3 {
for pos in 4..5 {
Expand Down
31 changes: 19 additions & 12 deletions Numerics/tests/IntegerHighLevelTests.qs
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Numerics.ToffoliTests {
namespace Microsoft.Quantum.Tests {
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Extensions.Math;

@Test("ToffoliSimulator")
operation MultiplyIExhaustiveTest() : Unit {
ExhaustiveTestHelper2Args(IntegerMultiplicationRun(false, _, _, _, _));
}

@Test("ToffoliSimulator")
operation SquareIExhaustiveTest() : Unit {
ExhaustiveTestHelper1Arg(IntegerSquareRun(false, _, _, _));
}

@Test("ToffoliSimulator")
operation DivideIExhaustiveTest() : Unit {
ExhaustiveTestHelper2Args(IntegerDivisionRun);
}

@Test("ToffoliSimulator")
operation SquareSIExhaustiveTest() : Unit {
ExhaustiveTestHelper1Arg(IntegerSquareRun(true, _, _, _));
}

@Test("ToffoliSimulator")
operation CompareGTSIExhaustiveTest() : Unit {
ExhaustiveTestHelper2Args(IntegerGreaterThanRun(true, _, _, _, _));
}

@Test("ToffoliSimulator")
operation MultiplySIExhaustiveTest() : Unit {
ExhaustiveTestHelper2Args(IntegerMultiplicationRun(true, _, _, _, _));
}

@Test("ToffoliSimulator")
operation ComputeReciprocalIExhaustiveTest() : Unit {
ExhaustiveTestHelper1Arg(IntegerReciprocalRun(false, _, _, _));
}

operation IntegerGreaterThanRun(signed: Bool, a: Int, b: Int,
n: Int, numCtrl: Int) : Unit {
internal operation IntegerGreaterThanRun(signed: Bool, a: Int, b: Int,
n: Int, numCtrl: Int) : Unit {
use aqs = Qubit[n];
use bqs = Qubit[n];
use result = Qubit();
Expand Down Expand Up @@ -94,8 +101,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

operation IntegerMultiplicationRun(signed: Bool, a: Int, b: Int,
n: Int, numCtrl: Int) : Unit {
internal operation IntegerMultiplicationRun(signed: Bool, a: Int, b: Int,
n: Int, numCtrl: Int) : Unit {
use aqs = Qubit[n];
use bqs = Qubit[n];
use cqs = Qubit[2 * n];
Expand Down Expand Up @@ -159,8 +166,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

operation IntegerSquareRun(signed: Bool, a: Int,
n: Int, numCtrl: Int) : Unit {
internal operation IntegerSquareRun(signed: Bool, a: Int,
n: Int, numCtrl: Int) : Unit {
use aqs = Qubit[n];
use cqs = Qubit[2 * n];
use ctrlqs = Qubit[numCtrl];
Expand Down Expand Up @@ -209,8 +216,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

operation IntegerReciprocalRun(signed: Bool, a: Int,
n: Int, numCtrl: Int) : Unit {
internal operation IntegerReciprocalRun(signed: Bool, a: Int,
n: Int, numCtrl: Int) : Unit {
use aqs = Qubit[n];
use cqs = Qubit[2 * n];
use ctrlqs = Qubit[numCtrl];
Expand Down Expand Up @@ -245,7 +252,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

operation IntegerDivisionRun(a: Int, b: Int, n: Int, numCtrl: Int): Unit {
internal operation IntegerDivisionRun(a: Int, b: Int, n: Int, numCtrl: Int): Unit {
use aqs = Qubit[n];
use bqs = Qubit[n];
use cqs = Qubit[n];
Expand Down Expand Up @@ -296,7 +303,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

operation ExhaustiveTestHelper1Arg(TestFunction: ((Int, Int, Int) => Unit)) : Unit {
internal operation ExhaustiveTestHelper1Arg(TestFunction: ((Int, Int, Int) => Unit)) : Unit {
for numCtrlQubits in 0..2 {
for numQubits in 1..5 {
for a in 0..2^numQubits - 1 {
Expand All @@ -306,7 +313,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests {
}
}

operation ExhaustiveTestHelper2Args(TestFunction: ((Int, Int, Int, Int) => Unit)) : Unit {
internal operation ExhaustiveTestHelper2Args(TestFunction: ((Int, Int, Int, Int) => Unit)) : Unit {
for numCtrlQubits in 0..2 {
for numQubits in 1..5 {
for a in 0..2^numQubits - 1 {
Expand Down
52 changes: 0 additions & 52 deletions Numerics/tests/NumericsTests.cs

This file was deleted.