diff --git a/Standard/tests/AmplitudeAmplificationTests.qs b/Standard/tests/AmplitudeAmplificationTests.qs index 07f6ce32f6d..2067e120e4d 100644 --- a/Standard/tests/AmplitudeAmplificationTests.qs +++ b/Standard/tests/AmplitudeAmplificationTests.qs @@ -12,35 +12,31 @@ namespace Microsoft.Quantum.Tests { open Microsoft.Quantum.Math; open Microsoft.Quantum.Oracles; - ///Here we consider the smallest example of amplitude amplification - ///Suppose we have a single-qubit oracle that prepares the state - /// O |0> = \lambda |1> + \sqrt{1-|\lambda|^2} |0> - /// The goal is to amplify the |1> state - /// We can do this either by synthesizing the reflection about the start and target states ourselves, - /// We can also do it by passing the oracle for state preparation - operation ExampleStatePrepImpl (lambda : Double, idxFlagQubit : Int, qubitStart : Qubit[]) : Unit is Adj + Ctl { + // Here we consider the smallest example of amplitude amplification + // Suppose we have a single-qubit oracle that prepares the state + // O |0> = \lambda |1> + \sqrt{1-|\lambda|^2} |0> + // The goal is to amplify the |1> state + // We can do this either by synthesizing the reflection about the start and target states ourselves, + // We can also do it by passing the oracle for state preparation + internal operation ExampleStatePrepImpl(lambda : Double, idxFlagQubit : Int, qubitStart : Qubit[]) : Unit is Adj + Ctl { let rotAngle = 2.0 * ArcSin(lambda); Ry(rotAngle, qubitStart[idxFlagQubit]); } - function ExampleStatePrep (lambda : Double) : StateOracle { - + internal function ExampleStatePrep(lambda : Double) : StateOracle { return StateOracle(ExampleStatePrepImpl(lambda, _, _)); } - /// In this minimal example, there are no system qubits, only a single flag qubit. - /// ExampleStatePrep is already of type StateOracle, so we call - /// StandardAmplitudeAmplification(iterations: Int, stateOracle : StateOracle, idxFlagQubit : Int startQubits: Qubit[]) : () + // In this minimal example, there are no system qubits, only a single flag qubit. + // ExampleStatePrep is already of type StateOracle, so we call + // StandardAmplitudeAmplification(iterations: Int, stateOracle : StateOracle, idxFlagQubit : Int startQubits: Qubit[]) : () @Test("QuantumSimulator") - operation CheckAmpAmpByOracle () : Unit { - + operation CheckAmpAmpByOracle() : Unit { use qubits = Qubit[1]; - ResetAll(qubits); for nIterations in 0 .. 5 { - for idx in 1 .. 20 { let lambda = IntAsDouble(idx) / 20.0; let rotAngle = ArcSin(lambda); @@ -50,16 +46,15 @@ namespace Microsoft.Quantum.Tests { (StandardAmplitudeAmplification(nIterations, stateOracle, idxFlag))(startQubits); let successAmplitude = Sin(IntAsDouble(2 * nIterations + 1) * rotAngle); let successProbability = successAmplitude * successAmplitude; - AssertMeasurementProbability([PauliZ], [startQubits[idxFlag]], One, successProbability, $"Error: Success probability does not match theory", 1E-10); + AssertMeasurementProbability([PauliZ], [startQubits[idxFlag]], One, successProbability, "Error: Success probability does not match theory", 1E-10); ResetAll(qubits); } } } @Test("QuantumSimulator") - operation CheckAmpAmpObliviousByOraclePhases () : Unit { + operation CheckAmpAmpObliviousByOraclePhases() : Unit { use qubits = Qubit[1]; - ResetAll(qubits); for nIterations in 0 .. 5 { let phases = StandardReflectionPhases(nIterations); @@ -74,16 +69,15 @@ namespace Microsoft.Quantum.Tests { (ObliviousAmplitudeAmplificationFromStatePreparation(phases, ancillaOracle, signalOracle, idxFlag))(auxRegister, systemRegister); let successAmplitude = Sin((IntAsDouble(2 * nIterations + 1) * rotAngle) * 0.5); let successProbability = successAmplitude * successAmplitude; - AssertMeasurementProbability([PauliZ], [auxRegister[idxFlag]], One, successProbability, $"Error: Success probability does not match theory", 1E-10); + AssertMeasurementProbability([PauliZ], [auxRegister[idxFlag]], One, successProbability, "Error: Success probability does not match theory", 1E-10); ResetAll(qubits); } } } @Test("QuantumSimulator") - operation CheckAmpAmpTargetStateReflectionOracle () : Unit { + operation CheckAmpAmpTargetStateReflectionOracle() : Unit { use qubits = Qubit[1]; - ResetAll(qubits); for idx in 0 .. 20 { let rotangle = (IntAsDouble(idx) * PI()) / 20.0; @@ -91,7 +85,7 @@ namespace Microsoft.Quantum.Tests { let success = Cos(0.5 * rotangle) * Cos(0.5 * rotangle); H(qubits[0]); targetStateReflection!(rotangle, qubits); - AssertMeasurementProbability([PauliX], qubits, Zero, success, $"Error: Success probability does not match theory", 1E-10); + AssertMeasurementProbability([PauliX], qubits, Zero, success, "Error: Success probability does not match theory", 1E-10); ResetAll(qubits); } } @@ -109,5 +103,3 @@ namespace Microsoft.Quantum.Tests { } } - -