From 0aee40692f9ca9abcbf6528a58ed9cfc134d526e Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 14 Apr 2022 17:08:58 +0200 Subject: [PATCH] Removed C# test driver. --- Numerics/tests/FixedPointTests.qs | 22 +++++++++-- Numerics/tests/IntegerHighLevelTests.qs | 31 +++++++++------ Numerics/tests/NumericsTests.cs | 52 ------------------------- 3 files changed, 37 insertions(+), 68 deletions(-) delete mode 100644 Numerics/tests/NumericsTests.cs diff --git a/Numerics/tests/FixedPointTests.qs b/Numerics/tests/FixedPointTests.qs index 0ecf6254e1d..77fb825399a 100644 --- a/Numerics/tests/FixedPointTests.qs +++ b/Numerics/tests/FixedPointTests.qs @@ -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; @@ -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]; @@ -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); @@ -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] { @@ -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] { @@ -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] { @@ -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] { @@ -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] { @@ -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); @@ -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 { @@ -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 @@ -180,6 +188,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation SquareFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 5..8 { @@ -210,6 +219,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation MultiplyFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 5..8 { @@ -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], @@ -278,6 +289,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation EvaluatePolynomialFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 4..5 { @@ -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], @@ -360,6 +373,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation EvaluateOddPolynomialFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 4..5 { diff --git a/Numerics/tests/IntegerHighLevelTests.qs b/Numerics/tests/IntegerHighLevelTests.qs index fe531b4e029..9950eb50937 100644 --- a/Numerics/tests/IntegerHighLevelTests.qs +++ b/Numerics/tests/IntegerHighLevelTests.qs @@ -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(); @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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 { @@ -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 { diff --git a/Numerics/tests/NumericsTests.cs b/Numerics/tests/NumericsTests.cs deleted file mode 100644 index 64a2590c41c..00000000000 --- a/Numerics/tests/NumericsTests.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.XUnit; -using Microsoft.Quantum.Simulation.Simulators; -using Xunit.Abstractions; -using System.Diagnostics; - -namespace Microsoft.Quantum.Numerics.Tests -{ - public class NumericsTests - { - private readonly ITestOutputHelper output; - - public NumericsTests(ITestOutputHelper output) - { - this.output = output; - } - - /// - /// This driver will run all Q# tests (operations named "...Test") - /// that are located inside Microsoft.Quantum.Numerics.Tests using the quantum - /// simulator. - /// - [OperationDriver(TestNamespace = "Microsoft.Quantum.Numerics.Tests", - TestCasePrefix = "QSim:")] - public void QSimTests(TestOperation op) - { - var sim = new QuantumSimulator(); - // OnLog defines action(s) performed when Q# test calls function Message - sim.OnLog += (msg) => { output.WriteLine(msg); }; - sim.OnLog += (msg) => { Debug.WriteLine(msg); }; - op.TestOperationRunner(sim); - } - - /// - /// This driver will run all Q# tests (operations named "...Test") - /// that are located inside Microsoft.Quantum.Numerics.ToffoliTests using the - /// Toffoli simulator. - /// - [OperationDriver(TestNamespace = "Microsoft.Quantum.Numerics.ToffoliTests", - TestCasePrefix = "ToffSim:")] - public void ToffoliSimTests(TestOperation op) - { - var sim = new ToffoliSimulator(); - // OnLog defines action(s) performed when Q# test calls function Message - sim.OnLog += (msg) => { output.WriteLine(msg); }; - sim.OnLog += (msg) => { Debug.WriteLine(msg); }; - op.TestOperationRunner(sim); - } - } -}