From 5de69b4b1f466093700c85c9186c377b4bd45cf4 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Wed, 9 Mar 2022 12:10:21 +0100 Subject: [PATCH 1/3] Fixes #444. --- Standard/tests/QcvvTests.cs | 13 +++++++------ Standard/tests/QcvvTests.qs | 36 +++++++++++++++++------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Standard/tests/QcvvTests.cs b/Standard/tests/QcvvTests.cs index 190ff00fd8f..e001a8134ca 100644 --- a/Standard/tests/QcvvTests.cs +++ b/Standard/tests/QcvvTests.cs @@ -2,15 +2,9 @@ // Licensed under the MIT License. using System; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.Quantum.Intrinsic; -using Microsoft.Quantum.Simulation; using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators; -using Microsoft.Quantum.Standard.Emulation; using Xunit; using Assert = Xunit.Assert; @@ -36,5 +30,12 @@ void TestOne(SimulatorBase sim, int expected) TestOne(new QuantumSimulator(), 1); TestOne(new ToffoliSimulator(), 2000); } + + [Fact] + public void TestRobustPhaseEstimation() + { + using var sim = new QuantumSimulator(randomNumberGeneratorSeed: 655321); + TestRobustPhaseEstimationInner.Run(sim).Wait(); + } } } diff --git a/Standard/tests/QcvvTests.qs b/Standard/tests/QcvvTests.qs index 1655d411684..1d9537186ca 100644 --- a/Standard/tests/QcvvTests.qs +++ b/Standard/tests/QcvvTests.qs @@ -2,16 +2,16 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Tests { - open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Canon; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Oracles; open Microsoft.Quantum.Characterization; - open Microsoft.Quantum.Preparation; + open Microsoft.Quantum.Convert; open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Math; open Microsoft.Quantum.Measurement as Meas; + open Microsoft.Quantum.Oracles; + open Microsoft.Quantum.Preparation; @Test("QuantumSimulator") operation TestChoiState() : Unit { @@ -20,8 +20,8 @@ namespace Microsoft.Quantum.Tests { // As usual, the same confusion about {+1, -1} and {0, 1} // labeling bites us here. - AssertMeasurement([PauliX, PauliX], register, Zero, $"XX"); - AssertMeasurement([PauliZ, PauliZ], register, Zero, $"ZZ"); + AssertMeasurement([PauliX, PauliX], register, Zero, "XX"); + AssertMeasurement([PauliZ, PauliZ], register, Zero, "ZZ"); ResetAll(register); } @@ -38,7 +38,7 @@ namespace Microsoft.Quantum.Tests { EqualityWithinToleranceFact(freq2, 0.5, 0.1); } - operation PrepareBiasedCoin(successProbability : Double, qubit : Qubit) : Unit is Adj { + internal operation PrepareBiasedCoin(successProbability : Double, qubit : Qubit) : Unit is Adj { let rotationAngle = 2.0 * ArcCos(Sqrt(successProbability)); Ry(rotationAngle, qubit); } @@ -90,7 +90,7 @@ namespace Microsoft.Quantum.Tests { Exp([PauliZ], phase * IntAsDouble(power), qubits); } - operation RobustPhaseEstimationDemoImpl (phaseSet : Double, bitsPrecision : Int) : Double { + internal operation RobustPhaseEstimationDemoImpl (phaseSet : Double, bitsPrecision : Int) : Double { let op = DiscreteOracle(RobustPhaseEstimationTestOp(phaseSet, _, _)); use q = Qubit(); @@ -99,9 +99,7 @@ namespace Microsoft.Quantum.Tests { return phaseEst; } - // Probabilistic test. Might fail occasionally - @Test("QuantumSimulator") - operation TestRobustPhaseEstimation() : Unit { + operation TestRobustPhaseEstimationInner() : Unit { let bitsPrecision = 10; for idxTest in 0 .. 9 { @@ -125,13 +123,13 @@ namespace Microsoft.Quantum.Tests { @Test("QuantumSimulator") operation TestSingleQubitProcessTomographyMeasurement() : Unit { - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliI, PauliI, H), Zero, $"Failed at ⟪I | H | I⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliI, H), Zero, $"Failed at ⟪I | H | X⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliI, H), Zero, $"Failed at ⟪I | H | Y⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliZ, PauliI, H), Zero, $"Failed at ⟪I | H | Z⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, $"Failed at ⟪Z | H | X⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliY, H), One, $"Failed at -⟪Y | H | Y⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, $"Failed at ⟪Z | H | X⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliI, PauliI, H), Zero, "Failed at ⟪I | H | I⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliI, H), Zero, "Failed at ⟪I | H | X⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliI, H), Zero, "Failed at ⟪I | H | Y⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliZ, PauliI, H), Zero, "Failed at ⟪I | H | Z⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, "Failed at ⟪Z | H | X⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliY, H), One, "Failed at -⟪Y | H | Y⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, "Failed at ⟪Z | H | X⟫."); } } From 1dd56f2619134aad1b8e6ada1c2f3785dedf8203 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 10 Mar 2022 13:25:24 +0100 Subject: [PATCH 2/3] Add other test. --- Standard/tests/QcvvTests.cs | 7 +++++++ Standard/tests/QcvvTests.qs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Standard/tests/QcvvTests.cs b/Standard/tests/QcvvTests.cs index e001a8134ca..fea185ab484 100644 --- a/Standard/tests/QcvvTests.cs +++ b/Standard/tests/QcvvTests.cs @@ -31,6 +31,13 @@ void TestOne(SimulatorBase sim, int expected) TestOne(new ToffoliSimulator(), 2000); } + [Fact] + public void TestEstimateFrequencyBinomial() + { + using var sim = new QuantumSimulator(randomNumberGeneratorSeed: 655321); + TestEstimateFrequencyBinomialInner.Run(sim).Wait(); + } + [Fact] public void TestRobustPhaseEstimation() { diff --git a/Standard/tests/QcvvTests.qs b/Standard/tests/QcvvTests.qs index 1d9537186ca..347ad3a265d 100644 --- a/Standard/tests/QcvvTests.qs +++ b/Standard/tests/QcvvTests.qs @@ -58,7 +58,7 @@ namespace Microsoft.Quantum.Tests { } @Test("QuantumSimulator") - operation TestEstimateFrequencyBinomial() : Unit { + operation TestEstimateFrequencyBinomialInner() : Unit { // If this is larger, tests fail less often, but more false negatives // slip through. let nStdDevs = 3.0; From 1cda5fcc1460b8ef4386ff63cc83f1b68811f766 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Fri, 11 Mar 2022 00:22:23 -0800 Subject: [PATCH 3/3] Update Standard/tests/QcvvTests.qs Co-authored-by: Mariia Mykhailova --- Standard/tests/QcvvTests.qs | 1 - 1 file changed, 1 deletion(-) diff --git a/Standard/tests/QcvvTests.qs b/Standard/tests/QcvvTests.qs index 347ad3a265d..3c00e88a6f2 100644 --- a/Standard/tests/QcvvTests.qs +++ b/Standard/tests/QcvvTests.qs @@ -57,7 +57,6 @@ namespace Microsoft.Quantum.Tests { EqualityWithinToleranceFact(expectation, actualFreq, tolerance); } - @Test("QuantumSimulator") operation TestEstimateFrequencyBinomialInner() : Unit { // If this is larger, tests fail less often, but more false negatives // slip through.