From 37cabd3ae84a90f7fcb62e120a92cb92f04a33eb Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Thu, 20 Aug 2020 16:56:05 -0700 Subject: [PATCH 01/17] Remove deprecated diagnostics. --- .../Diagnostics/DeprecatedDiagnostics.qs | 20 ------ .../Diagnostics/DeprecatedTesting.qs | 66 ------------------- 2 files changed, 86 deletions(-) delete mode 100644 src/Simulation/QsharpCore/Diagnostics/DeprecatedDiagnostics.qs delete mode 100644 src/Simulation/QsharpCore/Diagnostics/DeprecatedTesting.qs diff --git a/src/Simulation/QsharpCore/Diagnostics/DeprecatedDiagnostics.qs b/src/Simulation/QsharpCore/Diagnostics/DeprecatedDiagnostics.qs deleted file mode 100644 index 05a0a31185d..00000000000 --- a/src/Simulation/QsharpCore/Diagnostics/DeprecatedDiagnostics.qs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Extensions.Diagnostics { - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.dumpmachine". - @Deprecated("Microsoft.Quantum.Diagnostics.DumpMachine") - function DumpMachine<'T> (location : 'T) : Unit { - return Microsoft.Quantum.Diagnostics.DumpMachine(location); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.dumpregister". - @Deprecated("Microsoft.Quantum.Diagnostics.DumpRegister") - function DumpRegister<'T> (location : 'T, qubits : Qubit[]) : Unit { - return Microsoft.Quantum.Diagnostics.DumpRegister(location, qubits); - } - -} diff --git a/src/Simulation/QsharpCore/Diagnostics/DeprecatedTesting.qs b/src/Simulation/QsharpCore/Diagnostics/DeprecatedTesting.qs deleted file mode 100644 index 22886674a90..00000000000 --- a/src/Simulation/QsharpCore/Diagnostics/DeprecatedTesting.qs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Extensions.Testing { - open Microsoft.Quantum.Math; - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertqubit". - @Deprecated("Microsoft.Quantum.Diagnostics.AssertQubit") - operation AssertQubit(expected : Result, q : Qubit) : Unit { - Microsoft.Quantum.Diagnostics.AssertQubit(expected, q); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertqubitwithintolerance". - @Deprecated("Microsoft.Quantum.Diagnostics.AssertQubitWithinTolerance") - operation AssertQubitTol(expected : Result, q : Qubit, tolerance : Double) : Unit { - Microsoft.Quantum.Diagnostics.AssertQubitWithinTolerance(expected, q, tolerance); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertqubitisinstatewithintolerance". - @Deprecated("Microsoft.Quantum.Diagnostics.AssertQubitIsInStateWithinTolerance") - operation AssertQubitState(expected : (Complex, Complex), register : Qubit, tolerance : Double) : Unit { - Microsoft.Quantum.Diagnostics.AssertQubitIsInStateWithinTolerance(expected, register, tolerance); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertoperationsequalreferenced". - /// Note that the order of the arguments to this operation has changed. - @Deprecated("Microsoft.Quantum.Diagnostics.AssertOperationsEqualReferenced") - operation AssertOperationsEqualReferenced(actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit { - Microsoft.Quantum.Diagnostics.AssertOperationsEqualReferenced(nQubits, actual, expected); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertoperationsequalinplace". - /// Note that the order of the arguments to this operation has changed. - @Deprecated("Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlace") - operation AssertOperationsEqualInPlace(actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit { - Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlace(nQubits, actual, expected); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertoperationsequalinplaceCompBasis". - /// Note that the order of the arguments to this operation has changed. - @Deprecated("Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlaceCompBasis") - operation AssertOperationsEqualInPlaceCompBasis(actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit { - Microsoft.Quantum.Diagnostics.AssertOperationsEqualInPlaceCompBasis(nQubits, actual, expected); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertallzero". - @Deprecated("Microsoft.Quantum.Diagnostics.AssertAllZero") - operation AssertAllZero(qubits : Qubit[]) : Unit is Adj + Ctl { - Microsoft.Quantum.Diagnostics.AssertAllZero(qubits); - } - - /// # Deprecated - /// Please use @"microsoft.quantum.diagnostics.assertallzerowithintolerance". - @Deprecated("Microsoft.Quantum.Diagnostics.AssertAllZeroWithinTolerance") - operation AssertAllZeroTol(qubits : Qubit[], tolerance : Double) : Unit is Adj + Ctl { - Microsoft.Quantum.Diagnostics.AssertAllZeroWithinTolerance(qubits, tolerance); - } - -} From 988aac8d7c8cf94373de36a400aafe24218dd9f8 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Thu, 20 Aug 2020 16:56:22 -0700 Subject: [PATCH 02/17] Add Type2 targeting package --- .../TargetDefinitions/Decompositions/CCNOT.qs | 3 + .../TargetDefinitions/Decompositions/CNOT.qs | 3 + .../Decompositions/ExpFrac.qs | 2 + .../Decompositions/ExpFracFromIsing.qs | 57 ++++++ .../Decompositions/ExpFromIsing.qs | 44 +++++ .../TargetDefinitions/Decompositions/M.qs | 3 + .../Decompositions/MResetX.qs | 2 + .../Decompositions/MResetXWithNoReuse.qs | 28 +++ .../Decompositions/MResetY.qs | 10 +- .../Decompositions/MResetYWithNoReuse.qs | 28 +++ .../Decompositions/MResetZ.qs | 2 + .../Decompositions/MResetZWithNoReuse.qs | 28 +++ .../Decompositions/MeasureWithNoReuse.qs | 64 +++++++ .../TargetDefinitions/Decompositions/R.qs | 46 +++++ .../TargetDefinitions/Decompositions/R1.qs | 3 + .../Decompositions/R1Frac.qs | 3 + .../TargetDefinitions/Decompositions/RFrac.qs | 2 + .../TargetDefinitions/Decompositions/Reset.qs | 3 + .../Decompositions/ResetAll.qs | 3 + .../Decompositions/ResetWithoutReuse.qs | 18 ++ .../TargetDefinitions/Decompositions/Rx.qs | 3 + .../TargetDefinitions/Decompositions/Ry.qs | 3 + .../TargetDefinitions/Decompositions/Rz.qs | 3 + .../TargetDefinitions/Decompositions/SWAP.qs | 3 + .../Decompositions/SetToBasisState.qs | 2 + .../TargetDefinitions/Decompositions/Utils.qs | 169 ++++++++++++++++++ .../TargetDefinitions/Intrinsic/Exp.qs | 3 + .../TargetDefinitions/Intrinsic/H.qs | 3 + .../TargetDefinitions/Intrinsic/I.qs | 3 + .../TargetDefinitions/Intrinsic/IsingXX.qs | 23 +++ .../TargetDefinitions/Intrinsic/IsingYY.qs | 23 +++ .../TargetDefinitions/Intrinsic/IsingZZ.qs | 23 +++ .../TargetDefinitions/Intrinsic/M.qs | 36 ++++ .../TargetDefinitions/Intrinsic/Measure.qs | 3 + .../TargetDefinitions/Intrinsic/R.qs | 3 + .../TargetDefinitions/Intrinsic/Rx.qs | 35 ++++ .../TargetDefinitions/Intrinsic/Ry.qs | 35 ++++ .../TargetDefinitions/Intrinsic/Rz.qs | 35 ++++ .../TargetDefinitions/Intrinsic/S.qs | 3 + .../TargetDefinitions/Intrinsic/SWAP.qs | 41 +++++ .../TargetDefinitions/Intrinsic/T.qs | 3 + .../TargetDefinitions/Intrinsic/X.qs | 3 + .../TargetDefinitions/Intrinsic/Y.qs | 3 + .../TargetDefinitions/Intrinsic/Z.qs | 3 + .../TargetPackages/Type2.Package.props | 41 +++++ .../Microsoft.Quantum.Type2.Core.csproj | 47 +++++ 46 files changed, 898 insertions(+), 6 deletions(-) create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/R.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/Utils.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/M.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/Rx.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/Ry.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/Rz.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs create mode 100644 src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props create mode 100644 src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj diff --git a/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs b/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs index 430ab0e4c9f..99772e845a0 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/CCNOT.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the doubly controlled–NOT (CCNOT) gate to three qubits. /// @@ -18,6 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Controlled X([control1, control2], target); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.CCNOT") operation CCNOT (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj + Ctl { body (...) { Controlled X([control1, control2], target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs b/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs index f6403a74e5f..7817f4fd480 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/CNOT.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the controlled-NOT (CNOT) gate to a pair of qubits. /// @@ -29,6 +31,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Controlled X([control], target); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.CNOT") operation CNOT (control : Qubit, target : Qubit) : Unit is Adj + Ctl { body (...) { Controlled X([control], target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs index e18d4e98e0d..e6f6c55a406 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFrac.qs @@ -4,6 +4,7 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Math; open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies the exponential of a multi-qubit Pauli operator @@ -28,6 +29,7 @@ namespace Microsoft.Quantum.Intrinsic { /// the qubit register is to be rotated. /// ## qubits /// Register to apply the given rotation to. + @EnableTestingViaName("Test.TargetDefinitions.ExpFrac") operation ExpFrac (paulis : Pauli[], numerator : Int, power : Int, qubits : Qubit[]) : Unit is Adj + Ctl { let angle = (PI() * IntAsDouble(numerator)) / IntAsDouble(2 ^ power); Exp(paulis, angle, qubits); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs new file mode 100644 index 00000000000..b5ea0012eed --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the exponential of a multi-qubit Pauli operator + /// with an argument given by a dyadic fraction. + /// + /// # Description + /// \begin{align} + /// e^{i \pi k [P_0 \otimes P_1 \cdots P_{N-1}] / 2^n}, + /// \end{align} + /// where $P_i$ is the $i$th element of `paulis`, and where + /// $N = $`Length(paulis)`. + /// + /// # Input + /// ## paulis + /// Array of single-qubit Pauli values indicating the tensor product + /// factors on each qubit. + /// ## numerator + /// Numerator ($k$) in the dyadic fraction representation of the angle + /// by which the qubit register is to be rotated. + /// ## power + /// Power of two ($n$) specifying the denominator of the angle by which + /// the qubit register is to be rotated. + /// ## qubits + /// Register to apply the given rotation to. + @EnableTestingViaName("Test.TargetDefinitions.ExpFrac") + operation ExpFrac (paulis : Pauli[], numerator : Int, power : Int, qubits : Qubit[]) : Unit is Adj + Ctl { + body(...) { + if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'target' must have the same length"; } + + if (Length(paulis) != 0) { + let indices = IndicesOfNonIdentity(paulis); + let newPaulis = ArrayFromIndiciesP(paulis, indices); + let newQubits = ArrayFromIndiciesQ(qubits, indices); + + if (Length(indices) != 0) { + let (kModPositive, n) = ReducedDyadicFractionPeriodic(numerator, power); // k is odd, in the range [1,2*2^n-1] or (k,n) are both 0 + let numeratorD = PI() * IntAsDouble(kModPositive); + let theta = numeratorD * PowD(2.0, IntAsDouble(-n)); + ExpNoIdUtil(newPaulis, theta, newQubits, RFrac(_, numerator, power, _)); + } + else { + ApplyGlobalPhaseFracWithR1Frac(numerator, power); + } + } + } + adjoint(...) { + ExpFrac(paulis, -numerator, power, qubits); + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs new file mode 100644 index 00000000000..0501dbca050 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the exponential of a multi-qubit Pauli operator. + /// + /// # Description + /// \begin{align} + /// e^{i \theta [P_0 \otimes P_1 \cdots P_{N-1}]}, + /// \end{align} + /// where $P_i$ is the $i$th element of `paulis`, and where + /// $N = $`Length(paulis)`. + /// + /// # Input + /// ## paulis + /// Array of single-qubit Pauli values indicating the tensor product + /// factors on each qubit. + /// ## theta + /// Angle about the given multi-qubit Pauli operator by which the + /// target register is to be rotated. + /// ## qubits + /// Register to apply the given rotation to. + @EnableTestingViaName("Test.TargetDefinitions.Exp") + operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit is Adj + Ctl { + body(...) { + if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'qubits' must have the same length"; } + let (newPaulis, newQubits) = RemovePauliI(paulis, qubits); + + if (Length(newPaulis) != 0) { + if (Length(newPaulis) == 2 and newPaulis[0] != newPaulis[1]) { fail $"Target Package supports only rotation around XX, YY, ZZ, given {paulis}"; } + ExpNoIdUtil(newPaulis, theta , newQubits, R(_, -2.0 * theta, _)); + } + else { + ApplyGlobalPhase(theta); + } + } + adjoint(...) { + Exp(paulis, -theta, qubits); + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/M.qs b/src/Simulation/TargetDefinitions/Decompositions/M.qs index c5066f9ee6c..a8fb33939a2 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/M.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/M.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Performs a measurement of a single qubit in the /// Pauli $Z$ basis. @@ -27,6 +29,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// Measure([PauliZ], [qubit]); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.M") operation M (qubit : Qubit) : Result { return Measure([PauliZ], [qubit]); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs index ae845f9b788..30568c5f002 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetX.qs @@ -3,6 +3,7 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the X basis, @@ -20,6 +21,7 @@ namespace Microsoft.Quantum.Measurement { /// /// # Output /// The result of measuring `target` in the Pauli $X$ basis. + @EnableTestingViaName("Test.TargetDefinitions.MResetX") operation MResetX (target : Qubit) : Result { let result = Measure([PauliX], [target]); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs new file mode 100644 index 00000000000..c030f7c3f93 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetXWithNoReuse.qs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Measurement { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Measures a single qubit in the X basis, + /// and resets it to a fixed initial state + /// following the measurement. + /// + /// # Description + /// Performs a single-qubit measurement in the $X$-basis, + /// and ensures that the qubit is returned to $\ket{0}$ + /// following the measurement. + /// + /// # Input + /// ## target + /// A single qubit to be measured. + /// + /// # Output + /// The result of measuring `target` in the Pauli $X$ basis. + @EnableTestingViaName("Test.TargetDefinitions.MResetX") + operation MResetX (target : Qubit) : Result { + return Measure([PauliX], [target]); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs index 41271901ab9..070a5db0d7f 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetY.qs @@ -3,11 +3,7 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; - - internal operation BasisChangeZtoY(target : Qubit) : Unit is Adj + Ctl { - H(target); - S(target); - } + open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the Y basis, @@ -25,11 +21,13 @@ namespace Microsoft.Quantum.Measurement { /// /// # Output /// The result of measuring `target` in the Pauli $Y$ basis. + @EnableTestingViaName("Test.TargetDefinitions.MResetY") operation MResetY (target : Qubit) : Result { let result = Measure([PauliY], [target]); // We must return the qubit to the Z basis as well. - Adjoint BasisChangeZtoY(target); + S(target); + H(target); if (result == One) { // Recall that the +1 eigenspace of a measurement operator corresponds to diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs new file mode 100644 index 00000000000..3e9f9859b34 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetYWithNoReuse.qs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Measurement { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Measures a single qubit in the Y basis, + /// and resets it to a fixed initial state + /// following the measurement. + /// + /// # Description + /// Performs a single-qubit measurement in the $Y$-basis, + /// and ensures that the qubit is returned to $\ket{0}$ + /// following the measurement. + /// + /// # Input + /// ## target + /// A single qubit to be measured. + /// + /// # Output + /// The result of measuring `target` in the Pauli $Y$ basis. + @EnableTestingViaName("Test.TargetDefinitions.MResetY") + operation MResetY (target : Qubit) : Result { + return Measure([PauliY], [target]); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs index 64c04237af6..3d583df4075 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetZ.qs @@ -3,6 +3,7 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; /// # Summary /// Measures a single qubit in the Z basis, @@ -20,6 +21,7 @@ namespace Microsoft.Quantum.Measurement { /// /// # Output /// The result of measuring `target` in the Pauli $Z$ basis. + @EnableTestingViaName("Test.TargetDefinitions.MResetZ") operation MResetZ (target : Qubit) : Result { let result = M(target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs new file mode 100644 index 00000000000..623b7899e0e --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetZWithNoReuse.qs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Measurement { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Measures a single qubit in the Z basis, + /// and resets it to a fixed initial state + /// following the measurement. + /// + /// # Description + /// Performs a single-qubit measurement in the $Z$-basis, + /// and ensures that the qubit is returned to $\ket{0}$ + /// following the measurement. + /// + /// # Input + /// ## target + /// A single qubit to be measured. + /// + /// # Output + /// The result of measuring `target` in the Pauli $Z$ basis. + @EnableTestingViaName("Test.TargetDefinitions.MResetZ") + operation MResetZ (target : Qubit) : Result { + return M(target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs new file mode 100644 index 00000000000..f64e83b1d4b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Performs a joint measurement of one or more qubits in the + /// specified Pauli bases. + /// + /// # Description + /// The output result is given by the distribution: + /// \begin{align} + /// \Pr(\texttt{Zero} | \ket{\psi}) = + /// \frac12 \braket{ + /// \psi \mid| + /// \left( + /// \boldone + P_0 \otimes P_1 \otimes \cdots \otimes P_{N-1} + /// \right) \mid| + /// \psi + /// }, + /// \end{align} + /// where $P_i$ is the $i$th element of `bases`, and where + /// $N = \texttt{Length}(\texttt{bases})$. + /// That is, measurement returns a `Result` $d$ such that the eigenvalue of the + /// observed measurement effect is $(-1)^d$. + /// + /// # Input + /// ## bases + /// Array of single-qubit Pauli values indicating the tensor product + /// factors on each qubit. + /// ## qubits + /// Register of qubits to be measured. + /// + /// # Output + /// `Zero` if the $+1$ eigenvalue is observed, and `One` if + /// the $-1$ eigenvalue is observed. + /// + /// # Remarks + /// If the basis array and qubit array are different lengths, then the + /// operation will fail. + @EnableTestingViaName("Test.TargetDefinitions.Measure") + operation Measure (bases : Pauli[], qubits : Qubit[]) : Result { + if (Length(bases) == 1) { + MapPauli(qubits[0], PauliZ, bases[0]); + return M(qubits[0]); + } + else { + using (q = Qubit()) { + within { + H(q); + } + apply { + for (k in 0 .. Length(bases) - 1) { + if (bases[k] == PauliX) { Controlled X([qubits[k]], q); } + if (bases[k] == PauliZ) { Controlled Z([qubits[k]], q); } + if (bases[k] == PauliY) { Controlled Y([qubits[k]], q); } + } + } + return M(q); + } + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/R.qs b/src/Simulation/TargetDefinitions/Decompositions/R.qs new file mode 100644 index 00000000000..b5935a4ed7b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/R.qs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies a rotation about the given Pauli axis. + /// + /// # Description + /// \begin{align} + /// R_{\mu}(\theta) \mathrel{:=} + /// e^{-i \theta \sigma_{\mu} / 2}, + /// \end{align} + /// where $\mu \in \{I, X, Y, Z\}$. + /// + /// # Input + /// ## pauli + /// Pauli operator ($\mu$) to be exponentiated to form the rotation. + /// ## theta + /// Angle about which the qubit is to be rotated. + /// ## qubit + /// Qubit to which the gate should be applied. + /// + /// # Remarks + /// When called with `pauli = PauliI`, this operation applies + /// a *global phase*. This phase can be significant + /// when used with the `Controlled` functor. + @EnableTestingViaName("Test.TargetDefinitions.R") + operation R (pauli : Pauli, theta : Double, qubit : Qubit) : Unit is Adj + Ctl { + if( pauli != PauliI ) { + if( pauli == PauliX ) { + Rx(theta, qubit); + } + elif( pauli == PauliY ) { + Ry(theta, qubit); + } + else { // PauliZ + Rz(theta, qubit); + } + } + else { + ApplyGlobalPhase( - theta / 2.0 ); + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/R1.qs b/src/Simulation/TargetDefinitions/Decompositions/R1.qs index 06678d7f707..02ed51439bd 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/R1.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/R1.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies a rotation about the $\ket{1}$ state by a given angle. /// @@ -23,6 +25,7 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliZ, theta, qubit); /// R(PauliI, -theta, qubit); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.R1") operation R1 (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { R(PauliZ, theta, qubit); R(PauliI, -theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs b/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs index 338f32c8ff1..056e0ba9e54 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/R1Frac.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies a rotation about the $\ket{1}$ state by an angle specified /// as a dyadic fraction. @@ -33,6 +35,7 @@ namespace Microsoft.Quantum.Intrinsic { /// RFrac(PauliZ, -numerator, denominator + 1, qubit); /// RFrac(PauliI, numerator, denominator + 1, qubit); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.R1Frac") operation R1Frac (numerator : Int, power : Int, qubit : Qubit) : Unit is Adj + Ctl { RFrac(PauliZ, -numerator, power + 1, qubit); RFrac(PauliI, numerator, power + 1, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs b/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs index a0f632c7e03..f3fdfa62b19 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RFrac.qs @@ -4,6 +4,7 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Math; open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; /// # Summary /// Applies a rotation about the given Pauli axis by an angle specified @@ -38,6 +39,7 @@ namespace Microsoft.Quantum.Intrinsic { /// // PI() is a Q# function that returns an approximation of π. /// R(pauli, -PI() * IntAsDouble(numerator) / IntAsDouble(2 ^ (power - 1)), qubit); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.RFrac") operation RFrac (pauli : Pauli, numerator : Int, power : Int, qubit : Qubit) : Unit is Adj + Ctl { let angle = ((-2.0 * PI()) * IntAsDouble(numerator)) / IntAsDouble(2 ^ power); R(pauli, angle, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/Reset.qs b/src/Simulation/TargetDefinitions/Decompositions/Reset.qs index a5bb975894d..84b8d8ca38c 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Reset.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Reset.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Given a single qubit, measures it and ensures it is in the |0⟩ state /// such that it can be safely released. @@ -9,6 +11,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// The qubit whose state is to be reset to $\ket{0}$. + @EnableTestingViaName("Test.TargetDefinitions.Reset") operation Reset (target : Qubit) : Unit { if (M(target) == One) { X(target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs b/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs index cd76adc599e..6a520c85bb7 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ResetAll.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Given an array of qubits, measure them and ensure they are in the |0⟩ state /// such that they can be safely released. @@ -9,6 +11,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubits /// An array of qubits whose states are to be reset to $\ket{0}$. + @EnableTestingViaName("Test.TargetDefinitions.ResetAll") operation ResetAll (qubits : Qubit[]) : Unit { for (qubit in qubits) { Reset(qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs new file mode 100644 index 00000000000..f34e6bea635 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ResetWithoutReuse.qs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Given a single qubit, measures it and ensures it is in the |0⟩ state + /// such that it can be safely released. + /// + /// # Input + /// ## qubit + /// The qubit whose state is to be reset to $\ket{0}$. + @EnableTestingViaName("Test.TargetDefinitions.Reset") + operation Reset (target : Qubit) : Unit { + let r = M(target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/Rx.qs b/src/Simulation/TargetDefinitions/Decompositions/Rx.qs index d4c999a83b2..e7cf9c8be1c 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Rx.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Rx.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies a rotation about the $x$-axis by a given angle. /// @@ -26,6 +28,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliX, theta, qubit); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.Rx") operation Rx (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { R(PauliX, theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/Ry.qs b/src/Simulation/TargetDefinitions/Decompositions/Ry.qs index e68732523b6..ac1cb18dcfa 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Ry.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Ry.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies a rotation about the $y$-axis by a given angle. /// @@ -26,6 +28,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliY, theta, qubit); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.Ry") operation Ry (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { R(PauliY, theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/Rz.qs b/src/Simulation/TargetDefinitions/Decompositions/Rz.qs index 30956ac6640..08d0e2b239b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Rz.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Rz.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies a rotation about the $z$-axis by a given angle. /// @@ -26,6 +28,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ```qsharp /// R(PauliZ, theta, qubit); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.Rz") operation Rz (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body (...) { R(PauliZ, theta, qubit); diff --git a/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs b/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs index 19cc13a1634..6952df79af6 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/SWAP.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the SWAP gate to a pair of qubits. /// @@ -31,6 +33,7 @@ namespace Microsoft.Quantum.Intrinsic { /// CNOT(qubit2, qubit1); /// CNOT(qubit1, qubit2); /// ``` + @EnableTestingViaName("Test.TargetDefinitions.SWAP") operation SWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit is Adj + Ctl { body (...) { CNOT(qubit1, qubit2); diff --git a/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs b/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs index ff7ec846edf..740925d833c 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/SetToBasisState.qs @@ -3,6 +3,7 @@ namespace Microsoft.Quantum.Measurement { open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; /// # Summary /// Sets a qubit to a given computational basis state by measuring the @@ -17,6 +18,7 @@ namespace Microsoft.Quantum.Measurement { /// # Remarks /// As an invariant of this operation, calling `M(q)` immediately /// after `SetToBasisState(result, q)` will return `result`. + @EnableTestingViaName("Test.TargetDefinitions.SetToBasisState") operation SetToBasisState(desired : Result, target : Qubit) : Unit { if (desired != M(target)) { X(target); diff --git a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs new file mode 100644 index 00000000000..0ad8fad241c --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs @@ -0,0 +1,169 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + + internal operation ExpNoIdUtil(paulis : Pauli[], theta : Double, qubits : Qubit[], rotation : ((Pauli, Qubit) => Unit is Adj + Ctl)) : Unit is Ctl { + if (Length(paulis) != Length(qubits)) { fail "Arrays 'paulis' and 'qubits' must have the same length"; } + if (Length(paulis) == 1) { + rotation(paulis[0], qubits[0]); + } + elif (Length(paulis) == 2) { + within { + MapPauli(qubits[1], paulis[0], paulis[1]); + } + apply { + if (paulis[0] == PauliX) { + IsingXX(theta / 2.0, qubits[0], qubits[1]); + } elif (paulis[0] == PauliY) { + IsingYY(theta / 2.0, qubits[0], qubits[1]); + } elif (paulis[0] == PauliZ) { + IsingZZ(theta / 2.0, qubits[0], qubits[1]); + } else { + fail "Type2 decompositions do not support PauliI"; + } + } + } + else { // Length(paulis) > 2 + within { + for (i in 0 .. Length(paulis) - 1) { + MapPauli(qubits[i], PauliZ, paulis[i]); + } + } + apply { + within { + SpreadZ(qubits[1], qubits[2 .. Length(qubits) - 1]); + } + apply { + ExpNoIdUtil([PauliZ,PauliZ], theta, [qubits[0], qubits[1]], rotation); + } + } + } + } + + internal operation SpreadZ(from : Qubit, to : Qubit[]) : Unit is Adj { + if (Length(to) > 0) { + CNOT(to[0], from); + if (Length(to) > 1) { + let half = Length(to) / 2; + SpreadZ(to[0], to[half + 1 .. Length(to) - 1]); + SpreadZ(from, to[1 .. half]); + } + } + } + + internal operation ApplyGlobalPhase(theta : Double) : Unit is Ctl + Adj { + body(...) {} + controlled(controls, (...)) { + if (Length(controls) > 0) { + let qubit = controls[0]; + let rest = controls[1...]; + // Invoke Controlled R1, which will recursively call back into ApplyGlobalPhase. + // Each time the controls is one shorter, until it is empty and the recursion stops. + Controlled R1(rest, (theta, qubit)); + } + } + } + + internal operation ApplyGlobalPhaseFracWithR1Frac(numerator : Int, power : Int) : Unit is Adj + Ctl { + body(...) {} + controlled(ctrls, ... ) { + let numControls = Length(ctrls); + if (numControls > 0 ) { + // Invoke Controlled R1Frac, which will recursively call back into ApplyGlobalPhase. + // Each time the controls is one shorter, until it is empty and the recursion stops. + Controlled R1Frac(ctrls[1 .. numControls - 1], (numerator, power, ctrls[0])); + } + } + } + + internal operation MapPauli(qubit : Qubit, from : Pauli, to : Pauli) : Unit is Adj { + if (from == to) { + } + elif ((from == PauliZ and to == PauliX) or (from == PauliX and to == PauliZ)) { + H(qubit); + } + elif (from == PauliZ and to == PauliY) { + H(qubit); + S(qubit); + H(qubit); + } + elif (from == PauliY and to == PauliZ) { + H(qubit); + Adjoint S(qubit); + H(qubit); + } + elif (from == PauliY and to == PauliX) { + S(qubit); + } + elif (from == PauliX and to == PauliY) { + Adjoint S(qubit); + } + else { + fail "Unsupported input"; + } + } + + internal function ReducedDyadicFraction(numerator : Int, denominatorPowerOfTwo : Int) : (Int,Int) { + if (numerator == 0) { return (0,0); } + mutable num = numerator; + mutable denPow = denominatorPowerOfTwo; + while(num % 2 == 0) { + set num /= 2; + set denPow += 1; + } + return (num,denPow); + } + + internal function ReducedDyadicFractionPeriodic(numerator : Int, denominatorPowerOfTwo : Int) : (Int,Int) { + let (k,n) = ReducedDyadicFraction(numerator,denominatorPowerOfTwo); // k is odd, or (k,n) are both 0 + let period = 2*2^n; // \pi k / 2^n is 2\pi periodic, therefore k is 2 * 2^n periodic + let kMod = k % period; // if k was negative, we get kMod in a range [-period + 1, 0] + let kModPositive = kMod >= 0 ? kMod | kMod + period; // kModPositive is in the range [0, period - 1] + return (kModPositive, n); + } + + internal function ArrayFromIndiciesP(values : Pauli[], indicies : Int[]) : Pauli[] { + mutable arr = new Pauli[Length(indicies)]; + for (i in 0 .. Length(indicies) - 1) { + set arr w/= i <- values[indicies[i]]; + } + return arr; + } + + internal function ArrayFromIndiciesQ(values : Qubit[], indicies : Int[]) : Qubit[] { + mutable arr = new Qubit[Length(indicies)]; + for (i in 0 .. Length(indicies) - 1) { + set arr w/= i <- values[indicies[i]]; + } + return arr; + } + + internal function IndicesOfNonIdentity(paulies : Pauli[]) : Int[] { + mutable nonIdPauliCount = 0; + + for (i in 0 .. Length(paulies) - 1) { + if (paulies[i] != PauliI) { set nonIdPauliCount += 1; } + } + + mutable indices = new Int[nonIdPauliCount]; + mutable index = 0; + + for (i in 0 .. Length(paulies) - 1) { + if (paulies[i] != PauliI) { + set indices w/= index <- i; + set index = index + 1; + } + } + + return indices; + } + + internal function RemovePauliI(paulis : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) { + let indices = IndicesOfNonIdentity(paulis); + let newPaulis = ArrayFromIndiciesP(paulis, indices); + let newQubits = ArrayFromIndiciesQ(qubits, indices); + return (newPaulis, newQubits); + } + +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs b/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs index 0d008f67b25..df58c4a3f3c 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Exp.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the exponential of a multi-qubit Pauli operator. /// @@ -21,6 +23,7 @@ namespace Microsoft.Quantum.Intrinsic { /// target register is to be rotated. /// ## qubits /// Register to apply the given rotation to. + @EnableTestingViaName("Test.TargetDefinitions.Exp") operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/H.qs b/src/Simulation/TargetDefinitions/Intrinsic/H.qs index 25a12838d32..740796ddd0b 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/H.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/H.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the Hadamard transformation to a single qubit. /// @@ -18,6 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.H") operation H (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/I.qs b/src/Simulation/TargetDefinitions/Intrinsic/I.qs index 57a0a1d3125..39ddebc3797 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/I.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/I.qs @@ -2,12 +2,15 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Performs the identity operation (no-op) on a single qubit. /// /// # Remarks /// This is a no-op. It is provided for completeness and because /// sometimes it is useful to call the identity in an algorithm or to pass it as a parameter. + @EnableTestingViaName("Test.TargetDefinitions.I") operation I (target : Qubit) : Unit is Adj + Ctl { body (...) { } adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs new file mode 100644 index 00000000000..ec0982cc567 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Ising $XX$ gate. + /// + /// TODO - describe XX gate. + /// + /// # Input + /// ## theta + /// The angle about which the qubits are rotated. + /// ## qubit0 + /// The first qubit input to the gate. + /// ## qubit1 + /// The second qubit input to the gate. + @EnableTestingViaName("Test.TargetDefinitions.IsingXX") + operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Ctl { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs new file mode 100644 index 00000000000..2dd8f87298a --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Ising $YY$ gate. + /// + /// TODO - describe YY gate. + /// + /// # Input + /// ## theta + /// The angle about which the qubits are rotated. + /// ## qubit0 + /// The first qubit input to the gate. + /// ## qubit1 + /// The second qubit input to the gate. + @EnableTestingViaName("Test.TargetDefinitions.IsingYY") + operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Ctl { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs new file mode 100644 index 00000000000..47873fbe97b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Ising $ZZ$ gate. + /// + /// TODO - describe ZZ gate. + /// + /// # Input + /// ## theta + /// The angle about which the qubits are rotated. + /// ## qubit0 + /// The first qubit input to the gate. + /// ## qubit1 + /// The second qubit input to the gate. + @EnableTestingViaName("Test.TargetDefinitions.IsingZZ") + operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Ctl { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/M.qs b/src/Simulation/TargetDefinitions/Intrinsic/M.qs new file mode 100644 index 00000000000..7c44f88a5d1 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/M.qs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Performs a measurement of a single qubit in the + /// Pauli $Z$ basis. + /// + /// # Description + /// The output result is given by + /// the distribution + /// \begin{align} + /// \Pr(\texttt{Zero} | \ket{\psi}) = + /// \braket{\psi | 0} \braket{0 | \psi}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to be measured. + /// + /// # Output + /// `Zero` if the $+1$ eigenvalue is observed, and `One` if + /// the $-1$ eigenvalue is observed. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// Measure([PauliZ], [qubit]); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.M") + operation M (qubit : Qubit) : Result { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs b/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs index 957726d85da..ada792ca5f4 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Measure.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Performs a joint measurement of one or more qubits in the /// specified Pauli bases. @@ -37,6 +39,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Remarks /// If the basis array and qubit array are different lengths, then the /// operation will fail. + @EnableTestingViaName("Test.TargetDefinitions.Measure") operation Measure (bases : Pauli[], qubits : Qubit[]) : Result { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/R.qs b/src/Simulation/TargetDefinitions/Intrinsic/R.qs index ff64e63631b..8deee174ebb 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/R.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/R.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies a rotation about the given Pauli axis. /// @@ -24,6 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { /// When called with `pauli = PauliI`, this operation applies /// a *global phase*. This phase can be significant /// when used with the `Controlled` functor. + @EnableTestingViaName("Test.TargetDefinitions.R") operation R (pauli : Pauli, theta : Double, qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Rx.qs b/src/Simulation/TargetDefinitions/Intrinsic/Rx.qs new file mode 100644 index 00000000000..20aa42633b7 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/Rx.qs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies a rotation about the $x$-axis by a given angle. + /// + /// # Description + /// \begin{align} + /// R_x(\theta) \mathrel{:=} + /// e^{-i \theta \sigma_x / 2} = + /// \begin{bmatrix} + /// \cos \frac{\theta}{2} & -i\sin \frac{\theta}{2} \\\\ + /// -i\sin \frac{\theta}{2} & \cos \frac{\theta}{2} + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## theta + /// Angle about which the qubit is to be rotated. + /// ## qubit + /// Qubit to which the gate should be applied. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// R(PauliX, theta, qubit); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.Rx") + operation Rx (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Ry.qs b/src/Simulation/TargetDefinitions/Intrinsic/Ry.qs new file mode 100644 index 00000000000..e8df5d1fe88 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/Ry.qs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies a rotation about the $y$-axis by a given angle. + /// + /// # Description + /// \begin{align} + /// R_y(\theta) \mathrel{:=} + /// e^{-i \theta \sigma_y / 2} = + /// \begin{bmatrix} + /// \cos \frac{\theta}{2} & -\sin \frac{\theta}{2} \\\\ + /// \sin \frac{\theta}{2} & \cos \frac{\theta}{2} + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## theta + /// Angle about which the qubit is to be rotated. + /// ## qubit + /// Qubit to which the gate should be applied. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// R(PauliY, theta, qubit); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.Ry") + operation Ry (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Rz.qs b/src/Simulation/TargetDefinitions/Intrinsic/Rz.qs new file mode 100644 index 00000000000..ca7c2d4d74c --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/Rz.qs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies a rotation about the $z$-axis by a given angle. + /// + /// # Description + /// \begin{align} + /// R_z(\theta) \mathrel{:=} + /// e^{-i \theta \sigma_z / 2} = + /// \begin{bmatrix} + /// e^{-i \theta / 2} & 0 \\\\ + /// 0 & e^{i \theta / 2} + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## theta + /// Angle about which the qubit is to be rotated. + /// ## qubit + /// Qubit to which the gate should be applied. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// R(PauliZ, theta, qubit); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.Rz") + operation Rz (theta : Double, qubit : Qubit) : Unit is Adj + Ctl { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/S.qs b/src/Simulation/TargetDefinitions/Intrinsic/S.qs index e30b637d086..816c8771b31 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/S.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/S.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the π/4 phase gate to a single qubit. /// @@ -17,6 +19,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.S") operation S (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs b/src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs new file mode 100644 index 00000000000..9b9c80138ed --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/SWAP.qs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the SWAP gate to a pair of qubits. + /// + /// # Description + /// \begin{align} + /// \operatorname{SWAP} \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 & 0 & 0 \\\\ + /// 0 & 0 & 1 & 0 \\\\ + /// 0 & 1 & 0 & 0 \\\\ + /// 0 & 0 & 0 & 1 + /// \end{bmatrix}, + /// \end{align} + /// + /// where rows and columns are ordered as in the quantum concepts guide. + /// + /// # Input + /// ## qubit1 + /// First qubit to be swapped. + /// ## qubit2 + /// Second qubit to be swapped. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// CNOT(qubit1, qubit2); + /// CNOT(qubit2, qubit1); + /// CNOT(qubit1, qubit2); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.SWAP") + operation SWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit is Adj + Ctl { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/T.qs b/src/Simulation/TargetDefinitions/Intrinsic/T.qs index 287ec3087bc..dc3affe449a 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/T.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/T.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the π/8 gate to a single qubit. /// @@ -17,6 +19,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.T") operation T (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/X.qs b/src/Simulation/TargetDefinitions/Intrinsic/X.qs index 522592f537a..8b5f8feb62b 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/X.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/X.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the Pauli $X$ gate. /// @@ -17,6 +19,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.X") operation X (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Y.qs b/src/Simulation/TargetDefinitions/Intrinsic/Y.qs index 91769077adc..92b28478843 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Y.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Y.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the Pauli $Y$ gate. /// @@ -17,6 +19,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.Y") operation Y (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Z.qs b/src/Simulation/TargetDefinitions/Intrinsic/Z.qs index 9d505596f15..a05f34c60c8 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Z.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Z.qs @@ -2,6 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + /// # Summary /// Applies the Pauli $Z$ gate. /// @@ -17,6 +19,7 @@ namespace Microsoft.Quantum.Intrinsic { /// # Input /// ## qubit /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.Z") operation Z (qubit : Qubit) : Unit is Adj + Ctl { body intrinsic; adjoint self; diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props new file mode 100644 index 00000000000..a49fe647e5c --- /dev/null +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj new file mode 100644 index 00000000000..83acdd5914f --- /dev/null +++ b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj @@ -0,0 +1,47 @@ + + + + + + + + + netstandard2.1 + true + false + false + + + + Microsoft + Type2 Targeting support for the Q# programming language. + See: https://docs.microsoft.com/en-us/quantum/relnotes/ + MIT + https://github.com/microsoft/qsharp-runtime + qdk-nuget-icon.png + Quantum Q# Qsharp + true + + + + + + + + + + + + + + + + + + + + + + + + From 9a6e145f448aeefafcc6923f9b27a3e7980e3e02 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 21 Aug 2020 11:07:51 -0700 Subject: [PATCH 03/17] Clean up compilation and project references --- .../CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj | 2 -- .../Microsoft.Quantum.EntryPointDriver.csproj | 1 - src/Simulation/Simulators.Tests/DebuggingToolsTests.cs | 8 ++++---- .../TestProjects/IntrinsicTests/IntrinsicTests.csproj | 1 - .../TestProjects/TargetedExe/TargetedExe.csproj | 1 - .../TestProjects/UnitTests/UnitTests.csproj | 1 - 6 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj index 906f812078b..d5ee8e1add2 100644 --- a/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj @@ -51,9 +51,7 @@ - - diff --git a/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj b/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj index a506e16a6f9..3c13f0f8c65 100644 --- a/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj +++ b/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj @@ -26,7 +26,6 @@ - diff --git a/src/Simulation/Simulators.Tests/DebuggingToolsTests.cs b/src/Simulation/Simulators.Tests/DebuggingToolsTests.cs index 279a6185f00..0ef42022ab6 100644 --- a/src/Simulation/Simulators.Tests/DebuggingToolsTests.cs +++ b/src/Simulation/Simulators.Tests/DebuggingToolsTests.cs @@ -23,7 +23,7 @@ public void ToStringTests() => Helper.RunWithMultipleSimulators(qsim => { var _ = AbstractCallable._; - var dump = qsim.Get(typeof(Microsoft.Quantum.Extensions.Diagnostics.DumpMachine<>)); + var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)); var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)); var x = qsim.Get(); var q2 = new FreeQubit(2) as Qubit; @@ -223,7 +223,7 @@ public void GenericDebuggerProxy() { Helper.RunWithMultipleSimulators((qsim) => { - var dump = qsim.Get(typeof(Microsoft.Quantum.Extensions.Diagnostics.DumpMachine<>)) as GenericCallable; + var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable; var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)) as GenericCallable; var gen3 = qsim.Get(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable; @@ -231,7 +231,7 @@ public void GenericDebuggerProxy() TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Adjoint, "T => () : Adjoint, Controlled", trace.Adjoint); TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Controlled, "(Qubit[],T) => () : Adjoint, Controlled", trace.Controlled); TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.ControlledAdjoint, "(Qubit[],T) => () : Adjoint, Controlled", trace.Adjoint.Controlled); - TestOneProxy("DumpMachine", "Microsoft.Quantum.Extensions.Diagnostics.DumpMachine", OperationFunctor.Body, "T => ()", dump); + TestOneProxy("DumpMachine", "Microsoft.Quantum.Diagnostics.DumpMachine", OperationFunctor.Body, "T => ()", dump); TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Body, "(__T1,(__T2,__T3),Result) => () : Controlled", gen3); TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Controlled, "(Qubit[],(__T1,(__T2,__T3),Result)) => () : Controlled", gen3.Controlled); }); @@ -252,7 +252,7 @@ public void GenericPartialDebuggerProxy() { var _ = AbstractCallable._; - var dump = qsim.Get(typeof(Microsoft.Quantum.Extensions.Diagnostics.DumpMachine<>)) as GenericCallable; + var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable; var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)) as GenericCallable; var gen3 = qsim.Get(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable; diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj index 4fbf6b19d13..559956d7379 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -11,7 +11,6 @@ - diff --git a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj index f70061d4f60..96d0c0648c2 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj index ee89aad55fd..4f409e6eb3d 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -11,7 +11,6 @@ - From 439f760ab0538412f0063477e1ac7a74b8dd673b Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 21 Aug 2020 23:53:24 -0700 Subject: [PATCH 04/17] Only generate C# for reference when using testname This change makse it so that C# generation for references that have a test name attribute only happens when loading via test names is requested. --- src/Simulation/CsharpGeneration/Context.fs | 5 +++++ src/Simulation/CsharpGeneration/SimulationCode.fs | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Simulation/CsharpGeneration/Context.fs b/src/Simulation/CsharpGeneration/Context.fs index fa80c982c4f..514a7636577 100644 --- a/src/Simulation/CsharpGeneration/Context.fs +++ b/src/Simulation/CsharpGeneration/Context.fs @@ -119,6 +119,11 @@ type CodegenContext = { | true, name -> name | false, _ -> null + member public this.ExposeReferencesViaTestNames = + match this.assemblyConstants.TryGetValue AssemblyConstants.ExposeReferencesViaTestNames with + | true, propVal -> propVal = "true" + | false, _ -> false + member internal this.GenerateCodeForSource (fileName : NonNullable) = let targetsQuantumProcessor = match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with diff --git a/src/Simulation/CsharpGeneration/SimulationCode.fs b/src/Simulation/CsharpGeneration/SimulationCode.fs index dd853127c13..72a71a5e444 100644 --- a/src/Simulation/CsharpGeneration/SimulationCode.fs +++ b/src/Simulation/CsharpGeneration/SimulationCode.fs @@ -1619,13 +1619,15 @@ module SimulationCode = /// Builds the SyntaxTree for callables and types loaded via test names, /// formats it and returns it as a string. /// Returns null if no elements have been loaded via test name. - let loadedViaTestNames (dllName : NonNullable) globalContext = + let loadedViaTestNames (dllName : NonNullable) (globalContext : CodegenContext) = let isLoadedViaTestName nsElement = - let asOption = function | Value _ -> Some nsElement | _ -> None - match nsElement with - | QsCallable c as e -> SymbolResolution.TryGetTestName c.Attributes - | QsCustomType t as e -> SymbolResolution.TryGetTestName t.Attributes - |> asOption + if globalContext.ExposeReferencesViaTestNames then + let asOption = function | Value _ -> Some nsElement | _ -> None + match nsElement with + | QsCallable c as e -> SymbolResolution.TryGetTestName c.Attributes + | QsCustomType t as e -> SymbolResolution.TryGetTestName t.Attributes + |> asOption + else None let context = {globalContext with fileName = Some dllName.Value} let localElements = findLocalElements isLoadedViaTestName dllName context.allQsElements From e467de5dc18e83e4cf95b8eef457022787dec90c Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sat, 22 Aug 2020 13:59:06 -0700 Subject: [PATCH 05/17] Update compiler version --- NOTICE.txt | 2 +- .../CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj | 2 +- ....Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj | 2 +- src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj | 2 +- .../TestProjects/HoneywellExe/HoneywellExe.csproj | 2 +- .../TestProjects/IntrinsicTests/IntrinsicTests.csproj | 2 +- .../Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj | 2 +- .../TestProjects/Library with Spaces/Library with Spaces.csproj | 2 +- .../Simulators.Tests/TestProjects/Library1/Library1.csproj | 2 +- .../Simulators.Tests/TestProjects/Library2/Library2.csproj | 2 +- .../Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj | 2 +- .../Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj | 2 +- .../TestProjects/TargetedExe/TargetedExe.csproj | 2 +- .../Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj | 2 +- .../Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj | 2 +- src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 98ac8599c49..ea1fd3063d2 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -2715,7 +2715,7 @@ SOFTWARE. ------------------------------------------------------------------- -Microsoft.Quantum.Compiler 0.12.20072031 - MIT +Microsoft.Quantum.Compiler 0.12.20082209-beta - MIT (c) 2008 VeriSign, Inc. diff --git a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj index dddbbf8c3bb..65b75b2e1df 100644 --- a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj @@ -21,7 +21,7 @@ - + diff --git a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj index 74cf526a2da..a7d91377dcd 100644 --- a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj +++ b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index 3b0fe3f8c55..aa696216086 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj index 2556f1ae507..cb464f8c01d 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj index 559956d7379..17e02f7bfaa 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj index c625e48ab23..a7745b792ef 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj index f8f5cffa07f..6cce3506ac6 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 false diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj index 2714be57fcf..426f60111e2 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj index 2714be57fcf..426f60111e2 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj index dce291568b6..3bee22e3534 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj index 6ac84ace635..d6401020995 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj index 96d0c0648c2..e0d76a09805 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj index 4f409e6eb3d..010df093fd2 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj index 01ba825325e..ed018f6a6f2 100644 --- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj index 794bb15909b..ef8c2bb42b6 100644 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + From d707aae73b0adc3b8d8c458e988df54712929887 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sat, 22 Aug 2020 15:46:02 -0700 Subject: [PATCH 06/17] Add Type2 to the solution --- Simulation.sln | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Simulation.sln b/Simulation.sln index f3e268e45ec..15ef1f55baf 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -71,6 +71,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulation", "Simulation", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.QSharp.Foundation", "src\Simulation\QsharpFoundation\Microsoft.Quantum.QSharp.Foundation.csproj", "{DB45AD73-4D91-43F3-85CC-C63614A96FB0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Type2.Core", "src\Simulation\Type2Core\Microsoft.Quantum.Type2.Core.csproj", "{AF6CD304-8E03-433D-AAA2-6E0094B53071}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -499,6 +501,22 @@ Global {DB45AD73-4D91-43F3-85CC-C63614A96FB0}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU {DB45AD73-4D91-43F3-85CC-C63614A96FB0}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU {DB45AD73-4D91-43F3-85CC-C63614A96FB0}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|x64.ActiveCfg = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Debug|x64.Build.0 = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|Any CPU.Build.0 = Release|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|x64.ActiveCfg = Release|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.Release|x64.Build.0 = Release|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -532,6 +550,7 @@ Global {D292BF18-3956-4827-820E-254C3F81EF09} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820} {9008B252-2DF7-404B-B626-D4497BB70A05} = {BC562DAE-FE2B-4A8C-880C-C546F83F99E4} {DB45AD73-4D91-43F3-85CC-C63614A96FB0} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {AF6CD304-8E03-433D-AAA2-6E0094B53071} = {9008B252-2DF7-404B-B626-D4497BB70A05} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821} From c4887d6b13ee0683936a1e7d6ca8119f15e63655 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sat, 22 Aug 2020 16:44:56 -0700 Subject: [PATCH 07/17] Separate out QsharpCore Simulator --- Simulation.sln | 2 +- bootstrap.ps1 | 2 +- src/Simulation/Common/Simulators.Dev.props | 2 +- .../Tests.CsharpGeneration.fsproj | 2 +- .../Microsoft.Quantum.EntryPointDriver.csproj | 2 +- ...Microsoft.Quantum.QSharp.Foundation.csproj | 2 +- .../.gitignore | 0 .../FindNuspecReferences.ps1 | 2 +- .../Microsoft.Quantum.Simulators.csproj | 77 +++++++++++++++++++ ...crosoft.Quantum.Simulators.nuspec.template | 0 .../IntrinsicTests/IntrinsicTests.csproj | 2 +- .../TestProjects/UnitTests/UnitTests.csproj | 2 +- .../Microsoft.Quantum.Simulators.csproj | 45 ----------- .../Microsoft.Quantum.Type2.Core.csproj | 2 +- 14 files changed, 87 insertions(+), 55 deletions(-) rename src/Simulation/{Simulators => Simulators.Core}/.gitignore (100%) rename src/Simulation/{Simulators => Simulators.Core}/FindNuspecReferences.ps1 (97%) create mode 100644 src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj rename src/Simulation/{Simulators => Simulators.Core}/Microsoft.Quantum.Simulators.nuspec.template (100%) delete mode 100644 src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj diff --git a/Simulation.sln b/Simulation.sln index 15ef1f55baf..760bd1cd969 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.Simulatio EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.Simulation.Common", "src\Simulation\Common\Microsoft.Quantum.Simulation.Common.csproj", "{8EC46ADB-7FAA-49EA-BA63-E7B32C4F4445}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.Simulators", "src\Simulation\Simulators\Microsoft.Quantum.Simulators.csproj", "{72B7E75C-D305-45BD-929E-C86298AAA8DE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.Simulators", "src\Simulation\Simulators.Core\Microsoft.Quantum.Simulators.csproj", "{72B7E75C-D305-45BD-929E-C86298AAA8DE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime", "src\Simulation\QCTraceSimulator.Tests\Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj", "{DD50D2D9-2765-449B-8C4B-835A428E160D}" EndProject diff --git a/bootstrap.ps1 b/bootstrap.ps1 index 861a83f3f34..412e07618a8 100644 --- a/bootstrap.ps1 +++ b/bootstrap.ps1 @@ -7,7 +7,7 @@ Push-Location (Join-Path $PSScriptRoot "src/Simulation/CsharpGeneration") .\FindNuspecReferences.ps1 Pop-Location -Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators") +Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators.Core") .\FindNuspecReferences.ps1 Pop-Location diff --git a/src/Simulation/Common/Simulators.Dev.props b/src/Simulation/Common/Simulators.Dev.props index 7c44b437a38..ee61a11c722 100644 --- a/src/Simulation/Common/Simulators.Dev.props +++ b/src/Simulation/Common/Simulators.Dev.props @@ -23,7 +23,7 @@ - + diff --git a/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj index d5ee8e1add2..4e83f9f6035 100644 --- a/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration.Tests/Tests.CsharpGeneration.fsproj @@ -52,7 +52,7 @@ - + diff --git a/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj b/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj index 3c13f0f8c65..e78cf42f721 100644 --- a/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj +++ b/src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriver.csproj @@ -26,7 +26,7 @@ - + diff --git a/src/Simulation/QsharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj b/src/Simulation/QsharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj index f1400e76f30..48a339e16d8 100644 --- a/src/Simulation/QsharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj +++ b/src/Simulation/QsharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators/.gitignore b/src/Simulation/Simulators.Core/.gitignore similarity index 100% rename from src/Simulation/Simulators/.gitignore rename to src/Simulation/Simulators.Core/.gitignore diff --git a/src/Simulation/Simulators/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Core/FindNuspecReferences.ps1 similarity index 97% rename from src/Simulation/Simulators/FindNuspecReferences.ps1 rename to src/Simulation/Simulators.Core/FindNuspecReferences.ps1 index 993f4b0948e..c65fe6d7d6d 100644 --- a/src/Simulation/Simulators/FindNuspecReferences.ps1 +++ b/src/Simulation/Simulators.Core/FindNuspecReferences.ps1 @@ -97,7 +97,7 @@ function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) # Find all dependencies packaged as part of Microsoft.Quantum.Simulators Add-NuGetDependencyFromCsprojToNuspec "../QCTraceSimulator/Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj" # has a dependency on Common, need to list this because it is listed only in an imported props file ... -Add-NuGetDependencyFromCsprojToNuspec "../Simulators/Microsoft.Quantum.Simulators.csproj" +Add-NuGetDependencyFromCsprojToNuspec "Microsoft.Quantum.Simulators.csproj" # Save into .nuspec file: $nuspec.package.metadata.AppendChild($dep) diff --git a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj new file mode 100644 index 00000000000..0614096fa5f --- /dev/null +++ b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj @@ -0,0 +1,77 @@ + + + + + + + + netstandard2.1 + false + false + + + + 8.0 + enable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + runtimes\win-x64\native\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + false + + + runtimes\osx-x64\native\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + false + + + runtimes\linux-x64\native\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + false + + + + diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.nuspec.template b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec.template similarity index 100% rename from src/Simulation/Simulators/Microsoft.Quantum.Simulators.nuspec.template rename to src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec.template diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj index 17e02f7bfaa..b04dbe95ef3 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj index 010df093fd2..ad0471edaec 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj deleted file mode 100644 index ef8c2bb42b6..00000000000 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - netstandard2.1 - false - false - - - - 8.0 - enable - - - - - - - - - - - - - - runtimes\win-x64\native\%(RecursiveDir)%(FileName)%(Extension) - PreserveNewest - false - - - runtimes\osx-x64\native\%(RecursiveDir)%(FileName)%(Extension) - PreserveNewest - false - - - runtimes\linux-x64\native\%(RecursiveDir)%(FileName)%(Extension) - PreserveNewest - false - - - - diff --git a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj index 83acdd5914f..ac0bc289697 100644 --- a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj +++ b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj @@ -1,4 +1,4 @@ - + From 2d0dff00d115ffd10c35cb7259ae443d13ce3ade Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sat, 22 Aug 2020 18:26:41 -0700 Subject: [PATCH 08/17] Remove core simulator support for non-intrinsics --- .../Simulators.Core/Microsoft.Quantum.Simulators.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj index 0614096fa5f..42575509cad 100644 --- a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj @@ -23,14 +23,12 @@ - - From 3991ddffd1ad72794fd29f2d457985b2a763a3b1 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sat, 22 Aug 2020 20:19:33 -0700 Subject: [PATCH 09/17] Fixing core simulator packaging --- build/pack.ps1 | 2 +- .../Microsoft.Quantum.Simulators.csproj | 2 -- .../Microsoft.Quantum.Simulators.nuspec.template | 12 ++++++------ .../Properties/AssemblyInfo.cs | 0 4 files changed, 7 insertions(+), 9 deletions(-) rename src/Simulation/{Simulators => Simulators.Core}/Properties/AssemblyInfo.cs (100%) diff --git a/build/pack.ps1 b/build/pack.ps1 index 8bad978434d..d2418f08729 100644 --- a/build/pack.ps1 +++ b/build/pack.ps1 @@ -66,7 +66,7 @@ Pack-Dotnet '../src/Simulation/EntryPointDriver/Microsoft.Quantum.EntryPointDriv Pack-Dotnet '../src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj' Pack-Dotnet '../src/Simulation/QSharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj' Pack-Dotnet '../src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj' -Pack-One '../src/Simulation/Simulators/Microsoft.Quantum.Simulators.nuspec' +Pack-One '../src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec' Pack-One '../src/Quantum.Development.Kit/Microsoft.Quantum.Development.Kit.nuspec' Pack-One '../src/Xunit/Microsoft.Quantum.Xunit.csproj' diff --git a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj index 42575509cad..6e1dbfb848e 100644 --- a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj @@ -21,7 +21,6 @@ - @@ -38,7 +37,6 @@ - diff --git a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec.template b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec.template index a6b1ee3819e..3335cefd51b 100644 --- a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec.template +++ b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec.template @@ -20,12 +20,12 @@ - - - - - - + + + + + + diff --git a/src/Simulation/Simulators/Properties/AssemblyInfo.cs b/src/Simulation/Simulators.Core/Properties/AssemblyInfo.cs similarity index 100% rename from src/Simulation/Simulators/Properties/AssemblyInfo.cs rename to src/Simulation/Simulators.Core/Properties/AssemblyInfo.cs From 5295ca43e5cecc53b8053be6ad8aa9710494cf3b Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sun, 23 Aug 2020 00:19:32 -0700 Subject: [PATCH 10/17] Type2 simulator and test infrastructure --- .gitignore | 6 +- Simulation.sln | 165 +- ...Microsoft.Quantum.Simulation.Common.csproj | 1 - src/Simulation/Common/QubitManager.cs | 1 - .../Common/Simulators.Type2.Dev.props | 42 + .../Core/Properties/AssemblyInfo.cs | 1 + .../Diagnostics/Facts.qs | 0 .../Diagnostics/Properties/NamespaceInfo.qs | 0 .../Random/Convienence.qs | 0 .../Random/Internal.qs | 0 .../Random/Intrinsic.qs | 0 .../Random/Normal.qs | 0 .../Random/Types.qs | 0 .../Random/Uniform.qs | 0 .../App.config | 0 .../Circuits/AssertEqual.cs | 0 .../Circuits/AssertEqual.qs | 0 .../Circuits/BitOperations.qs | 0 .../Circuits/Bug1514.qs | 0 .../Circuits/Bug2212.qs | 0 .../Circuits/Bug2248.qs | 0 .../Circuits/Bug2469.qs | 0 .../Circuits/Bug3059.qs | 0 .../Circuits/Bug3758.qs | 0 .../Circuits/CallableInterfacesTest.qs | 0 .../Circuits/ClassicalRotationsTest.qs | 0 .../Circuits/ClosedType.qs | 0 .../Circuits/ConditionalExpression.qs | 0 .../Circuits/Convert.qs | 0 .../Circuits/CoreOperations.qs | 0 .../Circuits/ExpTest.qs | 0 .../Circuits/Fail.qs | 0 .../Circuits/Functions.qs | 0 .../Circuits/Generics.qs | 0 .../Circuits/GetAvailableTest.qs | 0 .../Circuits/Issue132.qs | 0 .../Circuits/Issue76.qs | 0 .../Circuits/JointMeasureTest.qs | 0 .../Circuits/Length.qs | 0 .../Circuits/NamedItems.qs | 0 .../Circuits/Namespaces.qs | 0 .../Circuits/NativeOperations.cs | 0 .../Circuits/NativeOperations.qs | 0 .../Circuits/PrimitiveEquivalences.qs | 0 .../Circuits/Recursion.qs | 0 .../Circuits/RepeatUntilSuccess.qs | 0 .../Circuits/ResourcesEstimator.qs | 0 .../Circuits/RuntimeMetadataTest.qs | 0 .../Circuits/SetQubit.qs | 0 .../Circuits/StartOperation.qs | 0 .../Circuits/SwapTest.qs | 0 .../Circuits/TeleportTest.qs | 0 .../Circuits/Tuples.qs | 0 .../Circuits/UnitTests.qs | 0 .../Circuits/UserDefinedTypes.qs | 0 .../Circuits/VerifyUnitary.qs | 0 .../Circuits/bug3223.qs | 0 .../CoreTests.cs | 0 .../DebuggingToolsTests.cs | 0 .../DiagnosticsWrappers.qs | 0 .../GenericsTests.cs | 0 .../GetQubitsTests.cs | 0 .../NativeOperationsTests.cs | 0 .../OperationsTestHelper.cs | 0 .../PartialMapperTests.cs | 0 .../PrimitivesExtensionsTests.cs | 0 .../QArrayTests.cs | 0 .../QCTraceSimulatorPrimitivesTests.cs | 0 .../InterfaceImpl.qs | 0 .../OneQubitOperationsTests.qs | 0 .../ThreePlusQubitOperationsTests.qs | 0 .../TwoQubitOperationsTests.qs | 0 .../QTupleTests.cs | 0 .../QuantumSimulatorTests/BasicTests.cs | 0 .../QuantumSimulatorTests/CircuitsTests.cs | 0 .../QuantumSimulatorTests/QubitReleaseTest.cs | 0 .../QuantumSimulatorTests/VerifyGates.cs | 0 .../QuantumTestSuite.cs | 0 .../QuantumTestSuite/AssertEqualInPlace.qs | 0 .../AssertProbAndCliffordOneQubitTest.qs | 0 .../AssertProbAndMeasureOneQubitTest.qs | 0 .../QuantumTestSuite/AssertProbMultiQubit.qs | 0 .../QuantumTestSuite/AssertProbOneQubit.qs | 0 .../QuantumTestSuite/AssertQubitUnitary.qs | 0 .../QuantumTestSuite/AssertState.qs | 0 .../QuantumTestSuite/AssertUnitary.qs | 0 .../QuantumTestSuite/Complex.qs | 0 .../QuantumTestSuite/Config.qs | 0 .../ControlledOperationTester.qs | 0 .../ControlledOperationsTestUtils.qs | 0 .../IterateThroughCartesianProduct.qs | 0 .../QuantumTestSuite/JointOneQubitTests.qs | 0 .../QuantumTestSuite/KnownIssues.qs | 0 .../QuantumTestSuite/LinearAlgebra.qs | 0 .../QuantumTestSuite/ManyControlQubitsTest.qs | 0 .../QuantumTestSuite/Math.qs | 0 .../QuantumTestSuite/Matrices.qs | 0 .../QuantumTestSuite/OneQubitTestList.qs | 0 .../QuantumTestSuite/OneQubitUnitaries.qs | 0 .../QuantumTestSuite/PauliExpectation.qs | 0 .../QuantumTestSuite/SelfTests.qs | 0 .../QuantumTestSuite/TestSuiteCalculations.nb | 0 .../QuantumTestSuite/ThreeQubitUnitaries.qs | 0 .../QuantumTestSuite/TwoQubitUnitaries.qs | 0 .../QubitManagerTests.cs | 0 .../RangeTests.cs | 0 .../ResourcesEstimatorTests.cs | 8 +- .../RuntimeMetadataTests.cs | 0 .../SimulatorBaseTests.cs | 0 .../StackTraceTests.cs | 0 .../StartOperationTests.cs | 0 .../ClassicallyControlledSupportTests.qs | 0 .../HoneywellExe/HoneywellExe.csproj | 0 .../HoneywellExe/MeasurementSupportTests.qs | 0 .../IntrinsicTests/IntrinsicTests.csproj | 1 - .../IntrinsicTests/Random/Tests.qs | 0 .../TestProjects/IonQExe/IonQExe.csproj | 0 .../IonQExe/MeasurementSupportTests.qs | 0 .../Library with Spaces.csproj | 0 .../Library with Spaces/Library.qs | 0 .../TestProjects/Library1/Library.qs | 0 .../TestProjects/Library1/Library1.csproj | 0 .../TestProjects/Library2/Library.qs | 0 .../TestProjects/Library2/Library2.csproj | 0 .../ClassicallyControlledSupportTests.qs | 0 .../QCIExe/MeasurementSupportTests.qs | 0 .../TestProjects/QCIExe/QCIExe.csproj | 0 .../TestProjects/QsharpExe/Main.qs | 0 .../TestProjects/QsharpExe/QsharpExe.csproj | 0 .../TestProjects/TargetedExe/Program.qs | 0 .../TargetedExe/TargetedExe.csproj | 0 .../TestProjects/UnitTests/Facts.qs | 0 .../TestProjects/UnitTests/Hello.qs | 30 +- .../UnitTests/HoneywellSimulation.qs | 96 +- .../TestProjects/UnitTests/IonQSimulation.qs | 0 .../TestProjects/UnitTests/QCISimulation.qs | 96 +- .../TestProjects/UnitTests/SpaceTests.qs | 0 .../TestProjects/UnitTests/TestNameTests.qs | 0 .../TestProjects/UnitTests/UnitTests.csproj | 0 .../Tests.Microsoft.Quantum.Simulators.csproj | 0 .../ToffoliSimulatorTests.cs | 0 .../TrivialSimulator.cs | 0 .../TypeExtensionsTest.cs | 0 .../Microsoft.Quantum.Simulators.csproj | 3 + .../Simulators.Type2.Tests/App.config | 6 + .../Circuits/AssertEqual.cs | 24 + .../Circuits/AssertEqual.qs | 12 + .../Circuits/BitOperations.qs | 33 + .../Circuits/Bug1514.qs | 27 + .../Circuits/Bug2212.qs | 29 + .../Circuits/Bug2248.qs | 38 + .../Circuits/Bug2469.qs | 23 + .../Circuits/Bug3059.qs | 35 + .../Circuits/Bug3758.qs | 50 + .../Circuits/CallableInterfacesTest.qs | 138 ++ .../Circuits/ClassicalRotationsTest.qs | 36 + .../Circuits/ClosedType.qs | 203 ++ .../Circuits/ConditionalExpression.qs | 24 + .../Circuits/Convert.qs | 36 + .../Circuits/CoreOperations.qs | 626 +++++ .../Circuits/ExpTest.qs | 32 + .../Simulators.Type2.Tests/Circuits/Fail.qs | 99 + .../Circuits/Functions.qs | 28 + .../Circuits/Generics.qs | 884 ++++++++ .../Circuits/GetAvailableTest.qs | 34 + .../Circuits/Issue132.qs | 25 + .../Circuits/Issue76.qs | 31 + .../Circuits/JointMeasureTest.qs | 43 + .../Simulators.Type2.Tests/Circuits/Length.qs | 33 + .../Circuits/NamedItems.qs | 30 + .../Circuits/Namespaces.qs | 22 + .../Circuits/NativeOperations.cs | 104 + .../Circuits/NativeOperations.qs | 25 + .../Circuits/PrimitiveEquivalences.qs | 113 + .../Circuits/Recursion.qs | 56 + .../Circuits/RepeatUntilSuccess.qs | 46 + .../Circuits/ResourcesEstimator.qs | 60 + .../Circuits/RuntimeMetadataTest.qs | 38 + .../Circuits/SetQubit.qs | 20 + .../Circuits/StartOperation.qs | 152 ++ .../Circuits/SwapTest.qs | 28 + .../Circuits/TeleportTest.qs | 42 + .../Simulators.Type2.Tests/Circuits/Tuples.qs | 81 + .../Circuits/UnitTests.qs | 23 + .../Circuits/UserDefinedTypes.qs | 132 ++ .../Circuits/VerifyUnitary.qs | 107 + .../Circuits/bug3223.qs | 39 + .../Simulators.Type2.Tests/CoreTests.cs | 283 +++ .../DebuggingToolsTests.cs | 293 +++ .../DiagnosticsWrappers.qs | 11 + .../Simulators.Type2.Tests/GenericsTests.cs | 852 +++++++ .../Simulators.Type2.Tests/GetQubitsTests.cs | 395 ++++ .../NativeOperationsTests.cs | 67 + .../OperationsTestHelper.cs | 372 +++ .../PartialMapperTests.cs | 175 ++ .../PrimitivesExtensionsTests.cs | 50 + .../Simulators.Type2.Tests/QArrayTests.cs | 315 +++ .../Simulators.Type2.Tests/QTupleTests.cs | 207 ++ .../QuantumSimulatorTests/BasicTests.cs | 388 ++++ .../QuantumSimulatorTests/CircuitsTests.cs | 27 + .../QuantumSimulatorTests/QubitReleaseTest.cs | 64 + .../QuantumSimulatorTests/VerifyGates.cs | 468 ++++ .../QuantumTestSuite.cs | 79 + .../QuantumTestSuite/AssertEqualInPlace.qs | 117 + .../AssertProbAndCliffordOneQubitTest.qs | 86 + .../AssertProbAndMeasureOneQubitTest.qs | 65 + .../QuantumTestSuite/AssertProbMultiQubit.qs | 100 + .../QuantumTestSuite/AssertProbOneQubit.qs | 48 + .../QuantumTestSuite/AssertQubitUnitary.qs | 55 + .../QuantumTestSuite/AssertState.qs | 61 + .../QuantumTestSuite/AssertUnitary.qs | 53 + .../QuantumTestSuite/Complex.qs | 124 + .../QuantumTestSuite/Config.qs | 49 + .../ControlledOperationTester.qs | 53 + .../ControlledOperationsTestUtils.qs | 74 + .../IterateThroughCartesianProduct.qs | 67 + .../QuantumTestSuite/JointOneQubitTests.qs | 68 + .../QuantumTestSuite/KnownIssues.qs | 59 + .../QuantumTestSuite/LinearAlgebra.qs | 331 +++ .../QuantumTestSuite/ManyControlQubitsTest.qs | 36 + .../QuantumTestSuite/Math.qs | 31 + .../QuantumTestSuite/Matrices.qs | 2004 +++++++++++++++++ .../QuantumTestSuite/OneQubitTestList.qs | 163 ++ .../QuantumTestSuite/OneQubitUnitaries.qs | 28 + .../QuantumTestSuite/PauliExpectation.qs | 93 + .../QuantumTestSuite/SelfTests.qs | 43 + .../QuantumTestSuite/TestSuiteCalculations.nb | 1280 +++++++++++ .../QuantumTestSuite/ThreeQubitUnitaries.qs | 34 + .../QuantumTestSuite/TwoQubitUnitaries.qs | 102 + .../QubitManagerTests.cs | 446 ++++ .../Simulators.Type2.Tests/RangeTests.cs | 174 ++ .../RuntimeMetadataTests.cs | 821 +++++++ .../SimulatorBaseTests.cs | 481 ++++ .../Simulators.Type2.Tests/StackTraceTests.cs | 134 ++ .../StartOperationTests.cs | 190 ++ .../IntrinsicTests/IntrinsicTests.csproj | 30 + .../IntrinsicTests/Random/Tests.qs | 248 ++ .../TestProjects/Library1/Library.qs | 43 + .../TestProjects/Library1/Library1.csproj | 21 + .../TestProjects/Library2/Library.qs | 31 + .../TestProjects/Library2/Library2.csproj | 21 + .../TestProjects/UnitTests/Facts.qs | 37 + .../TestProjects/UnitTests/Hello.qs | 16 + .../TestProjects/UnitTests/TestNameTests.qs | 48 + .../TestProjects/UnitTests/UnitTests.csproj | 32 + ....Microsoft.Quantum.Simulators.Type2.csproj | 52 + .../TrivialSimulator.cs | 43 + .../TypeExtensionsTest.cs | 152 ++ src/Simulation/Simulators.Type2/.gitignore | 1 + .../Simulators.Type2/FindNuspecReferences.ps1 | 103 + .../Microsoft.Quantum.Simulators.Type2.csproj | 74 + ...t.Quantum.Simulators.Type2.nuspec.template | 31 + .../Properties/AssemblyInfo.cs | 9 + .../QuantumSimulator}/Extensions.cs | 0 .../Simulators/QuantumSimulator/IsingXX.cs | 0 .../Simulators/QuantumSimulator/IsingYY.cs | 0 .../Simulators/QuantumSimulator/IsingZZ.cs | 0 .../Simulators/QuantumSimulator/Rx.cs | 0 .../Simulators/QuantumSimulator/Ry.cs | 0 .../Simulators/QuantumSimulator/Rz.cs | 0 .../Simulators/QuantumSimulator/SWAP.cs | 0 .../QuantumSimulator}/SimulatorBase.cs | 0 .../QuantumSimulator}/StackTrace.cs | 0 .../TargetDefinitions/Decompositions/Utils.qs | 14 +- .../TargetPackages/Type2.Package.props | 2 + 265 files changed, 16510 insertions(+), 131 deletions(-) create mode 100644 src/Simulation/Common/Simulators.Type2.Dev.props rename src/Simulation/{QsharpCore => QsharpFoundation}/Diagnostics/Facts.qs (100%) rename src/Simulation/{QsharpCore => QsharpFoundation}/Diagnostics/Properties/NamespaceInfo.qs (100%) rename src/Simulation/{QsharpCore => QsharpFoundation}/Random/Convienence.qs (100%) rename src/Simulation/{QsharpCore => QsharpFoundation}/Random/Internal.qs (100%) rename src/Simulation/{QsharpCore => QsharpFoundation}/Random/Intrinsic.qs (100%) rename src/Simulation/{QsharpCore => QsharpFoundation}/Random/Normal.qs (100%) rename src/Simulation/{QsharpCore => QsharpFoundation}/Random/Types.qs (100%) rename src/Simulation/{QsharpCore => QsharpFoundation}/Random/Uniform.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/App.config (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/AssertEqual.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/AssertEqual.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/BitOperations.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Bug1514.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Bug2212.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Bug2248.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Bug2469.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Bug3059.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Bug3758.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/CallableInterfacesTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/ClassicalRotationsTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/ClosedType.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/ConditionalExpression.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Convert.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/CoreOperations.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/ExpTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Fail.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Functions.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Generics.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/GetAvailableTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Issue132.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Issue76.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/JointMeasureTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Length.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/NamedItems.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Namespaces.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/NativeOperations.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/NativeOperations.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/PrimitiveEquivalences.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Recursion.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/RepeatUntilSuccess.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/ResourcesEstimator.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/RuntimeMetadataTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/SetQubit.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/StartOperation.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/SwapTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/TeleportTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/Tuples.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/UnitTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/UserDefinedTypes.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/VerifyUnitary.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Circuits/bug3223.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/CoreTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/DebuggingToolsTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/DiagnosticsWrappers.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/GenericsTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/GetQubitsTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/NativeOperationsTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/OperationsTestHelper.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/PartialMapperTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/PrimitivesExtensionsTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QArrayTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QCTraceSimulatorPrimitivesTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QTupleTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumSimulatorTests/BasicTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumSimulatorTests/CircuitsTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumSimulatorTests/QubitReleaseTest.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumSimulatorTests/VerifyGates.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertEqualInPlace.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertProbMultiQubit.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertProbOneQubit.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertQubitUnitary.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertState.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/AssertUnitary.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/Complex.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/Config.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/ControlledOperationTester.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/ControlledOperationsTestUtils.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/IterateThroughCartesianProduct.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/JointOneQubitTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/KnownIssues.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/LinearAlgebra.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/ManyControlQubitsTest.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/Math.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/Matrices.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/OneQubitTestList.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/OneQubitUnitaries.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/PauliExpectation.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/SelfTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/TestSuiteCalculations.nb (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/ThreeQubitUnitaries.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QuantumTestSuite/TwoQubitUnitaries.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/QubitManagerTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/RangeTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/ResourcesEstimatorTests.cs (99%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/RuntimeMetadataTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/SimulatorBaseTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/StackTraceTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/StartOperationTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/HoneywellExe/HoneywellExe.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/HoneywellExe/MeasurementSupportTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/IntrinsicTests/IntrinsicTests.csproj (94%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/IntrinsicTests/Random/Tests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/IonQExe/IonQExe.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/IonQExe/MeasurementSupportTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/Library with Spaces/Library with Spaces.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/Library with Spaces/Library.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/Library1/Library.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/Library1/Library1.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/Library2/Library.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/Library2/Library2.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/QCIExe/MeasurementSupportTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/QCIExe/QCIExe.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/QsharpExe/Main.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/QsharpExe/QsharpExe.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/TargetedExe/Program.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/TargetedExe/TargetedExe.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/Facts.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/Hello.qs (96%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/HoneywellSimulation.qs (80%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/IonQSimulation.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/QCISimulation.qs (80%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/SpaceTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/TestNameTests.qs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TestProjects/UnitTests/UnitTests.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/Tests.Microsoft.Quantum.Simulators.csproj (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/ToffoliSimulatorTests.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TrivialSimulator.cs (100%) rename src/Simulation/{Simulators.Tests => Simulators.Core.Tests}/TypeExtensionsTest.cs (100%) create mode 100644 src/Simulation/Simulators.Type2.Tests/App.config create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/CoreTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/GenericsTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QArrayTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QTupleTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/RangeTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs create mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj create mode 100644 src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj create mode 100644 src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs create mode 100644 src/Simulation/Simulators.Type2/.gitignore create mode 100644 src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 create mode 100644 src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj create mode 100644 src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template create mode 100644 src/Simulation/Simulators.Type2/Properties/AssemblyInfo.cs rename src/Simulation/{Common => Simulators/QuantumSimulator}/Extensions.cs (100%) create mode 100644 src/Simulation/Simulators/QuantumSimulator/IsingXX.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/IsingYY.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/Rx.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/Ry.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/Rz.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/SWAP.cs rename src/Simulation/{Common => Simulators/QuantumSimulator}/SimulatorBase.cs (100%) rename src/Simulation/{Common => Simulators/QuantumSimulator}/StackTrace.cs (100%) diff --git a/.gitignore b/.gitignore index 354f05b9d0d..e38131def08 100644 --- a/.gitignore +++ b/.gitignore @@ -335,5 +335,7 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ -/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/built -/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/built +/src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/built +/src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/built +/src/Simulation/Simulators.Type2.Tests/TestProjects/QsharpExe/built +/src/Simulation/Simulators.Type2.Tests/TestProjects/TargetedExe/built diff --git a/Simulation.sln b/Simulation.sln index 760bd1cd969..5ba0896306c 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.Simulator EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime", "src\Simulation\QCTraceSimulator.Tests\Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj", "{DD50D2D9-2765-449B-8C4B-835A428E160D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Microsoft.Quantum.Simulators", "src\Simulation\Simulators.Tests\Tests.Microsoft.Quantum.Simulators.csproj", "{23461B29-F9DE-4F5B-BC30-50BBE1A10B48}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Microsoft.Quantum.Simulators", "src\Simulation\Simulators.Core.Tests\Tests.Microsoft.Quantum.Simulators.csproj", "{23461B29-F9DE-4F5B-BC30-50BBE1A10B48}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "simulation", "simulation", "{34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}" EndProject @@ -37,19 +37,19 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Microsoft.Quantum.CsharpGen EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{09C842CB-930C-4C7D-AD5F-E30DE4A55820}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QsharpExe", "src\Simulation\Simulators.Tests\TestProjects\QsharpExe\QsharpExe.csproj", "{2F5796A7-4AF8-4B78-928A-0A3A80752F9D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QsharpExe", "src\Simulation\Simulators.Core.Tests\TestProjects\QsharpExe\QsharpExe.csproj", "{2F5796A7-4AF8-4B78-928A-0A3A80752F9D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.EntryPointDriver", "src\Simulation\EntryPointDriver\Microsoft.Quantum.EntryPointDriver.csproj", "{944FE7EF-9220-4CC6-BB20-CE517195B922}" EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Tests.Microsoft.Quantum.EntryPointDriver", "src\Simulation\EntryPointDriver.Tests\Tests.Microsoft.Quantum.EntryPointDriver.fsproj", "{E2F30496-19D8-46A8-9BC0-26936FFE70D2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library1", "src\Simulation\Simulators.Tests\TestProjects\Library1\Library1.csproj", "{7256B986-6705-42FC-9F57-485D72D9DE51}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library1", "src\Simulation\Simulators.Core.Tests\TestProjects\Library1\Library1.csproj", "{7256B986-6705-42FC-9F57-485D72D9DE51}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library2", "src\Simulation\Simulators.Tests\TestProjects\Library2\Library2.csproj", "{A85277B3-4E07-4E15-8F0C-07CC855A3BCB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library2", "src\Simulation\Simulators.Core.Tests\TestProjects\Library2\Library2.csproj", "{A85277B3-4E07-4E15-8F0C-07CC855A3BCB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library with Spaces", "src\Simulation\Simulators.Tests\TestProjects\Library with Spaces\Library with Spaces.csproj", "{418E79F7-9FCF-4128-AA35-1334A685377D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library with Spaces", "src\Simulation\Simulators.Core.Tests\TestProjects\Library with Spaces\Library with Spaces.csproj", "{418E79F7-9FCF-4128-AA35-1334A685377D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "src\Simulation\Simulators.Tests\TestProjects\UnitTests\UnitTests.csproj", "{46278108-D247-4EFC-AC34-23D4A676F62F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "src\Simulation\Simulators.Core.Tests\TestProjects\UnitTests\UnitTests.csproj", "{46278108-D247-4EFC-AC34-23D4A676F62F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure", "Azure", "{37CDC768-16D4-4574-8553-07D99D0A72F7}" EndProject @@ -57,13 +57,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Quantum.Cli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Quantum.Client.Test", "src\Azure\Azure.Quantum.Client.Test\Microsoft.Azure.Quantum.Client.Test.csproj", "{4858E5E3-23FA-4928-B99A-54065875A2B9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoneywellExe", "src\Simulation\Simulators.Tests\TestProjects\HoneywellExe\HoneywellExe.csproj", "{1448512E-132F-4DA8-BCBA-D98F16B31600}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoneywellExe", "src\Simulation\Simulators.Core.Tests\TestProjects\HoneywellExe\HoneywellExe.csproj", "{1448512E-132F-4DA8-BCBA-D98F16B31600}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IonQExe", "src\Simulation\Simulators.Tests\TestProjects\IonQExe\IonQExe.csproj", "{55833C6C-6E91-4413-9F77-96B3A09666B8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IonQExe", "src\Simulation\Simulators.Core.Tests\TestProjects\IonQExe\IonQExe.csproj", "{55833C6C-6E91-4413-9F77-96B3A09666B8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QCIExe", "src\Simulation\Simulators.Tests\TestProjects\QCIExe\QCIExe.csproj", "{C015FF41-9A51-4AF0-AEFC-2547D596B10A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QCIExe", "src\Simulation\Simulators.Core.Tests\TestProjects\QCIExe\QCIExe.csproj", "{C015FF41-9A51-4AF0-AEFC-2547D596B10A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TargetedExe", "src\Simulation\Simulators.Tests\TestProjects\TargetedExe\TargetedExe.csproj", "{D292BF18-3956-4827-820E-254C3F81EF09}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TargetedExe", "src\Simulation\Simulators.Core.Tests\TestProjects\TargetedExe\TargetedExe.csproj", "{D292BF18-3956-4827-820E-254C3F81EF09}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BC562DAE-FE2B-4A8C-880C-C546F83F99E4}" EndProject @@ -73,6 +73,28 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.QSharp.Fo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Type2.Core", "src\Simulation\Type2Core\Microsoft.Quantum.Type2.Core.csproj", "{AF6CD304-8E03-433D-AAA2-6E0094B53071}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Simulators.Type2", "src\Simulation\Simulators.Type2\Microsoft.Quantum.Simulators.Type2.csproj", "{E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Microsoft.Quantum.Simulators.Type2", "src\Simulation\Simulators.Type2.Tests\Tests.Microsoft.Quantum.Simulators.Type2.csproj", "{ED3D7040-4B3F-4217-A75E-9DF63DD84707}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulators.Type2.Tests", "Simulators.Type2.Tests", "{3DC13EC6-3C67-49D4-B2E2-6F9DD839F50C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library1", "src\Simulation\Simulators.Type2.Tests\TestProjects\Library1\Library1.csproj", "{9BC3A273-9C36-4204-B06A-A92FBE05F63E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library2", "src\Simulation\Simulators.Type2.Tests\TestProjects\Library2\Library2.csproj", "{5D6148F0-37A6-42D6-B562-429666AFE3FE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\Simulation\Simulators.Type2.Tests\TestProjects\UnitTests\UnitTests.csproj", "{3626EB54-E63A-48D1-BA67-3B249D0D3365}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulators.Core.Tests", "Simulators.Core.Tests", "{CF48986A-B487-407F-98A7-97AED29C6A43}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntrinsicTests", "src\Simulation\Simulators.Core.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntrinsicTests", "src\Simulation\Simulators.Type2.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -517,6 +539,118 @@ Global {AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU {AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU {AF6CD304-8E03-433D-AAA2-6E0094B53071}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Debug|x64.ActiveCfg = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Debug|x64.Build.0 = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Release|Any CPU.Build.0 = Release|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Release|x64.ActiveCfg = Release|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.Release|x64.Build.0 = Release|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|x64.ActiveCfg = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Debug|x64.Build.0 = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|Any CPU.Build.0 = Release|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|x64.ActiveCfg = Release|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.Release|x64.Build.0 = Release|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|x64.ActiveCfg = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|x64.Build.0 = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|Any CPU.Build.0 = Release|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|x64.ActiveCfg = Release|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|x64.Build.0 = Release|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|x64.ActiveCfg = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|x64.Build.0 = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|Any CPU.Build.0 = Release|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|x64.ActiveCfg = Release|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|x64.Build.0 = Release|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|x64.ActiveCfg = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|x64.Build.0 = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|Any CPU.Build.0 = Release|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|x64.ActiveCfg = Release|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|x64.Build.0 = Release|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|x64.ActiveCfg = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|x64.Build.0 = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|Any CPU.Build.0 = Release|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|x64.ActiveCfg = Release|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Release|x64.Build.0 = Release|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|x64.ActiveCfg = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|x64.Build.0 = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|Any CPU.Build.0 = Release|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|x64.ActiveCfg = Release|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|x64.Build.0 = Release|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -551,6 +685,17 @@ Global {9008B252-2DF7-404B-B626-D4497BB70A05} = {BC562DAE-FE2B-4A8C-880C-C546F83F99E4} {DB45AD73-4D91-43F3-85CC-C63614A96FB0} = {9008B252-2DF7-404B-B626-D4497BB70A05} {AF6CD304-8E03-433D-AAA2-6E0094B53071} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {ED3D7040-4B3F-4217-A75E-9DF63DD84707} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {3DC13EC6-3C67-49D4-B2E2-6F9DD839F50C} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} = {3DC13EC6-3C67-49D4-B2E2-6F9DD839F50C} + {9BC3A273-9C36-4204-B06A-A92FBE05F63E} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} + {5D6148F0-37A6-42D6-B562-429666AFE3FE} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} + {3626EB54-E63A-48D1-BA67-3B249D0D3365} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} + {CF48986A-B487-407F-98A7-97AED29C6A43} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3} = {CF48986A-B487-407F-98A7-97AED29C6A43} + {4EF958CA-B4A6-4E5F-924A-100B5615BEC3} = {F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3} + {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821} diff --git a/src/Simulation/Common/Microsoft.Quantum.Simulation.Common.csproj b/src/Simulation/Common/Microsoft.Quantum.Simulation.Common.csproj index db67c8130ed..5772508edfb 100644 --- a/src/Simulation/Common/Microsoft.Quantum.Simulation.Common.csproj +++ b/src/Simulation/Common/Microsoft.Quantum.Simulation.Common.csproj @@ -14,7 +14,6 @@ - diff --git a/src/Simulation/Common/QubitManager.cs b/src/Simulation/Common/QubitManager.cs index 9bc54dfce3d..1802583f793 100644 --- a/src/Simulation/Common/QubitManager.cs +++ b/src/Simulation/Common/QubitManager.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.Quantum.Intrinsic; using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators.Exceptions; diff --git a/src/Simulation/Common/Simulators.Type2.Dev.props b/src/Simulation/Common/Simulators.Type2.Dev.props new file mode 100644 index 00000000000..ce27923c3fd --- /dev/null +++ b/src/Simulation/Common/Simulators.Type2.Dev.props @@ -0,0 +1,42 @@ + + + + + bin\$(BuildConfiguration)\$(TargetFramework)\$(AssemblyName).xml + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\)) + $([MSBuild]::NormalizePath($(EnlistmentRoot)src/Simulation/Native/build/)) + + + + $([MSBuild]::NormalizePath($(NativeBuildPath)/libMicrosoft.Quantum.Simulator.Runtime.dylib)) + $([MSBuild]::NormalizePath($(NativeBuildPath)/libMicrosoft.Quantum.Simulator.Runtime.so)) + $([MSBuild]::NormalizePath($(NativeBuildPath)/Release/Microsoft.Quantum.Simulator.Runtime.dll)) + $([MSBuild]::NormalizePath($(NativeBuildPath)/Debug/Microsoft.Quantum.Simulator.Runtime.dll)) + $(QsimDllMac) + $(QsimDllLinux) + $(QsimDllWindowsRelease) + $(QsimDllWindowsDebug) + + + + + + + + + + + + Microsoft.Quantum.Simulator.Runtime.dll + PreserveNewest + false + + + + + + + + + + diff --git a/src/Simulation/Core/Properties/AssemblyInfo.cs b/src/Simulation/Core/Properties/AssemblyInfo.cs index c2a5d12dced..4ecfaf27ed6 100644 --- a/src/Simulation/Core/Properties/AssemblyInfo.cs +++ b/src/Simulation/Core/Properties/AssemblyInfo.cs @@ -7,3 +7,4 @@ // Allow the test assembly to use our internal methods [assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators" + SigningConstants.PUBLIC_KEY)] +[assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators.Type2" + SigningConstants.PUBLIC_KEY)] diff --git a/src/Simulation/QsharpCore/Diagnostics/Facts.qs b/src/Simulation/QsharpFoundation/Diagnostics/Facts.qs similarity index 100% rename from src/Simulation/QsharpCore/Diagnostics/Facts.qs rename to src/Simulation/QsharpFoundation/Diagnostics/Facts.qs diff --git a/src/Simulation/QsharpCore/Diagnostics/Properties/NamespaceInfo.qs b/src/Simulation/QsharpFoundation/Diagnostics/Properties/NamespaceInfo.qs similarity index 100% rename from src/Simulation/QsharpCore/Diagnostics/Properties/NamespaceInfo.qs rename to src/Simulation/QsharpFoundation/Diagnostics/Properties/NamespaceInfo.qs diff --git a/src/Simulation/QsharpCore/Random/Convienence.qs b/src/Simulation/QsharpFoundation/Random/Convienence.qs similarity index 100% rename from src/Simulation/QsharpCore/Random/Convienence.qs rename to src/Simulation/QsharpFoundation/Random/Convienence.qs diff --git a/src/Simulation/QsharpCore/Random/Internal.qs b/src/Simulation/QsharpFoundation/Random/Internal.qs similarity index 100% rename from src/Simulation/QsharpCore/Random/Internal.qs rename to src/Simulation/QsharpFoundation/Random/Internal.qs diff --git a/src/Simulation/QsharpCore/Random/Intrinsic.qs b/src/Simulation/QsharpFoundation/Random/Intrinsic.qs similarity index 100% rename from src/Simulation/QsharpCore/Random/Intrinsic.qs rename to src/Simulation/QsharpFoundation/Random/Intrinsic.qs diff --git a/src/Simulation/QsharpCore/Random/Normal.qs b/src/Simulation/QsharpFoundation/Random/Normal.qs similarity index 100% rename from src/Simulation/QsharpCore/Random/Normal.qs rename to src/Simulation/QsharpFoundation/Random/Normal.qs diff --git a/src/Simulation/QsharpCore/Random/Types.qs b/src/Simulation/QsharpFoundation/Random/Types.qs similarity index 100% rename from src/Simulation/QsharpCore/Random/Types.qs rename to src/Simulation/QsharpFoundation/Random/Types.qs diff --git a/src/Simulation/QsharpCore/Random/Uniform.qs b/src/Simulation/QsharpFoundation/Random/Uniform.qs similarity index 100% rename from src/Simulation/QsharpCore/Random/Uniform.qs rename to src/Simulation/QsharpFoundation/Random/Uniform.qs diff --git a/src/Simulation/Simulators.Tests/App.config b/src/Simulation/Simulators.Core.Tests/App.config similarity index 100% rename from src/Simulation/Simulators.Tests/App.config rename to src/Simulation/Simulators.Core.Tests/App.config diff --git a/src/Simulation/Simulators.Tests/Circuits/AssertEqual.cs b/src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.cs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/AssertEqual.cs rename to src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.cs diff --git a/src/Simulation/Simulators.Tests/Circuits/AssertEqual.qs b/src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/AssertEqual.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/BitOperations.qs b/src/Simulation/Simulators.Core.Tests/Circuits/BitOperations.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/BitOperations.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/BitOperations.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Bug1514.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Bug1514.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Bug1514.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Bug1514.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Bug2212.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Bug2212.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Bug2212.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Bug2212.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Bug2248.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Bug2248.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Bug2248.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Bug2248.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Bug2469.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Bug2469.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Bug2469.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Bug2469.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Bug3059.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Bug3059.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Bug3059.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Bug3059.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Bug3758.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Bug3758.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Bug3758.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Bug3758.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/CallableInterfacesTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/CallableInterfacesTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/CallableInterfacesTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/CallableInterfacesTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/ClassicalRotationsTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/ClassicalRotationsTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/ClassicalRotationsTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/ClassicalRotationsTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/ClosedType.qs b/src/Simulation/Simulators.Core.Tests/Circuits/ClosedType.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/ClosedType.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/ClosedType.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/ConditionalExpression.qs b/src/Simulation/Simulators.Core.Tests/Circuits/ConditionalExpression.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/ConditionalExpression.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/ConditionalExpression.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Convert.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Convert.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Convert.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Convert.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/CoreOperations.qs b/src/Simulation/Simulators.Core.Tests/Circuits/CoreOperations.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/CoreOperations.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/CoreOperations.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/ExpTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/ExpTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/ExpTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/ExpTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Fail.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Fail.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Fail.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Fail.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Functions.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Functions.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Functions.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Functions.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Generics.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Generics.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Generics.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Generics.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/GetAvailableTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/GetAvailableTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/GetAvailableTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/GetAvailableTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Issue132.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Issue132.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Issue132.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Issue132.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Issue76.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Issue76.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Issue76.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Issue76.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/JointMeasureTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/JointMeasureTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/JointMeasureTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/JointMeasureTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Length.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Length.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Length.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Length.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/NamedItems.qs b/src/Simulation/Simulators.Core.Tests/Circuits/NamedItems.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/NamedItems.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/NamedItems.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Namespaces.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Namespaces.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Namespaces.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Namespaces.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/NativeOperations.cs b/src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.cs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/NativeOperations.cs rename to src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.cs diff --git a/src/Simulation/Simulators.Tests/Circuits/NativeOperations.qs b/src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/NativeOperations.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/PrimitiveEquivalences.qs b/src/Simulation/Simulators.Core.Tests/Circuits/PrimitiveEquivalences.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/PrimitiveEquivalences.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/PrimitiveEquivalences.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Recursion.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Recursion.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Recursion.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Recursion.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/RepeatUntilSuccess.qs b/src/Simulation/Simulators.Core.Tests/Circuits/RepeatUntilSuccess.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/RepeatUntilSuccess.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/RepeatUntilSuccess.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs b/src/Simulation/Simulators.Core.Tests/Circuits/ResourcesEstimator.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/ResourcesEstimator.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/RuntimeMetadataTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/RuntimeMetadataTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/RuntimeMetadataTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/RuntimeMetadataTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/SetQubit.qs b/src/Simulation/Simulators.Core.Tests/Circuits/SetQubit.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/SetQubit.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/SetQubit.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/StartOperation.qs b/src/Simulation/Simulators.Core.Tests/Circuits/StartOperation.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/StartOperation.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/StartOperation.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/SwapTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/SwapTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/SwapTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/SwapTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/TeleportTest.qs b/src/Simulation/Simulators.Core.Tests/Circuits/TeleportTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/TeleportTest.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/TeleportTest.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/Tuples.qs b/src/Simulation/Simulators.Core.Tests/Circuits/Tuples.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/Tuples.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/Tuples.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/UnitTests.qs b/src/Simulation/Simulators.Core.Tests/Circuits/UnitTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/UnitTests.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/UnitTests.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/UserDefinedTypes.qs b/src/Simulation/Simulators.Core.Tests/Circuits/UserDefinedTypes.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/UserDefinedTypes.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/UserDefinedTypes.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs b/src/Simulation/Simulators.Core.Tests/Circuits/VerifyUnitary.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/VerifyUnitary.qs diff --git a/src/Simulation/Simulators.Tests/Circuits/bug3223.qs b/src/Simulation/Simulators.Core.Tests/Circuits/bug3223.qs similarity index 100% rename from src/Simulation/Simulators.Tests/Circuits/bug3223.qs rename to src/Simulation/Simulators.Core.Tests/Circuits/bug3223.qs diff --git a/src/Simulation/Simulators.Tests/CoreTests.cs b/src/Simulation/Simulators.Core.Tests/CoreTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/CoreTests.cs rename to src/Simulation/Simulators.Core.Tests/CoreTests.cs diff --git a/src/Simulation/Simulators.Tests/DebuggingToolsTests.cs b/src/Simulation/Simulators.Core.Tests/DebuggingToolsTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/DebuggingToolsTests.cs rename to src/Simulation/Simulators.Core.Tests/DebuggingToolsTests.cs diff --git a/src/Simulation/Simulators.Tests/DiagnosticsWrappers.qs b/src/Simulation/Simulators.Core.Tests/DiagnosticsWrappers.qs similarity index 100% rename from src/Simulation/Simulators.Tests/DiagnosticsWrappers.qs rename to src/Simulation/Simulators.Core.Tests/DiagnosticsWrappers.qs diff --git a/src/Simulation/Simulators.Tests/GenericsTests.cs b/src/Simulation/Simulators.Core.Tests/GenericsTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/GenericsTests.cs rename to src/Simulation/Simulators.Core.Tests/GenericsTests.cs diff --git a/src/Simulation/Simulators.Tests/GetQubitsTests.cs b/src/Simulation/Simulators.Core.Tests/GetQubitsTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/GetQubitsTests.cs rename to src/Simulation/Simulators.Core.Tests/GetQubitsTests.cs diff --git a/src/Simulation/Simulators.Tests/NativeOperationsTests.cs b/src/Simulation/Simulators.Core.Tests/NativeOperationsTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/NativeOperationsTests.cs rename to src/Simulation/Simulators.Core.Tests/NativeOperationsTests.cs diff --git a/src/Simulation/Simulators.Tests/OperationsTestHelper.cs b/src/Simulation/Simulators.Core.Tests/OperationsTestHelper.cs similarity index 100% rename from src/Simulation/Simulators.Tests/OperationsTestHelper.cs rename to src/Simulation/Simulators.Core.Tests/OperationsTestHelper.cs diff --git a/src/Simulation/Simulators.Tests/PartialMapperTests.cs b/src/Simulation/Simulators.Core.Tests/PartialMapperTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/PartialMapperTests.cs rename to src/Simulation/Simulators.Core.Tests/PartialMapperTests.cs diff --git a/src/Simulation/Simulators.Tests/PrimitivesExtensionsTests.cs b/src/Simulation/Simulators.Core.Tests/PrimitivesExtensionsTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/PrimitivesExtensionsTests.cs rename to src/Simulation/Simulators.Core.Tests/PrimitivesExtensionsTests.cs diff --git a/src/Simulation/Simulators.Tests/QArrayTests.cs b/src/Simulation/Simulators.Core.Tests/QArrayTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QArrayTests.cs rename to src/Simulation/Simulators.Core.Tests/QArrayTests.cs diff --git a/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests.cs b/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests.cs rename to src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests.cs diff --git a/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs b/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs rename to src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs diff --git a/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs b/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs rename to src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs diff --git a/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs b/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs rename to src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs diff --git a/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs b/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs rename to src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs diff --git a/src/Simulation/Simulators.Tests/QTupleTests.cs b/src/Simulation/Simulators.Core.Tests/QTupleTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QTupleTests.cs rename to src/Simulation/Simulators.Core.Tests/QTupleTests.cs diff --git a/src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs b/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/BasicTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs rename to src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/BasicTests.cs diff --git a/src/Simulation/Simulators.Tests/QuantumSimulatorTests/CircuitsTests.cs b/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/CircuitsTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumSimulatorTests/CircuitsTests.cs rename to src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/CircuitsTests.cs diff --git a/src/Simulation/Simulators.Tests/QuantumSimulatorTests/QubitReleaseTest.cs b/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/QubitReleaseTest.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumSimulatorTests/QubitReleaseTest.cs rename to src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/QubitReleaseTest.cs diff --git a/src/Simulation/Simulators.Tests/QuantumSimulatorTests/VerifyGates.cs b/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumSimulatorTests/VerifyGates.cs rename to src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite.cs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite.cs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite.cs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertEqualInPlace.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertEqualInPlace.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertEqualInPlace.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertEqualInPlace.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbMultiQubit.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbMultiQubit.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbMultiQubit.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbMultiQubit.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbOneQubit.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbOneQubit.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbOneQubit.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbOneQubit.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertQubitUnitary.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertQubitUnitary.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertQubitUnitary.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertQubitUnitary.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertState.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertState.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertState.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertState.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertUnitary.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertUnitary.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/AssertUnitary.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertUnitary.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/Complex.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Complex.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/Complex.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Complex.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/Config.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Config.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/Config.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Config.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationTester.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationTester.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationTester.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationTester.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/JointOneQubitTests.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/JointOneQubitTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/JointOneQubitTests.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/JointOneQubitTests.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/KnownIssues.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/KnownIssues.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/KnownIssues.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/KnownIssues.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/LinearAlgebra.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/LinearAlgebra.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/LinearAlgebra.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/LinearAlgebra.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/ManyControlQubitsTest.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ManyControlQubitsTest.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/ManyControlQubitsTest.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ManyControlQubitsTest.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/Math.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Math.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/Math.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Math.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/Matrices.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Matrices.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/Matrices.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Matrices.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitTestList.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitTestList.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitTestList.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitTestList.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitUnitaries.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitUnitaries.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitUnitaries.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitUnitaries.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/PauliExpectation.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/PauliExpectation.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/PauliExpectation.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/PauliExpectation.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/SelfTests.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/SelfTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/SelfTests.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/SelfTests.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/TestSuiteCalculations.nb b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TestSuiteCalculations.nb similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/TestSuiteCalculations.nb rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TestSuiteCalculations.nb diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs diff --git a/src/Simulation/Simulators.Tests/QuantumTestSuite/TwoQubitUnitaries.qs b/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TwoQubitUnitaries.qs similarity index 100% rename from src/Simulation/Simulators.Tests/QuantumTestSuite/TwoQubitUnitaries.qs rename to src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TwoQubitUnitaries.qs diff --git a/src/Simulation/Simulators.Tests/QubitManagerTests.cs b/src/Simulation/Simulators.Core.Tests/QubitManagerTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/QubitManagerTests.cs rename to src/Simulation/Simulators.Core.Tests/QubitManagerTests.cs diff --git a/src/Simulation/Simulators.Tests/RangeTests.cs b/src/Simulation/Simulators.Core.Tests/RangeTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/RangeTests.cs rename to src/Simulation/Simulators.Core.Tests/RangeTests.cs diff --git a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs b/src/Simulation/Simulators.Core.Tests/ResourcesEstimatorTests.cs similarity index 99% rename from src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs rename to src/Simulation/Simulators.Core.Tests/ResourcesEstimatorTests.cs index 0a60328484d..ce7d93c855f 100644 --- a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs +++ b/src/Simulation/Simulators.Core.Tests/ResourcesEstimatorTests.cs @@ -99,8 +99,8 @@ public void ToTSVTest() var cliffords = rows.First(r => r.StartsWith("QubitClifford")).Split('\t'); Assert.Equal(3, cliffords.Length); Assert.Equal("2", cliffords[1]); - } - + } + /// /// Shows that T gates on different qubits are counted for depth purposes as /// executing in parallel. @@ -117,8 +117,8 @@ public void DepthDifferentQubitsTest() Assert.Equal(4.0, data.Rows.Find("T")["Sum"]); Assert.Equal(3.0, data.Rows.Find("Width")["Sum"]); Assert.Equal(2.0, data.Rows.Find("Depth")["Sum"]); - } - + } + /// /// Documents that the width and depth statistics reflect independent lower /// bounds for each (two T gates cannot be combined into a circuit of depth diff --git a/src/Simulation/Simulators.Tests/RuntimeMetadataTests.cs b/src/Simulation/Simulators.Core.Tests/RuntimeMetadataTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/RuntimeMetadataTests.cs rename to src/Simulation/Simulators.Core.Tests/RuntimeMetadataTests.cs diff --git a/src/Simulation/Simulators.Tests/SimulatorBaseTests.cs b/src/Simulation/Simulators.Core.Tests/SimulatorBaseTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/SimulatorBaseTests.cs rename to src/Simulation/Simulators.Core.Tests/SimulatorBaseTests.cs diff --git a/src/Simulation/Simulators.Tests/StackTraceTests.cs b/src/Simulation/Simulators.Core.Tests/StackTraceTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/StackTraceTests.cs rename to src/Simulation/Simulators.Core.Tests/StackTraceTests.cs diff --git a/src/Simulation/Simulators.Tests/StartOperationTests.cs b/src/Simulation/Simulators.Core.Tests/StartOperationTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/StartOperationTests.cs rename to src/Simulation/Simulators.Core.Tests/StartOperationTests.cs diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj similarity index 94% rename from src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj index b04dbe95ef3..0fae894e16a 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ b/src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -3,7 +3,6 @@ netcoreapp3.1 false - true false false diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/Random/Tests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/Random/Tests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/IonQExe.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/IonQExe.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/Library1/Library.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library1.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library1.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/Library2/Library.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library2.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library2.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/QCIExe.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/QCIExe.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/Main.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/Main.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/QsharpExe/Main.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/Main.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/QsharpExe.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/QsharpExe.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/Program.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/Program.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/TargetedExe/Program.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/Program.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/TargetedExe.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/TargetedExe.csproj diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Facts.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Facts.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/Facts.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Facts.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Hello.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Hello.qs similarity index 96% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/Hello.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Hello.qs index 8e5d87f77a8..4d8cd71c3b1 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Hello.qs +++ b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Hello.qs @@ -1,16 +1,16 @@ -// Used for a unit test; -// do not change the name of this namespace! -namespace Microsoft.Quantum.Library { - - open Microsoft.Quantum.Intrinsic; - - // Used for a unit test; - // do not change the name or namespace of this type! - newtype Token = Unit; - - // Used for a unit test; - // do not change the name or namespace of this callable! - operation Hello(dummy : Token) : Unit { - Message("Hello!"); - } +// Used for a unit test; +// do not change the name of this namespace! +namespace Microsoft.Quantum.Library { + + open Microsoft.Quantum.Intrinsic; + + // Used for a unit test; + // do not change the name or namespace of this type! + newtype Token = Unit; + + // Used for a unit test; + // do not change the name or namespace of this callable! + operation Hello(dummy : Token) : Unit { + Message("Hello!"); + } } \ No newline at end of file diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/HoneywellSimulation.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/HoneywellSimulation.qs similarity index 80% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/HoneywellSimulation.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/HoneywellSimulation.qs index c57dbb3a827..5325dca658a 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/HoneywellSimulation.qs +++ b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/HoneywellSimulation.qs @@ -8,289 +8,289 @@ namespace Microsoft.Quantum.Simulation.Testing.Honeywell { open Microsoft.Quantum.Simulation.Testing.Honeywell.MeasurementSupportTests; @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation MeasureInMiddleTest() : Unit { MeasureInMiddle(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation QubitAfterMeasurementTest() : Unit { QubitAfterMeasurement(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation BranchOnMeasurementTest() : Unit { BranchOnMeasurement(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation BasicLiftTest() : Unit { BasicLift(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftLoopsTest() : Unit { LiftLoops(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftSingleNonCallTest() : Unit { LiftSingleNonCall(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftSelfContainedMutableTest() : Unit { LiftSelfContainedMutable(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ArgumentsPartiallyResolveTypeParametersTest() : Unit { ArgumentsPartiallyResolveTypeParameters(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftFunctorApplicationTest() : Unit { LiftFunctorApplication(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftPartialApplicationTest() : Unit { LiftPartialApplication(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftArrayItemCallTest() : Unit { LiftArrayItemCall(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftOneNotBothTest() : Unit { LiftOneNotBoth(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfZeroTest() : Unit { ApplyIfZero_Test(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfOneTest() : Unit { ApplyIfOne_Test(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfZeroElseOneTest() : Unit { ApplyIfZeroElseOne(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfOneElseZeroTest() : Unit { ApplyIfOneElseZero(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation IfElifTest() : Unit { IfElif(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AndConditionTest() : Unit { AndCondition(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation OrConditionTest() : Unit { OrCondition(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyConditionallyTest() : Unit { ApplyConditionally(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyConditionallyWithNoOpTest() : Unit { ApplyConditionallyWithNoOp(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyConditionallyTest() : Unit { InequalityWithApplyConditionally(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfOneElseZeroTest() : Unit { InequalityWithApplyIfOneElseZero(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfZeroElseOneTest() : Unit { InequalityWithApplyIfZeroElseOne(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfOneTest() : Unit { InequalityWithApplyIfOne(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfZeroTest() : Unit { InequalityWithApplyIfZero(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiteralOnTheLeftTest() : Unit { LiteralOnTheLeft(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation GenericsSupportTest() : Unit { GenericsSupport(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation WithinBlockSupportTest() : Unit { WithinBlockSupport(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AdjointSupportProvidedTest() : Unit { AdjointSupportProvided(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AdjointSupportSelfTest() : Unit { AdjointSupportSelf(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AdjointSupportInvertTest() : Unit { AdjointSupportInvert(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledSupportProvidedTest() : Unit { ControlledSupportProvided(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledSupportDistributeTest() : Unit { ControlledSupportDistribute(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedBodyTest() : Unit { ControlledAdjointSupportProvided_ProvidedBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedAdjointTest() : Unit { ControlledAdjointSupportProvided_ProvidedAdjoint(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedControlledTest() : Unit { ControlledAdjointSupportProvided_ProvidedControlled(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedAllTest() : Unit { ControlledAdjointSupportProvided_ProvidedAll(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeBodyTest() : Unit { ControlledAdjointSupportDistribute_DistributeBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeAdjointTest() : Unit { ControlledAdjointSupportDistribute_DistributeAdjoint(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeControlledTest() : Unit { ControlledAdjointSupportDistribute_DistributeControlled(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeAllTest() : Unit { ControlledAdjointSupportDistribute_DistributeAll(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertBodyTest() : Unit { ControlledAdjointSupportInvert_InvertBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertAdjointTest() : Unit { ControlledAdjointSupportInvert_InvertAdjoint(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertControlledTest() : Unit { ControlledAdjointSupportInvert_InvertControlled(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertAllTest() : Unit { ControlledAdjointSupportInvert_InvertAll(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportSelf_SelfBodyTest() : Unit { ControlledAdjointSupportSelf_SelfBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportSelf_SelfControlledTest() : Unit { ControlledAdjointSupportSelf_SelfControlled(); } diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/IonQSimulation.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/IonQSimulation.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/IonQSimulation.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/IonQSimulation.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/QCISimulation.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/QCISimulation.qs similarity index 80% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/QCISimulation.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/QCISimulation.qs index b03338fd293..8585758f894 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/QCISimulation.qs +++ b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/QCISimulation.qs @@ -8,289 +8,289 @@ namespace Microsoft.Quantum.Simulation.Testing.QCI { open Microsoft.Quantum.Simulation.Testing.QCI.MeasurementSupportTests; @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation MeasureInMiddleTest() : Unit { MeasureInMiddle(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation QubitAfterMeasurementTest() : Unit { QubitAfterMeasurement(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation BranchOnMeasurementTest() : Unit { BranchOnMeasurement(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation BasicLiftTest() : Unit { BasicLift(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftLoopsTest() : Unit { LiftLoops(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftSingleNonCallTest() : Unit { LiftSingleNonCall(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftSelfContainedMutableTest() : Unit { LiftSelfContainedMutable(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ArgumentsPartiallyResolveTypeParametersTest() : Unit { ArgumentsPartiallyResolveTypeParameters(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftFunctorApplicationTest() : Unit { LiftFunctorApplication(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftPartialApplicationTest() : Unit { LiftPartialApplication(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftArrayItemCallTest() : Unit { LiftArrayItemCall(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiftOneNotBothTest() : Unit { LiftOneNotBoth(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfZeroTest() : Unit { ApplyIfZero_Test(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfOneTest() : Unit { ApplyIfOne_Test(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfZeroElseOneTest() : Unit { ApplyIfZeroElseOne(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyIfOneElseZeroTest() : Unit { ApplyIfOneElseZero(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation IfElifTest() : Unit { IfElif(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AndConditionTest() : Unit { AndCondition(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation OrConditionTest() : Unit { OrCondition(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyConditionallyTest() : Unit { ApplyConditionally(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ApplyConditionallyWithNoOpTest() : Unit { ApplyConditionallyWithNoOp(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyConditionallyTest() : Unit { InequalityWithApplyConditionally(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfOneElseZeroTest() : Unit { InequalityWithApplyIfOneElseZero(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfZeroElseOneTest() : Unit { InequalityWithApplyIfZeroElseOne(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfOneTest() : Unit { InequalityWithApplyIfOne(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation InequalityWithApplyIfZeroTest() : Unit { InequalityWithApplyIfZero(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation LiteralOnTheLeftTest() : Unit { LiteralOnTheLeft(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation GenericsSupportTest() : Unit { GenericsSupport(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation WithinBlockSupportTest() : Unit { WithinBlockSupport(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AdjointSupportProvidedTest() : Unit { AdjointSupportProvided(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AdjointSupportSelfTest() : Unit { AdjointSupportSelf(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation AdjointSupportInvertTest() : Unit { AdjointSupportInvert(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledSupportProvidedTest() : Unit { ControlledSupportProvided(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledSupportDistributeTest() : Unit { ControlledSupportDistribute(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedBodyTest() : Unit { ControlledAdjointSupportProvided_ProvidedBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedAdjointTest() : Unit { ControlledAdjointSupportProvided_ProvidedAdjoint(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedControlledTest() : Unit { ControlledAdjointSupportProvided_ProvidedControlled(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportProvided_ProvidedAllTest() : Unit { ControlledAdjointSupportProvided_ProvidedAll(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeBodyTest() : Unit { ControlledAdjointSupportDistribute_DistributeBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeAdjointTest() : Unit { ControlledAdjointSupportDistribute_DistributeAdjoint(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeControlledTest() : Unit { ControlledAdjointSupportDistribute_DistributeControlled(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportDistribute_DistributeAllTest() : Unit { ControlledAdjointSupportDistribute_DistributeAll(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertBodyTest() : Unit { ControlledAdjointSupportInvert_InvertBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertAdjointTest() : Unit { ControlledAdjointSupportInvert_InvertAdjoint(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertControlledTest() : Unit { ControlledAdjointSupportInvert_InvertControlled(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportInvert_InvertAllTest() : Unit { ControlledAdjointSupportInvert_InvertAll(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportSelf_SelfBodyTest() : Unit { ControlledAdjointSupportSelf_SelfBody(); } @Test("QuantumSimulator") - // @Test("ResourcesEstimator") + @Test("ResourcesEstimator") operation ControlledAdjointSupportSelf_SelfControlledTest() : Unit { ControlledAdjointSupportSelf_SelfControlled(); } diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/SpaceTests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/SpaceTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/SpaceTests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/SpaceTests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/TestNameTests.qs b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/TestNameTests.qs similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/TestNameTests.qs rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/TestNameTests.qs diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/UnitTests.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj rename to src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/UnitTests.csproj diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Core.Tests/Tests.Microsoft.Quantum.Simulators.csproj similarity index 100% rename from src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj rename to src/Simulation/Simulators.Core.Tests/Tests.Microsoft.Quantum.Simulators.csproj diff --git a/src/Simulation/Simulators.Tests/ToffoliSimulatorTests.cs b/src/Simulation/Simulators.Core.Tests/ToffoliSimulatorTests.cs similarity index 100% rename from src/Simulation/Simulators.Tests/ToffoliSimulatorTests.cs rename to src/Simulation/Simulators.Core.Tests/ToffoliSimulatorTests.cs diff --git a/src/Simulation/Simulators.Tests/TrivialSimulator.cs b/src/Simulation/Simulators.Core.Tests/TrivialSimulator.cs similarity index 100% rename from src/Simulation/Simulators.Tests/TrivialSimulator.cs rename to src/Simulation/Simulators.Core.Tests/TrivialSimulator.cs diff --git a/src/Simulation/Simulators.Tests/TypeExtensionsTest.cs b/src/Simulation/Simulators.Core.Tests/TypeExtensionsTest.cs similarity index 100% rename from src/Simulation/Simulators.Tests/TypeExtensionsTest.cs rename to src/Simulation/Simulators.Core.Tests/TypeExtensionsTest.cs diff --git a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj index 6e1dbfb848e..c51082ca049 100644 --- a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj @@ -21,6 +21,7 @@ + @@ -29,6 +30,8 @@ + + diff --git a/src/Simulation/Simulators.Type2.Tests/App.config b/src/Simulation/Simulators.Type2.Tests/App.config new file mode 100644 index 00000000000..94ce1a2b94f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs b/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs new file mode 100644 index 00000000000..960c140c19f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Microsoft.Quantum.Simulation.Core; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + public partial class AssertEqual<__T__> + { + public class Native : AssertEqual<__T__> + { + public Native(IOperationFactory m) : base(m) { } + + public override Func<(__T__, __T__), QVoid> Body => (_args) => + { + var (expected, actual) = _args; + Assert.Equal(expected, actual); + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs new file mode 100644 index 00000000000..1555e88958f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + function AssertEqual<'T> (expected : 'T, actual : 'T) : Unit { + body intrinsic; + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs new file mode 100644 index 00000000000..bf7556f7704 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + operation TimesTwo (v : Int) : Int + { + return v <<< 1; + } + + operation DivideTwo (v : Int) : Int + { + return v >>> 1; + } + + operation IsEven (v : Int) : Bool + { + return (v &&& 1) == 0; + } + + operation BitOperationsTest () : Unit + { + AssertEqual(14, TimesTwo(7)); + AssertEqual(11, DivideTwo(22)); + AssertEqual(11, DivideTwo(23)); + + AssertEqual(17, DivideTwo(98) &&& 0x51); + AssertEqual(0xF000F, 0xF ||| TimesTwo(0x78002)); + AssertEqual(0x00110007, 0x000f000f ^^^ (TimesTwo(0x78002) + TimesTwo(0x78002))); + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs new file mode 100644 index 00000000000..e01bd983168 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Bug1514 { + + operation Bug1514() : Unit { + Foo(); + Bar(3); + } + + operation Foo() : Unit { + } + + function Bar<'T>(a: 'T) : Unit { + } +} + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Bug1514; + + operation Bug1514Test () : Unit + { + Bug1514(); + } +} + \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs new file mode 100644 index 00000000000..82ccb4bcfeb --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Bug2212 { + + function F<'T> (arg1 :'T , arg : Unit) : 'T { + return arg1; + } + + function RecursiveGeneric2<'T> (arg1 : (Unit -> 'T), arg2 : Int) : Int { + if ( arg2 <= 0 ) { + return arg2; + } else { + let _ = arg1(); + return RecursiveGeneric2<(Unit -> 'T)>(F(arg1,_),arg2 - 1); + } + } +} + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Bug2212; + + operation Bug2212Test () : Unit + { + // Calling this function used to trigger a run time exception. + let x = RecursiveGeneric2(F(3,_), 10); + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs new file mode 100644 index 00000000000..6f6f1dac376 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Bug2248 { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Diagnostics; + + + operation TestDumpMachineDoesntChangeState (N : Int) : Unit + { + using (qs = Qubit[N]) + { + for (q in qs) + { + X(q); + DumpMachine(""); + AssertQubit(One, q); + Reset(q); + } + } + } +} + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Bug2248; + + operation Bug2248Test () : Unit + { + for(i in 1..4) + { + TestDumpMachineDoesntChangeState(i); + } + } +} + \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs new file mode 100644 index 00000000000..8cddbc52100 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + operation TestSafeToRunCliffords (flag : Bool) : Unit + { + using (q = Qubit()) + { + X(q); + if (flag) + { + Y(q); + Z(q); + H(q); + S(q); + } + X(q); // So that it's safe to release + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs new file mode 100644 index 00000000000..98a3c3339e5 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Bug3059 { + + function CheckPair (fst : Int, snd : Int) : Unit { } + + function WithDiscardedSymbols (fct : ((Int, Int) -> Unit), arg : (Int, (Int, Int))[]) : Unit + { + let _ = arg; + let mapper = fct(1, _); + + for (_ in arg) { + for (_ in arg) { + for ((_, (i, _)) in arg) { + + let partial = fct(i, _); + partial(0); + } + } + } + let _ = arg; + mapper(0); + } +} + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Bug3059; + + operation DiscardedSymbolsTest () : Unit { + WithDiscardedSymbols(CheckPair, new (Int, (Int, Int))[5]); + } +} + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs new file mode 100644 index 00000000000..e65347a39e1 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Bug3758 { + open Microsoft.Quantum.Intrinsic; + + function Reverse<'T> (array : 'T[]) : 'T[] { + let nElements = Length(array); + return array[nElements-1..-1..0]; + } + + operation ApplyWithInputTransformation<'T, 'U>(fn : ('U -> 'T), op : ('T => Unit), input : 'U) : Unit { + op(fn(input)); + } + + function TransformedOperation<'T, 'U>(fn : ('U -> 'T), op : ('T => Unit)) : ('U => Unit) { + return ApplyWithInputTransformation(fn, op, _); + } + + + /// # Summary + /// An example operation used for testing input transformations. + operation TransformationReferenceForward(register : Qubit[]) : Unit is Adj + Ctl { + X(register[0]); + H(register[1]); + X(register[2]); + } + + /// # Summary + /// An example operation used for testing input transformations. + operation TransformationReferenceReverse(register : Qubit[]) : Unit is Adj + Ctl { + X(register[2]); + H(register[1]); + X(register[0]); + } +} + + + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + open Bug3758; + open Microsoft.Quantum.Diagnostics; + + operation TransformedOperationTest() : Unit { + AssertOperationsEqualReferenced(3, + TransformedOperation(Reverse, TransformationReferenceReverse), + TransformationReferenceForward + ); + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs new file mode 100644 index 00000000000..d21286ae838 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + operation NoOp (qubit : Qubit) : Unit { + + } + + + operation NoOpAdjoint (qubit : Qubit) : Unit { + + body (...) { + } + + adjoint invert; + } + + + operation NoOpControlled (qubit : Qubit) : Unit { + + body (...) { + } + + controlled distribute; + } + + + operation NoOpUnitary (qubit : Qubit) : Unit { + + body (...) { + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation NoOpTuple (r : Result, i : Int, qubit : Qubit) : Unit { + + } + + + operation NoOpAdjointTuple (r : Result, i : Int, qubit : Qubit) : Unit { + + body (...) { + } + + adjoint invert; + } + + + operation NoOpControlledTuple (r : Result, i : Int, qubit : Qubit) : Unit { + + body (...) { + } + + controlled distribute; + } + + + operation NoOpUnitaryTuple (r : Result, i : Int, qubit : Qubit) : Unit { + + body (...) { + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation CheckPlain (gate : (Qubit => Unit), qubit : Qubit) : Unit { + + gate(qubit); + } + + + operation CheckAdjoint (gate : (Qubit => Unit : Adjoint), qubit : Qubit) : Unit { + + Adjoint gate(qubit); + } + + + operation CheckControlled (gate : (Qubit => Unit : Controlled), qubit : Qubit) : Unit { + + + using (ctrls = Qubit[2]) { + Controlled gate(ctrls, qubit); + } + } + + + operation CheckUnitary (gate : (Qubit => Unit : Adjoint, Controlled), qubit : Qubit) : Unit { + + + using (ctrls = Qubit[2]) { + Adjoint Controlled gate(ctrls, qubit); + Controlled (Adjoint gate)(ctrls, qubit); + } + } + + + operation OneRound (plain : (Qubit => Unit), adj : (Qubit => Unit : Adjoint), ctr : (Qubit => Unit : Controlled), uni : (Qubit => Unit : Adjoint, Controlled)) : Unit { + + + using (qubits = Qubit[1]) { + let qubit = qubits[0]; + CheckPlain(plain, qubit); + CheckPlain(adj, qubit); + CheckPlain(ctr, qubit); + CheckPlain(uni, qubit); + CheckAdjoint(adj, qubit); + CheckAdjoint(uni, qubit); + CheckControlled(ctr, qubit); + CheckControlled(uni, qubit); + CheckUnitary(uni, qubit); + } + } + + + operation CallableInterfacesTest () : Unit { + + + // good 'ol operations + OneRound(NoOp, NoOpAdjoint, NoOpControlled, NoOpUnitary); + + // one level of partial application + OneRound(NoOpTuple(Zero, 1, _), NoOpAdjointTuple(Zero, 1, _), NoOpControlledTuple(Zero, 1, _), NoOpUnitaryTuple(Zero, 1, _)); + + // two level of partial application + OneRound((NoOpTuple(One, _, _))(1, _), (NoOpAdjointTuple(One, _, _))(1, _), (NoOpControlledTuple(One, _, _))(1, _), (NoOpUnitaryTuple(One, _, _))(1, _)); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs new file mode 100644 index 00000000000..58993da3734 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Math; + + + operation IncrementWithRotationsTest (start : Int) : Int { + + + using (qubits = Qubit[3]) { + for (shift in 0..2) { + if (((start >>> shift) &&& 1) == 1) { + R(PauliX, PI(), qubits[shift]); + } + } + + CCNOT(qubits[0], qubits[1], qubits[2]); + CNOT(qubits[0], qubits[1]); + //Rx(PI(), qubits[0]); + RFrac(PauliX, 1, 1, qubits[0]); + + let b0 = M(qubits[0]) == One ? 1 | 0; + let b1 = M(qubits[1]) == One ? 1 | 0; + let b2 = M(qubits[2]) == One ? 1 | 0; + + ResetAll(qubits); + + return b2 * 4 + b1 * 2 + b0; + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs new file mode 100644 index 00000000000..ad486935bed --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs @@ -0,0 +1,203 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// This files contains ClosedType version of operations that can normally be implemented +// with generics to verify that they can be used interchangeably. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.ClosedType { + + open Microsoft.Quantum.Intrinsic; + + + newtype Qs = Qubit[]; + + newtype UDT_C2 = (String, Int, Double); + + newtype UDT_C3 = (String, (Double, Pauli), Result); + + + operation AsString (v : Result) : String { + + + if (v == One) { + return $"uno"; + } + else { + return $"cero"; + } + } + + + operation Trace (tag : String) : Unit { + body intrinsic; + adjoint intrinsic; + controlled intrinsic; + controlled adjoint intrinsic; + } + + + operation TraceGate (gate : (Qubit => Unit : Adjoint, Controlled), tag : String, qubit : Qubit) : Unit { + + body (...) { + Trace(tag); + gate(qubit); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation ClosedType2 (tag : (String, Int, Double)) : Unit { + + body (...) { + let (msg, i, d) = tag; + Trace(msg); + } + + adjoint invert; + } + + + operation ClosedType3 (tag : (String, (Double, Pauli), Result)) : Unit { + + body (...) { + let (msg, t, r) = tag; + Trace(msg); + } + + controlled distribute; + } + + + operation ClosedType4 (r1 : Result, (t1 : String, t2 : Int), r2 : Result) : Unit { + + body (...) { + Trace(t1); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation ClosedType5 (tag : (String, Int, Double, Result)) : Unit { + + body (...) { + let (msg, i, d, r) = tag; + Trace(msg); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation Map (mapper : (Result => String), source : Result[]) : String[] { + + mutable result = new String[Length(source)]; + + for (i in 0 .. Length(source) - 1) { + let m = mapper(source[i]); + set result = result w/ i <- m; + } + + return result; + } + + + operation Iter (callback : (String => Unit), source : String[]) : Unit { + + + for (i in 0 .. Length(source) - 1) { + callback(source[i]); + } + } + + + operation Repeat (callback : (Qubit => Unit : Adjoint, Controlled), bodyCount : Int, adjointCount : Int, controlledCount : Int, source : Qubit) : Unit { + + body (...) { + + for (i in 1 .. bodyCount) { + callback(source); + } + + for (i in 1 .. adjointCount) { + Adjoint callback(source); + } + + for (i in 1 .. controlledCount) { + + using (ctrls = Qubit[1]) { + Controlled callback(ctrls, source); + } + } + } + + adjoint invert; + } + + + operation TestIter () : Unit { + + let ctrls = new Qubit[2]; + let a = [One, Zero, Zero]; + Iter(Trace, Map(AsString, a)); + let b = [One, One, Zero, Zero, Zero]; + Iter(Adjoint Trace, Map(AsString, b)); + let c = [One, Zero, One, One]; + let ctrlOp = Controlled Trace(ctrls, _); + Iter(ctrlOp, Map(AsString, c)); + let d = [One, Zero, One, Zero, One, Zero, One, Zero, One]; + let ctrlAdjOp = Adjoint Controlled Trace(ctrls, _); + Iter(ctrlAdjOp, Map(AsString, d)); + } + + + operation TestRepeatPartial () : Unit { + + let p1 = Repeat(_, 5, 2, _, _); + let p2 = p1(_, 3, _); + + using (qubits = Qubit[1]) { + p2(TraceGate(X, $"normal", _), qubits[0]); + Adjoint p2(TraceGate(X, $"adjoint", _), qubits[0]); + } + } + + + operation TestUDTsUnwrapping () : Unit { + + let d2a = ($"d2a", 2, 2.0); + let d2b = ($"d2b", 2, 2.0); + let u2c = UDT_C2(d2b); + let d2x = ($"d2x", 2, 2.0); + let d2y = ($"d2y", 2, 2.0); + let u2x = UDT_C2(d2x); + let u2y = UDT_C2(d2y); + + using (ctrls = Qubit[1]) { + let qs = Qs(ctrls); + ClosedType2(d2a); + ClosedType2((UDT_C2(d2b))!); + Adjoint ClosedType2(d2a); + Adjoint ClosedType2(u2c!); + let p = ClosedType5(_, _, _, One); + p(d2x); + p((UDT_C2(d2y))!); + Adjoint p(d2x); + Adjoint p(u2y!); + Controlled p(ctrls, u2x!); + Controlled p((Qs(ctrls))!, u2y!); + Adjoint Controlled p(qs!, u2x!); + Adjoint Controlled p(ctrls, u2y!); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs new file mode 100644 index 00000000000..8ecad7f1c0f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + operation ConditionalExpressionTest() : Unit { + using (q = Qubit()) { + AssertQubit(Zero, q); + + mutable flag = false; + (flag ? X | I)(q); + AssertQubit(Zero, q); + + set flag = true; + (flag ? X | I)(q); + AssertQubit(One, q); + + Reset(q); + } + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs new file mode 100644 index 00000000000..0bfa8a9bb98 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Convert; + + + operation ConvertTest () : Unit { + let (v1, b1) = MaybeBigIntAsInt(10L); + let (v2, b2) = MaybeBigIntAsInt(9223372036854775807L); + let (v3, b3) = MaybeBigIntAsInt(9223372036854775808L); + let (v4, b4) = MaybeBigIntAsInt(-10L); + let (v5, b5) = MaybeBigIntAsInt(-9223372036854775808L); + let (v6, b6) = MaybeBigIntAsInt(-9223372036854775809L); + + AssertEqual(10, v1); + AssertEqual(true, b1); + + AssertEqual(9223372036854775807, v2); + AssertEqual(true, b2); + + AssertEqual(0, v3); + AssertEqual(false, b3); + + AssertEqual(-10, v4); + AssertEqual(true, b4); + + //AssertEqual(-9223372036854775808, v5); should not fail + AssertEqual(true, b5); + + AssertEqual(0, v6); + AssertEqual(false, b6); + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs new file mode 100644 index 00000000000..75898a27657 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs @@ -0,0 +1,626 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Tests.CoreOperations { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Math; + + + newtype Q = Qubit; + + newtype Qs = Qubit[]; + + newtype T1 = (Qubit, Qubit); + + newtype T2 = (Qubit, Qubit[]); + + newtype T3 = (Qubit[], Qs); + + newtype T4 = (Int, (Double, Bool, Result)); + + newtype T5 = (Pauli, Qubit[], Qs, Q); + + newtype Plain1 = ((Qubit, Qubit) => Unit); + + newtype Adj1 = ((Qubit, Qubit) => Unit : Adjoint); + + newtype Adj2 = Adj1; + + newtype Ctrl1 = ((Qubit, Qubit) => Unit : Controlled); + + newtype U1 = ((Qubit, Qubit, Qubit[]) => Unit : Adjoint, Controlled); + + newtype U2 = U1; + + newtype U3 = (Qubit => Unit : Adjoint, Controlled); + + + operation BPlain1 (available : Int, q1 : Qubit, action : ((Qubit, Qubit) => Unit)) : Unit { + + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action(b[0], b[1]); + } + } + + + operation BPlain2 (available : Int, (q1 : Qubit, q2 : Qubit), action : Plain1) : Unit { + + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action!(b[0], b[1]); + } + } + + + operation BAdj1 (available : Int, (q1 : Qubit, q2 : Qubit, qs : Qubit[]), action : ((Qubit, Qubit) => Unit : Adjoint)) : Unit { + + body (...) { + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action(b[0], b[1]); + } + } + + adjoint invert; + } + + + operation BAdj2 (available : Int, qs : Qubit[], action : Adj1) : Unit { + + body (...) { + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action!(b[0], b[1]); + } + } + + adjoint invert; + } + + + operation BCtrl1 (available : Int, qs : Qs, action : ((Qubit, Qubit) => Unit : Controlled)) : Unit { + + body (...) { + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action(b[0], b[1]); + } + } + + controlled distribute; + } + + + operation BCtrl2 (available : Int, (qs1 : Qubit[], qs2 : Qs), action : Ctrl1) : Unit { + + body (...) { + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action!(b[0], b[1]); + } + } + + controlled distribute; + } + + + operation BU1 (available : Int, qs : Qubit[], action : ((Qubit, Qubit, Qubit[]) => Unit : Adjoint, Controlled)) : Unit { + + body (...) { + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action(b[0], b[1], qs); + } + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation BGen<'T> (available : Int, arg : 'T, action : ((Qubit, Qubit, 'T) => Unit : Adjoint, Controlled)) : Unit { + + body (...) { + + borrowing (b = Qubit[2]) { + Trace(available, b[0]); + Trace(available, b[1]); + action(b[0], b[1], arg); + } + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation Action (q0 : Qubit, q1 : Qubit, array : Qubit[]) : Unit { + + body (...) { + SWAP(q0, q1); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation ActionGen<'T> (q0 : Qubit, q1 : Qubit, array : 'T) : Unit { + + body (...) { + SWAP(q0, q1); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation TestAllVariants<'T> (available : Int, args : 'T, action : ((Qubit, Qubit, 'T) => Unit : Adjoint, Controlled), B : ((Int, 'T, ((Qubit, Qubit, 'T) => Unit : Adjoint, Controlled)) => Unit : Adjoint, Controlled)) : Unit { + + + using (ctrls = Qubit[2]) { + B(available, args, action); + Adjoint B(available, args, action); + Controlled B(ctrls, (available, args, action)); + Adjoint Controlled B(ctrls, (available, args, action)); + } + } + + + operation BorrowingTest () : Unit { + + + using (qubits = Qubit[5]) { + let q0 = qubits[0]; + let q1 = qubits[1]; + let q2 = qubits[2]; + let q3 = qubits[3]; + let q4 = qubits[4]; + let e = new Qubit[0]; + let n = new Qubit[5]; + let a_0 = [q0]; + let a_2_2 = [q2, q2]; + let a_2_4 = qubits[2 .. 4]; + let q_e = Qs(e); + let q_n = Qs(n); + let q_1 = Qs([q1]); + let q_2_2 = Qs(a_2_2); + let q_2_4 = Qs(a_2_4); + let t1_1_n = T1(q1, n[0]); + let t1_1_2 = T1(q1, q2); + let t2_1_n = T2(q1, n); + let t2_1_e = T2(q1, e); + let t2_1_a3 = T2(q1, a_2_4); + let t3_e_e = T3(e, q_e); + let t3_n_n = T3(n, q_n); + let t3_all = T3([q1, q2], q_2_4); + + BPlain1(0, n[0], Action(_,_,qubits)); // 0, q5 & q6 + + BPlain1(1, q1, Action(_,_,a_2_4)); // 1, q0 & q6 + BPlain2(1, ((Q(q0))!, (Q(q0))!), Plain1(Action(_,_,a_2_4))); // 1, q1 & q6 + + BPlain1(3, q0, Action(_,_,a_2_2)); // 3, q1 & q3 + BPlain2(3, (q1, q2), Plain1(SWAP)); // 3, q0 & q3 + + BPlain1(4, q1, (Plain1(SWAP))!); // 4, q0 & q2 + BPlain2(5, (n[0], n[1]), Plain1(SWAP)); // 5, q0 & q1 + + BAdj1(5, (n[0], n[1], e), (Adj1(SWAP))!); // 5, q0 & q1 + (Adjoint BAdj1)(1, (q1, q2, q_2_4!), SWAP); // 1, q0 & q6 + BAdj2(0, qubits, (Adj2(Adj1(SWAP)))!); // 0, q5 & q6 + (Adjoint BAdj2)(1, (Qs([q0, n[0]]))!, (Adj2(Adj1(Action(_,_,a_2_4))))!); // 1, q1 & q5 + + BCtrl1(5, q_n, SWAP); // 5, q0 & q1 + (Controlled BCtrl1)([q1], (1, q_2_4, SWAP)); // 1, q0 & q5 + BCtrl2(0, (a_2_2, Qs(qubits)), Ctrl1(SWAP)); // 0, q5 & q6 + let ctrl = (Controlled (Ctrl1(Action(_,_,a_2_2)))!)([q4], (_,_)); + (Controlled BCtrl2)([q0], (1, ([q3], q_n), Ctrl1(ctrl))); // 1, q1 & q5 + (Controlled BCtrl2)(q_e!, (5, (n, q_e), Ctrl1(Action(_,_,n)))); // 5, q0 & q1 + + TestAllVariants(0, qubits, ActionGen, BGen); // 0, q5 & q6 (q7 & q8 for controlled) + TestAllVariants(2, (q0, q1, q4), ActionGen<(Qubit, Qubit, Qubit)>, BGen<(Qubit, Qubit, Qubit)>); // 2, q2 & q3 + TestAllVariants(4, (Qs(q_1!))!, Action, BGen); // 4, q0 & q2 + TestAllVariants(3, [q0, q1], Action(_,_,_), BU1); // 3, q2 & q3 + TestAllVariants(0, qubits, ActionGen(_,_,_), BGen); // 0, q5 & q6 (q7 & q8 for controlled) + TestAllVariants(2, Qs([q0, q1, q4]), ActionGen(_,_,_), BGen); // 2, q2 & q3 + TestAllVariants(5, n, ActionGen(_,_,_), BGen); // 5, q0 & q1 + TestAllVariants(5, n, Action(_,_,_), BGen); // 5, q0 & q1 + TestAllVariants(4, a_0, Adjoint (ActionGen(_,_,_)), BGen); // 4, q1 & q2 + + TestAllVariants(1, e, (Controlled Action([q1,q2,q3,q0], (_,_,_))), BGen); // 1, q4 & q5 (q7 for controlled) + TestAllVariants(0, e, (Controlled (Adjoint ActionGen))(qubits, (_,_,_)), BGen); // 0, q5 & q6 (q7 & q8 for controlled) + } + } + + + operation SimpleRangeTest () : Unit { + + mutable ints = new Int[12]; + mutable results = new Result[12]; + mutable qubits = new Qubit[12]; + mutable qs = new Qs[12]; + mutable u1s = new U1[12]; + mutable state = new Complex[12]; + + for (i in 10 .. -2 .. 4) { + set ints = ints w/ i <- i; + set results = results w/ i <- One; + set qs = qs w/ i <- Qs(qubits); + set u1s = u1s w/ i <- U1(Action); + set state = state w/ i <- Complex(IntAsDouble(i), IntAsDouble(i + 1)); + Trace(ints[i]); + Trace(results[i]); + Trace(qubits[i]); + Trace(qs[i]); + Trace(u1s[i]); + Trace(state[i]); + } + } + + + operation SimpleDumpTest () : Unit { + + body (...) { + + using (qubits = Qubit[3]) { + Message($"Starting test"); + DumpMachine($"dumptest-start.txt"); + ApplyToEachCA(H, qubits); + DumpMachine($"dumptest-h.txt"); + DumpMachine($""); + + using (q2 = Qubit[2]) { + Assert([PauliZ, PauliZ], q2, Zero, $"Qubit should be in Zero state"); + DumpRegister($"dumptest-former.txt", qubits); + DumpRegister($"dumptest-later.txt", q2); + DumpRegister($"dumptest-one.txt", [qubits[1]]); + DumpRegister($"dumptest-two.txt", [qubits[1], q2[1]]); + DumpRegister((), [qubits[1], q2[1]]); + DumpRegister("", [q2[1], qubits[1]]); + DumpMachine($"dumptest-all.txt"); + ApplyToEachCA(Controlled X(qubits, _), q2); + DumpMachine($"dumptest-entangled.txt"); + DumpRegister((), [qubits[1], q2[1]]); + DumpRegister($"dumptest-twoQubitsEntangled.txt", [qubits[0], q2[0]]); + DumpMachine(); + ApplyToEachCA(Adjoint Controlled X(qubits, _), q2); + } + + Adjoint ApplyToEachCA(H, qubits); + } + + DumpMachine($"dumptest-end.txt"); + DumpMachine(); + } + } + + operation LockedFileDumpTest () : Unit { + using (qubits = Qubit[3]) { + DumpMachine($"locked-file.txt"); + DumpRegister($"locked-file.txt", qubits[0..1]); + + // Make sure execution continues: + Message("Done."); + } + } + + operation ZeroQubitsTest() : Unit + { + using (qubits = Qubit[0]) + { + if (Length(qubits) == 0) + { + Trace("zero"); + } + } + } +} + +// Using a different namespace, so tests can be auto-discovered. +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Math; + + operation QubitAllocationTest() : Unit { + let n = 3; + + using (q = Qubit()) { + Assert([PauliZ], [q], Zero, "Expecting Zero - a"); + } + + using (qs = Qubit[n]) { + AssertEqual(n, Length(qs)); + Assert([PauliZ, PauliZ, PauliZ], qs, Zero, "Expecting Zero - b"); + } + + using ((q1, (q2t, (_, q3s, _, q4s))) = (Qubit(), ((Qubit(), Qubit[2]), (Qubit(), Qubit[n], Qubit[n-1], Qubit[4])))) { + let (a, b) = q2t; + + AssertEqual(2, Length(b)); + AssertEqual(n, Length(q3s)); + AssertEqual(4, Length(q4s)); + + Assert([PauliZ, PauliZ], [q1, a], Zero, "Expecting Zero - c"); + Assert([PauliZ, PauliZ], b, Zero, "Expecting Zero - d"); + Assert([PauliZ, PauliZ, PauliZ], q3s, Zero, "Expecting Zero - d"); + Assert([PauliZ, PauliZ, PauliZ, PauliZ], q4s, Zero, "Expecting Zero - e"); + + } + + using (qt = (Qubit(), (Qubit[1], Qubit[2]))) { + let (qt1, (qt2a, qt2b)) = qt; + + Assert([PauliZ], [qt1], Zero, "Expecting Zero - f"); + Assert([PauliZ], qt2a, Zero, "Expecting Zero - g"); + Assert([PauliZ, PauliZ], qt2b, Zero, "Expecting Zero - h"); + } + } + + + operation ExtendedForTest() : Unit + { + mutable n = 0; + + using (qs = Qubit[3]) { + + for(q in qs) { + Assert([PauliZ], [q], Zero, "Expecting Zero - a"); + set n = n + 1; + } + + AssertEqual(3, n); + } + } + + function WhileLoopTest() : Unit + { + mutable ctr = 0; + while (ctr < 10) { + set ctr += 1; + } + AssertEqual(ctr, 10); + } + + newtype WrappedInt = (Int); + + operation InterpolatedStringTest() : Unit + { + let a = 5; + let b = "Hello"; + let c = 1..2..3; + let d = WrappedInt(6); + let s = $"{b}, world! {a}+{RangeStart(c)}={d!}"; + AssertEqual("Hello, world! 5+1=6", s); + } + + operation RandomOperationTest() : Unit + { + let a = Random([1.0, 0.0]); + AssertEqual(0, a); + + let b = Random([0.0,0.1]); + AssertEqual(1, b); + } + + function BigIntTest() : Unit + { + let a = 2L; + let b = 32L; + AssertEqual(b, a ^ 5); + AssertEqual(0L, a &&& b); + AssertEqual(34L, a + b); + let arr = [true, true, true, false, true]; // Not an even number of bytes + AssertEqual(23L, BoolArrayAsBigInt(arr)); + let arr2 = [true, true, true, false, true, false, false, false, + true, false, false, false, false, false, false, false]; // Exactly 2 bytes + AssertEqual(279L, BoolArrayAsBigInt(arr2)); + AssertEqual(37L, BoolArrayAsBigInt(BigIntAsBoolArray(37L))); + let (div, rem) = DivRemL(16L, 5L); + AssertEqual(3L, div); + AssertEqual(1L, rem); + AssertEqual(7L, MaxL(7L, 5L)); + AssertEqual(5L, MinL(7L, 5L)); + AssertEqual(1L, ModPowL(3L, 100L, 2L)); + } + + operation RangePropsTest() : Unit + { + let range = 1..2..10; + let actual = RangeStart(range) + RangeEnd(range) + RangeStep(range); + AssertEqual(13, actual); + } + + function ArraySlicingTest() : Unit + { + let arr = [1,2,3,4,5,6]; + let slice1 = arr[3...]; + AssertEqual(slice1, [4,5,6]); + let slice2 = arr [0 .. 2 ... ]; + AssertEqual(slice2, [1,3,5]); + let slice3 = arr[...2]; + AssertEqual(slice3, [1,2,3]); + let slice4 = arr[...2..3]; + AssertEqual(slice4, [1,3]); + let slice5 = arr[...2...]; + AssertEqual(slice5, [1,3,5]); + let slice6 = arr[...]; + AssertEqual(slice6, arr); + let slice7 = arr [4 .. -2 ... ]; + AssertEqual(slice7, [5,3,1]); + let slice8 = arr[ ... 0-1 .. 3]; + AssertEqual(slice8, [6,5,4]); + let slice9 = arr[...4-5...]; + AssertEqual(slice9, [6,5,4,3,2,1]); + } + + operation ReturnFromWithinUsing() : Int { + using (q = Qubit()){ + return 1; + } + } + + operation ReturnFromWithinBorrowing() : Int { + borrowing (q = Qubit()){ + return 1; + } + } + + operation ReturnTest() : Unit { + let _ = ReturnFromWithinUsing(); + let _ = ReturnFromWithinBorrowing(); + } + + operation VariablesScopeTest() : Unit + { + mutable a = 0; + + using (qubits = Qubit[5]) + { + for(q in qubits) { + set a = a + 1; + } + AssertEqual(5, a); + + for(q in 0 .. 3) { + set a = a + 1; + } + AssertEqual(9, a); + } + + borrowing (qubits = Qubit[2]) + { + for(q in qubits) { + set a = a + 1; + } + AssertEqual(11, a); + + for(q in 0 .. 0) { + set a = a + 1; + } + AssertEqual(12, a); + } + } + + // Returning the value returned by a function + // that returns Unit... + // Not totally sure if this should be allowed, but it works as of v0.3 + function Bar() : Unit { } + + function Foo<'T>(a: 'T) : Unit { + return Bar(); + } + + operation Bug2186Test() : Unit { + return Foo(3); + } + + operation UsingQubitCheck () : Unit + { + using (q = Qubit()) + { + X(q); + // Should raise an exception + } + } + + operation ReleaseMeasuredQubitCheck () : Unit + { + using (q = Qubit()) + { + X(q); + let r = M(q); + // Should not raise an exception + } + } + + operation BorrowingQubitCheck () : Unit + { + using (q = Qubit()) + { + QubitBorrower(); + } + } + + operation QubitBorrower() : Unit + { + borrowing (q = Qubit()) + { + X(q); + // Should raise an exception + } + } + + operation DumpPhaseTest() : Unit + { + using (qs = Qubit[5]) { + H(qs[0]); + Controlled X(qs[0..0], qs[1]); + T(qs[1]); + DumpRegister($"dumptest-entangled-and-phased.txt", qs[0..1]); + ResetAll(qs); + + for(q in qs) { H(q); } + + R1Frac(1, 3, qs[0]); + R1Frac(1, 2, qs[1]); + R1Frac(1, 1, qs[2]); + R1Frac(1, 0, qs[3]); + + DumpRegister($"dumptest-phase.txt", qs); + + ResetAll(qs); + } + } + + operation PiTest() : Unit { + let pi = PI(); + + AssertEqual(true, (pi > 3.14 and pi < 3.15)); + } + + internal function EmptyInternalFunction() : Unit { } + + internal operation EmptyInternalOperation() : Unit { } + + internal newtype InternalType = Int; + + internal operation MakeInternalType() : InternalType { + return InternalType(5); + } + + // This is a public operation that uses an internal type inside to test the access modifiers of the generated + // operation properties. + operation InternalCallablesTest() : Unit { + EmptyInternalFunction(); + EmptyInternalOperation(); + let x = InternalType(3); + let y = MakeInternalType(); + AssertEqual(15, x! * y!); + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs new file mode 100644 index 00000000000..430bbd0ccdd --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Intrinsic; + + + // At some point, this was causing the simulator to crash. + + operation ExpCrashTest () : Unit { + + + using (qubits = Qubit[3]) { + let q1 = qubits[0]; + let q2 = qubits[1]; + let ctrls = qubits[2 .. 2]; + Exp([PauliZ], 0.5678, [q1]); + Controlled Exp(ctrls, ([PauliZ], 0.5678, [q1])); + Exp([PauliZ, PauliZ], 0.6799, [q1, q2]); + Controlled Exp(ctrls, ([PauliZ, PauliZ], 0.6799, [q1, q2])); + + // Make sure all allocated qubits are measured before release + let (r1, r2, r3) = (M(q1), M(q2), M(ctrls[0])); + X(q1); + ResetAll(qubits); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs new file mode 100644 index 00000000000..1f079c005eb --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs @@ -0,0 +1,99 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + operation AlwaysFail() : Unit is Adj + Ctl{ + Fail(); + } + + operation AlwaysFail1() : Unit is Adj + Ctl{ + AlwaysFail(); + } + operation AlwaysFail2() : Unit is Adj + Ctl { + Controlled AlwaysFail1(new Qubit[0],()); + } + operation AlwaysFail3() : Unit is Adj + Ctl { + Adjoint AlwaysFail2(); + } + + operation AlwaysFail4() : Unit is Adj + Ctl { + Adjoint AlwaysFail3(); + } + + operation GenericFail<'T,'U>( a : 'T, b : 'U ) : Unit is Adj + Ctl { + AlwaysFail(); + } + + operation GenericFail1() : Unit is Adj + Ctl { + GenericFail(5,6); + } + + operation PartialFail( a : Int, b : Int ) : Unit is Adj + Ctl { + AlwaysFail(); + } + + operation PartialFail1() : Unit is Adj + Ctl { + let op = PartialFail(0,_); + op(2); + } + + operation PartialAdjFail1() : Unit is Adj + Ctl { + let op = PartialFail(0,_); + Adjoint op(2); + } + + operation PartialCtlFail1() : Unit is Adj + Ctl { + let op = PartialFail(0,_); + Controlled op(new Qubit[0], 2); + } + + operation GenericAdjFail1() : Unit is Adj + Ctl { + Adjoint GenericFail(5,6); + } + + operation GenericCtlFail1() : Unit is Adj + Ctl { + Controlled GenericFail( new Qubit[0], (5,6)); + } + + function Fail() : Unit { + fail "Always fail"; + } + + operation RecursionFail( a : Int) : Unit is Adj { + if ( a >= 1 ) + { + RecursionFail(a-1); + } + else + { + Fail(); + } + } + + operation RecursionFail1() : Unit { + RecursionFail(2); + } + + operation DivideBy0() : Int { + let z = 0; + return 3 / z; + } + + operation AllGood() : Unit { + Microsoft.Quantum.Intrinsic.Message("All good!"); + } + + operation AllGood1() : Unit { + AllGood(); + } + + operation AllocateQubit2 () : Unit { + using (q = Qubit()) { + Microsoft.Quantum.Intrinsic.H(q); + Microsoft.Quantum.Diagnostics.AssertMeasurement( + [PauliZ], [q], One, "" + ); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs new file mode 100644 index 00000000000..36e698a6924 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + function Add(a: Int, b: Int) : Int + { + return a + b; + } + + function ApplyTwice<'T>(f: ('T -> Int), a: 'T) : Int + { + return f(a) + f(a); + } + + operation PartialFunctionsTest () : Unit + { + let plusFive = Add(5, _); + let partial_3 = ApplyTwice(_, 3); + let partial_9 = ApplyTwice(_, 9); + + AssertEqual(12, ApplyTwice(plusFive, 1)); + AssertEqual(16, partial_3(plusFive)); + AssertEqual(28, partial_9(plusFive)); + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs new file mode 100644 index 00000000000..636f92002f3 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs @@ -0,0 +1,884 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// This files contains Generic version of gates in ClosedTypes.qb +// to verify that they can be used interchangeably. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; + + + newtype UDT_G1 = (Int, Qubit); + + newtype UDT_G2 = (Qubit, Qubit); + + newtype UDT_G3 = (Bool[], Qubit); + + newtype UDT_G4 = (Bool[], Int, Qubit); + + newtype UDT_G5 = (UDT_G1, UDT_G2); + + newtype UDT_G6 = (UDT_G1[], UDT_G2); + + newtype UDT_G7 = UDT_G1; + + newtype LittleEndian = Qubit[]; + + + operation AsString (v : Result) : String { + + if (v == One) { + return $"uno"; + } + else { + return $"cero"; + } + } + + + operation Trace<'T> (tag : 'T) : Unit + is Adj + Ctl { + body intrinsic; + } + + + operation Gen0<'I> (tag : 'I) : Unit + is Adj + Ctl { + Trace(tag); + } + + + operation Gen1<'I, 'O> (i : 'I, o : 'O) : 'O { + + Trace(i, o); + return o; + } + + + operation Gen2<'T1, 'T2> (tag : ('T1, Int, 'T2)) : Unit + is Adj { + Trace(tag); + } + + + operation Gen3<'T1, 'T2, 'T3> (tag : ('T1, ('T2, 'T3), Result)) : Unit + is Ctl { + Trace(tag); + } + + + operation Gen4<'T1, 'T2> (r1 : Result, (t1 : 'T1, t2 : 'T2), r2 : Result) : Unit + is Adj + Ctl { + Trace(r1, (t1, t2), r2); + } + + + operation Gen5<'I> (tags : 'I[]) : Unit + is Adj + Ctl { + + for (i in 0 .. Length(tags) - 1) { + Trace(tags[i]); + } + } + + + operation Gen6<'I> (data : ((Int, 'I)[], (Qubit, Qubit))) : Unit + is Adj + Ctl { + let (tags, qubits) = data; + + for (i in 0 .. Length(tags) - 1) { + Trace(tags[i]); + } + } + + + operation Gen7<'I> (data : (Int, 'I[])) : Unit + is Adj + Ctl { + let (index, tags) = data; + + for (i in 0 .. Length(tags) - 1) { + Trace(tags[i]); + } + } + + + operation TraceGate<'T> (gate : (Qubit => Unit is Adj + Ctl), tag : 'T, qubit : Qubit) : Unit + is Adj + Ctl { + Trace(tag); + gate(qubit); + } + + + operation Map<'T, 'U> (mapper : ('T => 'U), source : 'T[]) : 'U[] { + + mutable result = new 'U[Length(source)]; + + for (i in 0 .. Length(source) - 1) { + let m = mapper(source[i]); + set result = result w/ i <- m; + } + + return result; + } + + + operation Iter<'T> (callback : ('T => Unit), source : 'T[]) : Unit { + + for (i in 0 .. Length(source) - 1) { + callback(source[i]); + } + } + + + operation Repeat<'T> (callback : ('T => Unit is Adj + Ctl), bodyCount : Int, adjointCount : Int, controlledCount : Int, source : 'T) : Unit + is Adj { + let r = 1 .. bodyCount; + + for (i in r) { + callback(source); + } + + for (i in 1 .. adjointCount) { + Adjoint callback(source); + } + + for (i in 1 .. controlledCount) { + + using (ctrls = Qubit[1]) { + Controlled callback(ctrls, source); + } + } + } + + + operation TestIter () : Unit { + + using (ctrls = Qubit[2]) { + let a = [One, Zero, Zero]; + Iter(Trace, a); + Iter(Trace, Map(AsString, a)); + let b = [One, One, Zero, Zero, Zero]; + Iter(Adjoint Trace, b); + Iter(Adjoint Trace, Map(AsString, b)); + let c = [One, Zero, One, One]; + let ctrlOpResult = Controlled Trace(ctrls, _); + let ctrlOpString = Controlled Trace(ctrls, _); + Iter(ctrlOpResult, c); + Iter(ctrlOpString, Map(AsString, c)); + let d = [One, Zero, One, Zero, One, Zero, One, Zero, One]; + let ctrlAdjOpResult = Adjoint Controlled Trace(ctrls, _); + let ctrlAdjOpString = Adjoint Controlled Trace(ctrls, _); + Iter(ctrlAdjOpResult, d); + Iter(ctrlAdjOpString, Map(AsString, d)); + Iter(X, ctrls); + Iter(Adjoint X, ctrls); + } + } + + + operation TestRepeatPartial () : Unit { + + let p1 = Repeat(_, 5, 2, _, _); + let p2 = p1(_, 3, _); + + using (qubits = Qubit[1]) { + p2(TraceGate(X, $"normal", _), qubits[0]); + Adjoint p2(TraceGate(X, $"adjoint", _), qubits[0]); + } + } + + + operation RepeatWrapper (callback : (Qubit => Unit is Adj + Ctl)) : ((Int, Int, Int, Qubit) => Unit is Adj) { + + return Repeat(callback, _, _, _, _); + } + + + operation TestCreateRepeatWrapperPartial () : Unit { + + using (qubits = Qubit[1]) { + let traceNormal = TraceGate(X, $"normal", _); + let traceAdjoint = TraceGate(X, $"adjoint", _); + let normal = ((RepeatWrapper(traceNormal))(_, 2, _, _))(5, 3, _); + let adj = Adjoint ((RepeatWrapper(traceAdjoint))(5, 2, _, _))(3, _); + normal(qubits[0]); + adj(qubits[0]); + } + } + + + function ItemAt<'T> (i : Int, array : 'T[]) : 'T { + + return array[i]; + } + + + function CreateLookup<'T> (array : 'T[]) : (Int -> 'T) { + + return ItemAt(_, array); + } + + + operation DoAll<'T> (lookup : (Int -> ('T => Unit is Adj + Ctl)), range : Range, target : 'T) : Unit + is Adj + Ctl { + + using (ctrls = Qubit[2]) { + + for (i in range) { + let op = lookup(i); + op(target); + Adjoint op(target); + Controlled op(ctrls, target); + } + } + } + + + operation TestLookupUnitaries () : Unit { + + let traceLookup = CreateLookup([Trace, Trace, Trace]); + let xLookup = CreateLookup([X, X, X, X]); + let range = 0 .. 2; + + using (ctrls = Qubit[1]) { + DoAll(traceLookup, range, $"uno"); + Adjoint DoAll(traceLookup, range, $"uno"); + Controlled DoAll(ctrls, (traceLookup, range, $"uno")); + + using (qubits = Qubit[1]) { + DoAll(xLookup, range, qubits[0]); + Controlled DoAll(ctrls, (xLookup, range, qubits[0])); + } + } + } + + + operation NestedArgTuple (a : (String, String), (b : Int, (c : Int, d : (Result, Result)), e : String)) : Unit + is Adj + Ctl { + + Trace(a); + Trace(b); + Trace(c); + Trace(d); + Trace(e); + let (a1, a2) = a; + Trace(a1); + Trace(a2); + let (d1, d2) = d; + Trace(d1); + Trace(d2); + } + + + operation NestedArgTupleParameter (op : (((String, String), (Int, (Int, (Result, Result)), String)) => Unit is Adj + Ctl), a : (String, String), b : Int, c : Int, d : (Result, Result), e : String) : Unit { + + using (qubits = Qubit[2]) { + let (a1, a2) = a; + let (d1, d2) = d; + let p1A = op(a, (b, (_, d), _)); + let p2A = p1A(c, _); + p1A(c, e); + Adjoint p1A(c, e); + Controlled (Adjoint p1A)(qubits, (c, e)); + p2A(e); + Adjoint p2A(e); + Adjoint Controlled p2A(qubits, e); + let p1B = Controlled op(_, ((a1, _), (b, (c, (_, _)), _))); + let p2B = p1B(qubits, (a2, (_, _))); + let p3B = p2B(d, _); + p1B(qubits, (a2, (d, e))); + p1B(qubits[0 .. 1], (a2, ((d1, d2), e))); + Adjoint p2B(d, e); + Controlled p2B(qubits, ((d1, d2), e)); + Controlled (Adjoint p3B)(qubits, e); + } + } + + + operation TestNonGenericPartial () : Unit { + + let a = ($"a1", $"a2"); + let (a1, a2) = a; + let b = 2; + let c = 3; + let d = (Zero, One); + let (d1, d2) = d; + let e = $"e"; + let p1A = NestedArgTuple(a, (b, (_, d), _)); + let p2A = p1A(c, _); + p1A(c, e); + Adjoint p1A(c, e); + p2A(e); + Adjoint p2A(e); + let p1B = Adjoint NestedArgTuple((a1, _), (b, (c, (_, _)), _)); + let p2B = p1B(a2, (_, _)); + let p3B = p2B(d, _); + p1B(a2, (d, e)); + p1B(a2, ((d1, d2), e)); + p2B(d, e); + p2B((d1, d2), e); + p3B(e); + Adjoint p1B(a2, (d, e)); + Adjoint p2B(d, e); + Adjoint p3B(e); + NestedArgTupleParameter(NestedArgTuple, a, b, c, d, e); + } + + + operation NestedArgTupleGeneric<'A, 'B, 'C> (a : ('A, Int), (b : 'B, (c : Int, d : (Result, 'C)), e : Double)) : Unit { + + let (a1, a2) = a; + + // a1 is arg of type 'A + Trace(a1); + + // b is arg of type 'B + Trace(b); + let (d1, d2) = d; + + // d2 is arg of type 'C + Trace(d2); + } + + + operation TestGenericPartial () : Unit { + + let a = ($"argA", 0); + let (a1, a2) = a; + let b = $"argB"; + let c = 0; + let d = (Zero, $"argD"); + let (d1, d2) = d; + let e = 0.0; + let stringTuple = ($"T1", $"T2"); + + // NestedArgTupleGeneric (a, (b, (c, d), e)); + let p1A = NestedArgTupleGeneric(a, (b, (_, d), _)); + p1A(c, e); + let p1B = NestedArgTupleGeneric((stringTuple, a2), (b, (_, d), _)); + p1B(c, e); + let p1C = NestedArgTupleGeneric(a, (stringTuple, (_, d), _)); + p1C(c, e); + let p1D = NestedArgTupleGeneric(a, (b, (_, (d1, stringTuple)), _)); + p1D(c, e); + let p2A = NestedArgTupleGeneric(_, (_, (c, d), e)); + p2A(a, b); + let p2B = NestedArgTupleGeneric<(String, String), String, String>(_, (_, (c, d), e)); + p2B((stringTuple, a2), b); + let p2C = NestedArgTupleGeneric(_, (_, (c, d), e)); + p2C(a, stringTuple); + let p2D = NestedArgTupleGeneric(_, (_, (c, (d1, stringTuple)), e)); + p2D(a, b); + let p3A = NestedArgTupleGeneric(a, (_, (_, _), e)); + p3A(b, (c, d)); + let p3B = NestedArgTupleGeneric<(String, String), String, String>((stringTuple, a2), (_, (_, _), e)); + p3B(b, (c, d)); + let p3C = NestedArgTupleGeneric(a, (_, (_, _), e)); + p3C(stringTuple, (c, d)); + let p3D = NestedArgTupleGeneric(a, (_, (_, _), e)); + p3D(b, (c, (d1, stringTuple))); + + // Inner partials: + let p4A = NestedArgTupleGeneric(a, (_, (_, _), e)); + let p4Aa = p4A(b, (_, _)); + p4Aa(c, d); + let p4B = NestedArgTupleGeneric(a, (_, (_, _), e)); + let p4Ba = p4B(b, (c, _)); + p4Ba(One, $"otherD"); + return (); + } + + + operation BindTest () : Unit { + let bound = Bind([X, X, X]); + + // FIXME: switched the second argument from ApplyToEach(..) to ApplyToEachA(..) + AssertOperationsEqualReferenced(ApplyToEach(bound, _), ApplyToEachA(X, _), 3); + } + + + operation BindImpl<'T> (operations : ('T => Unit is Adj + Ctl )[], target : 'T) : Unit { + + for (idxOperation in 0 .. Length(operations) - 1) { + let op = operations[idxOperation]; + op(target); + } + } + + + function Bind<'T> (operations : ('T => Unit is Adj + Ctl)[]) : ('T => Unit) { + + return BindImpl(operations, _); + } + + + operation ApplyToEachA<'T> (singleQubitOperation : ('T => Unit is Adj), register : 'T[]) : Unit + is Adj { + + for (idxQubit in 0 .. Length(register) - 1) { + singleQubitOperation(register[idxQubit]); + } + } + + + operation ApplyToEach<'T> (singleQubitOperation : ('T => Unit), register : 'T[]) : Unit { + + for (idxQubit in 0 .. Length(register) - 1) { + singleQubitOperation(register[idxQubit]); + } + } + + + operation ApplyToEachCA<'T> (singleQubitOperation : ('T => Unit is Adj + Ctl), register : 'T[]) : Unit + is Adj + Ctl { + + for (idxQubit in 0 .. Length(register) - 1) { + singleQubitOperation(register[idxQubit]); + } + } + + + operation AssertOperationsEqualReferenced (actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit { + + using (qs = Qubit[2]) { + Adjoint expected(qs); + actual(qs); + } + + Trace($"success!"); + } + + + operation CCNOT2OuterCircuit (qs : Qubit[]) : Unit + is Adj + Ctl { } + + + operation UpToPhaseCCNOT2 (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit + is Adj { + WithA(CCNOT2OuterCircuit, [target, control1, control2]); + } + + + operation WithA<'T> (outerOperation : ('T => Unit is Adj), target : 'T) : Unit + is Adj {} + + + operation CCNOTCiruitsTest () : Unit { + + using (qubits = Qubit[3]) { + Adjoint UpToPhaseCCNOT2(qubits[0], qubits[1], qubits[2]); + } + + Trace($"success!"); + } + + + operation CountQs<'T> (qs : 'T[]) : Unit + is Adj { + + body (...) { + Trace(Length(qs)); + } + + controlled (cs, ...) { + Trace(Length(qs) + Length(cs)); + } + } + + + operation CountQsNonGeneric (qs : Qubit[]) : Unit + is Adj { + + body (...) { + Trace(Length(qs)); + } + + controlled (cs, ...) { + Trace(Length(qs + cs)); + } + } + + + operation MultiControlledTest () : Unit { + + using (qs = Qubit[1]) { + using (cs1 = Qubit[1]) { + using (cs2 = Qubit[1]) { + using (cs3 = Qubit[1]) { + CountQs(qs); + Controlled CountQs(cs1, qs); + Controlled (Controlled CountQs)(cs1, (cs2, qs)); + Controlled (Controlled (Controlled CountQs))(cs1, (cs2, (cs3, qs))); + } + } + } + } + } + + + operation MixedComponentsTest () : Unit { + + using (qs = Qubit[1]) { + using (cs1 = Qubit[1]) { + using (cs2 = Qubit[1]) { + Adjoint (Adjoint CountQs)(qs); + Controlled (Adjoint CountQs)(cs1, qs); + Adjoint Controlled (Adjoint CountQs)(cs1, qs); + Controlled (Controlled (Adjoint CountQs))(cs1, (cs2, qs)); + } + } + } + } + + + function AddControlled<'A> (op : ('A => Unit is Adj + Ctl)) : ((Qubit[], 'A) => Unit is Adj + Ctl) { + + return Controlled op; + } + + + function ReturnId<'A> (arg : 'A) : 'A { + + return arg; + } + + + operation AssignmentsTest () : Unit { + + using (qs = Qubit[1]) { + using (cs1 = Qubit[1]) { + using (cs2 = Qubit[1]) { + let AAOp = Adjoint (Adjoint CountQs); + AAOp(qs); + (ReturnId(Controlled (Adjoint CountQs)))(cs1, qs); + let CCAOp = AddControlled(Controlled (Adjoint CountQs)); + CCAOp(cs1, (cs2, qs)); + Adjoint CCAOp(cs1, (cs2, qs)); + let CCANGOp = AddControlled(Controlled (Adjoint CountQsNonGeneric)); + CCANGOp(cs1, (cs2, qs)); + Adjoint CCANGOp(cs1, (cs2, qs)); + } + } + } + } + + + operation AssignmentsWithPartialsTest () : Unit { + + using (qs = Qubit[1]) { + using (cs1 = Qubit[1]) { + using (cs2 = Qubit[1]) { + let Op1 = (ReturnId(Controlled (Adjoint CountQs)))(cs1, _); + Op1(qs); + let CCAOpFull = AddControlled(Controlled (Adjoint CountQs)); + let CCAOp = CCAOpFull(_, (cs2, _)); + Adjoint CCAOp(cs1, qs); + Adjoint (CCAOp(cs1, _))(qs); + let CCANGOpFull = AddControlled(Controlled (Adjoint CountQsNonGeneric)); + let CCANGOp = CCANGOpFull(cs1, _); + Adjoint CCANGOp(cs2, qs); + } + } + } + } + + + function Indirection<'A> (arg : 'A) : 'A[] { + + mutable arr = new 'A[5]; + + for (i in 0 .. Length(arr) - 1) { + set arr = arr w/ i <- arg; + } + + return arr; + } + + + function MapDefaults<'T> (fct : ('T -> Unit), dummy : 'T) : Unit { + + let arr = new 'T[5]; + let fcts = Indirection(fct); + + for (i in 0 .. Length(arr) - 1) { + fcts[i](arr[i]); + } + } + + + function Mapper (i : Int) : Unit { + + return (); + } + + + operation TestMapDefaults () : Unit { + + MapDefaults(Mapper, 1); + Trace($"success!"); + } + + + function ChooseFirst<'A, 'B, 'C> ((a : 'A, b : 'B), c : 'C) : 'A { + + return a; + } + + + operation TypeParameters<'A, 'B> (a : ('A, 'B), b : 'B, c : 'B, d : (('A, 'A), 'B)) : Unit + is Adj { + + body (...) { + Trace(ChooseFirst(d)); + } + + controlled (cs, ...) { + Trace(b, c); + } + } + + + operation TestMultipleTypeParamters () : Unit { + + let a = (2, Zero); + let b = One; + let d = ((1, 3), One); + TypeParameters(a, b, b, d); + } + + + operation TestDestructingArgTuple () : Unit { + + let a = (2, Zero); + let b = One; + let d = ((1, 3), One); + let arg = (a, b, b, d); + TypeParameters(arg); + let stringArg = (new Qubit[0], ((2, $""), $"Hello", $"World", ((2, 2), $""))); + Controlled TypeParameters(stringArg); + Controlled (Adjoint TypeParameters)(stringArg); + } + + + operation ComposeImpl<'A, 'B> (second : ('A => Unit), first : ('B => 'A), arg : 'B) : Unit { + + second(first(arg)); + } + + + operation Compose<'A, 'B> (second : ('A => Unit), first : ('B => 'A)) : ('B => Unit) { + + return ComposeImpl(second, first, _); + } + + + operation TestCompose () : Unit { + + let fct = Compose(Trace, AsString); + fct(Zero); + } + + + operation TraceNonGeneric (tag : String) : Unit + is Adj + Ctl { + + let arg = $"redirecting:" + tag; + Trace(arg); + } + + + operation TestComposeWithNonGeneric () : Unit { + + let fct = Compose(TraceNonGeneric, AsString); + fct(Zero); + } + + + operation WithCA<'T> (outerOperation : ('T => Unit is Adj), innerOperation : ('T => Unit is Adj + Ctl), target : 'T) : Unit + is Adj { + + body (...) { + outerOperation(target); + innerOperation(target); + Adjoint outerOperation(target); + } + + controlled (controlRegister, ...) { + outerOperation(target); + Controlled innerOperation(controlRegister, target); + Adjoint outerOperation(target); + } + } + + + operation ApplyPauliFromBitString (pauli : Pauli, bitApply : Bool, bits : Bool[], qubits : Qubit[]) : Unit + is Adj + Ctl { + let nBits = Length(bits); + + for (idxBit in 0 .. nBits - 1) { + + if (bits[idxBit] == bitApply) { + X(qubits[idxBit]); + Trace(idxBit); + } + } + } + + + operation ControlledOnBitStringImpl<'T> (bits : Bool[], oracle : ('T => Unit is Adj + Ctl), controlRegister : Qubit[], targetRegister : 'T) : Unit + is Adj + Ctl { + WithCA(ApplyPauliFromBitString(PauliX, false, bits, _), Controlled oracle(_, targetRegister), controlRegister); + } + + + function ControlledOnBitString<'T> (bits : Bool[], oracle : ('T => Unit is Adj + Ctl)) : ((Qubit[], 'T) => Unit is Adj + Ctl) { + + return ControlledOnBitStringImpl(bits, oracle, _, _); + } + + + // This tests that we can use UDT (that maps to a Q[]) as a controlled parameter. + + operation TestControlledBitString () : Unit { + + using (data = Qubit[3]) { + let bits = [false, true, false]; + + // this is key... allows to tes UDTs as input for partials that expects qubits. + // (not supported in 0.3+ without unwrapping...) + let qubits = LittleEndian(data); + (ControlledOnBitString(bits, Trace))(qubits!, $"ok"); + } + } + + + // This tests that we can use an UDT (that maps to a Q[]) as input where a Q[] is expected. + + operation TestApplyToEachUdt () : Unit { + + using (data = Qubit[3]) { + + using (control = Qubit[1]) { + let q0 = Gen1(0, data[0]); + let q1 = Gen1((UDT_G1(1, data[1]))!); + let q2 = Gen1((UDT_G7(UDT_G1(2, data[2])))!!); + let qubits = LittleEndian([q0, q1, q2]); + Controlled (ApplyToEachCA(Trace, _))(control, qubits!); + } + } + } + + + function UnboxG1Array (data : UDT_G1[]) : (Int, Qubit)[] { + + let count = Length(data); + mutable result = new (Int, Qubit)[count]; + + for (i in 0 .. count - 1) { + let (n, q) = data[i]!; + set result = result w/ i <- (n, q); + } + + return result; + } + + + function UnboxG6 (data : UDT_G6) : ((Int, Qubit)[], (Qubit, Qubit)) { + + let (u1, u2) = data!; + let (q1, q2) = u2!; + return (UnboxG1Array(u1), (q1, q2)); + } + + + operation TestUDTsPolyMorphism () : Unit { + + + using (data = Qubit[3]) { + + using (control = Qubit[1]) { + let q0 = Gen1(0, data[0]); + let q1 = Gen1((UDT_G1(1, data[1]))!); + let q2 = Gen1((UDT_G7(UDT_G1(2, data[2])))!!); + let qubits = LittleEndian([q0, q1, q2]); + let u1 = UDT_G1(1, qubits![1]); + let u2 = UDT_G2(q2, qubits![2]); + let u1s = [u1]; + let u2s = [u2, u2]; + let u6 = UDT_G6(u1s, u2); + let u7 = UDT_G7(u1); + let u7s = [u7]; + + //Gen5<'I>(tags: 'I[]) + Gen5(data); + Gen5(qubits!); + Gen5(u1s); + Gen5(u2s); + Gen5(u7s); + + //Gen6<'I>(tags: ((Int, 'I)[], (Qubit, Qubit)) + // TODO: Automatic unboxing for Arrays... Gen6(u1s, (q0, q1)); + // TODO: Automatic unboxing for Arrays... Gen6(u1s, u2); + // TODO: Automatic unboxing for Arrays... Gen6(u6); + Gen6([(1, [q1]), (2, [q1, q2])], (q0, q1)); + Gen6([(1, u1s), (2, u1s)], u2!); + Gen6(UnboxG6(u6)); + + //Gen7<'I>(tags: (Int, 'I[])) + Gen7(1, u1s); + Gen7(2, u7s); + } + } + } + + + function AsStr (r : Result) : String { + + if (r == One) { + return $"One"; + } + + return $"Zero"; + } + + + function AsInt (r : Result) : Int { + + + if (r == One) { + return 1; + } + + return 0; + } + + + function GenWrapper<'U, 'V> (op : ('U -> 'V), arg : 'U) : 'V { + + return op(arg); + } + + + operation WrapperWithDifferentReturnValuesTest () : Unit { + + let str0 = GenWrapper(AsStr, Zero); + let str1 = GenWrapper(AsStr, One); + let int0 = GenWrapper(AsInt, Zero); + let int1 = GenWrapper(AsInt, One); + let intOp = GenWrapper(AsInt, _); + let strOp = GenWrapper(AsStr, _); + AssertEqual($"One", str1); + AssertEqual($"Zero", str0); + AssertEqual($"One", strOp(One)); + AssertEqual($"Zero", strOp(Zero)); + AssertEqual(0, int0); + AssertEqual(1, int1); + AssertEqual(0, intOp(Zero)); + AssertEqual(1, intOp(One)); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs new file mode 100644 index 00000000000..0016786c024 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + open Microsoft.Quantum.Environment; + + operation BorrowSubTest () : (Int, Int) + { + mutable innerBorrow = 0; + borrowing (qb = Qubit()) + { + set innerBorrow = GetQubitsAvailableToBorrow(); + } + return (GetQubitsAvailableToBorrow(), innerBorrow); + } + + operation GetAvailableTest (allocSize : Int) : (Int, Int, Int, Int, Int, Int) + { + let initialUse = GetQubitsAvailableToUse(); + let initialBorrow = GetQubitsAvailableToBorrow(); + + mutable result = (0, 0, 0, 0, 0, 0); + + using (qs = Qubit[allocSize]) + { + let afterUse = GetQubitsAvailableToUse(); + let afterBorrow = GetQubitsAvailableToBorrow(); + let (subBorrow, innerBorrow) = BorrowSubTest(); + set result = (initialUse, initialBorrow, afterUse, afterBorrow, subBorrow, innerBorrow); + } + + return result; + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs new file mode 100644 index 00000000000..9b57996913a --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + operation SliceGenerationTest() : Unit { + using (qs = Qubit[4]) { + PrepareCatState(qs); + if (M(qs[0]) == One) { + for (target in qs) { + X(target); + } + } + } + } + + operation PrepareCatState(register : Qubit[]) : Unit is Adj + Ctl { + H(register[0]); + for (target in register[1...]) { + CNOT(register[0], target); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs new file mode 100644 index 00000000000..285736aaecd --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Issue76 +{ + open Microsoft.Quantum.Intrinsic; + + function BuggyReturn<'T> (param: 'T): Bool { + return true; + } + + function AssertBuggyReturn<'T> (param: 'T): Unit { + if (not BuggyReturn<'T>(param)) { + Message("BuggyReturn returned false"); + } + } +} + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Issue76; + open Microsoft.Quantum.Intrinsic; + + function BuggyReturnTest () : Unit + { + AssertBuggyReturn(0); + if (not BuggyReturn(0)) { + Message("BuggyReturn returned false"); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs new file mode 100644 index 00000000000..d802d3a68da --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Intrinsic; + + + operation JointMeasureTest () : Unit { + + + using (qubits = Qubit[3]) { + let q1 = qubits[0]; + let q2 = qubits[1]; + let q3 = qubits[2]; + let basis = [PauliZ, PauliZ, PauliZ]; + let r1 = Measure(basis, qubits); + AssertEqual(Zero, r1); + X(q1); + let r2 = Measure(basis, qubits); + AssertEqual(One, r2); + AssertEqual(One, Measure([PauliZ], [q1])); + AssertEqual(Zero, Measure([PauliZ], [q2])); + AssertEqual(Zero, Measure([PauliZ], [q3])); + X(q3); + let r3 = Measure(basis, qubits); + AssertEqual(Zero, r3); + AssertEqual(One, Measure([PauliZ], [q1])); + AssertEqual(Zero, Measure([PauliZ], [q2])); + AssertEqual(One, Measure([PauliZ], [q3])); + X(q2); + let r4 = Measure(basis, qubits); + AssertEqual(One, r4); + AssertEqual(One, Measure([PauliZ], [q1])); + AssertEqual(One, Measure([PauliZ], [q2])); + AssertEqual(One, Measure([PauliZ], [q3])); + ResetAll(qubits); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs new file mode 100644 index 00000000000..1cdadf8552b --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + operation MapF<'T, 'U> (mapper : ('T -> 'U), source : 'T[]) : 'U[] { + + mutable result = new 'U[Length(source)]; + + for (i in 0 .. Length(source) - 1) { + let m = mapper(source[i]); + set result = result w/ i <- m; + } + + return result; + } + + + operation LengthTest () : Unit + { + let a1 = [One, Zero]; + let a2 = [Zero, Zero, Zero]; + + AssertEqual(2, Length(a1)); + AssertEqual(3, Length(a2)); + + let values = MapF(Length, [a1, a2]); + AssertEqual(2, values[0]); + AssertEqual(3, values[1]); + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs new file mode 100644 index 00000000000..7db85674054 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + newtype NestedPair = (Double, ((Fst : Bool, String), Snd : Int)); + + operation NamedItemAccessTest () : Unit { + + let udt = NestedPair(1.0, ((true, "Hello"), 10)); + if (not udt::Fst) { + fail "wrong initialization"; + } + Message($"Snd is {udt::Snd}"); + } + + operation NamedItemUpdateTest () : Unit { + + let udt1 = NestedPair(1.0, ((true, "Hello"), 10)); + mutable udt2 = udt1 w/ Fst <- false; + set udt2 w/= Snd <- 5; + if (not udt1::Fst or udt1::Snd != 10 or udt2::Fst or udt2::Snd != 5) { + fail "wrong values"; + } + } + +} + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs new file mode 100644 index 00000000000..59f3c17d802 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs @@ -0,0 +1,22 @@ +// // Copyright (c) Microsoft Corporation. All rights reserved. +// // Licensed under the MIT License. + +// Will cause compilation failure if callable type references in generated C# aren't +// prepended with "global::". +namespace Issue46 { + + operation ReturnZero () : Result { + + return Zero; + } + +} + +namespace Microsoft.Quantum.Tests.Namespaces.Issue46 { + + operation TestOp () : Result { + + return Issue46.ReturnZero(); + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs b/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs new file mode 100644 index 00000000000..4be5584c1e8 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Simulators; +using Xunit; + +namespace NativeOperations +{ + // An intrinsic operation can specify its built-in Native implementation: + public partial class IntrinsicBody + { + public static string RESULT = "from native body"; + + // Make sure it works with other inner Types: + public class Other { } + + public class Native : IntrinsicBody + { + public Native(IOperationFactory m) : base(m) { } + + public override Func Body => (arg) => + { + return RESULT; + }; + } + } + + // An operation can have a body, and only Emulate for specific simulators: + public partial class DefaultBody + { + public class Native : DefaultBody + { + public Native(IOperationFactory m) : base(m) { } + + public override Func Body => (arg) => + { + if (this.Factory is QuantumSimulator) + { + return "Simulator"; + } + + return base.Body(arg); + }; + } + } + + // Same rules apply to Generic operations: + public partial class IntrinsicBodyGeneric<__T__> + { + // This one should not be used. It extends the Q# operation but has more generic type parameters + public class Other1 : IntrinsicBodyGeneric<__T__> + { + public Other1(IOperationFactory m) : base(m) { } + + public override Func<__T__, string> Body => throw new NotImplementedException(); + } + + // This one should not be used, it has the same number of Type parameters, + // but does not extend the actual Q# operation: + public class Other2 { } + + // This one should be used: + public class Emulation : IntrinsicBodyGeneric<__T__> + { + public Emulation(IOperationFactory m) : base(m) { } + + public override Func<__T__, string> Body => (arg) => + { + if (arg is string s) + { + return IntrinsicBody.RESULT; + } + else + { + return arg.ToString(); + } + }; + } + } + + // Make sure we can also call the body of a non-intrinsic generic + public partial class DefaultBodyGeneric<__T__> + { + // This one should be used: + public class Emulation : DefaultBodyGeneric<__T__> + { + public Emulation(IOperationFactory m) : base(m) { } + + public override Func<__T__, __T__> Body => (arg) => + { + if (arg is string s) + { + return (__T__)(object)IntrinsicBody.RESULT; + } + else + { + return base.Body(arg); + } + }; + } + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs new file mode 100644 index 00000000000..b6048b2af62 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace NativeOperations +{ + operation IntrinsicBody () : String + { + body intrinsic; + } + + operation DefaultBody () : String + { + return "hello"; + } + + operation IntrinsicBodyGeneric<'T>(arg: 'T) : String + { + body intrinsic; + } + + operation DefaultBodyGeneric<'T>(arg: 'T) : 'T + { + return arg; + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs new file mode 100644 index 00000000000..c34ca0bf6be --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Simulation.TestSuite; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + + + //------------------------------------------------------------------------ + + operation CNOTPrimitive (register : Qubit[]) : Unit { + + body (...) { + CNOT(register[0], register[1]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation CNOTEquivalent (register : Qubit[]) : Unit { + + body (...) { + Controlled X([register[0]], register[1]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation CNOTEquivalenceTest () : Unit { + AssertOperationsEqualInPlace(2, CNOTPrimitive, CNOTEquivalent); + } + + + //------------------------------------------------------------------------ + + operation CCNOTPrimitive (register : Qubit[]) : Unit { + + body (...) { + CCNOT(register[0], register[1], register[2]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation CCNOTEquivalent (register : Qubit[]) : Unit { + + body (...) { + Controlled X(register[0 .. 1], register[2]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation CCNOTEquivalenceTest () : Unit { + AssertOperationsEqualInPlace(3, CCNOTPrimitive, CCNOTEquivalent); + } + + + //------------------------------------------------------------------------ + + operation R1Primitive (theta : Double, register : Qubit[]) : Unit { + + body (...) { + R1(theta, register[0]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation R1Equivalent (theta : Double, register : Qubit[]) : Unit { + + body (...) { + R(PauliZ, theta, register[0]); + R(PauliI, -theta, register[0]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation R1EquivalentTest () : Unit { + + let nTheta = 101; + + for (idxTheta in 0 .. nTheta) { + let theta = ((2.0 * PI()) * IntAsDouble(idxTheta)) / IntAsDouble(nTheta); + AssertOperationsEqualInPlace(1, R1Primitive(theta, _), R1Equivalent(theta, _)); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs new file mode 100644 index 00000000000..f32486ecaa9 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + function Factorial (x : Int) : Int { + + + if (x == 1) { + return 1; + } + else { + return x * Factorial(x - 1); + } + } + + + operation OpFactorial (x : Int) : Int { + + + if (x == 1) { + return 1; + } + else { + return x * OpFactorial(x - 1); + } + } + + + function GenRecursion<'T> (x : 'T, cnt : Int) : 'T { + + + if (cnt == 0) { + return x; + } + else { + return GenRecursion(x, cnt - 1); + } + } + + + function GenRecursionPartial<'T> (x : 'T, cnt : Int) : 'T { + + + if (cnt == 0) { + return x; + } + else { + let fct = GenRecursionPartial<'T>(_, cnt - 1); + return fct(x); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs new file mode 100644 index 00000000000..05d5d7463c1 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + operation OneBitPrecisionEigenvalue (U : (Qubit => Unit is Adj + Ctl), P : (Qubit => Unit is Adj)) + : Bool { + + using ((control, eigenstate) = (Qubit(), Qubit())) { + P(eigenstate); + + mutable (measuredZero, measuredOne) = (false, false); + mutable iter = 0; + repeat { + set iter += 1; + + H(control); + Controlled U([control], eigenstate); + H(control); + + let meas = M(control); + if (meas == One) { X(control); } + set (measuredZero, measuredOne) = (measuredZero or meas == Zero, measuredOne or meas == One); + } + until (iter == 20 or measuredZero and measuredOne); + + Reset(eigenstate); + return not measuredZero or not measuredOne; + } + + } + + // testing + + operation RepeatUntilSuccessTest () : Unit { + let evZ = OneBitPrecisionEigenvalue(Z,X); + let evS = OneBitPrecisionEigenvalue(S,X); + let evX = OneBitPrecisionEigenvalue(X,H); + if (not evZ or not evX or evS) { + fail "wrong result"; + } + } + +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs new file mode 100644 index 00000000000..dd3e52fc884 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + open Microsoft.Quantum.Intrinsic; + + operation VerySimpleEstimate () : Unit + { + using(q = Qubit[3]) { + X(q[0]); + H(q[1]); + + Controlled X([q[1]], q[0]); + + ResetAll([q[1], q[0]]); + } + } + + // When multiple operations are traced by resource estimator, + // it should report cumulative statistics in the end. + operation Operation_1_of_2() : Unit + { + using ((a, b) = (Qubit(), Qubit())) { + H(a); + CNOT(a, b); + T(b); + } + } + operation Operation_2_of_2() : Result + { + using ((a, b, c) = (Qubit(), Qubit(), Qubit())) { + X(a); + CNOT(a, b); + Rx(0.42, b); + CNOT(b, c); + return M(c); + } + } + + // Tests for Depth and Width lower bounds + operation DepthDifferentQubits () : Unit + { + using(q = Qubit[3]) { + T(q[0]); + T(q[1]); + T(q[2]); + T(q[0]); + } + } + operation DepthVersusWidth () : Unit + { + using(q = Qubit()) { + T(q); + } + using(q = Qubit()) { + T(q); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs new file mode 100644 index 00000000000..5836a3426f5 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Intrinsic; + + newtype FooUDT = (String, (Qubit, Double)); + + operation FooUDTOp (foo : FooUDT) : Unit is Ctl + Adj { } + + operation Empty () : Unit is Ctl + Adj { } + + operation WrapperOp (op: (Qubit => Unit), q : Qubit) : Unit { + op(q); + Reset(q); + } + + operation HOp (q : Qubit) : Unit { + H(q); + Reset(q); + } + + operation NestedOp () : Unit { + using (q = Qubit()) { + HOp(q); + } + } + + operation TwoQubitOp (q1 : Qubit, q2 : Qubit) : Unit { + // ... + } + + operation BoolArrayOp (bits : Bool[]) : Unit { + // ... + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs new file mode 100644 index 00000000000..6aab6f402ea --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Intrinsic; + + + operation SetQubit (desired : Result, q1 : Qubit) : Unit { + + let current = M(q1); + + if (desired != current) { + X(q1); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs new file mode 100644 index 00000000000..dbbad4a7894 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs @@ -0,0 +1,152 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Tests.StartOperation { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics; + + + newtype Qubits = Qubit[]; + + newtype UDT1 = ((Int, Qubit, (Qubit, Qubit), Result) => Unit : Adjoint, Controlled); + + newtype UDT2 = (Qubit => Unit : Adjoint, Controlled); + + newtype UDT3 = ((Int, Qubit) => Int); + + + operation Basic (a : Int, b : Qubit, (c : Qubit, d : Qubit), e : Result) : Unit { + + body (...) { + X(b); + X(c); + X(d); + X(b); + Trace(a); + Trace(b); + Trace(c); + Trace(d); + Trace(e); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation B3 (i : Int, q : Qubit) : Int { + + Trace(q); + return i; + } + + + operation AllVariants<'T> (gate : ('T => Unit : Adjoint, Controlled), i : 'T, ctrls : Qubits) : Unit { + + body (...) { + gate(i); + Adjoint gate(i); + Controlled gate(ctrls!, i); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation StartOperationTest () : Unit { + + using (q = Qubit[5]) + { + let data = (0, q[1], (q[2], q[3]), One); + let ctrls = Qubits(q[0..0]); // B A C CA + + Basic(data); // 1 + (Adjoint Basic)(data); // 1 + (Controlled Basic)(ctrls!, data); // 1 + (Adjoint (Controlled Basic))(ctrls!, data); // 1 + + AllVariants(Basic, data, ctrls); // 1 1 1 + (Adjoint AllVariants)(Basic, data, ctrls); // 1 1 1 + (Controlled AllVariants)([q[4]], (Basic, data, ctrls)); // 2 1 + (Adjoint (Controlled AllVariants))([q[4]], (Basic, data, ctrls)); // 1 2 + + let partial = Basic(1, q[1], _, Zero); + AllVariants(partial, (q[2], q[3]), ctrls); // 1 1 1 + (Adjoint AllVariants)(partial, (q[2], q[3]), ctrls); // 1 1 1 + (Controlled AllVariants)([q[4]], (partial, (q[2], q[3]), ctrls)); // 2 1 + + let partial2 = partial(q[2], _); + partial2(q[3]); // 1 + partial2(q[3]); // 1 + partial2(q[3]); // 1 + AllVariants(partial2, q[3], ctrls); // 1 1 1 + (Adjoint partial2)(q[3]); // 1 + } + } + + + // This is needed to fix the bug that the parser is reporting incorrectly the type of UDTs: + + function UDT1asUnitary (u : UDT1) : ((Int, Qubit, (Qubit, Qubit), Result) => Unit : Adjoint, Controlled) { + + return u!; + } + + + operation StartOperationUDTTest () : Unit { + + using (q = Qubit[5]) + { + let data = (0, q[1], (q[2], q[3]), One); + let ctrls = Qubits(q[0..0]); + let u = UDT1(Basic); + let uni = UDT1asUnitary(UDT1(Basic)); + // B A C CA + u!(data); // 1 + (Adjoint u!)(data); // 1 + (Controlled u!)(ctrls!, data); // 1 + (Adjoint (Controlled u!))(ctrls!, data); // 1 + + uni(data); // 1 + AllVariants(uni, data, ctrls); // 1 1 1 + (Adjoint AllVariants)(uni, data, ctrls); // 1 1 1 + (Controlled AllVariants)([q[4]], (uni, data, ctrls)); // 2 1 + (Adjoint (Controlled AllVariants))([q[4]], (uni, data, ctrls)); // 1 2 + + let partial = uni(1, q[1], _, Zero); + AllVariants(partial, (q[2], q[3]), ctrls); // 1 1 1 + (Adjoint AllVariants)(partial, (q[2], q[3]), ctrls); // 1 1 1 + (Controlled AllVariants)([q[4]], (partial, (q[2], q[3]), ctrls)); // 2 1 + + let partial2 = partial(q[2], _); // + partial2(q[3]); // 1 + partial2(q[3]); // 1 + partial2(q[3]); // 1 + (Adjoint partial2)(q[3]); // 1 + + let u2 = UDT2(partial2); + u2!(q[2]); // 1 + u2!(q[2]); // 1 + AllVariants(u2!, q[1], ctrls); // 1 1 1 + + let u3 = UDT3(B3); + let p3 = u3!(_, q[0]); + mutable results = new Int[4]; + for (i in 0..3) + { + set results = results + w/ i <- u3!(i, q[i]) + w/ i <- p3(i); + } + + ResetAll(q); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs new file mode 100644 index 00000000000..8ebb32babd5 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + + operation SwapTest () : Unit { + + + using (qubits = Qubit[2]) { + let q1 = qubits[0]; + let q2 = qubits[1]; + X(q1); + SWAP(q1, q2); + + // Make sure all allocated qubits are measured before release + let (r1, r2) = (M(q1), M(q2)); + AssertQubit(Zero, q1); + AssertQubit(One, q2); + X(q2); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs new file mode 100644 index 00000000000..64d4808065e --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Intrinsic; + + + operation TeleportTest () : Unit { + + + using (qubits = Qubit[3]) { + let q1 = qubits[0]; + let q2 = qubits[1]; + let q3 = qubits[2]; + + // create a Bell pair + H(q1); + CNOT(q1, q2); + + // create quantum state + H(q3); + Rz(1.1, q3); + + // teleport + CNOT(q3, q2); + H(q3); + Controlled X([q2], q1); + Controlled Z([q3], q1); + + // check teleportation success + Rz(-1.1, q1); + H(q1); + + // Make sure all allocated qubits are retrurned to zero before release + ResetAll(qubits); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs new file mode 100644 index 00000000000..e5082d2c7b8 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Tests.OperationNames { + + operation Name () : Unit { + + } + + + operation Variant () : Unit { + + } + + + operation DataIn () : Unit { + + } + + + operation DataOut () : Unit { + + } + +} + + +namespace Microsoft.Quantum.Tests.Tuples { + + newtype Q = Qubit; + + newtype I = Int; + + newtype TupleA = (Int, Pauli, Qubit, (Qubit, Int, Qubit)); + + newtype TupleB = ((Int, Int), (Qubit, (Int, (Qubit, Qubit)), Double)); + + newtype TupleC = (Qubit, TupleB); + + newtype TupleD = Qubit[]; + + newtype TupleE = (Int, Qubit[]); + + newtype TupleF = ((TupleA, TupleD) => Unit : Adjoint, Controlled); + + newtype TupleG = (Qubit, TupleF, TupleC, TupleD); + + newtype TupleH = (TupleD, TupleG); + + newtype TupleI = ((TupleD, TupleF) -> TupleD); + + newtype TupleJ = (Int, Qubit)[]; + + newtype Name = String; + + newtype Variant = String; + + newtype DataIn = (Int, Qubit); + + newtype DataOut = (Int, (Qubit, Qubit)); + + + operation Op1 (a : TupleA, d : TupleD) : Unit { + + body (...) { + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + function F1 (d : TupleD, f : TupleF) : TupleD { + + return d; + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs new file mode 100644 index 00000000000..cd31d8f67d8 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + @Test("QuantumSimulator") + operation QsharpUnitTest() : Unit { + Message("Worked!"); + } + + @Test("QuantumSimulator") + @Test("Microsoft.Quantum.Simulation.Simulators.Tests.TrivialSimulator") + @Test("Microsoft.Quantum.Simulation.Simulators.Tests.ModifiedTrivialSimulator") + @Test("Microsoft.Quantum.Simulation.Simulators.Tests.UnitTests.TrivialSimulator") + operation ArbitraryUnitTestTarget() : Unit { + Message("Worked!"); + } + +} + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs new file mode 100644 index 00000000000..fa8cbc07cff --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + + newtype P1 = (Int, Int); + newtype P2 = ((Int, Int), Int); + newtype NamedTuple = (FirstItem: (Int, Double), SecondItem: Int); + newtype InnerNamedTuple = ((Fst : Result, Snd : (Int, Int)), Trd : String); + + function TakesUdtPartial<'T, 'U> (build : ('T -> 'U), remainingArgs : 'T) : 'U { + return build(remainingArgs); + } + + operation PassingUDTConstructorTest() : Unit + { + let ((a1, b1), c1) = (TakesUdtPartial(P2, ((1,2),3)))!; + AssertEqual(a1, 1); + AssertEqual(b1, 2); + AssertEqual(c1, 3); + + let partial = P2((_,2), _); + let full = TakesUdtPartial(partial, (3,1)); + let ((a2, b2), c2) = full!; + AssertEqual(a2, 3); + AssertEqual(b2, 2); + AssertEqual(c2, 1); + } + + operation PartialNestedUDTTest() : Unit + { + let partial = P2((_,2), _); + let full = partial(3, 1); + + let ((a, b), c) = full!; + AssertEqual(a, 3); + AssertEqual(b, 2); + AssertEqual(c, 1); + } + + operation PartialUDTTest() : Unit + { + let partial = P1(2, _); + let full = partial(3); + + let (a, b) = full!; + AssertEqual(5, a+b); + + let full2 = partial(10); + let (x, y) = full2!; + AssertEqual(12, x + y); + } + + operation IndirectPartialUDTTest() : Unit + { + let pa1 = P2((_,2), _); + let pa2 = pa1(1,_); + let ((a1, b1), c1) = (pa2(3))!; + AssertEqual(a1, 1); + AssertEqual(b1, 2); + AssertEqual(c1, 3); + + let full = TakesUdtPartial(pa1(3,_), 1); + let ((a2, b2), c2) = full!; + AssertEqual(a2, 3); + AssertEqual(b2, 2); + AssertEqual(c2, 1); + } + + function returnUdtConstructor () : (((Int, Int), Int) -> P2) { + return P2; + } + + function returnPartialUdtConstructor () : ((Int, Int) -> P2) { + return P2((3,_),_); + } + + function CallReturnedUdtConstructorTest () : Unit + { + let udt1 = (returnUdtConstructor())((1,2),3); + let ((a1,b1),c1) = udt1!; + AssertEqual(a1, 1); + AssertEqual(b1, 2); + AssertEqual(c1, 3); + + let udt2 = (returnPartialUdtConstructor())(2,1); + let ((a2,b2),c2) = udt2!; + AssertEqual(a2, 3); + AssertEqual(b2, 2); + AssertEqual(c2, 1); + } + + function ConstantArray<'T>(size : Int, item : 'T) : 'T[] { + mutable arr = new 'T[size]; + for (i in 0 .. size-1) { + set arr w/= i <- item; + } + return arr; + } + + function UdtConstructorArrayTest () : Unit { + let arr = ConstantArray(5, P2); + for (ctor in arr) { + let ((a,b),c) = (ctor((1, 2), 3))!; + AssertEqual(a, 1); + AssertEqual(b, 2); + AssertEqual(c, 3); + } + } + + function UdtNamedTupleFieldTest () : Unit { + let data = NamedTuple((1, 2.0), 3); + let (a, b) = data::FirstItem; + let c = data::SecondItem; + AssertEqual(a, 1); + AssertEqual(b, 2.0); + AssertEqual(c, 3); + } + + function UdtInnerNamedTupleFieldTest () : Unit { + let t = InnerNamedTuple((Zero, (0,1)), ""); + AssertEqual(Zero, t::Fst); + let snd = t::Snd; + let (s1, s2) = snd; + AssertEqual(0, s1); + AssertEqual(1, s2); + AssertEqual("", t::Trd); + } +} + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs new file mode 100644 index 00000000000..e44783a32d6 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Simulation.TestSuite; + + + /// + /// Verifies that all operations of the one-qubit Unitary work. + /// It receives as parameter the Unitary (notice that any gate can be converted to Unitary + /// using Partial Application), a start state that the qubit should be initialized with, + /// and the qubit state that the Qubit should be at + /// once the Unitary has been applied. + /// The verification applies the gate and asserts the qubit state. Then it applies + /// the Adjoint and verifies the qubit is back to Zero. + /// then it tests Controlled with different number of control qubits, also verifying that + /// Adjoint Controlled works. + /// + operation VerifyUnitary (gate : (Qubit => Unit : Adjoint, Controlled), start : (Pauli, Result), expected : (Complex, Complex)) : Unit { + + + using (qubits = Qubit[1]) { + let tolerance = 1E-05; + let q1 = qubits[0]; + let (a, b) = expected; + let (p, r) = start; + SetQubit(r, q1); + + if (p == PauliX) { + H(q1); + } + + // Make sure we start in correct state. + Assert([p], [q1], r, $"Qubit in invalid state."); + + // Apply the gate, make sure it's in the right state + gate(q1); + AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); + + // Apply Adjoint, back to Zero: + Adjoint gate(q1); + Assert([p], [q1], r, $"Qubit in invalid state."); + + // When no control qubits, it should be equivalent to just calling the gate: + Controlled gate(new Qubit[0], q1); + AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); + + // Apply Adjoint, back to Zero: + Controlled (Adjoint gate)(new Qubit[0], q1); + Assert([p], [q1], r, $"Qubit in invalid state."); + + // Now test control... We'll have 3 control qubits. + // We will run the test with 1..3 controls at a time. + let ctrlsCount = 3; + + using (ctrls = Qubit[ctrlsCount]) { + + for (i in 0 .. ctrlsCount - 1) { + + // We're starting fresh + Assert([p], [q1], r, $"Qubit in invalid state."); + + // Get a subset for control and initialize them to zero: + let c = ctrls[0 .. i]; + + for (j in 0 .. i) { + SetQubit(Zero, c[j]); + } + + // Noop when ctrls are all zero. + Controlled gate(c, q1); + Assert([p], [q1], r, $"Qubit in invalid state."); + + // turn on each of the controls one by one + for (j in 1 .. Length(c)) { + X(c[j - 1]); + Controlled gate(c, q1); + + // Only when all + if (j == Length(c)) { + AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); + } + else { + Assert([p], [q1], r, $"Qubit in invalid state."); + } + + Adjoint Controlled gate(c, q1); + } + } + + ResetAll(ctrls); + } + + // We're back where we started. + Assert([p], [q1], r, $"Qubit in invalid state."); + SetQubit(r, q1); + ResetAll(qubits); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs new file mode 100644 index 00000000000..0c5f250a672 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits +{ + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + operation F2 (x : Qubit[], y : Qubit) : Unit { + F1(x, y); + } + + operation F1 (x : Qubit[], y : Qubit) : Unit { + if (Length(x) > 1) { + F2(x[0..Length(x)-2], y); + } + else { + X(y); + } + } + + operation Solve (x : Qubit[], y : Qubit) : Unit + { + F1(x, y); + } + + operation MutuallyRecursiveOperationTest () : Unit { + + using (qubits = Qubit[4]) { + let x = qubits[0..2]; + let y = qubits[3]; + + Solve(x, y); + AssertQubit(One, y); + + ResetAll(qubits); + } + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/CoreTests.cs b/src/Simulation/Simulators.Type2.Tests/CoreTests.cs new file mode 100644 index 00000000000..74f3c211e52 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/CoreTests.cs @@ -0,0 +1,283 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text; +using Microsoft.Quantum.QsCompiler; +using Microsoft.Quantum.Simulation.Common; +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Tests.CoreOperations; + +using Xunit; +using Xunit.Abstractions; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class CoreTests + { + private readonly ITestOutputHelper output; + + public CoreTests(ITestOutputHelper output) + { + this.output = output; + } + + [Fact] + public void BasicExecution() + { + var asmPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + var exe = Path.Combine(asmPath, "TestExe", "QsharpExe.dll"); + + ProcessRunner.Run("dotnet", exe, out var _, out StringBuilder error, out int exitCode, out Exception ex); + Assert.Null(ex); + Assert.Equal(1, exitCode); + Assert.Contains("NotImplementedException", error.ToString()); + + ProcessRunner.Run("dotnet", $"{exe} --simulator QuantumSimulator", out var _, out error, out exitCode, out ex); + Assert.Null(ex); + Assert.Equal(0, exitCode); + Assert.Empty(error.ToString().Trim()); + } + + [Fact] + public void BasicExecutionTargetedExe() + { + var asmPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + var exe = Path.Combine(asmPath, "TestTargetedExe", "TargetedExe.dll"); + + ProcessRunner.Run("dotnet", exe, out StringBuilder output, out StringBuilder error, out int exitCode, out Exception ex); + + Assert.Null(ex); + Assert.Equal(0, exitCode); + Assert.Empty(error.ToString().Trim()); + Assert.Equal("TargetedExe", output.ToString().Trim()); + } + + [Fact] + public void Borrowing() + { + OperationsTestHelper.RunWithMultipleSimulators((s) => + { + var tracker = new StartTracker(s); + + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + var q3 = new FreeQubit(3) as Qubit; + var q4 = new FreeQubit(4) as Qubit; + var q5 = new FreeQubit(5) as Qubit; + var q6 = new FreeQubit(6) as Qubit; + var q7 = new FreeQubit(7) as Qubit; + var q8 = new FreeQubit(8) as Qubit; + + BorrowingTest.Run(s).Wait(); + + var tracer = OperationsTestHelper.GetTracer<(long, Qubit)>(s); + + var testOne = new Action((int callsCount, OperationFunctor variant, (int, Qubit) info) => + { + var (available, q) = info; + Assert.Equal(callsCount, tracer.Log.GetNumberOfCalls(variant, (available, q))); + }); + + var testOneBody = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.Body, info)); + var testOneAdjoint = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.Adjoint, info)); + var testOneCtrl = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.Controlled, info)); + var testOneCtrlAdj = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.ControlledAdjoint, info)); + + testOneBody(6, (0, q5)); + testOneBody(6, (0, q6)); + testOneBody(1, (1, q0)); + testOneBody(1, (1, q1)); + testOneBody(1, (1, q4)); + testOneBody(3, (1, q5)); + testOneBody(0, (1, q6)); + testOneBody(2, (2, q2)); + testOneBody(2, (2, q3)); + testOneBody(1, (3, q0)); + testOneBody(1, (3, q1)); + testOneBody(1, (3, q2)); + testOneBody(3, (3, q3)); + testOneBody(2, (4, q0)); + testOneBody(1, (4, q1)); + testOneBody(3, (4, q2)); + testOneBody(5, (5, q0)); + testOneBody(5, (5, q1)); + + testOneAdjoint(3, (0, q5)); + testOneAdjoint(3, (0, q6)); + testOneAdjoint(1, (1, q0)); + testOneAdjoint(1, (1, q1)); + testOneAdjoint(1, (1, q4)); + testOneAdjoint(3, (1, q5)); + testOneAdjoint(0, (1, q6)); + testOneAdjoint(2, (2, q2)); + testOneAdjoint(2, (2, q3)); + testOneAdjoint(1, (3, q2)); + testOneAdjoint(1, (3, q3)); + testOneAdjoint(1, (4, q0)); + testOneAdjoint(1, (4, q1)); + testOneAdjoint(2, (4, q2)); + testOneAdjoint(2, (5, q0)); + testOneAdjoint(2, (5, q1)); + + testOneCtrl(3, (0, q7)); + testOneCtrl(3, (0, q8)); + testOneCtrl(1, (1, q0)); + testOneCtrl(1, (1, q1)); + testOneCtrl(1, (1, q4)); + testOneCtrl(2, (1, q5)); + testOneCtrl(0, (1, q6)); + testOneCtrl(0, (2, q0)); + testOneCtrl(0, (2, q1)); + testOneCtrl(2, (2, q2)); + testOneCtrl(2, (2, q3)); + testOneCtrl(1, (3, q2)); + testOneCtrl(1, (3, q3)); + testOneCtrl(1, (4, q0)); + testOneCtrl(1, (4, q1)); + testOneCtrl(2, (4, q2)); + testOneCtrl(3, (5, q0)); + testOneCtrl(3, (5, q1)); + + testOneCtrlAdj(3, (0, q7)); + testOneCtrlAdj(3, (0, q8)); + testOneCtrlAdj(1, (1, q4)); + testOneCtrlAdj(1, (1, q7)); + testOneCtrlAdj(2, (2, q2)); + testOneCtrlAdj(2, (2, q3)); + testOneCtrlAdj(1, (3, q2)); + testOneCtrlAdj(1, (3, q3)); + testOneCtrlAdj(1, (4, q0)); + testOneCtrlAdj(1, (4, q1)); + testOneCtrlAdj(2, (4, q2)); + testOneCtrlAdj(2, (5, q0)); + testOneCtrlAdj(2, (5, q1)); + + Assert.Equal(20, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Body)); + Assert.Equal(11, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Adjoint)); + Assert.Equal(16, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Controlled)); + Assert.Equal(13, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.ControlledAdjoint)); + }); + } + + [Fact] + public void DumpState() + { + var expectedFiles = new string[] + { + "dumptest-start.txt", + "dumptest-h.txt", + "dumptest-former.txt", + "dumptest-later.txt", + "dumptest-one.txt", + "dumptest-two.txt", + "dumptest-entangled.txt", + "dumptest-twoQubitsEntangled.txt", + "dumptest-end.txt", + }; + + void RunOne(IOperationFactory s) + { + if (s is SimulatorBase sim) + { + // OnLog defines action(s) performed when Q# test calls function Message + sim.OnLog += (msg) => { output.WriteLine(msg); }; + } + + foreach (var name in expectedFiles) + { + if (File.Exists(name)) + { + File.Delete(name); + } + } + + if (File.Exists("()")) + { + File.Delete("()"); + } + + SimpleDumpTest.Run(s).Wait(); + + foreach (var name in expectedFiles) + { + Assert.True(File.Exists(name), $"File {name} did not exist after running SimpleDumpTest on {s}."); + } + + Assert.False(File.Exists("()")); + } + + OperationsTestHelper.RunWithMultipleSimulators((s) => RunOne(s as IOperationFactory)); + RunOne(new QuantumSimulator()); + } + + + [Fact] + public void ZeroQubits() + { + OperationsTestHelper.RunWithMultipleSimulators((s) => + { + var tracer = OperationsTestHelper.GetTracer(s); + + ZeroQubitsTest.Run(s).Wait(); + + Assert.Equal(1, tracer.GetNumberOfCalls(OperationFunctor.Body, "zero")); + }); + } + + [Fact] + public void InterpolatedStrings() + { + OperationsTestHelper.RunWithMultipleSimulators((s) => + { + Circuits.InterpolatedStringTest.Run(s).Wait(); // Throws if it doesn't succeed + }); + } + + [Fact] + public void RandomOperation() + { + OperationsTestHelper.RunWithMultipleSimulators((s) => + { + Circuits.RandomOperationTest.Run(s).Wait(); // Throws if it doesn't succeed + }); + } + + [Fact] + public void BigInts() + { + OperationsTestHelper.RunWithMultipleSimulators((s) => + { + Circuits.BigIntTest.Run(s).Wait(); // Throws if it doesn't succeed + }); + } + + [Fact] + public void CatchFail() + { + int exceptionCount = 0; + System.Action inc = (System.Runtime.ExceptionServices.ExceptionDispatchInfo e) => exceptionCount++; + var sim = new TrivialSimulator(); + sim.OnFail += inc; // increment exception counter when exception is caught + var inst = sim.Get(); + try + { + inst.Apply(QVoid.Instance); + Assert.True(false); // make sure that exception actually happened + } + catch(System.Exception e) + { + Assert.True(true); // make sure that exception actually happened + } + Assert.Equal(1, exceptionCount); // check that we cought exception once + } + + [Fact] + public void InternalCallables() => + OperationsTestHelper.RunWithMultipleSimulators(s => Circuits.InternalCallablesTest.Run(s).Wait()); + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs b/src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs new file mode 100644 index 00000000000..0ef42022ab6 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs @@ -0,0 +1,293 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Globalization; +using System.Threading; + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Tests.CoreOperations; + +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + using Helper = OperationsTestHelper; + /// + /// Provides test methods for things that are useful during debugging. + /// + public class DebuggingToolsTests + { + [Fact] + public void ToStringTests() => Helper.RunWithMultipleSimulators(qsim => + { + var _ = AbstractCallable._; + + var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)); + var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)); + var x = qsim.Get(); + var q2 = new FreeQubit(2) as Qubit; + var Q = new Q(q2); + var Qs = new QArray(q2); + var qs = new Qs(Qs); + var udtOp = new U3(x); + var udtQ = new Q(q2); + var t1 = new QTuple<(long, QRange, (Qubit, IUnitary))>((1L, new QRange(10, -2, 4), (q2, x))); + var t4 = new T4((3L, (1.1, false, Result.One))); + var t5 = new T5((Pauli.PauliX, Qs, qs, Q)); + + var d_1 = dump.Partial(_); + var d_2 = d_1.Partial(_); + var x_1 = x.Partial(new Func(q => q)); + var x_2 = x_1.Partial(new Func(q => q)); + var x_3 = x.Partial>(_); + + var t_1 = trace.Adjoint.Partial(_); + var t_2 = t_1.Controlled.Partial(_); + + WithInvariantCulture(() => + { + Assert.Equal("()", QVoid.Instance.ToString()); + Assert.Equal("_", _.ToString()); + Assert.Equal("U3(X)", udtOp.ToString()); + Assert.Equal("q:2", q2.ToString()); + Assert.Equal("Q(q:2)", udtQ.ToString()); + Assert.Equal("(1, 10..-2..4, (q:2, X))", t1.ToString()); + Assert.Equal("T4((3, (1.1, False, One)))", t4.ToString()); + Assert.Equal("T5((PauliX, [q:2], Qs([q:2]), Q(q:2)))", t5.ToString()); + Assert.Equal("X", x.ToString()); + Assert.Equal("(Adjoint X)", x.Adjoint.ToString()); + Assert.Equal("(Controlled X)", x.Controlled.ToString()); + Assert.Equal("(Adjoint (Controlled X))", x.Controlled.Adjoint.ToString()); + Assert.Equal("(Controlled (Adjoint X))", x.Adjoint.Controlled.ToString()); + Assert.Equal("X{_}", x_1.ToString()); + Assert.Equal("(Adjoint X{_})", x_1.Adjoint.ToString()); + Assert.Equal("X{_}{_}", x_2.ToString()); + Assert.Equal("X{_}", x_3.ToString()); + Assert.Equal("DumpMachine", dump.ToString()); + Assert.Equal("DumpMachine{_}", d_1.ToString()); + Assert.Equal("DumpMachine{_}{_}", d_2.ToString()); + Assert.Equal("Trace", trace.ToString()); + Assert.Equal("(Adjoint Trace)", trace.Adjoint.ToString()); + Assert.Equal("(Controlled Trace)", trace.Controlled.ToString()); + Assert.Equal("(Adjoint (Controlled Trace))", trace.Controlled.Adjoint.ToString()); + Assert.Equal("(Adjoint Trace){_}", t_1.ToString()); + Assert.Equal("(Adjoint (Controlled (Adjoint Trace){_}){_})", t_2.Adjoint.ToString()); + }); + }); + + [Fact] + public void QSharpTypeTests() + { + Helper.RunWithMultipleSimulators((qsim) => + { + var _ = AbstractCallable._; + + var x = qsim.Get(); + var q2 = new FreeQubit(2) as Qubit; + var Q = new Q(q2); + var Qs = new QArray(q2); + var qs = new Qs(Qs); + var udtOp = new U3(x); + var udtQ = new Q(q2); + var t4 = new T4((3L, (1.1, false, Result.One))); + var t5 = new T5((Pauli.PauliX, Qs, qs, Q)); + var plain = qsim.Get(); + var adj = qsim.Get(); + var ctrl = qsim.Get(); + var mapper = qsim.Get(); + + Assert.Equal("()", typeof(QVoid).QSharpType()); + Assert.Equal("_", _.GetType().QSharpType()); + Assert.Equal("U3", udtOp.GetType().QSharpType()); + Assert.Equal("Qubit => () : Adjoint, Controlled", udtOp.Data.GetType().QSharpType()); + Assert.Equal("Qubit", q2.GetType().QSharpType()); + Assert.Equal("Q", udtQ.GetType().QSharpType()); + Assert.Equal("Qubit", udtQ.Data.GetType().QSharpType()); + Assert.Equal("T4", t4.GetType().QSharpType()); + Assert.Equal("(Int,(Double,Boolean,Result))", t4.Data.GetType().QSharpType()); + Assert.Equal("T5", t5.GetType().QSharpType()); + Assert.Equal("(Pauli,Qubit[],Qs,Q)", t5.Data.GetType().QSharpType()); + Assert.Equal("Qubit => () : Adjoint, Controlled", x.GetType().QSharpType()); + Assert.Equal("Qubit => () : Adjoint, Controlled", x.Adjoint.GetType().QSharpType()); + Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.GetType().QSharpType()); + Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.Adjoint.GetType().QSharpType()); + Assert.Equal("(Int,Qubit,Callable) => ()", plain.GetType().QSharpType()); + Assert.Equal("(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj.GetType().QSharpType()); + Assert.Equal("(Int,Qs,Controllable) => () : Controlled", ctrl.GetType().QSharpType()); + Assert.Equal("(Callable,Result[]) => String[]", mapper.GetType().QSharpType()); + }); + } + + private void TestOneOp(string name, string fullName, OperationFunctor variant, string signature, AdjointedOperation op) + { + var proxy = new AdjointedOperation.DebuggerProxy(op); + TestOneProxy(name, fullName, variant, signature, proxy); + } + + private void TestOneOp(string name, string fullName, OperationFunctor variant, string signature, ControlledOperation op) + { + var proxy = new ControlledOperation.DebuggerProxy(op); + TestOneProxy(name, fullName, variant, signature, proxy); + } + + private void TestOneOp(string name, string fullName, OperationFunctor variant, string signature, Operation op) + { + TestOneProxy(name, fullName, variant, signature, new Operation.DebuggerProxy(op)); + } + + private void TestOneProxy(string name, string fullName, OperationFunctor variant, string signature, Operation.DebuggerProxy proxy) + { + Assert.Equal(name, proxy.Name); + Assert.Equal(fullName, proxy.FullName); + Assert.Equal(variant, proxy.Variant); + Assert.Equal(signature, proxy.Signature); + } + + [Fact] + public void NonGenericDebuggerProxy() + { + Helper.RunWithMultipleSimulators((qsim) => + { + var x = qsim.Get(); + var plain = qsim.Get(); + var adj = qsim.Get(); + var ctrl = qsim.Get(); + var mapper = qsim.Get(); + + TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body , "Qubit => () : Adjoint, Controlled", x); + TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint , "Qubit => () : Adjoint, Controlled", x.Adjoint); + TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled , "(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled); + TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint , "(Qubit[],Qubit) => () : Adjoint, Controlled", x.Adjoint.Controlled); + TestOneOp("BPlain1", "Microsoft.Quantum.Tests.CoreOperations.BPlain1", OperationFunctor.Body, "(Int,Qubit,Callable) => ()", plain); + TestOneOp("BAdj1", "Microsoft.Quantum.Tests.CoreOperations.BAdj1", OperationFunctor.Body, "(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj); + TestOneOp("BAdj1", "Microsoft.Quantum.Tests.CoreOperations.BAdj1", OperationFunctor.Adjoint, "(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj.Adjoint); + TestOneOp("BCtrl1", "Microsoft.Quantum.Tests.CoreOperations.BCtrl1", OperationFunctor.Body, "(Int,Qs,Controllable) => () : Controlled", ctrl); + TestOneOp("BCtrl1", "Microsoft.Quantum.Tests.CoreOperations.BCtrl1", OperationFunctor.Controlled, "(Qubit[],(Int,Qs,Controllable)) => () : Controlled", ctrl.Controlled); + TestOneOp("Map", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.ClosedType.Map", OperationFunctor.Body, "(Callable,Result[]) => String[]", mapper); + }); + } + + private void TestOneProxy(string signature, OperationPartial op) + { + var proxy = new OperationPartial.DebuggerProxy(op); + + Assert.Equal(op.BaseOp, proxy.Base); + Assert.Equal(signature, proxy.Signature); + } + + [Fact] + public void NonGenericPartialDebuggerProxy() + { + Helper.RunWithMultipleSimulators((qsim) => + { + var x = qsim.Get(); + var plain = qsim.Get(); + var adj = qsim.Get(); + var ctrl = qsim.Get(); + var mapper = qsim.Get(); + + var x_1 = x.Partial(new Func(q => q)); + var x_2 = x_1.Partial(new Func(q => q)); + var x_3 = x.Partial>(AbstractCallable._); + + var plain_1 = plain.Partial(new Func((arg) => (1, arg, x))); + var adj_1 = adj.Partial(new Func<((Qubit,Qubit,IQArray),IAdjointable), (Int64, (Qubit, Qubit, IQArray), IAdjointable)>((arg) => (3, arg.Item1, arg.Item2))); + var adj_2 = adj_1.Adjoint.Partial(new Func<(Qubit, Qubit, IQArray), ((Qubit, Qubit, IQArray), IAdjointable)>((arg) => (arg, adj))); + var ctrl_1 = ctrl.Partial(new Func<(Qs, IControllable), (Int64, Qs,IControllable)>((arg) => (4, arg.Item1, arg.Item2))); + var mapper_1 = mapper.Partial(new Func, (ICallable, IQArray)>((arg) => (x, arg))); + + TestOneProxy("Qubit => () : Adjoint, Controlled", x_1); + TestOneProxy("Qubit => () : Adjoint, Controlled", x_2); + TestOneProxy("Qubit => () : Adjoint, Controlled", x_3); + TestOneProxy("((Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj_1); + TestOneProxy("(Qubit,Qubit,Qubit[]) => () : Adjoint", adj_2); + TestOneOp("BAdj1", "Microsoft.Quantum.Tests.CoreOperations.BAdj1", OperationFunctor.Body, "(Qubit,Qubit,Qubit[]) => () : Adjoint", adj_2.Adjoint); + TestOneProxy("(Qs,Controllable) => () : Controlled", ctrl_1); + TestOneOp("BCtrl1", "Microsoft.Quantum.Tests.CoreOperations.BCtrl1", OperationFunctor.Controlled, "(Qubit[],(Qs,Controllable)) => () : Controlled", ctrl_1.Controlled); + TestOneProxy("Result[] => String[]", mapper_1); + }); + } + + private void TestOneProxy(string name, string fullName, OperationFunctor variant, string signature, GenericCallable op) + { + var proxy = new GenericCallable.DebuggerProxy(op); + + Assert.Equal(name, proxy.Name); + Assert.Equal(fullName, proxy.FullName); + Assert.Equal(variant, proxy.Variant); + } + + [Fact] + public void GenericDebuggerProxy() + { + Helper.RunWithMultipleSimulators((qsim) => + { + var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable; + var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)) as GenericCallable; + var gen3 = qsim.Get(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable; + + TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Body, "T => () : Adjoint, Controlled", trace); + TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Adjoint, "T => () : Adjoint, Controlled", trace.Adjoint); + TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Controlled, "(Qubit[],T) => () : Adjoint, Controlled", trace.Controlled); + TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.ControlledAdjoint, "(Qubit[],T) => () : Adjoint, Controlled", trace.Adjoint.Controlled); + TestOneProxy("DumpMachine", "Microsoft.Quantum.Diagnostics.DumpMachine", OperationFunctor.Body, "T => ()", dump); + TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Body, "(__T1,(__T2,__T3),Result) => () : Controlled", gen3); + TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Controlled, "(Qubit[],(__T1,(__T2,__T3),Result)) => () : Controlled", gen3.Controlled); + }); + } + + private void TestOneProxy(string partialTuple, GenericPartial op) + { + var proxy = new GenericPartial.DebuggerProxy(op); + + Assert.Equal(op.BaseOp, proxy.Base); + Assert.Equal(partialTuple, proxy.PartialTuple); + } + + [Fact] + public void GenericPartialDebuggerProxy() + { + Helper.RunWithMultipleSimulators((qsim) => + { + var _ = AbstractCallable._; + + var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable; + var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)) as GenericCallable; + var gen3 = qsim.Get(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable; + + var d_1 = dump.Partial(_); + var d_2 = d_1.Partial(_); + var d_3 = d_2.Adjoint.Partial(_); + + var t_1 = trace.Adjoint.Partial(_); + var t_2 = t_1.Controlled.Partial((_, true)); + + var g_1 = gen3.Partial((_, ("hello", _), _)); + var g_2 = g_1.Partial((_, Pauli.PauliX, Result.Zero)); + var g_3 = gen3.Partial(new Func(arg => (arg, ("bye", 3), Result.One))); + + TestOneProxy("_", t_1); + TestOneProxy("(_, True)", t_2); + TestOneProxy("_", d_1); + TestOneProxy("_", d_2); + TestOneProxy("(_, (hello, _), _)", g_1); + TestOneProxy("(_, PauliX, Zero)", g_2); + TestOneProxy("", g_3); + }); + } + + /// + /// Changes the current thread culture to the invariant culture, runs the action, and then restores the original + /// thread culture. + /// + /// The action to run within the invariant culture. + private static void WithInvariantCulture(System.Action action) + { + var culture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; + action(); + Thread.CurrentThread.CurrentCulture = culture; + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs b/src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs new file mode 100644 index 00000000000..04965adf032 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.Simulators.Tests { + open Microsoft.Quantum.Diagnostics; + + operation DumpToFile(filename : String) : Unit { + DumpMachine(filename); + } + +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/GenericsTests.cs b/src/Simulation/Simulators.Type2.Tests/GenericsTests.cs new file mode 100644 index 00000000000..a845b5472ad --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/GenericsTests.cs @@ -0,0 +1,852 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.ClosedType; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics; +using System; +using System.Collections.Generic; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + using Helper = Microsoft.Quantum.Simulation.Simulators.Tests.OperationsTestHelper; + + public class TestQubit : Qubit + { + public TestQubit() : base(0) { } + } + + public class GenericsTests + { + [Fact] + public void CreateGenericOperation() + { + Helper.RunWithMultipleSimulators((s) => + { + { + var gen = new GenericCallable(s, typeof(Gen0<>)); + Assert.Same(typeof(Gen0), gen.FindCallable(typeof(long), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen0<(long, Result)>), gen.FindCallable(typeof((long, Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen0<((long, bool), Result)>), gen.FindCallable(typeof(((long, bool), Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen0), gen.FindCallable(typeof(UDT_G1), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen0), gen.FindCallable(typeof(UDT_G2), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen0), gen.FindCallable(typeof(UDT_G3), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen0>), gen.FindCallable(typeof(QArray), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen0), gen.FindCallable(typeof(LittleEndian), typeof(QVoid)).GetType()); + } + { + var gen = new GenericCallable(s, typeof(Gen1<,>)); + Assert.Same(typeof(Gen1), gen.FindCallable(typeof((long, bool)), typeof(bool)).GetType()); + Assert.Same(typeof(Gen1<(long, Result), bool>), gen.FindCallable(typeof(((long, Result), bool)), typeof(bool)).GetType()); + Assert.Same(typeof(Gen1<((long, bool), Result), QVoid>), gen.FindCallable(typeof((((long, bool), Result), bool)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen1<((long, bool), Result), Pauli>), gen.FindCallable(typeof((((long, bool), Result), bool)), typeof(Pauli)).GetType()); + Assert.Same(typeof(Gen1, bool>), gen.FindCallable(typeof((QArray, bool)), typeof(bool)).GetType()); + Assert.Same(typeof(Gen1), gen.FindCallable(typeof(UDT_G1), typeof(Qubit)).GetType()); // no need to unwrapp qtuples automatically anymore. + Assert.Same(typeof(Gen1), gen.FindCallable(typeof(UDT_G2), typeof(Qubit)).GetType()); // no need to unwrapp qtuples automatically anymore. + Assert.Same(typeof(Gen1), gen.FindCallable(typeof(UDT_G5), typeof(UDT_G2)).GetType()); // no need to unwrapp qtuples automatically anymore. + } + + { + var gen = new GenericCallable(s, typeof(Gen2<,>)); + Assert.Same(typeof(Gen2), gen.FindCallable(typeof((Result, long, bool)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen2<(Result, Pauli, Qubit), bool>), gen.FindCallable(typeof(((Result, Pauli, Qubit), long, bool)), typeof(QVoid)).GetType()); + // not a valid scenario due to unwrap: Assert.Same(typeof(Gen2, Qubit>), gen.FindOperation(typeof(UDT_G4), typeof(QVoid)).GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Gen3<,,>)); + Assert.Same(typeof(Gen3), gen.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen3), gen.FindCallable(typeof((Result, ((long, long), Pauli), Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen3<(long, IAdjointable, double), bool, Pauli>), gen.FindCallable(typeof(((long, IAdjointable, double), (bool, Pauli), Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen3), gen.FindCallable(typeof((Result, (bool, (Pauli, Pauli)), Result)), typeof(QVoid)).GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Gen4<,>)); + Assert.Same(typeof(Gen4), gen.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen4<(bool, long, (int, ICallable)), Pauli>), gen.FindCallable(typeof((Result, ((bool, long, (int, ICallable)), Pauli), Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen4<(IUnitary, bool), (IAdjointable, Pauli)>), gen.FindCallable(typeof((Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result)), typeof(QVoid)).GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Gen5<>)); + Assert.Same(typeof(Gen5), gen.FindCallable(typeof(IQArray), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen5), gen.FindCallable(typeof(IQArray), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen5>), gen.FindCallable(typeof(IQArray>), typeof(QVoid)).GetType()); + // not a valid scenario due to unwrap: Assert.Same(typeof(Gen5), gen.FindOperation(typeof(LittleEndian), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen5), gen.FindCallable(typeof(IQArray), typeof(QVoid)).GetType()); + Assert.Same(typeof(Gen5>), gen.FindCallable(typeof(IQArray>), typeof(QVoid)).GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Iter<>)); + Assert.Same(typeof(Iter), gen.FindCallable(typeof((ICallable, IQArray)), typeof(QVoid)).GetType()); + } + }); + } + + [Fact] + public void CreateGenericAdjointOperation() + { + Helper.RunWithMultipleSimulators((s) => + { + var gen0 = new GenericCallable(s, typeof(Gen0<>)); + + Assert.Same(typeof(AdjointedOperation), gen0.Adjoint.FindCallable(typeof(long), typeof(QVoid)).GetType()); + Assert.Same(typeof(AdjointedOperation<(long, Result), QVoid>), gen0.Adjoint.FindCallable(typeof((long, Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(AdjointedOperation<((long, bool), Result), QVoid>), gen0.Adjoint.FindCallable(typeof(((long, bool), Result)), typeof(QVoid)).GetType()); + Assert.Same(typeof(AdjointedOperation<(long, Result), QVoid>), gen0.Adjoint.FindCallable(typeof((long, Result)), typeof(QVoid)).GetType()); // Twice to test caching. + + var gen2 = new GenericCallable(s, typeof(Gen2<,>)); + var r2 = gen2.Adjoint.FindCallable(typeof((Result, long, bool)), typeof(QVoid)) as AdjointedOperation<(Result, long, bool), QVoid>; + Assert.NotNull(r2); + Assert.Same(typeof(Gen2), r2.BaseOp.GetType()); + + var gen4 = new GenericCallable(s, typeof(Gen4<,>)); + var r4 = gen4.Adjoint.FindCallable(typeof((Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result)), typeof(QVoid)) as AdjointedOperation<(Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result), QVoid>; + Assert.NotNull(r4); + Assert.Same(typeof(Gen4<(IUnitary, bool), (IAdjointable, Pauli)>), r4.BaseOp.GetType()); + }); + } + + + [Fact] + public void CreateGenericControlledOperation() + { + Helper.RunWithMultipleSimulators((s) => + { + var gen0 = new GenericCallable(s, typeof(Gen0<>)); + + Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((QArray, long)), typeof(QVoid)).GetType()); + Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((LittleEndian, long)), typeof(QVoid)).GetType()); + Assert.Same(typeof(ControlledOperation<(long, Result), QVoid>), gen0.Controlled.FindCallable(typeof((QArray, (long, Result))), typeof(QVoid)).GetType()); + Assert.Same(typeof(ControlledOperation<((Qubit, bool), Result), QVoid>), gen0.Controlled.FindCallable(typeof((QArray, ((TestQubit, bool), Result))), typeof(QVoid)).GetType()); + Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((QArray, long)), typeof(QVoid)).GetType()); // Twice to check for caching. + + var gen2 = new GenericCallable(s, typeof(Gen2<,>)); + var r2 = gen2.Controlled.FindCallable(typeof((LittleEndian, (QArray, long, bool))), typeof(QVoid)) as ControlledOperation<(QArray, long, bool), QVoid>; + Assert.NotNull(r2); + Assert.Same(typeof(Gen2, bool>), r2.BaseOp.GetType()); + + var gen4 = new GenericCallable(s, typeof(Gen4<,>)); + var r4 = gen4.Controlled.FindCallable(typeof((QArray, (Result, ((IUnitary, bool), (IAdjointable<(TestQubit, Result)>, Pauli)), Result))), typeof(QVoid)) as ControlledOperation<(Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result), QVoid>; + Assert.NotNull(r4); + Assert.Same(typeof(Gen4<(IUnitary, bool), (IAdjointable, Pauli)>), r4.BaseOp.GetType()); + }); + } + [Fact] + public void FindOperation() + { + var _ = AbstractCallable._; + + Helper.RunWithMultipleSimulators((s) => + { + { + var gen = s.Get(typeof(Gen1<,>)); + + // Calling twice for the same input + var expected = gen.FindCallable(typeof((long, bool)), typeof(bool)); + var actual = gen.FindCallable(typeof((long, bool)), typeof(bool)); + Assert.Same(expected, actual); + + // Change the input type, different operations + expected = gen.FindCallable(typeof((long, Result)), typeof(Result)); + Assert.NotSame(expected, actual); + actual = gen.FindCallable(typeof((long, Result)), typeof(Result)); + Assert.Same(expected, actual); + + var unitary = s.Get(typeof(Gen4<,>)); + expected = unitary.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); + actual = unitary.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); + Assert.Same(expected, actual); + + expected = unitary.Adjoint.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); + actual = unitary.Adjoint.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); + Assert.Same(expected, actual); + + expected = unitary.Controlled.FindCallable(typeof((QArray, (Result, (bool, Pauli), Result))), typeof(QVoid)); + actual = unitary.Controlled.FindCallable(typeof((QArray, (Result, (bool, Pauli), Result))), typeof(QVoid)); + Assert.Same(expected, actual); + + // Partial gives us a new instance every time. + expected = unitary.Partial((_,_,_)); + actual = unitary.Partial((_, _, _)); + Assert.NotSame(expected, actual); + } + }); + } + + + [Fact] + public void CreateGenericOperationWithMultipleFunctors() + { + var _ = AbstractCallable._; + + Helper.RunWithMultipleSimulators((s) => + { + var gen0 = new GenericCallable(s, typeof(Gen0<>)); + + Assert.Same(typeof(Gen0), gen0.FindCallable(typeof(long), typeof(QVoid)).GetType()); + Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((IQArray, long)), typeof(QVoid)).GetType()); + Assert.Same(typeof(AdjointedOperation), gen0.Adjoint.FindCallable(typeof(long), typeof(QVoid)).GetType()); + { + var op = gen0.Adjoint.Controlled.FindCallable(typeof((IQArray, long)), typeof(QVoid)) as ControlledOperation; + Assert.NotNull(op); + Assert.Same(typeof(AdjointedOperation), op.BaseOp.GetType()); + } + { + var op = gen0.Controlled.Adjoint.FindCallable(typeof((IQArray, long)), typeof(QVoid)) as AdjointedOperation<(IQArray, long), QVoid>; + Assert.NotNull(op); + Assert.Same(typeof(ControlledOperation), op.BaseOp.GetType()); + } + }); + } + + + [Fact] + public void CreateGenericPartial() + { + var _ = AbstractCallable._; + + Helper.RunWithMultipleSimulators((s) => + { + { + var gen = new GenericCallable(s, typeof(Gen0<>)); + var partial = gen.Partial(_); + Assert.Same(typeof(long), partial.IdentifyBaseArgsType(typeof(long))); + Assert.Same(typeof(Qubit), partial.IdentifyBaseArgsType(typeof(Qubit))); + Assert.Same(typeof((bool, long)), partial.IdentifyBaseArgsType(typeof((bool, long)))); + + { + var op1 = partial.FindCallable(typeof(Qubit), typeof(QVoid)) as OperationPartial; + Assert.NotNull(op1); + } + { + var op1 = partial.FindCallable(typeof(Double), typeof(QVoid)) as OperationPartial; + Assert.NotNull(op1); + } + } + + { + var gen = new GenericCallable(s, typeof(Gen0<>)); + var partial = gen.Adjoint.Partial(_); + Assert.Same(typeof(long), partial.IdentifyBaseArgsType(typeof(long))); + Assert.Same(typeof(Qubit), partial.IdentifyBaseArgsType(typeof(Qubit))); + Assert.Same(typeof((bool, long)), partial.IdentifyBaseArgsType(typeof((bool, long)))); + + { + var op1 = partial.FindCallable(typeof(Qubit), typeof(QVoid)) as OperationPartial; + Assert.NotNull(op1); + } + { + var op1 = partial.FindCallable(typeof(Double), typeof(QVoid)) as OperationPartial; + Assert.NotNull(op1); + } + } + + { + var gen = new GenericCallable(s, typeof(Gen0<>)); + var ctrl = gen.Controlled; + var partial = ctrl.Partial((new QArray(), _)); + Assert.Same(typeof((QArray, long)), partial.IdentifyBaseArgsType(typeof(long))); + Assert.Same(typeof((QArray, string)), partial.IdentifyBaseArgsType(typeof(string))); + Assert.Same(typeof((QArray, Qubit)), partial.IdentifyBaseArgsType(typeof(Qubit))); + Assert.Same(typeof((QArray, (bool, long))), partial.IdentifyBaseArgsType(typeof((bool, long)))); + { + var op1 = partial.FindCallable(typeof(Result), typeof(QVoid)); + Assert.Equal(typeof(OperationPartial, Result), QVoid>), op1.GetType()); + } + { + var op1 = partial.FindCallable(typeof(string), typeof(QVoid)); + Assert.Equal(typeof(OperationPartial, string), QVoid>), op1.GetType()); + } + } + + { + var gen = new GenericCallable(s, typeof(TraceGate<>)); + var partial = gen.Partial((s.Get, Intrinsic.X>(), "normal", _)); + + Assert.Same(typeof((IUnitary, string, Result)), partial.IdentifyBaseArgsType(typeof(Result))); + Assert.Same(typeof((IUnitary, string, Qubit)), partial.IdentifyBaseArgsType(typeof(TestQubit))); + var op1 = partial.FindCallable(typeof(TestQubit), typeof(QVoid)); + Assert.Equal(typeof(OperationPartial), op1.GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Gen1<,>)); + var partial = gen.Partial((_, 2.3D)); + Assert.Same(typeof((Result, double)), partial.IdentifyBaseArgsType(typeof(Result))); + var op1 = partial.FindCallable(typeof(Result), typeof(double)); + Assert.Equal(typeof(OperationPartial), op1.GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Gen2<,>)); + var partial = gen.Partial((_, _, _)); + Assert.Same(typeof((Result, long, bool)), partial.IdentifyBaseArgsType(typeof((Result, long, bool)))); + } + + { + var gen = new GenericCallable(s, typeof(Gen2<,>)); + var p1 = new GenericCallable(s, typeof(Gen1<,>)) as ICallable; + var p2 = new GenericCallable(s, typeof(Gen2<,>)) as IAdjointable; + var p3 = p2.Partial((_, true)); + + var partial = gen.Partial((p1, _, (p2, p3))); + Assert.Same(typeof((ICallable, long, (IAdjointable, IAdjointable))), partial.IdentifyBaseArgsType(typeof(long))); + var op1 = partial.FindCallable(typeof(long), typeof(QVoid)); + Assert.Equal(typeof(OperationPartial), op1.GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Gen2<,>)); + var p1 = new GenericCallable(s, typeof(Gen1<,>)) as ICallable; + var p2 = new GenericCallable(s, typeof(Gen2<,>)) as IAdjointable; + var p3 = p2.Partial((_, true)); + + var partial = gen.Partial(((_, p1), _, (p2, p3))); + Assert.Same(typeof(((Qubit, ICallable), long, (IAdjointable, IAdjointable))), partial.IdentifyBaseArgsType(typeof((TestQubit, long)))); + var op1 = partial.FindCallable(typeof((TestQubit, long)), typeof(QVoid)); + Assert.Equal(typeof(OperationPartial<(Qubit, long), ((Qubit, ICallable), long, (IAdjointable, IAdjointable)), QVoid>), op1.GetType()); + } + + { + var gen = new GenericCallable(s, typeof(Gen2<,>)); + var partial = gen.Partial((_, 2L, false)); + Assert.Same(typeof((Result, long, bool)), partial.IdentifyBaseArgsType(typeof(Result))); + Assert.Same(typeof((IUnitary, long, bool)), partial.IdentifyBaseArgsType(typeof(IUnitary))); + } + + { + var gen = new GenericCallable(s, typeof(Gen3<,,>)); + var partial = gen.Partial((_, (_, s.Get, ClosedType3>()), Result.Zero)); + Assert.Same(typeof((long, (bool, IControllable), Result)), partial.IdentifyBaseArgsType(typeof((long, bool)))); + Assert.Same(typeof((IUnitary, (Qubit, IControllable), Result)), partial.IdentifyBaseArgsType(typeof((IUnitary, Qubit)))); + Assert.Same(typeof((string, (string, IControllable), Result)), partial.IdentifyBaseArgsType(typeof((string, string)))); + } + + { + var gen = new GenericCallable(s, typeof(Gen3<,,>)); + var partial = gen.Partial((s.Get, ClosedType2>(), (_, _), Result.Zero)); + Assert.Same(typeof((IAdjointable, (long, bool), Result)), partial.IdentifyBaseArgsType(typeof((long, bool)))); + Assert.Same(typeof((IAdjointable, (IUnitary, Qubit), Result)), partial.IdentifyBaseArgsType(typeof((IUnitary, Qubit)))); + Assert.Same(typeof((IAdjointable, (string, string), Result)), partial.IdentifyBaseArgsType(typeof((string, string)))); + } + + { + var gen = new GenericCallable(s, typeof(Gen4<,>)); + var partial = gen.Partial((Result.One, (s.Get, ClosedType4>(), _), Result.Zero)); + Assert.Same(typeof((Result, (IUnitary, bool), Result)), partial.IdentifyBaseArgsType(typeof(bool))); + Assert.Same(typeof((Result, (IUnitary, (IUnitary, Qubit)), Result)), partial.IdentifyBaseArgsType(typeof((IUnitary, Qubit)))); + Assert.Same(typeof((Result, (IUnitary, (string, string)), Result)), partial.IdentifyBaseArgsType(typeof((string, string)))); + } + + { + var gen = new GenericCallable(s, typeof(Gen3<,,>)); + var partial = gen.Partial((_,_,Result.Zero)); + Assert.Same(typeof(((long, bool), (double,double), Result)), partial.IdentifyBaseArgsType(typeof(((long, bool),(double,double))))); + Assert.Same(typeof((long, (double, double), Result)), partial.IdentifyBaseArgsType(typeof((long, (double, double))))); + Assert.Same(typeof((long, (double, (long,double)), Result)), partial.IdentifyBaseArgsType(typeof((long, (double, (long,double)))))); + } + + { + var gen = new GenericCallable(s, typeof(Gen3<,,>)); + var partial = gen.Partial((_, (4.1,_), Result.Zero)); + Assert.Same(typeof(((long, bool), (double, double), Result)), partial.IdentifyBaseArgsType(typeof(((long, bool), double)))); + Assert.Same(typeof((long, (double, double), Result)), partial.IdentifyBaseArgsType(typeof((long, double)))); + Assert.Same(typeof((long, (double ,(long, double)), Result)), partial.IdentifyBaseArgsType(typeof((long, (long, double))))); + } + }); + } + + + [Fact] + public void CreateDifferentPartial() + { + var _ = AbstractCallable._; + + Helper.RunWithMultipleSimulators((s) => + { + { + var gen = new GenericCallable(s, typeof(Gen1<,>)); + var partial = gen.Partial(_); + Assert.Equal(typeof(GenericPartial), partial.GetType()); + } + + { + var closed = new Gen1(s); + var partial = closed.Partial(_); + Assert.Equal(typeof(OperationPartial<(long, bool), (long, bool), bool>), partial.GetType()); + } + + { + var closed = new Gen1<(long, long), bool>(s); + var partial = closed.Partial(((3L, _), true)); + Assert.Equal(typeof(OperationPartial), partial.GetType()); + } + + { + var x = s.Get, Intrinsic.X>(); + var closed = new Gen1<(long, (IUnitary, Qubit, Result)), bool>(s); + var partial = closed.Partial(((_, (x, _, _)), true)); + Assert.Equal(typeof(OperationPartial<(long, (Qubit, Result)), ((long, (IUnitary, Qubit, Result)), bool), bool>), partial.GetType()); + } + + { + var x = s.Get, Intrinsic.X>(); + var closed = new Gen1<(long, (IUnitary, Qubit, Result)), bool>(s) as ICallable<((long, (IUnitary, Qubit, Result)), bool), bool>; + var partial = closed.Partial(((_, (x, _, _)), false)); + Assert.Equal(typeof(OperationPartial<(long, (Qubit, Result)), ((long, (IUnitary, Qubit, Result)), bool), bool>), partial.GetType()); + } + + { + var closed = new Gen2<(long, bool, Result), IUnitary>(s); + var partial = closed.Partial(((_, true, _), 3L, _)); + Assert.Equal(typeof(OperationPartial<((long, Result), IUnitary), ((long, bool, Result), long, IUnitary), QVoid>), partial.GetType()); + } + + { + var closed = new Gen2(s) as IAdjointable<(bool, long, Result)>; + var partial = closed.Partial((_, 3L, Result.Zero)); + Assert.Equal(typeof(OperationPartial), partial.GetType()); + } + + { + var closed = new Gen4(s) as IUnitary<(Result, (bool, bool), Result)>; + var partial = closed.Controlled.Partial((_, (_, (true, _), Result.Zero))); + Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); + } + + { + var closed = new Gen4(s) as IControllable<(Result, (bool, bool), Result)>; + var partial = closed.Controlled.Partial((_, (_, (true, _), Result.Zero))); + Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); + } + + { + var closed = new Gen2(s) as IAdjointable; + var partial = closed.Partial((_, 3L, Result.Zero)); + Assert.Equal(typeof(OperationPartial), partial.GetType()); + } + + { + var closed = new Gen4(s) as IUnitary; + var partial = closed.Adjoint.Controlled.Partial((_, (_, (true, _), Result.Zero))); + Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); + } + + { + var closed = new Gen4(s) as IControllable; + var partial = closed.Controlled.Partial((_, (_, (true, _), Result.Zero))); + Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); + } + }); + } + + private void CheckIter(Log log, T zero, T uno) + { + Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Body, zero)); + Assert.Equal(1, log.GetNumberOfCalls(OperationFunctor.Body, uno)); + + Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.Adjoint, zero)); + Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Adjoint, uno)); + + Assert.Equal(1, log.GetNumberOfCalls(OperationFunctor.Controlled, zero)); + Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.Controlled, uno)); + + Assert.Equal(4, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, zero)); + Assert.Equal(5, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, uno)); + } + + private void CheckRepeat(Log log) + { + Assert.Equal(5, log.GetNumberOfCalls(OperationFunctor.Body, "normal")); + Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Adjoint, "normal")); + Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.Controlled, "normal")); + Assert.Equal(0, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "normal")); + + Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Body, "adjoint")); + Assert.Equal(5, log.GetNumberOfCalls(OperationFunctor.Adjoint, "adjoint")); + Assert.Equal(0, log.GetNumberOfCalls(OperationFunctor.Controlled, "adjoint")); + Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "adjoint")); + } + + [Fact] + public void ClosedTypeIter() + { + Helper.RunWithMultipleSimulators((s) => + { + Circuits.ClosedType.TestIter.Run(s).Wait(); + + var tracer = s.Get() as Helper.TracerImpl; + CheckIter(tracer.Log, "cero", "uno"); + }); + } + + [Fact] + public void ClosedTypeRepeatPartial() + { + Helper.RunWithMultipleSimulators((s) => + { + Circuits.ClosedType.TestRepeatPartial.Run(s).Wait(); + + var t = s.Get() as Helper.TracerImpl; + CheckRepeat(t.Log); + }); + } + + [Fact] + public void GenericIter() + { + Helper.RunWithMultipleSimulators((s) => + { + Circuits.Generics.TestIter.Run(s).Wait(); + + var strTracer = s.GetTracer(); + CheckIter(strTracer.Log, "cero", "uno"); + + var resTracer = s.GetTracer(); + CheckIter(resTracer.Log, Result.Zero, Result.One); + }); + } + + [Fact] + public void GenericRepeatPartial() + { + Helper.RunWithMultipleSimulators((s) => + { + Circuits.Generics.TestRepeatPartial.Run(s).Wait(); + + var tracer = s.GetTracer(); + CheckRepeat(tracer.Log); + }); + } + + [Fact] + public void CreateRepeatWrapperPartial() + { + Helper.RunWithMultipleSimulators((s) => + { + TestCreateRepeatWrapperPartial.Run(s).Wait(); + + var tracer = s.GetTracer(); + CheckRepeat(tracer.Log); + }); + } + + [Fact] + public void TestLookupUnitaries() + { + Helper.RunWithMultipleSimulators((s) => + { + Circuits.Generics.TestLookupUnitaries.Run(s).Wait(); + + var tracer = s.GetTracer(); + + Assert.Equal(6, tracer.GetNumberOfCalls(OperationFunctor.Body, "uno")); + Assert.Equal(6, tracer.GetNumberOfCalls(OperationFunctor.Adjoint, "uno")); + Assert.Equal(9, tracer.GetNumberOfCalls(OperationFunctor.Controlled, "uno")); + Assert.Equal(6, tracer.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "uno")); + }); + } + + [Fact] + public void ClosedUDTsPolyMorphism() + { + Helper.RunWithMultipleSimulators((s) => + { + TestUDTsUnwrapping.Run(s).Wait(); + + var stracer = s.Get() as Helper.TracerImpl; + + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2a")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2b")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2a")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2b")); + + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2x")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2y")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2x")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2y")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "d2x")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "d2y")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "d2x")); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "d2y")); + }); + } + + [Fact] + public void NonGenericPartial() + { + Helper.RunWithMultipleSimulators((s) => + { + TestNonGenericPartial.Run(s).Wait(); + + var stracer = s.GetTracer(); + var itracer = s.GetTracer(); + var rtracer = s.GetTracer(); + var sstracer = s.GetTracer<(string, string)>(); + var rrtracer = s.GetTracer<(Result, Result)>(); + + Assert.Equal(7, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "a1")); + Assert.Equal(7, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "a2")); + Assert.Equal(7, itracer.Log.GetNumberOfCalls(OperationFunctor.Body, 2)); + Assert.Equal(7, itracer.Log.GetNumberOfCalls(OperationFunctor.Body, 3)); + Assert.Equal(7, rtracer.Log.GetNumberOfCalls(OperationFunctor.Body, Result.Zero)); + Assert.Equal(7, rtracer.Log.GetNumberOfCalls(OperationFunctor.Body, Result.One)); + Assert.Equal(7, sstracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("a1", "a2"))); + Assert.Equal(7, rrtracer.Log.GetNumberOfCalls(OperationFunctor.Body, (Result.Zero, Result.One))); + + + Assert.Equal(9, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "a1")); + Assert.Equal(9, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "a2")); + Assert.Equal(9, itracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 2)); + Assert.Equal(9, itracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 3)); + Assert.Equal(9, rtracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, Result.Zero)); + Assert.Equal(9, rtracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, Result.One)); + Assert.Equal(9, sstracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, ("a1", "a2"))); + Assert.Equal(9, rrtracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (Result.Zero, Result.One))); + + Assert.Equal(3, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "a1")); + Assert.Equal(3, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "a2")); + Assert.Equal(3, itracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, 2)); + Assert.Equal(3, itracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, 3)); + Assert.Equal(3, rtracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, Result.Zero)); + Assert.Equal(3, rtracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, Result.One)); + Assert.Equal(3, sstracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, ("a1", "a2"))); + Assert.Equal(3, rrtracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, (Result.Zero, Result.One))); + + Assert.Equal(4, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "a1")); + Assert.Equal(4, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "a2")); + Assert.Equal(4, itracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, 2)); + Assert.Equal(4, itracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, 3)); + Assert.Equal(4, rtracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, Result.Zero)); + Assert.Equal(4, rtracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, Result.One)); + Assert.Equal(4, sstracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, ("a1", "a2"))); + Assert.Equal(4, rrtracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, (Result.Zero, Result.One))); + }); + } + + [Fact] + public void GenericPartialNestedTupleArgs() + { + Helper.RunWithMultipleSimulators((s) => + { + TestGenericPartial.Run(s).Wait(); + + var sstracer = s.GetTracer<(string, string)>(); + var stracer = s.GetTracer(); + + Assert.Equal(9, sstracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("T1", "T2"))); + Assert.Equal(11, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("argA"))); + Assert.Equal(11, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("argB"))); + Assert.Equal(10, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("argD"))); + }); + } + + [Fact] + public void GenericsCallablesArguments() + { + Helper.RunWithMultipleSimulators((s) => + { + BindTest.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("success!"))); + }); + } + + [Fact] + public void GenericCompose() + // FIXME: there are more cases similar to this one where the workaround of using object + // for the parts of the type argument O in Apply which are unresolvable won't work + { + Helper.RunWithMultipleSimulators((s) => + { + TestCompose.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "cero")); + TestComposeWithNonGeneric.Run(s).Wait(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "redirecting:cero")); + }); + } + + [Fact] + public void GenericMultiControlled() + { + Helper.RunWithMultipleSimulators((s) => + { + MultiControlledTest.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1))); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (2))); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3))); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (4))); + }); + } + + [Fact] + public void GenericsMixedComponents() + { + Helper.RunWithMultipleSimulators((s) => + { + MixedComponentsTest.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1))); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (2))); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (2))); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (3))); + }); + } + + [Fact] + public void GenericsAssignments() + { + Helper.RunWithMultipleSimulators((s) => + { + AssignmentsTest.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1))); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (2))); + Assert.Equal(2, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (3))); + Assert.Equal(2, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3))); + }); + } + + [Fact] + public void GenericsAssignmentsWithPartialApplications() + { + Helper.RunWithMultipleSimulators((s) => + { + AssignmentsWithPartialsTest.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (2))); + Assert.Equal(3, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3))); + }); + } + + [Fact] + public void GenericsCallableCasts() + { + Helper.RunWithMultipleSimulators((s) => + { + CCNOTCiruitsTest.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("success!"))); + }); + } + + [Fact] // FIXME: remove dummy in MapDefaults in Generics.qs to make this test meaningful! (currently this is not supported in the simulation core) + public void GenericsHiddenGenericParameters() + { + Helper.RunWithMultipleSimulators((s) => + { + TestMapDefaults.Run(s).Wait(); + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("success!"))); + }); + } + + [Fact] + public void GenericsMultipleTypeParameters() + { + Helper.RunWithMultipleSimulators((s) => + { + TestMultipleTypeParamters.Run(s).Wait(); + var ltracer = s.GetTracer(); + Assert.Equal(1, ltracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1L))); + }); + } + + [Fact] + public void GenericsDestructingArgTuple() + { + Helper.RunWithMultipleSimulators((s) => + { + TestDestructingArgTuple.Run(s).Wait(); + var ltracer = s.GetTracer(); + Assert.Equal(1, ltracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1L))); + var sstracer = s.GetTracer<(string, string)>(); + Assert.Equal(1, sstracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, ("Hello", "World"))); + }); + } + + [Fact] + public void ControlledBitString() + { + Helper.RunWithMultipleSimulators((s) => + { + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + + TestControlledBitString.Run(s).Wait(); + var tracer = s.GetTracer(); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, 0)); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, 1)); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, 2)); + + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 0)); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 1)); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 2)); + + var stracer = s.GetTracer(); + Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "ok")); + }); + } + + + [Fact] + public void ApplyToEachUdt() + { + Helper.RunWithMultipleSimulators((s) => + { + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + + TestApplyToEachUdt.Run(s).Wait(); + var tracer = s.GetTracer(); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, q0)); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, q1)); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, q2)); + }); + } + + [Fact] + public void UDTsPolyMorphism() + { + Helper.RunWithMultipleSimulators((s) => + { + var tracker = new StartTracker(s); + + TestUDTsPolyMorphism.Run(s).Wait(); + + Assert.Equal(20, tracker.GetNumberOfCalls("Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Body)); + }); + } + + [Fact] + public void WrapperWithDifferentReturnValues() + { + Helper.RunWithMultipleSimulators((s) => + { + var gen = new GenericCallable(s, typeof(Gen0<>)); + WrapperWithDifferentReturnValuesTest.Run(s).Wait(); + + // do some manual tests to verify cache works: + var wrapper = new GenericCallable(s, typeof(GenWrapper<,>)); + var str1 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(String)); + var int1 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(Int64)); + var str2 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(String)); + var int2 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(Int64)); + + Assert.Same(str1, str2); + Assert.Same(int1, int2); + Assert.NotSame(str1, int1); + Assert.Same(typeof(GenWrapper), str1.GetType()); + Assert.Same(typeof(GenWrapper), int1.GetType()); + }); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs b/src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs new file mode 100644 index 00000000000..c952d210e5a --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs @@ -0,0 +1,395 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Tests.Tuples; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + internal class FreeQubit : Qubit + { + public FreeQubit(int id) : base(id) + { + } + } + + internal class UnitaryNoOp : Unitary, ICallable + { + public UnitaryNoOp() : base(null) { } + + public override void Init() { } + + public override Func<(IQArray, TInput), QVoid> ControlledAdjointBody => (arg) => + { + Debug.Write("NoOp:ControlledAdjointBody:" + typeof(TInput).FullName); + return QVoid.Instance; + }; + + public override Func AdjointBody => (arg) => + { + Debug.Write("NoOp:AdjointBody:" + typeof(TInput).FullName); + return QVoid.Instance; + }; + + public override Func<(IQArray, TInput), QVoid> ControlledBody => (arg) => + { + Debug.Write("NoOp:ControlledBody:" + typeof(TInput).FullName); + return QVoid.Instance; + }; + + public override Func Body => (TInput arg) => + { + Debug.Write("NoOp:Body:" + typeof(TInput).FullName); + return QVoid.Instance; + }; + + string ICallable.FullName => "UnitaryNoOp"; + } + + public class GetQubitsTests + { + int GetQubitsCount(object val) + { + var v = val.GetQubits(); + if (v == null) { return 0; } + return v.Count(); + } + + [Fact] + public void QubitFreeTypes() + { + Assert.Null((Pauli.PauliI as object).GetQubits()); + Assert.Null((OperationFunctor.Body as object).GetQubits()); + + var x1 = new QRange(0, 1); + Assert.Null((x1 as object).GetQubits()); + + var tpl1 = (1, 1, (1.2, new QRange(0, 1))); + Assert.Null((tpl1 as object).GetQubits()); + + var tpl2 = (1, new int[] { 1, 2 }); + Assert.Null((tpl2 as object).GetQubits()); + + var tpl3 = (1, 1, 1); + Assert.Null((tpl3 as object).GetQubits()); + + var tpl4 = (1, 1, 1, 1); + Assert.Null((tpl4 as object).GetQubits()); + + var tpl5 = (1, 1, 1, 1, 1); + Assert.Null((tpl5 as object).GetQubits()); + + var tpl6 = (1, 1, 1, 1, 1, 1); + Assert.Null((tpl6 as object).GetQubits()); + + var tpl7 = (1, 1, 1, 1, 1, 1, 1); + Assert.Null((tpl7 as object).GetQubits()); + + var tpl8 = (1, 1, 1, 1, 1, 1, 1, 1); + Assert.Null((tpl8 as object).GetQubits()); + + var tpl9 = (1, 1, 1, 1, 1, 1, 1, 1, 1); + Assert.Null((tpl9 as object).GetQubits()); + + var e1 = new int[][] { new int[] { 1 }, new int[] { 2, 3 } }; + Assert.Null((e1 as object).GetQubits()); + } + + static IQArray FreeQubitsRange(int start, int length) + { + var ids = Enumerable.Range(start, length); + return new QArray(ids.Select(id => new FreeQubit(id))); + } + + static IQArray<(T, Qubit)> FreeQubitsTuplesRange(int start, int length) + { + var ids = Enumerable.Range(start, length); + var items = ids.Select(id => (default(T), (Qubit) new FreeQubit(id))); + return new QArray<(T, Qubit)>(items); + } + + [Fact] + public void TypesWithQubits() + { + var tpl2 = (new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(2, GetQubitsCount(tpl2)); + + var tpl3 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(3, GetQubitsCount(tpl3)); + + var tpl4 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(4, GetQubitsCount(tpl4)); + + var tpl5 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(5, GetQubitsCount(tpl5)); + + var tpl6 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(6, GetQubitsCount(tpl6)); + + var tpl7 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(7, GetQubitsCount(tpl7)); + + var tpl8 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(8, GetQubitsCount(tpl8)); + + var tpl9 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); + Assert.Equal(9, GetQubitsCount(tpl9)); + + var rng2 = FreeQubitsTuplesRange<(int, int, double)>(0, 10); + Assert.Equal(rng2.Length, GetQubitsCount(rng2)); + + var rng5 = FreeQubitsRange(0, 10); + Assert.Equal(rng5.Length, GetQubitsCount(rng5)); + } + + void AssertAllFunctorsHaveNoQubitsCaptured(IUnitary op) + { + var AssertNullOrEmpty = new System.Action((qubits) => + { + Assert.True(qubits == null || qubits.Length == 0); + }); + + AssertNullOrEmpty(op.GetQubits()?.ToArray()); + AssertNullOrEmpty(op.Controlled.GetQubits()?.ToArray()); + AssertNullOrEmpty(op.Adjoint.GetQubits()?.ToArray()); + AssertNullOrEmpty(op.Controlled.Adjoint.GetQubits()?.ToArray()); + } + + void AssertAllFunctorsHaveQubitsCaptured(IUnitary op, int numberOfQubits) + { + Assert.Equal(numberOfQubits, GetQubitsCount(op)); + Assert.Equal(numberOfQubits, GetQubitsCount(op.Controlled)); + Assert.Equal(numberOfQubits, GetQubitsCount(op.Adjoint)); + Assert.Equal(numberOfQubits, GetQubitsCount(op.Adjoint.Controlled)); + } + + [Fact] + public void TypesWithClosures() + { + { + var op1 = new UnitaryNoOp<(int, int, int)>() as IUnitary<(int, int, int)>; + var partialOp1 = op1.Partial((AbstractCallable._, AbstractCallable._, 3)); + var partialOp3 = partialOp1.Partial((AbstractCallable._, 3)); + + AssertAllFunctorsHaveNoQubitsCaptured(partialOp1); + AssertAllFunctorsHaveNoQubitsCaptured(partialOp3); + AssertAllFunctorsHaveNoQubitsCaptured(op1); + } + { + var op2 = new UnitaryNoOp<(int, int, Qubit)>() as IUnitary<(int, int, Qubit)>; + var partialOp2 = op2.Partial((AbstractCallable._, AbstractCallable._, new FreeQubit(0))); + + AssertAllFunctorsHaveQubitsCaptured(partialOp2, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op2); + } + { + var op3 = new UnitaryNoOp<(int, Qubit, Qubit)>() as IUnitary<(int, Qubit, Qubit)>; + var partialOp4 = op3.Partial((AbstractCallable._, AbstractCallable._, new FreeQubit(0))); + + AssertAllFunctorsHaveQubitsCaptured(partialOp4, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op3); + + var partialOp5 = partialOp4.Partial((AbstractCallable._, new FreeQubit(1))); + AssertAllFunctorsHaveQubitsCaptured(partialOp5, 2); + } + { + var _ = AbstractCallable._; + var q0 = new FreeQubit(0); + var q1 = new FreeQubit(1); + var q2 = new FreeQubit(2); + var q3 = new FreeQubit(3); + var q4 = new FreeQubit(4); + var q5 = new FreeQubit(5); + var qArray = new QArray(q4, q5); + + var op = new UnitaryNoOp<(int, (Qubit, Qubit, Qubit), QArray)>() as IUnitary<(int, (Qubit, Qubit, Qubit), QArray)>; + var p1 = op.Partial((_, (_, q1, _), _)); + + AssertAllFunctorsHaveQubitsCaptured(p1, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op); + + var p2 = p1.Partial((_, _, qArray)); + AssertAllFunctorsHaveQubitsCaptured(p2, 3); + AssertAllFunctorsHaveQubitsCaptured(p1, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op); + + var p3 = p2.Partial(new Func(q => (2, (q3, q2)))); + AssertAllFunctorsHaveQubitsCaptured(p3, 5); + AssertAllFunctorsHaveQubitsCaptured(p2, 3); + AssertAllFunctorsHaveQubitsCaptured(p1, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op); + } + } + + [Fact] + public void GenericTypesWithClosures() + { + var _ = AbstractCallable._; + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + var q3 = new FreeQubit(3) as Qubit; + var q4 = new FreeQubit(4) as Qubit; + var q5 = new FreeQubit(5) as Qubit; + var qArray = new QArray(q4, q5); + + { + var op1 = new GenericCallable(null, typeof(UnitaryNoOp<(int, int, int)>)); + var partialOp1 = op1.Partial((AbstractCallable._, AbstractCallable._, 3)); + var partialOp3 = partialOp1.Partial((AbstractCallable._, 3)); + + AssertAllFunctorsHaveNoQubitsCaptured(partialOp1); + AssertAllFunctorsHaveNoQubitsCaptured(partialOp3); + AssertAllFunctorsHaveNoQubitsCaptured(op1); + } + { + var op2 = new GenericCallable(null, typeof(UnitaryNoOp<(int, int, Qubit)>)) as IUnitary; + var partialOp2 = op2.Partial((AbstractCallable._, AbstractCallable._, q0)); + + AssertAllFunctorsHaveQubitsCaptured(partialOp2, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op2); + AssertIDataQubits(partialOp2, q0); + } + { + var op3 = new GenericCallable(null, typeof(UnitaryNoOp<(int, Qubit, Qubit)>)) as IUnitary; + var partialOp4 = op3.Partial((AbstractCallable._, AbstractCallable._, q0)); + + AssertAllFunctorsHaveQubitsCaptured(partialOp4, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op3); + AssertIDataQubits(partialOp4, q0); + + var partialOp5 = partialOp4.Partial((AbstractCallable._, q1)); + AssertAllFunctorsHaveQubitsCaptured(partialOp5, 2); + AssertIDataQubits(partialOp5, q1, q0); + } + { + var op = new GenericCallable(null, typeof(UnitaryNoOp<(int, (Qubit, Qubit, Qubit), QArray)>)) as IUnitary; + var p1 = op.Partial((_, (_, q1, _), _)); + + AssertAllFunctorsHaveQubitsCaptured(p1, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op); + AssertIDataQubits(p1, q1); + + var p2 = p1.Partial((_, _, qArray)); + AssertAllFunctorsHaveQubitsCaptured(p2, 3); + AssertAllFunctorsHaveQubitsCaptured(p1, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op); + AssertIDataQubits(p1, q1); + AssertIDataQubits(p2, q4, q5, q1); + + var p3 = p2.Partial(new Func(q => (2, (q3, q2)))); + AssertAllFunctorsHaveQubitsCaptured(p3, 5); + AssertAllFunctorsHaveQubitsCaptured(p2, 3); + AssertAllFunctorsHaveQubitsCaptured(p1, 1); + AssertAllFunctorsHaveNoQubitsCaptured(op); + AssertIDataQubits(p1, q1); + AssertIDataQubits(p2, q4, q5, q1); + AssertIDataQubits(p3, q3, q2, q4, q5, q1); + } + } + + [Fact] + public void UdtTypesWithClosures() + { + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + + var op = new UnitaryNoOp<(TupleA,TupleD)>() as IUnitary<(TupleA, TupleD)>; + var p1 = op.Partial((AbstractCallable._, new TupleD(new QArray(q1, q0)))); + + var f0 = new TupleF(op); + var f1 = new TupleF(p1); + + AssertAllFunctorsHaveQubitsCaptured(f1.Data, 2); + AssertAllFunctorsHaveNoQubitsCaptured(f0.Data); + AssertIDataQubits(f1, q1, q0); + + var p1a = f0.Data.Partial(new Func<(long, TupleD), (TupleA, TupleD)>((arg) => (new TupleA((arg.Item1, Pauli.PauliZ, q2, (q0, 4L, q0))), arg.Item2))); + AssertAllFunctorsHaveQubitsCaptured(p1a, 3); + AssertIDataQubits(p1a, q2, q0, q0); + + var p2 = p1.Partial(new Func<(long, (Pauli, Qubit)), TupleA>((arg) => new TupleA((arg.Item1, arg.Item2.Item1, arg.Item2.Item2, (q1, 5L, q2))))); + var p2a = p1a.Partial(new Func(arg => (arg, new TupleD(new QArray(q1, q1))))); + var f2 = new TupleF(p2); + AssertAllFunctorsHaveQubitsCaptured(f2.Data, 5); + AssertIDataQubits(f2, null, q1, q2, q1, q0); + AssertAllFunctorsHaveQubitsCaptured(p2a, 5); + AssertIDataQubits(p2a, q2, q0, q0, q1, q1); + } + + [Fact] + public void QubitsFromUDTs() + { + var q0 = new FreeQubit(0); + var q1 = new FreeQubit(1); + var q2 = new FreeQubit(2); + var q3 = new FreeQubit(3); + var q4 = new FreeQubit(4); + var q5 = new FreeQubit(5); + var q6 = new FreeQubit(6); + var op = new UnitaryNoOp() as IUnitary; + + var qubits = new QArray(q2, q4, q6); + var bData = ((1L, 2L), (q1, (3L, (q2, q3)), 3.5)); + var qtuple = new QTuple<((Int64, Int64), (Qubit, (Int64, (Qubit, Qubit)), Double))>(bData) as IApplyData; + var tupleB = new TupleB(((1L, 2L), (q6, (3L, (q4, q6)), 3.5))); + var tupleA = new TupleA((1L, Pauli.PauliY, q1, (q4, 3L, q5))); + var tupleC = new TupleC((q5, tupleB)); + var tupleD = new TupleD(new QArray(q1, q2, q3, q4, q6)); + var tupleE = new TupleE((1L, new QArray(q1, q3, q4, q6))); + var tupleF = new TupleF(op); + var tupleG = new TupleG((q3, tupleF, tupleC, tupleD)); + var tupleH = new TupleH((tupleD, tupleG)); + var tupleJ = new TupleJ(new QArray<(long, Qubit)>((1L, q1), (2L, q2), (5L, q5), (3L, q3))); + var tupleU = new QTuple(null); + var q = new Q(q3); + + AssertEnumerable(new Qubit[] { q2 }, q2.Qubits); + AssertEnumerable(new Qubit[] { q1, q2, q3 }, qtuple.Qubits); + + AssertIDataQubits(q2, q2); + AssertIDataQubits(qtuple, q1, q2, q3); + AssertIDataQubits(tupleA, q1, q4, q5); + AssertIDataQubits(tupleB, q6, q4, q6); + AssertIDataQubits(tupleC, q5, q6, q4, q6); + AssertIDataQubits(tupleD, q1, q2, q3, q4, q6); + AssertIDataQubits(tupleE, q1, q3, q4, q6); + AssertIDataQubits(tupleF, null); + AssertIDataQubits(tupleG, q3, q5, q6, q4, q6, q1, q2, q3, q4, q6); + AssertIDataQubits(tupleH, q1, q2, q3, q4, q6, q3, q5, q6, q4, q6, q1, q2, q3, q4, q6); + AssertIDataQubits(tupleJ, q1, q2, q5, q3); + AssertIDataQubits(q, q3); + AssertIDataQubits(tupleU, null); + } + + private static void AssertEnumerable(IEnumerable e, IEnumerable a) + { + if (e == null) + { + Assert.Null(a); + } + else + { + var expected = e.ToArray(); + var actual = a.ToArray(); + + Assert.Equal(expected.Length, actual.Length); + for (int i = 0; i < expected.Length; i++) + { + Assert.Equal(expected[i], actual[i]); + } + } + } + + private static void AssertIDataQubits(IApplyData d, params Qubit[] expected) + { + AssertEnumerable(expected, d.Qubits); + } + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs b/src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs new file mode 100644 index 00000000000..14dd8afa22a --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +using Microsoft.Quantum.Simulation.Core; + +using NativeOperations; + +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class NativeOperationTests + { + [Fact] + public void NativeIntrinsicOperation() + { + OperationsTestHelper.RunWithMultipleSimulators((sim) => + { + var actual = IntrinsicBody.Run(sim).Result; + Assert.Equal(IntrinsicBody.RESULT, actual); + }); + } + + [Fact] + public void NativeOperationWithSimulatorSpecificEmulation() + { + void TestOne(IOperationFactory sim, string expected) + { + var actual = DefaultBody.Run(sim).Result; + Assert.Equal(expected, actual); + + if (sim is IDisposable dis) dis.Dispose(); + } + + TestOne(new QuantumSimulator(), "Simulator"); + } + + [Fact] + public void NativeIntrinsicGenericOperation() + { + OperationsTestHelper.RunWithMultipleSimulators((sim) => + { + var actual = IntrinsicBodyGeneric.Run(sim, "hello").Result; + Assert.Equal(IntrinsicBody.RESULT, actual); + + actual = IntrinsicBodyGeneric.Run(sim, 1234).Result; + Assert.Equal("1234", actual); + }); + } + + + [Fact] + public void NativeGenericOperation() + { + OperationsTestHelper.RunWithMultipleSimulators((sim) => + { + var actual1 = DefaultBodyGeneric.Run(sim, "hello").Result; + Assert.Equal(IntrinsicBody.RESULT, actual1); + + var actual2 = DefaultBodyGeneric.Run(sim, 1234).Result; + Assert.Equal(1234, actual2); + }); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs new file mode 100644 index 00000000000..5be7b17b8fa --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs @@ -0,0 +1,372 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Quantum.Simulation.Common; +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Simulators.Exceptions; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; + +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class Log + { + public Dictionary _log = new Dictionary(); + + public string Key(OperationFunctor functor, T tag) => $"{functor}:{tag}"; + + public int GetNumberOfCalls(OperationFunctor functor, T tag) + { + var key = Key(functor, tag); + + if (_log.ContainsKey(key)) + { + return _log[key]; + } + else + { + return 0; + } + } + + public QVoid Record(OperationFunctor functor, T tag) + { + var key = Key(functor, tag); + + if (_log.ContainsKey(key)) + { + _log[key] = _log[key] + 1; + } + else + { + _log[key] = 1; + } + + return QVoid.Instance; + } + } + + public class StartTracker + { + private List _log = new List(); + + private class Key + { + public ICallable callable; + public IApplyData data; + public Type dataType; + } + + public StartTracker(SimulatorBase s) + { + s.OnOperationStart += this.OnStart; + } + + public bool EqualData(object expected, object actual) + { + if (expected == null) return actual == null; + + var value = PartialMapper.CastTuple(expected.GetType(), actual); + return expected.Equals(value); + } + + + public int GetNumberOfCalls(string name) => _log.Where(r => r.callable.FullName == name).Count(); + + public int GetNumberOfCalls(string name, OperationFunctor variant) => _log.Where(r => r.callable.FullName == name && r.callable.Variant == variant).Count(); + + public int GetNumberOfCalls(string name, OperationFunctor variant, object data) => _log.Where(r =>r.callable.FullName == name && r.callable.Variant == variant && EqualData(data, r.data.Value)).Count(); + + private void OnStart(ICallable arg1, IApplyData arg2) + { + _log.Add(new Key { callable = arg1, data = arg2, dataType = arg2?.GetType() }); + } + } + + static class OperationsTestHelper + { + public static TraceImpl GetTracer(this SimulatorBase s) + { + return s.Get(typeof(Tests.Circuits.Generics.Trace<>)).FindCallable(typeof(T), typeof(QVoid)) as TraceImpl; + } + + + public class TracerImpl : Tests.Circuits.ClosedType.Trace + { + public TracerImpl(IOperationFactory m) : base(m) + { + this.Log = new Log(); + } + + public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); + public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); + public override Func<(IQArray, string), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); + public override Func<(IQArray, string), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); + + public Log Log { get; } + } + + public class TraceImpl : Tests.Circuits.Generics.Trace + { + public TraceImpl(IOperationFactory m) : base(m) + { + this.Log = new Log(); + } + + public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); + public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); + public override Func<(IQArray, T), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); + public override Func<(IQArray, T), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); + + public int GetNumberOfCalls(OperationFunctor functor, T tag) => this.Log.GetNumberOfCalls(functor, tag); + + public Log Log { get; } + } + + private static void InitSimulator(SimulatorBase sim) + { + sim.InitBuiltinOperations(typeof(OperationsTestHelper)); + sim.Register(typeof(Tests.Circuits.Generics.Trace<>), typeof(TraceImpl<>), typeof(IUnitary)); + } + + public static void RunWithMultipleSimulators(Action test) + { + var simulators = new SimulatorBase[] { new QuantumSimulator() }; + + foreach (var s in simulators) + { + InitSimulator(s); + + test(s); + + if (s is IDisposable sim) + { + sim.Dispose(); + } + } + } + + /// + /// A shell for simple Apply tests. + /// + internal static void applyTestShell(SimulatorBase sim, ICallable operation, Action test) + { + var allocate = sim.Get(); + var release = sim.Get(); + + var qbits = allocate.Apply(1); + + var q = qbits[0]; + operation.Apply(q); // this is ok. + + test(q); + + operation.Apply(q); // still ok. + release.Apply(qbits); + } + + + /// + /// Verifies general conditions that may cause errors on the Controlled method. + /// + internal static void ctrlErrorConditionsTests(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled) + { + ctrlOnReleasedQubitTest(sim, operationControlled); + + ctrlOnReleasedCtrlQubitTest(sim, operationControlled); + } + + /// + /// A shell for simple Controlled tests. It calls the controlled operation with 0..4 control qubits + /// set to all possible combination of 1 & 0. + /// + internal static void ctrlTestShell(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled, Action, Qubit> test) + { + var allocate = sim.Get(); + var release = sim.Get(); + var set = sim.Get(); + + // Number of control bits to use + for (int n = 0; n < 4; n++) + { + IQArray qbits = allocate.Apply(1); + IQArray ctrls = allocate.Apply(n); + + Qubit q = qbits[0]; + operationControlled((ctrls, q)); // this is ok. + + // Iterate through all possible combinations of ctrl values: + for (int i = 0; i < (1 << n); i++) + { + // set control bits to match i: + for (int j = 0; j < n; j++) + { + var value = (i & (1 << j)) == 0 + ? Result.Zero + : Result.One; + + set.Apply((value, ctrls[j])); + } + + // controlled is enabled only when all ctrls are 1 (e.g. last one): + bool enabled = (i == ((1 << n) - 1)); + test(enabled, ctrls, q); + } + + operationControlled((ctrls, q)); // still ok. + release.Apply(qbits); + release.Apply(ctrls); + + sim.CheckNoQubitLeak(); + } + } + + /// + /// Verifies that calling Controlled on a released qubit throws an Exception + /// + internal static void ctrlOnReleasedQubitTest(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled) + { + ctrlTestShell(sim, operationControlled, (enabled, ctrls, q) => + { + Intrinsic.Allocate allocate = sim.Get(); + Intrinsic.Release release = sim.Get(); + + IQArray qbits = allocate.Apply(1); + Qubit qfake = qbits[0]; + release.Apply(qbits); + + Assert.Throws("q1", () => + { + operationControlled((ctrls, qfake)); + }); + + }); + } + + /// + /// Verifies that calling Controlled using released qubits as control throws an Exception + /// + internal static void ctrlOnReleasedCtrlQubitTest(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled) + { + var random = new System.Random(); + + ctrlTestShell(sim, operationControlled, (enabled, ctrlQs, q) => + { + if (ctrlQs == null || ctrlQs.Length == 0) + { + return; + } + var ctrls = new QArray(ctrlQs); + + // Pass in a random released qubit + int index = random.Next((int)ctrls.Length); + Qubit released = ctrls[index]; + + Intrinsic.Allocate allocate = sim.Get(); + Intrinsic.Release release = sim.Get(); + + IQArray qbits = allocate.Apply(1); + Qubit qfake = qbits[0]; + release.Apply(qbits); + ctrls.Modify(index, qfake); + + Assert.Throws($"ctrls[{index}]", () => + { + operationControlled((ctrls, q)); + }); + + // Put real qubit back in place of released: + ctrls.Modify(index, released); + }); + } + + internal static void CheckNoQubitLeak(this SimulatorBase sim) + { + Assert.True(sim.QubitManager.GetAllocatedQubitsCount() == 0); + } + + /// + /// Verifies that multiple situations where over-allocating might happen throw an Exception. + /// + internal static void overAllocationTest(uint n, Func> allocate, Action> release) + { + // Allocating more than available + try + { + allocate(n + 1); + } + catch (NotEnoughQubits e) + { + Assert.Equal((int)n, e.Available); + Assert.Equal(n + 1, e.Requested); + } + + // Allocating max, then trying to allocate one more: + var qubits = allocate(n); + Assert.Throws(() => + { + allocate(1); + }); + release(qubits); + + // Allocating and releasing should be fine, + // then allocate one max (ok), and finally allocating one more: + qubits = allocate(n); + release(qubits); + + var qubits2 = allocate(1); + release(qubits2); + + qubits = allocate(n); + Assert.Throws(() => + { + allocate(1); + }); + release(qubits); + + + // Allocating max, release one in the middle. + // then re-allocate to max (ok), and finally allocating one more: + qubits = allocate(n); + release(new QArray(qubits[1])); + + qubits = new QArray(qubits.Where(q => q.Id != 1)); // Remove released qubit from qubits: + qubits2 = allocate(1); + + Assert.Throws(() => + { + allocate(1); + }); + release(qubits); + release(qubits2); + } + + public static Action AsAction(this Func gate) + { + return (q) => + { + gate.Invoke(q); + }; + } + + public static void IgnoreDebugAssert(this Action action) + { + IgnorableAssert.Disable(); + try + { + action.Invoke(); + } + finally + { + IgnorableAssert.Enable(); + } + } + + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs b/src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs new file mode 100644 index 00000000000..f945357366d --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs @@ -0,0 +1,175 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Microsoft.Quantum.Simulation.Core; +using Xunit; +using System.Linq; +using System.Collections.Generic; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + using TestTuple = ValueTuple)), Qubit>; + + public class PartialMapperTests + { + private class NoOp : Unitary, ICallable + { + public NoOp(IOperationFactory m) : base(m) { } + + string ICallable.FullName => "NoOp"; + + public override Func Body => (a) => QVoid.Instance; + + public override void Init() { } + } + + private void TestOneTupleNoSubstitution(I original, params object[] expected) + { + var emptyQueue = new Stack(); + var content = PartialMapper.GetTupleValues(original); + var tuple = PartialMapper.Combine(content, emptyQueue); + Assert.Equal(content, tuple); + } + + [Fact] + public void TupleNoSubstitutions() // substitutes nothing + { + Qubit qubit = null; + QArray qubits = new QArray(); + IUnitary op = new NoOp(null); + + TestOneTupleNoSubstitution(QVoid.Instance); + TestOneTupleNoSubstitution(1L, 1L); + TestOneTupleNoSubstitution(qubit, qubit); + TestOneTupleNoSubstitution(qubits, qubits); + TestOneTupleNoSubstitution((1L, 2.0), 1L, 2.0); + TestOneTupleNoSubstitution((1L, 2.0, Result.Zero), 1L, 2.0, Result.Zero); + TestOneTupleNoSubstitution(((1L, 2.0), Result.Zero), 1L, 2.0, Result.Zero); + TestOneTupleNoSubstitution(((1L, 2.0), (Result.Zero, qubit, qubits)), 1L, 2.0, Result.Zero, qubit, qubits); + TestOneTupleNoSubstitution(((op, 4L, (1L, 2.0)), (Result.Zero, (op, qubits, qubit))), op, 4L, 1L, 2.0, Result.Zero, op, qubits, qubit); + } + + private void TestOneMapping(I expected, A args, object values) + { + var partial = PartialMapper.Create(values); + var actual = partial(args); + Assert.Equal(expected, actual); + } + + [Fact] + public void PartialMapping() + { + Qubit qubit = null; + QArray qubits = new QArray(); + NoOp op = new NoOp(null); + + var _ = AbstractCallable._; + + TestOneMapping(1, 1, _); + TestOneMapping(op, op, _); + TestOneMapping(qubit, qubit, _); + TestOneMapping(QVoid.Instance, QVoid.Instance, _); + TestOneMapping(1, QVoid.Instance, 1); + TestOneMapping((1, op), op, (1, _)); + TestOneMapping((qubit, op), qubit, (_, op)); + TestOneMapping((qubit, op), (qubit, op), (_, _)); + TestOneMapping((qubit, op), (qubit, op), _); + TestOneMapping((Result.One, 2.0, 3, qubit, op), (3, op), (Result.One, 2.0, _, qubit, _)); + + var expected = (Result.One, (1, 2.0), (3, (op, qubits)), qubit); + TestOneMapping(expected, QVoid.Instance, (Result.One, (1, 2.0), (3, (op, qubits)), qubit)); + TestOneMapping(expected, Result.One, (_, (1, 2.0), (3, (op, qubits)), qubit)); + TestOneMapping(expected, (Result.One, (1, 2.0)), (_, _, (3, (op, qubits)), qubit)); + TestOneMapping(expected, (Result.One, (3, (op, qubits))), (_, (1, 2.0), _, qubit)); + TestOneMapping(expected, (Result.One, qubit), (_, (1, 2.0), (3, (op, qubits)), _)); + TestOneMapping(expected, qubit, (Result.One, (1, 2.0), (3, (op, qubits)), _)); + TestOneMapping(expected, (1, 2.0), (Result.One, _, (3, (op, qubits)), qubit)); + TestOneMapping(expected, ((1, 2.0), qubit), (Result.One, _, (3, (op, qubits)), _)); + TestOneMapping(expected, (3, (op, qubits)), (Result.One, (1, 2.0), _, qubit)); + TestOneMapping(expected, ((1, 2.0), (3, (op, qubits))), (Result.One, _, _, qubit)); + TestOneMapping(expected, 2.0, (Result.One, (1, _), (3, (op, qubits)), qubit)); + TestOneMapping(expected, (Result.One, 2.0, op), (_, (1, _), (3, (_, qubits)), qubit)); + TestOneMapping(expected, ((1, 2.0), (3, qubits)), (Result.One, _, (_, (op, _)), qubit)); + TestOneMapping(expected, expected, (_, _, _, _)); + TestOneMapping((expected, expected), expected, (expected, _)); + TestOneMapping((1, 2, (3, 4)), (2, 4), (1, _, (3, _))); + TestOneMapping((1, (2.1,2.2), (3, 4)), ((2.1,2.2), 4), (1, _, (3, _))); + TestOneMapping((1, (2.1, 2.2), (3, (4.1,4.2))), ((2.1, 2.2), (4.1,4.2)), (1, _, (3, _))); + } + + private void TestOnePartialType(Type expected, Type original, object partial) + { + var actual = Operation.FindPartialType(original, partial); + Assert.Equal(expected, actual); + } + + [Fact] + public void FindPartialType() + { + Qubit qubit = new TestQubit(); + QArray qubits = new QArray(); + IUnitary op = new NoOp(null); + + var _ = AbstractCallable._; + + TestOnePartialType(typeof(QVoid), typeof(long), 1L); + TestOnePartialType(typeof(long), typeof(long), _); + TestOnePartialType(typeof(IUnitary), typeof(IUnitary), _); + TestOnePartialType(typeof(Qubit), typeof(TestQubit), _); + TestOnePartialType(typeof(QVoid), typeof(QVoid), _); + + TestOnePartialType(typeof(IUnitary), (1, op).GetType(), (1, _)); + TestOnePartialType(typeof(Qubit), (qubit, op).GetType(), (_, op)); + + TestOnePartialType(typeof(ValueTuple), (qubit, op).GetType(), (_, _)); + TestOnePartialType(typeof(IUnitary), (qubit, op).GetType(), (qubit, _)); + TestOnePartialType(typeof(Qubit), (qubit, 1L, op).GetType(), (_, 1L, op)); + TestOnePartialType(typeof(ValueTuple), (Result.One, 2.0, 3L, qubit, op).GetType(), (Result.One, 2.0, _, qubit, _)); + + var original = (Result.One, (1L, 2.0), (3L, (op, qubits))); + TestOnePartialType(typeof(QVoid), original.GetType(), (Result.One, (1L, 2.0), (3L, (op, qubits)))); + TestOnePartialType(typeof(Result), original.GetType(), (_, (1L, 2.0), (3L, (op, qubits)))); + TestOnePartialType(typeof(ValueTuple), original.GetType(), (_, (_, 2.0), (_, (op, qubits)))); + TestOnePartialType(typeof(ValueTuple), original.GetType(), (Result.One, _, (3L, (op, qubits)))); + TestOnePartialType(typeof(ValueTuple), original.GetType(), (Result.One, (_, _), (3L, (op, qubits)))); + TestOnePartialType(typeof(ValueTuple>), original.GetType(), (Result.One, (1L, 2.0), (_, (op, _)))); + TestOnePartialType(typeof(ValueTuple>), original.GetType(), (_, (1L, 2.0), (_, (_, qubits)))); + } + + private void TestOneMappingError(A args, object values) where E : Exception + { + var partial = PartialMapper.Create(values); + Assert.Throws(() => partial(args)); + } + + [Fact] + public void PartialMappingErrors() + { + Qubit qubit = null; + QArray qubits = new QArray(); + NoOp op = new NoOp(null); + + var _ = AbstractCallable._; + var expected = (Result.One, (1, 2.0), (3, (op, qubits)), qubit); + + OperationsTestHelper.IgnoreDebugAssert(() => + { + // If too many parameters, are ignored: + TestOneMapping(expected, Result.One, (Result.One, (1, 2.0), (3, (op, qubits)), qubit)); + + // Parameters mismatch + TestOneMappingError((2.0, 3.0), (Result.One, _, (3, (op, qubits)), qubit)); + TestOneMappingError(1, (_, (1, 2.0), (3, (op, qubits)), qubit)); + TestOneMappingError(1, (Result.One, _, (3, (op, qubits)), qubit)); + //TestOneMapping((1, 2, (3, 4)), (2, 4), (1, new MissingParameter(typeof((int,int))), (3, _))); + + // Too little parameters + TestOneMappingError(Result.One, (_, _, (3, (op, qubits)), qubit)); + + // Both, parameters mismatch and too little parameters + TestOneMappingError(1, (_, _, (3, (op, qubits)), qubit)); + }); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs b/src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs new file mode 100644 index 00000000000..e62a5c102e6 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +using Microsoft.Quantum.Simulation.Core; + +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class PrimitivesExtensionsTests + { + [Fact] + void AllExtensionsAreImplementedTest() + { + TestExtension("Core"); + TestExtension("Math"); + TestExtension("Convert"); + TestExtension("Bitwise"); + } + + private static void TestExtension(string extensionName) + { + Assembly assembly = Assembly.Load("Microsoft.Quantum.QSharp.Core"); + string extensionsNameSpace = "Microsoft.Quantum." + extensionName; + + IEnumerable abstractTypes = + from opType in assembly.DefinedTypes + where opType.Namespace == extensionsNameSpace + where typeof(AbstractCallable).IsAssignableFrom(opType) + where !opType.IsNested + select opType; + + foreach (Type one in abstractTypes) + { + var t = one.IsGenericType + ? one.MakeGenericType(Enumerable.Repeat(typeof(string), one.GetGenericArguments().Length).ToArray()) + : one; + if (t.IsAbstract) + { + Assert.True(t.GetNativeImplementation() != null, $"{one.Name} missing Native implementation."); + } + } + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QArrayTests.cs b/src/Simulation/Simulators.Type2.Tests/QArrayTests.cs new file mode 100644 index 00000000000..4be981b34a1 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QArrayTests.cs @@ -0,0 +1,315 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Diagnostics; +using Microsoft.Quantum.Simulation.Core; +using Newtonsoft.Json; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class QArrayTests + { + [Fact] + public void CreateArrayWithDefaults() + { + var actual = new QArray(new Qubit[0]); + Assert.Empty(actual); + + actual = new QArray(new Qubit[1]); + Assert.Single(actual); + Assert.Null(actual[0]); + + actual = new QArray(new Qubit[5]); + Assert.Equal(5, actual.Length); + Assert.Null(actual[0]); + Assert.Null(actual[1]); + Assert.Null(actual[2]); + Assert.Null(actual[3]); + Assert.Null(actual[4]); + + var longs = new QArray(new long[0]); + Assert.Empty(longs); + + longs = new QArray(new long[3]); + Assert.Equal(3, longs.Length); + Assert.Equal(0, longs[0]); + Assert.Equal(0, longs[1]); + Assert.Equal(0, longs[2]); + + var ops = new QArray(new ICallable[2]); + Assert.Equal(2, ops.Length); + Assert.Null(ops[0]); + Assert.Null(ops[1]); + } + + private void Wrapper(long count) + { + var array = new QArray(new T[count]); + Assert.Equal(count, array.Length); + } + + [Fact] + public void CreateArrayWithGenerics() + { + Wrapper(3); + Wrapper(4); + } + + [Fact] + public void ArraysByIndex() + { + var longs = new QArray (2, 1, 0); + Assert.NotEmpty(longs); + Assert.Equal(3, longs.Length); + Assert.Equal(2, longs[0]); + Assert.Equal(1, longs[1]); + Assert.Equal(0, longs[2]); + + longs = new QArray(new long[5]); + longs.Modify(0, 5); + longs.Modify(2, 3); + longs.Modify(4, 1); + Assert.Equal(5, longs.Length); + Assert.Equal(5, longs[0]); + Assert.Equal(0, longs[1]); + Assert.Equal(3, longs[2]); + Assert.Equal(0, longs[3]); + Assert.Equal(1, longs[4]); + + OperationsTestHelper.IgnoreDebugAssert(() => + { + // Make sure we can call it with a long index: + Assert.Throws(() => longs[-1]); + Assert.Throws(() => longs[int.MaxValue]); + Assert.Throws(() => longs[(long)int.MaxValue + 1]); + }); + } + + [Fact] + public void JoinArrays() + { + var arr1 = new QArray(); + var arr2 = new QArray(); + var expected = new QArray(); + var actual = QArray.Add(arr1, arr2); + Assert.Equal(expected, actual); + + arr1 = new QArray(1); + arr2 = new QArray(); + expected = new QArray(1); + actual = QArray.Add(arr1, arr2); + Assert.Equal(expected, actual); + + arr1 = new QArray(); + arr2 = new QArray(1); + expected = new QArray(1); + actual = QArray.Add(arr1, arr2); + Assert.Equal(expected, actual); + + arr1 = new QArray(1, 2, 3); + arr2 = new QArray(1, 4, 5, 3, 6); + expected = new QArray(1, 2, 3, 1, 4, 5, 3, 6); + actual = QArray.Add(arr1, arr2); + Assert.Equal(expected, actual); + + OperationsTestHelper.IgnoreDebugAssert(() => + { + arr1 = null; + arr2 = new QArray(1, 4, 5, 3, 6); + expected = new QArray(1, 4, 5, 3, 6); + actual = QArray.Add(arr1, arr2); + Assert.Equal(expected, actual); + + arr1 = new QArray(1, 2, 3); + arr2 = null; + expected = new QArray(1, 2, 3); + actual = QArray.Add(arr1, arr2); + Assert.Equal(expected, actual); + + arr1 = null; + arr2 = null; + expected = null; + actual = QArray.Add(arr1, arr2); + Assert.Equal(expected, actual); + }); + } + + [Fact] + public void SliceArray() + { + var source = new QArray(0); + var range = new QRange(0, 0); + var expected = new QArray(0); + var actual = source.Slice(range); + Assert.Equal(expected, actual); + + source = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + range = new QRange(0, 2, 10); + expected = new QArray(0, 2, 4, 6, 8, 10); + actual = source.Slice(range); + Assert.Equal(expected, actual); + + + source = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + expected = new QArray(1, 6); + actual = source.Slice(new QRange(1, 5, 10)); + Assert.Equal(expected, actual); + + OperationsTestHelper.IgnoreDebugAssert(() => + { + source = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + range = null; + expected = new QArray(); + actual = source.Slice(range); + Assert.Equal(expected, actual); + }); + } + + [Fact] + public void ArraySharing() + { + // Basic copy-on-write + var array1 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + var array2 = new QArray(array1); + Assert.Equal(2, array1[2]); + Assert.Equal(2, array2[2]); + array1.Modify(2, 12); + Assert.Equal(12, array1[2]); + Assert.Equal(2, array2[2]); + array2.Modify(2, 22); + Assert.Equal(12, array1[2]); + Assert.Equal(22, array2[2]); + + // Arrays of arrays + array1 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + array2 = new QArray(array1); + var arrayArray1 = new QArray>(array1, array2); // in generated C# code, QArray> is used + var arrayArray2 = new QArray>(arrayArray1); + Assert.Equal(2, arrayArray1[0][2]); + Assert.Equal(2, arrayArray1[1][2]); + arrayArray1.Modify(0, arrayArray1[0].Modify(2, 12)); + Assert.Equal(12, arrayArray1[0][2]); + Assert.Equal(2, arrayArray1[1][2]); + Assert.Equal(12, array1[2]); + arrayArray1.Modify(1, arrayArray1[1].Modify(2, 22)); + Assert.Equal(12, arrayArray1[0][2]); + Assert.Equal(22, arrayArray1[1][2]); + Assert.Equal(12, array1[2]); + Assert.Equal(22, array2[2]); + + // Copy-on-write with slices + var r = new QRange(1, 2, 10); + var array3 = array2.Slice(r); + var expected = new QArray(1, 3, 5, 7, 9); + Assert.Equal(expected, array3); + array3.Modify(0, 11); + Assert.Equal(1, array2[1]); + Assert.Equal(11, array3[0]); + + // Mixing slicing and joining + array2 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + var expected2 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + r = new QRange(1, 2, 10); + array3 = array2.Slice(r); + var array4 = new QArray(11, 13); + var array5 = QArray.Add(array3, array4); + var expected3 = new QArray(1, 3, 5, 7, 9); + var expected4 = new QArray(11, 13); + var expected5 = new QArray(1, 3, 5, 7, 9, 11, 13); + Assert.Equal(expected2, array2); + Assert.Equal(expected3, array3); + Assert.Equal(expected4, array4); + Assert.Equal(expected5, array5); + + // Self-joining + array1 = new QArray(0, 1, 2); + array2 = new QArray(QArray.Add(array1, array1)); + var expected1 = new QArray(0, 1, 2); + expected2 = new QArray(0, 1, 2, 0, 1, 2); + Assert.Equal(expected1, array1); + Assert.Equal(expected2, array2); + array1.Modify(0, 10); + Assert.Equal(10, array1[0]); + Assert.Equal(0, array2[0]); + } + + [Fact] + public void ArrayEnumeration() + { + // Basic enumeration + var array1 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); + int index = 0; + foreach (var n in array1) + { + Assert.Equal(index, n); + index++; + } + Assert.Equal(10, index); + + // Enumerating a slice + var r = new QRange(1, 2, 10); + var array2 = array1.Slice(r); + index = 1; + foreach (var n in array2) + { + Assert.Equal(index, n); + index += 2; + } + Assert.Equal(11, index); + + // Enumerating a join + var array3 = QArray.Add(array1, array2); + index = 0; + foreach (var n in array3) + { + if (index < 10) + { + Assert.Equal(index, n); + } + else + { + Assert.Equal(2 * index - 19, n); + } + index++; + } + Assert.Equal(15, index); + } + + [Fact] + public void CastArrays() + { + // Basic enumeration + var array1 = new QArray(1L, 2L, 3L); + var array2 = new QArray(array1); + + Assert.Equal(array1.Length, array2.Length); + Assert.Equal((long)array1[0], array2[0]); + Assert.Equal((long)array1[2], array2[2]); + } + + [Fact] + public void IQArraySerialization() + { + // Basic enumeration + var array1 = new QArray(1L, 2L, 3L) as IQArray; + var json = JsonConvert.SerializeObject(array1); + Assert.Equal("[1,2,3]", json); + + var array2 = JsonConvert.DeserializeObject>(json); + var array3 = JsonConvert.DeserializeObject>(json); + Assert.Equal(array1, array2); + Assert.Equal(array1, array3); + + // Results enumeration + var array_result = new QArray(Result.One, Result.Zero, Result.Zero) as IQArray; + json = JsonConvert.SerializeObject(array_result); + Assert.Equal("[1,0,0]", json); + + var array_from_json = JsonConvert.DeserializeObject>(json); + Assert.Equal(array_result, array_from_json); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QTupleTests.cs b/src/Simulation/Simulators.Type2.Tests/QTupleTests.cs new file mode 100644 index 00000000000..0f5501b8a3b --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QTupleTests.cs @@ -0,0 +1,207 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using System; +using System.Linq; +using Xunit; +using Microsoft.Quantum.Tests.Tuples; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class QTupleTests + { + [Fact] + public void TupleEmptyConstructor() + { + var NullOrEmptyQubits = new Action((t) => + { + var qubits = t.Qubits; + Assert.True(qubits == null || qubits?.Where(q => q != null).Count() == 0); + }); + + { + var actual = new Q(); + Assert.Null(((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new I(); + Assert.Equal(0L, ((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleA(); + Assert.Equal(default((Int64, Pauli, Qubit, (Qubit, Int64, Qubit))), ((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleC(); + Assert.Equal(default((Qubit, TupleB)), ((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleD(); + Assert.Empty(((IApplyData)actual).Value as IQArray); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleE(); + Assert.Equal(default((Int64, IQArray)), ((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleF(); + Assert.Null(((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleH(); + Assert.Equal(default((TupleD, TupleG)), ((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleI(); + Assert.Null(((IApplyData)actual).Value); + NullOrEmptyQubits(actual); + } + { + var actual = new TupleJ(); + Assert.Empty(((IApplyData)actual).Value as IQArray<(Int64,Qubit)>); + NullOrEmptyQubits(actual); + } + } + + [Fact] + public void TupleBasicConstructor() + { + var AssertQubitsCount = new Action((count, t) => + { + var qubits = t.Qubits; + if (count == 0) + { + Assert.True(qubits == null || qubits?.Where(q => q != null).Count() == 0); + } else + { + Assert.Equal(count, qubits?.Where(q => q != null).Count()); + } + }); + + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + + { + var actual = new Q(q0); + Assert.Equal(q0, ((IApplyData)actual).Value); + AssertQubitsCount(1, actual); + } + { + var actual = new I(32L); + Assert.Equal(32L, ((IApplyData)actual).Value); + AssertQubitsCount(0, actual); + } + { + var data = (2L, Pauli.PauliY, q1, (q0, -7L, null as Qubit)); + var actual = new TupleA(data); + Assert.Equal(data, ((IApplyData)actual).Value); + AssertQubitsCount(2, actual); + } + { + var data = (q1, new TupleB(((2L, 3L), (q1, (4L, (q0, q2)), 3.0)))); + var actual = new TupleC(data); + Assert.Equal(data, ((IApplyData)actual).Value); + AssertQubitsCount(4, actual); + } + { + var data = new QArray(q1, q2, q0, q0, q1); + var actual = new TupleD(data); + Assert.Equal((IQArray)data, ((IApplyData)actual).Value); + AssertQubitsCount(5, actual); + } + { + var data = (5L, new QArray(q1, q2, q0)); + var actual = new TupleE(data); + Assert.Equal((data.Item1, (IQArray)data.Item2), ((IApplyData)actual).Value); + AssertQubitsCount(3, actual); + } + { + var data = new UnitaryNoOp<(TupleA, TupleD)>(); + var actual = new TupleF(data); + Assert.Equal(data, ((IApplyData)actual).Value); + AssertQubitsCount(0, actual); + } + { + var op= new UnitaryNoOp<(TupleA, TupleD)>(); + var mapper = new Func<(TupleA, TupleD), (IQArray, (TupleA, TupleD))>((_arg) => (new QArray(q1, q2), _arg)); + var data = op.Controlled.Partial(mapper); + var actual = new TupleF(data); + Assert.Equal(data, ((IApplyData)actual).Value); + AssertQubitsCount(2, actual); + } + { + var data = (new TupleD(new QArray(q1, q2, q0)), new TupleG()); + var actual = new TupleH(data); + Assert.Equal(data, ((IApplyData)actual).Value); + AssertQubitsCount(3, actual); + } + { + var data = new QArray<(Int64, Qubit)>((1L, q1)); + var actual = new TupleJ(data); + Assert.Equal((IQArray<(Int64, Qubit)>)data, ((IApplyData)actual).Value); + AssertQubitsCount(1, actual); + } + } + + private static void AssertOneData (T expected, Type tupleType) + { + var d = Activator.CreateInstance(tupleType, expected) as IApplyData; + + Assert.NotNull(d); + Assert.Equal(expected, d.Value); + if (d is QTuple tuple) + { + Assert.Equal(expected, tuple.Data); + } + } + + [Fact] + public void UdtData() + { + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + var q3 = new FreeQubit(3) as Qubit; + var q4 = new FreeQubit(4) as Qubit; + var q5 = new FreeQubit(5) as Qubit; + var q6 = new FreeQubit(6) as Qubit; + var op = new Op1(null) as IUnitary; + var f1 = new F1(null); + var qubits = new QArray(q2, q4, q6); + + var dataA = (1L, Pauli.PauliY, q1, (q4, 3L, q5)); + var dataB = ((1L, 2L), (q6, (3L, (q4, q6)), 3.5)); + var dataC = (q5, new TupleB(dataB)); + var dataD = new QArray(q1, q2, q3, q4, q6); + var dataE = (4L, (IQArray)qubits); + var dataF = op; + var dataG = (q3, new TupleF(dataF), new TupleC(dataC), new TupleD(dataD)); + var dataQ = ((1L, 2L), (q1, (3L, (q2, q3)), 3.5)); + var dataH = (new TupleD(dataD), new TupleG(dataG)); + var dataI = f1; + + AssertOneData(dataQ, typeof(QTuple<((Int64, Int64), (Qubit, (Int64, (Qubit, Qubit)), Double))>)); + AssertOneData(((ICallable)null), typeof(QTuple)); + AssertOneData(q3, typeof(Q)); + AssertOneData(dataA, typeof(TupleA)); + AssertOneData(dataB, typeof(TupleB)); + AssertOneData(dataC, typeof(TupleC)); + AssertOneData(dataD, typeof(TupleD)); + AssertOneData(dataE, typeof(TupleE)); + AssertOneData(dataF, typeof(TupleF)); + AssertOneData(dataG, typeof(TupleG)); + AssertOneData(dataH, typeof(TupleH)); + AssertOneData(dataI, typeof(TupleI)); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs new file mode 100644 index 00000000000..092106269f0 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs @@ -0,0 +1,388 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Simulators.Exceptions; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public partial class QuantumSimulatorTests + { + [Fact] + public void QSimConstructor() + { + using (var subject = new QuantumSimulator()) + { + Assert.Equal("Quantum Simulator", subject.Name); + } + } + + [Fact] + public void QSimVerifyPrimitivesCompleteness() + { + using (var sim = new QuantumSimulator()) + { + var ops = + from op in typeof(Intrinsic.X).Assembly.GetExportedTypes() + where op.IsSubclassOf(typeof(AbstractCallable)) + where !op.IsNested + select op; + + var missing = new List(); + + foreach (var op in ops) + { + try + { + var i = sim.GetInstance(op); + Assert.NotNull(i); + } + catch (Exception) + { + missing.Add(op); + } + } + + Assert.Empty(missing); + } + } + + [Fact] + public void QSimX() + { + using (var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) + { + var x = sim.Get(); + var measure = sim.Get(); + var set = sim.Get(); + + var ctrlX = x.ControlledBody.AsAction(); + OperationsTestHelper.ctrlTestShell(sim, ctrlX, (enabled, ctrls, q) => + { + set.Apply((Result.Zero, q)); + var result = measure.Apply(q); + var expected = Result.Zero; + Assert.Equal(expected, result); + + x.ControlledBody((ctrls, q)); + result = measure.Apply(q); + expected = (enabled) ? Result.One : Result.Zero; + Assert.Equal(expected, result); + }); + } + } + + [Fact] + public void QSimMultithreading() + { + var count = 5; + var tasks = new Task[count]; + + for (int i = 0; i < count; i++) + { + tasks[i] = Task.Run(() => + { + QSimVerifyX(); + QSimVerifyY(); + QSimVerifyZ(); + QSimVerifyExp(); + }); + } + + Task.WaitAll(tasks); + } + + + [Fact] + public void QSimRandom() + { + using (var sim = new QuantumSimulator()) + { + var r = sim.Get(); + var probs = new QArray (0.0, 0.0, 0.0, 0.7, 0.0, 0.0); + var result = r.Apply(probs); + Assert.Equal(3, result); + } + } + + [Fact] + public void QSimAssert() + { + using (var sim = new QuantumSimulator()) + { + var assert = sim.Get(); + var h = sim.Get(); + + Func, IQArray, Result, string)> mapper = + (q) => (new QArray(Pauli.PauliZ), new QArray (q), Result.Zero, "Assert failed"); + var applyWithZero = new OperationPartial, IQArray, Result, string), QVoid>(assert, mapper); + + OperationsTestHelper.applyTestShell(sim, applyWithZero, (q) => + { + h.Apply(q); + assert.Apply((new QArray(Pauli.PauliX), new QArray (q), Result.Zero, "Assert failed")); + + OperationsTestHelper.IgnoreDebugAssert(() => + { + Assert.Throws(() => assert.Apply((new QArray (Pauli.PauliX), new QArray (q), Result.One, "Assert failed"))); + + h.Apply(q); + Assert.Throws(() => assert.Apply((new QArray (Pauli.PauliZ), new QArray (q), Result.One, "Assert failed"))); + }); + + assert.Apply((new QArray (Pauli.PauliZ), new QArray(q), Result.Zero, "Assert failed")); + }); + } + } + + + [Fact] + public void QSimAssertProb() + { + using (var sim = new QuantumSimulator()) + { + var tolerance = 0.02; + var assertProb = sim.Get(); + var h = sim.Get(); + var allocate = sim.Get(); + var release = sim.Get(); + + Func, IQArray, Result, double, string, double)> mapper = (q) => + { + return (new QArray(Pauli.PauliZ), new QArray(q), Result.Zero, 1.0, "Assert failed", tolerance); + }; + var applyWithZero = new OperationPartial, IQArray, Result, double, string, double), QVoid>(assertProb, mapper); + + OperationsTestHelper.applyTestShell(sim, applyWithZero, (q1) => + { + assertProb.Apply((new QArray (Pauli.PauliZ), new QArray(q1), Result.One, 0.01, "Assert failed", tolerance)); + + // Within tolerance + assertProb.Apply((new QArray (Pauli.PauliX), new QArray (q1), Result.Zero, 0.51, "Assert failed", tolerance)); + assertProb.Apply((new QArray (Pauli.PauliX), new QArray (q1), Result.One, 0.51, "Assert failed", tolerance)); + // Outside of tolerance + OperationsTestHelper.IgnoreDebugAssert(() => + { + Assert.Throws(() => assertProb.Apply((new QArray(Pauli.PauliX), new QArray(q1), Result.One, 0.51, "Assert failed", 0.0))); + Assert.Throws(() => assertProb.Apply((new QArray(Pauli.PauliX), new QArray(q1), Result.Zero, 0.51, "Assert failed", 0.0))); + }); + + // Add a qubit + var qubits = allocate.Apply(1); + var q2 = qubits[0]; + + assertProb.Apply((new QArray (Pauli.PauliZ), new QArray (q1), Result.Zero, 0.99, "Assert failed", tolerance)); + assertProb.Apply((new QArray (Pauli.PauliZ), new QArray (q1), Result.One, 0.01, "Assert failed", tolerance)); + assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.Zero, 0.99, "Assert failed", tolerance)); + assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.One, 0.01, "Assert failed", tolerance)); + + assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliX), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", tolerance)); + assertProb.Apply((new QArray (Pauli.PauliX, Pauli.PauliZ), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", tolerance)); + assertProb.Apply((new QArray (Pauli.PauliX, Pauli.PauliX), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", tolerance)); + + OperationsTestHelper.IgnoreDebugAssert(() => + { + // Outside of tolerance + Assert.Throws(() => assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", 0.0))); + Assert.Throws(() => assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.One, 0.51, "Assert failed", 0.0))); + + // Missmatch number of arrays + Assert.Throws(() => assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1), Result.Zero, 0.51, "Assert failed", tolerance))); + }); + + release.Apply(qubits); + }); + } + } + + private static void TestCallable(ICallable gate, Qubit target) + { + gate.Apply(target); + Assert.Throws(() => gate.Apply(null)); + } + + private static void TestControllable(IControllable gate, IQArray ctrls, Qubit target) + { + var nullTarget = new Func, Qubit)>(q => (ctrls, q)); + var nullCtrl = new Func, Qubit)>(q => (new QArray(q, ctrls[1], ctrls[2]), target)); + + var dupeTarget = new QArray(target, ctrls[1], ctrls[2]); + var dupeCtrls1 = new QArray(ctrls[1], ctrls[1], ctrls[2]); + var dupeCtrls2 = new QArray(ctrls[0], ctrls[1], ctrls[0]); + + TestCallable(gate, target); + TestCallable(gate.Controlled.Partial(nullTarget), target); + TestCallable(gate.Controlled.Partial(nullCtrl), ctrls[0]); + + Assert.Throws(() => gate.Controlled.Apply((dupeTarget, target))); + Assert.Throws(() => gate.Controlled.Apply((dupeCtrls1, target))); + Assert.Throws(() => gate.Controlled.Apply((dupeCtrls2, target))); + } + + private static void TestUnitary(IUnitary gate, IQArray ctrls, IQArray target) + { + TestCallable(gate, target[0]); + TestCallable(gate.Adjoint, target[0]); + TestControllable(gate, ctrls, target[0]); + TestControllable(gate.Adjoint, ctrls, target[0]); + } + + private static void TestMultiCallable(ICallable, O> gate, IQArray targets) + { + var mapper = new Func>(q => new QArray(q, targets[1], targets[2])); + var dupTargets = new QArray(targets[0], targets[1], targets[0]); + + Assert.Throws(() => gate.Apply(null)); + Assert.Throws(() => gate.Apply(dupTargets)); + TestCallable(gate.Partial(mapper), targets[0]); + } + + private static void TestMultiControllable(IControllable> gate, IQArray ctrls, IQArray targets) + { + var mapper = new Func>(q => new QArray(q, targets[1], targets[2])); + + TestControllable(gate.Partial(mapper), ctrls, targets[0]); + } + + private static void TestMultiUnitary(IUnitary> gate, IQArray ctrls, IQArray targets) + { + TestMultiCallable(gate, targets); + TestMultiCallable(gate.Adjoint, targets); + TestMultiControllable(gate, ctrls, targets); + TestMultiControllable(gate.Adjoint, ctrls, targets); + } + + private void TestOne(QuantumSimulator qsim, T gate, Action, IQArray> action) + { + var allocate = qsim.Get(); + var release = qsim.Get(); + + var targets = allocate.Apply(3); + var ctrls = allocate.Apply(3); + + try + { + action(gate, ctrls, targets); + } + finally + { + release.Apply(ctrls); + release.Apply(targets); + } + } + + [Fact] + public void TestSimpleGateCheckQubits() + { + using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) + { + + // Single Qubit gates: + { + var gateTypes = new Type[] + { + typeof(Intrinsic.H), + typeof(Intrinsic.S), + typeof(Intrinsic.T), + typeof(Intrinsic.X), + typeof(Intrinsic.Y), + typeof(Intrinsic.Z) + }; + + foreach (var t in gateTypes) + { + var gate = qsim.Get>(t); + TestOne(qsim, gate, TestUnitary); + } + } + } + } + + [Fact] + public void TestRCheckQubits() + { + using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) + { + // R + var mapper = new Func(qubit => (Pauli.PauliZ, 1.0, qubit)); + var gate = qsim.Get(); + var p = gate.Partial(mapper); + TestOne(qsim, p, TestUnitary); + } + } + + [Fact] + public void TestExpCheckQubits() + { + using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) + { + // Exp + { + var mapper = new Func, (IQArray, Double, IQArray)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), 1.0, qubits)); + var gate = qsim.Get(); + var p = gate.Partial(mapper); + TestOne(qsim, p, TestMultiUnitary); + } + + // ExpFrac + { + var mapper = new Func, (IQArray, long, long, IQArray)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), 1, 2, qubits)); + var gate = qsim.Get(); + var p = gate.Partial(mapper); + TestOne(qsim, p, TestMultiUnitary); + } + } + } + + + [Fact] + public void TestMeasureCheckQubits() + { + using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) + { + // M + { + var gate = qsim.Get(); + TestOne(qsim, gate, (g, ctrls, t) => TestCallable(g, t[0])); + } + + // Measure + { + var gate = qsim.Get(); + var mapper = new Func, (IQArray, IQArray)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), qubits)); + var p = gate.Partial(mapper); + TestOne(qsim, p, (g, ctrls, t) => TestMultiCallable(p, t)); + } + } + } + + [Fact] + public void TestAssertCheckQubits() + { + using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) + { + // Assert + { + var gate = qsim.Get(); + var mapper = new Func, (IQArray, IQArray, Result, String)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), qubits, Result.Zero, "")); + var p = gate.Partial(mapper); + TestOne(qsim, gate, (g, ctrls, t) => TestMultiCallable(p, t)); + } + + // AssertProb + { + var gate = qsim.Get(); + var mapper = new Func, (IQArray, IQArray, Result, Double, String, Double)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), qubits, Result.Zero, 1.000, "", 0.002)); + var p = gate.Partial(mapper); + TestOne(qsim, p, (g, ctrls, t) => TestMultiCallable(p, t)); + } + } + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs new file mode 100644 index 00000000000..c5852fb1556 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Quantum.Intrinsic; +using Microsoft.Quantum.Simulation.Core; +using Xunit; +using Microsoft.Quantum.Simulation.XUnit; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public partial class QuantumSimulatorTests + { + [OperationDriver(TestCasePrefix ="QSim", TestNamespace = "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits")] + public void QSimTestTarget( TestOperation op ) + { + using (var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: true)) + { + op.TestOperationRunner(sim); + } + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs new file mode 100644 index 00000000000..a267a719274 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Simulators.Exceptions; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public partial class QuantumSimulatorTests + { + //test to check that qubit cannot be released if it is not in zero state + [Fact] + public async Task ZeroStateQubitReleaseTest() + { + var sim = new QuantumSimulator(); + + await Assert.ThrowsAsync(() => UsingQubitCheck.Run(sim)); + } + + //test to check that qubit can be released if measured + [Fact] + public async Task MeasuredQubitReleaseTest() + { + var sim = new QuantumSimulator(); + + //should not throw an exception, as Measured qubits are allowed to be released, and the release aspect is handled in the C++ code + await ReleaseMeasuredQubitCheck.Run(sim); + } + + //test to check that qubit that is released and reallocated is in state |0> + [Fact] + public async Task ReallocateQubitInGroundStateTest() + { + var sim = new QuantumSimulator(); + var allocate = sim.Get(); + var release = sim.Get(); + var q1 = allocate.Apply(1); + var q1Id = q1[0].Id; + var gate = sim.Get(); + var measure = sim.Get(); + gate.Apply(q1[0]); + var result1 = measure.Apply(q1[0]); + //Check X operation + Assert.Equal(result1, Result.One); + release.Apply(q1[0]); + var q2 = allocate.Apply(1); + var q2Id = q2[0].Id; + //Assert reallocated qubit has the same id as the one released + Assert.Equal(q1Id, q2Id); + var result2 = measure.Apply(q2[0]); + //Assert reallocated qubit has is initialized in state |0> + Assert.Equal(result2, Result.Zero); + + + + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs new file mode 100644 index 00000000000..0cc32328fdf --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs @@ -0,0 +1,468 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading.Tasks; +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; +using Xunit; + +using static System.Math; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class State + { + public State((double, double) alpha, (double, double) beta) + { + Alpha = new Microsoft.Quantum.Math.Complex(alpha); + Beta = new Microsoft.Quantum.Math.Complex(beta); + } + + public Microsoft.Quantum.Math.Complex Alpha { get; } + + public Microsoft.Quantum.Math.Complex Beta { get; } + + public (Microsoft.Quantum.Math.Complex, Microsoft.Quantum.Math.Complex) Value => (Alpha, Beta); + + + } + + public partial class QuantumSimulatorTests + { + public const int seed = 19740212; + public static System.Random r = new System.Random(seed); + + public static double sqrt1_2 = Sqrt(1.0 / 2.0); + + public static (double, double) E_i(double angle) + { + return (Cos(angle), Sin(angle)); + } + + public static (double, double) times(double d, (double, double) c) + { + var (r, i) = c; + return ((d * r, d * i)); + } + + public static double Angle(int nom, int powerDen) + { + return (PI * nom / (1 << powerDen)); + } + + /// + /// It runs the circuit to verify that the given one-qubit unitary gate performs + /// the right operation. For it, it receives an array of the expected states that the + /// Qubit must be in if starting from: + /// |0>, |1>, |+>, |-> + /// accordingly. + /// + private static void VerifyGate(IOperationFactory sim, IUnitary gate, State[] expected) + { + OperationsTestHelper.IgnoreDebugAssert(() => + { + var starts = new ValueTuple[] { + (Pauli.PauliZ, Result.Zero), + (Pauli.PauliZ, Result.One), + (Pauli.PauliX, Result.Zero), + (Pauli.PauliX, Result.One) + }; + + for (int i = 0; i < expected.Length; i++) + { + VerifyUnitary.Run(sim, gate, starts[i], expected[i].Value).Wait(); + } + }); + } + + private static void VerifyInvalidAngles(IOperationFactory sim, IUnitary<(double, Qubit)> gate) + { + OperationsTestHelper.IgnoreDebugAssert(() => + { + var q = sim.Get(typeof(Intrinsic.Allocate)).Apply(1); + + Assert.Throws(() => gate.Apply((Double.NaN, q[0]))); + Assert.Throws(() => gate.Apply((Double.PositiveInfinity, q[0]))); + Assert.Throws(() => gate.Apply((Double.NegativeInfinity, q[0]))); + }); + } + + [Fact] + public void QSimVerifyH() + { + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get(); + VerifyGate(sim, gate, new State[] + { + new State((sqrt1_2, 0.0), (sqrt1_2, .0)), + new State((sqrt1_2, 0.0), (-1 * sqrt1_2, .0)), + new State((1.0, 0.0), (0.0, 0.0)), + new State((0.0, 0.0), (1.0, 0.0)), + }); + } + } + + [Fact] + public void QSimVerifyX() + { + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get(); + + VerifyGate(sim, gate, new State[] + { + new State((0.0, 0.0), (1.0, 0.0)), + new State((1.0, 0.0), (0.0, 0.0)), + new State((sqrt1_2, 0.0), (sqrt1_2, 0.0)), + new State((-sqrt1_2, 0.0), (sqrt1_2, 0.0)) + }); + } + } + + [Fact] + public void QSimVerifyY() + { + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get(); + + VerifyGate(sim, gate, new State[] + { + new State((0.0, 0.0), (0.0, 1.0)), + new State((0.0, -1.0), (0.0, 0.0)), + new State((0.0, -sqrt1_2), (0.0, sqrt1_2)), + new State((0.0, sqrt1_2), (0.0, sqrt1_2)), + }); + } + } + + [Fact] + public void QSimVerifyZ() + { + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get(); + + VerifyGate(sim, gate, new State[] + { + new State((1.0, 0.0), (0.0, 0.0)), + new State((0.0, 0.0), (-1.0, 0.0)), + new State((sqrt1_2, 0.0), (-sqrt1_2, 0.0)), + new State((sqrt1_2, 0.0), (sqrt1_2, 0.0)) + }); + } + } + + [Fact] + public void QSimVerifyS() + { + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get(); + + VerifyGate(sim, gate, new State[] + { + new State((1.0, 0.0), (0.0, 0.0)), + new State((0.0, 0.0), (0.0, 1.0)), + new State((sqrt1_2, 0.0), (0.0, sqrt1_2)), + new State((sqrt1_2, 0.0), (0.0, -sqrt1_2)) + }); + } + } + + [Fact] + public void QSimVerifyT() + { + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get(); + + VerifyGate(sim, gate, new State[] + { + new State((1.0, 0.0), (0.0, 0.0)), + new State((0.0, 0.0), E_i(PI / 4)), + new State((sqrt1_2, 0.0), times(sqrt1_2, E_i(PI / 4))), + new State((sqrt1_2, 0.0), times(-sqrt1_2, E_i(PI / 4))) + }); + } + } + + [Fact] + public void QSimVerifyR1() + { + using (var sim = new QuantumSimulator()) + { + var angle = PI * r.NextDouble(); + Func mapper = (q) => (angle, q); + + var gate = sim.Get().Partial(mapper); + + VerifyGate(sim, gate, new State[] + { + new State((1.0, 0.0), (0.0, 0.0)), + new State((0.0, 0.0), E_i(angle)), + new State((sqrt1_2, 0.0), times(sqrt1_2, E_i(angle))), + new State((sqrt1_2, 0.0), times(-sqrt1_2, E_i(angle))) + }); + } + } + + /// + /// Returns the expected states when applying a rotation with the given angle + /// to the Qubit starting from |0>,|1>,|+>,|-> accordingly + /// + public static State[] ExponentExpectedStates(Pauli basis, double angle) + { + switch (basis) + { + case Pauli.PauliX: + return new State[] + { + new State((Cos(angle), 0.0), (0.0, Sin(angle))), + new State((0.0, Sin(angle)), (Cos(angle), 0.0)), + new State((sqrt1_2 * Cos(angle), sqrt1_2 * Sin(angle)), (sqrt1_2 * Cos(angle), sqrt1_2 * Sin(angle))), + new State((sqrt1_2 * Cos(angle), -sqrt1_2 * Sin(angle)), (-sqrt1_2 * Cos(angle), sqrt1_2 * Sin(angle))), + }; + case Pauli.PauliY: + return new State[] + { + new State((Cos(angle), 0.0), (-Sin(angle), 0.0)), + new State((Sin(angle), 0.0), (Cos(angle), 0.0)), + new State((sqrt1_2 * (Cos(angle) + Sin(angle)), 0.0), (sqrt1_2 * (Cos(angle) - Sin(angle)), 0.0)), + new State((sqrt1_2 * (Cos(angle) - Sin(angle)), 0.0), (sqrt1_2 * (-Cos(angle) - Sin(angle)), 0.0)) + }; + case Pauli.PauliZ: + return new State[] + { + new State(E_i(angle), (0.0, 0.0)), + new State((0.0, 0.0), E_i(-angle)), + new State(times(sqrt1_2, E_i(angle)), times(sqrt1_2, E_i(-angle))), + new State(times(sqrt1_2, E_i(angle)), times(-sqrt1_2, E_i(-angle))) + }; + case Pauli.PauliI: + return new State[] + { + new State(E_i(angle), (0.0, 0.0)), + new State((0.0, 0.0), E_i(angle)), + new State(times(sqrt1_2, E_i(angle)), times(sqrt1_2, E_i(angle))), + new State(times(sqrt1_2, E_i(angle)), times(-sqrt1_2, E_i(angle))), + }; + default: + throw new InvalidOperationException(); + } + } + + public static State[] ExponentExpectedStates(Pauli basis, int nom, int powerDen) + { + return ExponentExpectedStates(basis, Angle(nom, powerDen)); + } + + public static State[] RExpectedStates(Pauli basis, double angle) + { + return ExponentExpectedStates(basis, (-angle / 2)); + } + + public static State[] RExpectedStates(Pauli basis, int nom, int powerDen) + { + return ExponentExpectedStates(basis, Angle(nom, powerDen)); + } + + [Fact] + public void QSimVerifyRx() + { + var angle = 2 * PI * r.NextDouble(); + Func mapper = (q) + => (angle, q); + + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get().Partial(mapper); + VerifyGate(sim, gate, RExpectedStates(Pauli.PauliX, angle)); + + VerifyInvalidAngles(sim, sim.Get()); + } + } + + [Fact] + public void QSimVerifyRy() + { + var angle = 2 * PI * r.NextDouble(); + Func mapper = (q) + => (angle, q); + + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get().Partial(mapper); + VerifyGate(sim, gate, RExpectedStates(Pauli.PauliY, angle)); + + VerifyInvalidAngles(sim, sim.Get()); + } + } + + [Fact] + public void QSimVerifyRz() + { + var angle = 2 * PI * r.NextDouble(); + Func mapper = (q) + => (angle, q); + + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get().Partial(mapper); + VerifyGate(sim, gate, RExpectedStates(Pauli.PauliZ, angle)); + + VerifyInvalidAngles(sim, sim.Get()); + } + } + + [Fact] + public void QSimVerifyR() + { + var angle = 2 * PI * r.NextDouble(); + Func mapper = (q) + => (Pauli.PauliI, angle, q); + Func<(double, Qubit), (Pauli, double, Qubit)> needsAngle = (__arg) + => (Pauli.PauliI, __arg.Item1, __arg.Item2); + + using (var sim = new QuantumSimulator()) + { + var gate = sim.Get().Partial(mapper); + VerifyGate(sim, gate, RExpectedStates(Pauli.PauliI, angle)); + + var angleGate = sim.Get().Partial(needsAngle); + VerifyInvalidAngles(sim, angleGate); + } + } + + [Fact] + public void QSimVerifyRFrac() + { + using (var sim = new QuantumSimulator()) + { + var allBases = new[] { Pauli.PauliI, Pauli.PauliX, Pauli.PauliZ, Pauli.PauliY }; + + for (var k = 0; k < 4; k++) + { + for (var n = 0; n < 3; n++) + { + foreach (var p in allBases) + { + Func mapper = (q) => (p, k, n, q); + var gate = sim.Get().Partial(mapper); + + VerifyGate(sim, gate, RExpectedStates(p, k, n)); + } + } + } + } + } + + private void VerifyExp(Pauli pauli) + { + using (var sim = new QuantumSimulator()) + { + var angle = 2 * PI * r.NextDouble(); + + Func, double, IQArray)> mapper = (q) + => (new QArray (pauli), angle, new QArray (q)); + var gate = sim.Get().Partial(mapper); + + VerifyGate(sim, gate, ExponentExpectedStates(pauli, angle)); + + Func<(double, Qubit), (IQArray, double, IQArray)> needsAngle = (__arg) + => (new QArray (pauli), __arg.Item1, new QArray (__arg.Item2)); + var angleGate = sim.Get().Partial(needsAngle); + + VerifyInvalidAngles(sim, angleGate); + } + } + + [Fact] + public void QSimVerifyExp() + { + VerifyExp(Pauli.PauliI); + } + + [Fact] + public void QSimVerifyExpY() + { + VerifyExp(Pauli.PauliY); + } + + [Fact] + public void QSimVerifyExpZ() + { + VerifyExp(Pauli.PauliZ); + } + + [Fact] + public void QSimVerifyExpX() + { + VerifyExp(Pauli.PauliX); + } + + [Fact] + public void QSimVerifyExpFrac() + { + using (var sim = new QuantumSimulator()) + { + var allBases = new[] { Pauli.PauliI, Pauli.PauliX, Pauli.PauliZ, Pauli.PauliY }; + + for (var k = 0; k < 4; k++) + { + for (var n = 0; n < 3; n++) + { + foreach (var p in allBases) + { + Func, long, long, IQArray)> mapper = (q) + => (new QArray (p), k, n, new QArray (q)); + var gate = sim.Get().Partial(mapper); + + VerifyGate(sim, gate, ExponentExpectedStates(p, k, n)); + } + } + } + } + } + + [Fact] + public void QSimMeasure() + { + using (var sim = new QuantumSimulator()) + { + var op = sim.Get, JointMeasureTest>(); + op.Apply(QVoid.Instance); + } + } + + [Fact] + public void QSimM() + { + using (var sim = new QuantumSimulator()) + { + var m = sim.Get(); + + var allocate = sim.Get(); + var release = sim.Get(); + var x = sim.Get(); + + var qbits = allocate.Apply(1); + Assert.Single(qbits); + + var q = qbits[0]; + var result = m.Apply(q); + Assert.Equal(Result.Zero, result); + + x.Apply(q); + result = m.Apply(q); + Assert.Equal(Result.One, result); + x.Apply(q); + + release.Apply(qbits); + sim.CheckNoQubitLeak(); + } + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs new file mode 100644 index 00000000000..03864b46fd6 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.XUnit; +using System; +using Xunit; +using Xunit.Abstractions; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class QuantumTestSuite + { + private readonly ITestOutputHelper output; + + public QuantumTestSuite(ITestOutputHelper output) + { + this.output = output; + } + + [OperationDriver(TestCasePrefix = "QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite")] + public void QSimTestTarget(TestOperation op) + { + using (var sim = new QuantumSimulator( throwOnReleasingQubitsNotInZeroState: true )) + { + sim.OnLog += (msg) => { output.WriteLine(msg); }; + op.TestOperationRunner(sim); + } + } + + //[OperationDriver(TestCasePrefix = "QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite.VeryLong")] + private void QSimTestTargetVeryLong(TestOperation op) + { + using (var sim = new QuantumSimulator( throwOnReleasingQubitsNotInZeroState: true )) + { + sim.OnLog += (msg) => { output.WriteLine(msg); }; + op.TestOperationRunner(sim); + } + } + + //[OperationDriver(TestCasePrefix = "⊗ Fail QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite", Suffix = "QSimFail")] + [OperationDriver(TestCasePrefix = "⊗ Fail QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite", Suffix = "QSimFail", Skip = "These tests are known to fail" )] + public void QSimTestTargetFailures(TestOperation op) + { + using (var sim = new QuantumSimulator( throwOnReleasingQubitsNotInZeroState: true )) + { + sim.OnLog += (msg) => { output.WriteLine(msg); }; + Action action = () => op.TestOperationRunner(sim); + bool hasThrown = false; + try + { + action.IgnoreDebugAssert(); + } + catch (ExecutionFailException) + { + hasThrown = true; + } + Assert.True(hasThrown, "The operation was known to throw. It does not throw anymore. Congratulations ! You fixed the bug."); + } + } + } + + public class QuantumTestSuiteSelf + { + private readonly ITestOutputHelper output; + public QuantumTestSuiteSelf(ITestOutputHelper output) + { + this.output = output; + } + + [OperationDriver(TestCasePrefix = "QuantumTestSuite:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite.SelfTests")] + public void QuantumTestSuiteSelfTests(TestOperation op) + { + var sim = new TrivialSimulator(); //these tests do not do anything quantum + sim.OnLog += (msg) => { output.WriteLine(msg); }; + op.TestOperationRunner(sim); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs new file mode 100644 index 00000000000..f34826ba202 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Intrinsic; + + + /// + /// Test helper to be used with AssertOperationsEqualInPlace and AssertOperationsEqualReferenced + /// if one needs to check that the operation is identity + /// + operation IdentityTestHelper (q : Qubit[]) : Unit { + + body (...) { + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation OnFirstQubit (op : (Qubit => Unit), qubits : Qubit[]) : Unit { + + op(qubits[0]); + } + + + operation OnFirstQubitA (op : (Qubit => Unit : Adjoint), qubits : Qubit[]) : Unit { + + body (...) { + op(qubits[0]); + } + + adjoint invert; + } + + + operation OnFirstQubitAC (op : (Qubit => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { + + body (...) { + op(qubits[0]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation OnSecondQubitAC (op : (Qubit => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { + + body (...) { + op(qubits[1]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation OnFirstTwoQubitsAC (op : ((Qubit, Qubit) => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { + + body (...) { + op(qubits[0], qubits[1]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation OnFirstThreeQubitsAC (op : ((Qubit, Qubit, Qubit) => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { + + body (...) { + op(qubits[0], qubits[1], qubits[2]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation OnOneQubit (op : (Qubit[] => Unit), qubit : Qubit) : Unit { + + op([qubit]); + } + + + operation OnOneQubitA (op : (Qubit[] => Unit : Adjoint), qubit : Qubit) : Unit { + + body (...) { + op([qubit]); + } + + adjoint invert; + } + + + operation OnOneQubitAC (op : (Qubit[] => Unit : Adjoint, Controlled), qubit : Qubit) : Unit { + + body (...) { + op([qubit]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs new file mode 100644 index 00000000000..e65cd2e0342 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Intrinsic; + + + operation AssertProbAndCliffordOneQubitTest () : Unit { + + let totalQubits = MaxQubitsToAllocateForOneQubitTests(); + + using (qs = Qubit[totalQubits]) { + + for (i in 0 .. totalQubits - 1) { + let targetQubits = [qs[i]]; + AssertProbAndPaulies(targetQubits); + AssertProbAndS(Zero, targetQubits); + AssertProbAndS(One, targetQubits); + + if (IsStabilizerSimulator()) { + AssertProbAndH(Zero, targetQubits); + AssertProbAndH(One, targetQubits); + } + } + } + } + + + operation AssertProbAndPaulies (qs : Qubit[]) : Unit { + + Assert([PauliZ], qs, Zero, $"Newly allocated qubits are always zero"); + X(qs[0]); + Assert([PauliZ], qs, One, $""); + X(qs[0]); + Assert([PauliZ], qs, Zero, $""); + Y(qs[0]); + Assert([PauliZ], qs, One, $""); + Y(qs[0]); + } + + + operation AssertProbAndH (intial : Result, qs : Qubit[]) : Unit { + + + if (intial == One) { + X(qs[0]); + } + + Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); + H(qs[0]); + Assert([PauliX], qs, intial, $""); + AssertProb([PauliZ], qs, Zero, 0.5, $"", Accuracy()); + AssertProb([PauliY], qs, Zero, 0.5, $"", Accuracy()); + AssertProb([PauliZ], qs, One, 0.5, $"", Accuracy()); + AssertProb([PauliY], qs, One, 0.5, $"", Accuracy()); + H(qs[0]); + Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); + + if (intial == One) { + X(qs[0]); + } + } + + + operation AssertProbAndS (intial : Result, qs : Qubit[]) : Unit { + + + if (intial == One) { + X(qs[0]); + } + + Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); + S(qs[0]); + Assert([PauliZ], qs, intial, $""); + S(qs[0]); + Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); + + if (intial == One) { + X(qs[0]); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs new file mode 100644 index 00000000000..4add7409900 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Intrinsic; + + + operation AssertProbAndMeasureOneQubitTest () : Unit { + + let totalQubits = MaxQubitsToAllocateForOneQubitTests(); + + using (qs = Qubit[totalQubits]) { + + for (i in 0 .. totalQubits - 1) { + let q = qs[i]; + + if (IsStabilizerSimulator()) { + MeasureAndCorrect(PauliX, 0.5, q); + MeasureAndCorrect(PauliY, 0.5, q); + MeasureAndCorrect(PauliZ, 0.5, q); + } + } + } + } + + + operation ApplyNonCommutingPauli (pauli : Pauli, qubit : Qubit) : Unit { + + + if (pauli == PauliI) { + fail $"Every pauli commutes with Identity"; + } + elif (pauli == PauliX) { + Z(qubit); + } + elif (pauli == PauliY) { + X(qubit); + } + //PauliZ + else { + Y(qubit); + } + } + + + operation MeasureAndCorrect (observable : Pauli, probability : Double, qubit : Qubit) : Unit { + + AssertProb([observable], [qubit], Zero, probability, $"", 1E-10); + let res = Measure([observable], [qubit]); + Assert([observable], [qubit], res, $""); + + if (res == One) { + ApplyNonCommutingPauli(observable, qubit); + } + + Assert([observable], [qubit], Zero, $""); + ApplyNonCommutingPauli(observable, qubit); + Assert([observable], [qubit], One, $""); + ApplyNonCommutingPauli(observable, qubit); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs new file mode 100644 index 00000000000..61619fdc008 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Simulation.TestSuite.Math; + + + internal operation flipToBasis (basis : Int[], qubits : Qubit[]) : Unit is Adj + Ctl { + if (Length(qubits) != Length(basis)) + { + fail $"qubits and stateIds must have the same length"; + } + + for (i in 0 .. Length(qubits) - 1) + { + let id = basis[i]; + let qubit = qubits[i]; + + if (id < 0 or id > 3) { + fail $"Invalid basis. Must be between 0 and 3, it was {basis}"; + } + + if (id == 0) + { + I(qubit); + } + elif (id == 1) + { + X(qubit); + } + elif (id == 2) + { + H(qubit); + } + else + { + H(qubit); + S(qubit); + } + } + } + + operation AssertProbMultiQubitTest () : Unit { + + + for (numberOfQubits in 1 .. 2) { + AssertProbMultiQubitCheck(numberOfQubits); + } + } + + + operation AssertProbMultiQubitCheck (numberOfQubits : Int) : Unit { + + Message($"Testing on {numberOfQubits} qubits"); + IterateThroughCartesianPower(numberOfQubits, NumberOfPaulies(), AssertProbMultiQubitCheckPerObservable); + } + + + operation AssertProbMultiQubitCheckPerObservable (observable : Int[]) : Unit { + + let obs = PauliById(observable); + let checkOperation = AssertProbForStateAndObservable(obs, _); + + //this would check only computational basis + mutable statesToCheck = NumberOfComputationalBasisTestStates(); + + if (IsStabilizerSimulator()) { + + //this would check full basis with |0⟩,|1⟩,|+⟩,|i⟩ + set statesToCheck = NumberOfTestStates(); + } + + IterateThroughCartesianPower(Length(observable), statesToCheck, checkOperation); + } + + + operation AssertProbForStateAndObservable (observable : Pauli[], stateId : Int[]) : Unit { + + let l = Length(observable); + + if (l != Length(stateId)) { + fail $"arrays observable and stateId must have the same length"; + } + + using (qubits = Qubit[l]) { + flipToBasis(stateId, qubits); + let expectedZeroProbability = 0.5 + 0.5 * ExpectedValueForMultiPauliByStateId(observable, stateId); + let expectedOneProbability = 1.0 - expectedZeroProbability; + AssertMeasurementProbability(observable, qubits, Zero, expectedZeroProbability, $"", Accuracy()); + AssertMeasurementProbability(observable, qubits, One, expectedOneProbability, $"", Accuracy()); + Adjoint flipToBasis(stateId, qubits); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs new file mode 100644 index 00000000000..2aed00babe1 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Intrinsic; + + + operation AssertProbOneQubitTest () : Unit { + + + for (i in 1 .. MaxQubitsToAllocateForOneQubitTests()) { + CheckAllocatedQubitsAreInZeroState(i); + CheckZeroStateObservablesValues(i); + } + } + + + operation CheckAllocatedQubitsAreInZeroState (count : Int) : Unit { + + + using (qs = Qubit[count]) { + + for (i in 0 .. count - 1) { + AssertProb([PauliZ], [qs[i]], Zero, 1.0, $"Newly allocated qubits must be in |0⟩ state", Accuracy()); + Assert([PauliZ], [qs[i]], Zero, $"Newly allocated qubits must be in |0⟩ state"); + } + } + } + + + operation CheckZeroStateObservablesValues (count : Int) : Unit { + + + using (qs = Qubit[count]) { + + for (i in 0 .. count - 1) { + AssertProb([PauliX], [qs[i]], Zero, 0.5, $"Measuring I+X for zero state must have probability 0.5", Accuracy()); + AssertProb([PauliX], [qs[i]], One, 0.5, $"Measuring I-X for zero state must have probability 0.5", Accuracy()); + AssertProb([PauliY], [qs[i]], Zero, 0.5, $"Measuring I+Y for zero state must have probability 0.5", Accuracy()); + AssertProb([PauliY], [qs[i]], One, 0.5, $"Measuring I-Y for zero state must have probability 0.5", Accuracy()); + } + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs new file mode 100644 index 00000000000..642003c7f61 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Diagnostics; + + + operation AssertQubitUnitary (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit => Unit), qubit : Qubit) : Unit { + // check only computational basis for reversible target + let maxId = IsStabilizerSimulator() ? 3 | 1; + + for (stateId in 0 .. maxId) { + let expectedState = ApplyMatrix(unitaryMatrix, StateIdToVector(stateId)); + flipToBasis([stateId], [qubit]); + unitaryOp(qubit); + let alpha = Microsoft.Quantum.Math.Complex((expectedState![0])!); + let beta = Microsoft.Quantum.Math.Complex((expectedState![1])!); + AssertQubitIsInStateWithinTolerance((alpha, beta), qubit, Accuracy()); + Reset(qubit); + } + } + + + operation AssertQubitUnitaryWithAdjoint (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit => Unit : Adjoint)) : Unit { + + if (Length(unitaryMatrix!) != 2) { + fail $"qubit unitary matrix must have two rows"; + } + + let totalQubits = MaxQubitsToAllocateForOneQubitTests(); + AssertUnitaryMatrix(unitaryMatrix); + + using (qubits = Qubit[totalQubits]) { + for (activeQubitId in 0 .. totalQubits - 1) { + let qubit = qubits[activeQubitId]; + AssertQubitUnitary(unitaryMatrix, unitaryOp, qubit); + let op = OnFirstQubitA(unitaryOp, _); + + if (IsStabilizerSimulator()) { + //this checks that the adjoint is correct + AssertOperationsEqualInPlace(1, op, op); + } else { + AssertOperationsEqualInPlaceCompBasis(1, op, op); + } + } + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs new file mode 100644 index 00000000000..9d746b1248d --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Intrinsic; + + + function PruneObservable (observable : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) { + + mutable nonIdCount = 0; + + for (i in 0 .. Length(observable) - 1) { + + if (observable[i] != PauliI) { + set nonIdCount = nonIdCount + 1; + } + } + + mutable paulies = new Pauli[nonIdCount]; + mutable qubitsPr = new Qubit[nonIdCount]; + set nonIdCount = 0; + + for (i in 0 .. Length(observable) - 1) { + + if (observable[i] != PauliI) { + set paulies w/= nonIdCount <- observable[i]; + set qubitsPr w/= nonIdCount <- qubits[i]; + set nonIdCount += 1; + } + } + + return (paulies, qubitsPr); + } + + + operation AssertStateHelper (observableId : Int[], state : Vector, qubits : Qubit[]) : Unit { + + let observable = PauliById(observableId); + let probabilityOfZero = (1.0 + PauliExpectation(observable, state)) / 2.0; + + //TODO: remove when AssertProb is fixed + let (obsPr, qubitsPr) = PruneObservable(observable, qubits); + let left = Length(qubitsPr); + + if (left > 0) { + AssertProb(obsPr, qubitsPr, Zero, probabilityOfZero, $"Wrong expectation value of an observable", Accuracy()); + } + } + + + operation AssertState (state : Vector, qubits : Qubit[]) : Unit { + + let checkOperation = AssertStateHelper(_, state, qubits); + IterateThroughCartesianPower(Length(qubits), NumberOfPaulies(), checkOperation); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs new file mode 100644 index 00000000000..e808fdb532c --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + + operation AssertUnitaryHelper (stateIds : Int[], unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit[] => Unit), qubits : Qubit[]) : Unit { + + let expectedState = ApplyMatrix(unitaryMatrix, StateById(stateIds)); + flipToBasis(stateIds, qubits); + unitaryOp(qubits); + AssertState(expectedState, qubits); + ResetAll(qubits); + } + + + operation AssertUnitary (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit[] => Unit), qubits : Qubit[]) : Unit { + + mutable bound = NumberOfComputationalBasisTestStates(); + + if (IsStabilizerSimulator()) { + set bound = NumberOfTestStates(); + //check only computational basis for reversible target + } + + let checkOperation = AssertUnitaryHelper(_, unitaryMatrix, unitaryOp, qubits); + IterateThroughCartesianPower(Length(qubits), bound, checkOperation); + } + + + operation AssertUnitaryWithAdjoint (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit[] => Unit : Adjoint), qubits : Qubit[]) : Unit { + + + if (Length(unitaryMatrix!) != 2 ^ Length(qubits)) { + fail $"number of matrix rows must be 2^Length(qubits)"; + } + + AssertUnitaryMatrix(unitaryMatrix); + AssertUnitary(unitaryMatrix, unitaryOp, qubits); + + ( + IsStabilizerSimulator() + ? AssertOperationsEqualInPlace + | AssertOperationsEqualInPlaceCompBasis + )(Length(qubits), unitaryOp, unitaryOp); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs new file mode 100644 index 00000000000..180bb724cf0 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs @@ -0,0 +1,124 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite.Math { + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + + + newtype Complex = (Double, Double); + + + function ExpIC (phi : Double) : Complex { + + return Complex(Cos(phi), Sin(phi)); + } + + + function ExpICFrac (numerator : Int, denomPower : Int) : Complex { + + let denom = 2 ^ denomPower; + let phi = IntAsDouble(numerator) / IntAsDouble(denom); + return ExpIC(phi); + } + + + function PlusC (a : Complex, b : Complex) : Complex { + + let (aRe, aIm) = a!; + let (bRe, bIm) = b!; + return Complex(aRe + bRe, aIm + bIm); + } + + + function TimesC (a : Complex, b : Complex) : Complex { + + let (aRe, aIm) = a!; + let (bRe, bIm) = b!; + return Complex(aRe * bRe - aIm * bIm, aRe * bIm + aIm * bRe); + } + + + function ConjugateC (a : Complex) : Complex { + + let (aRe, aIm) = a!; + return Complex(aRe, -aIm); + } + + + function MinusC (a : Complex) : Complex { + + let (aRe, aIm) = a!; + return Complex(-aRe, -aIm); + } + + + function DivCD (a : Complex, b : Double) : Complex { + + let (aRe, aIm) = a!; + return Complex(aRe / b, aIm / b); + } + + + function AbsSquaredC (a : Complex) : Double { + + let (aRe, aIm) = a!; + return aRe * aRe + aIm * aIm; + } + + + function AbsC (a : Complex) : Double { + + return Sqrt(AbsSquaredC(a)); + } + + + function DivCC (a : Complex, b : Complex) : Complex { + + return DivCD(TimesC(a, ConjugateC(b)), AbsSquaredC(b)); + } + + + function ZeroC () : Complex { + + + //TODO: BUG 799 fix this when the bug is resolved + return Complex(0.0, 0.0); + } + + + function OneC () : Complex { + + + //TODO: BUG 799 fix this when the bug is resolved + return Complex(1.0, 0.0); + } + + + function ComplexI () : Complex { + + + //TODO: BUG 799 fix this when the bug is resolved + return Complex(0.0, 1.0); + } + + + function ComplexIPower (power : Int) : Complex { + let powMod4 = (power % 4 + 8) % 4; + + if (powMod4 == 0) { + return Complex(1.0, 0.0); + } elif (powMod4 == 1) { + return Complex(0.0, 1.0); + } elif (powMod4 == 2) { + return Complex(-1.0, 0.0); + } elif (powMod4 == 3) { + return Complex(0.0, -1.0); + } + + fail $"this line should never be reached"; + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs new file mode 100644 index 00000000000..d3b463df31a --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + function IsReversibleSimulator () : Bool { + + return true; + } + + + function IsStabilizerSimulator () : Bool { + + return true; + } + + + function Accuracy () : Double { + + return 1E-10; + } + + + function MaxQubitsToAllocateForOneQubitTests () : Int { + + return 5; + } + + + function MaxQubitsToAllocateForTwoQubitTests () : Int { + + return 2; + } + + + function IsFullSimulator () : Bool { + + return true; + } + + + function MaxDenomiantorPowerToTest () : Int { + + return 3; + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs new file mode 100644 index 00000000000..e50bd076976 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + + operation ControlledQubitOperationTester (actual : (Qubit => Unit : Controlled, Adjoint), expected : (Qubit => Unit : Controlled, Adjoint), numberOfQubits : Int) : Unit { + + Message($"Testing operation: {actual} against {expected}"); + + if (numberOfQubits < 1) { + fail $"numberOfQubits must be at least 1"; + } + + let actualOnQubitArr = OnFirstQubitA(actual, _); + let expectedOnQubitArr = OnFirstQubitA(expected, _); + AssertOperationsEqualReferenced(1, actualOnQubitArr, expectedOnQubitArr); + AssertOperationsEqualReferenced(1, Adjoint actualOnQubitArr, Adjoint expectedOnQubitArr); + + for (totalQubits in 1 .. numberOfQubits) { + let controlsCount = totalQubits - 1; + Message($"Testing equality of controlled version with {controlsCount} control(s)"); + let actualControlled = MultiControlledQubitTestHelper(actual, controlsCount, _); + let expectedControlled = MultiControlledQubitTestHelper(expected, controlsCount, _); + AssertOperationsEqualReferenced(totalQubits, actualControlled, expectedControlled); + AssertOperationsEqualReferenced(totalQubits, Adjoint actualControlled, Adjoint expectedControlled); + } + } + + + operation ControlledOperationTester (actual : (Qubit[] => Unit : Controlled, Adjoint), expected : (Qubit[] => Unit : Controlled, Adjoint), numberOfQubits : Int, numberOfControls : Int) : Unit { + + Message($"Testing operation: {actual} against {expected}"); + + if (numberOfQubits < 1) { + fail $"numberOfQubits must be at least 1"; + } + + AssertOperationsEqualReferenced(numberOfQubits, actual, expected); + AssertOperationsEqualReferenced(numberOfQubits, Adjoint actual, Adjoint expected); + + for (controls in 0 .. numberOfControls) { + Message($"Testing equality of controlled version with {controls} control(s)"); + let actualControlled = MultiControlledTestHelper(actual, controls, numberOfQubits, _); + let expectedControlled = MultiControlledTestHelper(expected, controls, numberOfQubits, _); + AssertOperationsEqualReferenced(controls + numberOfQubits, actualControlled, expectedControlled); + AssertOperationsEqualReferenced(controls + numberOfQubits, Adjoint actualControlled, Adjoint expectedControlled); + } + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs new file mode 100644 index 00000000000..8115cbafda9 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Intrinsic; + + + operation MultiControlledQubitTestHelper (qubitOperation : (Qubit => Unit : Controlled, Adjoint), controls : Int, target : Qubit[]) : Unit { + + body (...) { + + if (Length(target) != controls + 1) { + fail $"expecting {controls}+1 qubits as input"; + } + + Controlled qubitOperation(target[1 .. controls], target[0]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation MultiControlledTestHelper (testOperation : (Qubit[] => Unit : Controlled, Adjoint), controlsCount : Int, targetCount : Int, target : Qubit[]) : Unit { + + body (...) { + + if (Length(target) != controlsCount + targetCount) { + fail $"expecting {controlsCount}+{targetCount} qubits as input"; + } + + Controlled testOperation(target[targetCount .. (targetCount + controlsCount) - 1], target[0 .. targetCount - 1]); + } + + adjoint invert; + controlled distribute; + controlled adjoint distribute; + } + + + operation MultiControlledQubitOperationsTester (controls : Int) : Unit { + + + if (controls < 0) { + fail $"number of controlls must be non-negative"; + } + + Message($"Testing with {controls} controls"); + + for (test in OneQubitTestList()) { + let shouldExecute = + IsFullSimulator() or + (IsStabilizerSimulator() and LevelOfCliffordHierarchy(test) + controls <= 1) or + (IsReversibleSimulator() and FixesComputationalBasis(test)); + + if (shouldExecute) { + let map = OperationMap(test); + + using (qubits = Qubit[controls + 1]) { + AssertUnitaryWithAdjoint(ControlledMatrix(controls, OperationMatrix(test)), MultiControlledQubitTestHelper(map, controls, _), qubits); + } + + Message($"Passed:{map}"); + } + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs new file mode 100644 index 00000000000..849e62904d7 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// note: this code is duplicared in libraries + +namespace Microsoft.Quantum.Simulation.TestSuite { + + /// + /// Iterates a variable, say arr, through cartesian product + /// [ 0, bounds[0]-1 ] × [ 0, bounds[1]-1 ] × [ 0, bounds[Length(bounds)-1]-1 ] + /// and calls op(arr) for every element of the cartesian product + /// + operation IterateThroughCartesianProduct (bounds : Int[], op : (Int[] => Unit)) : Unit { + + mutable arr = new Int[Length(bounds)]; + mutable finished = false; + + repeat { + + if (not finished) { + op(arr); + } + } + until (finished) + fixup { + + //computes the next element in the Cartesian product + set arr w/= 0 <- arr[0] + 1; + + for (i in 0 .. Length(arr) - 2) { + + if (arr[i] == bounds[i]) { + set arr w/= i + 1 <- arr[i + 1] + 1; + set arr w/= i <- 0; + } + } + + if (arr[Length(arr) - 1] == bounds[Length(arr) - 1]) { + set finished = true; + } + } + } + + + /// # Summary + /// Creates an array of given length with all elments equal to given value. + function MakeConstArray(length : Int, value : Int) : Int[] { + mutable arr = new Int[length]; + + for (i in 0 .. length - 1) { + set arr = arr w/ i <- value; + } + + return arr; + } + + /// # Summary + /// Iterates a variable, say arr, through cartesian product + /// [ 0, bound - 1 ] × [ 0, bound - 1 ] × [ 0, bound - 1 ] + /// and calls op(arr) for every element of the cartesian product + operation IterateThroughCartesianPower (power : Int, bound : Int, op : (Int[] => Unit)) : Unit { + IterateThroughCartesianProduct(MakeConstArray(power, bound), op); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs new file mode 100644 index 00000000000..937b84b7099 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + + newtype QubitOperationMatrixPair = ((Qubit => Unit), RowMajorMatrix); + + + operation CheckJointState (inputStateId : Int[], operationsToTest : QubitOperationMatrixPair[], qubits : Qubit[]) : Unit { + + let numQubits = Length(qubits); + + if (Length(inputStateId) != Length(operationsToTest)) { + fail $"Length(inputStateId) and Length(operationsToTest) must be equal"; + } + + if (Length(inputStateId) != numQubits) { + fail $"Length(inputStateId) and Length(operationsToTest) must be equal"; + } + + mutable states = new Vector[numQubits]; + flipToBasis(inputStateId, qubits); + + for (i in 0 .. numQubits - 1) { + let (op, matrix) = operationsToTest[i]!; + set states = states w/ i <- ApplyMatrix(matrix, StateIdToVector(inputStateId[i])); + op(qubits[i]); + } + + AssertState(TensorProductOfArray(states), qubits); + ResetAll(qubits); + } + + + operation JointOneQubitTester (operationsToTest : QubitOperationMatrixPair[]) : Unit { + + let totalQubits = Length(operationsToTest); + + using (qubits = Qubit[totalQubits]) { + let checkOperation = CheckJointState(_, operationsToTest, qubits); + IterateThroughCartesianPower(totalQubits, NumberOfTestStates(), checkOperation); + } + } + + + operation JointOneQubitTest () : Unit { + + + if (IsStabilizerSimulator()) { + + if (IsFullSimulator()) { + JointOneQubitTester([QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(T, TMatrix())]); + } + + JointOneQubitTester([QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(H, HMatrix())]); + JointOneQubitTester([QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(S, SMatrix())]); + } + + JointOneQubitTester([QubitOperationMatrixPair(X, PauliMatrix(PauliX)), QubitOperationMatrixPair(X, PauliMatrix(PauliX)), QubitOperationMatrixPair(X, PauliMatrix(PauliX))]); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs new file mode 100644 index 00000000000..b1f8e371137 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Simulation.TestSuite.Math; + + + operation AssertProbMultiQubit1Test () : Unit { + + AssertProbForStateAndObservable([PauliI, PauliI], [0, 1]); + } + + + operation AssertProbMultiQubit2Test () : Unit { + + AssertProbForStateAndObservable([PauliI, PauliX], [1, 2]); + } + + + operation ControlledExpWithIPauliTest () : Unit { + + let controls = 1; + let phi = 0.1; + let pauli = PauliI; + let testOp = Exp([pauli], phi, _); + let matrix = ControlledMatrix(controls, ExpPauliMatrix(pauli, phi)); + let op = OnOneQubitAC(testOp, _); + let controlledOp = MultiControlledQubitTestHelper(op, controls, _); + + using (qubits = Qubit[2]) { + AssertUnitaryWithAdjoint(matrix, controlledOp, qubits); + } + } + + + operation FracEdgeCasesQSimFail () : Unit { + + let rzPlus = RFrac(PauliZ, 1, 0xFFFFFFFFFFFFFFF, _); + let rxPlus = RFrac(PauliX, 1, 0xFFFFFFFFFFFFFFF, _); + let ryPlus = RFrac(PauliY, 1, 0xFFFFFFFFFFFFFFF, _); + let rzMinus = RFrac(PauliZ, 1, -0xFFFFFFFFFFFFFFF, _); + let rxMinus = RFrac(PauliX, 1, -0xFFFFFFFFFFFFFFF, _); + let ryMinus = RFrac(PauliY, 1, -0xFFFFFFFFFFFFFFF, _); + + using (qubits = Qubit[1]) { + AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rxPlus, _), qubits); + AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(ryPlus, _), qubits); + AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rzPlus, _), qubits); + AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rxMinus, _), qubits); + AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(ryMinus, _), qubits); + AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rzMinus, _), qubits); + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs new file mode 100644 index 00000000000..12be491807c --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs @@ -0,0 +1,331 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite.Math { + open Microsoft.Quantum.Simulation.TestSuite; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + + + newtype RowMajorMatrix = Complex[][]; + + newtype RowVector = Complex[]; + + newtype Vector = Complex[]; + + + function ZeroState () : Vector { + return Vector([OneC(), ZeroC()]); + } + + + function OneState () : Vector { + return Vector([ZeroC(), OneC()]); + } + + + function PlusState () : Vector { + return Vector([Complex(1.0 / Sqrt(2.0), 0.0), Complex(1.0 / Sqrt(2.0), 0.0)]); + } + + + function IState () : Vector { + return Vector([Complex(1.0 / Sqrt(2.0), 0.0), Complex(0.0, 1.0 / Sqrt(2.0))]); + } + + + function NumberOfTestStates () : Int { + return 4; + } + + + function NumberOfComputationalBasisTestStates () : Int { + return 2; + } + + + function NumberOfPaulies () : Int { + return 4; + } + + + function TensorProduct (vector1 : Vector, vector2 : Vector) : Vector { + let len1 = Length(vector1!); + let len2 = Length(vector2!); + + if (len1 == 0) { + fail $"The tensor product is not defined when the length of vector1 is 0"; + } + + if (len2 == 0) { + fail $"The tensor product is not defined when the length of vector2 is 0"; + } + + mutable res = new Complex[Length(vector1!) * Length(vector2!)]; + + for (i in 0 .. len1 - 1) { + + for (j in 0 .. len2 - 1) { + set res = res w/ i * len2 + j <- TimesC(vector1![i], vector2![j]); + } + } + + return Vector(res); + } + + + function StateIdToVector (id : Int) : Vector { + let stateMaps = [ZeroState, OneState, PlusState, IState]; + return stateMaps[id](); + } + + + function StateById (stateId : Int[]) : Vector { + + + if (Length(stateId) == 0) { + fail $"Length of stateId must be at least 1"; + } + + mutable res = StateIdToVector(stateId[0]); + + for (i in 1 .. Length(stateId) - 1) { + set res = TensorProduct(StateIdToVector(stateId[i]), res); + } + + return res; + } + + + function TensorProductOfArray (states : Vector[]) : Vector { + + + if (Length(states) == 0) { + fail $"Length of stateId must be at least 1"; + } + + mutable res = states[0]; + + for (i in 1 .. Length(states) - 1) { + set res = TensorProduct(states[i], res); + } + + return res; + } + + + function PauliById (pauliId : Int[]) : Pauli[] { + + let paulies = [PauliX, PauliY, PauliZ, PauliI]; + mutable arr = new Pauli[Length(pauliId)]; + + for (i in 0 .. Length(pauliId) - 1) { + set arr = arr w/ i <- paulies[pauliId[i]]; + } + + return arr; + } + + + /// # Summary + /// Returns the expectation of measuring observable on the qubit in state given by stateId. + /// + /// # Remarks + /// The correspondence between + /// value of stateId and the qubit state is the following: + /// 0 -- |0⟩ + /// 1 -- |1⟩ + /// 2 -- |+⟩ + /// 3 -- |i⟩ ( +1 eigenstate of Pauli Y ) + function ExpectedValueForPauli (observable : Pauli, stateId : Int) : Double { + if (stateId < 0 or stateId > 3) { + fail $"stateId must have value between 0 and 3"; + } + + let XpauliArr = [0.0, 0.0, 1.0, 0.0]; + let YpauliArr = [0.0, 0.0, 0.0, 1.0]; + let ZpauliArr = [1.0, -1.0, 0.0, 0.0]; + + if (observable == PauliI) { + return 1.0; + } elif (observable == PauliX) { + return XpauliArr[stateId]; + } elif (observable == PauliY) { + return YpauliArr[stateId]; + } elif (observable == PauliZ) { + return ZpauliArr[stateId]; + } + + fail $"this line should never be reached"; + } + + + /// + /// Expectation of the observable P₁⊗…⊗Pₙ with respect to state |ψ₁⟩⊗…⊗|ψₙ⟩ given by stateId array. + /// The correspondence between + /// the values of stateId array and the qubit state is the following: + /// 0 -- |0⟩ + /// 1 -- |1⟩ + /// 2 -- |+⟩ + /// 3 -- |i⟩ ( +1 eigenstate of Pauli Y ) + /// + function ExpectedValueForMultiPauliByStateId (observable : Pauli[], stateId : Int[]) : Double { + + + if (Length(observable) != Length(stateId)) { + fail $"arrays observable and stateId must have the same length"; + } + + //note that writing 1.0 here will cause code gen to fail. + mutable res = IntAsDouble(1); + + for (i in 0 .. Length(observable) - 1) { + set res = res * ExpectedValueForPauli(observable[i], stateId[i]); + } + + return res; + } + + + function DotProduct (vector1 : Complex[], vector2 : Vector) : Complex { + + mutable res = ZeroC(); + let dimension = Length(vector1); + + if (dimension != Length(vector2!)) { + fail $"vector1 and vector2 must have he same dimension"; + } + + for (i in 0 .. dimension - 1) { + set res = PlusC(res, TimesC(vector1[i], vector2![i])); + } + + return res; + } + + + function HermitianProduct (vector1 : Vector, vector2 : Vector) : Complex { + + mutable res = ZeroC(); + let dimension = Length(vector1!); + + if (dimension != Length(vector2!)) { + fail $"vector1 and vector2 must have he same dimension"; + } + + for (i in 0 .. dimension - 1) { + set res = PlusC(res, TimesC(ConjugateC(vector1![i]), vector2![i])); + } + + return res; + } + + + function ApplyMatrix (matrixRowMajor : RowMajorMatrix, columnVector : Vector) : Vector { + + let rowCount = Length(matrixRowMajor!); + mutable res = new Complex[rowCount]; + + for (i in 0 .. rowCount - 1) { + set res = res w/ i <- DotProduct(matrixRowMajor![i], columnVector); + } + + return Vector(res); + } + + + function AssertUnitaryMatrix (unitaryMatrix : RowMajorMatrix) : Unit { + + let rowCount = Length(unitaryMatrix!); + + for (i in 0 .. rowCount - 1) { + + if (Length(unitaryMatrix![i]) != rowCount) { + fail $"matrix is not square"; + } + + let norm = HermitianProduct(Vector(unitaryMatrix![i]), Vector(unitaryMatrix![i])); + + if (AbsSquaredC(PlusC(norm, MinusC(OneC()))) >= Accuracy()) { + fail $"one of the rows does not have norm 1"; + } + } + + for (i in 0 .. rowCount - 1) { + + for (j in 0 .. rowCount - 1) { + + if (i != j) { + let hermProd = HermitianProduct(Vector(unitaryMatrix![i]), Vector(unitaryMatrix![j])); + + if (AbsSquaredC(hermProd) >= Accuracy()) { + fail $"some of the matrix rows are non-orthogonal with respect to hermitian product"; + } + } + } + } + } + + + function IdentityMatrix (size : Int) : RowMajorMatrix { + + mutable result = new Complex[][size]; + + for (i in 0 .. size - 1) { + set result = result w/ + i <- (new Complex[size] w/ i <- OneC()); + } + + return RowMajorMatrix(result); + } + + + function DirectSum (left : RowMajorMatrix, right : RowMajorMatrix) : RowMajorMatrix { + + let leftDimension = Length(left!); + let rightDimension = Length(right!); + let resultDimension = leftDimension + rightDimension; + mutable result = new Complex[][resultDimension]; + + for (i in 0 .. resultDimension - 1) { + mutable row = new Complex[resultDimension]; + + if (i < leftDimension) { + + for (j in 0 .. leftDimension - 1) { + set row = row w/ j <- left![i][j]; + } + } + else { + + for (j in 0 .. rightDimension - 1) { + set row = row w/ j + leftDimension <- right![i - leftDimension][j]; + } + } + set result = result w/ i <- row; + } + + return RowMajorMatrix(result); + } + + + function ControlledMatrix (numberOfControls : Int, matrix : RowMajorMatrix) : RowMajorMatrix { + + + if (numberOfControls < 1) { + fail $"Number of controls must be at least 1"; + } + + let (matrixQubits, nonPowerOfTwo) = PAdicValuation(Length(matrix!), 2); + + if (nonPowerOfTwo != 1) { + fail $"Dimension of the matrix must be power of two"; + } + + let identityMatrixDimension = 2 ^ (matrixQubits + numberOfControls) - Length(matrix!); + return DirectSum(IdentityMatrix(identityMatrixDimension), matrix); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs new file mode 100644 index 00000000000..9c89fd54ddc --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Intrinsic; + + + operation ManyControlQubitsTest () : Unit { + + let totalQubits = 18; + + for (i in 14 .. totalQubits) { + + using (qubits = Qubit[i]) { + + for (c in 0 .. i - 2) { + + for (h in 0 .. i - 1) { + H(qubits[h]); + } + + let ctrls = qubits[0 .. c]; + let target = qubits[i - 1]; + X(ctrls[c]); + Controlled X(ctrls, target); + } + + ResetAll(qubits); + } + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs new file mode 100644 index 00000000000..2f3dd7dba1d --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite.Math { + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + + function _pavRecursion (value : Int, valuationBase : Int, valuation : Int) : (Int, Int) { + if (value % valuationBase != 0 ) { + return (valuation, value); + } + + return _pavRecursion(value / valuationBase, valuationBase, valuation + 1); + } + + /// returns (a,b) where a is the biggest value such that value = b*valuationBase^a + function PAdicValuation (value : Int, valuationBase : Int) : (Int, Int) { + if (value == 0) { + fail $"value must be non-zero"; + } + + if (valuationBase <= 0) { + fail $"valuationBase must be positive"; + } + + return _pavRecursion(value, valuationBase, 0); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs new file mode 100644 index 00000000000..181e0347999 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs @@ -0,0 +1,2004 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite.Math { + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + + + function ExpXMatrix (phi : Double) : RowMajorMatrix { + + let matrix = [[Complex(Cos(phi), 0.0), Complex(0.0, Sin(phi))], [Complex(0.0, Sin(phi)), Complex(Cos(phi), 0.0)]]; + return RowMajorMatrix(matrix); + } + + + function ExpYMatrix (phi : Double) : RowMajorMatrix { + + let matrix = [[Complex(Cos(phi), 0.0), Complex(Sin(phi), 0.0)], [Complex(-Sin(phi), 0.0), Complex(Cos(phi), 0.0)]]; + return RowMajorMatrix(matrix); + } + + + function ExpZMatrix (phi : Double) : RowMajorMatrix { + + return RowMajorMatrix([[ExpIC(phi), ZeroC()], [ZeroC(), ExpIC(-phi)]]); + } + + + function ExpIMatrix (phi : Double) : RowMajorMatrix { + + return RowMajorMatrix([[ExpIC(phi), ZeroC()], [ZeroC(), ExpIC(phi)]]); + } + + + function ExpPauliMatrix (pauli : Pauli, phi : Double) : RowMajorMatrix { + + + if (pauli == PauliI) { + return ExpIMatrix(phi); + } + elif (pauli == PauliX) { + return ExpXMatrix(phi); + } + elif (pauli == PauliY) { + return ExpYMatrix(phi); + } + elif (pauli == PauliZ) { + return ExpZMatrix(phi); + } + + fail $"this line should never be reached"; + } + + + function R1Matrix (phi : Double) : RowMajorMatrix { + + return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), ExpIC(phi)]]); + } + + + function PauliMatrix (pauli : Pauli) : RowMajorMatrix { + + + if (pauli == PauliI) { + return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), OneC()]]); + } + elif (pauli == PauliX) { + return RowMajorMatrix([[ZeroC(), OneC()], [OneC(), ZeroC()]]); + } + elif (pauli == PauliY) { + return RowMajorMatrix([[ZeroC(), Complex(0.0, -1.0)], [Complex(0.0, 1.0), ZeroC()]]); + } + elif (pauli == PauliZ) { + return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), MinusC(OneC())]]); + } + + fail $"this line should never be reached"; + } + + + function SMatrix () : RowMajorMatrix { + + return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), Complex(0.0, 1.0)]]); + } + + + function TMatrix () : RowMajorMatrix { + + let oneOvSqrt2 = 1.0 / Sqrt(2.0); + return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), Complex(oneOvSqrt2, oneOvSqrt2)]]); + } + + + function HMatrix () : RowMajorMatrix { + + let oneOvSqrt2 = DivCD(OneC(), Sqrt(2.0)); + return RowMajorMatrix([[oneOvSqrt2, oneOvSqrt2], [oneOvSqrt2, MinusC(oneOvSqrt2)]]); + } + + + function CNOTMatrix () : RowMajorMatrix { + + let I = OneC(); + let O = ZeroC(); + let matrix = [ + [I, O, O, O], + [O, O, O, I], + [O, O, I, O], + [O, I, O, O] + ]; + return RowMajorMatrix(matrix); + } + + + function SWAPMatrix () : RowMajorMatrix { + + let I = OneC(); + let O = ZeroC(); + let matrix = [ + [I, O, O, O], + [O, O, I, O], + [O, I, O, O], + [O, O, O, I] + ]; + return RowMajorMatrix(matrix); + } + + + // All code below has been auto-generated using Mathematics notebook TestSuiteCalculations.nb + + function ExpIIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O], + [O, Ep, O, O], + [O, O, Ep, O], + [O, O, O, Ep] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, IS, O, O], + [IS, C, O, O], + [O, O, C, IS], + [O, O, IS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, pS, O, O], + [mS, C, O, O], + [O, O, C, pS], + [O, O, mS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O], + [O, Em, O, O], + [O, O, Ep, O], + [O, O, O, Em] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, IS, O], + [O, C, O, IS], + [IS, O, C, O], + [O, IS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, IS], + [O, C, IS, O], + [O, IS, C, O], + [IS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, pS], + [O, C, mS, O], + [O, pS, C, O], + [mS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, IS, O], [O, C, O, mIS], + [IS, O, C, O], + [O, mIS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, pS, O], + [O, C, O, pS], + [mS, O, C, O], + [O, mS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, pS], + [O, C, pS, O], + [O, mS, C, O], + [mS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, mIS], + [O, C, IS, O], + [O, IS, C, O], + [mIS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, pS, O], + [O, C, O, mS], + [mS, O, C, O], + [O, pS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O], + [O, Ep, O, O], + [O, O, Em, O], + [O, O, O, Em] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, IS, O, O], + [IS, C, O, O], + [O, O, C, mIS], + [O, O, mIS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, pS, O, O], + [mS, C, O, O], + [O, O, C, mS], + [O, O, pS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O], + [O, Em, O, O], + [O, O, Em, O], + [O, O, O, Ep] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIIIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Ep, O, O, O, O, O, O], + [O, O, Ep, O, O, O, O, O], + [O, O, O, Ep, O, O, O, O], + [O, O, O, O, Ep, O, O, O], + [O, O, O, O, O, Ep, O, O], + [O, O, O, O, O, O, Ep, O], + [O, O, O, O, O, O, O, Ep] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIIXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, IS, O, O, O, O, O, O], + [IS, C, O, O, O, O, O, O], + [O, O, C, IS, O, O, O, O], + [O, O, IS, C, O, O, O, O], + [O, O, O, O, C, IS, O, O], + [O, O, O, O, IS, C, O, O], + [O, O, O, O, O, O, C, IS], + [O, O, O, O, O, O, IS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIIYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, pS, O, O, O, O, O, O], + [mS, C, O, O, O, O, O, O], + [O, O, C, pS, O, O, O, O], + [O, O, mS, C, O, O, O, O], + [O, O, O, O, C, pS, O, O], + [O, O, O, O, mS, C, O, O], + [O, O, O, O, O, O, C, pS], + [O, O, O, O, O, O, mS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIIZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Em, O, O, O, O, O, O], + [O, O, Ep, O, O, O, O, O], + [O, O, O, Em, O, O, O, O], + [O, O, O, O, Ep, O, O, O], + [O, O, O, O, O, Em, O, O], + [O, O, O, O, O, O, Ep, O], + [O, O, O, O, O, O, O, Em] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIXIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, IS, O, O, O, O, O], + [O, C, O, IS, O, O, O, O], + [IS, O, C, O, O, O, O, O], + [O, IS, O, C, O, O, O, O], + [O, O, O, O, C, O, IS, O], + [O, O, O, O, O, C, O, IS], + [O, O, O, O, IS, O, C, O], + [O, O, O, O, O, IS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIXXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, IS, O, O, O, O], + [O, C, IS, O, O, O, O, O], + [O, IS, C, O, O, O, O, O], + [IS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, IS], + [O, O, O, O, O, C, IS, O], + [O, O, O, O, O, IS, C, O], + [O, O, O, O, IS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIXYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, pS, O, O, O, O], + [O, C, mS, O, O, O, O, O], + [O, pS, C, O, O, O, O, O], + [mS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, pS], + [O, O, O, O, O, C, mS, O], + [O, O, O, O, O, pS, C, O], + [O, O, O, O, mS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIXZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, IS, O, O, O, O, O], + [O, C, O, mIS, O, O, O, O], + [IS, O, C, O, O, O, O, O], + [O, mIS, O, C, O, O, O, O], + [O, O, O, O, C, O, IS, O], + [O, O, O, O, O, C, O, mIS], + [O, O, O, O, IS, O, C, O], + [O, O, O, O, O, mIS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIYIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, pS, O, O, O, O, O], + [O, C, O, pS, O, O, O, O], + [mS, O, C, O, O, O, O, O], + [O, mS, O, C, O, O, O, O], + [O, O, O, O, C, O, pS, O], + [O, O, O, O, O, C, O, pS], + [O, O, O, O, mS, O, C, O], + [O, O, O, O, O, mS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIYXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, pS, O, O, O, O], + [O, C, pS, O, O, O, O, O], + [O, mS, C, O, O, O, O, O], + [mS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, pS], + [O, O, O, O, O, C, pS, O], + [O, O, O, O, O, mS, C, O], + [O, O, O, O, mS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIYYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, mIS, O, O, O, O], + [O, C, IS, O, O, O, O, O], + [O, IS, C, O, O, O, O, O], + [mIS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, mIS], + [O, O, O, O, O, C, IS, O], + [O, O, O, O, O, IS, C, O], + [O, O, O, O, mIS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIYZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, pS, O, O, O, O, O], + [O, C, O, mS, O, O, O, O], + [mS, O, C, O, O, O, O, O], + [O, pS, O, C, O, O, O, O], + [O, O, O, O, C, O, pS, O], + [O, O, O, O, O, C, O, mS], + [O, O, O, O, mS, O, C, O], + [O, O, O, O, O, pS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIZIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Ep, O, O, O, O, O, O], + [O, O, Em, O, O, O, O, O], + [O, O, O, Em, O, O, O, O], + [O, O, O, O, Ep, O, O, O], + [O, O, O, O, O, Ep, O, O], + [O, O, O, O, O, O, Em, O], + [O, O, O, O, O, O, O, Em] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIZXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, IS, O, O, O, O, O, O], + [IS, C, O, O, O, O, O, O], + [O, O, C, mIS, O, O, O, O], + [O, O, mIS, C, O, O, O, O], + [O, O, O, O, C, IS, O, O], + [O, O, O, O, IS, C, O, O], + [O, O, O, O, O, O, C, mIS], + [O, O, O, O, O, O, mIS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIZYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, pS, O, O, O, O, O, O], + [mS, C, O, O, O, O, O, O], + [O, O, C, mS, O, O, O, O], + [O, O, pS, C, O, O, O, O], + [O, O, O, O, C, pS, O, O], + [O, O, O, O, mS, C, O, O], + [O, O, O, O, O, O, C, mS], + [O, O, O, O, O, O, pS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpIZZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Em, O, O, O, O, O, O], + [O, O, Em, O, O, O, O, O], + [O, O, O, Ep, O, O, O, O], + [O, O, O, O, Ep, O, O, O], + [O, O, O, O, O, Em, O, O], + [O, O, O, O, O, O, Em, O], + [O, O, O, O, O, O, O, Ep] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXIIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, IS, O, O, O], + [O, C, O, O, O, IS, O, O], + [O, O, C, O, O, O, IS, O], + [O, O, O, C, O, O, O, IS], + [IS, O, O, O, C, O, O, O], + [O, IS, O, O, O, C, O, O], + [O, O, IS, O, O, O, C, O], + [O, O, O, IS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXIXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, IS, O, O], + [O, C, O, O, IS, O, O, O], + [O, O, C, O, O, O, O, IS], + [O, O, O, C, O, O, IS, O], + [O, IS, O, O, C, O, O, O], + [IS, O, O, O, O, C, O, O], + [O, O, O, IS, O, O, C, O], + [O, O, IS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXIYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, pS, O, O], + [O, C, O, O, mS, O, O, O], + [O, O, C, O, O, O, O, pS], + [O, O, O, C, O, O, mS, O], + [O, pS, O, O, C, O, O, O], + [mS, O, O, O, O, C, O, O], + [O, O, O, pS, O, O, C, O], + [O, O, mS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXIZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, IS, O, O, O], + [O, C, O, O, O, mIS, O, O], + [O, O, C, O, O, O, IS, O], + [O, O, O, C, O, O, O, mIS], + [IS, O, O, O, C, O, O, O], + [O, mIS, O, O, O, C, O, O], + [O, O, IS, O, O, O, C, O], + [O, O, O, mIS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXXIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, IS, O], + [O, C, O, O, O, O, O, IS], + [O, O, C, O, IS, O, O, O], + [O, O, O, C, O, IS, O, O], + [O, O, IS, O, C, O, O, O], + [O, O, O, IS, O, C, O, O], + [IS, O, O, O, O, O, C, O], + [O, IS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXXXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, IS], + [O, C, O, O, O, O, IS, O], + [O, O, C, O, O, IS, O, O], + [O, O, O, C, IS, O, O, O], + [O, O, O, IS, C, O, O, O], + [O, O, IS, O, O, C, O, O], + [O, IS, O, O, O, O, C, O], + [IS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXXYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, pS], + [O, C, O, O, O, O, mS, O], + [O, O, C, O, O, pS, O, O], + [O, O, O, C, mS, O, O, O], + [O, O, O, pS, C, O, O, O], + [O, O, mS, O, O, C, O, O], + [O, pS, O, O, O, O, C, O], + [mS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXXZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, IS, O], + [O, C, O, O, O, O, O, mIS], + [O, O, C, O, IS, O, O, O], + [O, O, O, C, O, mIS, O, O], + [O, O, IS, O, C, O, O, O], + [O, O, O, mIS, O, C, O, O], + [IS, O, O, O, O, O, C, O], + [O, mIS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXYIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, pS, O], + [O, C, O, O, O, O, O, pS], + [O, O, C, O, mS, O, O, O], + [O, O, O, C, O, mS, O, O], + [O, O, pS, O, C, O, O, O], + [O, O, O, pS, O, C, O, O], + [mS, O, O, O, O, O, C, O], + [O, mS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXYXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, pS], + [O, C, O, O, O, O, pS, O], + [O, O, C, O, O, mS, O, O], + [O, O, O, C, mS, O, O, O], + [O, O, O, pS, C, O, O, O], + [O, O, pS, O, O, C, O, O], + [O, mS, O, O, O, O, C, O], + [mS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXYYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, mIS], + [O, C, O, O, O, O, IS, O], + [O, O, C, O, O, IS, O, O], + [O, O, O, C, mIS, O, O, O], + [O, O, O, mIS, C, O, O, O], + [O, O, IS, O, O, C, O, O], + [O, IS, O, O, O, O, C, O], + [mIS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXYZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, pS, O], + [O, C, O, O, O, O, O, mS], + [O, O, C, O, mS, O, O, O], + [O, O, O, C, O, pS, O, O], + [O, O, pS, O, C, O, O, O], + [O, O, O, mS, O, C, O, O], + [mS, O, O, O, O, O, C, O], + [O, pS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXZIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, IS, O, O, O], + [O, C, O, O, O, IS, O, O], + [O, O, C, O, O, O, mIS, O], + [O, O, O, C, O, O, O, mIS], + [IS, O, O, O, C, O, O, O], + [O, IS, O, O, O, C, O, O], + [O, O, mIS, O, O, O, C, O], + [O, O, O, mIS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXZXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, IS, O, O], + [O, C, O, O, IS, O, O, O], + [O, O, C, O, O, O, O, mIS], + [O, O, O, C, O, O, mIS, O], + [O, IS, O, O, C, O, O, O], + [IS, O, O, O, O, C, O, O], + [O, O, O, mIS, O, O, C, O], + [O, O, mIS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXZYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, pS, O, O], + [O, C, O, O, mS, O, O, O], + [O, O, C, O, O, O, O, mS], + [O, O, O, C, O, O, pS, O], + [O, pS, O, O, C, O, O, O], + [mS, O, O, O, O, C, O, O], + [O, O, O, mS, O, O, C, O], + [O, O, pS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpXZZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, IS, O, O, O], + [O, C, O, O, O, mIS, O, O], + [O, O, C, O, O, O, mIS, O], + [O, O, O, C, O, O, O, IS], + [IS, O, O, O, C, O, O, O], + [O, mIS, O, O, O, C, O, O], + [O, O, mIS, O, O, O, C, O], + [O, O, O, IS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYIIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, pS, O, O, O], + [O, C, O, O, O, pS, O, O], + [O, O, C, O, O, O, pS, O], + [O, O, O, C, O, O, O, pS], + [mS, O, O, O, C, O, O, O], + [O, mS, O, O, O, C, O, O], + [O, O, mS, O, O, O, C, O], + [O, O, O, mS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYIXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, pS, O, O], + [O, C, O, O, pS, O, O, O], + [O, O, C, O, O, O, O, pS], + [O, O, O, C, O, O, pS, O], + [O, mS, O, O, C, O, O, O], + [mS, O, O, O, O, C, O, O], + [O, O, O, mS, O, O, C, O], + [O, O, mS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYIYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, mIS, O, O], + [O, C, O, O, IS, O, O, O], + [O, O, C, O, O, O, O, mIS], + [O, O, O, C, O, O, IS, O], + [O, IS, O, O, C, O, O, O], + [mIS, O, O, O, O, C, O, O], + [O, O, O, IS, O, O, C, O], + [O, O, mIS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYIZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, pS, O, O, O], + [O, C, O, O, O, mS, O, O], + [O, O, C, O, O, O, pS, O], + [O, O, O, C, O, O, O, mS], + [mS, O, O, O, C, O, O, O], + [O, pS, O, O, O, C, O, O], + [O, O, mS, O, O, O, C, O], + [O, O, O, pS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYXIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, pS, O], + [O, C, O, O, O, O, O, pS], + [O, O, C, O, pS, O, O, O], + [O, O, O, C, O, pS, O, O], + [O, O, mS, O, C, O, O, O], + [O, O, O, mS, O, C, O, O], + [mS, O, O, O, O, O, C, O], + [O, mS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYXXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, pS], + [O, C, O, O, O, O, pS, O], + [O, O, C, O, O, pS, O, O], + [O, O, O, C, pS, O, O, O], + [O, O, O, mS, C, O, O, O], + [O, O, mS, O, O, C, O, O], + [O, mS, O, O, O, O, C, O], + [mS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYXYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, mIS], + [O, C, O, O, O, O, IS, O], + [O, O, C, O, O, mIS, O, O], + [O, O, O, C, IS, O, O, O], + [O, O, O, IS, C, O, O, O], + [O, O, mIS, O, O, C, O, O], + [O, IS, O, O, O, O, C, O], + [mIS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYXZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, pS, O], + [O, C, O, O, O, O, O, mS], + [O, O, C, O, pS, O, O, O], + [O, O, O, C, O, mS, O, O], + [O, O, mS, O, C, O, O, O], + [O, O, O, pS, O, C, O, O], + [mS, O, O, O, O, O, C, O], + [O, pS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYYIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, mIS, O], + [O, C, O, O, O, O, O, mIS], + [O, O, C, O, IS, O, O, O], + [O, O, O, C, O, IS, O, O], + [O, O, IS, O, C, O, O, O], + [O, O, O, IS, O, C, O, O], + [mIS, O, O, O, O, O, C, O], + [O, mIS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYYXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, mIS], + [O, C, O, O, O, O, mIS, O], + [O, O, C, O, O, IS, O, O], + [O, O, O, C, IS, O, O, O], + [O, O, O, IS, C, O, O, O], + [O, O, IS, O, O, C, O, O], + [O, mIS, O, O, O, O, C, O], + [mIS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYYYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, O, mS], + [O, C, O, O, O, O, pS, O], + [O, O, C, O, O, pS, O, O], + [O, O, O, C, mS, O, O, O], + [O, O, O, pS, C, O, O, O], + [O, O, mS, O, O, C, O, O], + [O, mS, O, O, O, O, C, O], + [pS, O, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYYZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, O, mIS, O], + [O, C, O, O, O, O, O, IS], + [O, O, C, O, IS, O, O, O], + [O, O, O, C, O, mIS, O, O], + [O, O, IS, O, C, O, O, O], + [O, O, O, mIS, O, C, O, O], + [mIS, O, O, O, O, O, C, O], + [O, IS, O, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYZIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, pS, O, O, O], + [O, C, O, O, O, pS, O, O], + [O, O, C, O, O, O, mS, O], + [O, O, O, C, O, O, O, mS], + [mS, O, O, O, C, O, O, O], + [O, mS, O, O, O, C, O, O], + [O, O, pS, O, O, O, C, O], + [O, O, O, pS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYZXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, pS, O, O], + [O, C, O, O, pS, O, O, O], + [O, O, C, O, O, O, O, mS], + [O, O, O, C, O, O, mS, O], + [O, mS, O, O, C, O, O, O], + [mS, O, O, O, O, C, O, O], + [O, O, O, pS, O, O, C, O], + [O, O, pS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYZYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, O, mIS, O, O], + [O, C, O, O, IS, O, O, O], + [O, O, C, O, O, O, O, IS], + [O, O, O, C, O, O, mIS, O], + [O, IS, O, O, C, O, O, O], + [mIS, O, O, O, O, C, O, O], + [O, O, O, mIS, O, O, C, O], + [O, O, IS, O, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpYZZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, O, pS, O, O, O], + [O, C, O, O, O, mS, O, O], + [O, O, C, O, O, O, mS, O], + [O, O, O, C, O, O, O, pS], + [mS, O, O, O, C, O, O, O], + [O, pS, O, O, O, C, O, O], + [O, O, pS, O, O, O, C, O], + [O, O, O, mS, O, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZIIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Ep, O, O, O, O, O, O], + [O, O, Ep, O, O, O, O, O], + [O, O, O, Ep, O, O, O, O], + [O, O, O, O, Em, O, O, O], + [O, O, O, O, O, Em, O, O], + [O, O, O, O, O, O, Em, O], + [O, O, O, O, O, O, O, Em] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZIXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, IS, O, O, O, O, O, O], + [IS, C, O, O, O, O, O, O], + [O, O, C, IS, O, O, O, O], + [O, O, IS, C, O, O, O, O], + [O, O, O, O, C, mIS, O, O], + [O, O, O, O, mIS, C, O, O], + [O, O, O, O, O, O, C, mIS], + [O, O, O, O, O, O, mIS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZIYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, pS, O, O, O, O, O, O], + [mS, C, O, O, O, O, O, O], + [O, O, C, pS, O, O, O, O], + [O, O, mS, C, O, O, O, O], + [O, O, O, O, C, mS, O, O], + [O, O, O, O, pS, C, O, O], + [O, O, O, O, O, O, C, mS], + [O, O, O, O, O, O, pS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZIZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Em, O, O, O, O, O, O], + [O, O, Ep, O, O, O, O, O], + [O, O, O, Em, O, O, O, O], + [O, O, O, O, Em, O, O, O], + [O, O, O, O, O, Ep, O, O], + [O, O, O, O, O, O, Em, O], + [O, O, O, O, O, O, O, Ep] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZXIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, IS, O, O, O, O, O], + [O, C, O, IS, O, O, O, O], + [IS, O, C, O, O, O, O, O], + [O, IS, O, C, O, O, O, O], + [O, O, O, O, C, O, mIS, O], + [O, O, O, O, O, C, O, mIS], + [O, O, O, O, mIS, O, C, O], + [O, O, O, O, O, mIS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZXXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, IS, O, O, O, O], + [O, C, IS, O, O, O, O, O], + [O, IS, C, O, O, O, O, O], + [IS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, mIS], + [O, O, O, O, O, C, mIS, O], + [O, O, O, O, O, mIS, C, O], + [O, O, O, O, mIS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZXYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, pS, O, O, O, O], + [O, C, mS, O, O, O, O, O], + [O, pS, C, O, O, O, O, O], + [mS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, mS], + [O, O, O, O, O, C, pS, O], + [O, O, O, O, O, mS, C, O], + [O, O, O, O, pS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZXZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, IS, O, O, O, O, O], + [O, C, O, mIS, O, O, O, O], + [IS, O, C, O, O, O, O, O], + [O, mIS, O, C, O, O, O, O], + [O, O, O, O, C, O, mIS, O], + [O, O, O, O, O, C, O, IS], + [O, O, O, O, mIS, O, C, O], + [O, O, O, O, O, IS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZYIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, pS, O, O, O, O, O], + [O, C, O, pS, O, O, O, O], + [mS, O, C, O, O, O, O, O], + [O, mS, O, C, O, O, O, O], + [O, O, O, O, C, O, mS, O], + [O, O, O, O, O, C, O, mS], + [O, O, O, O, pS, O, C, O], + [O, O, O, O, O, pS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZYXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, pS, O, O, O, O], + [O, C, pS, O, O, O, O, O], + [O, mS, C, O, O, O, O, O], + [mS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, mS], + [O, O, O, O, O, C, mS, O], + [O, O, O, O, O, pS, C, O], + [O, O, O, O, pS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZYYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, O, mIS, O, O, O, O], + [O, C, IS, O, O, O, O, O], + [O, IS, C, O, O, O, O, O], + [mIS, O, O, C, O, O, O, O], + [O, O, O, O, C, O, O, IS], + [O, O, O, O, O, C, mIS, O], + [O, O, O, O, O, mIS, C, O], + [O, O, O, O, IS, O, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZYZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, O, pS, O, O, O, O, O], + [O, C, O, mS, O, O, O, O], + [mS, O, C, O, O, O, O, O], + [O, pS, O, C, O, O, O, O], + [O, O, O, O, C, O, mS, O], + [O, O, O, O, O, C, O, pS], + [O, O, O, O, pS, O, C, O], + [O, O, O, O, O, mS, O, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZZIMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Ep, O, O, O, O, O, O], + [O, O, Em, O, O, O, O, O], + [O, O, O, Em, O, O, O, O], + [O, O, O, O, Em, O, O, O], + [O, O, O, O, O, Em, O, O], + [O, O, O, O, O, O, Ep, O], + [O, O, O, O, O, O, O, Ep] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZZXMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, IS, O, O, O, O, O, O], + [IS, C, O, O, O, O, O, O], + [O, O, C, mIS, O, O, O, O], + [O, O, mIS, C, O, O, O, O], + [O, O, O, O, C, mIS, O, O], + [O, O, O, O, mIS, C, O, O], + [O, O, O, O, O, O, C, IS], + [O, O, O, O, O, O, IS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZZYMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [C, pS, O, O, O, O, O, O], + [mS, C, O, O, O, O, O, O], + [O, O, C, mS, O, O, O, O], + [O, O, pS, C, O, O, O, O], + [O, O, O, O, C, mS, O, O], + [O, O, O, O, pS, C, O, O], + [O, O, O, O, O, O, C, pS], + [O, O, O, O, O, O, mS, C] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpZZZMatrix (t : Double) : RowMajorMatrix { + + let O = ZeroC(); + let C = Complex(Cos(t), 0.0); + let IS = Complex(0.0, Sin(t)); + let mIS = Complex(0.0, -Sin(t)); + let pS = Complex(Sin(t), 0.0); + let mS = Complex(-Sin(t), 0.0); + let Ep = ExpIC(t); + let Em = ExpIC(-t); + let matrix = [ + [Ep, O, O, O, O, O, O, O], + [O, Em, O, O, O, O, O, O], + [O, O, Em, O, O, O, O, O], + [O, O, O, Ep, O, O, O, O], + [O, O, O, O, Em, O, O, O], + [O, O, O, O, O, Ep, O, O], + [O, O, O, O, O, O, Ep, O], + [O, O, O, O, O, O, O, Em] + ]; + return RowMajorMatrix(matrix); + } + + + function ExpMultiPauliMatrix (paulies : Pauli[], t : Double) : RowMajorMatrix { + let len = Length(paulies); + + if (len > 3) { + fail $"Pauli arrays of length more than 3 are not supported"; + } + + let index = PauliArrayAsInt(paulies); + let functionLookup = [ + [ExpIMatrix, ExpXMatrix, ExpZMatrix, ExpYMatrix], + [ExpIIMatrix, ExpIXMatrix, ExpIZMatrix, ExpIYMatrix, ExpXIMatrix, ExpXXMatrix, ExpXZMatrix, ExpXYMatrix, ExpZIMatrix, ExpZXMatrix, ExpZZMatrix, ExpZYMatrix, ExpYIMatrix, ExpYXMatrix, ExpYZMatrix, ExpYYMatrix], + [ExpIIIMatrix, ExpIIXMatrix, ExpIIZMatrix, ExpIIYMatrix, ExpIXIMatrix, ExpIXXMatrix, ExpIXZMatrix, ExpIXYMatrix, ExpIZIMatrix, ExpIZXMatrix, ExpIZZMatrix, ExpIZYMatrix, ExpIYIMatrix, ExpIYXMatrix, ExpIYZMatrix, ExpIYYMatrix, ExpXIIMatrix, ExpXIXMatrix, ExpXIZMatrix, ExpXIYMatrix, ExpXXIMatrix, ExpXXXMatrix, ExpXXZMatrix, ExpXXYMatrix, ExpXZIMatrix, ExpXZXMatrix, ExpXZZMatrix, ExpXZYMatrix, ExpXYIMatrix, ExpXYXMatrix, ExpXYZMatrix, ExpXYYMatrix, ExpZIIMatrix, ExpZIXMatrix, ExpZIZMatrix, ExpZIYMatrix, ExpZXIMatrix, ExpZXXMatrix, ExpZXZMatrix, ExpZXYMatrix, ExpZZIMatrix, ExpZZXMatrix, ExpZZZMatrix, ExpZZYMatrix, ExpZYIMatrix, ExpZYXMatrix, ExpZYZMatrix, ExpZYYMatrix, ExpYIIMatrix, ExpYIXMatrix, ExpYIZMatrix, ExpYIYMatrix, ExpYXIMatrix, ExpYXXMatrix, ExpYXZMatrix, ExpYXYMatrix, ExpYZIMatrix, ExpYZXMatrix, ExpYZZMatrix, ExpYZYMatrix, ExpYYIMatrix, ExpYYXMatrix, ExpYYZMatrix, ExpYYYMatrix] + ]; + return (functionLookup[len - 1])[index](t); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs new file mode 100644 index 00000000000..b0fec5f655c --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs @@ -0,0 +1,163 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + + + newtype SingleQubitOperationDescription = ((Qubit => Unit : Adjoint, Controlled), RowMajorMatrix, Int, Bool); + + + function FixesComputationalBasis (record : SingleQubitOperationDescription) : Bool { + + let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; + return fixesComputationalBasis; + } + + + function OperationMap (record : SingleQubitOperationDescription) : (Qubit => Unit : Adjoint, Controlled) { + + let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; + return operationMap; + } + + + function LevelOfCliffordHierarchy (record : SingleQubitOperationDescription) : Int { + + let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; + return levelOfCliffordHierarchy; + } + + + function OperationMatrix (record : SingleQubitOperationDescription) : RowMajorMatrix { + + let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; + return operationMatrix; + } + + + function OutsideOfClifforfdHirerarchy () : Int { + + return 0x7FFFFFFFFFFFFFFF; + } + + + function ContinuousParameterTestList () : Double[] { + + return [0.1, PI() / 3.0]; + } + + + function RotationsWithDoubleParameterTestList () : SingleQubitOperationDescription[] { + + let list = ContinuousParameterTestList(); + mutable res = new SingleQubitOperationDescription[0]; + + for (phi in list) { + let level = OutsideOfClifforfdHirerarchy(); + set res = res + [ + SingleQubitOperationDescription(Rx(phi, _), ExpPauliMatrix(PauliX, -phi / 2.0), level, false), + SingleQubitOperationDescription(Ry(phi, _), ExpPauliMatrix(PauliY, -phi / 2.0), level, false), + SingleQubitOperationDescription(Rz(phi, _), ExpPauliMatrix(PauliZ, -phi / 2.0), level, true), + SingleQubitOperationDescription(R1(phi, _), R1Matrix(phi), level, true) + ]; + + //TODO: add PauliI here when the bugs are fixed + let paulies = [PauliX, PauliY, PauliZ]; + + for (j in 0 .. Length(paulies) - 1) { + let pauli = paulies[j]; + let fixesCompBasis = j >= 2; + let expOperation = Exp([pauli], phi, _); + set res = res + [ + SingleQubitOperationDescription(R(pauli, phi, _), ExpPauliMatrix(pauli, -phi / 2.0), level, fixesCompBasis), + SingleQubitOperationDescription(OnOneQubitAC(expOperation, _), ExpPauliMatrix(pauli, phi), level, fixesCompBasis) + ]; + } + } + + return res; + } + + + function FracParametersTestList () : (Int, Int)[] { + + mutable res = new (Int, Int)[0]; + + for (i in 0 .. MaxDenomiantorPowerToTest()) { + for (j in 0 .. 2 ^ i) { + set res = res + [(j, i)]; + } + } + + return res; + } + + + function R1FracCliffordHierarchyLevel (num : Int, denomPower : Int) : Int { + if (num == 0) { + return 0; + } + + let (numPowerOfTwo, reducedNum) = PAdicValuation(num, 2); + let denomPowerActual = denomPower - numPowerOfTwo; + + return denomPowerActual <= 0 ? 0 | denomPowerActual; + } + + + function RotationsWithFracParameterTestList () : SingleQubitOperationDescription[] { + + let list = FracParametersTestList(); + mutable res = new SingleQubitOperationDescription[0]; + + for (frac in list) { + let (num, denomPower) = frac; + let r1Level = R1FracCliffordHierarchyLevel(frac); + let rzLevel = MaxI(0, r1Level - 1); + let r1Phi = (PI() * IntAsDouble(num)) * PowD(IntAsDouble(2), IntAsDouble(-denomPower)); + set res = res + [SingleQubitOperationDescription(R1Frac(num, denomPower, _), R1Matrix(r1Phi), r1Level, true)]; + + // TODO: add PauliI here when the bugs are fixed + let paulies = [PauliI, PauliY, PauliZ]; + + for (j in 0 .. Length(paulies) - 1) { + let pauli = paulies[j]; + let fixesCompBasis = j >= 2; + let expOperation = ExpFrac([pauli], num, denomPower, _); + set res = res + [SingleQubitOperationDescription(RFrac(pauli, num, denomPower, _), ExpPauliMatrix(pauli, r1Phi), rzLevel, fixesCompBasis), SingleQubitOperationDescription(OnOneQubitAC(expOperation, _), ExpPauliMatrix(pauli, r1Phi), rzLevel, fixesCompBasis)]; + } + } + + return res; + } + + + function OneQubitTestList () : SingleQubitOperationDescription[] { + + mutable list = [ + (X, PauliMatrix(PauliX), 0, true), + (Y, PauliMatrix(PauliY), 0, true), + (Z, PauliMatrix(PauliZ), 0, true), + (H, HMatrix(), 1, false), + (S, SMatrix(), 1, true), + (T, TMatrix(), 2, true) + ]; + mutable result = new SingleQubitOperationDescription[Length(list)]; + + for (i in 0 .. Length(list) - 1) { + set result = result w/ i <- SingleQubitOperationDescription(list[i]); + } + + set result = result + RotationsWithDoubleParameterTestList(); + set result = result + RotationsWithFracParameterTestList(); + return result; + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs new file mode 100644 index 00000000000..a8fe1cf8339 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + open Microsoft.Quantum.Intrinsic; + + + operation OneQubitOperationsTest () : Unit { + + let list = OneQubitTestList(); + + for (test in OneQubitTestList()) { + let shouldExecute = + IsFullSimulator() or + (IsStabilizerSimulator() and LevelOfCliffordHierarchy(test) <= 1) or + (IsReversibleSimulator() and FixesComputationalBasis(test)); + + if (shouldExecute) { + let map = OperationMap(test); + AssertQubitUnitaryWithAdjoint(OperationMatrix(test), map); + Message($"Passed:{map}"); + } + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs new file mode 100644 index 00000000000..b9a2b77c406 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite.Math { + open Microsoft.Quantum.Simulation.TestSuite; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Bitwise; + open Microsoft.Quantum.Convert; + + // Computes expectation of the observable on a given state. + // + // Algorithm is based on the following observations: + // First note that for every bit b, and every single qubit Pauli matrix P + // it is the case that: + // P|b⟩ = iʸ(-1)^(b∧z)|b⊕x⟩, where:, + // x is equal to one when P is X or Y and equal to zero otherwise, we call this function XBit(P) + // z is equal to one when P is Z or Y and equal to zero otherwise, we call this function ZBit(P) + // y is equal to one when P is equal to Y and to zero otherwise, we call this function YCount(P) + // ⊕ is `Xor` + // For tensor product of Paulies P = P₁⊗…⊗Pₙ and multi-qubit states |b⟩=|bₙ…b₁⟩ this generalizes to: + // P|bₙ…b₁⟩ = iʸ⋅(-1)^Parity(b∧z)⋅|b⊕x⟩ where : + // y = Ycount(P) = Ycount(P₁) + … + Ycount(Pₙ), + // x = XBits(P) = (XBit(Pₙ)…XBit(P₁)) is a bitstring of length n + // z = ZBits(P) = (ZBit(Pₙ)…ZBit(P₁)) is a bitstring of length n + // b∧z is bitwise `And` + // b⊕x is bitwise `Xor` + // Parity(aₙ…a) of bitstring aₙ…a₁ is a₁⊕…⊕aₙ + // Using above observations we get: + // ⟨ψ|P|ψ⟩ = ∑ₐⱼ ⟨ψ|a⟩⟨a|P|j⟩⟨j|ψ⟩ = ∑ₐⱼ ⟨ψ|a⟩⟨a|P|j⟩⟨j|ψ⟩ = ∑ₐⱼ ⟨ψ|a⟩⟨a|( iʸ⋅(-1)^Parity(j∧z)⋅|j⊕x⟩ ) ⟨j|ψ⟩ = + // = iʸ⋅∑ⱼ⟨ψ|j⊕x⟩⋅(-1)^Parity(j∧z)⋅⟨j|ψ⟩ + // + // Note the bit order convention used: + // Consider Pauli[] = [ PauliZ, PauliX ]; + // state[2] is ⟨10|ψ⟩ and state[1] is ⟨01|ψ⟩ + // ZBits([ PauliZ, PauliX ]) is 01 in binary + // XBits([ PauliZ, PauliX ]) is 10 in binary + // + function PauliExpectation (observable : Pauli[], state : Vector) : Double { + + + if (Length(observable) == 0) { + fail $"observable array must have Length at least 1"; + } + + if (2 ^ Length(observable) != Length(state!)) { + fail $"size of the state does not match the observable length"; + } + + let xbits = XBits(observable); + let zbits = ZBits(observable); + mutable res = ZeroC(); + let phase = ComplexIPower(YCount(observable)); + + for (j in 0 .. Length(state!) - 1) { + mutable mul = ConjugateC(state![Xor(xbits, j)]); + + // now mul is ⟨ψ|j⊕x⟩ + if (Parity(And(zbits, j)) == 1) { + set mul = MinusC(mul); + } + + // now mul is ⟨ψ|j⊕x⟩⋅(-1)^Parity(j∧z) + // adding ⟨ψ|j⊕x⟩⋅(-1)^Parity(j∧z)⟨j|ψ⟩ to res + set res = PlusC(res, TimesC(mul, state![j])); + } + + let (reRes, imRes) = (TimesC(res, phase))!; + + if (AbsD(imRes) > Accuracy()) { + fail $"the expectation of the observable must be real number"; + } + + return reRes; + } + + + function YCount (observable : Pauli[]) : Int { + + mutable yCount = 0; + + for (i in 0 .. Length(observable) - 1) { + + if (observable[i] == PauliY) { + set yCount = yCount + 1; + } + } + + return yCount; + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs new file mode 100644 index 00000000000..332d0001782 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite.SelfTests { + + open Microsoft.Quantum.Simulation.TestSuite; + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Math; + + + operation PauliExpectationTestHelper (testData : Int[]) : Unit { + + let len = Length(testData); + + if (len % 2 != 0) { + fail $"testData must have even Length"; + } + + let half = len / 2; + let observable = PauliById(testData[0 .. half - 1]); + let stateIds = testData[half .. len - 1]; + let state = StateById(stateIds); + let expected = ExpectedValueForMultiPauliByStateId(observable, stateIds); + let given = PauliExpectation(observable, state); + + if (AbsD(expected - given) >= Accuracy()) { + fail $"wrong expectation value"; + } + } + + + operation PauliExpectationTest () : Unit { + + let totalQubitsToTest = 4; + + for (i in 1 .. totalQubitsToTest) { + let pauliesBound = MakeConstArray(i, NumberOfPaulies()); + let statesBound = MakeConstArray(i, NumberOfTestStates()); + IterateThroughCartesianProduct(pauliesBound + statesBound, PauliExpectationTestHelper); + } + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb new file mode 100644 index 00000000000..63845e59a02 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb @@ -0,0 +1,1280 @@ +(* Copyright (c) Microsoft Corporation. All rights reserved. *) +(* Licensed under the MIT License. *) + +(* Content-type: application/vnd.wolfram.mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 11.0' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 158, 7] +NotebookDataLength[ 73232, 1269] +NotebookOptionsPosition[ 71731, 1213] +NotebookOutlinePosition[ 72074, 1228] +CellTagsIndexPosition[ 72031, 1225] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["Prerequisites", "Chapter", + CellChangeTimes->{{3.7184788997811823`*^9, 3.7184789052925544`*^9}}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], "=", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"PauliMatrix", "[", "k", "]"}], ",", + RowBox[{"{", + RowBox[{"k", ",", "0", ",", "3"}], "}"}]}], "]"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"tp", " ", "=", " ", "KroneckerProduct"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"Dagger", " ", "=", " ", "ConjugateTranspose"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"zeroSt", " ", "=", " ", + RowBox[{"{", + RowBox[{"1", ",", "0"}], "}"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"oneSt", " ", "=", " ", + RowBox[{"{", + RowBox[{"0", ",", "1"}], "}"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"plusSt", " ", "=", + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "1"}], "}"}], "/", + RowBox[{"Sqrt", "[", "2", "]"}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"iSt", " ", "=", " ", + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "I"}], "}"}], "/", + RowBox[{"Sqrt", "[", "2", "]"}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"DensityMatr", "[", "x_", "]"}], ":=", + RowBox[{ + RowBox[{ + RowBox[{"Dagger", "[", + RowBox[{"{", "x", "}"}], "]"}], ".", + RowBox[{"{", "x", "}"}]}], "//", "Transpose"}]}], "\[IndentingNewLine]", + RowBox[{"(*", " ", + RowBox[{ + "This", " ", "is", " ", "ordering", " ", "used", " ", "everywhere", " ", + "in", " ", "the", " ", "TestSuite"}], " ", + "*)"}]}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"fullBasis", " ", "=", " ", + RowBox[{"{", + RowBox[{"zeroSt", ",", "oneSt", ",", "plusSt", ",", "iSt"}], "}"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"AsQDoubleArr", "[", "l_List", "]"}], ":=", " ", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"ToString", "[", + RowBox[{"CForm", "[", + RowBox[{"N", "[", "#", "]"}], "]"}], "]"}], "&"}], "/@", "l"}], "//", + RowBox[{ + RowBox[{"Riffle", "[", + RowBox[{"#", ",", "\"\<;\>\""}], "]"}], "&"}]}], "//", "StringJoin"}], + "//", + RowBox[{ + RowBox[{"(", + RowBox[{"\"\<[\>\"", "~~", "#", "~~", "\"\<]\>\""}], ")"}], + "&"}]}]}]}], "Input", + CellChangeTimes->{{3.718478910443024*^9, 3.718479218281523*^9}, { + 3.718479248879512*^9, 3.718479263034215*^9}, {3.7184793975740213`*^9, + 3.7184795991372766`*^9}, {3.7184796315949745`*^9, 3.7184797046591806`*^9}, { + 3.7184798375361357`*^9, 3.7184798433353157`*^9}, {3.7184800446945333`*^9, + 3.718480077458357*^9}, {3.7187181677029185`*^9, 3.718718172473008*^9}}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"AsQArr", "[", + RowBox[{"s_String", ",", " ", "level_"}], " ", "]"}], ":=", " ", "s"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"AsQArr", "[", + RowBox[{"0", ",", " ", "level_"}], " ", "]"}], ":=", " ", "\"\< O\>\""}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"AsQArr", "[", + RowBox[{"l_List", ",", " ", + RowBox[{"level_", " ", ":", " ", "0"}]}], " ", "]"}], ":=", " ", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"AsQArr", "[", + RowBox[{"#", ",", " ", + RowBox[{"level", "+", "1"}]}], " ", "]"}], "&"}], "/@", "l"}], "//", + RowBox[{ + RowBox[{"Riffle", "[", + RowBox[{"#", ",", + RowBox[{"If", "[", + RowBox[{ + RowBox[{"level", "\[Equal]", "0"}], ",", "\"\<;\\n\>\"", ",", + "\"\<;\>\""}], "]"}]}], "]"}], "&"}]}], "//", "\[IndentingNewLine]", + "StringJoin"}], "//", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"If", "[", + RowBox[{ + RowBox[{"level", "\[Equal]", "1"}], ",", "\"\< [\>\"", ",", + "\"\<[\>\""}], "]"}], "~~", "#", "~~", "\"\<]\>\""}], ")"}], + "&"}]}]}]}], "Input", + CellChangeTimes->{{3.718717964864356*^9, 3.718718020613718*^9}, { + 3.7187181124608784`*^9, 3.7187181126268125`*^9}, {3.7187181784710913`*^9, + 3.718718185125663*^9}, {3.718718237591975*^9, 3.7187182861989775`*^9}, { + 3.718718351396096*^9, 3.7187184780481606`*^9}, 3.718720367009722*^9}], + +Cell[BoxData[""], "Input", + CellChangeTimes->{{3.718718297010992*^9, 3.7187182978963203`*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["PauliExpectation.qs", "Chapter", + CellChangeTimes->{3.7184788834158244`*^9, 3.7186466473395104`*^9}], + +Cell[CellGroupData[{ + +Cell["ExpectedValueForPauli", "Section", + CellChangeTimes->{{3.7184788926643867`*^9, 3.7184788949642396`*^9}, + 3.718646644697502*^9}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"State", "[", "True", "]"}], "=", "oneSt"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"State", "[", "False", "]"}], "=", "zeroSt"}], ";"}], + "\[IndentingNewLine]"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"XBit", "[", "X", "]"}], "=", "True"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"XBit", "[", "Y", "]"}], "=", "True"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"XBit", "[", "Z", "]"}], "=", "False"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"XBit", "[", "Id", "]"}], "=", "False"}], ";"}], + "\[IndentingNewLine]"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"ZBit", "[", "X", "]"}], "=", "False"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"ZBit", "[", "Y", "]"}], "=", "True"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"ZBit", "[", "Z", "]"}], "=", "True"}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"ZBit", "[", "Id", "]"}], "=", "False"}], ";"}], + "\[IndentingNewLine]"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"Ycount", "[", "X", "]"}], "=", "0"}], ";", + RowBox[{ + RowBox[{"Ycount", "[", "Y", "]"}], "=", "1"}], ";", + RowBox[{ + RowBox[{"Ycount", "[", "Z", "]"}], "=", "0"}], ";", + RowBox[{ + RowBox[{"Ycount", "[", "Id", "]"}], "=", "0"}], ";"}]}], "Input", + CellChangeTimes->{{3.718646175503356*^9, 3.7186462656794095`*^9}, { + 3.7186463504314127`*^9, 3.718646405243431*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"FormulaCheck", "[", + RowBox[{"{", " ", + RowBox[{"pauli_", ",", " ", "stateBit_"}], "}"}], "]"}], ":=", " ", + "\[IndentingNewLine]", + RowBox[{ + RowBox[{"pauli", ".", + RowBox[{"State", "[", "stateBit", "]"}]}], "\[Equal]", + "\[IndentingNewLine]", + RowBox[{ + RowBox[{"I", "^", + RowBox[{"Ycount", "[", "pauli", "]"}]}], + RowBox[{ + RowBox[{"(", + RowBox[{"-", "1"}], ")"}], "^", + RowBox[{"Boole", "[", " ", + RowBox[{"And", "[", + RowBox[{"stateBit", ",", " ", + RowBox[{"ZBit", "[", "pauli", "]"}]}], "]"}], " ", "]"}]}], " ", + RowBox[{"State", "[", " ", + RowBox[{"Xor", "[", + RowBox[{"stateBit", " ", ",", + RowBox[{"XBit", "[", "pauli", "]"}]}], "]"}], "]"}]}]}]}], + ";"}]], "Input", + CellChangeTimes->{{3.7186462761153984`*^9, 3.7186463430594215`*^9}, { + 3.718646416155429*^9, 3.718646552232479*^9}, {3.7186465964045043`*^9, + 3.718646634713516*^9}, {3.7186467638007994`*^9, 3.718646769583794*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"FormulaCheck", "/@", + RowBox[{"Tuples", "[", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", + RowBox[{"{", + RowBox[{"True", ",", "False"}], "}"}]}], "}"}], "]"}]}], "//", + RowBox[{ + RowBox[{"And", "@@", "#"}], "&"}]}]], "Input", + CellChangeTimes->{{3.7186466565775075`*^9, 3.7186467799667997`*^9}}], + +Cell[BoxData["True"], "Output", + CellChangeTimes->{{3.718646693228776*^9, 3.718646703477778*^9}, { + 3.7186467381937866`*^9, 3.7186467806398077`*^9}, 3.7187175759767003`*^9, + 3.718718432580945*^9, 3.718720392855904*^9, 3.718720697142393*^9}] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Matrices.qb", "Chapter", + CellChangeTimes->{ + 3.7184788834158244`*^9, 3.7186466473395104`*^9, {3.7187204172956123`*^9, + 3.718720418865557*^9}}], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"PauliExpPiece", "[", "paulies__", "]"}], ":=", " ", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"MatrixExp", "[", + RowBox[{"I", " ", "t", " ", + RowBox[{"tp", "[", "paulies", "]"}]}], "]"}], "/.", + "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{"Exp", "[", + RowBox[{"I", " ", "t"}], "]"}], "\[Rule]", "\"\< Ep\>\""}], ",", + RowBox[{ + RowBox[{"Exp", "[", + RowBox[{ + RowBox[{"-", "I"}], " ", "t"}], "]"}], "\[Rule]", "\"\< Em\>\""}], + ",", + RowBox[{ + RowBox[{"I", " ", + RowBox[{"Sin", "[", "t", "]"}]}], "\[Rule]", " ", "\"\< IS\>\""}], + ",", " ", "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"-", "I"}], " ", + RowBox[{"Sin", "[", "t", "]"}]}], "\[Rule]", " ", "\"\\""}], + ",", + RowBox[{ + RowBox[{"Cos", "[", "t", "]"}], "\[Rule]", "\"\< C\>\""}], " ", + ",", + RowBox[{ + RowBox[{"Sin", "[", "t", "]"}], "\[Rule]", "\"\< pS\>\""}], ",", + RowBox[{ + RowBox[{"-", + RowBox[{"Sin", "[", "t", "]"}]}], "\[Rule]", "\"\< mS\>\""}]}], + "}"}]}], "//", + RowBox[{ + RowBox[{"AsQArr", "[", + RowBox[{"#", ",", "0"}], "]"}], "&"}]}], "//", + RowBox[{ + RowBox[{"StringReplace", "[", + RowBox[{"#", ",", + RowBox[{"\"\<[ [\>\"", "\[Rule]", "\"\< [[\>\""}]}], "]"}], + "&"}]}], "//", + RowBox[{ + RowBox[{"#", "~~", "\"\<;\\n\>\""}], "&"}]}]}], ";"}]], "Input", + CellChangeTimes->{{3.7187175797173595`*^9, 3.7187176146904716`*^9}, { + 3.7187176953540573`*^9, 3.7187177203616886`*^9}, {3.7187177626100025`*^9, + 3.7187179305017643`*^9}, {3.7187180027673273`*^9, + 3.7187180030132246`*^9}, {3.7187180457732887`*^9, + 3.7187181492506723`*^9}, {3.7187183149004974`*^9, 3.7187183193089037`*^9}, + 3.7187183573407354`*^9, {3.718718509074959*^9, 3.7187185614713545`*^9}, { + 3.7187187394897165`*^9, 3.7187187413639545`*^9}, {3.718718842163275*^9, + 3.718718843930902*^9}, {3.718718957950756*^9, 3.7187189622513447`*^9}, { + 3.7187201074064493`*^9, 3.718720145185424*^9}, {3.7187203726301537`*^9, + 3.7187203802452*^9}, {3.7187204309115763`*^9, 3.71872045656062*^9}, { + 3.7187206381508117`*^9, 3.718720638510955*^9}, {3.7187206925751505`*^9, + 3.7187206931353016`*^9}, {3.7187210087938433`*^9, 3.7187210392313623`*^9}}], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"StringOfPauli", "[", "X", "]"}], "=", "\"\\""}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"StringOfPauli", "[", "Y", "]"}], "=", "\"\\""}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"StringOfPauli", "[", "Z", "]"}], "=", "\"\\""}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"StringOfPauli", "[", "Id", "]"}], "=", "\"\\""}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"PauliStringPiece", "[", "paulies__", "]"}], ":=", + RowBox[{ + RowBox[{"StringOfPauli", "/@", " ", + RowBox[{"List", "[", "paulies", "]"}]}], "//", "StringJoin"}]}], + ";"}]}], "Input", + CellChangeTimes->{{3.718720298600816*^9, 3.7187203366639442`*^9}, { + 3.7187204829800806`*^9, 3.7187205222502007`*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"PauliExpPiece", "[", + RowBox[{"X", ",", "X", ",", "Z"}], "]"}]], "Input", + CellChangeTimes->{{3.7187204648372355`*^9, 3.7187204732011013`*^9}}], + +Cell[BoxData["\<\" [[ C; O; O; O; O; O; IS; O];\\n [ O; C; \ +O; O; O; O; O;mIS];\\n [ O; O; C; O; IS; O; O; O];\\n [ \ +O; O; O; C; O;mIS; O; O];\\n [ O; O; IS; O; C; O; O; O];\\n \ + [ O; O; O;mIS; O; C; O; O];\\n [ IS; O; O; O; O; O; C; \ +O];\\n [ O;mIS; O; O; O; O; O; C]];\\n\"\>"], "Output", + CellChangeTimes->{{3.718720468745313*^9, 3.718720473543486*^9}, + 3.71872069721196*^9, 3.7187210419218025`*^9}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"PauliStringPiece", "[", + RowBox[{"X", ",", "X", ",", "Z"}], "]"}]], "Input", + CellChangeTimes->{{3.7187205263700495`*^9, 3.718720533483435*^9}}], + +Cell[BoxData["\<\"XXZ\"\>"], "Output", + CellChangeTimes->{{3.7187205284171534`*^9, 3.718720534220138*^9}, + 3.7187206972275934`*^9}] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"PauliCode", "[", + RowBox[{"{", "paulies__", "}"}], "]"}], ":=", " ", "\[IndentingNewLine]", + RowBox[{"\"\\"", "~~", + RowBox[{"PauliStringPiece", "[", "paulies", "]"}], "~~", + "\"\\"", "~~", + RowBox[{"PauliExpPiece", "[", "paulies", "]"}], "~~", " ", "\n", " ", + "\"\< return matrix;\n}\\n\\n\>\""}]}]], "Input", + CellChangeTimes->{{3.718720547880199*^9, 3.718720731594817*^9}, { + 3.7187208838835783`*^9, 3.7187208860611715`*^9}, 3.7187209979137883`*^9, { + 3.7187210702636576`*^9, 3.718721086937796*^9}}], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"\[IndentingNewLine]", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"PauliCode", "/@", + RowBox[{"Tuples", "[", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", + RowBox[{"{", + RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}]}], "}"}], + "]"}]}], "//", "StringJoin"}], ")"}], "~~", "\[IndentingNewLine]", + RowBox[{"(", + RowBox[{ + RowBox[{"PauliCode", "/@", + RowBox[{"Tuples", "[", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", + RowBox[{"{", + RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", + RowBox[{"{", + RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}]}], "}"}], + "]"}]}], "//", "StringJoin"}], ")"}]}]}]], "Input", + CellChangeTimes->{{3.718720839316888*^9, 3.71872086218427*^9}, + 3.7187208973565545`*^9, {3.7187210496532717`*^9, 3.718721053305811*^9}, { + 3.7187212427277174`*^9, 3.7187212559646535`*^9}, {3.718721333366556*^9, + 3.718721361491644*^9}, {3.718727871584074*^9, 3.718727883288909*^9}, { + 3.718728040638919*^9, 3.7187281144712653`*^9}}], + +Cell[BoxData["\<\"function ExpIIMatrix( t: Double ) : Complex[][] {\\n let \ +O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ +Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ +Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ +O];\\n [ O; Ep; O; O];\\n [ O; O; Ep; O];\\n [ O; O; O; \ +Ep]];\\n return matrix;\\n}\\n\\nfunction ExpIXMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ +O];\\n [ IS; C; O; O];\\n [ O; O; C; IS];\\n [ O; O; IS; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpIYMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; O; \ +O];\\n [ mS; C; O; O];\\n [ O; O; C; pS];\\n [ O; O; mS; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpIZMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ +O];\\n [ O; Em; O; O];\\n [ O; O; Ep; O];\\n [ O; O; O; \ +Em]];\\n return matrix;\\n}\\n\\nfunction ExpXIMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; IS; \ +O];\\n [ O; C; O; IS];\\n [ IS; O; C; O];\\n [ O; IS; O; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpXXMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ +IS];\\n [ O; C; IS; O];\\n [ O; IS; C; O];\\n [ IS; O; O; \ + C]];\\n return matrix;\\n}\\n\\nfunction ExpXYMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ +pS];\\n [ O; C; mS; O];\\n [ O; pS; C; O];\\n [ mS; O; O; \ + C]];\\n return matrix;\\n}\\n\\nfunction ExpXZMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; IS; \ +O];\\n [ O; C; O;mIS];\\n [ IS; O; C; O];\\n [ O;mIS; O; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpYIMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; pS; \ +O];\\n [ O; C; O; pS];\\n [ mS; O; C; O];\\n [ O; mS; O; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpYXMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ +pS];\\n [ O; C; pS; O];\\n [ O; mS; C; O];\\n [ mS; O; O; \ + C]];\\n return matrix;\\n}\\n\\nfunction ExpYYMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ +O;mIS];\\n [ O; C; IS; O];\\n [ O; IS; C; O];\\n [mIS; O; \ +O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; pS; \ +O];\\n [ O; C; O; mS];\\n [ mS; O; C; O];\\n [ O; pS; O; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpZIMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ +O];\\n [ O; Ep; O; O];\\n [ O; O; Em; O];\\n [ O; O; O; \ +Em]];\\n return matrix;\\n}\\n\\nfunction ExpZXMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ +O];\\n [ IS; C; O; O];\\n [ O; O; C;mIS];\\n [ O; O;mIS; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpZYMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; O; \ +O];\\n [ mS; C; O; O];\\n [ O; O; C; mS];\\n [ O; O; pS; \ +C]];\\n return matrix;\\n}\\n\\nfunction ExpZZMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ +O];\\n [ O; Em; O; O];\\n [ O; O; Em; O];\\n [ O; O; O; \ +Ep]];\\n return matrix;\\n}\\n\\nfunction ExpIIIMatrix( t: Double ) : \ +Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ +let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ +pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ +O; O; O; O; O];\\n [ O; Ep; O; O; O; O; O; O];\\n [ O; \ +O; Ep; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ +[ O; O; O; O; Ep; O; O; O];\\n [ O; O; O; O; O; Ep; O; \ +O];\\n [ O; O; O; O; O; O; Ep; O];\\n [ O; O; O; O; O; \ +O; O; Ep]];\\n return matrix;\\n}\\n\\nfunction ExpIIXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; \ + O; O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ \ +O; O; C; IS; O; O; O; O];\\n [ O; O; IS; C; O; O; O; O];\\n \ + [ O; O; O; O; C; IS; O; O];\\n [ O; O; O; O; IS; C; O; \ +O];\\n [ O; O; O; O; O; O; C; IS];\\n [ O; O; O; O; O; \ +O; IS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIIYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ + O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ +O; O; C; pS; O; O; O; O];\\n [ O; O; mS; C; O; O; O; O];\\n \ + [ O; O; O; O; C; pS; O; O];\\n [ O; O; O; O; mS; C; O; \ +O];\\n [ O; O; O; O; O; O; C; pS];\\n [ O; O; O; O; O; \ +O; mS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIIZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ + O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ +O; O; Ep; O; O; O; O; O];\\n [ O; O; O; Em; O; O; O; O];\\n \ + [ O; O; O; O; Ep; O; O; O];\\n [ O; O; O; O; O; Em; O; \ +O];\\n [ O; O; O; O; O; O; Ep; O];\\n [ O; O; O; O; O; \ +O; O; Em]];\\n return matrix;\\n}\\n\\nfunction ExpIXIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ +IS; O; O; O; O; O];\\n [ O; C; O; IS; O; O; O; O];\\n [ \ +IS; O; C; O; O; O; O; O];\\n [ O; IS; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O; IS; O];\\n [ O; O; O; O; O; C; O; \ +IS];\\n [ O; O; O; O; IS; O; C; O];\\n [ O; O; O; O; O; \ +IS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIXXMatrix( t: Double \ +) : Complex[][] {\\n let O = ZeroC();\\n let C = \ +Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ +Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ +Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ + let matrix = \\n [[ C; O; O; IS; O; O; O; O];\\n [ O; C; IS; \ + O; O; O; O; O];\\n [ O; IS; C; O; O; O; O; O];\\n [ IS; \ +O; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; O; IS];\\n \ +[ O; O; O; O; O; C; IS; O];\\n [ O; O; O; O; O; IS; C; \ +O];\\n [ O; O; O; O; IS; O; O; C]];\\n return \ +matrix;\\n}\\n\\nfunction ExpIXYMatrix( t: Double ) : Complex[][] {\\n let \ +O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ +Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ +Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ +pS; O; O; O; O];\\n [ O; C; mS; O; O; O; O; O];\\n [ O; \ +pS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ +[ O; O; O; O; C; O; O; pS];\\n [ O; O; O; O; O; C; mS; \ +O];\\n [ O; O; O; O; O; pS; C; O];\\n [ O; O; O; O; mS; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIXZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ +IS; O; O; O; O; O];\\n [ O; C; O;mIS; O; O; O; O];\\n [ \ +IS; O; C; O; O; O; O; O];\\n [ O;mIS; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O; IS; O];\\n [ O; O; O; O; O; C; \ +O;mIS];\\n [ O; O; O; O; IS; O; C; O];\\n [ O; O; O; O; \ +O;mIS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIYIMatrix( t: \ +Double ) : Complex[][] {\\n let O = ZeroC();\\n let C = \ +Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ +Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ +Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ + let matrix = \\n [[ C; O; pS; O; O; O; O; O];\\n [ O; C; O; \ +pS; O; O; O; O];\\n [ mS; O; C; O; O; O; O; O];\\n [ O; \ +mS; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; pS; O];\\n \ +[ O; O; O; O; O; C; O; pS];\\n [ O; O; O; O; mS; O; C; \ +O];\\n [ O; O; O; O; O; mS; O; C]];\\n return \ +matrix;\\n}\\n\\nfunction ExpIYXMatrix( t: Double ) : Complex[][] {\\n let \ +O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ +Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ +Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ +pS; O; O; O; O];\\n [ O; C; pS; O; O; O; O; O];\\n [ O; \ +mS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ +[ O; O; O; O; C; O; O; pS];\\n [ O; O; O; O; O; C; pS; \ +O];\\n [ O; O; O; O; O; mS; C; O];\\n [ O; O; O; O; mS; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIYYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O;mIS; O; O; O; O];\\n [ O; C; IS; O; O; O; O; O];\\n [ \ +O; IS; C; O; O; O; O; O];\\n [mIS; O; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O; O;mIS];\\n [ O; O; O; O; O; C; IS; \ +O];\\n [ O; O; O; O; O; IS; C; O];\\n [ O; O; O; O;mIS; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIYZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ +pS; O; O; O; O; O];\\n [ O; C; O; mS; O; O; O; O];\\n [ \ +mS; O; C; O; O; O; O; O];\\n [ O; pS; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O; pS; O];\\n [ O; O; O; O; O; C; O; \ +mS];\\n [ O; O; O; O; mS; O; C; O];\\n [ O; O; O; O; O; \ +pS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIZIMatrix( t: Double \ +) : Complex[][] {\\n let O = ZeroC();\\n let C = \ +Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ +Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ +Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ + let matrix = \\n [[ Ep; O; O; O; O; O; O; O];\\n [ O; Ep; O; \ + O; O; O; O; O];\\n [ O; O; Em; O; O; O; O; O];\\n [ O; \ +O; O; Em; O; O; O; O];\\n [ O; O; O; O; Ep; O; O; O];\\n \ +[ O; O; O; O; O; Ep; O; O];\\n [ O; O; O; O; O; O; Em; \ +O];\\n [ O; O; O; O; O; O; O; Em]];\\n return \ +matrix;\\n}\\n\\nfunction ExpIZXMatrix( t: Double ) : Complex[][] {\\n let \ +O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ +Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ +Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ +O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ O; \ +O; C;mIS; O; O; O; O];\\n [ O; O;mIS; C; O; O; O; O];\\n \ +[ O; O; O; O; C; IS; O; O];\\n [ O; O; O; O; IS; C; O; \ +O];\\n [ O; O; O; O; O; O; C;mIS];\\n [ O; O; O; O; O; \ +O;mIS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIZYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ + O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ +O; O; C; mS; O; O; O; O];\\n [ O; O; pS; C; O; O; O; O];\\n \ + [ O; O; O; O; C; pS; O; O];\\n [ O; O; O; O; mS; C; O; \ +O];\\n [ O; O; O; O; O; O; C; mS];\\n [ O; O; O; O; O; \ +O; pS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIZZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ + O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ +O; O; Em; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ + [ O; O; O; O; Ep; O; O; O];\\n [ O; O; O; O; O; Em; O; \ +O];\\n [ O; O; O; O; O; O; Em; O];\\n [ O; O; O; O; O; \ +O; O; Ep]];\\n return matrix;\\n}\\n\\nfunction ExpXIIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; IS; O; O; O];\\n [ O; C; O; O; O; IS; O; O];\\n [ \ +O; O; C; O; O; O; IS; O];\\n [ O; O; O; C; O; O; O; IS];\\n \ + [ IS; O; O; O; C; O; O; O];\\n [ O; IS; O; O; O; C; O; \ +O];\\n [ O; O; IS; O; O; O; C; O];\\n [ O; O; O; IS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXIXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; IS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ +O; O; C; O; O; O; O; IS];\\n [ O; O; O; C; O; O; IS; O];\\n \ + [ O; IS; O; O; C; O; O; O];\\n [ IS; O; O; O; O; C; O; \ +O];\\n [ O; O; O; IS; O; O; C; O];\\n [ O; O; IS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXIYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; pS; O; O];\\n [ O; C; O; O; mS; O; O; O];\\n [ \ +O; O; C; O; O; O; O; pS];\\n [ O; O; O; C; O; O; mS; O];\\n \ + [ O; pS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ +O];\\n [ O; O; O; pS; O; O; C; O];\\n [ O; O; mS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXIZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; IS; O; O; O];\\n [ O; C; O; O; O;mIS; O; O];\\n [ \ +O; O; C; O; O; O; IS; O];\\n [ O; O; O; C; O; O; O;mIS];\\n \ + [ IS; O; O; O; C; O; O; O];\\n [ O;mIS; O; O; O; C; O; \ +O];\\n [ O; O; IS; O; O; O; C; O];\\n [ O; O; O;mIS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; IS; O];\\n [ O; C; O; O; O; O; O; IS];\\n [ \ +O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O; IS; O; O];\\n \ + [ O; O; IS; O; C; O; O; O];\\n [ O; O; O; IS; O; C; O; \ +O];\\n [ IS; O; O; O; O; O; C; O];\\n [ O; IS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O; IS];\\n [ O; C; O; O; O; O; IS; O];\\n [ \ +O; O; C; O; O; IS; O; O];\\n [ O; O; O; C; IS; O; O; O];\\n \ + [ O; O; O; IS; C; O; O; O];\\n [ O; O; IS; O; O; C; O; \ +O];\\n [ O; IS; O; O; O; O; C; O];\\n [ IS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O; pS];\\n [ O; C; O; O; O; O; mS; O];\\n [ \ +O; O; C; O; O; pS; O; O];\\n [ O; O; O; C; mS; O; O; O];\\n \ + [ O; O; O; pS; C; O; O; O];\\n [ O; O; mS; O; O; C; O; \ +O];\\n [ O; pS; O; O; O; O; C; O];\\n [ mS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; IS; O];\\n [ O; C; O; O; O; O; O;mIS];\\n [ \ +O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O;mIS; O; O];\\n \ + [ O; O; IS; O; C; O; O; O];\\n [ O; O; O;mIS; O; C; O; \ +O];\\n [ IS; O; O; O; O; O; C; O];\\n [ O;mIS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; pS];\\n [ \ +O; O; C; O; mS; O; O; O];\\n [ O; O; O; C; O; mS; O; O];\\n \ + [ O; O; pS; O; C; O; O; O];\\n [ O; O; O; pS; O; C; O; \ +O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; mS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O; pS];\\n [ O; C; O; O; O; O; pS; O];\\n [ \ +O; O; C; O; O; mS; O; O];\\n [ O; O; O; C; mS; O; O; O];\\n \ + [ O; O; O; pS; C; O; O; O];\\n [ O; O; pS; O; O; C; O; \ +O];\\n [ O; mS; O; O; O; O; C; O];\\n [ mS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O;mIS];\\n [ O; C; O; O; O; O; IS; O];\\n [ \ +O; O; C; O; O; IS; O; O];\\n [ O; O; O; C;mIS; O; O; O];\\n \ + [ O; O; O;mIS; C; O; O; O];\\n [ O; O; IS; O; O; C; O; \ +O];\\n [ O; IS; O; O; O; O; C; O];\\n [mIS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; mS];\\n [ \ +O; O; C; O; mS; O; O; O];\\n [ O; O; O; C; O; pS; O; O];\\n \ + [ O; O; pS; O; C; O; O; O];\\n [ O; O; O; mS; O; C; O; \ +O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; pS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; IS; O; O; O];\\n [ O; C; O; O; O; IS; O; O];\\n [ \ +O; O; C; O; O; O;mIS; O];\\n [ O; O; O; C; O; O; O;mIS];\\n \ + [ IS; O; O; O; C; O; O; O];\\n [ O; IS; O; O; O; C; O; \ +O];\\n [ O; O;mIS; O; O; O; C; O];\\n [ O; O; O;mIS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; IS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ +O; O; C; O; O; O; O;mIS];\\n [ O; O; O; C; O; O;mIS; O];\\n \ + [ O; IS; O; O; C; O; O; O];\\n [ IS; O; O; O; O; C; O; \ +O];\\n [ O; O; O;mIS; O; O; C; O];\\n [ O; O;mIS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; pS; O; O];\\n [ O; C; O; O; mS; O; O; O];\\n [ \ +O; O; C; O; O; O; O; mS];\\n [ O; O; O; C; O; O; pS; O];\\n \ + [ O; pS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ +O];\\n [ O; O; O; mS; O; O; C; O];\\n [ O; O; pS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; IS; O; O; O];\\n [ O; C; O; O; O;mIS; O; O];\\n [ \ +O; O; C; O; O; O;mIS; O];\\n [ O; O; O; C; O; O; O; IS];\\n \ + [ IS; O; O; O; C; O; O; O];\\n [ O;mIS; O; O; O; C; O; \ +O];\\n [ O; O;mIS; O; O; O; C; O];\\n [ O; O; O; IS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; pS; O; O; O];\\n [ O; C; O; O; O; pS; O; O];\\n [ \ +O; O; C; O; O; O; pS; O];\\n [ O; O; O; C; O; O; O; pS];\\n \ + [ mS; O; O; O; C; O; O; O];\\n [ O; mS; O; O; O; C; O; \ +O];\\n [ O; O; mS; O; O; O; C; O];\\n [ O; O; O; mS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; pS; O; O];\\n [ O; C; O; O; pS; O; O; O];\\n [ \ +O; O; C; O; O; O; O; pS];\\n [ O; O; O; C; O; O; pS; O];\\n \ + [ O; mS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ +O];\\n [ O; O; O; mS; O; O; C; O];\\n [ O; O; mS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O;mIS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ +O; O; C; O; O; O; O;mIS];\\n [ O; O; O; C; O; O; IS; O];\\n \ + [ O; IS; O; O; C; O; O; O];\\n [mIS; O; O; O; O; C; O; \ +O];\\n [ O; O; O; IS; O; O; C; O];\\n [ O; O;mIS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; pS; O; O; O];\\n [ O; C; O; O; O; mS; O; O];\\n [ \ +O; O; C; O; O; O; pS; O];\\n [ O; O; O; C; O; O; O; mS];\\n \ + [ mS; O; O; O; C; O; O; O];\\n [ O; pS; O; O; O; C; O; \ +O];\\n [ O; O; mS; O; O; O; C; O];\\n [ O; O; O; pS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; pS];\\n [ \ +O; O; C; O; pS; O; O; O];\\n [ O; O; O; C; O; pS; O; O];\\n \ + [ O; O; mS; O; C; O; O; O];\\n [ O; O; O; mS; O; C; O; \ +O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; mS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O; pS];\\n [ O; C; O; O; O; O; pS; O];\\n [ \ +O; O; C; O; O; pS; O; O];\\n [ O; O; O; C; pS; O; O; O];\\n \ + [ O; O; O; mS; C; O; O; O];\\n [ O; O; mS; O; O; C; O; \ +O];\\n [ O; mS; O; O; O; O; C; O];\\n [ mS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O;mIS];\\n [ O; C; O; O; O; O; IS; O];\\n [ \ +O; O; C; O; O;mIS; O; O];\\n [ O; O; O; C; IS; O; O; O];\\n \ + [ O; O; O; IS; C; O; O; O];\\n [ O; O;mIS; O; O; C; O; \ +O];\\n [ O; IS; O; O; O; O; C; O];\\n [mIS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; mS];\\n [ \ +O; O; C; O; pS; O; O; O];\\n [ O; O; O; C; O; mS; O; O];\\n \ + [ O; O; mS; O; C; O; O; O];\\n [ O; O; O; pS; O; C; O; \ +O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; pS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O;mIS; O];\\n [ O; C; O; O; O; O; O;mIS];\\n [ \ +O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O; IS; O; O];\\n \ + [ O; O; IS; O; C; O; O; O];\\n [ O; O; O; IS; O; C; O; \ +O];\\n [mIS; O; O; O; O; O; C; O];\\n [ O;mIS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O;mIS];\\n [ O; C; O; O; O; O;mIS; O];\\n [ \ +O; O; C; O; O; IS; O; O];\\n [ O; O; O; C; IS; O; O; O];\\n \ + [ O; O; O; IS; C; O; O; O];\\n [ O; O; IS; O; O; C; O; \ +O];\\n [ O;mIS; O; O; O; O; C; O];\\n [mIS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O; O; mS];\\n [ O; C; O; O; O; O; pS; O];\\n [ \ +O; O; C; O; O; pS; O; O];\\n [ O; O; O; C; mS; O; O; O];\\n \ + [ O; O; O; pS; C; O; O; O];\\n [ O; O; mS; O; O; C; O; \ +O];\\n [ O; mS; O; O; O; O; C; O];\\n [ pS; O; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; O;mIS; O];\\n [ O; C; O; O; O; O; O; IS];\\n [ \ +O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O;mIS; O; O];\\n \ + [ O; O; IS; O; C; O; O; O];\\n [ O; O; O;mIS; O; C; O; \ +O];\\n [mIS; O; O; O; O; O; C; O];\\n [ O; IS; O; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; pS; O; O; O];\\n [ O; C; O; O; O; pS; O; O];\\n [ \ +O; O; C; O; O; O; mS; O];\\n [ O; O; O; C; O; O; O; mS];\\n \ + [ mS; O; O; O; C; O; O; O];\\n [ O; mS; O; O; O; C; O; \ +O];\\n [ O; O; pS; O; O; O; C; O];\\n [ O; O; O; pS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O; pS; O; O];\\n [ O; C; O; O; pS; O; O; O];\\n [ \ +O; O; C; O; O; O; O; mS];\\n [ O; O; O; C; O; O; mS; O];\\n \ + [ O; mS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ +O];\\n [ O; O; O; pS; O; O; C; O];\\n [ O; O; pS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; O;mIS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ +O; O; C; O; O; O; O; IS];\\n [ O; O; O; C; O; O;mIS; O];\\n \ + [ O; IS; O; O; C; O; O; O];\\n [mIS; O; O; O; O; C; O; \ +O];\\n [ O; O; O;mIS; O; O; C; O];\\n [ O; O; IS; O; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O; O; pS; O; O; O];\\n [ O; C; O; O; O; mS; O; O];\\n [ \ +O; O; C; O; O; O; mS; O];\\n [ O; O; O; C; O; O; O; pS];\\n \ + [ mS; O; O; O; C; O; O; O];\\n [ O; pS; O; O; O; C; O; \ +O];\\n [ O; O; pS; O; O; O; C; O];\\n [ O; O; O; mS; O; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZIIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ + O; O; O; O; O; O];\\n [ O; Ep; O; O; O; O; O; O];\\n [ \ +O; O; Ep; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ + [ O; O; O; O; Em; O; O; O];\\n [ O; O; O; O; O; Em; O; \ +O];\\n [ O; O; O; O; O; O; Em; O];\\n [ O; O; O; O; O; \ +O; O; Em]];\\n return matrix;\\n}\\n\\nfunction ExpZIXMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; \ + O; O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ \ +O; O; C; IS; O; O; O; O];\\n [ O; O; IS; C; O; O; O; O];\\n \ + [ O; O; O; O; C;mIS; O; O];\\n [ O; O; O; O;mIS; C; O; \ +O];\\n [ O; O; O; O; O; O; C;mIS];\\n [ O; O; O; O; O; \ +O;mIS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZIYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ + O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ +O; O; C; pS; O; O; O; O];\\n [ O; O; mS; C; O; O; O; O];\\n \ + [ O; O; O; O; C; mS; O; O];\\n [ O; O; O; O; pS; C; O; \ +O];\\n [ O; O; O; O; O; O; C; mS];\\n [ O; O; O; O; O; \ +O; pS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZIZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ + O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ +O; O; Ep; O; O; O; O; O];\\n [ O; O; O; Em; O; O; O; O];\\n \ + [ O; O; O; O; Em; O; O; O];\\n [ O; O; O; O; O; Ep; O; \ +O];\\n [ O; O; O; O; O; O; Em; O];\\n [ O; O; O; O; O; \ +O; O; Ep]];\\n return matrix;\\n}\\n\\nfunction ExpZXIMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ +IS; O; O; O; O; O];\\n [ O; C; O; IS; O; O; O; O];\\n [ \ +IS; O; C; O; O; O; O; O];\\n [ O; IS; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O;mIS; O];\\n [ O; O; O; O; O; C; \ +O;mIS];\\n [ O; O; O; O;mIS; O; C; O];\\n [ O; O; O; O; \ +O;mIS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZXXMatrix( t: \ +Double ) : Complex[][] {\\n let O = ZeroC();\\n let C = \ +Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ +Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ +Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ + let matrix = \\n [[ C; O; O; IS; O; O; O; O];\\n [ O; C; IS; \ + O; O; O; O; O];\\n [ O; IS; C; O; O; O; O; O];\\n [ IS; \ +O; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; O;mIS];\\n \ +[ O; O; O; O; O; C;mIS; O];\\n [ O; O; O; O; O;mIS; C; \ +O];\\n [ O; O; O; O;mIS; O; O; C]];\\n return \ +matrix;\\n}\\n\\nfunction ExpZXYMatrix( t: Double ) : Complex[][] {\\n let \ +O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ +Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ +Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ +pS; O; O; O; O];\\n [ O; C; mS; O; O; O; O; O];\\n [ O; \ +pS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ +[ O; O; O; O; C; O; O; mS];\\n [ O; O; O; O; O; C; pS; \ +O];\\n [ O; O; O; O; O; mS; C; O];\\n [ O; O; O; O; pS; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZXZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ +IS; O; O; O; O; O];\\n [ O; C; O;mIS; O; O; O; O];\\n [ \ +IS; O; C; O; O; O; O; O];\\n [ O;mIS; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O;mIS; O];\\n [ O; O; O; O; O; C; O; \ +IS];\\n [ O; O; O; O;mIS; O; C; O];\\n [ O; O; O; O; O; \ +IS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZYIMatrix( t: Double \ +) : Complex[][] {\\n let O = ZeroC();\\n let C = \ +Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ +Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ +Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ + let matrix = \\n [[ C; O; pS; O; O; O; O; O];\\n [ O; C; O; \ +pS; O; O; O; O];\\n [ mS; O; C; O; O; O; O; O];\\n [ O; \ +mS; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; mS; O];\\n \ +[ O; O; O; O; O; C; O; mS];\\n [ O; O; O; O; pS; O; C; \ +O];\\n [ O; O; O; O; O; pS; O; C]];\\n return \ +matrix;\\n}\\n\\nfunction ExpZYXMatrix( t: Double ) : Complex[][] {\\n let \ +O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ +Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ +Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ +pS; O; O; O; O];\\n [ O; C; pS; O; O; O; O; O];\\n [ O; \ +mS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ +[ O; O; O; O; C; O; O; mS];\\n [ O; O; O; O; O; C; mS; \ +O];\\n [ O; O; O; O; O; pS; C; O];\\n [ O; O; O; O; pS; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZYYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ + O;mIS; O; O; O; O];\\n [ O; C; IS; O; O; O; O; O];\\n [ \ +O; IS; C; O; O; O; O; O];\\n [mIS; O; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O; O; IS];\\n [ O; O; O; O; O; C;mIS; \ +O];\\n [ O; O; O; O; O;mIS; C; O];\\n [ O; O; O; O; IS; \ +O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZYZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ +pS; O; O; O; O; O];\\n [ O; C; O; mS; O; O; O; O];\\n [ \ +mS; O; C; O; O; O; O; O];\\n [ O; pS; O; C; O; O; O; O];\\n \ + [ O; O; O; O; C; O; mS; O];\\n [ O; O; O; O; O; C; O; \ +pS];\\n [ O; O; O; O; pS; O; C; O];\\n [ O; O; O; O; O; \ +mS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZZIMatrix( t: Double \ +) : Complex[][] {\\n let O = ZeroC();\\n let C = \ +Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ +Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ +Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ + let matrix = \\n [[ Ep; O; O; O; O; O; O; O];\\n [ O; Ep; O; \ + O; O; O; O; O];\\n [ O; O; Em; O; O; O; O; O];\\n [ O; \ +O; O; Em; O; O; O; O];\\n [ O; O; O; O; Em; O; O; O];\\n \ +[ O; O; O; O; O; Em; O; O];\\n [ O; O; O; O; O; O; Ep; \ +O];\\n [ O; O; O; O; O; O; O; Ep]];\\n return \ +matrix;\\n}\\n\\nfunction ExpZZXMatrix( t: Double ) : Complex[][] {\\n let \ +O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ +Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ +Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ +ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ +O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ O; \ +O; C;mIS; O; O; O; O];\\n [ O; O;mIS; C; O; O; O; O];\\n \ +[ O; O; O; O; C;mIS; O; O];\\n [ O; O; O; O;mIS; C; O; \ +O];\\n [ O; O; O; O; O; O; C; IS];\\n [ O; O; O; O; O; \ +O; IS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZZYMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ + O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ +O; O; C; mS; O; O; O; O];\\n [ O; O; pS; C; O; O; O; O];\\n \ + [ O; O; O; O; C; mS; O; O];\\n [ O; O; O; O; pS; C; O; \ +O];\\n [ O; O; O; O; O; O; C; pS];\\n [ O; O; O; O; O; \ +O; mS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZZZMatrix( t: Double ) \ +: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ + let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ +let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ +Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ + O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ +O; O; Em; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ + [ O; O; O; O; Em; O; O; O];\\n [ O; O; O; O; O; Ep; O; \ +O];\\n [ O; O; O; O; O; O; Ep; O];\\n [ O; O; O; O; O; \ +O; O; Em]];\\n return matrix;\\n}\\n\\n\"\>"], "Output", + CellChangeTimes->{{3.7187281118107567`*^9, 3.7187281162899294`*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"\"\\"", "~~", + RowBox[{"StringJoin", "@@", "#"}], "~~", "\"\\""}], "&"}], + ")"}], "/@", + RowBox[{"Tuples", "[", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], + "}"}], ",", + RowBox[{"{", + RowBox[{ + "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], + "}"}]}], "}"}], "]"}]}], "//", + RowBox[{ + RowBox[{"AsQArr", "[", + RowBox[{"#", ",", "1"}], "]"}], "&"}]}]], "Input", + CellChangeTimes->{{3.718729478643132*^9, 3.7187295979697523`*^9}}], + +Cell[BoxData["\<\" \ +[ExpIIMatrix;ExpIXMatrix;ExpIZMatrix;ExpIYMatrix;ExpXIMatrix;ExpXXMatrix;\ +ExpXZMatrix;ExpXYMatrix;ExpZIMatrix;ExpZXMatrix;ExpZZMatrix;ExpZYMatrix;\ +ExpYIMatrix;ExpYXMatrix;ExpYZMatrix;ExpYYMatrix]\"\>"], "Output", + CellChangeTimes->{{3.7187294964524217`*^9, 3.718729502316864*^9}, { + 3.718729546251667*^9, 3.718729598585673*^9}}] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"\"\\"", "~~", + RowBox[{"StringJoin", "@@", "#"}], "~~", "\"\\""}], "&"}], + ")"}], "/@", + RowBox[{"Tuples", "[", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], + "}"}], ",", + RowBox[{"{", + RowBox[{ + "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], + "}"}], ",", + RowBox[{"{", + RowBox[{ + "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], + "}"}]}], "}"}], "]"}]}], "//", + RowBox[{ + RowBox[{"AsQArr", "[", + RowBox[{"#", ",", "1"}], "]"}], "&"}]}]], "Input", + CellChangeTimes->{{3.718729648233922*^9, 3.7187296517195964`*^9}}], + +Cell[BoxData["\<\" \ +[ExpIIIMatrix;ExpIIXMatrix;ExpIIZMatrix;ExpIIYMatrix;ExpIXIMatrix;\ +ExpIXXMatrix;ExpIXZMatrix;ExpIXYMatrix;ExpIZIMatrix;ExpIZXMatrix;ExpIZZMatrix;\ +ExpIZYMatrix;ExpIYIMatrix;ExpIYXMatrix;ExpIYZMatrix;ExpIYYMatrix;ExpXIIMatrix;\ +ExpXIXMatrix;ExpXIZMatrix;ExpXIYMatrix;ExpXXIMatrix;ExpXXXMatrix;ExpXXZMatrix;\ +ExpXXYMatrix;ExpXZIMatrix;ExpXZXMatrix;ExpXZZMatrix;ExpXZYMatrix;ExpXYIMatrix;\ +ExpXYXMatrix;ExpXYZMatrix;ExpXYYMatrix;ExpZIIMatrix;ExpZIXMatrix;ExpZIZMatrix;\ +ExpZIYMatrix;ExpZXIMatrix;ExpZXXMatrix;ExpZXZMatrix;ExpZXYMatrix;ExpZZIMatrix;\ +ExpZZXMatrix;ExpZZZMatrix;ExpZZYMatrix;ExpZYIMatrix;ExpZYXMatrix;ExpZYZMatrix;\ +ExpZYYMatrix;ExpYIIMatrix;ExpYIXMatrix;ExpYIZMatrix;ExpYIYMatrix;ExpYXIMatrix;\ +ExpYXXMatrix;ExpYXZMatrix;ExpYXYMatrix;ExpYZIMatrix;ExpYZXMatrix;ExpYZZMatrix;\ +ExpYZYMatrix;ExpYYIMatrix;ExpYYXMatrix;ExpYYZMatrix;ExpYYYMatrix]\"\>"], \ +"Output", + CellChangeTimes->{3.718729670538804*^9}] +}, Open ]] +}, Open ]] +}, +WindowSize->{759, 833}, +WindowMargins->{{Automatic, 462}, {48, Automatic}}, +FrontEndVersion->"11.0 for Microsoft Windows (64-bit) (July 28, 2016)", +StyleDefinitions->"Default.nb" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[580, 22, 102, 1, 72, "Chapter"], +Cell[685, 25, 2677, 77, 240, "Input"], +Cell[3365, 104, 1523, 42, 107, "Input"], +Cell[4891, 148, 94, 1, 30, "Input"] +}, Open ]], +Cell[CellGroupData[{ +Cell[5022, 154, 106, 1, 72, "Chapter"], +Cell[CellGroupData[{ +Cell[5153, 159, 136, 2, 70, "Section"], +Cell[5292, 163, 1616, 54, 335, "Input"], +Cell[6911, 219, 1057, 28, 88, "Input"], +Cell[CellGroupData[{ +Cell[7993, 251, 423, 12, 30, "Input"], +Cell[8419, 265, 245, 3, 30, "Output"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[8725, 275, 153, 3, 72, "Chapter"], +Cell[8881, 280, 2558, 61, 88, "Input"], +Cell[11442, 343, 844, 25, 107, "Input"], +Cell[CellGroupData[{ +Cell[12311, 372, 169, 3, 30, "Input"], +Cell[12483, 377, 495, 6, 183, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[13015, 388, 170, 3, 30, "Input"], +Cell[13188, 393, 134, 2, 30, "Output"] +}, Open ]], +Cell[13337, 398, 896, 15, 259, "Input"], +Cell[CellGroupData[{ +Cell[14258, 417, 1287, 31, 88, "Input"], +Cell[15548, 450, 53253, 679, 30735, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[68838, 1134, 697, 22, 50, "Input"], +Cell[69538, 1158, 356, 5, 88, "Output"] +}, Open ]], +Cell[CellGroupData[{ +Cell[69931, 1168, 830, 26, 69, "Input"], +Cell[70764, 1196, 939, 13, 254, "Output"] +}, Open ]] +}, Open ]] +} +] +*) + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs new file mode 100644 index 00000000000..3897780db25 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite.VeryLong { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Simulation.TestSuite; + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Math; + + + operation ExpTestHelper (pauliIds : Int[]) : Unit { + let pauli = PauliById(pauliIds); + + using (qubits = Qubit[Length(pauliIds)]) { + AssertUnitaryWithAdjoint(ExpMultiPauliMatrix(pauli, 0.1), Exp(pauli, 0.1, _), qubits); + } + } + + + operation ExpThreeQubitTest () : Unit { + if (IsFullSimulator()) { + IterateThroughCartesianPower(3, NumberOfPaulies(), ExpTestHelper); + } + } + + + operation OneQubitUnitariesWithTwoControlsTest () : Unit { + MultiControlledQubitOperationsTester(2); + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs new file mode 100644 index 00000000000..00ebd9ba89f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Simulation.TestSuite { + open Microsoft.Quantum.Simulation.TestSuite.Math; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Intrinsic; + + + operation TwoQubitUnitaryTestHelper (matrix : RowMajorMatrix, unitary : (Qubit[] => Unit : Adjoint)) : Unit { + let totalQubits = MaxQubitsToAllocateForTwoQubitTests(); + + using (qubits = Qubit[totalQubits]) { + for (i in 0 .. totalQubits - 1) { + for (j in 0 .. totalQubits - 1) { + if (i != j) { + AssertUnitaryWithAdjoint(matrix, unitary, [qubits[i], qubits[j]]); + } + } + } + } + } + + + operation CNOTTestHelper (qubits : Qubit[]) : Unit is Adj { + if (Length(qubits) != 2) { + fail $"operation expects 2 qubits"; + } + + CNOT(qubits[0], qubits[1]); + } + + + operation CNOTTwoQubitTest () : Unit { + TwoQubitUnitaryTestHelper(CNOTMatrix(), CNOTTestHelper); + } + + + operation SWAPTestHelper (qubits : Qubit[]) : Unit is Adj { + if (Length(qubits) != 2) { + fail $"operation expects 2 qubits"; + } + + SWAP(qubits[0], qubits[1]); + } + + + operation SWAPTwoQubitTest () : Unit { + TwoQubitUnitaryTestHelper(SWAPMatrix(), SWAPTestHelper); + } + + + operation ExpTwoQubitTestHelper (pauliIds : Int[]) : Unit { + + let pauli = PauliById(pauliIds); + Message($"{pauli}"); + TwoQubitUnitaryTestHelper(ExpMultiPauliMatrix(pauli, 0.1), Exp(pauli, 0.1, _)); + } + + + operation ExpTwoQubitTest () : Unit { + + + if (IsFullSimulator()) { + IterateThroughCartesianPower(2, NumberOfPaulies(), ExpTwoQubitTestHelper); + } + } + + + operation ControlledTestHelper (qubitOperation : (Qubit => Unit : Controlled, Adjoint), target : Qubit[]) : Unit { + + body (...) { + + if (Length(target) != 2) { + fail $"expecting 2 qubits as input"; + } + + Controlled qubitOperation([target[1]], target[0]); + } + + adjoint invert; + } + + + operation ControlledOneQubitOperationsTwoQubitTest () : Unit { + for (test in OneQubitTestList()) { + let shouldExecute = + IsFullSimulator() or + (IsStabilizerSimulator() and LevelOfCliffordHierarchy(test) <= 0) or + (IsReversibleSimulator() and FixesComputationalBasis(test)); + + if (shouldExecute) { + let map = OperationMap(test); + TwoQubitUnitaryTestHelper(ControlledMatrix(1, OperationMatrix(test)), ControlledTestHelper(map, _)); + Message($"Passed:{map}"); + } + } + } + +} + + diff --git a/src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs b/src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs new file mode 100644 index 00000000000..8ee972883a8 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs @@ -0,0 +1,446 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Common; +using Microsoft.Quantum.Simulation.Simulators.Exceptions; +using System; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class QubitManagerTests + { + /// + /// Test for QubitManager. + /// + [Fact] + public void TestQubitManager() + { + QubitManager qm = new QubitManager(20); + + // Test allocation of single qubit + Qubit q1 = qm.Allocate(); + Assert.True(q1.Id == 0); + + // Test allocation of multiple qubits + IQArray qa1 = qm.Allocate(4); + Assert.True(qa1.Length == 4); + Assert.True(qa1[0].Id == 1); + Assert.True(qa1[1].Id == 2); + Assert.True(qa1[2].Id == 3); + Assert.True(qa1[3].Id == 4); + + // Test reuse of deallocated qubits + qm.Release(qa1[1]); + + Qubit q2 = qm.Allocate(); + Assert.True(q2.Id == 2); + + IQArray qa2 = qm.Allocate(3); + Assert.True(qa2.Length == 3); + Assert.True(qa2[0].Id == 5); + Assert.True(qa2[1].Id == 6); + Assert.True(qa2[2].Id == 7); + + qm.Release(qa2); + + Qubit q3 = qm.Allocate(); + Assert.True(q3.Id == 5); + + Qubit q4 = qm.Allocate(); + Assert.True(q4.Id == 6); + + Qubit q5 = qm.Allocate(); + Assert.True(q5.Id == 7); + + // Test borrowing + Qubit[] exclusion = new Qubit[4]; + exclusion[0] = qa1[0]; + exclusion[1] = qa1[2]; + exclusion[2] = q4; + exclusion[3] = q3; + + long qubitsAvailable; + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qab = qm.Borrow(5, exclusion); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); + Assert.True(qab[0].Id == 0); + Assert.True(qab[1].Id == 2); + Assert.True(qab[2].Id == 4); + Assert.True(qab[3].Id == 5); + Assert.True(qab[4].Id == 8); + + Qubit q6 = qm.Allocate(); + Assert.True(q6.Id == 9); + + // Test borrowing of the same qubit again + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb1 = qm.Borrow(1, exclusion); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 0); + Assert.True(qb1[0].Id == 0); + qm.Return(qb1[0]); + + qm.Return(qab); + + // Test that qubit allocated for borrowing is freed after being returned + Qubit q7 = qm.Allocate(); + Assert.True(q7.Id == 8); + + // Test allocation of qubits out of order. + qm.Release(q4); + qm.Release(qa1[2]); + qm.Release(q1); + + IQArray qa3 = qm.Allocate(4); + Assert.True(qa3.Length == 4); + Assert.True(qa3[0].Id == 0); + Assert.True(qa3[1].Id == 3); + Assert.True(qa3[2].Id == 6); + Assert.True(qa3[3].Id == 10); + + // Test Disabling qubits + Qubit q8 = qm.Allocate(); + Assert.True(q8.Id == 11); + qm.Disable(q8); + IQArray qab2 = qm.Borrow(12, null); + Assert.True(qab2[11].Id == 12); // make sure 11 is not borrowed. + qm.Release(q8); + qm.Return(qab2); + + IQArray qa4 = qm.Allocate(2); + Assert.True(qa4[0].Id == 12); // make sure 11 is not reused. + Assert.True(qa4[1].Id == 13); // make sure 11 is not reused. + qm.Release(qa4); + + + { // Test allocating zero qubits + IQArray n_q; + n_q = qm.Allocate(0); + Assert.True(n_q.Length == 0); + n_q = qm.Borrow(0, exclusion); + Assert.True(n_q.Length == 0); + } + + // NOTE: The below tests trigger exceptions, which but the QubitManager into a bad + // state where it shouldn't be reused. Creating a separate QubitManager in a small + // scope to test the exceptions avoids having one test case pollute the other. + + // Test for over allocating and over borrowing. + { + QubitManager qm_small = new QubitManager(2); + IQArray n_q; + Assert.Throws(() => n_q = qm_small.Allocate(5)); + } + { + QubitManager qm_small = new QubitManager(2); + IQArray n_q; + Assert.Throws(() => n_q = qm_small.Borrow(5, null)); + } + + // Test for negative input to allocate and borrow. + { + QubitManager qm_small = new QubitManager(20); + IQArray n_q; + Assert.Throws(() => n_q = qm_small.Allocate(-2)); + } + { + QubitManager qm_small = new QubitManager(20); + IQArray n_q; + Assert.Throws(() => n_q = qm_small.Borrow(-2, null)); + } + } + + /// + /// Test for QubitManager. + /// + [Fact] + public void TestQubitManagerDiscouragingReuse() + { + { // BLOCK testing mayExtendCapacity:false + QubitManager qm = new QubitManager(10, mayExtendCapacity: false, disableBorrowing: false, encourageReuse: false); + + // Test allocation of single qubit + Qubit q1 = qm.Allocate(); + Assert.True(q1.Id == 0); + + // Test allocation of multiple qubits + IQArray qa1 = qm.Allocate(4); + Assert.True(qa1.Length == 4); + Assert.True(qa1[0].Id == 1); + Assert.True(qa1[1].Id == 2); + Assert.True(qa1[2].Id == 3); + Assert.True(qa1[3].Id == 4); + + // Test reuse of deallocated qubits + qm.Release(qa1[1]); + + Qubit q2 = qm.Allocate(); + Assert.True(q2.Id == 5); + + IQArray qa2 = qm.Allocate(3); + Assert.True(qa2.Length == 3); + Assert.True(qa2[0].Id == 6); + Assert.True(qa2[1].Id == 7); + Assert.True(qa2[2].Id == 8); + + qm.Release(qa2); + + Qubit q3 = qm.Allocate(); + Assert.True(q3.Id == 9); + + Qubit q4 = qm.Allocate(); + Assert.True(q4.Id == 2); + + Qubit q5 = qm.Allocate(); + Assert.True(q5.Id == 8); + } + + { // BLOCK testing mayExtendCapacity:true + QubitManager qm = new QubitManager(10, mayExtendCapacity: true, disableBorrowing: false, encourageReuse: false); + + // Test allocation of single qubit + Qubit q1 = qm.Allocate(); + Assert.True(q1.Id == 0); + + // Test allocation of multiple qubits + IQArray qa1 = qm.Allocate(4); + Assert.True(qa1.Length == 4); + Assert.True(qa1[0].Id == 1); + Assert.True(qa1[1].Id == 2); + Assert.True(qa1[2].Id == 3); + Assert.True(qa1[3].Id == 4); + + // Test reuse of deallocated qubits + qm.Release(qa1[1]); + + Qubit q2 = qm.Allocate(); + Assert.True(q2.Id == 5); + + IQArray qa2 = qm.Allocate(3); + Assert.True(qa2.Length == 3); + Assert.True(qa2[0].Id == 6); + Assert.True(qa2[1].Id == 7); + Assert.True(qa2[2].Id == 8); + + qm.Release(qa2); + + Qubit q3 = qm.Allocate(); + Assert.True(q3.Id == 9); + + Qubit q4 = qm.Allocate(); + Assert.True(q4.Id == 10); + + Qubit q5 = qm.Allocate(); + Assert.True(q5.Id == 11); + } + } + + /// + /// Test for QubitManagerTrackingScope. + /// + [Fact] + public void TestQubitManagerTrackingScope() + { + QubitManagerTrackingScope qm = new QubitManagerTrackingScope(20); + + Qubit q1 = qm.Allocate(); + Assert.True(q1.Id == 0); + + IQArray qa1 = qm.Allocate(4); + Assert.True(qa1.Length == 4); + Assert.True(qa1[0].Id == 1); + Assert.True(qa1[1].Id == 2); + Assert.True(qa1[2].Id == 3); + Assert.True(qa1[3].Id == 4); + + Qubit q2 = qm.Allocate(); + Assert.True(q2.Id == 5); + + qm.OnOperationStart(null, qa1); + + long qubitsAvailable; + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb1 = qm.Borrow(3); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); + Assert.True(qb1[0].Id == 0); + Assert.True(qb1[1].Id == 5); + Assert.True(qb1[2].Id == 6); + qm.Return(qb1[0]); + qm.Return(qb1[2]); + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb2 = qm.Borrow(3); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 2); + Assert.True(qb2[0].Id == 0); + Assert.True(qb2[1].Id == 6); + Assert.True(qb2[2].Id == 7); + + { + qm.OnOperationStart(null, qb2); + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb3 = qm.Borrow(3); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 0); + Assert.True(qb3[0].Id == 1); + Assert.True(qb3[1].Id == 2); + Assert.True(qb3[2].Id == 3); + + qm.OnOperationEnd(null, QVoid.Instance); + } + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb4 = qm.Borrow(1); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); + Assert.True(qb4[0].Id == 8); + + qm.OnOperationEnd(null, QVoid.Instance); + } + + [Fact] + public void TestQubitManagerDisabledBorrowing() + { + QubitManagerTrackingScope qm = new QubitManagerTrackingScope(20, mayExtendCapacity: true, disableBorrowing: true); + + Qubit q1 = qm.Allocate(); + Assert.True(q1.Id == 0); + + IQArray qa1 = qm.Allocate(4); + Assert.True(qa1.Length == 4); + Assert.True(qa1[0].Id == 1); + Assert.True(qa1[1].Id == 2); + Assert.True(qa1[2].Id == 3); + Assert.True(qa1[3].Id == 4); + + Qubit q2 = qm.Allocate(); + Assert.True(q2.Id == 5); + + qm.OnOperationStart(null, qa1); + + long qubitsAvailable; + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb1 = qm.Borrow(3); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 3); + Assert.True(qb1[0].Id == 6); + Assert.True(qb1[1].Id == 7); + Assert.True(qb1[2].Id == 8); + + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 11); + qm.Return(qb1[0]); + qm.Return(qb1[2]); + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 13); + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb2 = qm.Borrow(3); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 3); + Assert.True(qb2[0].Id == 8); + Assert.True(qb2[1].Id == 6); + Assert.True(qb2[2].Id == 9); + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 10); + + { + qm.OnOperationStart(null, qb2); + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb3 = qm.Borrow(3); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 3); + Assert.True(qb3[0].Id == 10); + Assert.True(qb3[1].Id == 11); + Assert.True(qb3[2].Id == 12); + + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 7); + + qm.OnOperationEnd(null, QVoid.Instance); + } + + qm.Release(qb2[1]); + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 8); + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb4 = qm.Borrow(1); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); + Assert.True(qb4[0].Id == 6); + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 7); + + qm.OnOperationEnd(null, QVoid.Instance); + } + + [Fact] + public void TestQubitManagerGrowth() + { + QubitManagerTrackingScope qm = new QubitManagerTrackingScope(7, mayExtendCapacity : true, disableBorrowing: false); + + Qubit q1 = qm.Allocate(); + Assert.True(q1.Id == 0); + + IQArray qa1 = qm.Allocate(4); + Assert.True(qa1.Length == 4); + Assert.True(qa1[0].Id == 1); + Assert.True(qa1[1].Id == 2); + Assert.True(qa1[2].Id == 3); + Assert.True(qa1[3].Id == 4); + + Qubit q2 = qm.Allocate(); + Assert.True(q2.Id == 5); + + qm.OnOperationStart(null, qa1); + + long qubitsAvailable; + + qubitsAvailable = qm.GetFreeQubitsCount(); + IQArray qb1 = qm.Borrow(3); + Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); + Assert.True(qb1[0].Id == 0); + Assert.True(qb1[1].Id == 5); + Assert.True(qb1[2].Id == 6); + qm.Return(qb1[0]); + qm.Return(qb1[2]); + + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 1); + IQArray qb2 = qm.Borrow(3); // This should grow qubit capacity + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 6); + Assert.True(qb2[0].Id == 0); + Assert.True(qb2[1].Id == 6); + Assert.True(qb2[2].Id == 7); + + qm.OnOperationEnd(null, null); + + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 6); + IQArray qa2 = qm.Allocate(4); + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 2); + Assert.True(qa2.Length == 4); + Assert.True(qa2[0].Id == 8); + Assert.True(qa2[1].Id == 9); + Assert.True(qa2[2].Id == 10); + Assert.True(qa2[3].Id == 11); + + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 2); + qm.Release(qa2[0]); + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 3); + + IQArray qa3 = qm.Allocate(4); // This should grow qubit capacity + qubitsAvailable = qm.GetFreeQubitsCount(); + Assert.True(qubitsAvailable == 13); + Assert.True(qa3.Length == 4); + Assert.True(qa3[0].Id == 8); + Assert.True(qa3[1].Id == 12); + Assert.True(qa3[2].Id == 13); + Assert.True(qa3[3].Id == 14); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/RangeTests.cs b/src/Simulation/Simulators.Type2.Tests/RangeTests.cs new file mode 100644 index 00000000000..516705c351f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/RangeTests.cs @@ -0,0 +1,174 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Tests.CoreOperations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + using Helper = Microsoft.Quantum.Simulation.Simulators.Tests.OperationsTestHelper; + + public class RangeTests + { + [Fact] + public void RangeConstructor() + { + // The SimulatorBase class only implements operations for Qubit management, + // i.e. Allocate/Release: + var subject = new QRange(1, 5, 10); + + Assert.Equal(1, subject.Start); + Assert.Equal(5, subject.Step); + Assert.Equal(10, subject.End); + + subject = new QRange(10, -5, 0); + + Assert.Equal(10, subject.Start); + Assert.Equal(-5, subject.Step); + Assert.Equal(0, subject.End); + } + + [Fact] + public void RangeSamples() + { + var subject = new QRange(1, 3); + var expected = new long[] { 1, 2, 3 }; + Assert.Equal(expected, subject); + + subject = new QRange(2, 2, 5); + expected = new long[] { 2, 4 }; + Assert.Equal(expected, subject); + + subject = new QRange(2, 2, 5); + expected = new long[] { 2, 4 }; + Assert.Equal(expected, subject); + + subject = new QRange(2, 2, 6); + expected = new long[] { 2, 4, 6 }; + Assert.Equal(expected, subject); + + subject = new QRange(6, -2, 2); + expected = new long[] { 6, 4, 2 }; + Assert.Equal(expected, subject); + + subject = new QRange(2, 6, 7); + expected = new long[] { 2 }; + Assert.Equal(expected, subject); + + subject = new QRange(-1, 2, 10); + expected = new long[] { -1, 1, 3, 5, 7, 9 }; + Assert.Equal(expected, subject); + + subject = new QRange(-1, -1, -5); + expected = new long[] { -1, -2, -3, -4, -5 }; + Assert.Equal(expected, subject); + + subject = new QRange(1, 1); + expected = new long[] { 1 }; + Assert.Equal(expected, subject); + } + + [Fact] + public void EmptyRangeSamples() + { + var subject = new QRange(2, 2, 1); + Assert.Empty(subject); + Assert.Empty(subject.Reverse()); + + subject = new QRange(2, 1); + Assert.Empty(subject); + Assert.Empty(subject.Reverse()); + + subject = new QRange(1, -1, 2); + Assert.Empty(subject); + Assert.Empty(subject.Reverse()); + + subject = new QRange(1, 2, 0); + Assert.Empty(subject); + Assert.Empty(subject.Reverse()); + } + + [Fact] + public void InvalidRangeStep() + { + Assert.Throws("step", () => { new QRange(1, 0, 10); }); + } + + [Fact] + public void RangeIteration() + { + var subject = new QRange(6, -2, 2); + var expected = new long[] { 6, 4, 2 }; + var actual = new List(); + + foreach (var i in subject) + { + actual.Add(i); + } + Assert.Equal(expected, actual); + + actual = new List(); + foreach (var j in new QRange(6, -(2L), 2)) + { + actual.Add(j); + } + Assert.Equal(expected, actual); + } + + [Fact] + public void RangeReversal() + { + var subject = new QRange(6, -2, 2); + var expected = new QRange(2, 2, 6); + Assert.Equal(expected, subject.Reverse()); + + subject = new QRange(1, 1, 0); + expected = new QRange(0, -1, 1); + Assert.Equal(expected, subject.Reverse()); + + subject = new QRange(1, 2, 2); + expected = new QRange(1, -2, 1); + Assert.Equal(expected, subject.Reverse()); + } + + [Fact] + public void SimpleRange() + { + Helper.RunWithMultipleSimulators((s) => + { + IgnorableAssert.Disable(); + try + { + //We have to call the method in the same thread for IgnorableAssert.Disable() to work + s.Get().Apply(QVoid.Instance); + } + finally + { + IgnorableAssert.Enable(); + } + + var tracer = s.GetTracer(); + + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (0L))); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1L))); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (2L))); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3L))); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (4L))); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (5L))); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (6L))); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (7L))); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (8L))); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (9L))); + Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (10L))); + Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (11L))); + + }); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs b/src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs new file mode 100644 index 00000000000..2d8ee9a75cd --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs @@ -0,0 +1,821 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable enable + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Quantum.Simulation.Core; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class RuntimeMetadataEqualityTests + { + [Fact] + public void WrongType() + { + var a = new RuntimeMetadata { }; + var i = 5; + Assert.False(a.Equals(i)); + } + + [Fact] + public void NullEquality() + { + var a = new RuntimeMetadata { }; + RuntimeMetadata? b = null; + Assert.NotEqual(a, b); + Assert.NotEqual(b, a); + } + + [Fact] + public void CheckEquality() + { + var a = new RuntimeMetadata() + { + Label = "H", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { }, + }; + var b = new RuntimeMetadata() + { + Label = "H", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { }, + }; + Assert.Equal(a, b); + Assert.Equal(a.GetHashCode(), b.GetHashCode()); + + b.Label = "X"; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + b.Label = "H"; + + b.FormattedNonQubitArgs = "(1)"; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + b.FormattedNonQubitArgs = ""; + + b.IsAdjoint = true; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + b.IsAdjoint = false; + + b.IsControlled = true; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + b.IsControlled = false; + + b.IsMeasurement = true; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + b.IsMeasurement = false; + + b.IsComposite = true; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + b.IsComposite = false; + } + + [Fact] + public void ControlsEquality() + { + var a = new RuntimeMetadata() + { + Controls = new List() { }, + }; + var b = new RuntimeMetadata() + { + Controls = new List() { }, + }; + Assert.Equal(a, b); + Assert.Equal(a.GetHashCode(), b.GetHashCode()); + + b.Controls = new List() { new FreeQubit(1) }; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + + a.Controls = new List() { new FreeQubit(1) }; + Assert.Equal(a, b); + Assert.Equal(a.GetHashCode(), b.GetHashCode()); + } + + [Fact] + public void TargetsEquality() + { + var a = new RuntimeMetadata() + { + Targets = new List() { }, + }; + var b = new RuntimeMetadata() + { + Targets = new List() { }, + }; + Assert.Equal(a, b); + Assert.Equal(a.GetHashCode(), b.GetHashCode()); + + b.Targets = new List() { new FreeQubit(1) }; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + + a.Targets = new List() { new FreeQubit(1) }; + Assert.Equal(a, b); + Assert.Equal(a.GetHashCode(), b.GetHashCode()); + } + + [Fact] + public void ChildrenEquality() + { + var a = new RuntimeMetadata() + { + Children = new[] + { + new List(), + new List(), + }, + }; + var b = new RuntimeMetadata() + { + Children = new[] + { + new List(), + new List(), + }, + }; + Assert.Equal(a, b); + Assert.Equal(a.GetHashCode(), b.GetHashCode()); + + var aChildren = a.Children.ToList(); + aChildren[0] = new List() { new RuntimeMetadata() { Label = "H" } }; + a.Children = aChildren; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + + var bChildren = b.Children.ToList(); + bChildren[0] = new List() { new RuntimeMetadata() { Label = "X" } }; + b.Children = bChildren; + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + + bChildren[0] = new List() { new RuntimeMetadata() { Label = "H" } }; + Assert.Equal(a, b); + Assert.Equal(a.GetHashCode(), b.GetHashCode()); + + b.Children = b.Children.SkipLast(1); + Assert.NotEqual(a, b); + Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); + } + } + + public class IntrinsicTests + { + [Fact] + public void CNOT() + { + var control = new FreeQubit(1); + var target = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn((control, target)); + var expected = new RuntimeMetadata() + { + Label = "X", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { control }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void CCNOT() + { + var control1 = new FreeQubit(0); + var control2 = new FreeQubit(2); + var target = new FreeQubit(1); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn((control1, control2, target)); + var expected = new RuntimeMetadata() + { + Label = "X", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { control1, control2 }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void Swap() + { + var q1 = new FreeQubit(0); + var q2 = new FreeQubit(1); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn((q1, q2)); + var expected = new RuntimeMetadata() + { + Label = "SWAP", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { q1, q2 }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void Ry() + { + var target = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn((2.1, target)); + var expected = new RuntimeMetadata() + { + Label = "Ry", + FormattedNonQubitArgs = "(" + 2.1 + ")", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void M() + { + var measureQubit = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(measureQubit); + var expected = new RuntimeMetadata() + { + Label = "M", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = true, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { measureQubit }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void Reset() + { + var target = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(target); + var expected = new RuntimeMetadata() + { + Label = "Reset", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void ResetAll() + { + IQArray targets = new QArray(new[] { new FreeQubit(0) }); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(targets); + var expected = new RuntimeMetadata() + { + Label = "ResetAll", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = true, + Children = null, + Controls = new List() { }, + Targets = targets, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + } + + public class MeasurementTests + { + [Fact] + public void MResetX() + { + var measureQubit = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(measureQubit); + var expected = new RuntimeMetadata() + { + Label = "MResetX", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = true, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { measureQubit }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void MResetY() + { + var measureQubit = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(measureQubit); + var expected = new RuntimeMetadata() + { + Label = "MResetY", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = true, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { measureQubit }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void MResetZ() + { + var measureQubit = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(measureQubit); + var expected = new RuntimeMetadata() + { + Label = "MResetZ", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = true, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { measureQubit }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + } + + public class CustomCircuitTests + { + [Fact] + public void EmptyOperation() + { + var measureQubit = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(QVoid.Instance); + var expected = new RuntimeMetadata() + { + Label = "Empty", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void OperationAsArgument() + { + var q = new FreeQubit(0); + var opArg = new QuantumSimulator().Get(); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn((opArg, q)); + var expected = new RuntimeMetadata() + { + Label = "WrapperOp", + FormattedNonQubitArgs = "(HOp)", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { q }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void NestedOperation() + { + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(QVoid.Instance); + var expected = new RuntimeMetadata() + { + Label = "NestedOp", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void DuplicateQubitArgs() + { + var q = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn((q, q)); + var expected = new RuntimeMetadata() + { + Label = "TwoQubitOp", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { q }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void QArrayArgs() + { + var op = new QuantumSimulator().Get(); + IQArray bits = new QArray(new bool[] { false, true }); + var args = op.__dataIn(bits); + var expected = new RuntimeMetadata() + { + Label = "BoolArrayOp", + FormattedNonQubitArgs = "[False, True]", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + } + + public class UDTTests + { + [Fact] + public void FooUDTOp() + { + Qubit target = new FreeQubit(0); + var op = new QuantumSimulator().Get(); + var args = op.__dataIn(new Circuits.FooUDT(("bar", (target, 2.1)))); + var expected = new RuntimeMetadata() + { + Label = "FooUDTOp", + FormattedNonQubitArgs = "(\"bar\", (" + 2.1 + "))", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + } + + public class ControlledOpTests + { + [Fact] + public void ControlledH() + { + IQArray controls = new QArray(new[] { new FreeQubit(0) }); + Qubit target = new FreeQubit(1); + var op = new QuantumSimulator().Get().Controlled; + var args = op.__dataIn((controls, target)); + var expected = new RuntimeMetadata() + { + Label = "H", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = controls, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void ControlledX() + { + IQArray controls = new QArray(new[] { new FreeQubit(0) }); + Qubit target = new FreeQubit(1); + var op = new QuantumSimulator().Get().Controlled; + var args = op.__dataIn((controls, target)); + var expected = new RuntimeMetadata() + { + Label = "X", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = controls, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void ControlledCNOT() + { + IQArray controls = new QArray(new[] { new FreeQubit(0) }); + Qubit control = new FreeQubit(1); + Qubit target = new FreeQubit(2); + var op = new QuantumSimulator().Get().Controlled; + var args = op.__dataIn((controls, (control, target))); + var expected = new RuntimeMetadata() + { + Label = "X", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = controls.Append(control), + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void ControlledCCNOT() + { + Qubit control1 = new FreeQubit(0); + Qubit control2 = new FreeQubit(1); + Qubit control3 = new FreeQubit(2); + Qubit target = new FreeQubit(3); + IQArray controls = new QArray(new[] { control1 }); + var op = new QuantumSimulator().Get().Controlled; + var args = op.__dataIn((controls, (control2, control3, target))); + var expected = new RuntimeMetadata() + { + Label = "X", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { control1, control2, control3 }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + } + + public class AdjointTests + { + [Fact] + public void AdjointH() + { + Qubit target = new FreeQubit(0); + var op = new QuantumSimulator().Get().Adjoint; + var args = op.__dataIn(target); + var expected = new RuntimeMetadata() + { + Label = "H", + FormattedNonQubitArgs = "", + IsAdjoint = true, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void AdjointX() + { + Qubit target = new FreeQubit(0); + var op = new QuantumSimulator().Get().Adjoint; + var args = op.__dataIn(target); + var expected = new RuntimeMetadata() + { + Label = "X", + FormattedNonQubitArgs = "", + IsAdjoint = true, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void AdjointAdjointH() + { + Qubit target = new FreeQubit(0); + var op = new QuantumSimulator().Get().Adjoint.Adjoint; + var args = op.__dataIn(target); + var expected = new RuntimeMetadata() + { + Label = "H", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void ControlledAdjointH() + { + IQArray controls = new QArray(new[] { new FreeQubit(0) }); + Qubit target = new FreeQubit(1); + var op1 = new QuantumSimulator().Get().Controlled.Adjoint; + var op2 = new QuantumSimulator().Get().Adjoint.Controlled; + var args = op1.__dataIn((controls, target)); + var expected = new RuntimeMetadata() + { + Label = "H", + FormattedNonQubitArgs = "", + IsAdjoint = true, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = controls, + Targets = new List() { target }, + }; + + Assert.Equal(op1.GetRuntimeMetadata(args), expected); + Assert.Equal(op2.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void ControlledAdjointAdjointH() + { + IQArray controls = new QArray(new[] { new FreeQubit(0) }); + Qubit target = new FreeQubit(1); + var op1 = new QuantumSimulator().Get().Controlled.Adjoint.Adjoint; + var op2 = new QuantumSimulator().Get().Adjoint.Controlled.Adjoint; + var op3 = new QuantumSimulator().Get().Adjoint.Adjoint.Controlled; + var args = op1.__dataIn((controls, target)); + var expected = new RuntimeMetadata() + { + Label = "H", + FormattedNonQubitArgs = "", + IsAdjoint = false, + IsControlled = true, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = controls, + Targets = new List() { target }, + }; + + Assert.Equal(op1.GetRuntimeMetadata(args), expected); + Assert.Equal(op2.GetRuntimeMetadata(args), expected); + Assert.Equal(op3.GetRuntimeMetadata(args), expected); + } + } + + public class PartialOpTests + { + + [Fact] + public void PartialRy() + { + var target = new FreeQubit(0); + var op = new QuantumSimulator().Get().Partial((double d) => + new ValueTuple(d, target)); + var args = op.__dataIn(2.1); + var expected = new RuntimeMetadata() + { + Label = "Ry", + FormattedNonQubitArgs = "(" + 2.1 + ")", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { target }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + + [Fact] + public void PartialUDT() + { + var target = new FreeQubit(0); + var op = new QuantumSimulator().Get>(typeof(Circuits.FooUDT)) + .Partial((double d) => (("bar", (target, d)))); + var args = new QTuple(2.1); + var expected = new RuntimeMetadata() + { + Label = "FooUDT", + FormattedNonQubitArgs = "(\"bar\", (" + 2.1 + "))", + IsAdjoint = false, + IsControlled = false, + IsMeasurement = false, + IsComposite = false, + Children = null, + Controls = new List() { }, + Targets = new List() { }, + }; + + Assert.Equal(op.GetRuntimeMetadata(args), expected); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs b/src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs new file mode 100644 index 00000000000..f9b73e477e9 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs @@ -0,0 +1,481 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Xunit; +using Xunit.Abstractions; + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Common; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public static class Extensions + { + /// + /// This method is a wrapper to let the tests keep using a one Type parameter + /// method to fetch for Gates. + /// + public static T Get(this SimulatorBase sim) where T : AbstractCallable + { + return sim.Get(); + } + } + + public class SimulatorBaseTests + { + private readonly ITestOutputHelper output; + + public SimulatorBaseTests(ITestOutputHelper output) + { + this.output = output; + } + + /// + /// Verifies that built-in operations (Allocate/Relase) can be retrieved and succesfully applied from a TrivialSimulator. + /// + [Fact] + public void SimulatorBuiltInOperations() + { + // The SimulatorBase class only implements operations for Qubit management, + // i.e. Allocate/Release: + var subject = new TrivialSimulator(); + + Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); + + // Check whether our events for allocation and deallocation + // are actually called. + var calledOnAllocate = false; + var calledOnRelease = false; + subject.OnAllocateQubits += count => + { + output.WriteLine($"Allocate count = {count}"); + calledOnAllocate = true; + }; + subject.OnReleaseQubits += register => + { + output.WriteLine($"Release qubits = {register}"); + calledOnRelease = true; + }; + + var allocate = subject.Get(); + var release = subject.Get(); + + // Try the operations + var qubits = allocate.Apply(3); + Assert.True(calledOnAllocate); + Assert.Equal(3, qubits.Length); + + release.Apply(qubits); + Assert.True(calledOnRelease); + + subject.CheckNoQubitLeak(); + } + + /// + /// Verifies that operations are not built-in in the TrivialSimulator can't be retrieved. + /// + [Fact] + public void OperationWithNoBody() + { + var subject = new TrivialSimulator(); + Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); + + Assert.Throws(() => + { + subject.Get(); + }); + } + + /// + /// Verifies that operations that have dependencies on operations that + /// are not built-in in the TrivialSimulator can't be retrieved. + /// + [Fact] + public void OperationWithNotImplementedDependency() + { + var subject = new TrivialSimulator(); + + Assert.Throws(() => + { + subject.Get(); + }); + } + + /// + /// Verifies that operations that have dependencies on operations that + /// are not built-in in the TrivialSimulator can't be retrieved. + /// + [Fact] + public void OperationWithRecursiveDependencies() + { + var subject = new TrivialSimulator(); + + var a = subject.Get(); + var b = subject.Get(); + + // Make sure the last instance is correctly cached. + var a2 = subject.Get(); + var b2 = subject.Get(); + Assert.Same(a, a2); + Assert.Same(b, b2); + Assert.Same(a, b.A); + Assert.Same(b, a.B); + } + + private class Nothing { } + private class NothingSquared : Nothing { } + + /// + /// Verifies that users can provide their own operation definitions. + /// + [Fact] + public void UserDefinedOperations() + { + var subject = new TrivialSimulator(); + Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); + + Assert.Throws(() => + { + subject.Get(); + }); + + try + { + subject.Register(null, typeof(DummyX)); + } + catch (ArgumentNullException e) + { + Assert.Equal("original", e.ParamName); + } + + try + { + subject.Register(typeof(Intrinsic.Allocate), null); + } + catch (ArgumentNullException e) + { + Assert.Equal("replace", e.ParamName); + } + + // You can only register an override of a class that extends Operation: + Assert.Throws(() => + { + subject.Register(typeof(Nothing), typeof(NothingSquared)); + }); + + // By default, you can only register a Gate that is a subclass of the gate it's overriding: + Assert.Throws(() => + { + subject.Register(typeof(Intrinsic.Allocate), typeof(DummyX)); + }); + + subject.Register(typeof(Intrinsic.X), typeof(DummyX)); + var customX = subject.Get(); + Assert.Equal(typeof(DummyX), customX.GetType()); + + subject.Register(typeof(Intrinsic.M), typeof(DummyM)); + var customM = subject.Get(); + Assert.Equal(typeof(DummyM), customM.GetType()); + } + + /// + /// Verifies that user-defined operations can override Intrinsics just by following the interface. + /// + [Fact] + public void OverrideWithNoInheritance() + { + var subject = new TrivialSimulator(); + Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); + + // If providing an interface, the original gate must implement that interface + Assert.Throws(() => + { + subject.Register(typeof(Intrinsic.CNOT), typeof(LikeX), typeof(IUnitary)); + }); + + // If providing an interface, the replacement gate must implement that interface + Assert.Throws(() => + { + subject.Register(typeof(Intrinsic.CNOT), typeof(LikeX), typeof(IUnitary<(Qubit, Qubit)>)); + }); + + // You can override without inheritance, as long as both implement the same interface: + subject.Register(typeof(Intrinsic.X), typeof(LikeX), typeof(IUnitary)); + + // Verify the replacement work + var x = subject.Get, Intrinsic.X>(); + Assert.NotNull(x); + Assert.Equal(typeof(LikeX), x.GetType()); + } + + /// + /// Verifies that operations instances are cached by the Simulator + /// + [Fact] + public void OperationsCache() + { + var subject = new TrivialSimulator(); + Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); + + var allocate1 = subject.Get(); + var allocate2 = subject.Get(); + + Assert.Same(allocate1, allocate2); + } + + [Fact] + public void GenericDependencies() + { + var subject = new TrivialSimulator(); + + // Can't get Gen because it depends on X + Assert.Throws(() => + { + subject.Get>(); + }); + + // TODO: because we can't check dependencies, this + // is not throwing an Exception, even though Gen depends on X: + var gen1 = subject.Get(); + Assert.NotNull(gen1); + + // Add an implementation of X: + subject.Register(typeof(Intrinsic.X), typeof(LikeX), typeof(IUnitary)); + var gen2 = subject.Get>(); + Assert.NotNull(gen1); + + // Asking for same T, should give same op, but asking for different T should not: + var gen2a = subject.Get>(); + var gen2b = subject.Get>(); + + Assert.Same(gen2, gen2a); + Assert.NotSame(gen2, gen2b); + } + + /// + /// Verifies that CheckQubits work as expected + /// + [Fact] + public void CheckQubits() + { + var sim = new TrivialSimulator(); + var allocate = sim.Get(); + var release = sim.Get(); + + var qubits = allocate.Apply(1); + var name = "foo"; + + // This should work: + sim.CheckQubits(qubits, name); + + // Calling with null will throw an Exception + Assert.Throws(name, () => sim.CheckQubits(null, name)); + + // Calling after release will throw an Exception + sim.CheckQubits(qubits, name); + release.Apply(qubits); + Assert.Throws($"{name}[0]", () => sim.CheckQubits(qubits, name)); + } + + /// + /// Verifies that GetQubitsAvailableToUse and GetQubitsAvailableToBorrow work correctly. + /// + [Fact] + public void TestQubitCounts() + { + var sim = new TrivialSimulator(); + + var baseCount = 32L; + var allocCount = 10L; + + var (initialUse, initialBorrow, afterUse, afterBorrow, subBorrow, innerBorrow) = + Circuits.GetAvailableTest.Run(sim, allocCount).Result; + + Assert.Equal(baseCount, initialUse); + Assert.Equal(baseCount, initialBorrow); + Assert.Equal(baseCount - allocCount, afterUse); + Assert.Equal(baseCount - allocCount, afterBorrow); + Assert.Equal(baseCount, subBorrow); + Assert.Equal(baseCount - 1, innerBorrow); + } + + /// + /// Verifies that recursive operations work as expected + /// + [Fact] + public void TextRecursion() + { + var sim = new TrivialSimulator(); + var res1 = Tests.Circuits.Factorial.Run(sim, 4L).Result; + var res2 = Tests.Circuits.OpFactorial.Run(sim, 4L).Result; + var res3 = Tests.Circuits.GenRecursion.Run(sim, 6L, 2L).Result; + var res4 = Tests.Circuits.GenRecursion.Run(sim, 6L, 2L).Result; + Assert.Equal(24L, res1); + Assert.Equal(24L, res2); + Assert.Equal(6L, res3); + Assert.Equal(6L, res4); + } + + + /// + // This class has no implementation, is just used to make sure + // a user can register their own Operation overrides: + /// + public class DummyX : Intrinsic.X + { + public DummyX(IOperationFactory m) : base(m) + { + } + + public override Func Body => throw new NotImplementedException(); + + public override Func<(IQArray, Qubit), QVoid> ControlledBody => throw new NotImplementedException(); + } + + /// + // This class has no implementation, is just used to make sure + // a user can register their own Operation overrides: + /// + public class DummyM : Intrinsic.M + { + public DummyM(IOperationFactory m) : base(m) + { + } + + public override Func Body => throw new NotImplementedException(); + + public override void Init() + { + } + } + + /// + /// This class is not abstract, but depends on X, which is. + /// + public class DependsOnX : Operation, ICallable + { + public DependsOnX(IOperationFactory m) : base(m) + { + } + + string ICallable.FullName => "DependsOnX"; + + public IUnitary X { get; set; } + + public override void Init() + { + this.X = this.Factory.Get, Intrinsic.X>(); + } + + public override Func Body => throw new NotImplementedException(); + } + + /// + // This class is a one qubit Unitary (like X), but + // it doesn't implement X. Still because it implmenets + // IUnitary we can use it to replace X.: + /// + public class LikeX : Unitary, ICallable + { + public LikeX(IOperationFactory m) : base(m) + { + } + + string ICallable.FullName => "LikeX"; + + public override void Init() { } + + public override Func<(IQArray, Qubit), QVoid> ControlledAdjointBody => throw new NotImplementedException(); + + public override Func AdjointBody => throw new NotImplementedException(); + + public override Func<(IQArray, Qubit), QVoid> ControlledBody => throw new NotImplementedException(); + + public override Func Body => throw new NotImplementedException(); + } + + + /// + /// This class has a recursive dependency with B + /// + public class A : Operation, ICallable + { + public A(IOperationFactory m) : base(m) + { + } + + public ICallable B { get; set; } + + public override void Init() + { + this.B = this.Factory.Get(); + } + + string ICallable.FullName => "A"; + + public override Func Body => (_) => { return QVoid.Instance; }; + } + + /// + /// This class has a recursive depdency with A + /// + public class B : Operation, ICallable + { + public B(IOperationFactory m) : base(m) + { + } + + string ICallable.FullName => "B"; + + public ICallable A { get; set; } + + public override void Init() + { + this.A = this.Factory.Get(); + } + + public override Func Body => (_) => { return QVoid.Instance; }; + } + + public class Gen : Operation, ICallable + { + public Gen(IOperationFactory m) : base(m) + { + } + + string ICallable.FullName => "Gen"; + + public override Func Body => (_) => { return QVoid.Instance; }; + + public ICallable A { get; set; } + + public IUnitary X { get; set; } + + public override void Init() + { + this.A = this.Factory.Get(); + this.X = this.Factory.Get, Intrinsic.X>(); + } + } + + + public class DependsOnGen : Operation, ICallable + { + public DependsOnGen(IOperationFactory m) : base(m) + { + } + + string ICallable.FullName => "DependsOnGen"; + + public ICallable Gen { get; set; } + + public override Func Body => (_) => { return QVoid.Instance; }; + + public override void Init() + { + this.Gen = this.Factory.Get(typeof(Gen<>)); + } + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs b/src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs new file mode 100644 index 00000000000..c85fac9bfac --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#nullable enable + +using Xunit; + +using System; +using System.Threading.Tasks; + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Simulation.Common; +using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; +using Microsoft.Quantum.Simulation.Simulators.Exceptions; +using Xunit.Abstractions; +using System.Text; +using System.Collections.Generic; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class StackTraceTests + { + const string namespacePrefix = "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits."; + + private readonly ITestOutputHelper output; + public StackTraceTests(ITestOutputHelper output) + { + this.output = output; + } + + [Fact] + public void AllocateQubit2Test() + { + using var sim = new QuantumSimulator(); + try + { + IgnorableAssert.Disable(); + QVoid res = sim.Execute(QVoid.Instance); + } + catch (ExecutionFailException) + { + var stackFrames = sim.CallStack; + + // Make sure that the call stack isn't null before proceeding. + Assert.NotNull(stackFrames); + + // The following assumes that Assert is on Q# stack. + Assert.Equal(2, stackFrames!.Length); + + Assert.Equal("Microsoft.Quantum.Diagnostics.AssertMeasurement", stackFrames[0].Callable.FullName); + Assert.Equal(namespacePrefix + "AllocateQubit2", stackFrames[1].Callable.FullName); + + Assert.Equal(OperationFunctor.Body, stackFrames[0].Callable.Variant); + Assert.Equal(OperationFunctor.Body, stackFrames[1].Callable.Variant); + + Assert.Equal(94, stackFrames[1].FailedLineNumber); + } + finally + { + IgnorableAssert.Enable(); + } + } + + [Fact] + public void AlwaysFail4Test() + { + using (var sim = new QuantumSimulator()) + { + try + { + QVoid res = AlwaysFail4.Run(sim).Result; + } + catch (AggregateException ex) + { + Assert.True(ex.InnerException is ExecutionFailException); + + StackFrame[] stackFrames = sim.CallStack; + + Assert.Equal(5, stackFrames.Length); + + Assert.Equal(namespacePrefix + "AlwaysFail", stackFrames[0].Callable.FullName); + Assert.Equal(namespacePrefix + "AlwaysFail1", stackFrames[1].Callable.FullName); + Assert.Equal(namespacePrefix + "AlwaysFail2", stackFrames[2].Callable.FullName); + Assert.Equal(namespacePrefix + "AlwaysFail3", stackFrames[3].Callable.FullName); + Assert.Equal(namespacePrefix + "AlwaysFail4", stackFrames[4].Callable.FullName); + + Assert.Equal(OperationFunctor.Controlled, stackFrames[0].Callable.Variant); + Assert.Equal(OperationFunctor.Controlled, stackFrames[1].Callable.Variant); + Assert.Equal(OperationFunctor.Body, stackFrames[2].Callable.Variant); + Assert.Equal(OperationFunctor.Adjoint, stackFrames[3].Callable.Variant); + Assert.Equal(OperationFunctor.Body, stackFrames[4].Callable.Variant); + + Assert.Equal(14, stackFrames[2].FailedLineNumber); + Assert.Equal(21, stackFrames[4].FailedLineNumber); + + // For Adjoint and Controlled we expect failedLineNumber to be equal to declarationStartLineNumber + Assert.Equal(stackFrames[0].DeclarationStartLineNumber, stackFrames[0].FailedLineNumber); + Assert.Equal(stackFrames[1].DeclarationStartLineNumber, stackFrames[1].FailedLineNumber); + Assert.Equal(stackFrames[3].DeclarationStartLineNumber, stackFrames[3].FailedLineNumber); + + for (int i = 0; i < stackFrames.Length; ++i) + { + Assert.StartsWith(@"https://github.com/", stackFrames[i].GetURLFromPDB()); + Assert.EndsWith($"#L{stackFrames[i].FailedLineNumber}", stackFrames[i].GetURLFromPDB()); + } + + StringBuilder builder = new StringBuilder(); + builder.Append("13 ".PadLeft(PortablePDBEmbeddedFilesCache.lineNumberPaddingWidth)); + builder.AppendLine(" operation AlwaysFail2() : Unit is Adj + Ctl {"); + builder.Append("14 ".PadLeft(PortablePDBEmbeddedFilesCache.lineNumberPaddingWidth) + PortablePDBEmbeddedFilesCache.lineMarkPrefix); + builder.AppendLine(" Controlled AlwaysFail1(new Qubit[0],());"); + builder.Append("15 ".PadLeft(PortablePDBEmbeddedFilesCache.lineNumberPaddingWidth)); + builder.AppendLine(" }"); + Assert.Equal(builder.ToString(), stackFrames[2].GetOperationSourceFromPDB()); + + for (int i = 0; i < stackFrames.Length; ++i) + { + output.WriteLine($"operation:{stackFrames[i].Callable.FullName}"); + output.WriteLine(stackFrames[i].GetOperationSourceFromPDB()); + } + } + } + } + + [Fact] + public void UrlMappingTest() + { + const string rawUrl = @"https://raw.githubusercontent.com/microsoft/qsharp-runtime/af6262c05522d645d0a0952272443e84eeab677a/src/Xunit/TestCaseDiscoverer.cs"; + const string expectedURL = @"https://github.com/microsoft/qsharp-runtime/blob/af6262c05522d645d0a0952272443e84eeab677a/src/Xunit/TestCaseDiscoverer.cs#L13"; + Assert.Equal(expectedURL, PortablePdbSymbolReader.TryFormatGitHubUrl(rawUrl, 13)); + } + + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs b/src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs new file mode 100644 index 00000000000..d07af93db07 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs @@ -0,0 +1,190 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Core; +using Microsoft.Quantum.Tests.StartOperation; +using System; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + using Helper = Microsoft.Quantum.Simulation.Simulators.Tests.OperationsTestHelper; + + public class StartOperationTests + { + [Fact] + public void StartOperationCalls() + { + Helper.RunWithMultipleSimulators((s) => + { + var tracker = new StartTracker(s); + StartOperationTest.Run(s).Wait(); + + var q0 = new FreeQubit(0) as Qubit; + var q1 = new FreeQubit(1) as Qubit; + var q2 = new FreeQubit(2) as Qubit; + var q3 = new FreeQubit(3) as Qubit; + + Assert.Equal(1, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.StartOperationTest")); + + var allVariantsBody = 3; + var allVariantsAdjoint = 2; + var allVariantsCtrl = 2; + var allVariantsAdjointCtrl = 1; + var allVariants = allVariantsBody + allVariantsAdjoint + allVariantsCtrl + allVariantsAdjointCtrl; + Assert.Equal(allVariants, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants")); + Assert.Equal(allVariantsBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Body)); + Assert.Equal(allVariantsAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Adjoint)); + Assert.Equal(allVariantsCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Controlled)); + Assert.Equal(allVariantsAdjointCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.ControlledAdjoint)); + + var basicBody = 9; + var basicAdjoint = 7; + var basicCtrl = 9; + var basicCtrlAdjoint = 7; + var basic = basicBody + basicAdjoint + basicCtrl + basicCtrlAdjoint; + Assert.Equal(basic, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic")); + Assert.Equal(basicBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body)); + Assert.Equal(basicAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint)); + Assert.Equal(basicCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Controlled)); + Assert.Equal(basicCtrlAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.ControlledAdjoint)); + + var data1 = (0L, q1, (q2, q3), Result.One); + Assert.Equal(3, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body, data1)); + Assert.Equal(3, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint, data1)); + + var data2 = (1L, q1, (q2, q3), Result.Zero); + Assert.Equal(6, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body, data2)); + Assert.Equal(4, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint, data2)); + + Assert.Equal(basic * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X")); + Assert.Equal(basicBody * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body)); + Assert.Equal(basicAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint)); + Assert.Equal(basicCtrl * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled)); + Assert.Equal(basicCtrlAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint)); + }); + } + + [Fact] + public void StartUDTOperationCalls() + { + Helper.RunWithMultipleSimulators((s) => + { + var tracker = new StartTracker(s); + StartOperationUDTTest.Run(s).Wait(); + + Assert.Equal(1, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.StartOperationUDTTest")); + + var allVariantsBody = 3; + var allVariantsAdjoint = 2; + var allVariantsCtrl = 2; + var allVariantsAdjointCtrl = 1; + var allVariants = allVariantsBody + allVariantsAdjoint + allVariantsCtrl + allVariantsAdjointCtrl; + Assert.Equal(allVariants, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants")); + Assert.Equal(allVariantsBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Body)); + Assert.Equal(allVariantsAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Adjoint)); + Assert.Equal(allVariantsCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Controlled)); + Assert.Equal(allVariantsAdjointCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.ControlledAdjoint)); + + var basicBody = 12; + var basicAdjoint = 7; + var basicCtrl = 9; + var basicCtrlAdjoint = 7; + var basic = basicBody + basicAdjoint + basicCtrl + basicCtrlAdjoint; + Assert.Equal(basic, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic")); + Assert.Equal(basicBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body)); + Assert.Equal(basicAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint)); + Assert.Equal(basicCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Controlled)); + Assert.Equal(basicCtrlAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.ControlledAdjoint)); + + // Because of unwrapping, udts are not called directly, only their base operation: + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1")); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Body)); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Adjoint)); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Controlled)); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.ControlledAdjoint)); + + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2")); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Body)); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Adjoint)); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Controlled)); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.ControlledAdjoint)); + + Assert.Equal(basic * 4 + 2, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X")); + Assert.Equal(basicBody * 4 + 2, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body)); + Assert.Equal(basicAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint)); + Assert.Equal(basicCtrl * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled)); + Assert.Equal(basicCtrlAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint)); + + var b3Body = 8; + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT3")); + Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT3", OperationFunctor.Body)); + Assert.Equal(b3Body, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.B3")); + Assert.Equal(b3Body, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.B3", OperationFunctor.Body)); ; + }); + } + + + [Fact] + public void StartDataIn() + { + Helper. RunWithMultipleSimulators((s) => + { + var basic = s.Get(); + var q1 = new FreeQubit(1); + var q2 = new FreeQubit(2); + var q3 = new FreeQubit(3); + var expected = (1L, q1, (q2, q3), Result.One); + + var m1 = new Func<(Qubit, Qubit), (Int64, Qubit, (Qubit, Qubit), Result)>((_arg1) => (1L, q1, (_arg1.Item1, _arg1.Item2), Result.One)); + var m2 = new Func((_arg2) => (_arg2, q3)); + var p1 = basic.Partial(m1); + var p2 = p1.Partial(m2); + + AssertTuple(expected, p1.__dataIn((q2, q3)).Value); + AssertTuple(expected, p2.__dataIn((q2)).Value); + + Assert.Equal(new Qubit[] { q1, q2, q3 }, p1.__dataIn((q2, q3)).Qubits); + Assert.Equal(new Qubit[] { q1, q2, q3 }, p2.__dataIn(q2).Qubits); + + Assert.Null(((IApplyData)basic).Qubits); + Assert.Equal(new Qubit[] { q1, null, null }, ((IApplyData)p1).Qubits); + Assert.Equal(new Qubit[] { q1, null, q3 }, ((IApplyData)p2).Qubits); + }); + } + + [Fact] + public void StartUDTDataIn() + { + Helper.RunWithMultipleSimulators((s) => + { + var basic = new UDT1(s.Get()); + var q1 = new FreeQubit(1); + var q2 = new FreeQubit(2); + var q3 = new FreeQubit(3); + var expected = (1L, q1, (q2, q3), Result.One); + + var m1 = new Func<(Qubit, Qubit), (Int64, Qubit, (Qubit, Qubit), Result)>((_arg1) => (1L, q1, (_arg1.Item1, _arg1.Item2), Result.One)); + var m2 = new Func((_arg2) => (_arg2, q3)); + var p1 = ((Basic)basic.Data).Partial(m1); + var p2 = p1.Partial(m2); + + AssertTuple(expected, p1.__dataIn((q2, q3)).Value); + AssertTuple(expected, p2.__dataIn((q2)).Value); + + Assert.Equal(new Qubit[] { q1, q2, q3 }, p1.__dataIn((q2, q3)).Qubits); + Assert.Equal(new Qubit[] { q1, q2, q3 }, p2.__dataIn(q2).Qubits); + + Assert.Null(((IApplyData)basic).Qubits); + Assert.Equal(new Qubit[] { q1, null, null }, ((IApplyData)p1).Qubits); + Assert.Equal(new Qubit[] { q1, null, q3 }, ((IApplyData)p2).Qubits); + }); + } + + private static void AssertTuple(object expected, object actual) + { + var value = PartialMapper.CastTuple(expected.GetType(), actual); + Assert.Equal(expected, value); + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj new file mode 100644 index 00000000000..ebff7c89f2f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp3.1 + false + true + + false + false + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs new file mode 100644 index 00000000000..64cb257b421 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs @@ -0,0 +1,248 @@ +namespace Microsoft.Quantum.Tests { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Random; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Math; + + // Uses Welford's method to compute the mean and variance of an array + // of samples. + internal function SampleMeanAndVariance(samples : Double[]) : (Double, Double) { + mutable meanAcc = 0.0; + mutable varAcc = 0.0; + for (idx in 0..Length(samples) - 1) { + let sample = samples[idx]; + let oldMeanAcc = meanAcc; + let delta = (sample - meanAcc); + set meanAcc += delta / IntAsDouble(idx + 1); + set varAcc += delta * (sample - oldMeanAcc); + } + + return (meanAcc, varAcc / IntAsDouble(Length(samples) - 1)); + } + + internal operation EstimateMeanAndVariance(dist : ContinuousDistribution, nSamples : Int) : (Double, Double) { + mutable samples = new Double[nSamples]; + for (idx in 0..nSamples - 1) { + set samples w/= idx <- dist::Sample(); + } + return SampleMeanAndVariance(samples); + } + + internal operation CheckMeanAndVariance( + name : String, + distribution : ContinuousDistribution, + nSamples : Int, + (expectedMean : Double, expectedVariance : Double), + tolerance : Double + ) : Unit { + let (mean, variance) = EstimateMeanAndVariance( + distribution, + nSamples + ); + Fact( + expectedMean - tolerance <= mean and + mean <= expectedMean + tolerance, + $"Mean of {name} distribution should be {expectedMean}, was {mean}." + ); + Fact( + expectedVariance - tolerance <= variance and + variance <= expectedVariance + tolerance, + $"Variance of {name} distribution should be {expectedVariance}, was {variance}." + ); + } + + /// # Summary + /// Checks that @"microsoft.quantum.random.drawrandomdouble" obeys ranges. + @Test("QuantumSimulator") + operation CheckDrawRandomDoubleObeysRanges() : Unit { + for (j in 0..10000) { + let random = DrawRandomDouble(0.0, 1.0); + if (random < 0.0 or random > 1.0) { + fail $"DrawRandomDouble(0.0, 1.0) returned {random}, outside the allowed interval."; + } + } + } + + /// # Summary + /// Checks that @"microsoft.quantum.random.drawrandomdint" obeys ranges. + @Test("QuantumSimulator") + operation CheckDrawRandomIntObeysRanges() : Unit { + let randomInt = DrawRandomInt(0, 45); + if (randomInt > 45 or randomInt < 0) { + fail $"DrawRandomInt(0, 45) returned {randomInt}, outside the allowed range."; + } + } + + /// # Summary + /// Checks that @"microsoft.quantum.random.continuousuniformdistribution" has the + /// expected moments. + @Test("QuantumSimulator") + operation CheckContinuousUniformDistributionHasRightMoments() : Unit { + CheckMeanAndVariance( + "uniform", + ContinuousUniformDistribution(0.0, 1.0), + 1000000, + (0.5, 1.0 / 12.0), + 0.02 + ); + } + + /// # Summary + /// Checks that @"microsoft.quantum.random.standardnormaldistribution" has the + /// expected moments. + @Test("QuantumSimulator") + operation CheckStandardNormalDistributionHasRightMoments() : Unit { + CheckMeanAndVariance( + "standard normal", + StandardNormalDistribution(), + 1000000, + (0.0, 1.0), + 0.02 + ); + } + + /// # Summary + /// Checks that @"microsoft.quantum.random.normaldistribution" has the + /// expected moments. + @Test("QuantumSimulator") + operation CheckNormalDistributionHasRightMoments() : Unit { + CheckMeanAndVariance( + "normal(-2.0, 5.0)", + NormalDistribution(-2.0, 5.0), + 1000000, + (-2.0, 5.0), + 0.02 + ); + } + + /// # Summary + /// Checks that @"microsoft.quantum.random.drawrandombool" has the right + /// first moment. Note that since DrawRandomBool represents a Bernoulli + /// trial, it is entirely characterized by its first moment; we don't need + /// to check variance here. + @Test("QuantumSimulator") + operation CheckDrawRandomBoolHasRightExpectation() : Unit { + // NB: DrawMany isn't available yet, since it's in the + // Microsoft.Quantum.Standard package, not QSharpCore. + let prHeads = 0.65; + let nFlips = 1000000; + let stdDev = Sqrt(IntAsDouble(nFlips) * prHeads * (1.0 - prHeads)); + let expected = IntAsDouble(nFlips) * prHeads; + let nAllowedStdDev = 4.0; + mutable nHeads = 0; + for (idx in 0..nFlips - 1) { + if (DrawRandomBool(prHeads)) { + set nHeads += 1; + } + } + + let delta = IntAsDouble(nHeads) - expected; + + Fact( + -nAllowedStdDev * stdDev <= delta and + delta <= nAllowedStdDev * stdDev, + "First moment of Bernoulli distribution was incorrect." + ); + } + + /// # Summary + /// Checks that DrawCategorical never draws elements with probability zero. + @Test("QuantumSimulator") + operation CheckImpossibleEventsAreNotDrawn() : Unit { + let distribution = CategoricalDistribution([0.5, 0.0, 0.5]); + let nTrials = 100000; + for (idxTrial in 0..nTrials - 1) { + let variate = distribution::Sample(); + Fact( + variate != 1, + "A variate of 1 was drawn from a categorical distribution, despite having a probability of 0." + ); + } + } + + // We define a couple callables to help us run continuous tests on discrete + // distributions as well. + + internal operation DrawDiscreteAsContinuous(discrete : DiscreteDistribution, delay : Unit) : Double { + return IntAsDouble(discrete::Sample()); + } + + internal function DiscreteAsContinuous(discrete : DiscreteDistribution) : ContinuousDistribution { + return ContinuousDistribution(DrawDiscreteAsContinuous(discrete, _)); + } + + @Test("QuantumSimulator") + operation CheckCategoricalMomentsAreCorrect() : Unit { + let categorical = DiscreteAsContinuous( + CategoricalDistribution([0.2, 0.5, 0.3]) + ); + let expected = 0.0 * 0.2 + 1.0 * 0.5 + 2.0 * 0.3; + let variance = PowD(0.0 - expected, 2.0) * 0.2 + + PowD(1.0 - expected, 2.0) * 0.5 + + PowD(2.0 - expected, 2.0) * 0.3; + + CheckMeanAndVariance( + "categorical([0.2, 0.5, 0.3])", + categorical, + 1000000, + (expected, variance), + 0.04 + ); + } + + @Test("QuantumSimulator") + operation CheckRescaledCategoricalMomentsAreCorrect() : Unit { + let categorical = DiscreteAsContinuous( + CategoricalDistribution([2.0, 5.0, 3.0]) + ); + let expected = 0.0 * 0.2 + 1.0 * 0.5 + 2.0 * 0.3; + let variance = PowD(0.0 - expected, 2.0) * 0.2 + + PowD(1.0 - expected, 2.0) * 0.5 + + PowD(2.0 - expected, 2.0) * 0.3; + + CheckMeanAndVariance( + "categorical([0.2, 0.5, 0.3])", + categorical, + 1000000, + (expected, variance), + 0.04 + ); + } + + @Test("QuantumSimulator") + operation CheckCategoricalHistogramIsCorrect() : Unit { + let categorical = CategoricalDistribution([0.2, 0.5, 0.3]); + mutable counts = new Int[3]; + let nSamples = 1000000; + + for (idx in 0..nSamples - 1) { + let sample = categorical::Sample(); + set counts w/= sample <- counts[sample] + 1; + } + + Fact(190000 <= counts[0] and counts[0] <= 210000, $"counts[0] was {counts[0]}, expected about 200000."); + Fact(490000 <= counts[1] and counts[1] <= 510000, $"counts[1] was {counts[1]}, expected about 500000."); + Fact(290000 <= counts[2] and counts[2] <= 310000, $"counts[2] was {counts[2]}, expected about 300000."); + } + + @Test("QuantumSimulator") + operation CheckDiscreteUniformMomentsAreCorrect() : Unit { + let (min, max) = (-3, 7); + let expected = 0.5 * (IntAsDouble(min + max)); + let variance = (1.0 / 12.0) * ( + PowD(IntAsDouble(max - min + 1), 2.0) - 1.0 + ); + CheckMeanAndVariance( + $"discrete uniform ({min}, {max})", + DiscreteAsContinuous( + DiscreteUniformDistribution(min, max) + ), + 1000000, + (expected, variance), + 0.1 + ); + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs new file mode 100644 index 00000000000..15972e2efc4 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs @@ -0,0 +1,43 @@ +// Used for a unit test; +// do not change the name of this namespace! +namespace Microsoft.Quantum.Library { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + // Used for a unit test; + // do not change the name or namespace of this type! + @EnableTestingViaName("Library1.MyInt") + newtype MyInt = (Value1 : Int); + + // Used for a unit test; + // do not change the name or namespace of this type! + newtype MyString = (Text : String); + + // Used for a unit test; + // do not change the name or namespace of this type! + @EnableTestingViaName("Library1.Token") + newtype Token = Unit; + + // Used for a unit test; + // do not change the name or namespace of this callable! + @EnableTestingViaName("Library1.LibraryId") + function LibraryId() : Int { + return 1; + } + + // Used for a unit test; + // do not change the name or namespace of this callable! + function DllName() : String { + return "Library1"; + } + + // Used for a unit test; + // do not change the name or namespace of this callable! + @EnableTestingViaName("Library1.Hello") + operation Hello(dummy : Token) : String { + return "Hello from Library1!"; + } + + +} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj new file mode 100644 index 00000000000..265201bd85f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.1 + + false + false + + + + + + + + + + + + + + diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs new file mode 100644 index 00000000000..237186bb92a --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs @@ -0,0 +1,31 @@ +// Used for a unit test; +// do not change the name of this namespace! +namespace Microsoft.Quantum.Library { + + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + + // Used for a unit test; + // do not change the name or namespace of this type! + @EnableTestingViaName("Library2.MyInt") + newtype MyInt = (Value2 : Int); + + // Used for a unit test; + // do not change the name or namespace of this type! + @EnableTestingViaName("Library2.MyString") + newtype MyString = (Text : String); + + // Used for a unit test; + // do not change the name or namespace of this callable! + @EnableTestingViaName("Library2.LibraryId") + function LibraryId() : Int { + return 2; + } + + // Used for a unit test; + // do not change the name or namespace of this callable! + @EnableTestingViaName("Library2.DllName") + function DllName() : String { + return "Library2"; + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj new file mode 100644 index 00000000000..265201bd85f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.1 + + false + false + + + + + + + + + + + + + + diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs new file mode 100644 index 00000000000..880bdf81a85 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs @@ -0,0 +1,37 @@ +namespace Microsoft.Quantum.Testing { + internal function FactI(expected : Int, got : Int) : Unit { + if (expected != got) { + fail $"Expected: {expected}, got: {got}"; + } + } + + internal function FactS(expected : String, got : String) : Unit { + if (expected != got) { + fail $"Expected: {expected}, got: {got}"; + } + } + + internal function FactMyInt1(expected : Int, got : Library1.MyInt) : Unit { + if (expected != got::Value1) { + fail $"Expected: {expected}, got: {got::Value1}"; + } + } + + internal function FactMyInt2(expected : Int, got : Library2.MyInt) : Unit { + if (expected != got::Value2) { + fail $"Expected: {expected}, got: {got::Value2}"; + } + } + + internal function FactMyString1(expected : String, got : Microsoft.Quantum.Library.MyString) : Unit { + if (expected != got::Text) { + fail $"Expected: {expected}, got: {got::Text}"; + } + } + + internal function FactMyString2(expected : String, got : Library2.MyString) : Unit { + if (expected != got::Text) { + fail $"Expected: {expected}, got: {got::Text}"; + } + } +} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs new file mode 100644 index 00000000000..4d8cd71c3b1 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs @@ -0,0 +1,16 @@ +// Used for a unit test; +// do not change the name of this namespace! +namespace Microsoft.Quantum.Library { + + open Microsoft.Quantum.Intrinsic; + + // Used for a unit test; + // do not change the name or namespace of this type! + newtype Token = Unit; + + // Used for a unit test; + // do not change the name or namespace of this callable! + operation Hello(dummy : Token) : Unit { + Message("Hello!"); + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs new file mode 100644 index 00000000000..68a3ee38845 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs @@ -0,0 +1,48 @@ +namespace Microsoft.Quantum.Testing.LoadViaTestName { + + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Testing; + + @Test("QuantumSimulator") + operation BothCallables () : Unit { + + FactI(1, Library1.LibraryId()); + FactI(2, Library2.LibraryId()); + } + + @Test("QuantumSimulator") + operation OneCallable () : Unit { + + FactS("Library1", Microsoft.Quantum.Library.DllName()); + FactS("Library2", Library2.DllName()); + } + + @Test("QuantumSimulator") + operation BothTypes () : Unit { + + let i1 = Library1.MyInt(1); + let i2 = Library2.MyInt(2); + FactMyInt1(1, i1); + FactMyInt2(2, i2); + } + + @Test("QuantumSimulator") + operation OneType () : Unit { + + let s1 = Microsoft.Quantum.Library.MyString("Library1"); + let s2 = Library2.MyString("Library2"); + FactMyString1("Library1", s1); + FactMyString2("Library2", s2); + } + + @Test("QuantumSimulator") + operation ConflictingWithSource () : Unit { + + let h1 = Library1.Hello(Library1.Token()); + let h2 = Microsoft.Quantum.Library.Hello(Microsoft.Quantum.Library.Token()); + FactS("Hello from Library1!", h1); + return h2; + } + +} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj new file mode 100644 index 00000000000..b181e10a11f --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -0,0 +1,32 @@ + + + + netcoreapp3.1 + false + true + + false + false + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj new file mode 100644 index 00000000000..0480e675622 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj @@ -0,0 +1,52 @@ + + + + + + + + netcoreapp3.1 + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + <_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\ + <_TargetedExeDir>$(MSBuildThisFileDirectory)TestProjects\TargetedExe\built\ + + + <_ExeFiles Include="$(_ExeDir)*" /> + <_TargetedExeFiles Include="$(_TargetedExeDir)*" /> + + + + + + + + + + diff --git a/src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs b/src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs new file mode 100644 index 00000000000..f11afdea853 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Quantum.Simulation.Common; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + /// + /// This is a trivial implementation of a Simulator. Only used for unittesting. + /// Not apt to simulate any circuits as it implements no Intrinsic Gates. + /// + public class TrivialSimulator : SimulatorBase + { + public TrivialSimulator() : base(new QubitManagerTrackingScope(32)) + { + } + + public override string Name + { + get + { + return this.GetType().Name; + } + } + } + + /// + /// This is a trivial implementation of a Simulator. Only used for unittesting. + /// Not apt to simulate any circuits as it implements no Intrinsic Gates. + /// + public class ModifiedTrivialSimulator : TrivialSimulator + { } +} + +namespace Microsoft.Quantum.Simulation.Simulators.Tests.UnitTests +{ + /// + /// This is a trivial implementation of a Simulator. Only used for unittesting. + /// Not apt to simulate any circuits as it implements no Intrinsic Gates. + /// + public class TrivialSimulator : Tests.TrivialSimulator + { } +} diff --git a/src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs b/src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs new file mode 100644 index 00000000000..2707ca2b150 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs @@ -0,0 +1,152 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using Microsoft.Quantum.Simulation.Core; +using Xunit; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + public class ApplyData : IApplyData + { + public T Data; + + public ApplyData(T data) + { + this.Data = data; + } + + object IApplyData.Value => this.Data; + + IEnumerable IApplyData.Qubits => QubitsExtractor.Get(typeof(T))?.Extract(Data); + } + + public class GetNonQubitArgumentsAsStringTests + { + [Fact] + public void BasicTypes() + { + Assert.Equal("3", 3.GetNonQubitArgumentsAsString()); + Assert.Equal("False", false.GetNonQubitArgumentsAsString()); + Assert.Equal("\"Foo\"", "Foo".GetNonQubitArgumentsAsString()); + Assert.Equal("\"\"", "".GetNonQubitArgumentsAsString()); + } + + [Fact] + public void OperationTypes() + { + var op = new QuantumSimulator().Get(); + Assert.Equal("H", op.GetNonQubitArgumentsAsString()); + + var op2 = new QuantumSimulator().Get(); + Assert.Equal("CNOT", op2.GetNonQubitArgumentsAsString()); + } + + [Fact] + public void QubitTypes() + { + var q = new FreeQubit(0); + Assert.Null(q.GetNonQubitArgumentsAsString()); + + var qs = new QArray(new[] { new FreeQubit(0) }); + Assert.Null(qs.GetNonQubitArgumentsAsString()); + + qs = new QArray(new[] { new FreeQubit(0), new FreeQubit(1) }); + Assert.Null(qs.GetNonQubitArgumentsAsString()); + + var qtuple = new QTuple(q); + Assert.Null(qtuple.GetNonQubitArgumentsAsString()); + } + + [Fact] + public void TupleTypes() + { + Assert.Equal("(1, 2)", (1, 2).GetNonQubitArgumentsAsString()); + Assert.Equal("(\"foo\", \"bar\")", ("foo", "bar").GetNonQubitArgumentsAsString()); + Assert.Equal("(\"foo\", \"bar\", \"\")", ("foo", "bar", "").GetNonQubitArgumentsAsString()); + Assert.Equal("(\"foo\", (\"bar\", \"car\"))", ("foo", ("bar", "car")).GetNonQubitArgumentsAsString()); + Assert.Equal("((\"foo\"), (\"bar\", \"car\"))", (("foo", new FreeQubit(0)), ("bar", "car")).GetNonQubitArgumentsAsString()); + + var op = new QuantumSimulator().Get(); + var opTuple = new QTuple<(ICallable, string)>((op, "foo")); + Assert.Equal("(H, \"foo\")", opTuple.GetNonQubitArgumentsAsString()); + + var qtuple = new QTuple<(Qubit, string)>((new FreeQubit(0), "foo")); + Assert.Equal("(\"foo\")", qtuple.GetNonQubitArgumentsAsString()); + } + + [Fact] + public void ArrayTypes() + { + Assert.Equal("[1, 2, 3]", new[] { 1, 2, 3 }.GetNonQubitArgumentsAsString()); + Assert.Equal("[\"foo\", \"bar\"]", new[] { "foo", "bar" }.GetNonQubitArgumentsAsString()); + + var opArr = new ICallable[] { + new QuantumSimulator().Get(), + new QuantumSimulator().Get(), + new QuantumSimulator().Get(), + }; + Assert.Equal("[H, CNOT, Ry]", opArr.GetNonQubitArgumentsAsString()); + + var qTupleArr = new[] { + (new FreeQubit(0), "foo"), + (new FreeQubit(1), "bar"), + }; + Assert.Equal("[(\"foo\"), (\"bar\")]", qTupleArr.GetNonQubitArgumentsAsString()); + + var qArrayBool = new QArray(new[] { false, true }); + Assert.Equal("[False, True]", qArrayBool.GetNonQubitArgumentsAsString()); + } + + [Fact] + public void IApplyDataTypes() + { + IApplyData data; + data = new ApplyData(3); + Assert.Equal("3", data.GetNonQubitArgumentsAsString()); + + data = new ApplyData(false); + Assert.Equal("False", data.GetNonQubitArgumentsAsString()); + + data = new ApplyData("Foo"); + Assert.Equal("\"Foo\"", data.GetNonQubitArgumentsAsString()); + + var op = new QuantumSimulator().Get(); + data = new ApplyData(op); + Assert.Equal("H", data.GetNonQubitArgumentsAsString()); + + data = new ApplyData>((1, "foo")); + Assert.Equal("(1, \"foo\")", data.GetNonQubitArgumentsAsString()); + + data = new ApplyData, ValueTuple>>((("foo", new FreeQubit(0)), ("bar", "car"))); + Assert.Equal("((\"foo\"), (\"bar\", \"car\"))", data.GetNonQubitArgumentsAsString()); + + data = new ApplyData(new[] { 1, 2, 3 }); + Assert.Equal("[1, 2, 3]", data.GetNonQubitArgumentsAsString()); + + var arr = new[] { + (new FreeQubit(0), "foo"), + (new FreeQubit(1), "bar"), + }; + data = new ApplyData<(FreeQubit, string)[]>(arr); + Assert.Equal("[(\"foo\"), (\"bar\")]", data.GetNonQubitArgumentsAsString()); + + var qtupleWithString = new QTuple<(Qubit, string)>((new FreeQubit(0), "foo")); + data = new ApplyData>(qtupleWithString); + Assert.Equal("(\"foo\")", data.GetNonQubitArgumentsAsString()); + + var q = new FreeQubit(0); + data = new ApplyData(q); + Assert.Null(data.GetNonQubitArgumentsAsString()); + + var qs = new QArray(new[] { new FreeQubit(0), new FreeQubit(1) }); + data = new ApplyData>(qs); + Assert.Null(data.GetNonQubitArgumentsAsString()); + + var qtuple = new QTuple(q); + data = new ApplyData>(qtuple); + Assert.Null(data.GetNonQubitArgumentsAsString()); + } + } +} diff --git a/src/Simulation/Simulators.Type2/.gitignore b/src/Simulation/Simulators.Type2/.gitignore new file mode 100644 index 00000000000..a9a143aa9ce --- /dev/null +++ b/src/Simulation/Simulators.Type2/.gitignore @@ -0,0 +1 @@ +Microsoft.Quantum.Simulators.Type2.nuspec \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 new file mode 100644 index 00000000000..e351c75dfcb --- /dev/null +++ b/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 @@ -0,0 +1,103 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +######################################## +# When creating a package with dotnet pack, nuget changes every ProjectReference to be itself +# a PackageReference (without checking if that project has a corresponding package). +# This is problematic because we currently don't want to create a package for every dll. +# +# On the other hand, when creating a package using nuget pack, nuget does not +# identifies PackageReferences defined in the csproj, so all the dependencies +# are not listed and the package doesn't work. +# +# We don't want to hardcode the list of dependencies on the .nuspec, as they can +# quickly become out-of-sync. +# This script will find the PackageReferences recursively on the simulation projects and add them +# to the nuspec, so we can then create the package using nuget pack with the corresponding +# dependencies listed. +# +# nuget is tracking this problem at: https://github.com/NuGet/Home/issues/4491 +######################################## + +$target = Join-Path $PSScriptRoot "Microsoft.Quantum.Simulators.Type2.nuspec" + +if (Test-Path $target) { + Write-Host "$target exists. Skipping generating new one." + exit + } + + +# Start with the nuspec template +$nuspec = [xml](Get-Content (Join-Path $PSScriptRoot "Microsoft.Quantum.Simulators.Type2.nuspec.template")) +$dep = $nuspec.CreateElement('dependencies', $nuspec.package.metadata.NamespaceURI) + +function Add-PackageReferenceIfNew($ref) +{ + # Identify package's id either from "Include" or "Update" attribute: + $id = $ref.Include + $version = $ref.Version + + if ($id -eq $null -or $id -eq "") { + $id = $ref.Update + } + if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj')) + { + $id = [System.IO.Path]::GetFileNameWithoutExtension($id) + } + + if ($version -eq $null -or $version -eq "") { + $version = '$version$' + } + + # Check if package already added as dependency, only add if new: + $added = $dep.dependency | Where { $_.id -eq $id } + if (!$added) { + Write-Host "Adding $id (version: $version)" + $onedependency = $dep.AppendChild($nuspec.CreateElement('dependency', $nuspec.package.metadata.NamespaceURI)) + $onedependency.SetAttribute('id', $id) + $onedependency.SetAttribute('version', $version) + } +} + +# Recursively find PackageReferences on all ProjectReferences: +function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) +{ + Write-Host "`nFinding dependencies for $PathToCsproj" + $csproj = [xml](Get-Content $PathToCsproj) + + # Find all PackageReferences nodes: + $packageDependency = $csproj.Project.ItemGroup.PackageReference | Where-Object { $null -ne $_ } + $packageDependency | ForEach-Object { + $id = $_.Include + Write-Host "Detected package dependencies: $id" + } + + $packageDependency | ForEach-Object { + Add-PackageReferenceIfNew $_ + } + + $projectDependency = $csproj.Project.ItemGroup.ProjectReference | Where-Object { $null -ne $_ } + $projectDependency | ForEach-Object { + $id = $_.Include + Write-Host "Detected project dependencies: $id" + } + + # Assume there is a package for project references that are not tagged as to be included in the simulator package: + $projectDependency | Where-Object {$_.IncludeInSimulatorPackage -ne 'true' -and $_.IsQscReference -ne 'true'} | ForEach-Object { + Add-PackageReferenceIfNew $_ + } + + # Recursively check on project references if they are private: + $projectDependency | Where-Object {$_.IncludeInSimulatorPackage -eq 'true' -and $_.IsQscReference -ne 'true'} | ForEach-Object { + $id = $_.Include + Write-Host "Recurring for $id" + Add-NuGetDependencyFromCsprojToNuspec $_.Include + } +} + +# Find all dependencies packaged as part of Microsoft.Quantum.Simulators.Type2 +Add-NuGetDependencyFromCsprojToNuspec "Microsoft.Quantum.Simulators.Type2.csproj" + +# Save into .nuspec file: +$nuspec.package.metadata.AppendChild($dep) +$nuspec.Save($target) diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj new file mode 100644 index 00000000000..a8ac8f18e82 --- /dev/null +++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj @@ -0,0 +1,74 @@ + + + + + + + + + netstandard2.1 + false + false + + + + 8.0 + enable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + runtimes\win-x64\native\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + false + + + runtimes\osx-x64\native\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + false + + + runtimes\linux-x64\native\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + false + + + + diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template new file mode 100644 index 00000000000..0259a979f74 --- /dev/null +++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template @@ -0,0 +1,31 @@ + + + + Microsoft.Quantum.Simulators + $version$ + $title$ + Microsoft + QuantumEngineering, Microsoft + MIT + https://docs.microsoft.com/en-us/quantum + images\qdk-nuget-icon.png + false + Type2 simulators of quantum computers for the Q# programming language. + See: https://docs.microsoft.com/en-us/quantum/relnotes/ + © Microsoft Corporation. All rights reserved. + Quantum Q# Qsharp + + + + + + + + + + + + + + + diff --git a/src/Simulation/Simulators.Type2/Properties/AssemblyInfo.cs b/src/Simulation/Simulators.Type2/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..a11422cdc41 --- /dev/null +++ b/src/Simulation/Simulators.Type2/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allow the test assembly to use our internal methods +[assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators.Type2" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file diff --git a/src/Simulation/Common/Extensions.cs b/src/Simulation/Simulators/QuantumSimulator/Extensions.cs similarity index 100% rename from src/Simulation/Common/Extensions.cs rename to src/Simulation/Simulators/QuantumSimulator/Extensions.cs diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Simulation/Simulators/QuantumSimulator/Rx.cs b/src/Simulation/Simulators/QuantumSimulator/Rx.cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Simulation/Simulators/QuantumSimulator/Ry.cs b/src/Simulation/Simulators/QuantumSimulator/Ry.cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Simulation/Simulators/QuantumSimulator/Rz.cs b/src/Simulation/Simulators/QuantumSimulator/Rz.cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Simulation/Simulators/QuantumSimulator/SWAP.cs b/src/Simulation/Simulators/QuantumSimulator/SWAP.cs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/Simulation/Common/SimulatorBase.cs b/src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs similarity index 100% rename from src/Simulation/Common/SimulatorBase.cs rename to src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs diff --git a/src/Simulation/Common/StackTrace.cs b/src/Simulation/Simulators/QuantumSimulator/StackTrace.cs similarity index 100% rename from src/Simulation/Common/StackTrace.cs rename to src/Simulation/Simulators/QuantumSimulator/StackTrace.cs diff --git a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs index 0ad8fad241c..1b0d9e2a986 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs @@ -2,7 +2,9 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + @EnableTestingViaName("Test.TargetDefinitions.ExpNoIdUtil") internal operation ExpNoIdUtil(paulis : Pauli[], theta : Double, qubits : Qubit[], rotation : ((Pauli, Qubit) => Unit is Adj + Ctl)) : Unit is Ctl { if (Length(paulis) != Length(qubits)) { fail "Arrays 'paulis' and 'qubits' must have the same length"; } if (Length(paulis) == 1) { @@ -20,7 +22,7 @@ namespace Microsoft.Quantum.Intrinsic { } elif (paulis[0] == PauliZ) { IsingZZ(theta / 2.0, qubits[0], qubits[1]); } else { - fail "Type2 decompositions do not support PauliI"; + fail "Type2 decompositions do not support PauliI as an input to Exp"; } } } @@ -41,6 +43,7 @@ namespace Microsoft.Quantum.Intrinsic { } } + @EnableTestingViaName("Test.TargetDefinitions.SpreadZ") internal operation SpreadZ(from : Qubit, to : Qubit[]) : Unit is Adj { if (Length(to) > 0) { CNOT(to[0], from); @@ -52,6 +55,7 @@ namespace Microsoft.Quantum.Intrinsic { } } + @EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhase") internal operation ApplyGlobalPhase(theta : Double) : Unit is Ctl + Adj { body(...) {} controlled(controls, (...)) { @@ -65,6 +69,7 @@ namespace Microsoft.Quantum.Intrinsic { } } + @EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhaseFracWithR1Frac") internal operation ApplyGlobalPhaseFracWithR1Frac(numerator : Int, power : Int) : Unit is Adj + Ctl { body(...) {} controlled(ctrls, ... ) { @@ -77,6 +82,7 @@ namespace Microsoft.Quantum.Intrinsic { } } + @EnableTestingViaName("Test.TargetDefinitions.MapPauli") internal operation MapPauli(qubit : Qubit, from : Pauli, to : Pauli) : Unit is Adj { if (from == to) { } @@ -104,6 +110,7 @@ namespace Microsoft.Quantum.Intrinsic { } } + @EnableTestingViaName("Test.TargetDefinitions.ReducedDyadicFraction") internal function ReducedDyadicFraction(numerator : Int, denominatorPowerOfTwo : Int) : (Int,Int) { if (numerator == 0) { return (0,0); } mutable num = numerator; @@ -115,6 +122,7 @@ namespace Microsoft.Quantum.Intrinsic { return (num,denPow); } + @EnableTestingViaName("Test.TargetDefinitions.ReducedDyadicFractionPeriodic") internal function ReducedDyadicFractionPeriodic(numerator : Int, denominatorPowerOfTwo : Int) : (Int,Int) { let (k,n) = ReducedDyadicFraction(numerator,denominatorPowerOfTwo); // k is odd, or (k,n) are both 0 let period = 2*2^n; // \pi k / 2^n is 2\pi periodic, therefore k is 2 * 2^n periodic @@ -123,6 +131,7 @@ namespace Microsoft.Quantum.Intrinsic { return (kModPositive, n); } + @EnableTestingViaName("Test.TargetDefinitions.ArrayFromIndicesP") internal function ArrayFromIndiciesP(values : Pauli[], indicies : Int[]) : Pauli[] { mutable arr = new Pauli[Length(indicies)]; for (i in 0 .. Length(indicies) - 1) { @@ -131,6 +140,7 @@ namespace Microsoft.Quantum.Intrinsic { return arr; } + @EnableTestingViaName("Test.TargetDefinitions.ArrayFromIndicesQ") internal function ArrayFromIndiciesQ(values : Qubit[], indicies : Int[]) : Qubit[] { mutable arr = new Qubit[Length(indicies)]; for (i in 0 .. Length(indicies) - 1) { @@ -139,6 +149,7 @@ namespace Microsoft.Quantum.Intrinsic { return arr; } + @EnableTestingViaName("Test.TargetDefinitions.IndicesOfNonIdentity") internal function IndicesOfNonIdentity(paulies : Pauli[]) : Int[] { mutable nonIdPauliCount = 0; @@ -159,6 +170,7 @@ namespace Microsoft.Quantum.Intrinsic { return indices; } + @EnableTestingViaName("Test.TargetDefinitions.RemovePauliI") internal function RemovePauliI(paulis : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) { let indices = IndicesOfNonIdentity(paulis); let newPaulis = ArrayFromIndiciesP(paulis, indices); diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props index a49fe647e5c..6076e7bc662 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props @@ -20,6 +20,8 @@ + + From aaa736f8f70d54e43d64e783e34abd171d44e1ed Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sun, 23 Aug 2020 01:49:14 -0700 Subject: [PATCH 11/17] Reduce test surface for Type2 to avoid duplicaiton --- .../QuantumSimulatorTests/VerifyGates.cs | 1 - .../Circuits/BitOperations.qs | 33 - .../Circuits/Bug1514.qs | 27 - .../Circuits/Bug2212.qs | 29 - .../Circuits/Bug2248.qs | 38 - .../Circuits/Bug2469.qs | 23 - .../Circuits/Bug3059.qs | 35 - .../Circuits/Bug3758.qs | 50 - .../Circuits/CallableInterfacesTest.qs | 138 -- .../Circuits/ClassicalRotationsTest.qs | 36 - .../Circuits/ClosedType.qs | 203 -- .../Circuits/ConditionalExpression.qs | 24 - .../Circuits/Convert.qs | 36 - .../Circuits/CoreOperations.qs | 626 ----- .../Circuits/ExpTest.qs | 32 - .../Simulators.Type2.Tests/Circuits/Fail.qs | 99 - .../Circuits/Functions.qs | 28 - .../Circuits/Generics.qs | 884 -------- .../Circuits/GetAvailableTest.qs | 34 - .../Circuits/Issue132.qs | 25 - .../Circuits/Issue76.qs | 31 - .../Simulators.Type2.Tests/Circuits/Length.qs | 33 - .../Circuits/NamedItems.qs | 30 - .../Circuits/Namespaces.qs | 22 - .../Circuits/NativeOperations.cs | 104 - .../Circuits/NativeOperations.qs | 25 - .../Circuits/PrimitiveEquivalences.qs | 113 - .../Circuits/Recursion.qs | 56 - .../Circuits/RepeatUntilSuccess.qs | 46 - .../Circuits/ResourcesEstimator.qs | 60 - .../Circuits/RuntimeMetadataTest.qs | 38 - .../Circuits/SetQubit.qs | 20 - .../Circuits/StartOperation.qs | 152 -- .../Circuits/SwapTest.qs | 28 - .../Circuits/TeleportTest.qs | 42 - .../Simulators.Type2.Tests/Circuits/Tuples.qs | 81 - .../Circuits/UnitTests.qs | 23 - .../Circuits/UserDefinedTypes.qs | 132 -- .../Circuits/VerifyUnitary.qs | 22 +- .../Circuits/bug3223.qs | 39 - .../Simulators.Type2.Tests/CoreTests.cs | 283 --- .../DebuggingToolsTests.cs | 293 --- .../DiagnosticsWrappers.qs | 11 - .../Simulators.Type2.Tests/GenericsTests.cs | 852 ------- .../Simulators.Type2.Tests/GetQubitsTests.cs | 395 ---- .../NativeOperationsTests.cs | 67 - .../OperationsTestHelper.cs | 53 +- .../PartialMapperTests.cs | 175 -- .../PrimitivesExtensionsTests.cs | 50 - .../Simulators.Type2.Tests/QArrayTests.cs | 315 --- .../Simulators.Type2.Tests/QTupleTests.cs | 207 -- .../QuantumSimulatorTests/BasicTests.cs | 3 +- .../QuantumSimulatorTests/CircuitsTests.cs | 27 - .../QuantumSimulatorTests/QubitReleaseTest.cs | 64 - .../QuantumTestSuite.cs | 79 - .../QuantumTestSuite/AssertEqualInPlace.qs | 117 - .../AssertProbAndCliffordOneQubitTest.qs | 86 - .../AssertProbAndMeasureOneQubitTest.qs | 65 - .../QuantumTestSuite/AssertProbMultiQubit.qs | 100 - .../QuantumTestSuite/AssertProbOneQubit.qs | 48 - .../QuantumTestSuite/AssertQubitUnitary.qs | 55 - .../QuantumTestSuite/AssertState.qs | 61 - .../QuantumTestSuite/AssertUnitary.qs | 53 - .../QuantumTestSuite/Complex.qs | 124 - .../QuantumTestSuite/Config.qs | 49 - .../ControlledOperationTester.qs | 53 - .../ControlledOperationsTestUtils.qs | 74 - .../IterateThroughCartesianProduct.qs | 67 - .../QuantumTestSuite/JointOneQubitTests.qs | 68 - .../QuantumTestSuite/KnownIssues.qs | 59 - .../QuantumTestSuite/LinearAlgebra.qs | 331 --- .../QuantumTestSuite/ManyControlQubitsTest.qs | 36 - .../QuantumTestSuite/Math.qs | 31 - .../QuantumTestSuite/Matrices.qs | 2004 ----------------- .../QuantumTestSuite/OneQubitTestList.qs | 163 -- .../QuantumTestSuite/OneQubitUnitaries.qs | 28 - .../QuantumTestSuite/PauliExpectation.qs | 93 - .../QuantumTestSuite/SelfTests.qs | 43 - .../QuantumTestSuite/TestSuiteCalculations.nb | 1280 ----------- .../QuantumTestSuite/ThreeQubitUnitaries.qs | 34 - .../QuantumTestSuite/TwoQubitUnitaries.qs | 102 - .../QubitManagerTests.cs | 446 ---- .../Simulators.Type2.Tests/RangeTests.cs | 174 -- .../RuntimeMetadataTests.cs | 821 ------- .../SimulatorBaseTests.cs | 481 ---- .../Simulators.Type2.Tests/StackTraceTests.cs | 134 -- .../StartOperationTests.cs | 190 -- .../TrivialSimulator.cs | 43 - .../TypeExtensionsTest.cs | 152 -- .../Microsoft.Quantum.Simulators.Type2.csproj | 7 - .../TargetPackages/Type2.Package.props | 1 + 91 files changed, 26 insertions(+), 14019 deletions(-) delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/CoreTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/GenericsTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QArrayTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QTupleTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/RangeTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs b/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs index 0cc32328fdf..7b1b652e6cc 100644 --- a/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs +++ b/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System; -using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; using Xunit; diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs deleted file mode 100644 index bf7556f7704..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/BitOperations.qs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - operation TimesTwo (v : Int) : Int - { - return v <<< 1; - } - - operation DivideTwo (v : Int) : Int - { - return v >>> 1; - } - - operation IsEven (v : Int) : Bool - { - return (v &&& 1) == 0; - } - - operation BitOperationsTest () : Unit - { - AssertEqual(14, TimesTwo(7)); - AssertEqual(11, DivideTwo(22)); - AssertEqual(11, DivideTwo(23)); - - AssertEqual(17, DivideTwo(98) &&& 0x51); - AssertEqual(0xF000F, 0xF ||| TimesTwo(0x78002)); - AssertEqual(0x00110007, 0x000f000f ^^^ (TimesTwo(0x78002) + TimesTwo(0x78002))); - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs deleted file mode 100644 index e01bd983168..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug1514.qs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Bug1514 { - - operation Bug1514() : Unit { - Foo(); - Bar(3); - } - - operation Foo() : Unit { - } - - function Bar<'T>(a: 'T) : Unit { - } -} - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Bug1514; - - operation Bug1514Test () : Unit - { - Bug1514(); - } -} - \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs deleted file mode 100644 index 82ccb4bcfeb..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2212.qs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Bug2212 { - - function F<'T> (arg1 :'T , arg : Unit) : 'T { - return arg1; - } - - function RecursiveGeneric2<'T> (arg1 : (Unit -> 'T), arg2 : Int) : Int { - if ( arg2 <= 0 ) { - return arg2; - } else { - let _ = arg1(); - return RecursiveGeneric2<(Unit -> 'T)>(F(arg1,_),arg2 - 1); - } - } -} - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Bug2212; - - operation Bug2212Test () : Unit - { - // Calling this function used to trigger a run time exception. - let x = RecursiveGeneric2(F(3,_), 10); - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs deleted file mode 100644 index 6f6f1dac376..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2248.qs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Bug2248 { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Diagnostics; - - - operation TestDumpMachineDoesntChangeState (N : Int) : Unit - { - using (qs = Qubit[N]) - { - for (q in qs) - { - X(q); - DumpMachine(""); - AssertQubit(One, q); - Reset(q); - } - } - } -} - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Bug2248; - - operation Bug2248Test () : Unit - { - for(i in 1..4) - { - TestDumpMachineDoesntChangeState(i); - } - } -} - \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs deleted file mode 100644 index 8cddbc52100..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug2469.qs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - operation TestSafeToRunCliffords (flag : Bool) : Unit - { - using (q = Qubit()) - { - X(q); - if (flag) - { - Y(q); - Z(q); - H(q); - S(q); - } - X(q); // So that it's safe to release - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs deleted file mode 100644 index 98a3c3339e5..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3059.qs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Bug3059 { - - function CheckPair (fst : Int, snd : Int) : Unit { } - - function WithDiscardedSymbols (fct : ((Int, Int) -> Unit), arg : (Int, (Int, Int))[]) : Unit - { - let _ = arg; - let mapper = fct(1, _); - - for (_ in arg) { - for (_ in arg) { - for ((_, (i, _)) in arg) { - - let partial = fct(i, _); - partial(0); - } - } - } - let _ = arg; - mapper(0); - } -} - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Bug3059; - - operation DiscardedSymbolsTest () : Unit { - WithDiscardedSymbols(CheckPair, new (Int, (Int, Int))[5]); - } -} - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs deleted file mode 100644 index e65347a39e1..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Bug3758.qs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace Bug3758 { - open Microsoft.Quantum.Intrinsic; - - function Reverse<'T> (array : 'T[]) : 'T[] { - let nElements = Length(array); - return array[nElements-1..-1..0]; - } - - operation ApplyWithInputTransformation<'T, 'U>(fn : ('U -> 'T), op : ('T => Unit), input : 'U) : Unit { - op(fn(input)); - } - - function TransformedOperation<'T, 'U>(fn : ('U -> 'T), op : ('T => Unit)) : ('U => Unit) { - return ApplyWithInputTransformation(fn, op, _); - } - - - /// # Summary - /// An example operation used for testing input transformations. - operation TransformationReferenceForward(register : Qubit[]) : Unit is Adj + Ctl { - X(register[0]); - H(register[1]); - X(register[2]); - } - - /// # Summary - /// An example operation used for testing input transformations. - operation TransformationReferenceReverse(register : Qubit[]) : Unit is Adj + Ctl { - X(register[2]); - H(register[1]); - X(register[0]); - } -} - - - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - open Bug3758; - open Microsoft.Quantum.Diagnostics; - - operation TransformedOperationTest() : Unit { - AssertOperationsEqualReferenced(3, - TransformedOperation(Reverse, TransformationReferenceReverse), - TransformationReferenceForward - ); - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs deleted file mode 100644 index d21286ae838..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/CallableInterfacesTest.qs +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - operation NoOp (qubit : Qubit) : Unit { - - } - - - operation NoOpAdjoint (qubit : Qubit) : Unit { - - body (...) { - } - - adjoint invert; - } - - - operation NoOpControlled (qubit : Qubit) : Unit { - - body (...) { - } - - controlled distribute; - } - - - operation NoOpUnitary (qubit : Qubit) : Unit { - - body (...) { - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation NoOpTuple (r : Result, i : Int, qubit : Qubit) : Unit { - - } - - - operation NoOpAdjointTuple (r : Result, i : Int, qubit : Qubit) : Unit { - - body (...) { - } - - adjoint invert; - } - - - operation NoOpControlledTuple (r : Result, i : Int, qubit : Qubit) : Unit { - - body (...) { - } - - controlled distribute; - } - - - operation NoOpUnitaryTuple (r : Result, i : Int, qubit : Qubit) : Unit { - - body (...) { - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation CheckPlain (gate : (Qubit => Unit), qubit : Qubit) : Unit { - - gate(qubit); - } - - - operation CheckAdjoint (gate : (Qubit => Unit : Adjoint), qubit : Qubit) : Unit { - - Adjoint gate(qubit); - } - - - operation CheckControlled (gate : (Qubit => Unit : Controlled), qubit : Qubit) : Unit { - - - using (ctrls = Qubit[2]) { - Controlled gate(ctrls, qubit); - } - } - - - operation CheckUnitary (gate : (Qubit => Unit : Adjoint, Controlled), qubit : Qubit) : Unit { - - - using (ctrls = Qubit[2]) { - Adjoint Controlled gate(ctrls, qubit); - Controlled (Adjoint gate)(ctrls, qubit); - } - } - - - operation OneRound (plain : (Qubit => Unit), adj : (Qubit => Unit : Adjoint), ctr : (Qubit => Unit : Controlled), uni : (Qubit => Unit : Adjoint, Controlled)) : Unit { - - - using (qubits = Qubit[1]) { - let qubit = qubits[0]; - CheckPlain(plain, qubit); - CheckPlain(adj, qubit); - CheckPlain(ctr, qubit); - CheckPlain(uni, qubit); - CheckAdjoint(adj, qubit); - CheckAdjoint(uni, qubit); - CheckControlled(ctr, qubit); - CheckControlled(uni, qubit); - CheckUnitary(uni, qubit); - } - } - - - operation CallableInterfacesTest () : Unit { - - - // good 'ol operations - OneRound(NoOp, NoOpAdjoint, NoOpControlled, NoOpUnitary); - - // one level of partial application - OneRound(NoOpTuple(Zero, 1, _), NoOpAdjointTuple(Zero, 1, _), NoOpControlledTuple(Zero, 1, _), NoOpUnitaryTuple(Zero, 1, _)); - - // two level of partial application - OneRound((NoOpTuple(One, _, _))(1, _), (NoOpAdjointTuple(One, _, _))(1, _), (NoOpControlledTuple(One, _, _))(1, _), (NoOpUnitaryTuple(One, _, _))(1, _)); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs deleted file mode 100644 index 58993da3734..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/ClassicalRotationsTest.qs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Math; - - - operation IncrementWithRotationsTest (start : Int) : Int { - - - using (qubits = Qubit[3]) { - for (shift in 0..2) { - if (((start >>> shift) &&& 1) == 1) { - R(PauliX, PI(), qubits[shift]); - } - } - - CCNOT(qubits[0], qubits[1], qubits[2]); - CNOT(qubits[0], qubits[1]); - //Rx(PI(), qubits[0]); - RFrac(PauliX, 1, 1, qubits[0]); - - let b0 = M(qubits[0]) == One ? 1 | 0; - let b1 = M(qubits[1]) == One ? 1 | 0; - let b2 = M(qubits[2]) == One ? 1 | 0; - - ResetAll(qubits); - - return b2 * 4 + b1 * 2 + b0; - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs deleted file mode 100644 index ad486935bed..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/ClosedType.qs +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// This files contains ClosedType version of operations that can normally be implemented -// with generics to verify that they can be used interchangeably. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.ClosedType { - - open Microsoft.Quantum.Intrinsic; - - - newtype Qs = Qubit[]; - - newtype UDT_C2 = (String, Int, Double); - - newtype UDT_C3 = (String, (Double, Pauli), Result); - - - operation AsString (v : Result) : String { - - - if (v == One) { - return $"uno"; - } - else { - return $"cero"; - } - } - - - operation Trace (tag : String) : Unit { - body intrinsic; - adjoint intrinsic; - controlled intrinsic; - controlled adjoint intrinsic; - } - - - operation TraceGate (gate : (Qubit => Unit : Adjoint, Controlled), tag : String, qubit : Qubit) : Unit { - - body (...) { - Trace(tag); - gate(qubit); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation ClosedType2 (tag : (String, Int, Double)) : Unit { - - body (...) { - let (msg, i, d) = tag; - Trace(msg); - } - - adjoint invert; - } - - - operation ClosedType3 (tag : (String, (Double, Pauli), Result)) : Unit { - - body (...) { - let (msg, t, r) = tag; - Trace(msg); - } - - controlled distribute; - } - - - operation ClosedType4 (r1 : Result, (t1 : String, t2 : Int), r2 : Result) : Unit { - - body (...) { - Trace(t1); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation ClosedType5 (tag : (String, Int, Double, Result)) : Unit { - - body (...) { - let (msg, i, d, r) = tag; - Trace(msg); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation Map (mapper : (Result => String), source : Result[]) : String[] { - - mutable result = new String[Length(source)]; - - for (i in 0 .. Length(source) - 1) { - let m = mapper(source[i]); - set result = result w/ i <- m; - } - - return result; - } - - - operation Iter (callback : (String => Unit), source : String[]) : Unit { - - - for (i in 0 .. Length(source) - 1) { - callback(source[i]); - } - } - - - operation Repeat (callback : (Qubit => Unit : Adjoint, Controlled), bodyCount : Int, adjointCount : Int, controlledCount : Int, source : Qubit) : Unit { - - body (...) { - - for (i in 1 .. bodyCount) { - callback(source); - } - - for (i in 1 .. adjointCount) { - Adjoint callback(source); - } - - for (i in 1 .. controlledCount) { - - using (ctrls = Qubit[1]) { - Controlled callback(ctrls, source); - } - } - } - - adjoint invert; - } - - - operation TestIter () : Unit { - - let ctrls = new Qubit[2]; - let a = [One, Zero, Zero]; - Iter(Trace, Map(AsString, a)); - let b = [One, One, Zero, Zero, Zero]; - Iter(Adjoint Trace, Map(AsString, b)); - let c = [One, Zero, One, One]; - let ctrlOp = Controlled Trace(ctrls, _); - Iter(ctrlOp, Map(AsString, c)); - let d = [One, Zero, One, Zero, One, Zero, One, Zero, One]; - let ctrlAdjOp = Adjoint Controlled Trace(ctrls, _); - Iter(ctrlAdjOp, Map(AsString, d)); - } - - - operation TestRepeatPartial () : Unit { - - let p1 = Repeat(_, 5, 2, _, _); - let p2 = p1(_, 3, _); - - using (qubits = Qubit[1]) { - p2(TraceGate(X, $"normal", _), qubits[0]); - Adjoint p2(TraceGate(X, $"adjoint", _), qubits[0]); - } - } - - - operation TestUDTsUnwrapping () : Unit { - - let d2a = ($"d2a", 2, 2.0); - let d2b = ($"d2b", 2, 2.0); - let u2c = UDT_C2(d2b); - let d2x = ($"d2x", 2, 2.0); - let d2y = ($"d2y", 2, 2.0); - let u2x = UDT_C2(d2x); - let u2y = UDT_C2(d2y); - - using (ctrls = Qubit[1]) { - let qs = Qs(ctrls); - ClosedType2(d2a); - ClosedType2((UDT_C2(d2b))!); - Adjoint ClosedType2(d2a); - Adjoint ClosedType2(u2c!); - let p = ClosedType5(_, _, _, One); - p(d2x); - p((UDT_C2(d2y))!); - Adjoint p(d2x); - Adjoint p(u2y!); - Controlled p(ctrls, u2x!); - Controlled p((Qs(ctrls))!, u2y!); - Adjoint Controlled p(qs!, u2x!); - Adjoint Controlled p(ctrls, u2y!); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs deleted file mode 100644 index 8ecad7f1c0f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/ConditionalExpression.qs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - operation ConditionalExpressionTest() : Unit { - using (q = Qubit()) { - AssertQubit(Zero, q); - - mutable flag = false; - (flag ? X | I)(q); - AssertQubit(Zero, q); - - set flag = true; - (flag ? X | I)(q); - AssertQubit(One, q); - - Reset(q); - } - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs deleted file mode 100644 index 0bfa8a9bb98..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Convert.qs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Convert; - - - operation ConvertTest () : Unit { - let (v1, b1) = MaybeBigIntAsInt(10L); - let (v2, b2) = MaybeBigIntAsInt(9223372036854775807L); - let (v3, b3) = MaybeBigIntAsInt(9223372036854775808L); - let (v4, b4) = MaybeBigIntAsInt(-10L); - let (v5, b5) = MaybeBigIntAsInt(-9223372036854775808L); - let (v6, b6) = MaybeBigIntAsInt(-9223372036854775809L); - - AssertEqual(10, v1); - AssertEqual(true, b1); - - AssertEqual(9223372036854775807, v2); - AssertEqual(true, b2); - - AssertEqual(0, v3); - AssertEqual(false, b3); - - AssertEqual(-10, v4); - AssertEqual(true, b4); - - //AssertEqual(-9223372036854775808, v5); should not fail - AssertEqual(true, b5); - - AssertEqual(0, v6); - AssertEqual(false, b6); - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs deleted file mode 100644 index 75898a27657..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/CoreOperations.qs +++ /dev/null @@ -1,626 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Tests.CoreOperations { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Math; - - - newtype Q = Qubit; - - newtype Qs = Qubit[]; - - newtype T1 = (Qubit, Qubit); - - newtype T2 = (Qubit, Qubit[]); - - newtype T3 = (Qubit[], Qs); - - newtype T4 = (Int, (Double, Bool, Result)); - - newtype T5 = (Pauli, Qubit[], Qs, Q); - - newtype Plain1 = ((Qubit, Qubit) => Unit); - - newtype Adj1 = ((Qubit, Qubit) => Unit : Adjoint); - - newtype Adj2 = Adj1; - - newtype Ctrl1 = ((Qubit, Qubit) => Unit : Controlled); - - newtype U1 = ((Qubit, Qubit, Qubit[]) => Unit : Adjoint, Controlled); - - newtype U2 = U1; - - newtype U3 = (Qubit => Unit : Adjoint, Controlled); - - - operation BPlain1 (available : Int, q1 : Qubit, action : ((Qubit, Qubit) => Unit)) : Unit { - - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action(b[0], b[1]); - } - } - - - operation BPlain2 (available : Int, (q1 : Qubit, q2 : Qubit), action : Plain1) : Unit { - - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action!(b[0], b[1]); - } - } - - - operation BAdj1 (available : Int, (q1 : Qubit, q2 : Qubit, qs : Qubit[]), action : ((Qubit, Qubit) => Unit : Adjoint)) : Unit { - - body (...) { - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action(b[0], b[1]); - } - } - - adjoint invert; - } - - - operation BAdj2 (available : Int, qs : Qubit[], action : Adj1) : Unit { - - body (...) { - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action!(b[0], b[1]); - } - } - - adjoint invert; - } - - - operation BCtrl1 (available : Int, qs : Qs, action : ((Qubit, Qubit) => Unit : Controlled)) : Unit { - - body (...) { - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action(b[0], b[1]); - } - } - - controlled distribute; - } - - - operation BCtrl2 (available : Int, (qs1 : Qubit[], qs2 : Qs), action : Ctrl1) : Unit { - - body (...) { - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action!(b[0], b[1]); - } - } - - controlled distribute; - } - - - operation BU1 (available : Int, qs : Qubit[], action : ((Qubit, Qubit, Qubit[]) => Unit : Adjoint, Controlled)) : Unit { - - body (...) { - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action(b[0], b[1], qs); - } - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation BGen<'T> (available : Int, arg : 'T, action : ((Qubit, Qubit, 'T) => Unit : Adjoint, Controlled)) : Unit { - - body (...) { - - borrowing (b = Qubit[2]) { - Trace(available, b[0]); - Trace(available, b[1]); - action(b[0], b[1], arg); - } - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation Action (q0 : Qubit, q1 : Qubit, array : Qubit[]) : Unit { - - body (...) { - SWAP(q0, q1); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation ActionGen<'T> (q0 : Qubit, q1 : Qubit, array : 'T) : Unit { - - body (...) { - SWAP(q0, q1); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation TestAllVariants<'T> (available : Int, args : 'T, action : ((Qubit, Qubit, 'T) => Unit : Adjoint, Controlled), B : ((Int, 'T, ((Qubit, Qubit, 'T) => Unit : Adjoint, Controlled)) => Unit : Adjoint, Controlled)) : Unit { - - - using (ctrls = Qubit[2]) { - B(available, args, action); - Adjoint B(available, args, action); - Controlled B(ctrls, (available, args, action)); - Adjoint Controlled B(ctrls, (available, args, action)); - } - } - - - operation BorrowingTest () : Unit { - - - using (qubits = Qubit[5]) { - let q0 = qubits[0]; - let q1 = qubits[1]; - let q2 = qubits[2]; - let q3 = qubits[3]; - let q4 = qubits[4]; - let e = new Qubit[0]; - let n = new Qubit[5]; - let a_0 = [q0]; - let a_2_2 = [q2, q2]; - let a_2_4 = qubits[2 .. 4]; - let q_e = Qs(e); - let q_n = Qs(n); - let q_1 = Qs([q1]); - let q_2_2 = Qs(a_2_2); - let q_2_4 = Qs(a_2_4); - let t1_1_n = T1(q1, n[0]); - let t1_1_2 = T1(q1, q2); - let t2_1_n = T2(q1, n); - let t2_1_e = T2(q1, e); - let t2_1_a3 = T2(q1, a_2_4); - let t3_e_e = T3(e, q_e); - let t3_n_n = T3(n, q_n); - let t3_all = T3([q1, q2], q_2_4); - - BPlain1(0, n[0], Action(_,_,qubits)); // 0, q5 & q6 - - BPlain1(1, q1, Action(_,_,a_2_4)); // 1, q0 & q6 - BPlain2(1, ((Q(q0))!, (Q(q0))!), Plain1(Action(_,_,a_2_4))); // 1, q1 & q6 - - BPlain1(3, q0, Action(_,_,a_2_2)); // 3, q1 & q3 - BPlain2(3, (q1, q2), Plain1(SWAP)); // 3, q0 & q3 - - BPlain1(4, q1, (Plain1(SWAP))!); // 4, q0 & q2 - BPlain2(5, (n[0], n[1]), Plain1(SWAP)); // 5, q0 & q1 - - BAdj1(5, (n[0], n[1], e), (Adj1(SWAP))!); // 5, q0 & q1 - (Adjoint BAdj1)(1, (q1, q2, q_2_4!), SWAP); // 1, q0 & q6 - BAdj2(0, qubits, (Adj2(Adj1(SWAP)))!); // 0, q5 & q6 - (Adjoint BAdj2)(1, (Qs([q0, n[0]]))!, (Adj2(Adj1(Action(_,_,a_2_4))))!); // 1, q1 & q5 - - BCtrl1(5, q_n, SWAP); // 5, q0 & q1 - (Controlled BCtrl1)([q1], (1, q_2_4, SWAP)); // 1, q0 & q5 - BCtrl2(0, (a_2_2, Qs(qubits)), Ctrl1(SWAP)); // 0, q5 & q6 - let ctrl = (Controlled (Ctrl1(Action(_,_,a_2_2)))!)([q4], (_,_)); - (Controlled BCtrl2)([q0], (1, ([q3], q_n), Ctrl1(ctrl))); // 1, q1 & q5 - (Controlled BCtrl2)(q_e!, (5, (n, q_e), Ctrl1(Action(_,_,n)))); // 5, q0 & q1 - - TestAllVariants(0, qubits, ActionGen, BGen); // 0, q5 & q6 (q7 & q8 for controlled) - TestAllVariants(2, (q0, q1, q4), ActionGen<(Qubit, Qubit, Qubit)>, BGen<(Qubit, Qubit, Qubit)>); // 2, q2 & q3 - TestAllVariants(4, (Qs(q_1!))!, Action, BGen); // 4, q0 & q2 - TestAllVariants(3, [q0, q1], Action(_,_,_), BU1); // 3, q2 & q3 - TestAllVariants(0, qubits, ActionGen(_,_,_), BGen); // 0, q5 & q6 (q7 & q8 for controlled) - TestAllVariants(2, Qs([q0, q1, q4]), ActionGen(_,_,_), BGen); // 2, q2 & q3 - TestAllVariants(5, n, ActionGen(_,_,_), BGen); // 5, q0 & q1 - TestAllVariants(5, n, Action(_,_,_), BGen); // 5, q0 & q1 - TestAllVariants(4, a_0, Adjoint (ActionGen(_,_,_)), BGen); // 4, q1 & q2 - - TestAllVariants(1, e, (Controlled Action([q1,q2,q3,q0], (_,_,_))), BGen); // 1, q4 & q5 (q7 for controlled) - TestAllVariants(0, e, (Controlled (Adjoint ActionGen))(qubits, (_,_,_)), BGen); // 0, q5 & q6 (q7 & q8 for controlled) - } - } - - - operation SimpleRangeTest () : Unit { - - mutable ints = new Int[12]; - mutable results = new Result[12]; - mutable qubits = new Qubit[12]; - mutable qs = new Qs[12]; - mutable u1s = new U1[12]; - mutable state = new Complex[12]; - - for (i in 10 .. -2 .. 4) { - set ints = ints w/ i <- i; - set results = results w/ i <- One; - set qs = qs w/ i <- Qs(qubits); - set u1s = u1s w/ i <- U1(Action); - set state = state w/ i <- Complex(IntAsDouble(i), IntAsDouble(i + 1)); - Trace(ints[i]); - Trace(results[i]); - Trace(qubits[i]); - Trace(qs[i]); - Trace(u1s[i]); - Trace(state[i]); - } - } - - - operation SimpleDumpTest () : Unit { - - body (...) { - - using (qubits = Qubit[3]) { - Message($"Starting test"); - DumpMachine($"dumptest-start.txt"); - ApplyToEachCA(H, qubits); - DumpMachine($"dumptest-h.txt"); - DumpMachine($""); - - using (q2 = Qubit[2]) { - Assert([PauliZ, PauliZ], q2, Zero, $"Qubit should be in Zero state"); - DumpRegister($"dumptest-former.txt", qubits); - DumpRegister($"dumptest-later.txt", q2); - DumpRegister($"dumptest-one.txt", [qubits[1]]); - DumpRegister($"dumptest-two.txt", [qubits[1], q2[1]]); - DumpRegister((), [qubits[1], q2[1]]); - DumpRegister("", [q2[1], qubits[1]]); - DumpMachine($"dumptest-all.txt"); - ApplyToEachCA(Controlled X(qubits, _), q2); - DumpMachine($"dumptest-entangled.txt"); - DumpRegister((), [qubits[1], q2[1]]); - DumpRegister($"dumptest-twoQubitsEntangled.txt", [qubits[0], q2[0]]); - DumpMachine(); - ApplyToEachCA(Adjoint Controlled X(qubits, _), q2); - } - - Adjoint ApplyToEachCA(H, qubits); - } - - DumpMachine($"dumptest-end.txt"); - DumpMachine(); - } - } - - operation LockedFileDumpTest () : Unit { - using (qubits = Qubit[3]) { - DumpMachine($"locked-file.txt"); - DumpRegister($"locked-file.txt", qubits[0..1]); - - // Make sure execution continues: - Message("Done."); - } - } - - operation ZeroQubitsTest() : Unit - { - using (qubits = Qubit[0]) - { - if (Length(qubits) == 0) - { - Trace("zero"); - } - } - } -} - -// Using a different namespace, so tests can be auto-discovered. -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Math; - - operation QubitAllocationTest() : Unit { - let n = 3; - - using (q = Qubit()) { - Assert([PauliZ], [q], Zero, "Expecting Zero - a"); - } - - using (qs = Qubit[n]) { - AssertEqual(n, Length(qs)); - Assert([PauliZ, PauliZ, PauliZ], qs, Zero, "Expecting Zero - b"); - } - - using ((q1, (q2t, (_, q3s, _, q4s))) = (Qubit(), ((Qubit(), Qubit[2]), (Qubit(), Qubit[n], Qubit[n-1], Qubit[4])))) { - let (a, b) = q2t; - - AssertEqual(2, Length(b)); - AssertEqual(n, Length(q3s)); - AssertEqual(4, Length(q4s)); - - Assert([PauliZ, PauliZ], [q1, a], Zero, "Expecting Zero - c"); - Assert([PauliZ, PauliZ], b, Zero, "Expecting Zero - d"); - Assert([PauliZ, PauliZ, PauliZ], q3s, Zero, "Expecting Zero - d"); - Assert([PauliZ, PauliZ, PauliZ, PauliZ], q4s, Zero, "Expecting Zero - e"); - - } - - using (qt = (Qubit(), (Qubit[1], Qubit[2]))) { - let (qt1, (qt2a, qt2b)) = qt; - - Assert([PauliZ], [qt1], Zero, "Expecting Zero - f"); - Assert([PauliZ], qt2a, Zero, "Expecting Zero - g"); - Assert([PauliZ, PauliZ], qt2b, Zero, "Expecting Zero - h"); - } - } - - - operation ExtendedForTest() : Unit - { - mutable n = 0; - - using (qs = Qubit[3]) { - - for(q in qs) { - Assert([PauliZ], [q], Zero, "Expecting Zero - a"); - set n = n + 1; - } - - AssertEqual(3, n); - } - } - - function WhileLoopTest() : Unit - { - mutable ctr = 0; - while (ctr < 10) { - set ctr += 1; - } - AssertEqual(ctr, 10); - } - - newtype WrappedInt = (Int); - - operation InterpolatedStringTest() : Unit - { - let a = 5; - let b = "Hello"; - let c = 1..2..3; - let d = WrappedInt(6); - let s = $"{b}, world! {a}+{RangeStart(c)}={d!}"; - AssertEqual("Hello, world! 5+1=6", s); - } - - operation RandomOperationTest() : Unit - { - let a = Random([1.0, 0.0]); - AssertEqual(0, a); - - let b = Random([0.0,0.1]); - AssertEqual(1, b); - } - - function BigIntTest() : Unit - { - let a = 2L; - let b = 32L; - AssertEqual(b, a ^ 5); - AssertEqual(0L, a &&& b); - AssertEqual(34L, a + b); - let arr = [true, true, true, false, true]; // Not an even number of bytes - AssertEqual(23L, BoolArrayAsBigInt(arr)); - let arr2 = [true, true, true, false, true, false, false, false, - true, false, false, false, false, false, false, false]; // Exactly 2 bytes - AssertEqual(279L, BoolArrayAsBigInt(arr2)); - AssertEqual(37L, BoolArrayAsBigInt(BigIntAsBoolArray(37L))); - let (div, rem) = DivRemL(16L, 5L); - AssertEqual(3L, div); - AssertEqual(1L, rem); - AssertEqual(7L, MaxL(7L, 5L)); - AssertEqual(5L, MinL(7L, 5L)); - AssertEqual(1L, ModPowL(3L, 100L, 2L)); - } - - operation RangePropsTest() : Unit - { - let range = 1..2..10; - let actual = RangeStart(range) + RangeEnd(range) + RangeStep(range); - AssertEqual(13, actual); - } - - function ArraySlicingTest() : Unit - { - let arr = [1,2,3,4,5,6]; - let slice1 = arr[3...]; - AssertEqual(slice1, [4,5,6]); - let slice2 = arr [0 .. 2 ... ]; - AssertEqual(slice2, [1,3,5]); - let slice3 = arr[...2]; - AssertEqual(slice3, [1,2,3]); - let slice4 = arr[...2..3]; - AssertEqual(slice4, [1,3]); - let slice5 = arr[...2...]; - AssertEqual(slice5, [1,3,5]); - let slice6 = arr[...]; - AssertEqual(slice6, arr); - let slice7 = arr [4 .. -2 ... ]; - AssertEqual(slice7, [5,3,1]); - let slice8 = arr[ ... 0-1 .. 3]; - AssertEqual(slice8, [6,5,4]); - let slice9 = arr[...4-5...]; - AssertEqual(slice9, [6,5,4,3,2,1]); - } - - operation ReturnFromWithinUsing() : Int { - using (q = Qubit()){ - return 1; - } - } - - operation ReturnFromWithinBorrowing() : Int { - borrowing (q = Qubit()){ - return 1; - } - } - - operation ReturnTest() : Unit { - let _ = ReturnFromWithinUsing(); - let _ = ReturnFromWithinBorrowing(); - } - - operation VariablesScopeTest() : Unit - { - mutable a = 0; - - using (qubits = Qubit[5]) - { - for(q in qubits) { - set a = a + 1; - } - AssertEqual(5, a); - - for(q in 0 .. 3) { - set a = a + 1; - } - AssertEqual(9, a); - } - - borrowing (qubits = Qubit[2]) - { - for(q in qubits) { - set a = a + 1; - } - AssertEqual(11, a); - - for(q in 0 .. 0) { - set a = a + 1; - } - AssertEqual(12, a); - } - } - - // Returning the value returned by a function - // that returns Unit... - // Not totally sure if this should be allowed, but it works as of v0.3 - function Bar() : Unit { } - - function Foo<'T>(a: 'T) : Unit { - return Bar(); - } - - operation Bug2186Test() : Unit { - return Foo(3); - } - - operation UsingQubitCheck () : Unit - { - using (q = Qubit()) - { - X(q); - // Should raise an exception - } - } - - operation ReleaseMeasuredQubitCheck () : Unit - { - using (q = Qubit()) - { - X(q); - let r = M(q); - // Should not raise an exception - } - } - - operation BorrowingQubitCheck () : Unit - { - using (q = Qubit()) - { - QubitBorrower(); - } - } - - operation QubitBorrower() : Unit - { - borrowing (q = Qubit()) - { - X(q); - // Should raise an exception - } - } - - operation DumpPhaseTest() : Unit - { - using (qs = Qubit[5]) { - H(qs[0]); - Controlled X(qs[0..0], qs[1]); - T(qs[1]); - DumpRegister($"dumptest-entangled-and-phased.txt", qs[0..1]); - ResetAll(qs); - - for(q in qs) { H(q); } - - R1Frac(1, 3, qs[0]); - R1Frac(1, 2, qs[1]); - R1Frac(1, 1, qs[2]); - R1Frac(1, 0, qs[3]); - - DumpRegister($"dumptest-phase.txt", qs); - - ResetAll(qs); - } - } - - operation PiTest() : Unit { - let pi = PI(); - - AssertEqual(true, (pi > 3.14 and pi < 3.15)); - } - - internal function EmptyInternalFunction() : Unit { } - - internal operation EmptyInternalOperation() : Unit { } - - internal newtype InternalType = Int; - - internal operation MakeInternalType() : InternalType { - return InternalType(5); - } - - // This is a public operation that uses an internal type inside to test the access modifiers of the generated - // operation properties. - operation InternalCallablesTest() : Unit { - EmptyInternalFunction(); - EmptyInternalOperation(); - let x = InternalType(3); - let y = MakeInternalType(); - AssertEqual(15, x! * y!); - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs deleted file mode 100644 index 430bbd0ccdd..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/ExpTest.qs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Intrinsic; - - - // At some point, this was causing the simulator to crash. - - operation ExpCrashTest () : Unit { - - - using (qubits = Qubit[3]) { - let q1 = qubits[0]; - let q2 = qubits[1]; - let ctrls = qubits[2 .. 2]; - Exp([PauliZ], 0.5678, [q1]); - Controlled Exp(ctrls, ([PauliZ], 0.5678, [q1])); - Exp([PauliZ, PauliZ], 0.6799, [q1, q2]); - Controlled Exp(ctrls, ([PauliZ, PauliZ], 0.6799, [q1, q2])); - - // Make sure all allocated qubits are measured before release - let (r1, r2, r3) = (M(q1), M(q2), M(ctrls[0])); - X(q1); - ResetAll(qubits); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs deleted file mode 100644 index 1f079c005eb..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Fail.qs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - operation AlwaysFail() : Unit is Adj + Ctl{ - Fail(); - } - - operation AlwaysFail1() : Unit is Adj + Ctl{ - AlwaysFail(); - } - operation AlwaysFail2() : Unit is Adj + Ctl { - Controlled AlwaysFail1(new Qubit[0],()); - } - operation AlwaysFail3() : Unit is Adj + Ctl { - Adjoint AlwaysFail2(); - } - - operation AlwaysFail4() : Unit is Adj + Ctl { - Adjoint AlwaysFail3(); - } - - operation GenericFail<'T,'U>( a : 'T, b : 'U ) : Unit is Adj + Ctl { - AlwaysFail(); - } - - operation GenericFail1() : Unit is Adj + Ctl { - GenericFail(5,6); - } - - operation PartialFail( a : Int, b : Int ) : Unit is Adj + Ctl { - AlwaysFail(); - } - - operation PartialFail1() : Unit is Adj + Ctl { - let op = PartialFail(0,_); - op(2); - } - - operation PartialAdjFail1() : Unit is Adj + Ctl { - let op = PartialFail(0,_); - Adjoint op(2); - } - - operation PartialCtlFail1() : Unit is Adj + Ctl { - let op = PartialFail(0,_); - Controlled op(new Qubit[0], 2); - } - - operation GenericAdjFail1() : Unit is Adj + Ctl { - Adjoint GenericFail(5,6); - } - - operation GenericCtlFail1() : Unit is Adj + Ctl { - Controlled GenericFail( new Qubit[0], (5,6)); - } - - function Fail() : Unit { - fail "Always fail"; - } - - operation RecursionFail( a : Int) : Unit is Adj { - if ( a >= 1 ) - { - RecursionFail(a-1); - } - else - { - Fail(); - } - } - - operation RecursionFail1() : Unit { - RecursionFail(2); - } - - operation DivideBy0() : Int { - let z = 0; - return 3 / z; - } - - operation AllGood() : Unit { - Microsoft.Quantum.Intrinsic.Message("All good!"); - } - - operation AllGood1() : Unit { - AllGood(); - } - - operation AllocateQubit2 () : Unit { - using (q = Qubit()) { - Microsoft.Quantum.Intrinsic.H(q); - Microsoft.Quantum.Diagnostics.AssertMeasurement( - [PauliZ], [q], One, "" - ); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs deleted file mode 100644 index 36e698a6924..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Functions.qs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - function Add(a: Int, b: Int) : Int - { - return a + b; - } - - function ApplyTwice<'T>(f: ('T -> Int), a: 'T) : Int - { - return f(a) + f(a); - } - - operation PartialFunctionsTest () : Unit - { - let plusFive = Add(5, _); - let partial_3 = ApplyTwice(_, 3); - let partial_9 = ApplyTwice(_, 9); - - AssertEqual(12, ApplyTwice(plusFive, 1)); - AssertEqual(16, partial_3(plusFive)); - AssertEqual(28, partial_9(plusFive)); - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs deleted file mode 100644 index 636f92002f3..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Generics.qs +++ /dev/null @@ -1,884 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// This files contains Generic version of gates in ClosedTypes.qb -// to verify that they can be used interchangeably. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; - - - newtype UDT_G1 = (Int, Qubit); - - newtype UDT_G2 = (Qubit, Qubit); - - newtype UDT_G3 = (Bool[], Qubit); - - newtype UDT_G4 = (Bool[], Int, Qubit); - - newtype UDT_G5 = (UDT_G1, UDT_G2); - - newtype UDT_G6 = (UDT_G1[], UDT_G2); - - newtype UDT_G7 = UDT_G1; - - newtype LittleEndian = Qubit[]; - - - operation AsString (v : Result) : String { - - if (v == One) { - return $"uno"; - } - else { - return $"cero"; - } - } - - - operation Trace<'T> (tag : 'T) : Unit - is Adj + Ctl { - body intrinsic; - } - - - operation Gen0<'I> (tag : 'I) : Unit - is Adj + Ctl { - Trace(tag); - } - - - operation Gen1<'I, 'O> (i : 'I, o : 'O) : 'O { - - Trace(i, o); - return o; - } - - - operation Gen2<'T1, 'T2> (tag : ('T1, Int, 'T2)) : Unit - is Adj { - Trace(tag); - } - - - operation Gen3<'T1, 'T2, 'T3> (tag : ('T1, ('T2, 'T3), Result)) : Unit - is Ctl { - Trace(tag); - } - - - operation Gen4<'T1, 'T2> (r1 : Result, (t1 : 'T1, t2 : 'T2), r2 : Result) : Unit - is Adj + Ctl { - Trace(r1, (t1, t2), r2); - } - - - operation Gen5<'I> (tags : 'I[]) : Unit - is Adj + Ctl { - - for (i in 0 .. Length(tags) - 1) { - Trace(tags[i]); - } - } - - - operation Gen6<'I> (data : ((Int, 'I)[], (Qubit, Qubit))) : Unit - is Adj + Ctl { - let (tags, qubits) = data; - - for (i in 0 .. Length(tags) - 1) { - Trace(tags[i]); - } - } - - - operation Gen7<'I> (data : (Int, 'I[])) : Unit - is Adj + Ctl { - let (index, tags) = data; - - for (i in 0 .. Length(tags) - 1) { - Trace(tags[i]); - } - } - - - operation TraceGate<'T> (gate : (Qubit => Unit is Adj + Ctl), tag : 'T, qubit : Qubit) : Unit - is Adj + Ctl { - Trace(tag); - gate(qubit); - } - - - operation Map<'T, 'U> (mapper : ('T => 'U), source : 'T[]) : 'U[] { - - mutable result = new 'U[Length(source)]; - - for (i in 0 .. Length(source) - 1) { - let m = mapper(source[i]); - set result = result w/ i <- m; - } - - return result; - } - - - operation Iter<'T> (callback : ('T => Unit), source : 'T[]) : Unit { - - for (i in 0 .. Length(source) - 1) { - callback(source[i]); - } - } - - - operation Repeat<'T> (callback : ('T => Unit is Adj + Ctl), bodyCount : Int, adjointCount : Int, controlledCount : Int, source : 'T) : Unit - is Adj { - let r = 1 .. bodyCount; - - for (i in r) { - callback(source); - } - - for (i in 1 .. adjointCount) { - Adjoint callback(source); - } - - for (i in 1 .. controlledCount) { - - using (ctrls = Qubit[1]) { - Controlled callback(ctrls, source); - } - } - } - - - operation TestIter () : Unit { - - using (ctrls = Qubit[2]) { - let a = [One, Zero, Zero]; - Iter(Trace, a); - Iter(Trace, Map(AsString, a)); - let b = [One, One, Zero, Zero, Zero]; - Iter(Adjoint Trace, b); - Iter(Adjoint Trace, Map(AsString, b)); - let c = [One, Zero, One, One]; - let ctrlOpResult = Controlled Trace(ctrls, _); - let ctrlOpString = Controlled Trace(ctrls, _); - Iter(ctrlOpResult, c); - Iter(ctrlOpString, Map(AsString, c)); - let d = [One, Zero, One, Zero, One, Zero, One, Zero, One]; - let ctrlAdjOpResult = Adjoint Controlled Trace(ctrls, _); - let ctrlAdjOpString = Adjoint Controlled Trace(ctrls, _); - Iter(ctrlAdjOpResult, d); - Iter(ctrlAdjOpString, Map(AsString, d)); - Iter(X, ctrls); - Iter(Adjoint X, ctrls); - } - } - - - operation TestRepeatPartial () : Unit { - - let p1 = Repeat(_, 5, 2, _, _); - let p2 = p1(_, 3, _); - - using (qubits = Qubit[1]) { - p2(TraceGate(X, $"normal", _), qubits[0]); - Adjoint p2(TraceGate(X, $"adjoint", _), qubits[0]); - } - } - - - operation RepeatWrapper (callback : (Qubit => Unit is Adj + Ctl)) : ((Int, Int, Int, Qubit) => Unit is Adj) { - - return Repeat(callback, _, _, _, _); - } - - - operation TestCreateRepeatWrapperPartial () : Unit { - - using (qubits = Qubit[1]) { - let traceNormal = TraceGate(X, $"normal", _); - let traceAdjoint = TraceGate(X, $"adjoint", _); - let normal = ((RepeatWrapper(traceNormal))(_, 2, _, _))(5, 3, _); - let adj = Adjoint ((RepeatWrapper(traceAdjoint))(5, 2, _, _))(3, _); - normal(qubits[0]); - adj(qubits[0]); - } - } - - - function ItemAt<'T> (i : Int, array : 'T[]) : 'T { - - return array[i]; - } - - - function CreateLookup<'T> (array : 'T[]) : (Int -> 'T) { - - return ItemAt(_, array); - } - - - operation DoAll<'T> (lookup : (Int -> ('T => Unit is Adj + Ctl)), range : Range, target : 'T) : Unit - is Adj + Ctl { - - using (ctrls = Qubit[2]) { - - for (i in range) { - let op = lookup(i); - op(target); - Adjoint op(target); - Controlled op(ctrls, target); - } - } - } - - - operation TestLookupUnitaries () : Unit { - - let traceLookup = CreateLookup([Trace, Trace, Trace]); - let xLookup = CreateLookup([X, X, X, X]); - let range = 0 .. 2; - - using (ctrls = Qubit[1]) { - DoAll(traceLookup, range, $"uno"); - Adjoint DoAll(traceLookup, range, $"uno"); - Controlled DoAll(ctrls, (traceLookup, range, $"uno")); - - using (qubits = Qubit[1]) { - DoAll(xLookup, range, qubits[0]); - Controlled DoAll(ctrls, (xLookup, range, qubits[0])); - } - } - } - - - operation NestedArgTuple (a : (String, String), (b : Int, (c : Int, d : (Result, Result)), e : String)) : Unit - is Adj + Ctl { - - Trace(a); - Trace(b); - Trace(c); - Trace(d); - Trace(e); - let (a1, a2) = a; - Trace(a1); - Trace(a2); - let (d1, d2) = d; - Trace(d1); - Trace(d2); - } - - - operation NestedArgTupleParameter (op : (((String, String), (Int, (Int, (Result, Result)), String)) => Unit is Adj + Ctl), a : (String, String), b : Int, c : Int, d : (Result, Result), e : String) : Unit { - - using (qubits = Qubit[2]) { - let (a1, a2) = a; - let (d1, d2) = d; - let p1A = op(a, (b, (_, d), _)); - let p2A = p1A(c, _); - p1A(c, e); - Adjoint p1A(c, e); - Controlled (Adjoint p1A)(qubits, (c, e)); - p2A(e); - Adjoint p2A(e); - Adjoint Controlled p2A(qubits, e); - let p1B = Controlled op(_, ((a1, _), (b, (c, (_, _)), _))); - let p2B = p1B(qubits, (a2, (_, _))); - let p3B = p2B(d, _); - p1B(qubits, (a2, (d, e))); - p1B(qubits[0 .. 1], (a2, ((d1, d2), e))); - Adjoint p2B(d, e); - Controlled p2B(qubits, ((d1, d2), e)); - Controlled (Adjoint p3B)(qubits, e); - } - } - - - operation TestNonGenericPartial () : Unit { - - let a = ($"a1", $"a2"); - let (a1, a2) = a; - let b = 2; - let c = 3; - let d = (Zero, One); - let (d1, d2) = d; - let e = $"e"; - let p1A = NestedArgTuple(a, (b, (_, d), _)); - let p2A = p1A(c, _); - p1A(c, e); - Adjoint p1A(c, e); - p2A(e); - Adjoint p2A(e); - let p1B = Adjoint NestedArgTuple((a1, _), (b, (c, (_, _)), _)); - let p2B = p1B(a2, (_, _)); - let p3B = p2B(d, _); - p1B(a2, (d, e)); - p1B(a2, ((d1, d2), e)); - p2B(d, e); - p2B((d1, d2), e); - p3B(e); - Adjoint p1B(a2, (d, e)); - Adjoint p2B(d, e); - Adjoint p3B(e); - NestedArgTupleParameter(NestedArgTuple, a, b, c, d, e); - } - - - operation NestedArgTupleGeneric<'A, 'B, 'C> (a : ('A, Int), (b : 'B, (c : Int, d : (Result, 'C)), e : Double)) : Unit { - - let (a1, a2) = a; - - // a1 is arg of type 'A - Trace(a1); - - // b is arg of type 'B - Trace(b); - let (d1, d2) = d; - - // d2 is arg of type 'C - Trace(d2); - } - - - operation TestGenericPartial () : Unit { - - let a = ($"argA", 0); - let (a1, a2) = a; - let b = $"argB"; - let c = 0; - let d = (Zero, $"argD"); - let (d1, d2) = d; - let e = 0.0; - let stringTuple = ($"T1", $"T2"); - - // NestedArgTupleGeneric (a, (b, (c, d), e)); - let p1A = NestedArgTupleGeneric(a, (b, (_, d), _)); - p1A(c, e); - let p1B = NestedArgTupleGeneric((stringTuple, a2), (b, (_, d), _)); - p1B(c, e); - let p1C = NestedArgTupleGeneric(a, (stringTuple, (_, d), _)); - p1C(c, e); - let p1D = NestedArgTupleGeneric(a, (b, (_, (d1, stringTuple)), _)); - p1D(c, e); - let p2A = NestedArgTupleGeneric(_, (_, (c, d), e)); - p2A(a, b); - let p2B = NestedArgTupleGeneric<(String, String), String, String>(_, (_, (c, d), e)); - p2B((stringTuple, a2), b); - let p2C = NestedArgTupleGeneric(_, (_, (c, d), e)); - p2C(a, stringTuple); - let p2D = NestedArgTupleGeneric(_, (_, (c, (d1, stringTuple)), e)); - p2D(a, b); - let p3A = NestedArgTupleGeneric(a, (_, (_, _), e)); - p3A(b, (c, d)); - let p3B = NestedArgTupleGeneric<(String, String), String, String>((stringTuple, a2), (_, (_, _), e)); - p3B(b, (c, d)); - let p3C = NestedArgTupleGeneric(a, (_, (_, _), e)); - p3C(stringTuple, (c, d)); - let p3D = NestedArgTupleGeneric(a, (_, (_, _), e)); - p3D(b, (c, (d1, stringTuple))); - - // Inner partials: - let p4A = NestedArgTupleGeneric(a, (_, (_, _), e)); - let p4Aa = p4A(b, (_, _)); - p4Aa(c, d); - let p4B = NestedArgTupleGeneric(a, (_, (_, _), e)); - let p4Ba = p4B(b, (c, _)); - p4Ba(One, $"otherD"); - return (); - } - - - operation BindTest () : Unit { - let bound = Bind([X, X, X]); - - // FIXME: switched the second argument from ApplyToEach(..) to ApplyToEachA(..) - AssertOperationsEqualReferenced(ApplyToEach(bound, _), ApplyToEachA(X, _), 3); - } - - - operation BindImpl<'T> (operations : ('T => Unit is Adj + Ctl )[], target : 'T) : Unit { - - for (idxOperation in 0 .. Length(operations) - 1) { - let op = operations[idxOperation]; - op(target); - } - } - - - function Bind<'T> (operations : ('T => Unit is Adj + Ctl)[]) : ('T => Unit) { - - return BindImpl(operations, _); - } - - - operation ApplyToEachA<'T> (singleQubitOperation : ('T => Unit is Adj), register : 'T[]) : Unit - is Adj { - - for (idxQubit in 0 .. Length(register) - 1) { - singleQubitOperation(register[idxQubit]); - } - } - - - operation ApplyToEach<'T> (singleQubitOperation : ('T => Unit), register : 'T[]) : Unit { - - for (idxQubit in 0 .. Length(register) - 1) { - singleQubitOperation(register[idxQubit]); - } - } - - - operation ApplyToEachCA<'T> (singleQubitOperation : ('T => Unit is Adj + Ctl), register : 'T[]) : Unit - is Adj + Ctl { - - for (idxQubit in 0 .. Length(register) - 1) { - singleQubitOperation(register[idxQubit]); - } - } - - - operation AssertOperationsEqualReferenced (actual : (Qubit[] => Unit), expected : (Qubit[] => Unit is Adj), nQubits : Int) : Unit { - - using (qs = Qubit[2]) { - Adjoint expected(qs); - actual(qs); - } - - Trace($"success!"); - } - - - operation CCNOT2OuterCircuit (qs : Qubit[]) : Unit - is Adj + Ctl { } - - - operation UpToPhaseCCNOT2 (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit - is Adj { - WithA(CCNOT2OuterCircuit, [target, control1, control2]); - } - - - operation WithA<'T> (outerOperation : ('T => Unit is Adj), target : 'T) : Unit - is Adj {} - - - operation CCNOTCiruitsTest () : Unit { - - using (qubits = Qubit[3]) { - Adjoint UpToPhaseCCNOT2(qubits[0], qubits[1], qubits[2]); - } - - Trace($"success!"); - } - - - operation CountQs<'T> (qs : 'T[]) : Unit - is Adj { - - body (...) { - Trace(Length(qs)); - } - - controlled (cs, ...) { - Trace(Length(qs) + Length(cs)); - } - } - - - operation CountQsNonGeneric (qs : Qubit[]) : Unit - is Adj { - - body (...) { - Trace(Length(qs)); - } - - controlled (cs, ...) { - Trace(Length(qs + cs)); - } - } - - - operation MultiControlledTest () : Unit { - - using (qs = Qubit[1]) { - using (cs1 = Qubit[1]) { - using (cs2 = Qubit[1]) { - using (cs3 = Qubit[1]) { - CountQs(qs); - Controlled CountQs(cs1, qs); - Controlled (Controlled CountQs)(cs1, (cs2, qs)); - Controlled (Controlled (Controlled CountQs))(cs1, (cs2, (cs3, qs))); - } - } - } - } - } - - - operation MixedComponentsTest () : Unit { - - using (qs = Qubit[1]) { - using (cs1 = Qubit[1]) { - using (cs2 = Qubit[1]) { - Adjoint (Adjoint CountQs)(qs); - Controlled (Adjoint CountQs)(cs1, qs); - Adjoint Controlled (Adjoint CountQs)(cs1, qs); - Controlled (Controlled (Adjoint CountQs))(cs1, (cs2, qs)); - } - } - } - } - - - function AddControlled<'A> (op : ('A => Unit is Adj + Ctl)) : ((Qubit[], 'A) => Unit is Adj + Ctl) { - - return Controlled op; - } - - - function ReturnId<'A> (arg : 'A) : 'A { - - return arg; - } - - - operation AssignmentsTest () : Unit { - - using (qs = Qubit[1]) { - using (cs1 = Qubit[1]) { - using (cs2 = Qubit[1]) { - let AAOp = Adjoint (Adjoint CountQs); - AAOp(qs); - (ReturnId(Controlled (Adjoint CountQs)))(cs1, qs); - let CCAOp = AddControlled(Controlled (Adjoint CountQs)); - CCAOp(cs1, (cs2, qs)); - Adjoint CCAOp(cs1, (cs2, qs)); - let CCANGOp = AddControlled(Controlled (Adjoint CountQsNonGeneric)); - CCANGOp(cs1, (cs2, qs)); - Adjoint CCANGOp(cs1, (cs2, qs)); - } - } - } - } - - - operation AssignmentsWithPartialsTest () : Unit { - - using (qs = Qubit[1]) { - using (cs1 = Qubit[1]) { - using (cs2 = Qubit[1]) { - let Op1 = (ReturnId(Controlled (Adjoint CountQs)))(cs1, _); - Op1(qs); - let CCAOpFull = AddControlled(Controlled (Adjoint CountQs)); - let CCAOp = CCAOpFull(_, (cs2, _)); - Adjoint CCAOp(cs1, qs); - Adjoint (CCAOp(cs1, _))(qs); - let CCANGOpFull = AddControlled(Controlled (Adjoint CountQsNonGeneric)); - let CCANGOp = CCANGOpFull(cs1, _); - Adjoint CCANGOp(cs2, qs); - } - } - } - } - - - function Indirection<'A> (arg : 'A) : 'A[] { - - mutable arr = new 'A[5]; - - for (i in 0 .. Length(arr) - 1) { - set arr = arr w/ i <- arg; - } - - return arr; - } - - - function MapDefaults<'T> (fct : ('T -> Unit), dummy : 'T) : Unit { - - let arr = new 'T[5]; - let fcts = Indirection(fct); - - for (i in 0 .. Length(arr) - 1) { - fcts[i](arr[i]); - } - } - - - function Mapper (i : Int) : Unit { - - return (); - } - - - operation TestMapDefaults () : Unit { - - MapDefaults(Mapper, 1); - Trace($"success!"); - } - - - function ChooseFirst<'A, 'B, 'C> ((a : 'A, b : 'B), c : 'C) : 'A { - - return a; - } - - - operation TypeParameters<'A, 'B> (a : ('A, 'B), b : 'B, c : 'B, d : (('A, 'A), 'B)) : Unit - is Adj { - - body (...) { - Trace(ChooseFirst(d)); - } - - controlled (cs, ...) { - Trace(b, c); - } - } - - - operation TestMultipleTypeParamters () : Unit { - - let a = (2, Zero); - let b = One; - let d = ((1, 3), One); - TypeParameters(a, b, b, d); - } - - - operation TestDestructingArgTuple () : Unit { - - let a = (2, Zero); - let b = One; - let d = ((1, 3), One); - let arg = (a, b, b, d); - TypeParameters(arg); - let stringArg = (new Qubit[0], ((2, $""), $"Hello", $"World", ((2, 2), $""))); - Controlled TypeParameters(stringArg); - Controlled (Adjoint TypeParameters)(stringArg); - } - - - operation ComposeImpl<'A, 'B> (second : ('A => Unit), first : ('B => 'A), arg : 'B) : Unit { - - second(first(arg)); - } - - - operation Compose<'A, 'B> (second : ('A => Unit), first : ('B => 'A)) : ('B => Unit) { - - return ComposeImpl(second, first, _); - } - - - operation TestCompose () : Unit { - - let fct = Compose(Trace, AsString); - fct(Zero); - } - - - operation TraceNonGeneric (tag : String) : Unit - is Adj + Ctl { - - let arg = $"redirecting:" + tag; - Trace(arg); - } - - - operation TestComposeWithNonGeneric () : Unit { - - let fct = Compose(TraceNonGeneric, AsString); - fct(Zero); - } - - - operation WithCA<'T> (outerOperation : ('T => Unit is Adj), innerOperation : ('T => Unit is Adj + Ctl), target : 'T) : Unit - is Adj { - - body (...) { - outerOperation(target); - innerOperation(target); - Adjoint outerOperation(target); - } - - controlled (controlRegister, ...) { - outerOperation(target); - Controlled innerOperation(controlRegister, target); - Adjoint outerOperation(target); - } - } - - - operation ApplyPauliFromBitString (pauli : Pauli, bitApply : Bool, bits : Bool[], qubits : Qubit[]) : Unit - is Adj + Ctl { - let nBits = Length(bits); - - for (idxBit in 0 .. nBits - 1) { - - if (bits[idxBit] == bitApply) { - X(qubits[idxBit]); - Trace(idxBit); - } - } - } - - - operation ControlledOnBitStringImpl<'T> (bits : Bool[], oracle : ('T => Unit is Adj + Ctl), controlRegister : Qubit[], targetRegister : 'T) : Unit - is Adj + Ctl { - WithCA(ApplyPauliFromBitString(PauliX, false, bits, _), Controlled oracle(_, targetRegister), controlRegister); - } - - - function ControlledOnBitString<'T> (bits : Bool[], oracle : ('T => Unit is Adj + Ctl)) : ((Qubit[], 'T) => Unit is Adj + Ctl) { - - return ControlledOnBitStringImpl(bits, oracle, _, _); - } - - - // This tests that we can use UDT (that maps to a Q[]) as a controlled parameter. - - operation TestControlledBitString () : Unit { - - using (data = Qubit[3]) { - let bits = [false, true, false]; - - // this is key... allows to tes UDTs as input for partials that expects qubits. - // (not supported in 0.3+ without unwrapping...) - let qubits = LittleEndian(data); - (ControlledOnBitString(bits, Trace))(qubits!, $"ok"); - } - } - - - // This tests that we can use an UDT (that maps to a Q[]) as input where a Q[] is expected. - - operation TestApplyToEachUdt () : Unit { - - using (data = Qubit[3]) { - - using (control = Qubit[1]) { - let q0 = Gen1(0, data[0]); - let q1 = Gen1((UDT_G1(1, data[1]))!); - let q2 = Gen1((UDT_G7(UDT_G1(2, data[2])))!!); - let qubits = LittleEndian([q0, q1, q2]); - Controlled (ApplyToEachCA(Trace, _))(control, qubits!); - } - } - } - - - function UnboxG1Array (data : UDT_G1[]) : (Int, Qubit)[] { - - let count = Length(data); - mutable result = new (Int, Qubit)[count]; - - for (i in 0 .. count - 1) { - let (n, q) = data[i]!; - set result = result w/ i <- (n, q); - } - - return result; - } - - - function UnboxG6 (data : UDT_G6) : ((Int, Qubit)[], (Qubit, Qubit)) { - - let (u1, u2) = data!; - let (q1, q2) = u2!; - return (UnboxG1Array(u1), (q1, q2)); - } - - - operation TestUDTsPolyMorphism () : Unit { - - - using (data = Qubit[3]) { - - using (control = Qubit[1]) { - let q0 = Gen1(0, data[0]); - let q1 = Gen1((UDT_G1(1, data[1]))!); - let q2 = Gen1((UDT_G7(UDT_G1(2, data[2])))!!); - let qubits = LittleEndian([q0, q1, q2]); - let u1 = UDT_G1(1, qubits![1]); - let u2 = UDT_G2(q2, qubits![2]); - let u1s = [u1]; - let u2s = [u2, u2]; - let u6 = UDT_G6(u1s, u2); - let u7 = UDT_G7(u1); - let u7s = [u7]; - - //Gen5<'I>(tags: 'I[]) - Gen5(data); - Gen5(qubits!); - Gen5(u1s); - Gen5(u2s); - Gen5(u7s); - - //Gen6<'I>(tags: ((Int, 'I)[], (Qubit, Qubit)) - // TODO: Automatic unboxing for Arrays... Gen6(u1s, (q0, q1)); - // TODO: Automatic unboxing for Arrays... Gen6(u1s, u2); - // TODO: Automatic unboxing for Arrays... Gen6(u6); - Gen6([(1, [q1]), (2, [q1, q2])], (q0, q1)); - Gen6([(1, u1s), (2, u1s)], u2!); - Gen6(UnboxG6(u6)); - - //Gen7<'I>(tags: (Int, 'I[])) - Gen7(1, u1s); - Gen7(2, u7s); - } - } - } - - - function AsStr (r : Result) : String { - - if (r == One) { - return $"One"; - } - - return $"Zero"; - } - - - function AsInt (r : Result) : Int { - - - if (r == One) { - return 1; - } - - return 0; - } - - - function GenWrapper<'U, 'V> (op : ('U -> 'V), arg : 'U) : 'V { - - return op(arg); - } - - - operation WrapperWithDifferentReturnValuesTest () : Unit { - - let str0 = GenWrapper(AsStr, Zero); - let str1 = GenWrapper(AsStr, One); - let int0 = GenWrapper(AsInt, Zero); - let int1 = GenWrapper(AsInt, One); - let intOp = GenWrapper(AsInt, _); - let strOp = GenWrapper(AsStr, _); - AssertEqual($"One", str1); - AssertEqual($"Zero", str0); - AssertEqual($"One", strOp(One)); - AssertEqual($"Zero", strOp(Zero)); - AssertEqual(0, int0); - AssertEqual(1, int1); - AssertEqual(0, intOp(Zero)); - AssertEqual(1, intOp(One)); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs deleted file mode 100644 index 0016786c024..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/GetAvailableTest.qs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - open Microsoft.Quantum.Environment; - - operation BorrowSubTest () : (Int, Int) - { - mutable innerBorrow = 0; - borrowing (qb = Qubit()) - { - set innerBorrow = GetQubitsAvailableToBorrow(); - } - return (GetQubitsAvailableToBorrow(), innerBorrow); - } - - operation GetAvailableTest (allocSize : Int) : (Int, Int, Int, Int, Int, Int) - { - let initialUse = GetQubitsAvailableToUse(); - let initialBorrow = GetQubitsAvailableToBorrow(); - - mutable result = (0, 0, 0, 0, 0, 0); - - using (qs = Qubit[allocSize]) - { - let afterUse = GetQubitsAvailableToUse(); - let afterBorrow = GetQubitsAvailableToBorrow(); - let (subBorrow, innerBorrow) = BorrowSubTest(); - set result = (initialUse, initialBorrow, afterUse, afterBorrow, subBorrow, innerBorrow); - } - - return result; - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs deleted file mode 100644 index 9b57996913a..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Issue132.qs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - operation SliceGenerationTest() : Unit { - using (qs = Qubit[4]) { - PrepareCatState(qs); - if (M(qs[0]) == One) { - for (target in qs) { - X(target); - } - } - } - } - - operation PrepareCatState(register : Qubit[]) : Unit is Adj + Ctl { - H(register[0]); - for (target in register[1...]) { - CNOT(register[0], target); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs deleted file mode 100644 index 285736aaecd..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Issue76.qs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Issue76 -{ - open Microsoft.Quantum.Intrinsic; - - function BuggyReturn<'T> (param: 'T): Bool { - return true; - } - - function AssertBuggyReturn<'T> (param: 'T): Unit { - if (not BuggyReturn<'T>(param)) { - Message("BuggyReturn returned false"); - } - } -} - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Issue76; - open Microsoft.Quantum.Intrinsic; - - function BuggyReturnTest () : Unit - { - AssertBuggyReturn(0); - if (not BuggyReturn(0)) { - Message("BuggyReturn returned false"); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs deleted file mode 100644 index 1cdadf8552b..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Length.qs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - operation MapF<'T, 'U> (mapper : ('T -> 'U), source : 'T[]) : 'U[] { - - mutable result = new 'U[Length(source)]; - - for (i in 0 .. Length(source) - 1) { - let m = mapper(source[i]); - set result = result w/ i <- m; - } - - return result; - } - - - operation LengthTest () : Unit - { - let a1 = [One, Zero]; - let a2 = [Zero, Zero, Zero]; - - AssertEqual(2, Length(a1)); - AssertEqual(3, Length(a2)); - - let values = MapF(Length, [a1, a2]); - AssertEqual(2, values[0]); - AssertEqual(3, values[1]); - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs deleted file mode 100644 index 7db85674054..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/NamedItems.qs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - newtype NestedPair = (Double, ((Fst : Bool, String), Snd : Int)); - - operation NamedItemAccessTest () : Unit { - - let udt = NestedPair(1.0, ((true, "Hello"), 10)); - if (not udt::Fst) { - fail "wrong initialization"; - } - Message($"Snd is {udt::Snd}"); - } - - operation NamedItemUpdateTest () : Unit { - - let udt1 = NestedPair(1.0, ((true, "Hello"), 10)); - mutable udt2 = udt1 w/ Fst <- false; - set udt2 w/= Snd <- 5; - if (not udt1::Fst or udt1::Snd != 10 or udt2::Fst or udt2::Snd != 5) { - fail "wrong values"; - } - } - -} - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs deleted file mode 100644 index 59f3c17d802..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Namespaces.qs +++ /dev/null @@ -1,22 +0,0 @@ -// // Copyright (c) Microsoft Corporation. All rights reserved. -// // Licensed under the MIT License. - -// Will cause compilation failure if callable type references in generated C# aren't -// prepended with "global::". -namespace Issue46 { - - operation ReturnZero () : Result { - - return Zero; - } - -} - -namespace Microsoft.Quantum.Tests.Namespaces.Issue46 { - - operation TestOp () : Result { - - return Issue46.ReturnZero(); - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs b/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs deleted file mode 100644 index 4be5584c1e8..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.cs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Simulators; -using Xunit; - -namespace NativeOperations -{ - // An intrinsic operation can specify its built-in Native implementation: - public partial class IntrinsicBody - { - public static string RESULT = "from native body"; - - // Make sure it works with other inner Types: - public class Other { } - - public class Native : IntrinsicBody - { - public Native(IOperationFactory m) : base(m) { } - - public override Func Body => (arg) => - { - return RESULT; - }; - } - } - - // An operation can have a body, and only Emulate for specific simulators: - public partial class DefaultBody - { - public class Native : DefaultBody - { - public Native(IOperationFactory m) : base(m) { } - - public override Func Body => (arg) => - { - if (this.Factory is QuantumSimulator) - { - return "Simulator"; - } - - return base.Body(arg); - }; - } - } - - // Same rules apply to Generic operations: - public partial class IntrinsicBodyGeneric<__T__> - { - // This one should not be used. It extends the Q# operation but has more generic type parameters - public class Other1 : IntrinsicBodyGeneric<__T__> - { - public Other1(IOperationFactory m) : base(m) { } - - public override Func<__T__, string> Body => throw new NotImplementedException(); - } - - // This one should not be used, it has the same number of Type parameters, - // but does not extend the actual Q# operation: - public class Other2 { } - - // This one should be used: - public class Emulation : IntrinsicBodyGeneric<__T__> - { - public Emulation(IOperationFactory m) : base(m) { } - - public override Func<__T__, string> Body => (arg) => - { - if (arg is string s) - { - return IntrinsicBody.RESULT; - } - else - { - return arg.ToString(); - } - }; - } - } - - // Make sure we can also call the body of a non-intrinsic generic - public partial class DefaultBodyGeneric<__T__> - { - // This one should be used: - public class Emulation : DefaultBodyGeneric<__T__> - { - public Emulation(IOperationFactory m) : base(m) { } - - public override Func<__T__, __T__> Body => (arg) => - { - if (arg is string s) - { - return (__T__)(object)IntrinsicBody.RESULT; - } - else - { - return base.Body(arg); - } - }; - } - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs deleted file mode 100644 index b6048b2af62..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/NativeOperations.qs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace NativeOperations -{ - operation IntrinsicBody () : String - { - body intrinsic; - } - - operation DefaultBody () : String - { - return "hello"; - } - - operation IntrinsicBodyGeneric<'T>(arg: 'T) : String - { - body intrinsic; - } - - operation DefaultBodyGeneric<'T>(arg: 'T) : 'T - { - return arg; - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs deleted file mode 100644 index c34ca0bf6be..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/PrimitiveEquivalences.qs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Simulation.TestSuite; - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Diagnostics; - - - //------------------------------------------------------------------------ - - operation CNOTPrimitive (register : Qubit[]) : Unit { - - body (...) { - CNOT(register[0], register[1]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation CNOTEquivalent (register : Qubit[]) : Unit { - - body (...) { - Controlled X([register[0]], register[1]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation CNOTEquivalenceTest () : Unit { - AssertOperationsEqualInPlace(2, CNOTPrimitive, CNOTEquivalent); - } - - - //------------------------------------------------------------------------ - - operation CCNOTPrimitive (register : Qubit[]) : Unit { - - body (...) { - CCNOT(register[0], register[1], register[2]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation CCNOTEquivalent (register : Qubit[]) : Unit { - - body (...) { - Controlled X(register[0 .. 1], register[2]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation CCNOTEquivalenceTest () : Unit { - AssertOperationsEqualInPlace(3, CCNOTPrimitive, CCNOTEquivalent); - } - - - //------------------------------------------------------------------------ - - operation R1Primitive (theta : Double, register : Qubit[]) : Unit { - - body (...) { - R1(theta, register[0]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation R1Equivalent (theta : Double, register : Qubit[]) : Unit { - - body (...) { - R(PauliZ, theta, register[0]); - R(PauliI, -theta, register[0]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation R1EquivalentTest () : Unit { - - let nTheta = 101; - - for (idxTheta in 0 .. nTheta) { - let theta = ((2.0 * PI()) * IntAsDouble(idxTheta)) / IntAsDouble(nTheta); - AssertOperationsEqualInPlace(1, R1Primitive(theta, _), R1Equivalent(theta, _)); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs deleted file mode 100644 index f32486ecaa9..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Recursion.qs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - function Factorial (x : Int) : Int { - - - if (x == 1) { - return 1; - } - else { - return x * Factorial(x - 1); - } - } - - - operation OpFactorial (x : Int) : Int { - - - if (x == 1) { - return 1; - } - else { - return x * OpFactorial(x - 1); - } - } - - - function GenRecursion<'T> (x : 'T, cnt : Int) : 'T { - - - if (cnt == 0) { - return x; - } - else { - return GenRecursion(x, cnt - 1); - } - } - - - function GenRecursionPartial<'T> (x : 'T, cnt : Int) : 'T { - - - if (cnt == 0) { - return x; - } - else { - let fct = GenRecursionPartial<'T>(_, cnt - 1); - return fct(x); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs deleted file mode 100644 index 05d5d7463c1..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/RepeatUntilSuccess.qs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - operation OneBitPrecisionEigenvalue (U : (Qubit => Unit is Adj + Ctl), P : (Qubit => Unit is Adj)) - : Bool { - - using ((control, eigenstate) = (Qubit(), Qubit())) { - P(eigenstate); - - mutable (measuredZero, measuredOne) = (false, false); - mutable iter = 0; - repeat { - set iter += 1; - - H(control); - Controlled U([control], eigenstate); - H(control); - - let meas = M(control); - if (meas == One) { X(control); } - set (measuredZero, measuredOne) = (measuredZero or meas == Zero, measuredOne or meas == One); - } - until (iter == 20 or measuredZero and measuredOne); - - Reset(eigenstate); - return not measuredZero or not measuredOne; - } - - } - - // testing - - operation RepeatUntilSuccessTest () : Unit { - let evZ = OneBitPrecisionEigenvalue(Z,X); - let evS = OneBitPrecisionEigenvalue(S,X); - let evX = OneBitPrecisionEigenvalue(X,H); - if (not evZ or not evX or evS) { - fail "wrong result"; - } - } - -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs deleted file mode 100644 index dd3e52fc884..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/ResourcesEstimator.qs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - open Microsoft.Quantum.Intrinsic; - - operation VerySimpleEstimate () : Unit - { - using(q = Qubit[3]) { - X(q[0]); - H(q[1]); - - Controlled X([q[1]], q[0]); - - ResetAll([q[1], q[0]]); - } - } - - // When multiple operations are traced by resource estimator, - // it should report cumulative statistics in the end. - operation Operation_1_of_2() : Unit - { - using ((a, b) = (Qubit(), Qubit())) { - H(a); - CNOT(a, b); - T(b); - } - } - operation Operation_2_of_2() : Result - { - using ((a, b, c) = (Qubit(), Qubit(), Qubit())) { - X(a); - CNOT(a, b); - Rx(0.42, b); - CNOT(b, c); - return M(c); - } - } - - // Tests for Depth and Width lower bounds - operation DepthDifferentQubits () : Unit - { - using(q = Qubit[3]) { - T(q[0]); - T(q[1]); - T(q[2]); - T(q[0]); - } - } - operation DepthVersusWidth () : Unit - { - using(q = Qubit()) { - T(q); - } - using(q = Qubit()) { - T(q); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs deleted file mode 100644 index 5836a3426f5..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/RuntimeMetadataTest.qs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Intrinsic; - - newtype FooUDT = (String, (Qubit, Double)); - - operation FooUDTOp (foo : FooUDT) : Unit is Ctl + Adj { } - - operation Empty () : Unit is Ctl + Adj { } - - operation WrapperOp (op: (Qubit => Unit), q : Qubit) : Unit { - op(q); - Reset(q); - } - - operation HOp (q : Qubit) : Unit { - H(q); - Reset(q); - } - - operation NestedOp () : Unit { - using (q = Qubit()) { - HOp(q); - } - } - - operation TwoQubitOp (q1 : Qubit, q2 : Qubit) : Unit { - // ... - } - - operation BoolArrayOp (bits : Bool[]) : Unit { - // ... - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs deleted file mode 100644 index 6aab6f402ea..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/SetQubit.qs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Intrinsic; - - - operation SetQubit (desired : Result, q1 : Qubit) : Unit { - - let current = M(q1); - - if (desired != current) { - X(q1); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs deleted file mode 100644 index dbbad4a7894..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/StartOperation.qs +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Tests.StartOperation { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics; - - - newtype Qubits = Qubit[]; - - newtype UDT1 = ((Int, Qubit, (Qubit, Qubit), Result) => Unit : Adjoint, Controlled); - - newtype UDT2 = (Qubit => Unit : Adjoint, Controlled); - - newtype UDT3 = ((Int, Qubit) => Int); - - - operation Basic (a : Int, b : Qubit, (c : Qubit, d : Qubit), e : Result) : Unit { - - body (...) { - X(b); - X(c); - X(d); - X(b); - Trace(a); - Trace(b); - Trace(c); - Trace(d); - Trace(e); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation B3 (i : Int, q : Qubit) : Int { - - Trace(q); - return i; - } - - - operation AllVariants<'T> (gate : ('T => Unit : Adjoint, Controlled), i : 'T, ctrls : Qubits) : Unit { - - body (...) { - gate(i); - Adjoint gate(i); - Controlled gate(ctrls!, i); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation StartOperationTest () : Unit { - - using (q = Qubit[5]) - { - let data = (0, q[1], (q[2], q[3]), One); - let ctrls = Qubits(q[0..0]); // B A C CA - - Basic(data); // 1 - (Adjoint Basic)(data); // 1 - (Controlled Basic)(ctrls!, data); // 1 - (Adjoint (Controlled Basic))(ctrls!, data); // 1 - - AllVariants(Basic, data, ctrls); // 1 1 1 - (Adjoint AllVariants)(Basic, data, ctrls); // 1 1 1 - (Controlled AllVariants)([q[4]], (Basic, data, ctrls)); // 2 1 - (Adjoint (Controlled AllVariants))([q[4]], (Basic, data, ctrls)); // 1 2 - - let partial = Basic(1, q[1], _, Zero); - AllVariants(partial, (q[2], q[3]), ctrls); // 1 1 1 - (Adjoint AllVariants)(partial, (q[2], q[3]), ctrls); // 1 1 1 - (Controlled AllVariants)([q[4]], (partial, (q[2], q[3]), ctrls)); // 2 1 - - let partial2 = partial(q[2], _); - partial2(q[3]); // 1 - partial2(q[3]); // 1 - partial2(q[3]); // 1 - AllVariants(partial2, q[3], ctrls); // 1 1 1 - (Adjoint partial2)(q[3]); // 1 - } - } - - - // This is needed to fix the bug that the parser is reporting incorrectly the type of UDTs: - - function UDT1asUnitary (u : UDT1) : ((Int, Qubit, (Qubit, Qubit), Result) => Unit : Adjoint, Controlled) { - - return u!; - } - - - operation StartOperationUDTTest () : Unit { - - using (q = Qubit[5]) - { - let data = (0, q[1], (q[2], q[3]), One); - let ctrls = Qubits(q[0..0]); - let u = UDT1(Basic); - let uni = UDT1asUnitary(UDT1(Basic)); - // B A C CA - u!(data); // 1 - (Adjoint u!)(data); // 1 - (Controlled u!)(ctrls!, data); // 1 - (Adjoint (Controlled u!))(ctrls!, data); // 1 - - uni(data); // 1 - AllVariants(uni, data, ctrls); // 1 1 1 - (Adjoint AllVariants)(uni, data, ctrls); // 1 1 1 - (Controlled AllVariants)([q[4]], (uni, data, ctrls)); // 2 1 - (Adjoint (Controlled AllVariants))([q[4]], (uni, data, ctrls)); // 1 2 - - let partial = uni(1, q[1], _, Zero); - AllVariants(partial, (q[2], q[3]), ctrls); // 1 1 1 - (Adjoint AllVariants)(partial, (q[2], q[3]), ctrls); // 1 1 1 - (Controlled AllVariants)([q[4]], (partial, (q[2], q[3]), ctrls)); // 2 1 - - let partial2 = partial(q[2], _); // - partial2(q[3]); // 1 - partial2(q[3]); // 1 - partial2(q[3]); // 1 - (Adjoint partial2)(q[3]); // 1 - - let u2 = UDT2(partial2); - u2!(q[2]); // 1 - u2!(q[2]); // 1 - AllVariants(u2!, q[1], ctrls); // 1 1 1 - - let u3 = UDT3(B3); - let p3 = u3!(_, q[0]); - mutable results = new Int[4]; - for (i in 0..3) - { - set results = results - w/ i <- u3!(i, q[i]) - w/ i <- p3(i); - } - - ResetAll(q); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs deleted file mode 100644 index 8ebb32babd5..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/SwapTest.qs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - - operation SwapTest () : Unit { - - - using (qubits = Qubit[2]) { - let q1 = qubits[0]; - let q2 = qubits[1]; - X(q1); - SWAP(q1, q2); - - // Make sure all allocated qubits are measured before release - let (r1, r2) = (M(q1), M(q2)); - AssertQubit(Zero, q1); - AssertQubit(One, q2); - X(q2); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs deleted file mode 100644 index 64d4808065e..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/TeleportTest.qs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Intrinsic; - - - operation TeleportTest () : Unit { - - - using (qubits = Qubit[3]) { - let q1 = qubits[0]; - let q2 = qubits[1]; - let q3 = qubits[2]; - - // create a Bell pair - H(q1); - CNOT(q1, q2); - - // create quantum state - H(q3); - Rz(1.1, q3); - - // teleport - CNOT(q3, q2); - H(q3); - Controlled X([q2], q1); - Controlled Z([q3], q1); - - // check teleportation success - Rz(-1.1, q1); - H(q1); - - // Make sure all allocated qubits are retrurned to zero before release - ResetAll(qubits); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs deleted file mode 100644 index e5082d2c7b8..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/Tuples.qs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Tests.OperationNames { - - operation Name () : Unit { - - } - - - operation Variant () : Unit { - - } - - - operation DataIn () : Unit { - - } - - - operation DataOut () : Unit { - - } - -} - - -namespace Microsoft.Quantum.Tests.Tuples { - - newtype Q = Qubit; - - newtype I = Int; - - newtype TupleA = (Int, Pauli, Qubit, (Qubit, Int, Qubit)); - - newtype TupleB = ((Int, Int), (Qubit, (Int, (Qubit, Qubit)), Double)); - - newtype TupleC = (Qubit, TupleB); - - newtype TupleD = Qubit[]; - - newtype TupleE = (Int, Qubit[]); - - newtype TupleF = ((TupleA, TupleD) => Unit : Adjoint, Controlled); - - newtype TupleG = (Qubit, TupleF, TupleC, TupleD); - - newtype TupleH = (TupleD, TupleG); - - newtype TupleI = ((TupleD, TupleF) -> TupleD); - - newtype TupleJ = (Int, Qubit)[]; - - newtype Name = String; - - newtype Variant = String; - - newtype DataIn = (Int, Qubit); - - newtype DataOut = (Int, (Qubit, Qubit)); - - - operation Op1 (a : TupleA, d : TupleD) : Unit { - - body (...) { - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - function F1 (d : TupleD, f : TupleF) : TupleD { - - return d; - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs deleted file mode 100644 index cd31d8f67d8..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/UnitTests.qs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - @Test("QuantumSimulator") - operation QsharpUnitTest() : Unit { - Message("Worked!"); - } - - @Test("QuantumSimulator") - @Test("Microsoft.Quantum.Simulation.Simulators.Tests.TrivialSimulator") - @Test("Microsoft.Quantum.Simulation.Simulators.Tests.ModifiedTrivialSimulator") - @Test("Microsoft.Quantum.Simulation.Simulators.Tests.UnitTests.TrivialSimulator") - operation ArbitraryUnitTestTarget() : Unit { - Message("Worked!"); - } - -} - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs deleted file mode 100644 index fa8cbc07cff..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/UserDefinedTypes.qs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - - newtype P1 = (Int, Int); - newtype P2 = ((Int, Int), Int); - newtype NamedTuple = (FirstItem: (Int, Double), SecondItem: Int); - newtype InnerNamedTuple = ((Fst : Result, Snd : (Int, Int)), Trd : String); - - function TakesUdtPartial<'T, 'U> (build : ('T -> 'U), remainingArgs : 'T) : 'U { - return build(remainingArgs); - } - - operation PassingUDTConstructorTest() : Unit - { - let ((a1, b1), c1) = (TakesUdtPartial(P2, ((1,2),3)))!; - AssertEqual(a1, 1); - AssertEqual(b1, 2); - AssertEqual(c1, 3); - - let partial = P2((_,2), _); - let full = TakesUdtPartial(partial, (3,1)); - let ((a2, b2), c2) = full!; - AssertEqual(a2, 3); - AssertEqual(b2, 2); - AssertEqual(c2, 1); - } - - operation PartialNestedUDTTest() : Unit - { - let partial = P2((_,2), _); - let full = partial(3, 1); - - let ((a, b), c) = full!; - AssertEqual(a, 3); - AssertEqual(b, 2); - AssertEqual(c, 1); - } - - operation PartialUDTTest() : Unit - { - let partial = P1(2, _); - let full = partial(3); - - let (a, b) = full!; - AssertEqual(5, a+b); - - let full2 = partial(10); - let (x, y) = full2!; - AssertEqual(12, x + y); - } - - operation IndirectPartialUDTTest() : Unit - { - let pa1 = P2((_,2), _); - let pa2 = pa1(1,_); - let ((a1, b1), c1) = (pa2(3))!; - AssertEqual(a1, 1); - AssertEqual(b1, 2); - AssertEqual(c1, 3); - - let full = TakesUdtPartial(pa1(3,_), 1); - let ((a2, b2), c2) = full!; - AssertEqual(a2, 3); - AssertEqual(b2, 2); - AssertEqual(c2, 1); - } - - function returnUdtConstructor () : (((Int, Int), Int) -> P2) { - return P2; - } - - function returnPartialUdtConstructor () : ((Int, Int) -> P2) { - return P2((3,_),_); - } - - function CallReturnedUdtConstructorTest () : Unit - { - let udt1 = (returnUdtConstructor())((1,2),3); - let ((a1,b1),c1) = udt1!; - AssertEqual(a1, 1); - AssertEqual(b1, 2); - AssertEqual(c1, 3); - - let udt2 = (returnPartialUdtConstructor())(2,1); - let ((a2,b2),c2) = udt2!; - AssertEqual(a2, 3); - AssertEqual(b2, 2); - AssertEqual(c2, 1); - } - - function ConstantArray<'T>(size : Int, item : 'T) : 'T[] { - mutable arr = new 'T[size]; - for (i in 0 .. size-1) { - set arr w/= i <- item; - } - return arr; - } - - function UdtConstructorArrayTest () : Unit { - let arr = ConstantArray(5, P2); - for (ctor in arr) { - let ((a,b),c) = (ctor((1, 2), 3))!; - AssertEqual(a, 1); - AssertEqual(b, 2); - AssertEqual(c, 3); - } - } - - function UdtNamedTupleFieldTest () : Unit { - let data = NamedTuple((1, 2.0), 3); - let (a, b) = data::FirstItem; - let c = data::SecondItem; - AssertEqual(a, 1); - AssertEqual(b, 2.0); - AssertEqual(c, 3); - } - - function UdtInnerNamedTupleFieldTest () : Unit { - let t = InnerNamedTuple((Zero, (0,1)), ""); - AssertEqual(Zero, t::Fst); - let snd = t::Snd; - let (s1, s2) = snd; - AssertEqual(0, s1); - AssertEqual(1, s2); - AssertEqual("", t::Trd); - } -} - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs index e44783a32d6..e4f2d61388e 100644 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs @@ -5,8 +5,8 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Math; + open Microsoft.Quantum.Measurement; open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Simulation.TestSuite; /// @@ -28,14 +28,14 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { let q1 = qubits[0]; let (a, b) = expected; let (p, r) = start; - SetQubit(r, q1); + SetToBasisState(r, q1); if (p == PauliX) { H(q1); } // Make sure we start in correct state. - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // Apply the gate, make sure it's in the right state gate(q1); @@ -43,7 +43,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { // Apply Adjoint, back to Zero: Adjoint gate(q1); - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // When no control qubits, it should be equivalent to just calling the gate: Controlled gate(new Qubit[0], q1); @@ -51,7 +51,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { // Apply Adjoint, back to Zero: Controlled (Adjoint gate)(new Qubit[0], q1); - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // Now test control... We'll have 3 control qubits. // We will run the test with 1..3 controls at a time. @@ -62,18 +62,18 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { for (i in 0 .. ctrlsCount - 1) { // We're starting fresh - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // Get a subset for control and initialize them to zero: let c = ctrls[0 .. i]; for (j in 0 .. i) { - SetQubit(Zero, c[j]); + SetToBasisState(Zero, c[j]); } // Noop when ctrls are all zero. Controlled gate(c, q1); - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // turn on each of the controls one by one for (j in 1 .. Length(c)) { @@ -85,7 +85,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); } else { - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); } Adjoint Controlled gate(c, q1); @@ -96,8 +96,8 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { } // We're back where we started. - Assert([p], [q1], r, $"Qubit in invalid state."); - SetQubit(r, q1); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); + SetToBasisState(r, q1); ResetAll(qubits); } } diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs deleted file mode 100644 index 0c5f250a672..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/bug3223.qs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - operation F2 (x : Qubit[], y : Qubit) : Unit { - F1(x, y); - } - - operation F1 (x : Qubit[], y : Qubit) : Unit { - if (Length(x) > 1) { - F2(x[0..Length(x)-2], y); - } - else { - X(y); - } - } - - operation Solve (x : Qubit[], y : Qubit) : Unit - { - F1(x, y); - } - - operation MutuallyRecursiveOperationTest () : Unit { - - using (qubits = Qubit[4]) { - let x = qubits[0..2]; - let y = qubits[3]; - - Solve(x, y); - AssertQubit(One, y); - - ResetAll(qubits); - } - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/CoreTests.cs b/src/Simulation/Simulators.Type2.Tests/CoreTests.cs deleted file mode 100644 index 74f3c211e52..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/CoreTests.cs +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Text; -using Microsoft.Quantum.QsCompiler; -using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Tests.CoreOperations; - -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class CoreTests - { - private readonly ITestOutputHelper output; - - public CoreTests(ITestOutputHelper output) - { - this.output = output; - } - - [Fact] - public void BasicExecution() - { - var asmPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - var exe = Path.Combine(asmPath, "TestExe", "QsharpExe.dll"); - - ProcessRunner.Run("dotnet", exe, out var _, out StringBuilder error, out int exitCode, out Exception ex); - Assert.Null(ex); - Assert.Equal(1, exitCode); - Assert.Contains("NotImplementedException", error.ToString()); - - ProcessRunner.Run("dotnet", $"{exe} --simulator QuantumSimulator", out var _, out error, out exitCode, out ex); - Assert.Null(ex); - Assert.Equal(0, exitCode); - Assert.Empty(error.ToString().Trim()); - } - - [Fact] - public void BasicExecutionTargetedExe() - { - var asmPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - var exe = Path.Combine(asmPath, "TestTargetedExe", "TargetedExe.dll"); - - ProcessRunner.Run("dotnet", exe, out StringBuilder output, out StringBuilder error, out int exitCode, out Exception ex); - - Assert.Null(ex); - Assert.Equal(0, exitCode); - Assert.Empty(error.ToString().Trim()); - Assert.Equal("TargetedExe", output.ToString().Trim()); - } - - [Fact] - public void Borrowing() - { - OperationsTestHelper.RunWithMultipleSimulators((s) => - { - var tracker = new StartTracker(s); - - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - var q3 = new FreeQubit(3) as Qubit; - var q4 = new FreeQubit(4) as Qubit; - var q5 = new FreeQubit(5) as Qubit; - var q6 = new FreeQubit(6) as Qubit; - var q7 = new FreeQubit(7) as Qubit; - var q8 = new FreeQubit(8) as Qubit; - - BorrowingTest.Run(s).Wait(); - - var tracer = OperationsTestHelper.GetTracer<(long, Qubit)>(s); - - var testOne = new Action((int callsCount, OperationFunctor variant, (int, Qubit) info) => - { - var (available, q) = info; - Assert.Equal(callsCount, tracer.Log.GetNumberOfCalls(variant, (available, q))); - }); - - var testOneBody = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.Body, info)); - var testOneAdjoint = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.Adjoint, info)); - var testOneCtrl = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.Controlled, info)); - var testOneCtrlAdj = new Action((callsCount, info) => testOne(callsCount, OperationFunctor.ControlledAdjoint, info)); - - testOneBody(6, (0, q5)); - testOneBody(6, (0, q6)); - testOneBody(1, (1, q0)); - testOneBody(1, (1, q1)); - testOneBody(1, (1, q4)); - testOneBody(3, (1, q5)); - testOneBody(0, (1, q6)); - testOneBody(2, (2, q2)); - testOneBody(2, (2, q3)); - testOneBody(1, (3, q0)); - testOneBody(1, (3, q1)); - testOneBody(1, (3, q2)); - testOneBody(3, (3, q3)); - testOneBody(2, (4, q0)); - testOneBody(1, (4, q1)); - testOneBody(3, (4, q2)); - testOneBody(5, (5, q0)); - testOneBody(5, (5, q1)); - - testOneAdjoint(3, (0, q5)); - testOneAdjoint(3, (0, q6)); - testOneAdjoint(1, (1, q0)); - testOneAdjoint(1, (1, q1)); - testOneAdjoint(1, (1, q4)); - testOneAdjoint(3, (1, q5)); - testOneAdjoint(0, (1, q6)); - testOneAdjoint(2, (2, q2)); - testOneAdjoint(2, (2, q3)); - testOneAdjoint(1, (3, q2)); - testOneAdjoint(1, (3, q3)); - testOneAdjoint(1, (4, q0)); - testOneAdjoint(1, (4, q1)); - testOneAdjoint(2, (4, q2)); - testOneAdjoint(2, (5, q0)); - testOneAdjoint(2, (5, q1)); - - testOneCtrl(3, (0, q7)); - testOneCtrl(3, (0, q8)); - testOneCtrl(1, (1, q0)); - testOneCtrl(1, (1, q1)); - testOneCtrl(1, (1, q4)); - testOneCtrl(2, (1, q5)); - testOneCtrl(0, (1, q6)); - testOneCtrl(0, (2, q0)); - testOneCtrl(0, (2, q1)); - testOneCtrl(2, (2, q2)); - testOneCtrl(2, (2, q3)); - testOneCtrl(1, (3, q2)); - testOneCtrl(1, (3, q3)); - testOneCtrl(1, (4, q0)); - testOneCtrl(1, (4, q1)); - testOneCtrl(2, (4, q2)); - testOneCtrl(3, (5, q0)); - testOneCtrl(3, (5, q1)); - - testOneCtrlAdj(3, (0, q7)); - testOneCtrlAdj(3, (0, q8)); - testOneCtrlAdj(1, (1, q4)); - testOneCtrlAdj(1, (1, q7)); - testOneCtrlAdj(2, (2, q2)); - testOneCtrlAdj(2, (2, q3)); - testOneCtrlAdj(1, (3, q2)); - testOneCtrlAdj(1, (3, q3)); - testOneCtrlAdj(1, (4, q0)); - testOneCtrlAdj(1, (4, q1)); - testOneCtrlAdj(2, (4, q2)); - testOneCtrlAdj(2, (5, q0)); - testOneCtrlAdj(2, (5, q1)); - - Assert.Equal(20, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Body)); - Assert.Equal(11, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Adjoint)); - Assert.Equal(16, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Controlled)); - Assert.Equal(13, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.ControlledAdjoint)); - }); - } - - [Fact] - public void DumpState() - { - var expectedFiles = new string[] - { - "dumptest-start.txt", - "dumptest-h.txt", - "dumptest-former.txt", - "dumptest-later.txt", - "dumptest-one.txt", - "dumptest-two.txt", - "dumptest-entangled.txt", - "dumptest-twoQubitsEntangled.txt", - "dumptest-end.txt", - }; - - void RunOne(IOperationFactory s) - { - if (s is SimulatorBase sim) - { - // OnLog defines action(s) performed when Q# test calls function Message - sim.OnLog += (msg) => { output.WriteLine(msg); }; - } - - foreach (var name in expectedFiles) - { - if (File.Exists(name)) - { - File.Delete(name); - } - } - - if (File.Exists("()")) - { - File.Delete("()"); - } - - SimpleDumpTest.Run(s).Wait(); - - foreach (var name in expectedFiles) - { - Assert.True(File.Exists(name), $"File {name} did not exist after running SimpleDumpTest on {s}."); - } - - Assert.False(File.Exists("()")); - } - - OperationsTestHelper.RunWithMultipleSimulators((s) => RunOne(s as IOperationFactory)); - RunOne(new QuantumSimulator()); - } - - - [Fact] - public void ZeroQubits() - { - OperationsTestHelper.RunWithMultipleSimulators((s) => - { - var tracer = OperationsTestHelper.GetTracer(s); - - ZeroQubitsTest.Run(s).Wait(); - - Assert.Equal(1, tracer.GetNumberOfCalls(OperationFunctor.Body, "zero")); - }); - } - - [Fact] - public void InterpolatedStrings() - { - OperationsTestHelper.RunWithMultipleSimulators((s) => - { - Circuits.InterpolatedStringTest.Run(s).Wait(); // Throws if it doesn't succeed - }); - } - - [Fact] - public void RandomOperation() - { - OperationsTestHelper.RunWithMultipleSimulators((s) => - { - Circuits.RandomOperationTest.Run(s).Wait(); // Throws if it doesn't succeed - }); - } - - [Fact] - public void BigInts() - { - OperationsTestHelper.RunWithMultipleSimulators((s) => - { - Circuits.BigIntTest.Run(s).Wait(); // Throws if it doesn't succeed - }); - } - - [Fact] - public void CatchFail() - { - int exceptionCount = 0; - System.Action inc = (System.Runtime.ExceptionServices.ExceptionDispatchInfo e) => exceptionCount++; - var sim = new TrivialSimulator(); - sim.OnFail += inc; // increment exception counter when exception is caught - var inst = sim.Get(); - try - { - inst.Apply(QVoid.Instance); - Assert.True(false); // make sure that exception actually happened - } - catch(System.Exception e) - { - Assert.True(true); // make sure that exception actually happened - } - Assert.Equal(1, exceptionCount); // check that we cought exception once - } - - [Fact] - public void InternalCallables() => - OperationsTestHelper.RunWithMultipleSimulators(s => Circuits.InternalCallablesTest.Run(s).Wait()); - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs b/src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs deleted file mode 100644 index 0ef42022ab6..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/DebuggingToolsTests.cs +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Globalization; -using System.Threading; - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Tests.CoreOperations; - -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - using Helper = OperationsTestHelper; - /// - /// Provides test methods for things that are useful during debugging. - /// - public class DebuggingToolsTests - { - [Fact] - public void ToStringTests() => Helper.RunWithMultipleSimulators(qsim => - { - var _ = AbstractCallable._; - - var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)); - var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)); - var x = qsim.Get(); - var q2 = new FreeQubit(2) as Qubit; - var Q = new Q(q2); - var Qs = new QArray(q2); - var qs = new Qs(Qs); - var udtOp = new U3(x); - var udtQ = new Q(q2); - var t1 = new QTuple<(long, QRange, (Qubit, IUnitary))>((1L, new QRange(10, -2, 4), (q2, x))); - var t4 = new T4((3L, (1.1, false, Result.One))); - var t5 = new T5((Pauli.PauliX, Qs, qs, Q)); - - var d_1 = dump.Partial(_); - var d_2 = d_1.Partial(_); - var x_1 = x.Partial(new Func(q => q)); - var x_2 = x_1.Partial(new Func(q => q)); - var x_3 = x.Partial>(_); - - var t_1 = trace.Adjoint.Partial(_); - var t_2 = t_1.Controlled.Partial(_); - - WithInvariantCulture(() => - { - Assert.Equal("()", QVoid.Instance.ToString()); - Assert.Equal("_", _.ToString()); - Assert.Equal("U3(X)", udtOp.ToString()); - Assert.Equal("q:2", q2.ToString()); - Assert.Equal("Q(q:2)", udtQ.ToString()); - Assert.Equal("(1, 10..-2..4, (q:2, X))", t1.ToString()); - Assert.Equal("T4((3, (1.1, False, One)))", t4.ToString()); - Assert.Equal("T5((PauliX, [q:2], Qs([q:2]), Q(q:2)))", t5.ToString()); - Assert.Equal("X", x.ToString()); - Assert.Equal("(Adjoint X)", x.Adjoint.ToString()); - Assert.Equal("(Controlled X)", x.Controlled.ToString()); - Assert.Equal("(Adjoint (Controlled X))", x.Controlled.Adjoint.ToString()); - Assert.Equal("(Controlled (Adjoint X))", x.Adjoint.Controlled.ToString()); - Assert.Equal("X{_}", x_1.ToString()); - Assert.Equal("(Adjoint X{_})", x_1.Adjoint.ToString()); - Assert.Equal("X{_}{_}", x_2.ToString()); - Assert.Equal("X{_}", x_3.ToString()); - Assert.Equal("DumpMachine", dump.ToString()); - Assert.Equal("DumpMachine{_}", d_1.ToString()); - Assert.Equal("DumpMachine{_}{_}", d_2.ToString()); - Assert.Equal("Trace", trace.ToString()); - Assert.Equal("(Adjoint Trace)", trace.Adjoint.ToString()); - Assert.Equal("(Controlled Trace)", trace.Controlled.ToString()); - Assert.Equal("(Adjoint (Controlled Trace))", trace.Controlled.Adjoint.ToString()); - Assert.Equal("(Adjoint Trace){_}", t_1.ToString()); - Assert.Equal("(Adjoint (Controlled (Adjoint Trace){_}){_})", t_2.Adjoint.ToString()); - }); - }); - - [Fact] - public void QSharpTypeTests() - { - Helper.RunWithMultipleSimulators((qsim) => - { - var _ = AbstractCallable._; - - var x = qsim.Get(); - var q2 = new FreeQubit(2) as Qubit; - var Q = new Q(q2); - var Qs = new QArray(q2); - var qs = new Qs(Qs); - var udtOp = new U3(x); - var udtQ = new Q(q2); - var t4 = new T4((3L, (1.1, false, Result.One))); - var t5 = new T5((Pauli.PauliX, Qs, qs, Q)); - var plain = qsim.Get(); - var adj = qsim.Get(); - var ctrl = qsim.Get(); - var mapper = qsim.Get(); - - Assert.Equal("()", typeof(QVoid).QSharpType()); - Assert.Equal("_", _.GetType().QSharpType()); - Assert.Equal("U3", udtOp.GetType().QSharpType()); - Assert.Equal("Qubit => () : Adjoint, Controlled", udtOp.Data.GetType().QSharpType()); - Assert.Equal("Qubit", q2.GetType().QSharpType()); - Assert.Equal("Q", udtQ.GetType().QSharpType()); - Assert.Equal("Qubit", udtQ.Data.GetType().QSharpType()); - Assert.Equal("T4", t4.GetType().QSharpType()); - Assert.Equal("(Int,(Double,Boolean,Result))", t4.Data.GetType().QSharpType()); - Assert.Equal("T5", t5.GetType().QSharpType()); - Assert.Equal("(Pauli,Qubit[],Qs,Q)", t5.Data.GetType().QSharpType()); - Assert.Equal("Qubit => () : Adjoint, Controlled", x.GetType().QSharpType()); - Assert.Equal("Qubit => () : Adjoint, Controlled", x.Adjoint.GetType().QSharpType()); - Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.GetType().QSharpType()); - Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.Adjoint.GetType().QSharpType()); - Assert.Equal("(Int,Qubit,Callable) => ()", plain.GetType().QSharpType()); - Assert.Equal("(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj.GetType().QSharpType()); - Assert.Equal("(Int,Qs,Controllable) => () : Controlled", ctrl.GetType().QSharpType()); - Assert.Equal("(Callable,Result[]) => String[]", mapper.GetType().QSharpType()); - }); - } - - private void TestOneOp(string name, string fullName, OperationFunctor variant, string signature, AdjointedOperation op) - { - var proxy = new AdjointedOperation.DebuggerProxy(op); - TestOneProxy(name, fullName, variant, signature, proxy); - } - - private void TestOneOp(string name, string fullName, OperationFunctor variant, string signature, ControlledOperation op) - { - var proxy = new ControlledOperation.DebuggerProxy(op); - TestOneProxy(name, fullName, variant, signature, proxy); - } - - private void TestOneOp(string name, string fullName, OperationFunctor variant, string signature, Operation op) - { - TestOneProxy(name, fullName, variant, signature, new Operation.DebuggerProxy(op)); - } - - private void TestOneProxy(string name, string fullName, OperationFunctor variant, string signature, Operation.DebuggerProxy proxy) - { - Assert.Equal(name, proxy.Name); - Assert.Equal(fullName, proxy.FullName); - Assert.Equal(variant, proxy.Variant); - Assert.Equal(signature, proxy.Signature); - } - - [Fact] - public void NonGenericDebuggerProxy() - { - Helper.RunWithMultipleSimulators((qsim) => - { - var x = qsim.Get(); - var plain = qsim.Get(); - var adj = qsim.Get(); - var ctrl = qsim.Get(); - var mapper = qsim.Get(); - - TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body , "Qubit => () : Adjoint, Controlled", x); - TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint , "Qubit => () : Adjoint, Controlled", x.Adjoint); - TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled , "(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled); - TestOneOp("X", "Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint , "(Qubit[],Qubit) => () : Adjoint, Controlled", x.Adjoint.Controlled); - TestOneOp("BPlain1", "Microsoft.Quantum.Tests.CoreOperations.BPlain1", OperationFunctor.Body, "(Int,Qubit,Callable) => ()", plain); - TestOneOp("BAdj1", "Microsoft.Quantum.Tests.CoreOperations.BAdj1", OperationFunctor.Body, "(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj); - TestOneOp("BAdj1", "Microsoft.Quantum.Tests.CoreOperations.BAdj1", OperationFunctor.Adjoint, "(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj.Adjoint); - TestOneOp("BCtrl1", "Microsoft.Quantum.Tests.CoreOperations.BCtrl1", OperationFunctor.Body, "(Int,Qs,Controllable) => () : Controlled", ctrl); - TestOneOp("BCtrl1", "Microsoft.Quantum.Tests.CoreOperations.BCtrl1", OperationFunctor.Controlled, "(Qubit[],(Int,Qs,Controllable)) => () : Controlled", ctrl.Controlled); - TestOneOp("Map", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.ClosedType.Map", OperationFunctor.Body, "(Callable,Result[]) => String[]", mapper); - }); - } - - private void TestOneProxy(string signature, OperationPartial op) - { - var proxy = new OperationPartial.DebuggerProxy(op); - - Assert.Equal(op.BaseOp, proxy.Base); - Assert.Equal(signature, proxy.Signature); - } - - [Fact] - public void NonGenericPartialDebuggerProxy() - { - Helper.RunWithMultipleSimulators((qsim) => - { - var x = qsim.Get(); - var plain = qsim.Get(); - var adj = qsim.Get(); - var ctrl = qsim.Get(); - var mapper = qsim.Get(); - - var x_1 = x.Partial(new Func(q => q)); - var x_2 = x_1.Partial(new Func(q => q)); - var x_3 = x.Partial>(AbstractCallable._); - - var plain_1 = plain.Partial(new Func((arg) => (1, arg, x))); - var adj_1 = adj.Partial(new Func<((Qubit,Qubit,IQArray),IAdjointable), (Int64, (Qubit, Qubit, IQArray), IAdjointable)>((arg) => (3, arg.Item1, arg.Item2))); - var adj_2 = adj_1.Adjoint.Partial(new Func<(Qubit, Qubit, IQArray), ((Qubit, Qubit, IQArray), IAdjointable)>((arg) => (arg, adj))); - var ctrl_1 = ctrl.Partial(new Func<(Qs, IControllable), (Int64, Qs,IControllable)>((arg) => (4, arg.Item1, arg.Item2))); - var mapper_1 = mapper.Partial(new Func, (ICallable, IQArray)>((arg) => (x, arg))); - - TestOneProxy("Qubit => () : Adjoint, Controlled", x_1); - TestOneProxy("Qubit => () : Adjoint, Controlled", x_2); - TestOneProxy("Qubit => () : Adjoint, Controlled", x_3); - TestOneProxy("((Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj_1); - TestOneProxy("(Qubit,Qubit,Qubit[]) => () : Adjoint", adj_2); - TestOneOp("BAdj1", "Microsoft.Quantum.Tests.CoreOperations.BAdj1", OperationFunctor.Body, "(Qubit,Qubit,Qubit[]) => () : Adjoint", adj_2.Adjoint); - TestOneProxy("(Qs,Controllable) => () : Controlled", ctrl_1); - TestOneOp("BCtrl1", "Microsoft.Quantum.Tests.CoreOperations.BCtrl1", OperationFunctor.Controlled, "(Qubit[],(Qs,Controllable)) => () : Controlled", ctrl_1.Controlled); - TestOneProxy("Result[] => String[]", mapper_1); - }); - } - - private void TestOneProxy(string name, string fullName, OperationFunctor variant, string signature, GenericCallable op) - { - var proxy = new GenericCallable.DebuggerProxy(op); - - Assert.Equal(name, proxy.Name); - Assert.Equal(fullName, proxy.FullName); - Assert.Equal(variant, proxy.Variant); - } - - [Fact] - public void GenericDebuggerProxy() - { - Helper.RunWithMultipleSimulators((qsim) => - { - var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable; - var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)) as GenericCallable; - var gen3 = qsim.Get(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable; - - TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Body, "T => () : Adjoint, Controlled", trace); - TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Adjoint, "T => () : Adjoint, Controlled", trace.Adjoint); - TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Controlled, "(Qubit[],T) => () : Adjoint, Controlled", trace.Controlled); - TestOneProxy("Trace", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.ControlledAdjoint, "(Qubit[],T) => () : Adjoint, Controlled", trace.Adjoint.Controlled); - TestOneProxy("DumpMachine", "Microsoft.Quantum.Diagnostics.DumpMachine", OperationFunctor.Body, "T => ()", dump); - TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Body, "(__T1,(__T2,__T3),Result) => () : Controlled", gen3); - TestOneProxy("Gen3", "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Gen3", OperationFunctor.Controlled, "(Qubit[],(__T1,(__T2,__T3),Result)) => () : Controlled", gen3.Controlled); - }); - } - - private void TestOneProxy(string partialTuple, GenericPartial op) - { - var proxy = new GenericPartial.DebuggerProxy(op); - - Assert.Equal(op.BaseOp, proxy.Base); - Assert.Equal(partialTuple, proxy.PartialTuple); - } - - [Fact] - public void GenericPartialDebuggerProxy() - { - Helper.RunWithMultipleSimulators((qsim) => - { - var _ = AbstractCallable._; - - var dump = qsim.Get(typeof(Microsoft.Quantum.Diagnostics.DumpMachine<>)) as GenericCallable; - var trace = qsim.Get(typeof(Circuits.Generics.Trace<>)) as GenericCallable; - var gen3 = qsim.Get(typeof(Circuits.Generics.Gen3<,,>)) as GenericCallable; - - var d_1 = dump.Partial(_); - var d_2 = d_1.Partial(_); - var d_3 = d_2.Adjoint.Partial(_); - - var t_1 = trace.Adjoint.Partial(_); - var t_2 = t_1.Controlled.Partial((_, true)); - - var g_1 = gen3.Partial((_, ("hello", _), _)); - var g_2 = g_1.Partial((_, Pauli.PauliX, Result.Zero)); - var g_3 = gen3.Partial(new Func(arg => (arg, ("bye", 3), Result.One))); - - TestOneProxy("_", t_1); - TestOneProxy("(_, True)", t_2); - TestOneProxy("_", d_1); - TestOneProxy("_", d_2); - TestOneProxy("(_, (hello, _), _)", g_1); - TestOneProxy("(_, PauliX, Zero)", g_2); - TestOneProxy("", g_3); - }); - } - - /// - /// Changes the current thread culture to the invariant culture, runs the action, and then restores the original - /// thread culture. - /// - /// The action to run within the invariant culture. - private static void WithInvariantCulture(System.Action action) - { - var culture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; - action(); - Thread.CurrentThread.CurrentCulture = culture; - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs b/src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs deleted file mode 100644 index 04965adf032..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/DiagnosticsWrappers.qs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests { - open Microsoft.Quantum.Diagnostics; - - operation DumpToFile(filename : String) : Unit { - DumpMachine(filename); - } - -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/GenericsTests.cs b/src/Simulation/Simulators.Type2.Tests/GenericsTests.cs deleted file mode 100644 index a845b5472ad..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/GenericsTests.cs +++ /dev/null @@ -1,852 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.ClosedType; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics; -using System; -using System.Collections.Generic; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - using Helper = Microsoft.Quantum.Simulation.Simulators.Tests.OperationsTestHelper; - - public class TestQubit : Qubit - { - public TestQubit() : base(0) { } - } - - public class GenericsTests - { - [Fact] - public void CreateGenericOperation() - { - Helper.RunWithMultipleSimulators((s) => - { - { - var gen = new GenericCallable(s, typeof(Gen0<>)); - Assert.Same(typeof(Gen0), gen.FindCallable(typeof(long), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen0<(long, Result)>), gen.FindCallable(typeof((long, Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen0<((long, bool), Result)>), gen.FindCallable(typeof(((long, bool), Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen0), gen.FindCallable(typeof(UDT_G1), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen0), gen.FindCallable(typeof(UDT_G2), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen0), gen.FindCallable(typeof(UDT_G3), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen0>), gen.FindCallable(typeof(QArray), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen0), gen.FindCallable(typeof(LittleEndian), typeof(QVoid)).GetType()); - } - { - var gen = new GenericCallable(s, typeof(Gen1<,>)); - Assert.Same(typeof(Gen1), gen.FindCallable(typeof((long, bool)), typeof(bool)).GetType()); - Assert.Same(typeof(Gen1<(long, Result), bool>), gen.FindCallable(typeof(((long, Result), bool)), typeof(bool)).GetType()); - Assert.Same(typeof(Gen1<((long, bool), Result), QVoid>), gen.FindCallable(typeof((((long, bool), Result), bool)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen1<((long, bool), Result), Pauli>), gen.FindCallable(typeof((((long, bool), Result), bool)), typeof(Pauli)).GetType()); - Assert.Same(typeof(Gen1, bool>), gen.FindCallable(typeof((QArray, bool)), typeof(bool)).GetType()); - Assert.Same(typeof(Gen1), gen.FindCallable(typeof(UDT_G1), typeof(Qubit)).GetType()); // no need to unwrapp qtuples automatically anymore. - Assert.Same(typeof(Gen1), gen.FindCallable(typeof(UDT_G2), typeof(Qubit)).GetType()); // no need to unwrapp qtuples automatically anymore. - Assert.Same(typeof(Gen1), gen.FindCallable(typeof(UDT_G5), typeof(UDT_G2)).GetType()); // no need to unwrapp qtuples automatically anymore. - } - - { - var gen = new GenericCallable(s, typeof(Gen2<,>)); - Assert.Same(typeof(Gen2), gen.FindCallable(typeof((Result, long, bool)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen2<(Result, Pauli, Qubit), bool>), gen.FindCallable(typeof(((Result, Pauli, Qubit), long, bool)), typeof(QVoid)).GetType()); - // not a valid scenario due to unwrap: Assert.Same(typeof(Gen2, Qubit>), gen.FindOperation(typeof(UDT_G4), typeof(QVoid)).GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Gen3<,,>)); - Assert.Same(typeof(Gen3), gen.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen3), gen.FindCallable(typeof((Result, ((long, long), Pauli), Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen3<(long, IAdjointable, double), bool, Pauli>), gen.FindCallable(typeof(((long, IAdjointable, double), (bool, Pauli), Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen3), gen.FindCallable(typeof((Result, (bool, (Pauli, Pauli)), Result)), typeof(QVoid)).GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Gen4<,>)); - Assert.Same(typeof(Gen4), gen.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen4<(bool, long, (int, ICallable)), Pauli>), gen.FindCallable(typeof((Result, ((bool, long, (int, ICallable)), Pauli), Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen4<(IUnitary, bool), (IAdjointable, Pauli)>), gen.FindCallable(typeof((Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result)), typeof(QVoid)).GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Gen5<>)); - Assert.Same(typeof(Gen5), gen.FindCallable(typeof(IQArray), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen5), gen.FindCallable(typeof(IQArray), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen5>), gen.FindCallable(typeof(IQArray>), typeof(QVoid)).GetType()); - // not a valid scenario due to unwrap: Assert.Same(typeof(Gen5), gen.FindOperation(typeof(LittleEndian), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen5), gen.FindCallable(typeof(IQArray), typeof(QVoid)).GetType()); - Assert.Same(typeof(Gen5>), gen.FindCallable(typeof(IQArray>), typeof(QVoid)).GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Iter<>)); - Assert.Same(typeof(Iter), gen.FindCallable(typeof((ICallable, IQArray)), typeof(QVoid)).GetType()); - } - }); - } - - [Fact] - public void CreateGenericAdjointOperation() - { - Helper.RunWithMultipleSimulators((s) => - { - var gen0 = new GenericCallable(s, typeof(Gen0<>)); - - Assert.Same(typeof(AdjointedOperation), gen0.Adjoint.FindCallable(typeof(long), typeof(QVoid)).GetType()); - Assert.Same(typeof(AdjointedOperation<(long, Result), QVoid>), gen0.Adjoint.FindCallable(typeof((long, Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(AdjointedOperation<((long, bool), Result), QVoid>), gen0.Adjoint.FindCallable(typeof(((long, bool), Result)), typeof(QVoid)).GetType()); - Assert.Same(typeof(AdjointedOperation<(long, Result), QVoid>), gen0.Adjoint.FindCallable(typeof((long, Result)), typeof(QVoid)).GetType()); // Twice to test caching. - - var gen2 = new GenericCallable(s, typeof(Gen2<,>)); - var r2 = gen2.Adjoint.FindCallable(typeof((Result, long, bool)), typeof(QVoid)) as AdjointedOperation<(Result, long, bool), QVoid>; - Assert.NotNull(r2); - Assert.Same(typeof(Gen2), r2.BaseOp.GetType()); - - var gen4 = new GenericCallable(s, typeof(Gen4<,>)); - var r4 = gen4.Adjoint.FindCallable(typeof((Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result)), typeof(QVoid)) as AdjointedOperation<(Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result), QVoid>; - Assert.NotNull(r4); - Assert.Same(typeof(Gen4<(IUnitary, bool), (IAdjointable, Pauli)>), r4.BaseOp.GetType()); - }); - } - - - [Fact] - public void CreateGenericControlledOperation() - { - Helper.RunWithMultipleSimulators((s) => - { - var gen0 = new GenericCallable(s, typeof(Gen0<>)); - - Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((QArray, long)), typeof(QVoid)).GetType()); - Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((LittleEndian, long)), typeof(QVoid)).GetType()); - Assert.Same(typeof(ControlledOperation<(long, Result), QVoid>), gen0.Controlled.FindCallable(typeof((QArray, (long, Result))), typeof(QVoid)).GetType()); - Assert.Same(typeof(ControlledOperation<((Qubit, bool), Result), QVoid>), gen0.Controlled.FindCallable(typeof((QArray, ((TestQubit, bool), Result))), typeof(QVoid)).GetType()); - Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((QArray, long)), typeof(QVoid)).GetType()); // Twice to check for caching. - - var gen2 = new GenericCallable(s, typeof(Gen2<,>)); - var r2 = gen2.Controlled.FindCallable(typeof((LittleEndian, (QArray, long, bool))), typeof(QVoid)) as ControlledOperation<(QArray, long, bool), QVoid>; - Assert.NotNull(r2); - Assert.Same(typeof(Gen2, bool>), r2.BaseOp.GetType()); - - var gen4 = new GenericCallable(s, typeof(Gen4<,>)); - var r4 = gen4.Controlled.FindCallable(typeof((QArray, (Result, ((IUnitary, bool), (IAdjointable<(TestQubit, Result)>, Pauli)), Result))), typeof(QVoid)) as ControlledOperation<(Result, ((IUnitary, bool), (IAdjointable, Pauli)), Result), QVoid>; - Assert.NotNull(r4); - Assert.Same(typeof(Gen4<(IUnitary, bool), (IAdjointable, Pauli)>), r4.BaseOp.GetType()); - }); - } - [Fact] - public void FindOperation() - { - var _ = AbstractCallable._; - - Helper.RunWithMultipleSimulators((s) => - { - { - var gen = s.Get(typeof(Gen1<,>)); - - // Calling twice for the same input - var expected = gen.FindCallable(typeof((long, bool)), typeof(bool)); - var actual = gen.FindCallable(typeof((long, bool)), typeof(bool)); - Assert.Same(expected, actual); - - // Change the input type, different operations - expected = gen.FindCallable(typeof((long, Result)), typeof(Result)); - Assert.NotSame(expected, actual); - actual = gen.FindCallable(typeof((long, Result)), typeof(Result)); - Assert.Same(expected, actual); - - var unitary = s.Get(typeof(Gen4<,>)); - expected = unitary.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); - actual = unitary.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); - Assert.Same(expected, actual); - - expected = unitary.Adjoint.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); - actual = unitary.Adjoint.FindCallable(typeof((Result, (bool, Pauli), Result)), typeof(QVoid)); - Assert.Same(expected, actual); - - expected = unitary.Controlled.FindCallable(typeof((QArray, (Result, (bool, Pauli), Result))), typeof(QVoid)); - actual = unitary.Controlled.FindCallable(typeof((QArray, (Result, (bool, Pauli), Result))), typeof(QVoid)); - Assert.Same(expected, actual); - - // Partial gives us a new instance every time. - expected = unitary.Partial((_,_,_)); - actual = unitary.Partial((_, _, _)); - Assert.NotSame(expected, actual); - } - }); - } - - - [Fact] - public void CreateGenericOperationWithMultipleFunctors() - { - var _ = AbstractCallable._; - - Helper.RunWithMultipleSimulators((s) => - { - var gen0 = new GenericCallable(s, typeof(Gen0<>)); - - Assert.Same(typeof(Gen0), gen0.FindCallable(typeof(long), typeof(QVoid)).GetType()); - Assert.Same(typeof(ControlledOperation), gen0.Controlled.FindCallable(typeof((IQArray, long)), typeof(QVoid)).GetType()); - Assert.Same(typeof(AdjointedOperation), gen0.Adjoint.FindCallable(typeof(long), typeof(QVoid)).GetType()); - { - var op = gen0.Adjoint.Controlled.FindCallable(typeof((IQArray, long)), typeof(QVoid)) as ControlledOperation; - Assert.NotNull(op); - Assert.Same(typeof(AdjointedOperation), op.BaseOp.GetType()); - } - { - var op = gen0.Controlled.Adjoint.FindCallable(typeof((IQArray, long)), typeof(QVoid)) as AdjointedOperation<(IQArray, long), QVoid>; - Assert.NotNull(op); - Assert.Same(typeof(ControlledOperation), op.BaseOp.GetType()); - } - }); - } - - - [Fact] - public void CreateGenericPartial() - { - var _ = AbstractCallable._; - - Helper.RunWithMultipleSimulators((s) => - { - { - var gen = new GenericCallable(s, typeof(Gen0<>)); - var partial = gen.Partial(_); - Assert.Same(typeof(long), partial.IdentifyBaseArgsType(typeof(long))); - Assert.Same(typeof(Qubit), partial.IdentifyBaseArgsType(typeof(Qubit))); - Assert.Same(typeof((bool, long)), partial.IdentifyBaseArgsType(typeof((bool, long)))); - - { - var op1 = partial.FindCallable(typeof(Qubit), typeof(QVoid)) as OperationPartial; - Assert.NotNull(op1); - } - { - var op1 = partial.FindCallable(typeof(Double), typeof(QVoid)) as OperationPartial; - Assert.NotNull(op1); - } - } - - { - var gen = new GenericCallable(s, typeof(Gen0<>)); - var partial = gen.Adjoint.Partial(_); - Assert.Same(typeof(long), partial.IdentifyBaseArgsType(typeof(long))); - Assert.Same(typeof(Qubit), partial.IdentifyBaseArgsType(typeof(Qubit))); - Assert.Same(typeof((bool, long)), partial.IdentifyBaseArgsType(typeof((bool, long)))); - - { - var op1 = partial.FindCallable(typeof(Qubit), typeof(QVoid)) as OperationPartial; - Assert.NotNull(op1); - } - { - var op1 = partial.FindCallable(typeof(Double), typeof(QVoid)) as OperationPartial; - Assert.NotNull(op1); - } - } - - { - var gen = new GenericCallable(s, typeof(Gen0<>)); - var ctrl = gen.Controlled; - var partial = ctrl.Partial((new QArray(), _)); - Assert.Same(typeof((QArray, long)), partial.IdentifyBaseArgsType(typeof(long))); - Assert.Same(typeof((QArray, string)), partial.IdentifyBaseArgsType(typeof(string))); - Assert.Same(typeof((QArray, Qubit)), partial.IdentifyBaseArgsType(typeof(Qubit))); - Assert.Same(typeof((QArray, (bool, long))), partial.IdentifyBaseArgsType(typeof((bool, long)))); - { - var op1 = partial.FindCallable(typeof(Result), typeof(QVoid)); - Assert.Equal(typeof(OperationPartial, Result), QVoid>), op1.GetType()); - } - { - var op1 = partial.FindCallable(typeof(string), typeof(QVoid)); - Assert.Equal(typeof(OperationPartial, string), QVoid>), op1.GetType()); - } - } - - { - var gen = new GenericCallable(s, typeof(TraceGate<>)); - var partial = gen.Partial((s.Get, Intrinsic.X>(), "normal", _)); - - Assert.Same(typeof((IUnitary, string, Result)), partial.IdentifyBaseArgsType(typeof(Result))); - Assert.Same(typeof((IUnitary, string, Qubit)), partial.IdentifyBaseArgsType(typeof(TestQubit))); - var op1 = partial.FindCallable(typeof(TestQubit), typeof(QVoid)); - Assert.Equal(typeof(OperationPartial), op1.GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Gen1<,>)); - var partial = gen.Partial((_, 2.3D)); - Assert.Same(typeof((Result, double)), partial.IdentifyBaseArgsType(typeof(Result))); - var op1 = partial.FindCallable(typeof(Result), typeof(double)); - Assert.Equal(typeof(OperationPartial), op1.GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Gen2<,>)); - var partial = gen.Partial((_, _, _)); - Assert.Same(typeof((Result, long, bool)), partial.IdentifyBaseArgsType(typeof((Result, long, bool)))); - } - - { - var gen = new GenericCallable(s, typeof(Gen2<,>)); - var p1 = new GenericCallable(s, typeof(Gen1<,>)) as ICallable; - var p2 = new GenericCallable(s, typeof(Gen2<,>)) as IAdjointable; - var p3 = p2.Partial((_, true)); - - var partial = gen.Partial((p1, _, (p2, p3))); - Assert.Same(typeof((ICallable, long, (IAdjointable, IAdjointable))), partial.IdentifyBaseArgsType(typeof(long))); - var op1 = partial.FindCallable(typeof(long), typeof(QVoid)); - Assert.Equal(typeof(OperationPartial), op1.GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Gen2<,>)); - var p1 = new GenericCallable(s, typeof(Gen1<,>)) as ICallable; - var p2 = new GenericCallable(s, typeof(Gen2<,>)) as IAdjointable; - var p3 = p2.Partial((_, true)); - - var partial = gen.Partial(((_, p1), _, (p2, p3))); - Assert.Same(typeof(((Qubit, ICallable), long, (IAdjointable, IAdjointable))), partial.IdentifyBaseArgsType(typeof((TestQubit, long)))); - var op1 = partial.FindCallable(typeof((TestQubit, long)), typeof(QVoid)); - Assert.Equal(typeof(OperationPartial<(Qubit, long), ((Qubit, ICallable), long, (IAdjointable, IAdjointable)), QVoid>), op1.GetType()); - } - - { - var gen = new GenericCallable(s, typeof(Gen2<,>)); - var partial = gen.Partial((_, 2L, false)); - Assert.Same(typeof((Result, long, bool)), partial.IdentifyBaseArgsType(typeof(Result))); - Assert.Same(typeof((IUnitary, long, bool)), partial.IdentifyBaseArgsType(typeof(IUnitary))); - } - - { - var gen = new GenericCallable(s, typeof(Gen3<,,>)); - var partial = gen.Partial((_, (_, s.Get, ClosedType3>()), Result.Zero)); - Assert.Same(typeof((long, (bool, IControllable), Result)), partial.IdentifyBaseArgsType(typeof((long, bool)))); - Assert.Same(typeof((IUnitary, (Qubit, IControllable), Result)), partial.IdentifyBaseArgsType(typeof((IUnitary, Qubit)))); - Assert.Same(typeof((string, (string, IControllable), Result)), partial.IdentifyBaseArgsType(typeof((string, string)))); - } - - { - var gen = new GenericCallable(s, typeof(Gen3<,,>)); - var partial = gen.Partial((s.Get, ClosedType2>(), (_, _), Result.Zero)); - Assert.Same(typeof((IAdjointable, (long, bool), Result)), partial.IdentifyBaseArgsType(typeof((long, bool)))); - Assert.Same(typeof((IAdjointable, (IUnitary, Qubit), Result)), partial.IdentifyBaseArgsType(typeof((IUnitary, Qubit)))); - Assert.Same(typeof((IAdjointable, (string, string), Result)), partial.IdentifyBaseArgsType(typeof((string, string)))); - } - - { - var gen = new GenericCallable(s, typeof(Gen4<,>)); - var partial = gen.Partial((Result.One, (s.Get, ClosedType4>(), _), Result.Zero)); - Assert.Same(typeof((Result, (IUnitary, bool), Result)), partial.IdentifyBaseArgsType(typeof(bool))); - Assert.Same(typeof((Result, (IUnitary, (IUnitary, Qubit)), Result)), partial.IdentifyBaseArgsType(typeof((IUnitary, Qubit)))); - Assert.Same(typeof((Result, (IUnitary, (string, string)), Result)), partial.IdentifyBaseArgsType(typeof((string, string)))); - } - - { - var gen = new GenericCallable(s, typeof(Gen3<,,>)); - var partial = gen.Partial((_,_,Result.Zero)); - Assert.Same(typeof(((long, bool), (double,double), Result)), partial.IdentifyBaseArgsType(typeof(((long, bool),(double,double))))); - Assert.Same(typeof((long, (double, double), Result)), partial.IdentifyBaseArgsType(typeof((long, (double, double))))); - Assert.Same(typeof((long, (double, (long,double)), Result)), partial.IdentifyBaseArgsType(typeof((long, (double, (long,double)))))); - } - - { - var gen = new GenericCallable(s, typeof(Gen3<,,>)); - var partial = gen.Partial((_, (4.1,_), Result.Zero)); - Assert.Same(typeof(((long, bool), (double, double), Result)), partial.IdentifyBaseArgsType(typeof(((long, bool), double)))); - Assert.Same(typeof((long, (double, double), Result)), partial.IdentifyBaseArgsType(typeof((long, double)))); - Assert.Same(typeof((long, (double ,(long, double)), Result)), partial.IdentifyBaseArgsType(typeof((long, (long, double))))); - } - }); - } - - - [Fact] - public void CreateDifferentPartial() - { - var _ = AbstractCallable._; - - Helper.RunWithMultipleSimulators((s) => - { - { - var gen = new GenericCallable(s, typeof(Gen1<,>)); - var partial = gen.Partial(_); - Assert.Equal(typeof(GenericPartial), partial.GetType()); - } - - { - var closed = new Gen1(s); - var partial = closed.Partial(_); - Assert.Equal(typeof(OperationPartial<(long, bool), (long, bool), bool>), partial.GetType()); - } - - { - var closed = new Gen1<(long, long), bool>(s); - var partial = closed.Partial(((3L, _), true)); - Assert.Equal(typeof(OperationPartial), partial.GetType()); - } - - { - var x = s.Get, Intrinsic.X>(); - var closed = new Gen1<(long, (IUnitary, Qubit, Result)), bool>(s); - var partial = closed.Partial(((_, (x, _, _)), true)); - Assert.Equal(typeof(OperationPartial<(long, (Qubit, Result)), ((long, (IUnitary, Qubit, Result)), bool), bool>), partial.GetType()); - } - - { - var x = s.Get, Intrinsic.X>(); - var closed = new Gen1<(long, (IUnitary, Qubit, Result)), bool>(s) as ICallable<((long, (IUnitary, Qubit, Result)), bool), bool>; - var partial = closed.Partial(((_, (x, _, _)), false)); - Assert.Equal(typeof(OperationPartial<(long, (Qubit, Result)), ((long, (IUnitary, Qubit, Result)), bool), bool>), partial.GetType()); - } - - { - var closed = new Gen2<(long, bool, Result), IUnitary>(s); - var partial = closed.Partial(((_, true, _), 3L, _)); - Assert.Equal(typeof(OperationPartial<((long, Result), IUnitary), ((long, bool, Result), long, IUnitary), QVoid>), partial.GetType()); - } - - { - var closed = new Gen2(s) as IAdjointable<(bool, long, Result)>; - var partial = closed.Partial((_, 3L, Result.Zero)); - Assert.Equal(typeof(OperationPartial), partial.GetType()); - } - - { - var closed = new Gen4(s) as IUnitary<(Result, (bool, bool), Result)>; - var partial = closed.Controlled.Partial((_, (_, (true, _), Result.Zero))); - Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); - } - - { - var closed = new Gen4(s) as IControllable<(Result, (bool, bool), Result)>; - var partial = closed.Controlled.Partial((_, (_, (true, _), Result.Zero))); - Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); - } - - { - var closed = new Gen2(s) as IAdjointable; - var partial = closed.Partial((_, 3L, Result.Zero)); - Assert.Equal(typeof(OperationPartial), partial.GetType()); - } - - { - var closed = new Gen4(s) as IUnitary; - var partial = closed.Adjoint.Controlled.Partial((_, (_, (true, _), Result.Zero))); - Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); - } - - { - var closed = new Gen4(s) as IControllable; - var partial = closed.Controlled.Partial((_, (_, (true, _), Result.Zero))); - Assert.Equal(typeof(OperationPartial<(IQArray, (Result, bool)), (IQArray, (Result, (bool, bool), Result)), QVoid>), partial.GetType()); - } - }); - } - - private void CheckIter(Log log, T zero, T uno) - { - Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Body, zero)); - Assert.Equal(1, log.GetNumberOfCalls(OperationFunctor.Body, uno)); - - Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.Adjoint, zero)); - Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Adjoint, uno)); - - Assert.Equal(1, log.GetNumberOfCalls(OperationFunctor.Controlled, zero)); - Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.Controlled, uno)); - - Assert.Equal(4, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, zero)); - Assert.Equal(5, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, uno)); - } - - private void CheckRepeat(Log log) - { - Assert.Equal(5, log.GetNumberOfCalls(OperationFunctor.Body, "normal")); - Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Adjoint, "normal")); - Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.Controlled, "normal")); - Assert.Equal(0, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "normal")); - - Assert.Equal(2, log.GetNumberOfCalls(OperationFunctor.Body, "adjoint")); - Assert.Equal(5, log.GetNumberOfCalls(OperationFunctor.Adjoint, "adjoint")); - Assert.Equal(0, log.GetNumberOfCalls(OperationFunctor.Controlled, "adjoint")); - Assert.Equal(3, log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "adjoint")); - } - - [Fact] - public void ClosedTypeIter() - { - Helper.RunWithMultipleSimulators((s) => - { - Circuits.ClosedType.TestIter.Run(s).Wait(); - - var tracer = s.Get() as Helper.TracerImpl; - CheckIter(tracer.Log, "cero", "uno"); - }); - } - - [Fact] - public void ClosedTypeRepeatPartial() - { - Helper.RunWithMultipleSimulators((s) => - { - Circuits.ClosedType.TestRepeatPartial.Run(s).Wait(); - - var t = s.Get() as Helper.TracerImpl; - CheckRepeat(t.Log); - }); - } - - [Fact] - public void GenericIter() - { - Helper.RunWithMultipleSimulators((s) => - { - Circuits.Generics.TestIter.Run(s).Wait(); - - var strTracer = s.GetTracer(); - CheckIter(strTracer.Log, "cero", "uno"); - - var resTracer = s.GetTracer(); - CheckIter(resTracer.Log, Result.Zero, Result.One); - }); - } - - [Fact] - public void GenericRepeatPartial() - { - Helper.RunWithMultipleSimulators((s) => - { - Circuits.Generics.TestRepeatPartial.Run(s).Wait(); - - var tracer = s.GetTracer(); - CheckRepeat(tracer.Log); - }); - } - - [Fact] - public void CreateRepeatWrapperPartial() - { - Helper.RunWithMultipleSimulators((s) => - { - TestCreateRepeatWrapperPartial.Run(s).Wait(); - - var tracer = s.GetTracer(); - CheckRepeat(tracer.Log); - }); - } - - [Fact] - public void TestLookupUnitaries() - { - Helper.RunWithMultipleSimulators((s) => - { - Circuits.Generics.TestLookupUnitaries.Run(s).Wait(); - - var tracer = s.GetTracer(); - - Assert.Equal(6, tracer.GetNumberOfCalls(OperationFunctor.Body, "uno")); - Assert.Equal(6, tracer.GetNumberOfCalls(OperationFunctor.Adjoint, "uno")); - Assert.Equal(9, tracer.GetNumberOfCalls(OperationFunctor.Controlled, "uno")); - Assert.Equal(6, tracer.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "uno")); - }); - } - - [Fact] - public void ClosedUDTsPolyMorphism() - { - Helper.RunWithMultipleSimulators((s) => - { - TestUDTsUnwrapping.Run(s).Wait(); - - var stracer = s.Get() as Helper.TracerImpl; - - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2a")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2b")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2a")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2b")); - - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2x")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "d2y")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2x")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "d2y")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "d2x")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "d2y")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "d2x")); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "d2y")); - }); - } - - [Fact] - public void NonGenericPartial() - { - Helper.RunWithMultipleSimulators((s) => - { - TestNonGenericPartial.Run(s).Wait(); - - var stracer = s.GetTracer(); - var itracer = s.GetTracer(); - var rtracer = s.GetTracer(); - var sstracer = s.GetTracer<(string, string)>(); - var rrtracer = s.GetTracer<(Result, Result)>(); - - Assert.Equal(7, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "a1")); - Assert.Equal(7, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "a2")); - Assert.Equal(7, itracer.Log.GetNumberOfCalls(OperationFunctor.Body, 2)); - Assert.Equal(7, itracer.Log.GetNumberOfCalls(OperationFunctor.Body, 3)); - Assert.Equal(7, rtracer.Log.GetNumberOfCalls(OperationFunctor.Body, Result.Zero)); - Assert.Equal(7, rtracer.Log.GetNumberOfCalls(OperationFunctor.Body, Result.One)); - Assert.Equal(7, sstracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("a1", "a2"))); - Assert.Equal(7, rrtracer.Log.GetNumberOfCalls(OperationFunctor.Body, (Result.Zero, Result.One))); - - - Assert.Equal(9, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "a1")); - Assert.Equal(9, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, "a2")); - Assert.Equal(9, itracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 2)); - Assert.Equal(9, itracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 3)); - Assert.Equal(9, rtracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, Result.Zero)); - Assert.Equal(9, rtracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, Result.One)); - Assert.Equal(9, sstracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, ("a1", "a2"))); - Assert.Equal(9, rrtracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (Result.Zero, Result.One))); - - Assert.Equal(3, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "a1")); - Assert.Equal(3, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "a2")); - Assert.Equal(3, itracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, 2)); - Assert.Equal(3, itracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, 3)); - Assert.Equal(3, rtracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, Result.Zero)); - Assert.Equal(3, rtracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, Result.One)); - Assert.Equal(3, sstracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, ("a1", "a2"))); - Assert.Equal(3, rrtracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, (Result.Zero, Result.One))); - - Assert.Equal(4, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "a1")); - Assert.Equal(4, stracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, "a2")); - Assert.Equal(4, itracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, 2)); - Assert.Equal(4, itracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, 3)); - Assert.Equal(4, rtracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, Result.Zero)); - Assert.Equal(4, rtracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, Result.One)); - Assert.Equal(4, sstracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, ("a1", "a2"))); - Assert.Equal(4, rrtracer.Log.GetNumberOfCalls(OperationFunctor.ControlledAdjoint, (Result.Zero, Result.One))); - }); - } - - [Fact] - public void GenericPartialNestedTupleArgs() - { - Helper.RunWithMultipleSimulators((s) => - { - TestGenericPartial.Run(s).Wait(); - - var sstracer = s.GetTracer<(string, string)>(); - var stracer = s.GetTracer(); - - Assert.Equal(9, sstracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("T1", "T2"))); - Assert.Equal(11, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("argA"))); - Assert.Equal(11, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("argB"))); - Assert.Equal(10, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("argD"))); - }); - } - - [Fact] - public void GenericsCallablesArguments() - { - Helper.RunWithMultipleSimulators((s) => - { - BindTest.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("success!"))); - }); - } - - [Fact] - public void GenericCompose() - // FIXME: there are more cases similar to this one where the workaround of using object - // for the parts of the type argument O in Apply which are unresolvable won't work - { - Helper.RunWithMultipleSimulators((s) => - { - TestCompose.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "cero")); - TestComposeWithNonGeneric.Run(s).Wait(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, "redirecting:cero")); - }); - } - - [Fact] - public void GenericMultiControlled() - { - Helper.RunWithMultipleSimulators((s) => - { - MultiControlledTest.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1))); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (2))); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3))); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (4))); - }); - } - - [Fact] - public void GenericsMixedComponents() - { - Helper.RunWithMultipleSimulators((s) => - { - MixedComponentsTest.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1))); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (2))); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (2))); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (3))); - }); - } - - [Fact] - public void GenericsAssignments() - { - Helper.RunWithMultipleSimulators((s) => - { - AssignmentsTest.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1))); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (2))); - Assert.Equal(2, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (3))); - Assert.Equal(2, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3))); - }); - } - - [Fact] - public void GenericsAssignmentsWithPartialApplications() - { - Helper.RunWithMultipleSimulators((s) => - { - AssignmentsWithPartialsTest.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, (2))); - Assert.Equal(3, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3))); - }); - } - - [Fact] - public void GenericsCallableCasts() - { - Helper.RunWithMultipleSimulators((s) => - { - CCNOTCiruitsTest.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("success!"))); - }); - } - - [Fact] // FIXME: remove dummy in MapDefaults in Generics.qs to make this test meaningful! (currently this is not supported in the simulation core) - public void GenericsHiddenGenericParameters() - { - Helper.RunWithMultipleSimulators((s) => - { - TestMapDefaults.Run(s).Wait(); - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Body, ("success!"))); - }); - } - - [Fact] - public void GenericsMultipleTypeParameters() - { - Helper.RunWithMultipleSimulators((s) => - { - TestMultipleTypeParamters.Run(s).Wait(); - var ltracer = s.GetTracer(); - Assert.Equal(1, ltracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1L))); - }); - } - - [Fact] - public void GenericsDestructingArgTuple() - { - Helper.RunWithMultipleSimulators((s) => - { - TestDestructingArgTuple.Run(s).Wait(); - var ltracer = s.GetTracer(); - Assert.Equal(1, ltracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1L))); - var sstracer = s.GetTracer<(string, string)>(); - Assert.Equal(1, sstracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, ("Hello", "World"))); - }); - } - - [Fact] - public void ControlledBitString() - { - Helper.RunWithMultipleSimulators((s) => - { - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - - TestControlledBitString.Run(s).Wait(); - var tracer = s.GetTracer(); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, 0)); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, 1)); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, 2)); - - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 0)); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 1)); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Adjoint, 2)); - - var stracer = s.GetTracer(); - Assert.Equal(1, stracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, "ok")); - }); - } - - - [Fact] - public void ApplyToEachUdt() - { - Helper.RunWithMultipleSimulators((s) => - { - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - - TestApplyToEachUdt.Run(s).Wait(); - var tracer = s.GetTracer(); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, q0)); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, q1)); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Controlled, q2)); - }); - } - - [Fact] - public void UDTsPolyMorphism() - { - Helper.RunWithMultipleSimulators((s) => - { - var tracker = new StartTracker(s); - - TestUDTsPolyMorphism.Run(s).Wait(); - - Assert.Equal(20, tracker.GetNumberOfCalls("Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Body)); - }); - } - - [Fact] - public void WrapperWithDifferentReturnValues() - { - Helper.RunWithMultipleSimulators((s) => - { - var gen = new GenericCallable(s, typeof(Gen0<>)); - WrapperWithDifferentReturnValuesTest.Run(s).Wait(); - - // do some manual tests to verify cache works: - var wrapper = new GenericCallable(s, typeof(GenWrapper<,>)); - var str1 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(String)); - var int1 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(Int64)); - var str2 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(String)); - var int2 = wrapper.FindCallable(typeof((ICallable, Result)), typeof(Int64)); - - Assert.Same(str1, str2); - Assert.Same(int1, int2); - Assert.NotSame(str1, int1); - Assert.Same(typeof(GenWrapper), str1.GetType()); - Assert.Same(typeof(GenWrapper), int1.GetType()); - }); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs b/src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs deleted file mode 100644 index c952d210e5a..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/GetQubitsTests.cs +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Tests.Tuples; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - internal class FreeQubit : Qubit - { - public FreeQubit(int id) : base(id) - { - } - } - - internal class UnitaryNoOp : Unitary, ICallable - { - public UnitaryNoOp() : base(null) { } - - public override void Init() { } - - public override Func<(IQArray, TInput), QVoid> ControlledAdjointBody => (arg) => - { - Debug.Write("NoOp:ControlledAdjointBody:" + typeof(TInput).FullName); - return QVoid.Instance; - }; - - public override Func AdjointBody => (arg) => - { - Debug.Write("NoOp:AdjointBody:" + typeof(TInput).FullName); - return QVoid.Instance; - }; - - public override Func<(IQArray, TInput), QVoid> ControlledBody => (arg) => - { - Debug.Write("NoOp:ControlledBody:" + typeof(TInput).FullName); - return QVoid.Instance; - }; - - public override Func Body => (TInput arg) => - { - Debug.Write("NoOp:Body:" + typeof(TInput).FullName); - return QVoid.Instance; - }; - - string ICallable.FullName => "UnitaryNoOp"; - } - - public class GetQubitsTests - { - int GetQubitsCount(object val) - { - var v = val.GetQubits(); - if (v == null) { return 0; } - return v.Count(); - } - - [Fact] - public void QubitFreeTypes() - { - Assert.Null((Pauli.PauliI as object).GetQubits()); - Assert.Null((OperationFunctor.Body as object).GetQubits()); - - var x1 = new QRange(0, 1); - Assert.Null((x1 as object).GetQubits()); - - var tpl1 = (1, 1, (1.2, new QRange(0, 1))); - Assert.Null((tpl1 as object).GetQubits()); - - var tpl2 = (1, new int[] { 1, 2 }); - Assert.Null((tpl2 as object).GetQubits()); - - var tpl3 = (1, 1, 1); - Assert.Null((tpl3 as object).GetQubits()); - - var tpl4 = (1, 1, 1, 1); - Assert.Null((tpl4 as object).GetQubits()); - - var tpl5 = (1, 1, 1, 1, 1); - Assert.Null((tpl5 as object).GetQubits()); - - var tpl6 = (1, 1, 1, 1, 1, 1); - Assert.Null((tpl6 as object).GetQubits()); - - var tpl7 = (1, 1, 1, 1, 1, 1, 1); - Assert.Null((tpl7 as object).GetQubits()); - - var tpl8 = (1, 1, 1, 1, 1, 1, 1, 1); - Assert.Null((tpl8 as object).GetQubits()); - - var tpl9 = (1, 1, 1, 1, 1, 1, 1, 1, 1); - Assert.Null((tpl9 as object).GetQubits()); - - var e1 = new int[][] { new int[] { 1 }, new int[] { 2, 3 } }; - Assert.Null((e1 as object).GetQubits()); - } - - static IQArray FreeQubitsRange(int start, int length) - { - var ids = Enumerable.Range(start, length); - return new QArray(ids.Select(id => new FreeQubit(id))); - } - - static IQArray<(T, Qubit)> FreeQubitsTuplesRange(int start, int length) - { - var ids = Enumerable.Range(start, length); - var items = ids.Select(id => (default(T), (Qubit) new FreeQubit(id))); - return new QArray<(T, Qubit)>(items); - } - - [Fact] - public void TypesWithQubits() - { - var tpl2 = (new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(2, GetQubitsCount(tpl2)); - - var tpl3 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(3, GetQubitsCount(tpl3)); - - var tpl4 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(4, GetQubitsCount(tpl4)); - - var tpl5 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(5, GetQubitsCount(tpl5)); - - var tpl6 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(6, GetQubitsCount(tpl6)); - - var tpl7 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(7, GetQubitsCount(tpl7)); - - var tpl8 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(8, GetQubitsCount(tpl8)); - - var tpl9 = (new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0), new FreeQubit(0)); - Assert.Equal(9, GetQubitsCount(tpl9)); - - var rng2 = FreeQubitsTuplesRange<(int, int, double)>(0, 10); - Assert.Equal(rng2.Length, GetQubitsCount(rng2)); - - var rng5 = FreeQubitsRange(0, 10); - Assert.Equal(rng5.Length, GetQubitsCount(rng5)); - } - - void AssertAllFunctorsHaveNoQubitsCaptured(IUnitary op) - { - var AssertNullOrEmpty = new System.Action((qubits) => - { - Assert.True(qubits == null || qubits.Length == 0); - }); - - AssertNullOrEmpty(op.GetQubits()?.ToArray()); - AssertNullOrEmpty(op.Controlled.GetQubits()?.ToArray()); - AssertNullOrEmpty(op.Adjoint.GetQubits()?.ToArray()); - AssertNullOrEmpty(op.Controlled.Adjoint.GetQubits()?.ToArray()); - } - - void AssertAllFunctorsHaveQubitsCaptured(IUnitary op, int numberOfQubits) - { - Assert.Equal(numberOfQubits, GetQubitsCount(op)); - Assert.Equal(numberOfQubits, GetQubitsCount(op.Controlled)); - Assert.Equal(numberOfQubits, GetQubitsCount(op.Adjoint)); - Assert.Equal(numberOfQubits, GetQubitsCount(op.Adjoint.Controlled)); - } - - [Fact] - public void TypesWithClosures() - { - { - var op1 = new UnitaryNoOp<(int, int, int)>() as IUnitary<(int, int, int)>; - var partialOp1 = op1.Partial((AbstractCallable._, AbstractCallable._, 3)); - var partialOp3 = partialOp1.Partial((AbstractCallable._, 3)); - - AssertAllFunctorsHaveNoQubitsCaptured(partialOp1); - AssertAllFunctorsHaveNoQubitsCaptured(partialOp3); - AssertAllFunctorsHaveNoQubitsCaptured(op1); - } - { - var op2 = new UnitaryNoOp<(int, int, Qubit)>() as IUnitary<(int, int, Qubit)>; - var partialOp2 = op2.Partial((AbstractCallable._, AbstractCallable._, new FreeQubit(0))); - - AssertAllFunctorsHaveQubitsCaptured(partialOp2, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op2); - } - { - var op3 = new UnitaryNoOp<(int, Qubit, Qubit)>() as IUnitary<(int, Qubit, Qubit)>; - var partialOp4 = op3.Partial((AbstractCallable._, AbstractCallable._, new FreeQubit(0))); - - AssertAllFunctorsHaveQubitsCaptured(partialOp4, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op3); - - var partialOp5 = partialOp4.Partial((AbstractCallable._, new FreeQubit(1))); - AssertAllFunctorsHaveQubitsCaptured(partialOp5, 2); - } - { - var _ = AbstractCallable._; - var q0 = new FreeQubit(0); - var q1 = new FreeQubit(1); - var q2 = new FreeQubit(2); - var q3 = new FreeQubit(3); - var q4 = new FreeQubit(4); - var q5 = new FreeQubit(5); - var qArray = new QArray(q4, q5); - - var op = new UnitaryNoOp<(int, (Qubit, Qubit, Qubit), QArray)>() as IUnitary<(int, (Qubit, Qubit, Qubit), QArray)>; - var p1 = op.Partial((_, (_, q1, _), _)); - - AssertAllFunctorsHaveQubitsCaptured(p1, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op); - - var p2 = p1.Partial((_, _, qArray)); - AssertAllFunctorsHaveQubitsCaptured(p2, 3); - AssertAllFunctorsHaveQubitsCaptured(p1, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op); - - var p3 = p2.Partial(new Func(q => (2, (q3, q2)))); - AssertAllFunctorsHaveQubitsCaptured(p3, 5); - AssertAllFunctorsHaveQubitsCaptured(p2, 3); - AssertAllFunctorsHaveQubitsCaptured(p1, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op); - } - } - - [Fact] - public void GenericTypesWithClosures() - { - var _ = AbstractCallable._; - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - var q3 = new FreeQubit(3) as Qubit; - var q4 = new FreeQubit(4) as Qubit; - var q5 = new FreeQubit(5) as Qubit; - var qArray = new QArray(q4, q5); - - { - var op1 = new GenericCallable(null, typeof(UnitaryNoOp<(int, int, int)>)); - var partialOp1 = op1.Partial((AbstractCallable._, AbstractCallable._, 3)); - var partialOp3 = partialOp1.Partial((AbstractCallable._, 3)); - - AssertAllFunctorsHaveNoQubitsCaptured(partialOp1); - AssertAllFunctorsHaveNoQubitsCaptured(partialOp3); - AssertAllFunctorsHaveNoQubitsCaptured(op1); - } - { - var op2 = new GenericCallable(null, typeof(UnitaryNoOp<(int, int, Qubit)>)) as IUnitary; - var partialOp2 = op2.Partial((AbstractCallable._, AbstractCallable._, q0)); - - AssertAllFunctorsHaveQubitsCaptured(partialOp2, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op2); - AssertIDataQubits(partialOp2, q0); - } - { - var op3 = new GenericCallable(null, typeof(UnitaryNoOp<(int, Qubit, Qubit)>)) as IUnitary; - var partialOp4 = op3.Partial((AbstractCallable._, AbstractCallable._, q0)); - - AssertAllFunctorsHaveQubitsCaptured(partialOp4, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op3); - AssertIDataQubits(partialOp4, q0); - - var partialOp5 = partialOp4.Partial((AbstractCallable._, q1)); - AssertAllFunctorsHaveQubitsCaptured(partialOp5, 2); - AssertIDataQubits(partialOp5, q1, q0); - } - { - var op = new GenericCallable(null, typeof(UnitaryNoOp<(int, (Qubit, Qubit, Qubit), QArray)>)) as IUnitary; - var p1 = op.Partial((_, (_, q1, _), _)); - - AssertAllFunctorsHaveQubitsCaptured(p1, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op); - AssertIDataQubits(p1, q1); - - var p2 = p1.Partial((_, _, qArray)); - AssertAllFunctorsHaveQubitsCaptured(p2, 3); - AssertAllFunctorsHaveQubitsCaptured(p1, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op); - AssertIDataQubits(p1, q1); - AssertIDataQubits(p2, q4, q5, q1); - - var p3 = p2.Partial(new Func(q => (2, (q3, q2)))); - AssertAllFunctorsHaveQubitsCaptured(p3, 5); - AssertAllFunctorsHaveQubitsCaptured(p2, 3); - AssertAllFunctorsHaveQubitsCaptured(p1, 1); - AssertAllFunctorsHaveNoQubitsCaptured(op); - AssertIDataQubits(p1, q1); - AssertIDataQubits(p2, q4, q5, q1); - AssertIDataQubits(p3, q3, q2, q4, q5, q1); - } - } - - [Fact] - public void UdtTypesWithClosures() - { - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - - var op = new UnitaryNoOp<(TupleA,TupleD)>() as IUnitary<(TupleA, TupleD)>; - var p1 = op.Partial((AbstractCallable._, new TupleD(new QArray(q1, q0)))); - - var f0 = new TupleF(op); - var f1 = new TupleF(p1); - - AssertAllFunctorsHaveQubitsCaptured(f1.Data, 2); - AssertAllFunctorsHaveNoQubitsCaptured(f0.Data); - AssertIDataQubits(f1, q1, q0); - - var p1a = f0.Data.Partial(new Func<(long, TupleD), (TupleA, TupleD)>((arg) => (new TupleA((arg.Item1, Pauli.PauliZ, q2, (q0, 4L, q0))), arg.Item2))); - AssertAllFunctorsHaveQubitsCaptured(p1a, 3); - AssertIDataQubits(p1a, q2, q0, q0); - - var p2 = p1.Partial(new Func<(long, (Pauli, Qubit)), TupleA>((arg) => new TupleA((arg.Item1, arg.Item2.Item1, arg.Item2.Item2, (q1, 5L, q2))))); - var p2a = p1a.Partial(new Func(arg => (arg, new TupleD(new QArray(q1, q1))))); - var f2 = new TupleF(p2); - AssertAllFunctorsHaveQubitsCaptured(f2.Data, 5); - AssertIDataQubits(f2, null, q1, q2, q1, q0); - AssertAllFunctorsHaveQubitsCaptured(p2a, 5); - AssertIDataQubits(p2a, q2, q0, q0, q1, q1); - } - - [Fact] - public void QubitsFromUDTs() - { - var q0 = new FreeQubit(0); - var q1 = new FreeQubit(1); - var q2 = new FreeQubit(2); - var q3 = new FreeQubit(3); - var q4 = new FreeQubit(4); - var q5 = new FreeQubit(5); - var q6 = new FreeQubit(6); - var op = new UnitaryNoOp() as IUnitary; - - var qubits = new QArray(q2, q4, q6); - var bData = ((1L, 2L), (q1, (3L, (q2, q3)), 3.5)); - var qtuple = new QTuple<((Int64, Int64), (Qubit, (Int64, (Qubit, Qubit)), Double))>(bData) as IApplyData; - var tupleB = new TupleB(((1L, 2L), (q6, (3L, (q4, q6)), 3.5))); - var tupleA = new TupleA((1L, Pauli.PauliY, q1, (q4, 3L, q5))); - var tupleC = new TupleC((q5, tupleB)); - var tupleD = new TupleD(new QArray(q1, q2, q3, q4, q6)); - var tupleE = new TupleE((1L, new QArray(q1, q3, q4, q6))); - var tupleF = new TupleF(op); - var tupleG = new TupleG((q3, tupleF, tupleC, tupleD)); - var tupleH = new TupleH((tupleD, tupleG)); - var tupleJ = new TupleJ(new QArray<(long, Qubit)>((1L, q1), (2L, q2), (5L, q5), (3L, q3))); - var tupleU = new QTuple(null); - var q = new Q(q3); - - AssertEnumerable(new Qubit[] { q2 }, q2.Qubits); - AssertEnumerable(new Qubit[] { q1, q2, q3 }, qtuple.Qubits); - - AssertIDataQubits(q2, q2); - AssertIDataQubits(qtuple, q1, q2, q3); - AssertIDataQubits(tupleA, q1, q4, q5); - AssertIDataQubits(tupleB, q6, q4, q6); - AssertIDataQubits(tupleC, q5, q6, q4, q6); - AssertIDataQubits(tupleD, q1, q2, q3, q4, q6); - AssertIDataQubits(tupleE, q1, q3, q4, q6); - AssertIDataQubits(tupleF, null); - AssertIDataQubits(tupleG, q3, q5, q6, q4, q6, q1, q2, q3, q4, q6); - AssertIDataQubits(tupleH, q1, q2, q3, q4, q6, q3, q5, q6, q4, q6, q1, q2, q3, q4, q6); - AssertIDataQubits(tupleJ, q1, q2, q5, q3); - AssertIDataQubits(q, q3); - AssertIDataQubits(tupleU, null); - } - - private static void AssertEnumerable(IEnumerable e, IEnumerable a) - { - if (e == null) - { - Assert.Null(a); - } - else - { - var expected = e.ToArray(); - var actual = a.ToArray(); - - Assert.Equal(expected.Length, actual.Length); - for (int i = 0; i < expected.Length; i++) - { - Assert.Equal(expected[i], actual[i]); - } - } - } - - private static void AssertIDataQubits(IApplyData d, params Qubit[] expected) - { - AssertEnumerable(expected, d.Qubits); - } - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs b/src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs deleted file mode 100644 index 14dd8afa22a..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/NativeOperationsTests.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; - -using Microsoft.Quantum.Simulation.Core; - -using NativeOperations; - -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class NativeOperationTests - { - [Fact] - public void NativeIntrinsicOperation() - { - OperationsTestHelper.RunWithMultipleSimulators((sim) => - { - var actual = IntrinsicBody.Run(sim).Result; - Assert.Equal(IntrinsicBody.RESULT, actual); - }); - } - - [Fact] - public void NativeOperationWithSimulatorSpecificEmulation() - { - void TestOne(IOperationFactory sim, string expected) - { - var actual = DefaultBody.Run(sim).Result; - Assert.Equal(expected, actual); - - if (sim is IDisposable dis) dis.Dispose(); - } - - TestOne(new QuantumSimulator(), "Simulator"); - } - - [Fact] - public void NativeIntrinsicGenericOperation() - { - OperationsTestHelper.RunWithMultipleSimulators((sim) => - { - var actual = IntrinsicBodyGeneric.Run(sim, "hello").Result; - Assert.Equal(IntrinsicBody.RESULT, actual); - - actual = IntrinsicBodyGeneric.Run(sim, 1234).Result; - Assert.Equal("1234", actual); - }); - } - - - [Fact] - public void NativeGenericOperation() - { - OperationsTestHelper.RunWithMultipleSimulators((sim) => - { - var actual1 = DefaultBodyGeneric.Run(sim, "hello").Result; - Assert.Equal(IntrinsicBody.RESULT, actual1); - - var actual2 = DefaultBodyGeneric.Run(sim, 1234).Result; - Assert.Equal(1234, actual2); - }); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs index 5be7b17b8fa..b1dfbd7ae70 100644 --- a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs +++ b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs @@ -14,6 +14,18 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests { + public static class Extensions + { + /// + /// This method is a wrapper to let the tests keep using a one Type parameter + /// method to fetch for Gates. + /// + public static T Get(this SimulatorBase sim) where T : AbstractCallable + { + return sim.Get(); + } + } + public class Log { public Dictionary _log = new Dictionary(); @@ -90,48 +102,9 @@ private void OnStart(ICallable arg1, IApplyData arg2) static class OperationsTestHelper { - public static TraceImpl GetTracer(this SimulatorBase s) - { - return s.Get(typeof(Tests.Circuits.Generics.Trace<>)).FindCallable(typeof(T), typeof(QVoid)) as TraceImpl; - } - - - public class TracerImpl : Tests.Circuits.ClosedType.Trace - { - public TracerImpl(IOperationFactory m) : base(m) - { - this.Log = new Log(); - } - - public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); - public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); - public override Func<(IQArray, string), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); - public override Func<(IQArray, string), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); - - public Log Log { get; } - } - - public class TraceImpl : Tests.Circuits.Generics.Trace - { - public TraceImpl(IOperationFactory m) : base(m) - { - this.Log = new Log(); - } - - public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); - public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); - public override Func<(IQArray, T), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); - public override Func<(IQArray, T), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); - - public int GetNumberOfCalls(OperationFunctor functor, T tag) => this.Log.GetNumberOfCalls(functor, tag); - - public Log Log { get; } - } - private static void InitSimulator(SimulatorBase sim) { sim.InitBuiltinOperations(typeof(OperationsTestHelper)); - sim.Register(typeof(Tests.Circuits.Generics.Trace<>), typeof(TraceImpl<>), typeof(IUnitary)); } public static void RunWithMultipleSimulators(Action test) @@ -189,7 +162,7 @@ internal static void ctrlTestShell(SimulatorBase sim, Action<(IQArray, Qu { var allocate = sim.Get(); var release = sim.Get(); - var set = sim.Get(); + var set = sim.Get(); // Number of control bits to use for (int n = 0; n < 4; n++) diff --git a/src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs b/src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs deleted file mode 100644 index f945357366d..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/PartialMapperTests.cs +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; -using Xunit; -using System.Linq; -using System.Collections.Generic; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - using TestTuple = ValueTuple)), Qubit>; - - public class PartialMapperTests - { - private class NoOp : Unitary, ICallable - { - public NoOp(IOperationFactory m) : base(m) { } - - string ICallable.FullName => "NoOp"; - - public override Func Body => (a) => QVoid.Instance; - - public override void Init() { } - } - - private void TestOneTupleNoSubstitution(I original, params object[] expected) - { - var emptyQueue = new Stack(); - var content = PartialMapper.GetTupleValues(original); - var tuple = PartialMapper.Combine(content, emptyQueue); - Assert.Equal(content, tuple); - } - - [Fact] - public void TupleNoSubstitutions() // substitutes nothing - { - Qubit qubit = null; - QArray qubits = new QArray(); - IUnitary op = new NoOp(null); - - TestOneTupleNoSubstitution(QVoid.Instance); - TestOneTupleNoSubstitution(1L, 1L); - TestOneTupleNoSubstitution(qubit, qubit); - TestOneTupleNoSubstitution(qubits, qubits); - TestOneTupleNoSubstitution((1L, 2.0), 1L, 2.0); - TestOneTupleNoSubstitution((1L, 2.0, Result.Zero), 1L, 2.0, Result.Zero); - TestOneTupleNoSubstitution(((1L, 2.0), Result.Zero), 1L, 2.0, Result.Zero); - TestOneTupleNoSubstitution(((1L, 2.0), (Result.Zero, qubit, qubits)), 1L, 2.0, Result.Zero, qubit, qubits); - TestOneTupleNoSubstitution(((op, 4L, (1L, 2.0)), (Result.Zero, (op, qubits, qubit))), op, 4L, 1L, 2.0, Result.Zero, op, qubits, qubit); - } - - private void TestOneMapping(I expected, A args, object values) - { - var partial = PartialMapper.Create(values); - var actual = partial(args); - Assert.Equal(expected, actual); - } - - [Fact] - public void PartialMapping() - { - Qubit qubit = null; - QArray qubits = new QArray(); - NoOp op = new NoOp(null); - - var _ = AbstractCallable._; - - TestOneMapping(1, 1, _); - TestOneMapping(op, op, _); - TestOneMapping(qubit, qubit, _); - TestOneMapping(QVoid.Instance, QVoid.Instance, _); - TestOneMapping(1, QVoid.Instance, 1); - TestOneMapping((1, op), op, (1, _)); - TestOneMapping((qubit, op), qubit, (_, op)); - TestOneMapping((qubit, op), (qubit, op), (_, _)); - TestOneMapping((qubit, op), (qubit, op), _); - TestOneMapping((Result.One, 2.0, 3, qubit, op), (3, op), (Result.One, 2.0, _, qubit, _)); - - var expected = (Result.One, (1, 2.0), (3, (op, qubits)), qubit); - TestOneMapping(expected, QVoid.Instance, (Result.One, (1, 2.0), (3, (op, qubits)), qubit)); - TestOneMapping(expected, Result.One, (_, (1, 2.0), (3, (op, qubits)), qubit)); - TestOneMapping(expected, (Result.One, (1, 2.0)), (_, _, (3, (op, qubits)), qubit)); - TestOneMapping(expected, (Result.One, (3, (op, qubits))), (_, (1, 2.0), _, qubit)); - TestOneMapping(expected, (Result.One, qubit), (_, (1, 2.0), (3, (op, qubits)), _)); - TestOneMapping(expected, qubit, (Result.One, (1, 2.0), (3, (op, qubits)), _)); - TestOneMapping(expected, (1, 2.0), (Result.One, _, (3, (op, qubits)), qubit)); - TestOneMapping(expected, ((1, 2.0), qubit), (Result.One, _, (3, (op, qubits)), _)); - TestOneMapping(expected, (3, (op, qubits)), (Result.One, (1, 2.0), _, qubit)); - TestOneMapping(expected, ((1, 2.0), (3, (op, qubits))), (Result.One, _, _, qubit)); - TestOneMapping(expected, 2.0, (Result.One, (1, _), (3, (op, qubits)), qubit)); - TestOneMapping(expected, (Result.One, 2.0, op), (_, (1, _), (3, (_, qubits)), qubit)); - TestOneMapping(expected, ((1, 2.0), (3, qubits)), (Result.One, _, (_, (op, _)), qubit)); - TestOneMapping(expected, expected, (_, _, _, _)); - TestOneMapping((expected, expected), expected, (expected, _)); - TestOneMapping((1, 2, (3, 4)), (2, 4), (1, _, (3, _))); - TestOneMapping((1, (2.1,2.2), (3, 4)), ((2.1,2.2), 4), (1, _, (3, _))); - TestOneMapping((1, (2.1, 2.2), (3, (4.1,4.2))), ((2.1, 2.2), (4.1,4.2)), (1, _, (3, _))); - } - - private void TestOnePartialType(Type expected, Type original, object partial) - { - var actual = Operation.FindPartialType(original, partial); - Assert.Equal(expected, actual); - } - - [Fact] - public void FindPartialType() - { - Qubit qubit = new TestQubit(); - QArray qubits = new QArray(); - IUnitary op = new NoOp(null); - - var _ = AbstractCallable._; - - TestOnePartialType(typeof(QVoid), typeof(long), 1L); - TestOnePartialType(typeof(long), typeof(long), _); - TestOnePartialType(typeof(IUnitary), typeof(IUnitary), _); - TestOnePartialType(typeof(Qubit), typeof(TestQubit), _); - TestOnePartialType(typeof(QVoid), typeof(QVoid), _); - - TestOnePartialType(typeof(IUnitary), (1, op).GetType(), (1, _)); - TestOnePartialType(typeof(Qubit), (qubit, op).GetType(), (_, op)); - - TestOnePartialType(typeof(ValueTuple), (qubit, op).GetType(), (_, _)); - TestOnePartialType(typeof(IUnitary), (qubit, op).GetType(), (qubit, _)); - TestOnePartialType(typeof(Qubit), (qubit, 1L, op).GetType(), (_, 1L, op)); - TestOnePartialType(typeof(ValueTuple), (Result.One, 2.0, 3L, qubit, op).GetType(), (Result.One, 2.0, _, qubit, _)); - - var original = (Result.One, (1L, 2.0), (3L, (op, qubits))); - TestOnePartialType(typeof(QVoid), original.GetType(), (Result.One, (1L, 2.0), (3L, (op, qubits)))); - TestOnePartialType(typeof(Result), original.GetType(), (_, (1L, 2.0), (3L, (op, qubits)))); - TestOnePartialType(typeof(ValueTuple), original.GetType(), (_, (_, 2.0), (_, (op, qubits)))); - TestOnePartialType(typeof(ValueTuple), original.GetType(), (Result.One, _, (3L, (op, qubits)))); - TestOnePartialType(typeof(ValueTuple), original.GetType(), (Result.One, (_, _), (3L, (op, qubits)))); - TestOnePartialType(typeof(ValueTuple>), original.GetType(), (Result.One, (1L, 2.0), (_, (op, _)))); - TestOnePartialType(typeof(ValueTuple>), original.GetType(), (_, (1L, 2.0), (_, (_, qubits)))); - } - - private void TestOneMappingError(A args, object values) where E : Exception - { - var partial = PartialMapper.Create(values); - Assert.Throws(() => partial(args)); - } - - [Fact] - public void PartialMappingErrors() - { - Qubit qubit = null; - QArray qubits = new QArray(); - NoOp op = new NoOp(null); - - var _ = AbstractCallable._; - var expected = (Result.One, (1, 2.0), (3, (op, qubits)), qubit); - - OperationsTestHelper.IgnoreDebugAssert(() => - { - // If too many parameters, are ignored: - TestOneMapping(expected, Result.One, (Result.One, (1, 2.0), (3, (op, qubits)), qubit)); - - // Parameters mismatch - TestOneMappingError((2.0, 3.0), (Result.One, _, (3, (op, qubits)), qubit)); - TestOneMappingError(1, (_, (1, 2.0), (3, (op, qubits)), qubit)); - TestOneMappingError(1, (Result.One, _, (3, (op, qubits)), qubit)); - //TestOneMapping((1, 2, (3, 4)), (2, 4), (1, new MissingParameter(typeof((int,int))), (3, _))); - - // Too little parameters - TestOneMappingError(Result.One, (_, _, (3, (op, qubits)), qubit)); - - // Both, parameters mismatch and too little parameters - TestOneMappingError(1, (_, _, (3, (op, qubits)), qubit)); - }); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs b/src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs deleted file mode 100644 index e62a5c102e6..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/PrimitivesExtensionsTests.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -using Microsoft.Quantum.Simulation.Core; - -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class PrimitivesExtensionsTests - { - [Fact] - void AllExtensionsAreImplementedTest() - { - TestExtension("Core"); - TestExtension("Math"); - TestExtension("Convert"); - TestExtension("Bitwise"); - } - - private static void TestExtension(string extensionName) - { - Assembly assembly = Assembly.Load("Microsoft.Quantum.QSharp.Core"); - string extensionsNameSpace = "Microsoft.Quantum." + extensionName; - - IEnumerable abstractTypes = - from opType in assembly.DefinedTypes - where opType.Namespace == extensionsNameSpace - where typeof(AbstractCallable).IsAssignableFrom(opType) - where !opType.IsNested - select opType; - - foreach (Type one in abstractTypes) - { - var t = one.IsGenericType - ? one.MakeGenericType(Enumerable.Repeat(typeof(string), one.GetGenericArguments().Length).ToArray()) - : one; - if (t.IsAbstract) - { - Assert.True(t.GetNativeImplementation() != null, $"{one.Name} missing Native implementation."); - } - } - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/QArrayTests.cs b/src/Simulation/Simulators.Type2.Tests/QArrayTests.cs deleted file mode 100644 index 4be981b34a1..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QArrayTests.cs +++ /dev/null @@ -1,315 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections; -using System.Diagnostics; -using Microsoft.Quantum.Simulation.Core; -using Newtonsoft.Json; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class QArrayTests - { - [Fact] - public void CreateArrayWithDefaults() - { - var actual = new QArray(new Qubit[0]); - Assert.Empty(actual); - - actual = new QArray(new Qubit[1]); - Assert.Single(actual); - Assert.Null(actual[0]); - - actual = new QArray(new Qubit[5]); - Assert.Equal(5, actual.Length); - Assert.Null(actual[0]); - Assert.Null(actual[1]); - Assert.Null(actual[2]); - Assert.Null(actual[3]); - Assert.Null(actual[4]); - - var longs = new QArray(new long[0]); - Assert.Empty(longs); - - longs = new QArray(new long[3]); - Assert.Equal(3, longs.Length); - Assert.Equal(0, longs[0]); - Assert.Equal(0, longs[1]); - Assert.Equal(0, longs[2]); - - var ops = new QArray(new ICallable[2]); - Assert.Equal(2, ops.Length); - Assert.Null(ops[0]); - Assert.Null(ops[1]); - } - - private void Wrapper(long count) - { - var array = new QArray(new T[count]); - Assert.Equal(count, array.Length); - } - - [Fact] - public void CreateArrayWithGenerics() - { - Wrapper(3); - Wrapper(4); - } - - [Fact] - public void ArraysByIndex() - { - var longs = new QArray (2, 1, 0); - Assert.NotEmpty(longs); - Assert.Equal(3, longs.Length); - Assert.Equal(2, longs[0]); - Assert.Equal(1, longs[1]); - Assert.Equal(0, longs[2]); - - longs = new QArray(new long[5]); - longs.Modify(0, 5); - longs.Modify(2, 3); - longs.Modify(4, 1); - Assert.Equal(5, longs.Length); - Assert.Equal(5, longs[0]); - Assert.Equal(0, longs[1]); - Assert.Equal(3, longs[2]); - Assert.Equal(0, longs[3]); - Assert.Equal(1, longs[4]); - - OperationsTestHelper.IgnoreDebugAssert(() => - { - // Make sure we can call it with a long index: - Assert.Throws(() => longs[-1]); - Assert.Throws(() => longs[int.MaxValue]); - Assert.Throws(() => longs[(long)int.MaxValue + 1]); - }); - } - - [Fact] - public void JoinArrays() - { - var arr1 = new QArray(); - var arr2 = new QArray(); - var expected = new QArray(); - var actual = QArray.Add(arr1, arr2); - Assert.Equal(expected, actual); - - arr1 = new QArray(1); - arr2 = new QArray(); - expected = new QArray(1); - actual = QArray.Add(arr1, arr2); - Assert.Equal(expected, actual); - - arr1 = new QArray(); - arr2 = new QArray(1); - expected = new QArray(1); - actual = QArray.Add(arr1, arr2); - Assert.Equal(expected, actual); - - arr1 = new QArray(1, 2, 3); - arr2 = new QArray(1, 4, 5, 3, 6); - expected = new QArray(1, 2, 3, 1, 4, 5, 3, 6); - actual = QArray.Add(arr1, arr2); - Assert.Equal(expected, actual); - - OperationsTestHelper.IgnoreDebugAssert(() => - { - arr1 = null; - arr2 = new QArray(1, 4, 5, 3, 6); - expected = new QArray(1, 4, 5, 3, 6); - actual = QArray.Add(arr1, arr2); - Assert.Equal(expected, actual); - - arr1 = new QArray(1, 2, 3); - arr2 = null; - expected = new QArray(1, 2, 3); - actual = QArray.Add(arr1, arr2); - Assert.Equal(expected, actual); - - arr1 = null; - arr2 = null; - expected = null; - actual = QArray.Add(arr1, arr2); - Assert.Equal(expected, actual); - }); - } - - [Fact] - public void SliceArray() - { - var source = new QArray(0); - var range = new QRange(0, 0); - var expected = new QArray(0); - var actual = source.Slice(range); - Assert.Equal(expected, actual); - - source = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - range = new QRange(0, 2, 10); - expected = new QArray(0, 2, 4, 6, 8, 10); - actual = source.Slice(range); - Assert.Equal(expected, actual); - - - source = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - expected = new QArray(1, 6); - actual = source.Slice(new QRange(1, 5, 10)); - Assert.Equal(expected, actual); - - OperationsTestHelper.IgnoreDebugAssert(() => - { - source = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - range = null; - expected = new QArray(); - actual = source.Slice(range); - Assert.Equal(expected, actual); - }); - } - - [Fact] - public void ArraySharing() - { - // Basic copy-on-write - var array1 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); - var array2 = new QArray(array1); - Assert.Equal(2, array1[2]); - Assert.Equal(2, array2[2]); - array1.Modify(2, 12); - Assert.Equal(12, array1[2]); - Assert.Equal(2, array2[2]); - array2.Modify(2, 22); - Assert.Equal(12, array1[2]); - Assert.Equal(22, array2[2]); - - // Arrays of arrays - array1 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); - array2 = new QArray(array1); - var arrayArray1 = new QArray>(array1, array2); // in generated C# code, QArray> is used - var arrayArray2 = new QArray>(arrayArray1); - Assert.Equal(2, arrayArray1[0][2]); - Assert.Equal(2, arrayArray1[1][2]); - arrayArray1.Modify(0, arrayArray1[0].Modify(2, 12)); - Assert.Equal(12, arrayArray1[0][2]); - Assert.Equal(2, arrayArray1[1][2]); - Assert.Equal(12, array1[2]); - arrayArray1.Modify(1, arrayArray1[1].Modify(2, 22)); - Assert.Equal(12, arrayArray1[0][2]); - Assert.Equal(22, arrayArray1[1][2]); - Assert.Equal(12, array1[2]); - Assert.Equal(22, array2[2]); - - // Copy-on-write with slices - var r = new QRange(1, 2, 10); - var array3 = array2.Slice(r); - var expected = new QArray(1, 3, 5, 7, 9); - Assert.Equal(expected, array3); - array3.Modify(0, 11); - Assert.Equal(1, array2[1]); - Assert.Equal(11, array3[0]); - - // Mixing slicing and joining - array2 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); - var expected2 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); - r = new QRange(1, 2, 10); - array3 = array2.Slice(r); - var array4 = new QArray(11, 13); - var array5 = QArray.Add(array3, array4); - var expected3 = new QArray(1, 3, 5, 7, 9); - var expected4 = new QArray(11, 13); - var expected5 = new QArray(1, 3, 5, 7, 9, 11, 13); - Assert.Equal(expected2, array2); - Assert.Equal(expected3, array3); - Assert.Equal(expected4, array4); - Assert.Equal(expected5, array5); - - // Self-joining - array1 = new QArray(0, 1, 2); - array2 = new QArray(QArray.Add(array1, array1)); - var expected1 = new QArray(0, 1, 2); - expected2 = new QArray(0, 1, 2, 0, 1, 2); - Assert.Equal(expected1, array1); - Assert.Equal(expected2, array2); - array1.Modify(0, 10); - Assert.Equal(10, array1[0]); - Assert.Equal(0, array2[0]); - } - - [Fact] - public void ArrayEnumeration() - { - // Basic enumeration - var array1 = new QArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); - int index = 0; - foreach (var n in array1) - { - Assert.Equal(index, n); - index++; - } - Assert.Equal(10, index); - - // Enumerating a slice - var r = new QRange(1, 2, 10); - var array2 = array1.Slice(r); - index = 1; - foreach (var n in array2) - { - Assert.Equal(index, n); - index += 2; - } - Assert.Equal(11, index); - - // Enumerating a join - var array3 = QArray.Add(array1, array2); - index = 0; - foreach (var n in array3) - { - if (index < 10) - { - Assert.Equal(index, n); - } - else - { - Assert.Equal(2 * index - 19, n); - } - index++; - } - Assert.Equal(15, index); - } - - [Fact] - public void CastArrays() - { - // Basic enumeration - var array1 = new QArray(1L, 2L, 3L); - var array2 = new QArray(array1); - - Assert.Equal(array1.Length, array2.Length); - Assert.Equal((long)array1[0], array2[0]); - Assert.Equal((long)array1[2], array2[2]); - } - - [Fact] - public void IQArraySerialization() - { - // Basic enumeration - var array1 = new QArray(1L, 2L, 3L) as IQArray; - var json = JsonConvert.SerializeObject(array1); - Assert.Equal("[1,2,3]", json); - - var array2 = JsonConvert.DeserializeObject>(json); - var array3 = JsonConvert.DeserializeObject>(json); - Assert.Equal(array1, array2); - Assert.Equal(array1, array3); - - // Results enumeration - var array_result = new QArray(Result.One, Result.Zero, Result.Zero) as IQArray; - json = JsonConvert.SerializeObject(array_result); - Assert.Equal("[1,0,0]", json); - - var array_from_json = JsonConvert.DeserializeObject>(json); - Assert.Equal(array_result, array_from_json); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/QTupleTests.cs b/src/Simulation/Simulators.Type2.Tests/QTupleTests.cs deleted file mode 100644 index 0f5501b8a3b..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QTupleTests.cs +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Core; -using System; -using System.Linq; -using Xunit; -using Microsoft.Quantum.Tests.Tuples; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class QTupleTests - { - [Fact] - public void TupleEmptyConstructor() - { - var NullOrEmptyQubits = new Action((t) => - { - var qubits = t.Qubits; - Assert.True(qubits == null || qubits?.Where(q => q != null).Count() == 0); - }); - - { - var actual = new Q(); - Assert.Null(((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new I(); - Assert.Equal(0L, ((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleA(); - Assert.Equal(default((Int64, Pauli, Qubit, (Qubit, Int64, Qubit))), ((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleC(); - Assert.Equal(default((Qubit, TupleB)), ((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleD(); - Assert.Empty(((IApplyData)actual).Value as IQArray); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleE(); - Assert.Equal(default((Int64, IQArray)), ((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleF(); - Assert.Null(((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleH(); - Assert.Equal(default((TupleD, TupleG)), ((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleI(); - Assert.Null(((IApplyData)actual).Value); - NullOrEmptyQubits(actual); - } - { - var actual = new TupleJ(); - Assert.Empty(((IApplyData)actual).Value as IQArray<(Int64,Qubit)>); - NullOrEmptyQubits(actual); - } - } - - [Fact] - public void TupleBasicConstructor() - { - var AssertQubitsCount = new Action((count, t) => - { - var qubits = t.Qubits; - if (count == 0) - { - Assert.True(qubits == null || qubits?.Where(q => q != null).Count() == 0); - } else - { - Assert.Equal(count, qubits?.Where(q => q != null).Count()); - } - }); - - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - - { - var actual = new Q(q0); - Assert.Equal(q0, ((IApplyData)actual).Value); - AssertQubitsCount(1, actual); - } - { - var actual = new I(32L); - Assert.Equal(32L, ((IApplyData)actual).Value); - AssertQubitsCount(0, actual); - } - { - var data = (2L, Pauli.PauliY, q1, (q0, -7L, null as Qubit)); - var actual = new TupleA(data); - Assert.Equal(data, ((IApplyData)actual).Value); - AssertQubitsCount(2, actual); - } - { - var data = (q1, new TupleB(((2L, 3L), (q1, (4L, (q0, q2)), 3.0)))); - var actual = new TupleC(data); - Assert.Equal(data, ((IApplyData)actual).Value); - AssertQubitsCount(4, actual); - } - { - var data = new QArray(q1, q2, q0, q0, q1); - var actual = new TupleD(data); - Assert.Equal((IQArray)data, ((IApplyData)actual).Value); - AssertQubitsCount(5, actual); - } - { - var data = (5L, new QArray(q1, q2, q0)); - var actual = new TupleE(data); - Assert.Equal((data.Item1, (IQArray)data.Item2), ((IApplyData)actual).Value); - AssertQubitsCount(3, actual); - } - { - var data = new UnitaryNoOp<(TupleA, TupleD)>(); - var actual = new TupleF(data); - Assert.Equal(data, ((IApplyData)actual).Value); - AssertQubitsCount(0, actual); - } - { - var op= new UnitaryNoOp<(TupleA, TupleD)>(); - var mapper = new Func<(TupleA, TupleD), (IQArray, (TupleA, TupleD))>((_arg) => (new QArray(q1, q2), _arg)); - var data = op.Controlled.Partial(mapper); - var actual = new TupleF(data); - Assert.Equal(data, ((IApplyData)actual).Value); - AssertQubitsCount(2, actual); - } - { - var data = (new TupleD(new QArray(q1, q2, q0)), new TupleG()); - var actual = new TupleH(data); - Assert.Equal(data, ((IApplyData)actual).Value); - AssertQubitsCount(3, actual); - } - { - var data = new QArray<(Int64, Qubit)>((1L, q1)); - var actual = new TupleJ(data); - Assert.Equal((IQArray<(Int64, Qubit)>)data, ((IApplyData)actual).Value); - AssertQubitsCount(1, actual); - } - } - - private static void AssertOneData (T expected, Type tupleType) - { - var d = Activator.CreateInstance(tupleType, expected) as IApplyData; - - Assert.NotNull(d); - Assert.Equal(expected, d.Value); - if (d is QTuple tuple) - { - Assert.Equal(expected, tuple.Data); - } - } - - [Fact] - public void UdtData() - { - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - var q3 = new FreeQubit(3) as Qubit; - var q4 = new FreeQubit(4) as Qubit; - var q5 = new FreeQubit(5) as Qubit; - var q6 = new FreeQubit(6) as Qubit; - var op = new Op1(null) as IUnitary; - var f1 = new F1(null); - var qubits = new QArray(q2, q4, q6); - - var dataA = (1L, Pauli.PauliY, q1, (q4, 3L, q5)); - var dataB = ((1L, 2L), (q6, (3L, (q4, q6)), 3.5)); - var dataC = (q5, new TupleB(dataB)); - var dataD = new QArray(q1, q2, q3, q4, q6); - var dataE = (4L, (IQArray)qubits); - var dataF = op; - var dataG = (q3, new TupleF(dataF), new TupleC(dataC), new TupleD(dataD)); - var dataQ = ((1L, 2L), (q1, (3L, (q2, q3)), 3.5)); - var dataH = (new TupleD(dataD), new TupleG(dataG)); - var dataI = f1; - - AssertOneData(dataQ, typeof(QTuple<((Int64, Int64), (Qubit, (Int64, (Qubit, Qubit)), Double))>)); - AssertOneData(((ICallable)null), typeof(QTuple)); - AssertOneData(q3, typeof(Q)); - AssertOneData(dataA, typeof(TupleA)); - AssertOneData(dataB, typeof(TupleB)); - AssertOneData(dataC, typeof(TupleC)); - AssertOneData(dataD, typeof(TupleD)); - AssertOneData(dataE, typeof(TupleE)); - AssertOneData(dataF, typeof(TupleF)); - AssertOneData(dataG, typeof(TupleG)); - AssertOneData(dataH, typeof(TupleH)); - AssertOneData(dataI, typeof(TupleI)); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs index 092106269f0..64bb4ec919c 100644 --- a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs +++ b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators.Exceptions; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; using Xunit; namespace Microsoft.Quantum.Simulation.Simulators.Tests @@ -60,7 +59,7 @@ public void QSimX() { var x = sim.Get(); var measure = sim.Get(); - var set = sim.Get(); + var set = sim.Get(); var ctrlX = x.ControlledBody.AsAction(); OperationsTestHelper.ctrlTestShell(sim, ctrlX, (enabled, ctrls, q) => diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs deleted file mode 100644 index c5852fb1556..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/CircuitsTests.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Quantum.Intrinsic; -using Microsoft.Quantum.Simulation.Core; -using Xunit; -using Microsoft.Quantum.Simulation.XUnit; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public partial class QuantumSimulatorTests - { - [OperationDriver(TestCasePrefix ="QSim", TestNamespace = "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits")] - public void QSimTestTarget( TestOperation op ) - { - using (var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: true)) - { - op.TestOperationRunner(sim); - } - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs deleted file mode 100644 index a267a719274..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/QubitReleaseTest.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Simulators.Exceptions; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public partial class QuantumSimulatorTests - { - //test to check that qubit cannot be released if it is not in zero state - [Fact] - public async Task ZeroStateQubitReleaseTest() - { - var sim = new QuantumSimulator(); - - await Assert.ThrowsAsync(() => UsingQubitCheck.Run(sim)); - } - - //test to check that qubit can be released if measured - [Fact] - public async Task MeasuredQubitReleaseTest() - { - var sim = new QuantumSimulator(); - - //should not throw an exception, as Measured qubits are allowed to be released, and the release aspect is handled in the C++ code - await ReleaseMeasuredQubitCheck.Run(sim); - } - - //test to check that qubit that is released and reallocated is in state |0> - [Fact] - public async Task ReallocateQubitInGroundStateTest() - { - var sim = new QuantumSimulator(); - var allocate = sim.Get(); - var release = sim.Get(); - var q1 = allocate.Apply(1); - var q1Id = q1[0].Id; - var gate = sim.Get(); - var measure = sim.Get(); - gate.Apply(q1[0]); - var result1 = measure.Apply(q1[0]); - //Check X operation - Assert.Equal(result1, Result.One); - release.Apply(q1[0]); - var q2 = allocate.Apply(1); - var q2Id = q2[0].Id; - //Assert reallocated qubit has the same id as the one released - Assert.Equal(q1Id, q2Id); - var result2 = measure.Apply(q2[0]); - //Assert reallocated qubit has is initialized in state |0> - Assert.Equal(result2, Result.Zero); - - - - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs deleted file mode 100644 index 03864b46fd6..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite.cs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.XUnit; -using System; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class QuantumTestSuite - { - private readonly ITestOutputHelper output; - - public QuantumTestSuite(ITestOutputHelper output) - { - this.output = output; - } - - [OperationDriver(TestCasePrefix = "QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite")] - public void QSimTestTarget(TestOperation op) - { - using (var sim = new QuantumSimulator( throwOnReleasingQubitsNotInZeroState: true )) - { - sim.OnLog += (msg) => { output.WriteLine(msg); }; - op.TestOperationRunner(sim); - } - } - - //[OperationDriver(TestCasePrefix = "QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite.VeryLong")] - private void QSimTestTargetVeryLong(TestOperation op) - { - using (var sim = new QuantumSimulator( throwOnReleasingQubitsNotInZeroState: true )) - { - sim.OnLog += (msg) => { output.WriteLine(msg); }; - op.TestOperationRunner(sim); - } - } - - //[OperationDriver(TestCasePrefix = "⊗ Fail QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite", Suffix = "QSimFail")] - [OperationDriver(TestCasePrefix = "⊗ Fail QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite", Suffix = "QSimFail", Skip = "These tests are known to fail" )] - public void QSimTestTargetFailures(TestOperation op) - { - using (var sim = new QuantumSimulator( throwOnReleasingQubitsNotInZeroState: true )) - { - sim.OnLog += (msg) => { output.WriteLine(msg); }; - Action action = () => op.TestOperationRunner(sim); - bool hasThrown = false; - try - { - action.IgnoreDebugAssert(); - } - catch (ExecutionFailException) - { - hasThrown = true; - } - Assert.True(hasThrown, "The operation was known to throw. It does not throw anymore. Congratulations ! You fixed the bug."); - } - } - } - - public class QuantumTestSuiteSelf - { - private readonly ITestOutputHelper output; - public QuantumTestSuiteSelf(ITestOutputHelper output) - { - this.output = output; - } - - [OperationDriver(TestCasePrefix = "QuantumTestSuite:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite.SelfTests")] - public void QuantumTestSuiteSelfTests(TestOperation op) - { - var sim = new TrivialSimulator(); //these tests do not do anything quantum - sim.OnLog += (msg) => { output.WriteLine(msg); }; - op.TestOperationRunner(sim); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs deleted file mode 100644 index f34826ba202..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertEqualInPlace.qs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Intrinsic; - - - /// - /// Test helper to be used with AssertOperationsEqualInPlace and AssertOperationsEqualReferenced - /// if one needs to check that the operation is identity - /// - operation IdentityTestHelper (q : Qubit[]) : Unit { - - body (...) { - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation OnFirstQubit (op : (Qubit => Unit), qubits : Qubit[]) : Unit { - - op(qubits[0]); - } - - - operation OnFirstQubitA (op : (Qubit => Unit : Adjoint), qubits : Qubit[]) : Unit { - - body (...) { - op(qubits[0]); - } - - adjoint invert; - } - - - operation OnFirstQubitAC (op : (Qubit => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { - - body (...) { - op(qubits[0]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation OnSecondQubitAC (op : (Qubit => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { - - body (...) { - op(qubits[1]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation OnFirstTwoQubitsAC (op : ((Qubit, Qubit) => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { - - body (...) { - op(qubits[0], qubits[1]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation OnFirstThreeQubitsAC (op : ((Qubit, Qubit, Qubit) => Unit : Adjoint, Controlled), qubits : Qubit[]) : Unit { - - body (...) { - op(qubits[0], qubits[1], qubits[2]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation OnOneQubit (op : (Qubit[] => Unit), qubit : Qubit) : Unit { - - op([qubit]); - } - - - operation OnOneQubitA (op : (Qubit[] => Unit : Adjoint), qubit : Qubit) : Unit { - - body (...) { - op([qubit]); - } - - adjoint invert; - } - - - operation OnOneQubitAC (op : (Qubit[] => Unit : Adjoint, Controlled), qubit : Qubit) : Unit { - - body (...) { - op([qubit]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs deleted file mode 100644 index e65cd2e0342..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Intrinsic; - - - operation AssertProbAndCliffordOneQubitTest () : Unit { - - let totalQubits = MaxQubitsToAllocateForOneQubitTests(); - - using (qs = Qubit[totalQubits]) { - - for (i in 0 .. totalQubits - 1) { - let targetQubits = [qs[i]]; - AssertProbAndPaulies(targetQubits); - AssertProbAndS(Zero, targetQubits); - AssertProbAndS(One, targetQubits); - - if (IsStabilizerSimulator()) { - AssertProbAndH(Zero, targetQubits); - AssertProbAndH(One, targetQubits); - } - } - } - } - - - operation AssertProbAndPaulies (qs : Qubit[]) : Unit { - - Assert([PauliZ], qs, Zero, $"Newly allocated qubits are always zero"); - X(qs[0]); - Assert([PauliZ], qs, One, $""); - X(qs[0]); - Assert([PauliZ], qs, Zero, $""); - Y(qs[0]); - Assert([PauliZ], qs, One, $""); - Y(qs[0]); - } - - - operation AssertProbAndH (intial : Result, qs : Qubit[]) : Unit { - - - if (intial == One) { - X(qs[0]); - } - - Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); - H(qs[0]); - Assert([PauliX], qs, intial, $""); - AssertProb([PauliZ], qs, Zero, 0.5, $"", Accuracy()); - AssertProb([PauliY], qs, Zero, 0.5, $"", Accuracy()); - AssertProb([PauliZ], qs, One, 0.5, $"", Accuracy()); - AssertProb([PauliY], qs, One, 0.5, $"", Accuracy()); - H(qs[0]); - Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); - - if (intial == One) { - X(qs[0]); - } - } - - - operation AssertProbAndS (intial : Result, qs : Qubit[]) : Unit { - - - if (intial == One) { - X(qs[0]); - } - - Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); - S(qs[0]); - Assert([PauliZ], qs, intial, $""); - S(qs[0]); - Assert([PauliZ], qs, intial, $"Newly allocated qubits are always zero"); - - if (intial == One) { - X(qs[0]); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs deleted file mode 100644 index 4add7409900..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Intrinsic; - - - operation AssertProbAndMeasureOneQubitTest () : Unit { - - let totalQubits = MaxQubitsToAllocateForOneQubitTests(); - - using (qs = Qubit[totalQubits]) { - - for (i in 0 .. totalQubits - 1) { - let q = qs[i]; - - if (IsStabilizerSimulator()) { - MeasureAndCorrect(PauliX, 0.5, q); - MeasureAndCorrect(PauliY, 0.5, q); - MeasureAndCorrect(PauliZ, 0.5, q); - } - } - } - } - - - operation ApplyNonCommutingPauli (pauli : Pauli, qubit : Qubit) : Unit { - - - if (pauli == PauliI) { - fail $"Every pauli commutes with Identity"; - } - elif (pauli == PauliX) { - Z(qubit); - } - elif (pauli == PauliY) { - X(qubit); - } - //PauliZ - else { - Y(qubit); - } - } - - - operation MeasureAndCorrect (observable : Pauli, probability : Double, qubit : Qubit) : Unit { - - AssertProb([observable], [qubit], Zero, probability, $"", 1E-10); - let res = Measure([observable], [qubit]); - Assert([observable], [qubit], res, $""); - - if (res == One) { - ApplyNonCommutingPauli(observable, qubit); - } - - Assert([observable], [qubit], Zero, $""); - ApplyNonCommutingPauli(observable, qubit); - Assert([observable], [qubit], One, $""); - ApplyNonCommutingPauli(observable, qubit); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs deleted file mode 100644 index 61619fdc008..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbMultiQubit.qs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Simulation.TestSuite.Math; - - - internal operation flipToBasis (basis : Int[], qubits : Qubit[]) : Unit is Adj + Ctl { - if (Length(qubits) != Length(basis)) - { - fail $"qubits and stateIds must have the same length"; - } - - for (i in 0 .. Length(qubits) - 1) - { - let id = basis[i]; - let qubit = qubits[i]; - - if (id < 0 or id > 3) { - fail $"Invalid basis. Must be between 0 and 3, it was {basis}"; - } - - if (id == 0) - { - I(qubit); - } - elif (id == 1) - { - X(qubit); - } - elif (id == 2) - { - H(qubit); - } - else - { - H(qubit); - S(qubit); - } - } - } - - operation AssertProbMultiQubitTest () : Unit { - - - for (numberOfQubits in 1 .. 2) { - AssertProbMultiQubitCheck(numberOfQubits); - } - } - - - operation AssertProbMultiQubitCheck (numberOfQubits : Int) : Unit { - - Message($"Testing on {numberOfQubits} qubits"); - IterateThroughCartesianPower(numberOfQubits, NumberOfPaulies(), AssertProbMultiQubitCheckPerObservable); - } - - - operation AssertProbMultiQubitCheckPerObservable (observable : Int[]) : Unit { - - let obs = PauliById(observable); - let checkOperation = AssertProbForStateAndObservable(obs, _); - - //this would check only computational basis - mutable statesToCheck = NumberOfComputationalBasisTestStates(); - - if (IsStabilizerSimulator()) { - - //this would check full basis with |0⟩,|1⟩,|+⟩,|i⟩ - set statesToCheck = NumberOfTestStates(); - } - - IterateThroughCartesianPower(Length(observable), statesToCheck, checkOperation); - } - - - operation AssertProbForStateAndObservable (observable : Pauli[], stateId : Int[]) : Unit { - - let l = Length(observable); - - if (l != Length(stateId)) { - fail $"arrays observable and stateId must have the same length"; - } - - using (qubits = Qubit[l]) { - flipToBasis(stateId, qubits); - let expectedZeroProbability = 0.5 + 0.5 * ExpectedValueForMultiPauliByStateId(observable, stateId); - let expectedOneProbability = 1.0 - expectedZeroProbability; - AssertMeasurementProbability(observable, qubits, Zero, expectedZeroProbability, $"", Accuracy()); - AssertMeasurementProbability(observable, qubits, One, expectedOneProbability, $"", Accuracy()); - Adjoint flipToBasis(stateId, qubits); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs deleted file mode 100644 index 2aed00babe1..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertProbOneQubit.qs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Intrinsic; - - - operation AssertProbOneQubitTest () : Unit { - - - for (i in 1 .. MaxQubitsToAllocateForOneQubitTests()) { - CheckAllocatedQubitsAreInZeroState(i); - CheckZeroStateObservablesValues(i); - } - } - - - operation CheckAllocatedQubitsAreInZeroState (count : Int) : Unit { - - - using (qs = Qubit[count]) { - - for (i in 0 .. count - 1) { - AssertProb([PauliZ], [qs[i]], Zero, 1.0, $"Newly allocated qubits must be in |0⟩ state", Accuracy()); - Assert([PauliZ], [qs[i]], Zero, $"Newly allocated qubits must be in |0⟩ state"); - } - } - } - - - operation CheckZeroStateObservablesValues (count : Int) : Unit { - - - using (qs = Qubit[count]) { - - for (i in 0 .. count - 1) { - AssertProb([PauliX], [qs[i]], Zero, 0.5, $"Measuring I+X for zero state must have probability 0.5", Accuracy()); - AssertProb([PauliX], [qs[i]], One, 0.5, $"Measuring I-X for zero state must have probability 0.5", Accuracy()); - AssertProb([PauliY], [qs[i]], Zero, 0.5, $"Measuring I+Y for zero state must have probability 0.5", Accuracy()); - AssertProb([PauliY], [qs[i]], One, 0.5, $"Measuring I-Y for zero state must have probability 0.5", Accuracy()); - } - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs deleted file mode 100644 index 642003c7f61..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertQubitUnitary.qs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Diagnostics; - - - operation AssertQubitUnitary (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit => Unit), qubit : Qubit) : Unit { - // check only computational basis for reversible target - let maxId = IsStabilizerSimulator() ? 3 | 1; - - for (stateId in 0 .. maxId) { - let expectedState = ApplyMatrix(unitaryMatrix, StateIdToVector(stateId)); - flipToBasis([stateId], [qubit]); - unitaryOp(qubit); - let alpha = Microsoft.Quantum.Math.Complex((expectedState![0])!); - let beta = Microsoft.Quantum.Math.Complex((expectedState![1])!); - AssertQubitIsInStateWithinTolerance((alpha, beta), qubit, Accuracy()); - Reset(qubit); - } - } - - - operation AssertQubitUnitaryWithAdjoint (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit => Unit : Adjoint)) : Unit { - - if (Length(unitaryMatrix!) != 2) { - fail $"qubit unitary matrix must have two rows"; - } - - let totalQubits = MaxQubitsToAllocateForOneQubitTests(); - AssertUnitaryMatrix(unitaryMatrix); - - using (qubits = Qubit[totalQubits]) { - for (activeQubitId in 0 .. totalQubits - 1) { - let qubit = qubits[activeQubitId]; - AssertQubitUnitary(unitaryMatrix, unitaryOp, qubit); - let op = OnFirstQubitA(unitaryOp, _); - - if (IsStabilizerSimulator()) { - //this checks that the adjoint is correct - AssertOperationsEqualInPlace(1, op, op); - } else { - AssertOperationsEqualInPlaceCompBasis(1, op, op); - } - } - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs deleted file mode 100644 index 9d746b1248d..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertState.qs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Intrinsic; - - - function PruneObservable (observable : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) { - - mutable nonIdCount = 0; - - for (i in 0 .. Length(observable) - 1) { - - if (observable[i] != PauliI) { - set nonIdCount = nonIdCount + 1; - } - } - - mutable paulies = new Pauli[nonIdCount]; - mutable qubitsPr = new Qubit[nonIdCount]; - set nonIdCount = 0; - - for (i in 0 .. Length(observable) - 1) { - - if (observable[i] != PauliI) { - set paulies w/= nonIdCount <- observable[i]; - set qubitsPr w/= nonIdCount <- qubits[i]; - set nonIdCount += 1; - } - } - - return (paulies, qubitsPr); - } - - - operation AssertStateHelper (observableId : Int[], state : Vector, qubits : Qubit[]) : Unit { - - let observable = PauliById(observableId); - let probabilityOfZero = (1.0 + PauliExpectation(observable, state)) / 2.0; - - //TODO: remove when AssertProb is fixed - let (obsPr, qubitsPr) = PruneObservable(observable, qubits); - let left = Length(qubitsPr); - - if (left > 0) { - AssertProb(obsPr, qubitsPr, Zero, probabilityOfZero, $"Wrong expectation value of an observable", Accuracy()); - } - } - - - operation AssertState (state : Vector, qubits : Qubit[]) : Unit { - - let checkOperation = AssertStateHelper(_, state, qubits); - IterateThroughCartesianPower(Length(qubits), NumberOfPaulies(), checkOperation); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs deleted file mode 100644 index e808fdb532c..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/AssertUnitary.qs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - - operation AssertUnitaryHelper (stateIds : Int[], unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit[] => Unit), qubits : Qubit[]) : Unit { - - let expectedState = ApplyMatrix(unitaryMatrix, StateById(stateIds)); - flipToBasis(stateIds, qubits); - unitaryOp(qubits); - AssertState(expectedState, qubits); - ResetAll(qubits); - } - - - operation AssertUnitary (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit[] => Unit), qubits : Qubit[]) : Unit { - - mutable bound = NumberOfComputationalBasisTestStates(); - - if (IsStabilizerSimulator()) { - set bound = NumberOfTestStates(); - //check only computational basis for reversible target - } - - let checkOperation = AssertUnitaryHelper(_, unitaryMatrix, unitaryOp, qubits); - IterateThroughCartesianPower(Length(qubits), bound, checkOperation); - } - - - operation AssertUnitaryWithAdjoint (unitaryMatrix : RowMajorMatrix, unitaryOp : (Qubit[] => Unit : Adjoint), qubits : Qubit[]) : Unit { - - - if (Length(unitaryMatrix!) != 2 ^ Length(qubits)) { - fail $"number of matrix rows must be 2^Length(qubits)"; - } - - AssertUnitaryMatrix(unitaryMatrix); - AssertUnitary(unitaryMatrix, unitaryOp, qubits); - - ( - IsStabilizerSimulator() - ? AssertOperationsEqualInPlace - | AssertOperationsEqualInPlaceCompBasis - )(Length(qubits), unitaryOp, unitaryOp); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs deleted file mode 100644 index 180bb724cf0..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Complex.qs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite.Math { - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Convert; - - - newtype Complex = (Double, Double); - - - function ExpIC (phi : Double) : Complex { - - return Complex(Cos(phi), Sin(phi)); - } - - - function ExpICFrac (numerator : Int, denomPower : Int) : Complex { - - let denom = 2 ^ denomPower; - let phi = IntAsDouble(numerator) / IntAsDouble(denom); - return ExpIC(phi); - } - - - function PlusC (a : Complex, b : Complex) : Complex { - - let (aRe, aIm) = a!; - let (bRe, bIm) = b!; - return Complex(aRe + bRe, aIm + bIm); - } - - - function TimesC (a : Complex, b : Complex) : Complex { - - let (aRe, aIm) = a!; - let (bRe, bIm) = b!; - return Complex(aRe * bRe - aIm * bIm, aRe * bIm + aIm * bRe); - } - - - function ConjugateC (a : Complex) : Complex { - - let (aRe, aIm) = a!; - return Complex(aRe, -aIm); - } - - - function MinusC (a : Complex) : Complex { - - let (aRe, aIm) = a!; - return Complex(-aRe, -aIm); - } - - - function DivCD (a : Complex, b : Double) : Complex { - - let (aRe, aIm) = a!; - return Complex(aRe / b, aIm / b); - } - - - function AbsSquaredC (a : Complex) : Double { - - let (aRe, aIm) = a!; - return aRe * aRe + aIm * aIm; - } - - - function AbsC (a : Complex) : Double { - - return Sqrt(AbsSquaredC(a)); - } - - - function DivCC (a : Complex, b : Complex) : Complex { - - return DivCD(TimesC(a, ConjugateC(b)), AbsSquaredC(b)); - } - - - function ZeroC () : Complex { - - - //TODO: BUG 799 fix this when the bug is resolved - return Complex(0.0, 0.0); - } - - - function OneC () : Complex { - - - //TODO: BUG 799 fix this when the bug is resolved - return Complex(1.0, 0.0); - } - - - function ComplexI () : Complex { - - - //TODO: BUG 799 fix this when the bug is resolved - return Complex(0.0, 1.0); - } - - - function ComplexIPower (power : Int) : Complex { - let powMod4 = (power % 4 + 8) % 4; - - if (powMod4 == 0) { - return Complex(1.0, 0.0); - } elif (powMod4 == 1) { - return Complex(0.0, 1.0); - } elif (powMod4 == 2) { - return Complex(-1.0, 0.0); - } elif (powMod4 == 3) { - return Complex(0.0, -1.0); - } - - fail $"this line should never be reached"; - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs deleted file mode 100644 index d3b463df31a..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Config.qs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - function IsReversibleSimulator () : Bool { - - return true; - } - - - function IsStabilizerSimulator () : Bool { - - return true; - } - - - function Accuracy () : Double { - - return 1E-10; - } - - - function MaxQubitsToAllocateForOneQubitTests () : Int { - - return 5; - } - - - function MaxQubitsToAllocateForTwoQubitTests () : Int { - - return 2; - } - - - function IsFullSimulator () : Bool { - - return true; - } - - - function MaxDenomiantorPowerToTest () : Int { - - return 3; - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs deleted file mode 100644 index e50bd076976..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationTester.qs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - - operation ControlledQubitOperationTester (actual : (Qubit => Unit : Controlled, Adjoint), expected : (Qubit => Unit : Controlled, Adjoint), numberOfQubits : Int) : Unit { - - Message($"Testing operation: {actual} against {expected}"); - - if (numberOfQubits < 1) { - fail $"numberOfQubits must be at least 1"; - } - - let actualOnQubitArr = OnFirstQubitA(actual, _); - let expectedOnQubitArr = OnFirstQubitA(expected, _); - AssertOperationsEqualReferenced(1, actualOnQubitArr, expectedOnQubitArr); - AssertOperationsEqualReferenced(1, Adjoint actualOnQubitArr, Adjoint expectedOnQubitArr); - - for (totalQubits in 1 .. numberOfQubits) { - let controlsCount = totalQubits - 1; - Message($"Testing equality of controlled version with {controlsCount} control(s)"); - let actualControlled = MultiControlledQubitTestHelper(actual, controlsCount, _); - let expectedControlled = MultiControlledQubitTestHelper(expected, controlsCount, _); - AssertOperationsEqualReferenced(totalQubits, actualControlled, expectedControlled); - AssertOperationsEqualReferenced(totalQubits, Adjoint actualControlled, Adjoint expectedControlled); - } - } - - - operation ControlledOperationTester (actual : (Qubit[] => Unit : Controlled, Adjoint), expected : (Qubit[] => Unit : Controlled, Adjoint), numberOfQubits : Int, numberOfControls : Int) : Unit { - - Message($"Testing operation: {actual} against {expected}"); - - if (numberOfQubits < 1) { - fail $"numberOfQubits must be at least 1"; - } - - AssertOperationsEqualReferenced(numberOfQubits, actual, expected); - AssertOperationsEqualReferenced(numberOfQubits, Adjoint actual, Adjoint expected); - - for (controls in 0 .. numberOfControls) { - Message($"Testing equality of controlled version with {controls} control(s)"); - let actualControlled = MultiControlledTestHelper(actual, controls, numberOfQubits, _); - let expectedControlled = MultiControlledTestHelper(expected, controls, numberOfQubits, _); - AssertOperationsEqualReferenced(controls + numberOfQubits, actualControlled, expectedControlled); - AssertOperationsEqualReferenced(controls + numberOfQubits, Adjoint actualControlled, Adjoint expectedControlled); - } - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs deleted file mode 100644 index 8115cbafda9..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Intrinsic; - - - operation MultiControlledQubitTestHelper (qubitOperation : (Qubit => Unit : Controlled, Adjoint), controls : Int, target : Qubit[]) : Unit { - - body (...) { - - if (Length(target) != controls + 1) { - fail $"expecting {controls}+1 qubits as input"; - } - - Controlled qubitOperation(target[1 .. controls], target[0]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation MultiControlledTestHelper (testOperation : (Qubit[] => Unit : Controlled, Adjoint), controlsCount : Int, targetCount : Int, target : Qubit[]) : Unit { - - body (...) { - - if (Length(target) != controlsCount + targetCount) { - fail $"expecting {controlsCount}+{targetCount} qubits as input"; - } - - Controlled testOperation(target[targetCount .. (targetCount + controlsCount) - 1], target[0 .. targetCount - 1]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; - } - - - operation MultiControlledQubitOperationsTester (controls : Int) : Unit { - - - if (controls < 0) { - fail $"number of controlls must be non-negative"; - } - - Message($"Testing with {controls} controls"); - - for (test in OneQubitTestList()) { - let shouldExecute = - IsFullSimulator() or - (IsStabilizerSimulator() and LevelOfCliffordHierarchy(test) + controls <= 1) or - (IsReversibleSimulator() and FixesComputationalBasis(test)); - - if (shouldExecute) { - let map = OperationMap(test); - - using (qubits = Qubit[controls + 1]) { - AssertUnitaryWithAdjoint(ControlledMatrix(controls, OperationMatrix(test)), MultiControlledQubitTestHelper(map, controls, _), qubits); - } - - Message($"Passed:{map}"); - } - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs deleted file mode 100644 index 849e62904d7..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// note: this code is duplicared in libraries - -namespace Microsoft.Quantum.Simulation.TestSuite { - - /// - /// Iterates a variable, say arr, through cartesian product - /// [ 0, bounds[0]-1 ] × [ 0, bounds[1]-1 ] × [ 0, bounds[Length(bounds)-1]-1 ] - /// and calls op(arr) for every element of the cartesian product - /// - operation IterateThroughCartesianProduct (bounds : Int[], op : (Int[] => Unit)) : Unit { - - mutable arr = new Int[Length(bounds)]; - mutable finished = false; - - repeat { - - if (not finished) { - op(arr); - } - } - until (finished) - fixup { - - //computes the next element in the Cartesian product - set arr w/= 0 <- arr[0] + 1; - - for (i in 0 .. Length(arr) - 2) { - - if (arr[i] == bounds[i]) { - set arr w/= i + 1 <- arr[i + 1] + 1; - set arr w/= i <- 0; - } - } - - if (arr[Length(arr) - 1] == bounds[Length(arr) - 1]) { - set finished = true; - } - } - } - - - /// # Summary - /// Creates an array of given length with all elments equal to given value. - function MakeConstArray(length : Int, value : Int) : Int[] { - mutable arr = new Int[length]; - - for (i in 0 .. length - 1) { - set arr = arr w/ i <- value; - } - - return arr; - } - - /// # Summary - /// Iterates a variable, say arr, through cartesian product - /// [ 0, bound - 1 ] × [ 0, bound - 1 ] × [ 0, bound - 1 ] - /// and calls op(arr) for every element of the cartesian product - operation IterateThroughCartesianPower (power : Int, bound : Int, op : (Int[] => Unit)) : Unit { - IterateThroughCartesianProduct(MakeConstArray(power, bound), op); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs deleted file mode 100644 index 937b84b7099..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/JointOneQubitTests.qs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - - newtype QubitOperationMatrixPair = ((Qubit => Unit), RowMajorMatrix); - - - operation CheckJointState (inputStateId : Int[], operationsToTest : QubitOperationMatrixPair[], qubits : Qubit[]) : Unit { - - let numQubits = Length(qubits); - - if (Length(inputStateId) != Length(operationsToTest)) { - fail $"Length(inputStateId) and Length(operationsToTest) must be equal"; - } - - if (Length(inputStateId) != numQubits) { - fail $"Length(inputStateId) and Length(operationsToTest) must be equal"; - } - - mutable states = new Vector[numQubits]; - flipToBasis(inputStateId, qubits); - - for (i in 0 .. numQubits - 1) { - let (op, matrix) = operationsToTest[i]!; - set states = states w/ i <- ApplyMatrix(matrix, StateIdToVector(inputStateId[i])); - op(qubits[i]); - } - - AssertState(TensorProductOfArray(states), qubits); - ResetAll(qubits); - } - - - operation JointOneQubitTester (operationsToTest : QubitOperationMatrixPair[]) : Unit { - - let totalQubits = Length(operationsToTest); - - using (qubits = Qubit[totalQubits]) { - let checkOperation = CheckJointState(_, operationsToTest, qubits); - IterateThroughCartesianPower(totalQubits, NumberOfTestStates(), checkOperation); - } - } - - - operation JointOneQubitTest () : Unit { - - - if (IsStabilizerSimulator()) { - - if (IsFullSimulator()) { - JointOneQubitTester([QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(T, TMatrix())]); - } - - JointOneQubitTester([QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(H, HMatrix())]); - JointOneQubitTester([QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(H, HMatrix()), QubitOperationMatrixPair(S, SMatrix())]); - } - - JointOneQubitTester([QubitOperationMatrixPair(X, PauliMatrix(PauliX)), QubitOperationMatrixPair(X, PauliMatrix(PauliX)), QubitOperationMatrixPair(X, PauliMatrix(PauliX))]); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs deleted file mode 100644 index b1f8e371137..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/KnownIssues.qs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Simulation.TestSuite.Math; - - - operation AssertProbMultiQubit1Test () : Unit { - - AssertProbForStateAndObservable([PauliI, PauliI], [0, 1]); - } - - - operation AssertProbMultiQubit2Test () : Unit { - - AssertProbForStateAndObservable([PauliI, PauliX], [1, 2]); - } - - - operation ControlledExpWithIPauliTest () : Unit { - - let controls = 1; - let phi = 0.1; - let pauli = PauliI; - let testOp = Exp([pauli], phi, _); - let matrix = ControlledMatrix(controls, ExpPauliMatrix(pauli, phi)); - let op = OnOneQubitAC(testOp, _); - let controlledOp = MultiControlledQubitTestHelper(op, controls, _); - - using (qubits = Qubit[2]) { - AssertUnitaryWithAdjoint(matrix, controlledOp, qubits); - } - } - - - operation FracEdgeCasesQSimFail () : Unit { - - let rzPlus = RFrac(PauliZ, 1, 0xFFFFFFFFFFFFFFF, _); - let rxPlus = RFrac(PauliX, 1, 0xFFFFFFFFFFFFFFF, _); - let ryPlus = RFrac(PauliY, 1, 0xFFFFFFFFFFFFFFF, _); - let rzMinus = RFrac(PauliZ, 1, -0xFFFFFFFFFFFFFFF, _); - let rxMinus = RFrac(PauliX, 1, -0xFFFFFFFFFFFFFFF, _); - let ryMinus = RFrac(PauliY, 1, -0xFFFFFFFFFFFFFFF, _); - - using (qubits = Qubit[1]) { - AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rxPlus, _), qubits); - AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(ryPlus, _), qubits); - AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rzPlus, _), qubits); - AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rxMinus, _), qubits); - AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(ryMinus, _), qubits); - AssertUnitaryWithAdjoint(IdentityMatrix(2), OnFirstQubitA(rzMinus, _), qubits); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs deleted file mode 100644 index 12be491807c..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/LinearAlgebra.qs +++ /dev/null @@ -1,331 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite.Math { - open Microsoft.Quantum.Simulation.TestSuite; - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Convert; - - - newtype RowMajorMatrix = Complex[][]; - - newtype RowVector = Complex[]; - - newtype Vector = Complex[]; - - - function ZeroState () : Vector { - return Vector([OneC(), ZeroC()]); - } - - - function OneState () : Vector { - return Vector([ZeroC(), OneC()]); - } - - - function PlusState () : Vector { - return Vector([Complex(1.0 / Sqrt(2.0), 0.0), Complex(1.0 / Sqrt(2.0), 0.0)]); - } - - - function IState () : Vector { - return Vector([Complex(1.0 / Sqrt(2.0), 0.0), Complex(0.0, 1.0 / Sqrt(2.0))]); - } - - - function NumberOfTestStates () : Int { - return 4; - } - - - function NumberOfComputationalBasisTestStates () : Int { - return 2; - } - - - function NumberOfPaulies () : Int { - return 4; - } - - - function TensorProduct (vector1 : Vector, vector2 : Vector) : Vector { - let len1 = Length(vector1!); - let len2 = Length(vector2!); - - if (len1 == 0) { - fail $"The tensor product is not defined when the length of vector1 is 0"; - } - - if (len2 == 0) { - fail $"The tensor product is not defined when the length of vector2 is 0"; - } - - mutable res = new Complex[Length(vector1!) * Length(vector2!)]; - - for (i in 0 .. len1 - 1) { - - for (j in 0 .. len2 - 1) { - set res = res w/ i * len2 + j <- TimesC(vector1![i], vector2![j]); - } - } - - return Vector(res); - } - - - function StateIdToVector (id : Int) : Vector { - let stateMaps = [ZeroState, OneState, PlusState, IState]; - return stateMaps[id](); - } - - - function StateById (stateId : Int[]) : Vector { - - - if (Length(stateId) == 0) { - fail $"Length of stateId must be at least 1"; - } - - mutable res = StateIdToVector(stateId[0]); - - for (i in 1 .. Length(stateId) - 1) { - set res = TensorProduct(StateIdToVector(stateId[i]), res); - } - - return res; - } - - - function TensorProductOfArray (states : Vector[]) : Vector { - - - if (Length(states) == 0) { - fail $"Length of stateId must be at least 1"; - } - - mutable res = states[0]; - - for (i in 1 .. Length(states) - 1) { - set res = TensorProduct(states[i], res); - } - - return res; - } - - - function PauliById (pauliId : Int[]) : Pauli[] { - - let paulies = [PauliX, PauliY, PauliZ, PauliI]; - mutable arr = new Pauli[Length(pauliId)]; - - for (i in 0 .. Length(pauliId) - 1) { - set arr = arr w/ i <- paulies[pauliId[i]]; - } - - return arr; - } - - - /// # Summary - /// Returns the expectation of measuring observable on the qubit in state given by stateId. - /// - /// # Remarks - /// The correspondence between - /// value of stateId and the qubit state is the following: - /// 0 -- |0⟩ - /// 1 -- |1⟩ - /// 2 -- |+⟩ - /// 3 -- |i⟩ ( +1 eigenstate of Pauli Y ) - function ExpectedValueForPauli (observable : Pauli, stateId : Int) : Double { - if (stateId < 0 or stateId > 3) { - fail $"stateId must have value between 0 and 3"; - } - - let XpauliArr = [0.0, 0.0, 1.0, 0.0]; - let YpauliArr = [0.0, 0.0, 0.0, 1.0]; - let ZpauliArr = [1.0, -1.0, 0.0, 0.0]; - - if (observable == PauliI) { - return 1.0; - } elif (observable == PauliX) { - return XpauliArr[stateId]; - } elif (observable == PauliY) { - return YpauliArr[stateId]; - } elif (observable == PauliZ) { - return ZpauliArr[stateId]; - } - - fail $"this line should never be reached"; - } - - - /// - /// Expectation of the observable P₁⊗…⊗Pₙ with respect to state |ψ₁⟩⊗…⊗|ψₙ⟩ given by stateId array. - /// The correspondence between - /// the values of stateId array and the qubit state is the following: - /// 0 -- |0⟩ - /// 1 -- |1⟩ - /// 2 -- |+⟩ - /// 3 -- |i⟩ ( +1 eigenstate of Pauli Y ) - /// - function ExpectedValueForMultiPauliByStateId (observable : Pauli[], stateId : Int[]) : Double { - - - if (Length(observable) != Length(stateId)) { - fail $"arrays observable and stateId must have the same length"; - } - - //note that writing 1.0 here will cause code gen to fail. - mutable res = IntAsDouble(1); - - for (i in 0 .. Length(observable) - 1) { - set res = res * ExpectedValueForPauli(observable[i], stateId[i]); - } - - return res; - } - - - function DotProduct (vector1 : Complex[], vector2 : Vector) : Complex { - - mutable res = ZeroC(); - let dimension = Length(vector1); - - if (dimension != Length(vector2!)) { - fail $"vector1 and vector2 must have he same dimension"; - } - - for (i in 0 .. dimension - 1) { - set res = PlusC(res, TimesC(vector1[i], vector2![i])); - } - - return res; - } - - - function HermitianProduct (vector1 : Vector, vector2 : Vector) : Complex { - - mutable res = ZeroC(); - let dimension = Length(vector1!); - - if (dimension != Length(vector2!)) { - fail $"vector1 and vector2 must have he same dimension"; - } - - for (i in 0 .. dimension - 1) { - set res = PlusC(res, TimesC(ConjugateC(vector1![i]), vector2![i])); - } - - return res; - } - - - function ApplyMatrix (matrixRowMajor : RowMajorMatrix, columnVector : Vector) : Vector { - - let rowCount = Length(matrixRowMajor!); - mutable res = new Complex[rowCount]; - - for (i in 0 .. rowCount - 1) { - set res = res w/ i <- DotProduct(matrixRowMajor![i], columnVector); - } - - return Vector(res); - } - - - function AssertUnitaryMatrix (unitaryMatrix : RowMajorMatrix) : Unit { - - let rowCount = Length(unitaryMatrix!); - - for (i in 0 .. rowCount - 1) { - - if (Length(unitaryMatrix![i]) != rowCount) { - fail $"matrix is not square"; - } - - let norm = HermitianProduct(Vector(unitaryMatrix![i]), Vector(unitaryMatrix![i])); - - if (AbsSquaredC(PlusC(norm, MinusC(OneC()))) >= Accuracy()) { - fail $"one of the rows does not have norm 1"; - } - } - - for (i in 0 .. rowCount - 1) { - - for (j in 0 .. rowCount - 1) { - - if (i != j) { - let hermProd = HermitianProduct(Vector(unitaryMatrix![i]), Vector(unitaryMatrix![j])); - - if (AbsSquaredC(hermProd) >= Accuracy()) { - fail $"some of the matrix rows are non-orthogonal with respect to hermitian product"; - } - } - } - } - } - - - function IdentityMatrix (size : Int) : RowMajorMatrix { - - mutable result = new Complex[][size]; - - for (i in 0 .. size - 1) { - set result = result w/ - i <- (new Complex[size] w/ i <- OneC()); - } - - return RowMajorMatrix(result); - } - - - function DirectSum (left : RowMajorMatrix, right : RowMajorMatrix) : RowMajorMatrix { - - let leftDimension = Length(left!); - let rightDimension = Length(right!); - let resultDimension = leftDimension + rightDimension; - mutable result = new Complex[][resultDimension]; - - for (i in 0 .. resultDimension - 1) { - mutable row = new Complex[resultDimension]; - - if (i < leftDimension) { - - for (j in 0 .. leftDimension - 1) { - set row = row w/ j <- left![i][j]; - } - } - else { - - for (j in 0 .. rightDimension - 1) { - set row = row w/ j + leftDimension <- right![i - leftDimension][j]; - } - } - set result = result w/ i <- row; - } - - return RowMajorMatrix(result); - } - - - function ControlledMatrix (numberOfControls : Int, matrix : RowMajorMatrix) : RowMajorMatrix { - - - if (numberOfControls < 1) { - fail $"Number of controls must be at least 1"; - } - - let (matrixQubits, nonPowerOfTwo) = PAdicValuation(Length(matrix!), 2); - - if (nonPowerOfTwo != 1) { - fail $"Dimension of the matrix must be power of two"; - } - - let identityMatrixDimension = 2 ^ (matrixQubits + numberOfControls) - Length(matrix!); - return DirectSum(IdentityMatrix(identityMatrixDimension), matrix); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs deleted file mode 100644 index 9c89fd54ddc..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ManyControlQubitsTest.qs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Intrinsic; - - - operation ManyControlQubitsTest () : Unit { - - let totalQubits = 18; - - for (i in 14 .. totalQubits) { - - using (qubits = Qubit[i]) { - - for (c in 0 .. i - 2) { - - for (h in 0 .. i - 1) { - H(qubits[h]); - } - - let ctrls = qubits[0 .. c]; - let target = qubits[i - 1]; - X(ctrls[c]); - Controlled X(ctrls, target); - } - - ResetAll(qubits); - } - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs deleted file mode 100644 index 2f3dd7dba1d..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Math.qs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite.Math { - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Convert; - - function _pavRecursion (value : Int, valuationBase : Int, valuation : Int) : (Int, Int) { - if (value % valuationBase != 0 ) { - return (valuation, value); - } - - return _pavRecursion(value / valuationBase, valuationBase, valuation + 1); - } - - /// returns (a,b) where a is the biggest value such that value = b*valuationBase^a - function PAdicValuation (value : Int, valuationBase : Int) : (Int, Int) { - if (value == 0) { - fail $"value must be non-zero"; - } - - if (valuationBase <= 0) { - fail $"valuationBase must be positive"; - } - - return _pavRecursion(value, valuationBase, 0); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs deleted file mode 100644 index 181e0347999..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/Matrices.qs +++ /dev/null @@ -1,2004 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite.Math { - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Convert; - - - function ExpXMatrix (phi : Double) : RowMajorMatrix { - - let matrix = [[Complex(Cos(phi), 0.0), Complex(0.0, Sin(phi))], [Complex(0.0, Sin(phi)), Complex(Cos(phi), 0.0)]]; - return RowMajorMatrix(matrix); - } - - - function ExpYMatrix (phi : Double) : RowMajorMatrix { - - let matrix = [[Complex(Cos(phi), 0.0), Complex(Sin(phi), 0.0)], [Complex(-Sin(phi), 0.0), Complex(Cos(phi), 0.0)]]; - return RowMajorMatrix(matrix); - } - - - function ExpZMatrix (phi : Double) : RowMajorMatrix { - - return RowMajorMatrix([[ExpIC(phi), ZeroC()], [ZeroC(), ExpIC(-phi)]]); - } - - - function ExpIMatrix (phi : Double) : RowMajorMatrix { - - return RowMajorMatrix([[ExpIC(phi), ZeroC()], [ZeroC(), ExpIC(phi)]]); - } - - - function ExpPauliMatrix (pauli : Pauli, phi : Double) : RowMajorMatrix { - - - if (pauli == PauliI) { - return ExpIMatrix(phi); - } - elif (pauli == PauliX) { - return ExpXMatrix(phi); - } - elif (pauli == PauliY) { - return ExpYMatrix(phi); - } - elif (pauli == PauliZ) { - return ExpZMatrix(phi); - } - - fail $"this line should never be reached"; - } - - - function R1Matrix (phi : Double) : RowMajorMatrix { - - return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), ExpIC(phi)]]); - } - - - function PauliMatrix (pauli : Pauli) : RowMajorMatrix { - - - if (pauli == PauliI) { - return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), OneC()]]); - } - elif (pauli == PauliX) { - return RowMajorMatrix([[ZeroC(), OneC()], [OneC(), ZeroC()]]); - } - elif (pauli == PauliY) { - return RowMajorMatrix([[ZeroC(), Complex(0.0, -1.0)], [Complex(0.0, 1.0), ZeroC()]]); - } - elif (pauli == PauliZ) { - return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), MinusC(OneC())]]); - } - - fail $"this line should never be reached"; - } - - - function SMatrix () : RowMajorMatrix { - - return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), Complex(0.0, 1.0)]]); - } - - - function TMatrix () : RowMajorMatrix { - - let oneOvSqrt2 = 1.0 / Sqrt(2.0); - return RowMajorMatrix([[OneC(), ZeroC()], [ZeroC(), Complex(oneOvSqrt2, oneOvSqrt2)]]); - } - - - function HMatrix () : RowMajorMatrix { - - let oneOvSqrt2 = DivCD(OneC(), Sqrt(2.0)); - return RowMajorMatrix([[oneOvSqrt2, oneOvSqrt2], [oneOvSqrt2, MinusC(oneOvSqrt2)]]); - } - - - function CNOTMatrix () : RowMajorMatrix { - - let I = OneC(); - let O = ZeroC(); - let matrix = [ - [I, O, O, O], - [O, O, O, I], - [O, O, I, O], - [O, I, O, O] - ]; - return RowMajorMatrix(matrix); - } - - - function SWAPMatrix () : RowMajorMatrix { - - let I = OneC(); - let O = ZeroC(); - let matrix = [ - [I, O, O, O], - [O, O, I, O], - [O, I, O, O], - [O, O, O, I] - ]; - return RowMajorMatrix(matrix); - } - - - // All code below has been auto-generated using Mathematics notebook TestSuiteCalculations.nb - - function ExpIIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O], - [O, Ep, O, O], - [O, O, Ep, O], - [O, O, O, Ep] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, IS, O, O], - [IS, C, O, O], - [O, O, C, IS], - [O, O, IS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, pS, O, O], - [mS, C, O, O], - [O, O, C, pS], - [O, O, mS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O], - [O, Em, O, O], - [O, O, Ep, O], - [O, O, O, Em] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, IS, O], - [O, C, O, IS], - [IS, O, C, O], - [O, IS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, IS], - [O, C, IS, O], - [O, IS, C, O], - [IS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, pS], - [O, C, mS, O], - [O, pS, C, O], - [mS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, IS, O], [O, C, O, mIS], - [IS, O, C, O], - [O, mIS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, pS, O], - [O, C, O, pS], - [mS, O, C, O], - [O, mS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, pS], - [O, C, pS, O], - [O, mS, C, O], - [mS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, mIS], - [O, C, IS, O], - [O, IS, C, O], - [mIS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, pS, O], - [O, C, O, mS], - [mS, O, C, O], - [O, pS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O], - [O, Ep, O, O], - [O, O, Em, O], - [O, O, O, Em] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, IS, O, O], - [IS, C, O, O], - [O, O, C, mIS], - [O, O, mIS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, pS, O, O], - [mS, C, O, O], - [O, O, C, mS], - [O, O, pS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O], - [O, Em, O, O], - [O, O, Em, O], - [O, O, O, Ep] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIIIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Ep, O, O, O, O, O, O], - [O, O, Ep, O, O, O, O, O], - [O, O, O, Ep, O, O, O, O], - [O, O, O, O, Ep, O, O, O], - [O, O, O, O, O, Ep, O, O], - [O, O, O, O, O, O, Ep, O], - [O, O, O, O, O, O, O, Ep] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIIXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, IS, O, O, O, O, O, O], - [IS, C, O, O, O, O, O, O], - [O, O, C, IS, O, O, O, O], - [O, O, IS, C, O, O, O, O], - [O, O, O, O, C, IS, O, O], - [O, O, O, O, IS, C, O, O], - [O, O, O, O, O, O, C, IS], - [O, O, O, O, O, O, IS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIIYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, pS, O, O, O, O, O, O], - [mS, C, O, O, O, O, O, O], - [O, O, C, pS, O, O, O, O], - [O, O, mS, C, O, O, O, O], - [O, O, O, O, C, pS, O, O], - [O, O, O, O, mS, C, O, O], - [O, O, O, O, O, O, C, pS], - [O, O, O, O, O, O, mS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIIZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Em, O, O, O, O, O, O], - [O, O, Ep, O, O, O, O, O], - [O, O, O, Em, O, O, O, O], - [O, O, O, O, Ep, O, O, O], - [O, O, O, O, O, Em, O, O], - [O, O, O, O, O, O, Ep, O], - [O, O, O, O, O, O, O, Em] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIXIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, IS, O, O, O, O, O], - [O, C, O, IS, O, O, O, O], - [IS, O, C, O, O, O, O, O], - [O, IS, O, C, O, O, O, O], - [O, O, O, O, C, O, IS, O], - [O, O, O, O, O, C, O, IS], - [O, O, O, O, IS, O, C, O], - [O, O, O, O, O, IS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIXXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, IS, O, O, O, O], - [O, C, IS, O, O, O, O, O], - [O, IS, C, O, O, O, O, O], - [IS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, IS], - [O, O, O, O, O, C, IS, O], - [O, O, O, O, O, IS, C, O], - [O, O, O, O, IS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIXYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, pS, O, O, O, O], - [O, C, mS, O, O, O, O, O], - [O, pS, C, O, O, O, O, O], - [mS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, pS], - [O, O, O, O, O, C, mS, O], - [O, O, O, O, O, pS, C, O], - [O, O, O, O, mS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIXZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, IS, O, O, O, O, O], - [O, C, O, mIS, O, O, O, O], - [IS, O, C, O, O, O, O, O], - [O, mIS, O, C, O, O, O, O], - [O, O, O, O, C, O, IS, O], - [O, O, O, O, O, C, O, mIS], - [O, O, O, O, IS, O, C, O], - [O, O, O, O, O, mIS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIYIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, pS, O, O, O, O, O], - [O, C, O, pS, O, O, O, O], - [mS, O, C, O, O, O, O, O], - [O, mS, O, C, O, O, O, O], - [O, O, O, O, C, O, pS, O], - [O, O, O, O, O, C, O, pS], - [O, O, O, O, mS, O, C, O], - [O, O, O, O, O, mS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIYXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, pS, O, O, O, O], - [O, C, pS, O, O, O, O, O], - [O, mS, C, O, O, O, O, O], - [mS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, pS], - [O, O, O, O, O, C, pS, O], - [O, O, O, O, O, mS, C, O], - [O, O, O, O, mS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIYYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, mIS, O, O, O, O], - [O, C, IS, O, O, O, O, O], - [O, IS, C, O, O, O, O, O], - [mIS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, mIS], - [O, O, O, O, O, C, IS, O], - [O, O, O, O, O, IS, C, O], - [O, O, O, O, mIS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIYZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, pS, O, O, O, O, O], - [O, C, O, mS, O, O, O, O], - [mS, O, C, O, O, O, O, O], - [O, pS, O, C, O, O, O, O], - [O, O, O, O, C, O, pS, O], - [O, O, O, O, O, C, O, mS], - [O, O, O, O, mS, O, C, O], - [O, O, O, O, O, pS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIZIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Ep, O, O, O, O, O, O], - [O, O, Em, O, O, O, O, O], - [O, O, O, Em, O, O, O, O], - [O, O, O, O, Ep, O, O, O], - [O, O, O, O, O, Ep, O, O], - [O, O, O, O, O, O, Em, O], - [O, O, O, O, O, O, O, Em] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIZXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, IS, O, O, O, O, O, O], - [IS, C, O, O, O, O, O, O], - [O, O, C, mIS, O, O, O, O], - [O, O, mIS, C, O, O, O, O], - [O, O, O, O, C, IS, O, O], - [O, O, O, O, IS, C, O, O], - [O, O, O, O, O, O, C, mIS], - [O, O, O, O, O, O, mIS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIZYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, pS, O, O, O, O, O, O], - [mS, C, O, O, O, O, O, O], - [O, O, C, mS, O, O, O, O], - [O, O, pS, C, O, O, O, O], - [O, O, O, O, C, pS, O, O], - [O, O, O, O, mS, C, O, O], - [O, O, O, O, O, O, C, mS], - [O, O, O, O, O, O, pS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpIZZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Em, O, O, O, O, O, O], - [O, O, Em, O, O, O, O, O], - [O, O, O, Ep, O, O, O, O], - [O, O, O, O, Ep, O, O, O], - [O, O, O, O, O, Em, O, O], - [O, O, O, O, O, O, Em, O], - [O, O, O, O, O, O, O, Ep] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXIIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, IS, O, O, O], - [O, C, O, O, O, IS, O, O], - [O, O, C, O, O, O, IS, O], - [O, O, O, C, O, O, O, IS], - [IS, O, O, O, C, O, O, O], - [O, IS, O, O, O, C, O, O], - [O, O, IS, O, O, O, C, O], - [O, O, O, IS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXIXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, IS, O, O], - [O, C, O, O, IS, O, O, O], - [O, O, C, O, O, O, O, IS], - [O, O, O, C, O, O, IS, O], - [O, IS, O, O, C, O, O, O], - [IS, O, O, O, O, C, O, O], - [O, O, O, IS, O, O, C, O], - [O, O, IS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXIYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, pS, O, O], - [O, C, O, O, mS, O, O, O], - [O, O, C, O, O, O, O, pS], - [O, O, O, C, O, O, mS, O], - [O, pS, O, O, C, O, O, O], - [mS, O, O, O, O, C, O, O], - [O, O, O, pS, O, O, C, O], - [O, O, mS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXIZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, IS, O, O, O], - [O, C, O, O, O, mIS, O, O], - [O, O, C, O, O, O, IS, O], - [O, O, O, C, O, O, O, mIS], - [IS, O, O, O, C, O, O, O], - [O, mIS, O, O, O, C, O, O], - [O, O, IS, O, O, O, C, O], - [O, O, O, mIS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXXIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, IS, O], - [O, C, O, O, O, O, O, IS], - [O, O, C, O, IS, O, O, O], - [O, O, O, C, O, IS, O, O], - [O, O, IS, O, C, O, O, O], - [O, O, O, IS, O, C, O, O], - [IS, O, O, O, O, O, C, O], - [O, IS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXXXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, IS], - [O, C, O, O, O, O, IS, O], - [O, O, C, O, O, IS, O, O], - [O, O, O, C, IS, O, O, O], - [O, O, O, IS, C, O, O, O], - [O, O, IS, O, O, C, O, O], - [O, IS, O, O, O, O, C, O], - [IS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXXYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, pS], - [O, C, O, O, O, O, mS, O], - [O, O, C, O, O, pS, O, O], - [O, O, O, C, mS, O, O, O], - [O, O, O, pS, C, O, O, O], - [O, O, mS, O, O, C, O, O], - [O, pS, O, O, O, O, C, O], - [mS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXXZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, IS, O], - [O, C, O, O, O, O, O, mIS], - [O, O, C, O, IS, O, O, O], - [O, O, O, C, O, mIS, O, O], - [O, O, IS, O, C, O, O, O], - [O, O, O, mIS, O, C, O, O], - [IS, O, O, O, O, O, C, O], - [O, mIS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXYIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, pS, O], - [O, C, O, O, O, O, O, pS], - [O, O, C, O, mS, O, O, O], - [O, O, O, C, O, mS, O, O], - [O, O, pS, O, C, O, O, O], - [O, O, O, pS, O, C, O, O], - [mS, O, O, O, O, O, C, O], - [O, mS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXYXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, pS], - [O, C, O, O, O, O, pS, O], - [O, O, C, O, O, mS, O, O], - [O, O, O, C, mS, O, O, O], - [O, O, O, pS, C, O, O, O], - [O, O, pS, O, O, C, O, O], - [O, mS, O, O, O, O, C, O], - [mS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXYYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, mIS], - [O, C, O, O, O, O, IS, O], - [O, O, C, O, O, IS, O, O], - [O, O, O, C, mIS, O, O, O], - [O, O, O, mIS, C, O, O, O], - [O, O, IS, O, O, C, O, O], - [O, IS, O, O, O, O, C, O], - [mIS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXYZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, pS, O], - [O, C, O, O, O, O, O, mS], - [O, O, C, O, mS, O, O, O], - [O, O, O, C, O, pS, O, O], - [O, O, pS, O, C, O, O, O], - [O, O, O, mS, O, C, O, O], - [mS, O, O, O, O, O, C, O], - [O, pS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXZIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, IS, O, O, O], - [O, C, O, O, O, IS, O, O], - [O, O, C, O, O, O, mIS, O], - [O, O, O, C, O, O, O, mIS], - [IS, O, O, O, C, O, O, O], - [O, IS, O, O, O, C, O, O], - [O, O, mIS, O, O, O, C, O], - [O, O, O, mIS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXZXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, IS, O, O], - [O, C, O, O, IS, O, O, O], - [O, O, C, O, O, O, O, mIS], - [O, O, O, C, O, O, mIS, O], - [O, IS, O, O, C, O, O, O], - [IS, O, O, O, O, C, O, O], - [O, O, O, mIS, O, O, C, O], - [O, O, mIS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXZYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, pS, O, O], - [O, C, O, O, mS, O, O, O], - [O, O, C, O, O, O, O, mS], - [O, O, O, C, O, O, pS, O], - [O, pS, O, O, C, O, O, O], - [mS, O, O, O, O, C, O, O], - [O, O, O, mS, O, O, C, O], - [O, O, pS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpXZZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, IS, O, O, O], - [O, C, O, O, O, mIS, O, O], - [O, O, C, O, O, O, mIS, O], - [O, O, O, C, O, O, O, IS], - [IS, O, O, O, C, O, O, O], - [O, mIS, O, O, O, C, O, O], - [O, O, mIS, O, O, O, C, O], - [O, O, O, IS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYIIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, pS, O, O, O], - [O, C, O, O, O, pS, O, O], - [O, O, C, O, O, O, pS, O], - [O, O, O, C, O, O, O, pS], - [mS, O, O, O, C, O, O, O], - [O, mS, O, O, O, C, O, O], - [O, O, mS, O, O, O, C, O], - [O, O, O, mS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYIXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, pS, O, O], - [O, C, O, O, pS, O, O, O], - [O, O, C, O, O, O, O, pS], - [O, O, O, C, O, O, pS, O], - [O, mS, O, O, C, O, O, O], - [mS, O, O, O, O, C, O, O], - [O, O, O, mS, O, O, C, O], - [O, O, mS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYIYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, mIS, O, O], - [O, C, O, O, IS, O, O, O], - [O, O, C, O, O, O, O, mIS], - [O, O, O, C, O, O, IS, O], - [O, IS, O, O, C, O, O, O], - [mIS, O, O, O, O, C, O, O], - [O, O, O, IS, O, O, C, O], - [O, O, mIS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYIZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, pS, O, O, O], - [O, C, O, O, O, mS, O, O], - [O, O, C, O, O, O, pS, O], - [O, O, O, C, O, O, O, mS], - [mS, O, O, O, C, O, O, O], - [O, pS, O, O, O, C, O, O], - [O, O, mS, O, O, O, C, O], - [O, O, O, pS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYXIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, pS, O], - [O, C, O, O, O, O, O, pS], - [O, O, C, O, pS, O, O, O], - [O, O, O, C, O, pS, O, O], - [O, O, mS, O, C, O, O, O], - [O, O, O, mS, O, C, O, O], - [mS, O, O, O, O, O, C, O], - [O, mS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYXXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, pS], - [O, C, O, O, O, O, pS, O], - [O, O, C, O, O, pS, O, O], - [O, O, O, C, pS, O, O, O], - [O, O, O, mS, C, O, O, O], - [O, O, mS, O, O, C, O, O], - [O, mS, O, O, O, O, C, O], - [mS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYXYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, mIS], - [O, C, O, O, O, O, IS, O], - [O, O, C, O, O, mIS, O, O], - [O, O, O, C, IS, O, O, O], - [O, O, O, IS, C, O, O, O], - [O, O, mIS, O, O, C, O, O], - [O, IS, O, O, O, O, C, O], - [mIS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYXZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, pS, O], - [O, C, O, O, O, O, O, mS], - [O, O, C, O, pS, O, O, O], - [O, O, O, C, O, mS, O, O], - [O, O, mS, O, C, O, O, O], - [O, O, O, pS, O, C, O, O], - [mS, O, O, O, O, O, C, O], - [O, pS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYYIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, mIS, O], - [O, C, O, O, O, O, O, mIS], - [O, O, C, O, IS, O, O, O], - [O, O, O, C, O, IS, O, O], - [O, O, IS, O, C, O, O, O], - [O, O, O, IS, O, C, O, O], - [mIS, O, O, O, O, O, C, O], - [O, mIS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYYXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, mIS], - [O, C, O, O, O, O, mIS, O], - [O, O, C, O, O, IS, O, O], - [O, O, O, C, IS, O, O, O], - [O, O, O, IS, C, O, O, O], - [O, O, IS, O, O, C, O, O], - [O, mIS, O, O, O, O, C, O], - [mIS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYYYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, O, mS], - [O, C, O, O, O, O, pS, O], - [O, O, C, O, O, pS, O, O], - [O, O, O, C, mS, O, O, O], - [O, O, O, pS, C, O, O, O], - [O, O, mS, O, O, C, O, O], - [O, mS, O, O, O, O, C, O], - [pS, O, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYYZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, O, mIS, O], - [O, C, O, O, O, O, O, IS], - [O, O, C, O, IS, O, O, O], - [O, O, O, C, O, mIS, O, O], - [O, O, IS, O, C, O, O, O], - [O, O, O, mIS, O, C, O, O], - [mIS, O, O, O, O, O, C, O], - [O, IS, O, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYZIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, pS, O, O, O], - [O, C, O, O, O, pS, O, O], - [O, O, C, O, O, O, mS, O], - [O, O, O, C, O, O, O, mS], - [mS, O, O, O, C, O, O, O], - [O, mS, O, O, O, C, O, O], - [O, O, pS, O, O, O, C, O], - [O, O, O, pS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYZXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, pS, O, O], - [O, C, O, O, pS, O, O, O], - [O, O, C, O, O, O, O, mS], - [O, O, O, C, O, O, mS, O], - [O, mS, O, O, C, O, O, O], - [mS, O, O, O, O, C, O, O], - [O, O, O, pS, O, O, C, O], - [O, O, pS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYZYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, O, mIS, O, O], - [O, C, O, O, IS, O, O, O], - [O, O, C, O, O, O, O, IS], - [O, O, O, C, O, O, mIS, O], - [O, IS, O, O, C, O, O, O], - [mIS, O, O, O, O, C, O, O], - [O, O, O, mIS, O, O, C, O], - [O, O, IS, O, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpYZZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, O, pS, O, O, O], - [O, C, O, O, O, mS, O, O], - [O, O, C, O, O, O, mS, O], - [O, O, O, C, O, O, O, pS], - [mS, O, O, O, C, O, O, O], - [O, pS, O, O, O, C, O, O], - [O, O, pS, O, O, O, C, O], - [O, O, O, mS, O, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZIIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Ep, O, O, O, O, O, O], - [O, O, Ep, O, O, O, O, O], - [O, O, O, Ep, O, O, O, O], - [O, O, O, O, Em, O, O, O], - [O, O, O, O, O, Em, O, O], - [O, O, O, O, O, O, Em, O], - [O, O, O, O, O, O, O, Em] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZIXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, IS, O, O, O, O, O, O], - [IS, C, O, O, O, O, O, O], - [O, O, C, IS, O, O, O, O], - [O, O, IS, C, O, O, O, O], - [O, O, O, O, C, mIS, O, O], - [O, O, O, O, mIS, C, O, O], - [O, O, O, O, O, O, C, mIS], - [O, O, O, O, O, O, mIS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZIYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, pS, O, O, O, O, O, O], - [mS, C, O, O, O, O, O, O], - [O, O, C, pS, O, O, O, O], - [O, O, mS, C, O, O, O, O], - [O, O, O, O, C, mS, O, O], - [O, O, O, O, pS, C, O, O], - [O, O, O, O, O, O, C, mS], - [O, O, O, O, O, O, pS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZIZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Em, O, O, O, O, O, O], - [O, O, Ep, O, O, O, O, O], - [O, O, O, Em, O, O, O, O], - [O, O, O, O, Em, O, O, O], - [O, O, O, O, O, Ep, O, O], - [O, O, O, O, O, O, Em, O], - [O, O, O, O, O, O, O, Ep] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZXIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, IS, O, O, O, O, O], - [O, C, O, IS, O, O, O, O], - [IS, O, C, O, O, O, O, O], - [O, IS, O, C, O, O, O, O], - [O, O, O, O, C, O, mIS, O], - [O, O, O, O, O, C, O, mIS], - [O, O, O, O, mIS, O, C, O], - [O, O, O, O, O, mIS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZXXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, IS, O, O, O, O], - [O, C, IS, O, O, O, O, O], - [O, IS, C, O, O, O, O, O], - [IS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, mIS], - [O, O, O, O, O, C, mIS, O], - [O, O, O, O, O, mIS, C, O], - [O, O, O, O, mIS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZXYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, pS, O, O, O, O], - [O, C, mS, O, O, O, O, O], - [O, pS, C, O, O, O, O, O], - [mS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, mS], - [O, O, O, O, O, C, pS, O], - [O, O, O, O, O, mS, C, O], - [O, O, O, O, pS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZXZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, IS, O, O, O, O, O], - [O, C, O, mIS, O, O, O, O], - [IS, O, C, O, O, O, O, O], - [O, mIS, O, C, O, O, O, O], - [O, O, O, O, C, O, mIS, O], - [O, O, O, O, O, C, O, IS], - [O, O, O, O, mIS, O, C, O], - [O, O, O, O, O, IS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZYIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, pS, O, O, O, O, O], - [O, C, O, pS, O, O, O, O], - [mS, O, C, O, O, O, O, O], - [O, mS, O, C, O, O, O, O], - [O, O, O, O, C, O, mS, O], - [O, O, O, O, O, C, O, mS], - [O, O, O, O, pS, O, C, O], - [O, O, O, O, O, pS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZYXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, pS, O, O, O, O], - [O, C, pS, O, O, O, O, O], - [O, mS, C, O, O, O, O, O], - [mS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, mS], - [O, O, O, O, O, C, mS, O], - [O, O, O, O, O, pS, C, O], - [O, O, O, O, pS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZYYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, O, mIS, O, O, O, O], - [O, C, IS, O, O, O, O, O], - [O, IS, C, O, O, O, O, O], - [mIS, O, O, C, O, O, O, O], - [O, O, O, O, C, O, O, IS], - [O, O, O, O, O, C, mIS, O], - [O, O, O, O, O, mIS, C, O], - [O, O, O, O, IS, O, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZYZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, O, pS, O, O, O, O, O], - [O, C, O, mS, O, O, O, O], - [mS, O, C, O, O, O, O, O], - [O, pS, O, C, O, O, O, O], - [O, O, O, O, C, O, mS, O], - [O, O, O, O, O, C, O, pS], - [O, O, O, O, pS, O, C, O], - [O, O, O, O, O, mS, O, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZZIMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Ep, O, O, O, O, O, O], - [O, O, Em, O, O, O, O, O], - [O, O, O, Em, O, O, O, O], - [O, O, O, O, Em, O, O, O], - [O, O, O, O, O, Em, O, O], - [O, O, O, O, O, O, Ep, O], - [O, O, O, O, O, O, O, Ep] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZZXMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, IS, O, O, O, O, O, O], - [IS, C, O, O, O, O, O, O], - [O, O, C, mIS, O, O, O, O], - [O, O, mIS, C, O, O, O, O], - [O, O, O, O, C, mIS, O, O], - [O, O, O, O, mIS, C, O, O], - [O, O, O, O, O, O, C, IS], - [O, O, O, O, O, O, IS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZZYMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [C, pS, O, O, O, O, O, O], - [mS, C, O, O, O, O, O, O], - [O, O, C, mS, O, O, O, O], - [O, O, pS, C, O, O, O, O], - [O, O, O, O, C, mS, O, O], - [O, O, O, O, pS, C, O, O], - [O, O, O, O, O, O, C, pS], - [O, O, O, O, O, O, mS, C] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpZZZMatrix (t : Double) : RowMajorMatrix { - - let O = ZeroC(); - let C = Complex(Cos(t), 0.0); - let IS = Complex(0.0, Sin(t)); - let mIS = Complex(0.0, -Sin(t)); - let pS = Complex(Sin(t), 0.0); - let mS = Complex(-Sin(t), 0.0); - let Ep = ExpIC(t); - let Em = ExpIC(-t); - let matrix = [ - [Ep, O, O, O, O, O, O, O], - [O, Em, O, O, O, O, O, O], - [O, O, Em, O, O, O, O, O], - [O, O, O, Ep, O, O, O, O], - [O, O, O, O, Em, O, O, O], - [O, O, O, O, O, Ep, O, O], - [O, O, O, O, O, O, Ep, O], - [O, O, O, O, O, O, O, Em] - ]; - return RowMajorMatrix(matrix); - } - - - function ExpMultiPauliMatrix (paulies : Pauli[], t : Double) : RowMajorMatrix { - let len = Length(paulies); - - if (len > 3) { - fail $"Pauli arrays of length more than 3 are not supported"; - } - - let index = PauliArrayAsInt(paulies); - let functionLookup = [ - [ExpIMatrix, ExpXMatrix, ExpZMatrix, ExpYMatrix], - [ExpIIMatrix, ExpIXMatrix, ExpIZMatrix, ExpIYMatrix, ExpXIMatrix, ExpXXMatrix, ExpXZMatrix, ExpXYMatrix, ExpZIMatrix, ExpZXMatrix, ExpZZMatrix, ExpZYMatrix, ExpYIMatrix, ExpYXMatrix, ExpYZMatrix, ExpYYMatrix], - [ExpIIIMatrix, ExpIIXMatrix, ExpIIZMatrix, ExpIIYMatrix, ExpIXIMatrix, ExpIXXMatrix, ExpIXZMatrix, ExpIXYMatrix, ExpIZIMatrix, ExpIZXMatrix, ExpIZZMatrix, ExpIZYMatrix, ExpIYIMatrix, ExpIYXMatrix, ExpIYZMatrix, ExpIYYMatrix, ExpXIIMatrix, ExpXIXMatrix, ExpXIZMatrix, ExpXIYMatrix, ExpXXIMatrix, ExpXXXMatrix, ExpXXZMatrix, ExpXXYMatrix, ExpXZIMatrix, ExpXZXMatrix, ExpXZZMatrix, ExpXZYMatrix, ExpXYIMatrix, ExpXYXMatrix, ExpXYZMatrix, ExpXYYMatrix, ExpZIIMatrix, ExpZIXMatrix, ExpZIZMatrix, ExpZIYMatrix, ExpZXIMatrix, ExpZXXMatrix, ExpZXZMatrix, ExpZXYMatrix, ExpZZIMatrix, ExpZZXMatrix, ExpZZZMatrix, ExpZZYMatrix, ExpZYIMatrix, ExpZYXMatrix, ExpZYZMatrix, ExpZYYMatrix, ExpYIIMatrix, ExpYIXMatrix, ExpYIZMatrix, ExpYIYMatrix, ExpYXIMatrix, ExpYXXMatrix, ExpYXZMatrix, ExpYXYMatrix, ExpYZIMatrix, ExpYZXMatrix, ExpYZZMatrix, ExpYZYMatrix, ExpYYIMatrix, ExpYYXMatrix, ExpYYZMatrix, ExpYYYMatrix] - ]; - return (functionLookup[len - 1])[index](t); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs deleted file mode 100644 index b0fec5f655c..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitTestList.qs +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Convert; - - - newtype SingleQubitOperationDescription = ((Qubit => Unit : Adjoint, Controlled), RowMajorMatrix, Int, Bool); - - - function FixesComputationalBasis (record : SingleQubitOperationDescription) : Bool { - - let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; - return fixesComputationalBasis; - } - - - function OperationMap (record : SingleQubitOperationDescription) : (Qubit => Unit : Adjoint, Controlled) { - - let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; - return operationMap; - } - - - function LevelOfCliffordHierarchy (record : SingleQubitOperationDescription) : Int { - - let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; - return levelOfCliffordHierarchy; - } - - - function OperationMatrix (record : SingleQubitOperationDescription) : RowMajorMatrix { - - let (operationMap, operationMatrix, levelOfCliffordHierarchy, fixesComputationalBasis) = record!; - return operationMatrix; - } - - - function OutsideOfClifforfdHirerarchy () : Int { - - return 0x7FFFFFFFFFFFFFFF; - } - - - function ContinuousParameterTestList () : Double[] { - - return [0.1, PI() / 3.0]; - } - - - function RotationsWithDoubleParameterTestList () : SingleQubitOperationDescription[] { - - let list = ContinuousParameterTestList(); - mutable res = new SingleQubitOperationDescription[0]; - - for (phi in list) { - let level = OutsideOfClifforfdHirerarchy(); - set res = res + [ - SingleQubitOperationDescription(Rx(phi, _), ExpPauliMatrix(PauliX, -phi / 2.0), level, false), - SingleQubitOperationDescription(Ry(phi, _), ExpPauliMatrix(PauliY, -phi / 2.0), level, false), - SingleQubitOperationDescription(Rz(phi, _), ExpPauliMatrix(PauliZ, -phi / 2.0), level, true), - SingleQubitOperationDescription(R1(phi, _), R1Matrix(phi), level, true) - ]; - - //TODO: add PauliI here when the bugs are fixed - let paulies = [PauliX, PauliY, PauliZ]; - - for (j in 0 .. Length(paulies) - 1) { - let pauli = paulies[j]; - let fixesCompBasis = j >= 2; - let expOperation = Exp([pauli], phi, _); - set res = res + [ - SingleQubitOperationDescription(R(pauli, phi, _), ExpPauliMatrix(pauli, -phi / 2.0), level, fixesCompBasis), - SingleQubitOperationDescription(OnOneQubitAC(expOperation, _), ExpPauliMatrix(pauli, phi), level, fixesCompBasis) - ]; - } - } - - return res; - } - - - function FracParametersTestList () : (Int, Int)[] { - - mutable res = new (Int, Int)[0]; - - for (i in 0 .. MaxDenomiantorPowerToTest()) { - for (j in 0 .. 2 ^ i) { - set res = res + [(j, i)]; - } - } - - return res; - } - - - function R1FracCliffordHierarchyLevel (num : Int, denomPower : Int) : Int { - if (num == 0) { - return 0; - } - - let (numPowerOfTwo, reducedNum) = PAdicValuation(num, 2); - let denomPowerActual = denomPower - numPowerOfTwo; - - return denomPowerActual <= 0 ? 0 | denomPowerActual; - } - - - function RotationsWithFracParameterTestList () : SingleQubitOperationDescription[] { - - let list = FracParametersTestList(); - mutable res = new SingleQubitOperationDescription[0]; - - for (frac in list) { - let (num, denomPower) = frac; - let r1Level = R1FracCliffordHierarchyLevel(frac); - let rzLevel = MaxI(0, r1Level - 1); - let r1Phi = (PI() * IntAsDouble(num)) * PowD(IntAsDouble(2), IntAsDouble(-denomPower)); - set res = res + [SingleQubitOperationDescription(R1Frac(num, denomPower, _), R1Matrix(r1Phi), r1Level, true)]; - - // TODO: add PauliI here when the bugs are fixed - let paulies = [PauliI, PauliY, PauliZ]; - - for (j in 0 .. Length(paulies) - 1) { - let pauli = paulies[j]; - let fixesCompBasis = j >= 2; - let expOperation = ExpFrac([pauli], num, denomPower, _); - set res = res + [SingleQubitOperationDescription(RFrac(pauli, num, denomPower, _), ExpPauliMatrix(pauli, r1Phi), rzLevel, fixesCompBasis), SingleQubitOperationDescription(OnOneQubitAC(expOperation, _), ExpPauliMatrix(pauli, r1Phi), rzLevel, fixesCompBasis)]; - } - } - - return res; - } - - - function OneQubitTestList () : SingleQubitOperationDescription[] { - - mutable list = [ - (X, PauliMatrix(PauliX), 0, true), - (Y, PauliMatrix(PauliY), 0, true), - (Z, PauliMatrix(PauliZ), 0, true), - (H, HMatrix(), 1, false), - (S, SMatrix(), 1, true), - (T, TMatrix(), 2, true) - ]; - mutable result = new SingleQubitOperationDescription[Length(list)]; - - for (i in 0 .. Length(list) - 1) { - set result = result w/ i <- SingleQubitOperationDescription(list[i]); - } - - set result = result + RotationsWithDoubleParameterTestList(); - set result = result + RotationsWithFracParameterTestList(); - return result; - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs deleted file mode 100644 index a8fe1cf8339..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/OneQubitUnitaries.qs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - open Microsoft.Quantum.Intrinsic; - - - operation OneQubitOperationsTest () : Unit { - - let list = OneQubitTestList(); - - for (test in OneQubitTestList()) { - let shouldExecute = - IsFullSimulator() or - (IsStabilizerSimulator() and LevelOfCliffordHierarchy(test) <= 1) or - (IsReversibleSimulator() and FixesComputationalBasis(test)); - - if (shouldExecute) { - let map = OperationMap(test); - AssertQubitUnitaryWithAdjoint(OperationMatrix(test), map); - Message($"Passed:{map}"); - } - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs deleted file mode 100644 index b9a2b77c406..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/PauliExpectation.qs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite.Math { - open Microsoft.Quantum.Simulation.TestSuite; - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Bitwise; - open Microsoft.Quantum.Convert; - - // Computes expectation of the observable on a given state. - // - // Algorithm is based on the following observations: - // First note that for every bit b, and every single qubit Pauli matrix P - // it is the case that: - // P|b⟩ = iʸ(-1)^(b∧z)|b⊕x⟩, where:, - // x is equal to one when P is X or Y and equal to zero otherwise, we call this function XBit(P) - // z is equal to one when P is Z or Y and equal to zero otherwise, we call this function ZBit(P) - // y is equal to one when P is equal to Y and to zero otherwise, we call this function YCount(P) - // ⊕ is `Xor` - // For tensor product of Paulies P = P₁⊗…⊗Pₙ and multi-qubit states |b⟩=|bₙ…b₁⟩ this generalizes to: - // P|bₙ…b₁⟩ = iʸ⋅(-1)^Parity(b∧z)⋅|b⊕x⟩ where : - // y = Ycount(P) = Ycount(P₁) + … + Ycount(Pₙ), - // x = XBits(P) = (XBit(Pₙ)…XBit(P₁)) is a bitstring of length n - // z = ZBits(P) = (ZBit(Pₙ)…ZBit(P₁)) is a bitstring of length n - // b∧z is bitwise `And` - // b⊕x is bitwise `Xor` - // Parity(aₙ…a) of bitstring aₙ…a₁ is a₁⊕…⊕aₙ - // Using above observations we get: - // ⟨ψ|P|ψ⟩ = ∑ₐⱼ ⟨ψ|a⟩⟨a|P|j⟩⟨j|ψ⟩ = ∑ₐⱼ ⟨ψ|a⟩⟨a|P|j⟩⟨j|ψ⟩ = ∑ₐⱼ ⟨ψ|a⟩⟨a|( iʸ⋅(-1)^Parity(j∧z)⋅|j⊕x⟩ ) ⟨j|ψ⟩ = - // = iʸ⋅∑ⱼ⟨ψ|j⊕x⟩⋅(-1)^Parity(j∧z)⋅⟨j|ψ⟩ - // - // Note the bit order convention used: - // Consider Pauli[] = [ PauliZ, PauliX ]; - // state[2] is ⟨10|ψ⟩ and state[1] is ⟨01|ψ⟩ - // ZBits([ PauliZ, PauliX ]) is 01 in binary - // XBits([ PauliZ, PauliX ]) is 10 in binary - // - function PauliExpectation (observable : Pauli[], state : Vector) : Double { - - - if (Length(observable) == 0) { - fail $"observable array must have Length at least 1"; - } - - if (2 ^ Length(observable) != Length(state!)) { - fail $"size of the state does not match the observable length"; - } - - let xbits = XBits(observable); - let zbits = ZBits(observable); - mutable res = ZeroC(); - let phase = ComplexIPower(YCount(observable)); - - for (j in 0 .. Length(state!) - 1) { - mutable mul = ConjugateC(state![Xor(xbits, j)]); - - // now mul is ⟨ψ|j⊕x⟩ - if (Parity(And(zbits, j)) == 1) { - set mul = MinusC(mul); - } - - // now mul is ⟨ψ|j⊕x⟩⋅(-1)^Parity(j∧z) - // adding ⟨ψ|j⊕x⟩⋅(-1)^Parity(j∧z)⟨j|ψ⟩ to res - set res = PlusC(res, TimesC(mul, state![j])); - } - - let (reRes, imRes) = (TimesC(res, phase))!; - - if (AbsD(imRes) > Accuracy()) { - fail $"the expectation of the observable must be real number"; - } - - return reRes; - } - - - function YCount (observable : Pauli[]) : Int { - - mutable yCount = 0; - - for (i in 0 .. Length(observable) - 1) { - - if (observable[i] == PauliY) { - set yCount = yCount + 1; - } - } - - return yCount; - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs deleted file mode 100644 index 332d0001782..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/SelfTests.qs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite.SelfTests { - - open Microsoft.Quantum.Simulation.TestSuite; - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Math; - - - operation PauliExpectationTestHelper (testData : Int[]) : Unit { - - let len = Length(testData); - - if (len % 2 != 0) { - fail $"testData must have even Length"; - } - - let half = len / 2; - let observable = PauliById(testData[0 .. half - 1]); - let stateIds = testData[half .. len - 1]; - let state = StateById(stateIds); - let expected = ExpectedValueForMultiPauliByStateId(observable, stateIds); - let given = PauliExpectation(observable, state); - - if (AbsD(expected - given) >= Accuracy()) { - fail $"wrong expectation value"; - } - } - - - operation PauliExpectationTest () : Unit { - - let totalQubitsToTest = 4; - - for (i in 1 .. totalQubitsToTest) { - let pauliesBound = MakeConstArray(i, NumberOfPaulies()); - let statesBound = MakeConstArray(i, NumberOfTestStates()); - IterateThroughCartesianProduct(pauliesBound + statesBound, PauliExpectationTestHelper); - } - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb deleted file mode 100644 index 63845e59a02..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TestSuiteCalculations.nb +++ /dev/null @@ -1,1280 +0,0 @@ -(* Copyright (c) Microsoft Corporation. All rights reserved. *) -(* Licensed under the MIT License. *) - -(* Content-type: application/vnd.wolfram.mathematica *) - -(*** Wolfram Notebook File ***) -(* http://www.wolfram.com/nb *) - -(* CreatedBy='Mathematica 11.0' *) - -(*CacheID: 234*) -(* Internal cache information: -NotebookFileLineBreakTest -NotebookFileLineBreakTest -NotebookDataPosition[ 158, 7] -NotebookDataLength[ 73232, 1269] -NotebookOptionsPosition[ 71731, 1213] -NotebookOutlinePosition[ 72074, 1228] -CellTagsIndexPosition[ 72031, 1225] -WindowFrame->Normal*) - -(* Beginning of Notebook Content *) -Notebook[{ - -Cell[CellGroupData[{ -Cell["Prerequisites", "Chapter", - CellChangeTimes->{{3.7184788997811823`*^9, 3.7184789052925544`*^9}}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{ - RowBox[{"{", - RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], "=", - RowBox[{"Table", "[", - RowBox[{ - RowBox[{"PauliMatrix", "[", "k", "]"}], ",", - RowBox[{"{", - RowBox[{"k", ",", "0", ",", "3"}], "}"}]}], "]"}]}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"tp", " ", "=", " ", "KroneckerProduct"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"Dagger", " ", "=", " ", "ConjugateTranspose"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"zeroSt", " ", "=", " ", - RowBox[{"{", - RowBox[{"1", ",", "0"}], "}"}]}], ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"oneSt", " ", "=", " ", - RowBox[{"{", - RowBox[{"0", ",", "1"}], "}"}]}], ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"plusSt", " ", "=", - RowBox[{ - RowBox[{"{", - RowBox[{"1", ",", "1"}], "}"}], "/", - RowBox[{"Sqrt", "[", "2", "]"}]}]}], ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"iSt", " ", "=", " ", - RowBox[{ - RowBox[{"{", - RowBox[{"1", ",", "I"}], "}"}], "/", - RowBox[{"Sqrt", "[", "2", "]"}]}]}], ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"DensityMatr", "[", "x_", "]"}], ":=", - RowBox[{ - RowBox[{ - RowBox[{"Dagger", "[", - RowBox[{"{", "x", "}"}], "]"}], ".", - RowBox[{"{", "x", "}"}]}], "//", "Transpose"}]}], "\[IndentingNewLine]", - RowBox[{"(*", " ", - RowBox[{ - "This", " ", "is", " ", "ordering", " ", "used", " ", "everywhere", " ", - "in", " ", "the", " ", "TestSuite"}], " ", - "*)"}]}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"fullBasis", " ", "=", " ", - RowBox[{"{", - RowBox[{"zeroSt", ",", "oneSt", ",", "plusSt", ",", "iSt"}], "}"}]}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"AsQDoubleArr", "[", "l_List", "]"}], ":=", " ", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"ToString", "[", - RowBox[{"CForm", "[", - RowBox[{"N", "[", "#", "]"}], "]"}], "]"}], "&"}], "/@", "l"}], "//", - RowBox[{ - RowBox[{"Riffle", "[", - RowBox[{"#", ",", "\"\<;\>\""}], "]"}], "&"}]}], "//", "StringJoin"}], - "//", - RowBox[{ - RowBox[{"(", - RowBox[{"\"\<[\>\"", "~~", "#", "~~", "\"\<]\>\""}], ")"}], - "&"}]}]}]}], "Input", - CellChangeTimes->{{3.718478910443024*^9, 3.718479218281523*^9}, { - 3.718479248879512*^9, 3.718479263034215*^9}, {3.7184793975740213`*^9, - 3.7184795991372766`*^9}, {3.7184796315949745`*^9, 3.7184797046591806`*^9}, { - 3.7184798375361357`*^9, 3.7184798433353157`*^9}, {3.7184800446945333`*^9, - 3.718480077458357*^9}, {3.7187181677029185`*^9, 3.718718172473008*^9}}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{ - RowBox[{"AsQArr", "[", - RowBox[{"s_String", ",", " ", "level_"}], " ", "]"}], ":=", " ", "s"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"AsQArr", "[", - RowBox[{"0", ",", " ", "level_"}], " ", "]"}], ":=", " ", "\"\< O\>\""}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"AsQArr", "[", - RowBox[{"l_List", ",", " ", - RowBox[{"level_", " ", ":", " ", "0"}]}], " ", "]"}], ":=", " ", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"AsQArr", "[", - RowBox[{"#", ",", " ", - RowBox[{"level", "+", "1"}]}], " ", "]"}], "&"}], "/@", "l"}], "//", - RowBox[{ - RowBox[{"Riffle", "[", - RowBox[{"#", ",", - RowBox[{"If", "[", - RowBox[{ - RowBox[{"level", "\[Equal]", "0"}], ",", "\"\<;\\n\>\"", ",", - "\"\<;\>\""}], "]"}]}], "]"}], "&"}]}], "//", "\[IndentingNewLine]", - "StringJoin"}], "//", - RowBox[{ - RowBox[{"(", - RowBox[{ - RowBox[{"If", "[", - RowBox[{ - RowBox[{"level", "\[Equal]", "1"}], ",", "\"\< [\>\"", ",", - "\"\<[\>\""}], "]"}], "~~", "#", "~~", "\"\<]\>\""}], ")"}], - "&"}]}]}]}], "Input", - CellChangeTimes->{{3.718717964864356*^9, 3.718718020613718*^9}, { - 3.7187181124608784`*^9, 3.7187181126268125`*^9}, {3.7187181784710913`*^9, - 3.718718185125663*^9}, {3.718718237591975*^9, 3.7187182861989775`*^9}, { - 3.718718351396096*^9, 3.7187184780481606`*^9}, 3.718720367009722*^9}], - -Cell[BoxData[""], "Input", - CellChangeTimes->{{3.718718297010992*^9, 3.7187182978963203`*^9}}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell["PauliExpectation.qs", "Chapter", - CellChangeTimes->{3.7184788834158244`*^9, 3.7186466473395104`*^9}], - -Cell[CellGroupData[{ - -Cell["ExpectedValueForPauli", "Section", - CellChangeTimes->{{3.7184788926643867`*^9, 3.7184788949642396`*^9}, - 3.718646644697502*^9}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{ - RowBox[{"State", "[", "True", "]"}], "=", "oneSt"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"State", "[", "False", "]"}], "=", "zeroSt"}], ";"}], - "\[IndentingNewLine]"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"XBit", "[", "X", "]"}], "=", "True"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"XBit", "[", "Y", "]"}], "=", "True"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"XBit", "[", "Z", "]"}], "=", "False"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"XBit", "[", "Id", "]"}], "=", "False"}], ";"}], - "\[IndentingNewLine]"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"ZBit", "[", "X", "]"}], "=", "False"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"ZBit", "[", "Y", "]"}], "=", "True"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"ZBit", "[", "Z", "]"}], "=", "True"}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"ZBit", "[", "Id", "]"}], "=", "False"}], ";"}], - "\[IndentingNewLine]"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"Ycount", "[", "X", "]"}], "=", "0"}], ";", - RowBox[{ - RowBox[{"Ycount", "[", "Y", "]"}], "=", "1"}], ";", - RowBox[{ - RowBox[{"Ycount", "[", "Z", "]"}], "=", "0"}], ";", - RowBox[{ - RowBox[{"Ycount", "[", "Id", "]"}], "=", "0"}], ";"}]}], "Input", - CellChangeTimes->{{3.718646175503356*^9, 3.7186462656794095`*^9}, { - 3.7186463504314127`*^9, 3.718646405243431*^9}}], - -Cell[BoxData[ - RowBox[{ - RowBox[{ - RowBox[{"FormulaCheck", "[", - RowBox[{"{", " ", - RowBox[{"pauli_", ",", " ", "stateBit_"}], "}"}], "]"}], ":=", " ", - "\[IndentingNewLine]", - RowBox[{ - RowBox[{"pauli", ".", - RowBox[{"State", "[", "stateBit", "]"}]}], "\[Equal]", - "\[IndentingNewLine]", - RowBox[{ - RowBox[{"I", "^", - RowBox[{"Ycount", "[", "pauli", "]"}]}], - RowBox[{ - RowBox[{"(", - RowBox[{"-", "1"}], ")"}], "^", - RowBox[{"Boole", "[", " ", - RowBox[{"And", "[", - RowBox[{"stateBit", ",", " ", - RowBox[{"ZBit", "[", "pauli", "]"}]}], "]"}], " ", "]"}]}], " ", - RowBox[{"State", "[", " ", - RowBox[{"Xor", "[", - RowBox[{"stateBit", " ", ",", - RowBox[{"XBit", "[", "pauli", "]"}]}], "]"}], "]"}]}]}]}], - ";"}]], "Input", - CellChangeTimes->{{3.7186462761153984`*^9, 3.7186463430594215`*^9}, { - 3.718646416155429*^9, 3.718646552232479*^9}, {3.7186465964045043`*^9, - 3.718646634713516*^9}, {3.7186467638007994`*^9, 3.718646769583794*^9}}], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{ - RowBox[{"FormulaCheck", "/@", - RowBox[{"Tuples", "[", - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", - RowBox[{"{", - RowBox[{"True", ",", "False"}], "}"}]}], "}"}], "]"}]}], "//", - RowBox[{ - RowBox[{"And", "@@", "#"}], "&"}]}]], "Input", - CellChangeTimes->{{3.7186466565775075`*^9, 3.7186467799667997`*^9}}], - -Cell[BoxData["True"], "Output", - CellChangeTimes->{{3.718646693228776*^9, 3.718646703477778*^9}, { - 3.7186467381937866`*^9, 3.7186467806398077`*^9}, 3.7187175759767003`*^9, - 3.718718432580945*^9, 3.718720392855904*^9, 3.718720697142393*^9}] -}, Open ]] -}, Open ]] -}, Open ]], - -Cell[CellGroupData[{ - -Cell["Matrices.qb", "Chapter", - CellChangeTimes->{ - 3.7184788834158244`*^9, 3.7186466473395104`*^9, {3.7187204172956123`*^9, - 3.718720418865557*^9}}], - -Cell[BoxData[ - RowBox[{ - RowBox[{ - RowBox[{"PauliExpPiece", "[", "paulies__", "]"}], ":=", " ", - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{ - RowBox[{"MatrixExp", "[", - RowBox[{"I", " ", "t", " ", - RowBox[{"tp", "[", "paulies", "]"}]}], "]"}], "/.", - "\[IndentingNewLine]", - RowBox[{"{", - RowBox[{ - RowBox[{ - RowBox[{"Exp", "[", - RowBox[{"I", " ", "t"}], "]"}], "\[Rule]", "\"\< Ep\>\""}], ",", - RowBox[{ - RowBox[{"Exp", "[", - RowBox[{ - RowBox[{"-", "I"}], " ", "t"}], "]"}], "\[Rule]", "\"\< Em\>\""}], - ",", - RowBox[{ - RowBox[{"I", " ", - RowBox[{"Sin", "[", "t", "]"}]}], "\[Rule]", " ", "\"\< IS\>\""}], - ",", " ", "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"-", "I"}], " ", - RowBox[{"Sin", "[", "t", "]"}]}], "\[Rule]", " ", "\"\\""}], - ",", - RowBox[{ - RowBox[{"Cos", "[", "t", "]"}], "\[Rule]", "\"\< C\>\""}], " ", - ",", - RowBox[{ - RowBox[{"Sin", "[", "t", "]"}], "\[Rule]", "\"\< pS\>\""}], ",", - RowBox[{ - RowBox[{"-", - RowBox[{"Sin", "[", "t", "]"}]}], "\[Rule]", "\"\< mS\>\""}]}], - "}"}]}], "//", - RowBox[{ - RowBox[{"AsQArr", "[", - RowBox[{"#", ",", "0"}], "]"}], "&"}]}], "//", - RowBox[{ - RowBox[{"StringReplace", "[", - RowBox[{"#", ",", - RowBox[{"\"\<[ [\>\"", "\[Rule]", "\"\< [[\>\""}]}], "]"}], - "&"}]}], "//", - RowBox[{ - RowBox[{"#", "~~", "\"\<;\\n\>\""}], "&"}]}]}], ";"}]], "Input", - CellChangeTimes->{{3.7187175797173595`*^9, 3.7187176146904716`*^9}, { - 3.7187176953540573`*^9, 3.7187177203616886`*^9}, {3.7187177626100025`*^9, - 3.7187179305017643`*^9}, {3.7187180027673273`*^9, - 3.7187180030132246`*^9}, {3.7187180457732887`*^9, - 3.7187181492506723`*^9}, {3.7187183149004974`*^9, 3.7187183193089037`*^9}, - 3.7187183573407354`*^9, {3.718718509074959*^9, 3.7187185614713545`*^9}, { - 3.7187187394897165`*^9, 3.7187187413639545`*^9}, {3.718718842163275*^9, - 3.718718843930902*^9}, {3.718718957950756*^9, 3.7187189622513447`*^9}, { - 3.7187201074064493`*^9, 3.718720145185424*^9}, {3.7187203726301537`*^9, - 3.7187203802452*^9}, {3.7187204309115763`*^9, 3.71872045656062*^9}, { - 3.7187206381508117`*^9, 3.718720638510955*^9}, {3.7187206925751505`*^9, - 3.7187206931353016`*^9}, {3.7187210087938433`*^9, 3.7187210392313623`*^9}}], - -Cell[BoxData[{ - RowBox[{ - RowBox[{ - RowBox[{"StringOfPauli", "[", "X", "]"}], "=", "\"\\""}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"StringOfPauli", "[", "Y", "]"}], "=", "\"\\""}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"StringOfPauli", "[", "Z", "]"}], "=", "\"\\""}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"StringOfPauli", "[", "Id", "]"}], "=", "\"\\""}], - ";"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{ - RowBox[{"PauliStringPiece", "[", "paulies__", "]"}], ":=", - RowBox[{ - RowBox[{"StringOfPauli", "/@", " ", - RowBox[{"List", "[", "paulies", "]"}]}], "//", "StringJoin"}]}], - ";"}]}], "Input", - CellChangeTimes->{{3.718720298600816*^9, 3.7187203366639442`*^9}, { - 3.7187204829800806`*^9, 3.7187205222502007`*^9}}], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"PauliExpPiece", "[", - RowBox[{"X", ",", "X", ",", "Z"}], "]"}]], "Input", - CellChangeTimes->{{3.7187204648372355`*^9, 3.7187204732011013`*^9}}], - -Cell[BoxData["\<\" [[ C; O; O; O; O; O; IS; O];\\n [ O; C; \ -O; O; O; O; O;mIS];\\n [ O; O; C; O; IS; O; O; O];\\n [ \ -O; O; O; C; O;mIS; O; O];\\n [ O; O; IS; O; C; O; O; O];\\n \ - [ O; O; O;mIS; O; C; O; O];\\n [ IS; O; O; O; O; O; C; \ -O];\\n [ O;mIS; O; O; O; O; O; C]];\\n\"\>"], "Output", - CellChangeTimes->{{3.718720468745313*^9, 3.718720473543486*^9}, - 3.71872069721196*^9, 3.7187210419218025`*^9}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"PauliStringPiece", "[", - RowBox[{"X", ",", "X", ",", "Z"}], "]"}]], "Input", - CellChangeTimes->{{3.7187205263700495`*^9, 3.718720533483435*^9}}], - -Cell[BoxData["\<\"XXZ\"\>"], "Output", - CellChangeTimes->{{3.7187205284171534`*^9, 3.718720534220138*^9}, - 3.7187206972275934`*^9}] -}, Open ]], - -Cell[BoxData[ - RowBox[{ - RowBox[{"PauliCode", "[", - RowBox[{"{", "paulies__", "}"}], "]"}], ":=", " ", "\[IndentingNewLine]", - RowBox[{"\"\\"", "~~", - RowBox[{"PauliStringPiece", "[", "paulies", "]"}], "~~", - "\"\\"", "~~", - RowBox[{"PauliExpPiece", "[", "paulies", "]"}], "~~", " ", "\n", " ", - "\"\< return matrix;\n}\\n\\n\>\""}]}]], "Input", - CellChangeTimes->{{3.718720547880199*^9, 3.718720731594817*^9}, { - 3.7187208838835783`*^9, 3.7187208860611715`*^9}, 3.7187209979137883`*^9, { - 3.7187210702636576`*^9, 3.718721086937796*^9}}], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"\[IndentingNewLine]", "\[IndentingNewLine]", - RowBox[{ - RowBox[{"(", - RowBox[{ - RowBox[{"PauliCode", "/@", - RowBox[{"Tuples", "[", - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", - RowBox[{"{", - RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}]}], "}"}], - "]"}]}], "//", "StringJoin"}], ")"}], "~~", "\[IndentingNewLine]", - RowBox[{"(", - RowBox[{ - RowBox[{"PauliCode", "/@", - RowBox[{"Tuples", "[", - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", - RowBox[{"{", - RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}], ",", - RowBox[{"{", - RowBox[{"Id", ",", "X", ",", "Y", ",", "Z"}], "}"}]}], "}"}], - "]"}]}], "//", "StringJoin"}], ")"}]}]}]], "Input", - CellChangeTimes->{{3.718720839316888*^9, 3.71872086218427*^9}, - 3.7187208973565545`*^9, {3.7187210496532717`*^9, 3.718721053305811*^9}, { - 3.7187212427277174`*^9, 3.7187212559646535`*^9}, {3.718721333366556*^9, - 3.718721361491644*^9}, {3.718727871584074*^9, 3.718727883288909*^9}, { - 3.718728040638919*^9, 3.7187281144712653`*^9}}], - -Cell[BoxData["\<\"function ExpIIMatrix( t: Double ) : Complex[][] {\\n let \ -O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ -Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ -Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ -O];\\n [ O; Ep; O; O];\\n [ O; O; Ep; O];\\n [ O; O; O; \ -Ep]];\\n return matrix;\\n}\\n\\nfunction ExpIXMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ -O];\\n [ IS; C; O; O];\\n [ O; O; C; IS];\\n [ O; O; IS; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpIYMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; O; \ -O];\\n [ mS; C; O; O];\\n [ O; O; C; pS];\\n [ O; O; mS; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpIZMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ -O];\\n [ O; Em; O; O];\\n [ O; O; Ep; O];\\n [ O; O; O; \ -Em]];\\n return matrix;\\n}\\n\\nfunction ExpXIMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; IS; \ -O];\\n [ O; C; O; IS];\\n [ IS; O; C; O];\\n [ O; IS; O; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpXXMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ -IS];\\n [ O; C; IS; O];\\n [ O; IS; C; O];\\n [ IS; O; O; \ - C]];\\n return matrix;\\n}\\n\\nfunction ExpXYMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ -pS];\\n [ O; C; mS; O];\\n [ O; pS; C; O];\\n [ mS; O; O; \ - C]];\\n return matrix;\\n}\\n\\nfunction ExpXZMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; IS; \ -O];\\n [ O; C; O;mIS];\\n [ IS; O; C; O];\\n [ O;mIS; O; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpYIMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; pS; \ -O];\\n [ O; C; O; pS];\\n [ mS; O; C; O];\\n [ O; mS; O; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpYXMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ -pS];\\n [ O; C; pS; O];\\n [ O; mS; C; O];\\n [ mS; O; O; \ - C]];\\n return matrix;\\n}\\n\\nfunction ExpYYMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ -O;mIS];\\n [ O; C; IS; O];\\n [ O; IS; C; O];\\n [mIS; O; \ -O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; pS; \ -O];\\n [ O; C; O; mS];\\n [ mS; O; C; O];\\n [ O; pS; O; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpZIMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ -O];\\n [ O; Ep; O; O];\\n [ O; O; Em; O];\\n [ O; O; O; \ -Em]];\\n return matrix;\\n}\\n\\nfunction ExpZXMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ -O];\\n [ IS; C; O; O];\\n [ O; O; C;mIS];\\n [ O; O;mIS; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpZYMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; O; \ -O];\\n [ mS; C; O; O];\\n [ O; O; C; mS];\\n [ O; O; pS; \ -C]];\\n return matrix;\\n}\\n\\nfunction ExpZZMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ -O];\\n [ O; Em; O; O];\\n [ O; O; Em; O];\\n [ O; O; O; \ -Ep]];\\n return matrix;\\n}\\n\\nfunction ExpIIIMatrix( t: Double ) : \ -Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ -let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let \ -pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; O; \ -O; O; O; O; O];\\n [ O; Ep; O; O; O; O; O; O];\\n [ O; \ -O; Ep; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ -[ O; O; O; O; Ep; O; O; O];\\n [ O; O; O; O; O; Ep; O; \ -O];\\n [ O; O; O; O; O; O; Ep; O];\\n [ O; O; O; O; O; \ -O; O; Ep]];\\n return matrix;\\n}\\n\\nfunction ExpIIXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; \ - O; O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ \ -O; O; C; IS; O; O; O; O];\\n [ O; O; IS; C; O; O; O; O];\\n \ - [ O; O; O; O; C; IS; O; O];\\n [ O; O; O; O; IS; C; O; \ -O];\\n [ O; O; O; O; O; O; C; IS];\\n [ O; O; O; O; O; \ -O; IS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIIYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ - O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ -O; O; C; pS; O; O; O; O];\\n [ O; O; mS; C; O; O; O; O];\\n \ - [ O; O; O; O; C; pS; O; O];\\n [ O; O; O; O; mS; C; O; \ -O];\\n [ O; O; O; O; O; O; C; pS];\\n [ O; O; O; O; O; \ -O; mS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIIZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ - O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ -O; O; Ep; O; O; O; O; O];\\n [ O; O; O; Em; O; O; O; O];\\n \ - [ O; O; O; O; Ep; O; O; O];\\n [ O; O; O; O; O; Em; O; \ -O];\\n [ O; O; O; O; O; O; Ep; O];\\n [ O; O; O; O; O; \ -O; O; Em]];\\n return matrix;\\n}\\n\\nfunction ExpIXIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ -IS; O; O; O; O; O];\\n [ O; C; O; IS; O; O; O; O];\\n [ \ -IS; O; C; O; O; O; O; O];\\n [ O; IS; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O; IS; O];\\n [ O; O; O; O; O; C; O; \ -IS];\\n [ O; O; O; O; IS; O; C; O];\\n [ O; O; O; O; O; \ -IS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIXXMatrix( t: Double \ -) : Complex[][] {\\n let O = ZeroC();\\n let C = \ -Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ -Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ -Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ - let matrix = \\n [[ C; O; O; IS; O; O; O; O];\\n [ O; C; IS; \ - O; O; O; O; O];\\n [ O; IS; C; O; O; O; O; O];\\n [ IS; \ -O; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; O; IS];\\n \ -[ O; O; O; O; O; C; IS; O];\\n [ O; O; O; O; O; IS; C; \ -O];\\n [ O; O; O; O; IS; O; O; C]];\\n return \ -matrix;\\n}\\n\\nfunction ExpIXYMatrix( t: Double ) : Complex[][] {\\n let \ -O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ -Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ -Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ -pS; O; O; O; O];\\n [ O; C; mS; O; O; O; O; O];\\n [ O; \ -pS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ -[ O; O; O; O; C; O; O; pS];\\n [ O; O; O; O; O; C; mS; \ -O];\\n [ O; O; O; O; O; pS; C; O];\\n [ O; O; O; O; mS; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIXZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ -IS; O; O; O; O; O];\\n [ O; C; O;mIS; O; O; O; O];\\n [ \ -IS; O; C; O; O; O; O; O];\\n [ O;mIS; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O; IS; O];\\n [ O; O; O; O; O; C; \ -O;mIS];\\n [ O; O; O; O; IS; O; C; O];\\n [ O; O; O; O; \ -O;mIS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIYIMatrix( t: \ -Double ) : Complex[][] {\\n let O = ZeroC();\\n let C = \ -Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ -Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ -Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ - let matrix = \\n [[ C; O; pS; O; O; O; O; O];\\n [ O; C; O; \ -pS; O; O; O; O];\\n [ mS; O; C; O; O; O; O; O];\\n [ O; \ -mS; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; pS; O];\\n \ -[ O; O; O; O; O; C; O; pS];\\n [ O; O; O; O; mS; O; C; \ -O];\\n [ O; O; O; O; O; mS; O; C]];\\n return \ -matrix;\\n}\\n\\nfunction ExpIYXMatrix( t: Double ) : Complex[][] {\\n let \ -O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ -Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ -Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ -pS; O; O; O; O];\\n [ O; C; pS; O; O; O; O; O];\\n [ O; \ -mS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ -[ O; O; O; O; C; O; O; pS];\\n [ O; O; O; O; O; C; pS; \ -O];\\n [ O; O; O; O; O; mS; C; O];\\n [ O; O; O; O; mS; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIYYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O;mIS; O; O; O; O];\\n [ O; C; IS; O; O; O; O; O];\\n [ \ -O; IS; C; O; O; O; O; O];\\n [mIS; O; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O; O;mIS];\\n [ O; O; O; O; O; C; IS; \ -O];\\n [ O; O; O; O; O; IS; C; O];\\n [ O; O; O; O;mIS; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIYZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ -pS; O; O; O; O; O];\\n [ O; C; O; mS; O; O; O; O];\\n [ \ -mS; O; C; O; O; O; O; O];\\n [ O; pS; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O; pS; O];\\n [ O; O; O; O; O; C; O; \ -mS];\\n [ O; O; O; O; mS; O; C; O];\\n [ O; O; O; O; O; \ -pS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpIZIMatrix( t: Double \ -) : Complex[][] {\\n let O = ZeroC();\\n let C = \ -Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ -Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ -Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ - let matrix = \\n [[ Ep; O; O; O; O; O; O; O];\\n [ O; Ep; O; \ - O; O; O; O; O];\\n [ O; O; Em; O; O; O; O; O];\\n [ O; \ -O; O; Em; O; O; O; O];\\n [ O; O; O; O; Ep; O; O; O];\\n \ -[ O; O; O; O; O; Ep; O; O];\\n [ O; O; O; O; O; O; Em; \ -O];\\n [ O; O; O; O; O; O; O; Em]];\\n return \ -matrix;\\n}\\n\\nfunction ExpIZXMatrix( t: Double ) : Complex[][] {\\n let \ -O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ -Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ -Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ -O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ O; \ -O; C;mIS; O; O; O; O];\\n [ O; O;mIS; C; O; O; O; O];\\n \ -[ O; O; O; O; C; IS; O; O];\\n [ O; O; O; O; IS; C; O; \ -O];\\n [ O; O; O; O; O; O; C;mIS];\\n [ O; O; O; O; O; \ -O;mIS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIZYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ - O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ -O; O; C; mS; O; O; O; O];\\n [ O; O; pS; C; O; O; O; O];\\n \ - [ O; O; O; O; C; pS; O; O];\\n [ O; O; O; O; mS; C; O; \ -O];\\n [ O; O; O; O; O; O; C; mS];\\n [ O; O; O; O; O; \ -O; pS; C]];\\n return matrix;\\n}\\n\\nfunction ExpIZZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ - O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ -O; O; Em; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ - [ O; O; O; O; Ep; O; O; O];\\n [ O; O; O; O; O; Em; O; \ -O];\\n [ O; O; O; O; O; O; Em; O];\\n [ O; O; O; O; O; \ -O; O; Ep]];\\n return matrix;\\n}\\n\\nfunction ExpXIIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; IS; O; O; O];\\n [ O; C; O; O; O; IS; O; O];\\n [ \ -O; O; C; O; O; O; IS; O];\\n [ O; O; O; C; O; O; O; IS];\\n \ - [ IS; O; O; O; C; O; O; O];\\n [ O; IS; O; O; O; C; O; \ -O];\\n [ O; O; IS; O; O; O; C; O];\\n [ O; O; O; IS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXIXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; IS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ -O; O; C; O; O; O; O; IS];\\n [ O; O; O; C; O; O; IS; O];\\n \ - [ O; IS; O; O; C; O; O; O];\\n [ IS; O; O; O; O; C; O; \ -O];\\n [ O; O; O; IS; O; O; C; O];\\n [ O; O; IS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXIYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; pS; O; O];\\n [ O; C; O; O; mS; O; O; O];\\n [ \ -O; O; C; O; O; O; O; pS];\\n [ O; O; O; C; O; O; mS; O];\\n \ - [ O; pS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ -O];\\n [ O; O; O; pS; O; O; C; O];\\n [ O; O; mS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXIZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; IS; O; O; O];\\n [ O; C; O; O; O;mIS; O; O];\\n [ \ -O; O; C; O; O; O; IS; O];\\n [ O; O; O; C; O; O; O;mIS];\\n \ - [ IS; O; O; O; C; O; O; O];\\n [ O;mIS; O; O; O; C; O; \ -O];\\n [ O; O; IS; O; O; O; C; O];\\n [ O; O; O;mIS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; IS; O];\\n [ O; C; O; O; O; O; O; IS];\\n [ \ -O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O; IS; O; O];\\n \ - [ O; O; IS; O; C; O; O; O];\\n [ O; O; O; IS; O; C; O; \ -O];\\n [ IS; O; O; O; O; O; C; O];\\n [ O; IS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O; IS];\\n [ O; C; O; O; O; O; IS; O];\\n [ \ -O; O; C; O; O; IS; O; O];\\n [ O; O; O; C; IS; O; O; O];\\n \ - [ O; O; O; IS; C; O; O; O];\\n [ O; O; IS; O; O; C; O; \ -O];\\n [ O; IS; O; O; O; O; C; O];\\n [ IS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O; pS];\\n [ O; C; O; O; O; O; mS; O];\\n [ \ -O; O; C; O; O; pS; O; O];\\n [ O; O; O; C; mS; O; O; O];\\n \ - [ O; O; O; pS; C; O; O; O];\\n [ O; O; mS; O; O; C; O; \ -O];\\n [ O; pS; O; O; O; O; C; O];\\n [ mS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXXZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; IS; O];\\n [ O; C; O; O; O; O; O;mIS];\\n [ \ -O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O;mIS; O; O];\\n \ - [ O; O; IS; O; C; O; O; O];\\n [ O; O; O;mIS; O; C; O; \ -O];\\n [ IS; O; O; O; O; O; C; O];\\n [ O;mIS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; pS];\\n [ \ -O; O; C; O; mS; O; O; O];\\n [ O; O; O; C; O; mS; O; O];\\n \ - [ O; O; pS; O; C; O; O; O];\\n [ O; O; O; pS; O; C; O; \ -O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; mS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O; pS];\\n [ O; C; O; O; O; O; pS; O];\\n [ \ -O; O; C; O; O; mS; O; O];\\n [ O; O; O; C; mS; O; O; O];\\n \ - [ O; O; O; pS; C; O; O; O];\\n [ O; O; pS; O; O; C; O; \ -O];\\n [ O; mS; O; O; O; O; C; O];\\n [ mS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O;mIS];\\n [ O; C; O; O; O; O; IS; O];\\n [ \ -O; O; C; O; O; IS; O; O];\\n [ O; O; O; C;mIS; O; O; O];\\n \ - [ O; O; O;mIS; C; O; O; O];\\n [ O; O; IS; O; O; C; O; \ -O];\\n [ O; IS; O; O; O; O; C; O];\\n [mIS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXYZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; mS];\\n [ \ -O; O; C; O; mS; O; O; O];\\n [ O; O; O; C; O; pS; O; O];\\n \ - [ O; O; pS; O; C; O; O; O];\\n [ O; O; O; mS; O; C; O; \ -O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; pS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; IS; O; O; O];\\n [ O; C; O; O; O; IS; O; O];\\n [ \ -O; O; C; O; O; O;mIS; O];\\n [ O; O; O; C; O; O; O;mIS];\\n \ - [ IS; O; O; O; C; O; O; O];\\n [ O; IS; O; O; O; C; O; \ -O];\\n [ O; O;mIS; O; O; O; C; O];\\n [ O; O; O;mIS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; IS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ -O; O; C; O; O; O; O;mIS];\\n [ O; O; O; C; O; O;mIS; O];\\n \ - [ O; IS; O; O; C; O; O; O];\\n [ IS; O; O; O; O; C; O; \ -O];\\n [ O; O; O;mIS; O; O; C; O];\\n [ O; O;mIS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; pS; O; O];\\n [ O; C; O; O; mS; O; O; O];\\n [ \ -O; O; C; O; O; O; O; mS];\\n [ O; O; O; C; O; O; pS; O];\\n \ - [ O; pS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ -O];\\n [ O; O; O; mS; O; O; C; O];\\n [ O; O; pS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpXZZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; IS; O; O; O];\\n [ O; C; O; O; O;mIS; O; O];\\n [ \ -O; O; C; O; O; O;mIS; O];\\n [ O; O; O; C; O; O; O; IS];\\n \ - [ IS; O; O; O; C; O; O; O];\\n [ O;mIS; O; O; O; C; O; \ -O];\\n [ O; O;mIS; O; O; O; C; O];\\n [ O; O; O; IS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; pS; O; O; O];\\n [ O; C; O; O; O; pS; O; O];\\n [ \ -O; O; C; O; O; O; pS; O];\\n [ O; O; O; C; O; O; O; pS];\\n \ - [ mS; O; O; O; C; O; O; O];\\n [ O; mS; O; O; O; C; O; \ -O];\\n [ O; O; mS; O; O; O; C; O];\\n [ O; O; O; mS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; pS; O; O];\\n [ O; C; O; O; pS; O; O; O];\\n [ \ -O; O; C; O; O; O; O; pS];\\n [ O; O; O; C; O; O; pS; O];\\n \ - [ O; mS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ -O];\\n [ O; O; O; mS; O; O; C; O];\\n [ O; O; mS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O;mIS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ -O; O; C; O; O; O; O;mIS];\\n [ O; O; O; C; O; O; IS; O];\\n \ - [ O; IS; O; O; C; O; O; O];\\n [mIS; O; O; O; O; C; O; \ -O];\\n [ O; O; O; IS; O; O; C; O];\\n [ O; O;mIS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYIZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; pS; O; O; O];\\n [ O; C; O; O; O; mS; O; O];\\n [ \ -O; O; C; O; O; O; pS; O];\\n [ O; O; O; C; O; O; O; mS];\\n \ - [ mS; O; O; O; C; O; O; O];\\n [ O; pS; O; O; O; C; O; \ -O];\\n [ O; O; mS; O; O; O; C; O];\\n [ O; O; O; pS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; pS];\\n [ \ -O; O; C; O; pS; O; O; O];\\n [ O; O; O; C; O; pS; O; O];\\n \ - [ O; O; mS; O; C; O; O; O];\\n [ O; O; O; mS; O; C; O; \ -O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; mS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O; pS];\\n [ O; C; O; O; O; O; pS; O];\\n [ \ -O; O; C; O; O; pS; O; O];\\n [ O; O; O; C; pS; O; O; O];\\n \ - [ O; O; O; mS; C; O; O; O];\\n [ O; O; mS; O; O; C; O; \ -O];\\n [ O; mS; O; O; O; O; C; O];\\n [ mS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O;mIS];\\n [ O; C; O; O; O; O; IS; O];\\n [ \ -O; O; C; O; O;mIS; O; O];\\n [ O; O; O; C; IS; O; O; O];\\n \ - [ O; O; O; IS; C; O; O; O];\\n [ O; O;mIS; O; O; C; O; \ -O];\\n [ O; IS; O; O; O; O; C; O];\\n [mIS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYXZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; pS; O];\\n [ O; C; O; O; O; O; O; mS];\\n [ \ -O; O; C; O; pS; O; O; O];\\n [ O; O; O; C; O; mS; O; O];\\n \ - [ O; O; mS; O; C; O; O; O];\\n [ O; O; O; pS; O; C; O; \ -O];\\n [ mS; O; O; O; O; O; C; O];\\n [ O; pS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O;mIS; O];\\n [ O; C; O; O; O; O; O;mIS];\\n [ \ -O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O; IS; O; O];\\n \ - [ O; O; IS; O; C; O; O; O];\\n [ O; O; O; IS; O; C; O; \ -O];\\n [mIS; O; O; O; O; O; C; O];\\n [ O;mIS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O;mIS];\\n [ O; C; O; O; O; O;mIS; O];\\n [ \ -O; O; C; O; O; IS; O; O];\\n [ O; O; O; C; IS; O; O; O];\\n \ - [ O; O; O; IS; C; O; O; O];\\n [ O; O; IS; O; O; C; O; \ -O];\\n [ O;mIS; O; O; O; O; C; O];\\n [mIS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O; O; mS];\\n [ O; C; O; O; O; O; pS; O];\\n [ \ -O; O; C; O; O; pS; O; O];\\n [ O; O; O; C; mS; O; O; O];\\n \ - [ O; O; O; pS; C; O; O; O];\\n [ O; O; mS; O; O; C; O; \ -O];\\n [ O; mS; O; O; O; O; C; O];\\n [ pS; O; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYYZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; O;mIS; O];\\n [ O; C; O; O; O; O; O; IS];\\n [ \ -O; O; C; O; IS; O; O; O];\\n [ O; O; O; C; O;mIS; O; O];\\n \ - [ O; O; IS; O; C; O; O; O];\\n [ O; O; O;mIS; O; C; O; \ -O];\\n [mIS; O; O; O; O; O; C; O];\\n [ O; IS; O; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; pS; O; O; O];\\n [ O; C; O; O; O; pS; O; O];\\n [ \ -O; O; C; O; O; O; mS; O];\\n [ O; O; O; C; O; O; O; mS];\\n \ - [ mS; O; O; O; C; O; O; O];\\n [ O; mS; O; O; O; C; O; \ -O];\\n [ O; O; pS; O; O; O; C; O];\\n [ O; O; O; pS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O; pS; O; O];\\n [ O; C; O; O; pS; O; O; O];\\n [ \ -O; O; C; O; O; O; O; mS];\\n [ O; O; O; C; O; O; mS; O];\\n \ - [ O; mS; O; O; C; O; O; O];\\n [ mS; O; O; O; O; C; O; \ -O];\\n [ O; O; O; pS; O; O; C; O];\\n [ O; O; pS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; O;mIS; O; O];\\n [ O; C; O; O; IS; O; O; O];\\n [ \ -O; O; C; O; O; O; O; IS];\\n [ O; O; O; C; O; O;mIS; O];\\n \ - [ O; IS; O; O; C; O; O; O];\\n [mIS; O; O; O; O; C; O; \ -O];\\n [ O; O; O;mIS; O; O; C; O];\\n [ O; O; IS; O; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpYZZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O; O; pS; O; O; O];\\n [ O; C; O; O; O; mS; O; O];\\n [ \ -O; O; C; O; O; O; mS; O];\\n [ O; O; O; C; O; O; O; pS];\\n \ - [ mS; O; O; O; C; O; O; O];\\n [ O; pS; O; O; O; C; O; \ -O];\\n [ O; O; pS; O; O; O; C; O];\\n [ O; O; O; mS; O; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZIIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ - O; O; O; O; O; O];\\n [ O; Ep; O; O; O; O; O; O];\\n [ \ -O; O; Ep; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ - [ O; O; O; O; Em; O; O; O];\\n [ O; O; O; O; O; Em; O; \ -O];\\n [ O; O; O; O; O; O; Em; O];\\n [ O; O; O; O; O; \ -O; O; Em]];\\n return matrix;\\n}\\n\\nfunction ExpZIXMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; \ - O; O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ \ -O; O; C; IS; O; O; O; O];\\n [ O; O; IS; C; O; O; O; O];\\n \ - [ O; O; O; O; C;mIS; O; O];\\n [ O; O; O; O;mIS; C; O; \ -O];\\n [ O; O; O; O; O; O; C;mIS];\\n [ O; O; O; O; O; \ -O;mIS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZIYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ - O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ -O; O; C; pS; O; O; O; O];\\n [ O; O; mS; C; O; O; O; O];\\n \ - [ O; O; O; O; C; mS; O; O];\\n [ O; O; O; O; pS; C; O; \ -O];\\n [ O; O; O; O; O; O; C; mS];\\n [ O; O; O; O; O; \ -O; pS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZIZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ - O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ -O; O; Ep; O; O; O; O; O];\\n [ O; O; O; Em; O; O; O; O];\\n \ - [ O; O; O; O; Em; O; O; O];\\n [ O; O; O; O; O; Ep; O; \ -O];\\n [ O; O; O; O; O; O; Em; O];\\n [ O; O; O; O; O; \ -O; O; Ep]];\\n return matrix;\\n}\\n\\nfunction ExpZXIMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ -IS; O; O; O; O; O];\\n [ O; C; O; IS; O; O; O; O];\\n [ \ -IS; O; C; O; O; O; O; O];\\n [ O; IS; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O;mIS; O];\\n [ O; O; O; O; O; C; \ -O;mIS];\\n [ O; O; O; O;mIS; O; C; O];\\n [ O; O; O; O; \ -O;mIS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZXXMatrix( t: \ -Double ) : Complex[][] {\\n let O = ZeroC();\\n let C = \ -Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ -Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ -Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ - let matrix = \\n [[ C; O; O; IS; O; O; O; O];\\n [ O; C; IS; \ - O; O; O; O; O];\\n [ O; IS; C; O; O; O; O; O];\\n [ IS; \ -O; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; O;mIS];\\n \ -[ O; O; O; O; O; C;mIS; O];\\n [ O; O; O; O; O;mIS; C; \ -O];\\n [ O; O; O; O;mIS; O; O; C]];\\n return \ -matrix;\\n}\\n\\nfunction ExpZXYMatrix( t: Double ) : Complex[][] {\\n let \ -O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ -Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ -Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ -pS; O; O; O; O];\\n [ O; C; mS; O; O; O; O; O];\\n [ O; \ -pS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ -[ O; O; O; O; C; O; O; mS];\\n [ O; O; O; O; O; C; pS; \ -O];\\n [ O; O; O; O; O; mS; C; O];\\n [ O; O; O; O; pS; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZXZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ -IS; O; O; O; O; O];\\n [ O; C; O;mIS; O; O; O; O];\\n [ \ -IS; O; C; O; O; O; O; O];\\n [ O;mIS; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O;mIS; O];\\n [ O; O; O; O; O; C; O; \ -IS];\\n [ O; O; O; O;mIS; O; C; O];\\n [ O; O; O; O; O; \ -IS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZYIMatrix( t: Double \ -) : Complex[][] {\\n let O = ZeroC();\\n let C = \ -Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ -Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ -Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ - let matrix = \\n [[ C; O; pS; O; O; O; O; O];\\n [ O; C; O; \ -pS; O; O; O; O];\\n [ mS; O; C; O; O; O; O; O];\\n [ O; \ -mS; O; C; O; O; O; O];\\n [ O; O; O; O; C; O; mS; O];\\n \ -[ O; O; O; O; O; C; O; mS];\\n [ O; O; O; O; pS; O; C; \ -O];\\n [ O; O; O; O; O; pS; O; C]];\\n return \ -matrix;\\n}\\n\\nfunction ExpZYXMatrix( t: Double ) : Complex[][] {\\n let \ -O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ -Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ -Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; O; \ -pS; O; O; O; O];\\n [ O; C; pS; O; O; O; O; O];\\n [ O; \ -mS; C; O; O; O; O; O];\\n [ mS; O; O; C; O; O; O; O];\\n \ -[ O; O; O; O; C; O; O; mS];\\n [ O; O; O; O; O; C; mS; \ -O];\\n [ O; O; O; O; O; pS; C; O];\\n [ O; O; O; O; pS; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZYYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ - O;mIS; O; O; O; O];\\n [ O; C; IS; O; O; O; O; O];\\n [ \ -O; IS; C; O; O; O; O; O];\\n [mIS; O; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O; O; IS];\\n [ O; O; O; O; O; C;mIS; \ -O];\\n [ O; O; O; O; O;mIS; C; O];\\n [ O; O; O; O; IS; \ -O; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZYZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; O; \ -pS; O; O; O; O; O];\\n [ O; C; O; mS; O; O; O; O];\\n [ \ -mS; O; C; O; O; O; O; O];\\n [ O; pS; O; C; O; O; O; O];\\n \ - [ O; O; O; O; C; O; mS; O];\\n [ O; O; O; O; O; C; O; \ -pS];\\n [ O; O; O; O; pS; O; C; O];\\n [ O; O; O; O; O; \ -mS; O; C]];\\n return matrix;\\n}\\n\\nfunction ExpZZIMatrix( t: Double \ -) : Complex[][] {\\n let O = ZeroC();\\n let C = \ -Complex(Cos(t),0.0);\\n let IS = Complex(0.0,Sin(t));\\n let mIS = \ -Complex(0.0,-Sin(t));\\n let pS = Complex(Sin(t),0.0);\\n let mS = \ -Complex(-Sin(t),0.0);\\n let Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n \ - let matrix = \\n [[ Ep; O; O; O; O; O; O; O];\\n [ O; Ep; O; \ - O; O; O; O; O];\\n [ O; O; Em; O; O; O; O; O];\\n [ O; \ -O; O; Em; O; O; O; O];\\n [ O; O; O; O; Em; O; O; O];\\n \ -[ O; O; O; O; O; Em; O; O];\\n [ O; O; O; O; O; O; Ep; \ -O];\\n [ O; O; O; O; O; O; O; Ep]];\\n return \ -matrix;\\n}\\n\\nfunction ExpZZXMatrix( t: Double ) : Complex[][] {\\n let \ -O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n let IS = \ -Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n let pS = \ -Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let Ep = \ -ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; IS; O; \ -O; O; O; O; O];\\n [ IS; C; O; O; O; O; O; O];\\n [ O; \ -O; C;mIS; O; O; O; O];\\n [ O; O;mIS; C; O; O; O; O];\\n \ -[ O; O; O; O; C;mIS; O; O];\\n [ O; O; O; O;mIS; C; O; \ -O];\\n [ O; O; O; O; O; O; C; IS];\\n [ O; O; O; O; O; \ -O; IS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZZYMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ C; pS; \ - O; O; O; O; O; O];\\n [ mS; C; O; O; O; O; O; O];\\n [ \ -O; O; C; mS; O; O; O; O];\\n [ O; O; pS; C; O; O; O; O];\\n \ - [ O; O; O; O; C; mS; O; O];\\n [ O; O; O; O; pS; C; O; \ -O];\\n [ O; O; O; O; O; O; C; pS];\\n [ O; O; O; O; O; \ -O; mS; C]];\\n return matrix;\\n}\\n\\nfunction ExpZZZMatrix( t: Double ) \ -: Complex[][] {\\n let O = ZeroC();\\n let C = Complex(Cos(t),0.0);\\n \ - let IS = Complex(0.0,Sin(t));\\n let mIS = Complex(0.0,-Sin(t));\\n \ -let pS = Complex(Sin(t),0.0);\\n let mS = Complex(-Sin(t),0.0);\\n let \ -Ep = ExpIC(t);\\n let Em = ExpIC(-t);\\n let matrix = \\n [[ Ep; O; \ - O; O; O; O; O; O];\\n [ O; Em; O; O; O; O; O; O];\\n [ \ -O; O; Em; O; O; O; O; O];\\n [ O; O; O; Ep; O; O; O; O];\\n \ - [ O; O; O; O; Em; O; O; O];\\n [ O; O; O; O; O; Ep; O; \ -O];\\n [ O; O; O; O; O; O; Ep; O];\\n [ O; O; O; O; O; \ -O; O; Em]];\\n return matrix;\\n}\\n\\n\"\>"], "Output", - CellChangeTimes->{{3.7187281118107567`*^9, 3.7187281162899294`*^9}}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{ - RowBox[{ - RowBox[{"(", - RowBox[{ - RowBox[{"\"\\"", "~~", - RowBox[{"StringJoin", "@@", "#"}], "~~", "\"\\""}], "&"}], - ")"}], "/@", - RowBox[{"Tuples", "[", - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{ - "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], - "}"}], ",", - RowBox[{"{", - RowBox[{ - "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], - "}"}]}], "}"}], "]"}]}], "//", - RowBox[{ - RowBox[{"AsQArr", "[", - RowBox[{"#", ",", "1"}], "]"}], "&"}]}]], "Input", - CellChangeTimes->{{3.718729478643132*^9, 3.7187295979697523`*^9}}], - -Cell[BoxData["\<\" \ -[ExpIIMatrix;ExpIXMatrix;ExpIZMatrix;ExpIYMatrix;ExpXIMatrix;ExpXXMatrix;\ -ExpXZMatrix;ExpXYMatrix;ExpZIMatrix;ExpZXMatrix;ExpZZMatrix;ExpZYMatrix;\ -ExpYIMatrix;ExpYXMatrix;ExpYZMatrix;ExpYYMatrix]\"\>"], "Output", - CellChangeTimes->{{3.7187294964524217`*^9, 3.718729502316864*^9}, { - 3.718729546251667*^9, 3.718729598585673*^9}}] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{ - RowBox[{ - RowBox[{"(", - RowBox[{ - RowBox[{"\"\\"", "~~", - RowBox[{"StringJoin", "@@", "#"}], "~~", "\"\\""}], "&"}], - ")"}], "/@", - RowBox[{"Tuples", "[", - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{ - "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], - "}"}], ",", - RowBox[{"{", - RowBox[{ - "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], - "}"}], ",", - RowBox[{"{", - RowBox[{ - "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], - "}"}]}], "}"}], "]"}]}], "//", - RowBox[{ - RowBox[{"AsQArr", "[", - RowBox[{"#", ",", "1"}], "]"}], "&"}]}]], "Input", - CellChangeTimes->{{3.718729648233922*^9, 3.7187296517195964`*^9}}], - -Cell[BoxData["\<\" \ -[ExpIIIMatrix;ExpIIXMatrix;ExpIIZMatrix;ExpIIYMatrix;ExpIXIMatrix;\ -ExpIXXMatrix;ExpIXZMatrix;ExpIXYMatrix;ExpIZIMatrix;ExpIZXMatrix;ExpIZZMatrix;\ -ExpIZYMatrix;ExpIYIMatrix;ExpIYXMatrix;ExpIYZMatrix;ExpIYYMatrix;ExpXIIMatrix;\ -ExpXIXMatrix;ExpXIZMatrix;ExpXIYMatrix;ExpXXIMatrix;ExpXXXMatrix;ExpXXZMatrix;\ -ExpXXYMatrix;ExpXZIMatrix;ExpXZXMatrix;ExpXZZMatrix;ExpXZYMatrix;ExpXYIMatrix;\ -ExpXYXMatrix;ExpXYZMatrix;ExpXYYMatrix;ExpZIIMatrix;ExpZIXMatrix;ExpZIZMatrix;\ -ExpZIYMatrix;ExpZXIMatrix;ExpZXXMatrix;ExpZXZMatrix;ExpZXYMatrix;ExpZZIMatrix;\ -ExpZZXMatrix;ExpZZZMatrix;ExpZZYMatrix;ExpZYIMatrix;ExpZYXMatrix;ExpZYZMatrix;\ -ExpZYYMatrix;ExpYIIMatrix;ExpYIXMatrix;ExpYIZMatrix;ExpYIYMatrix;ExpYXIMatrix;\ -ExpYXXMatrix;ExpYXZMatrix;ExpYXYMatrix;ExpYZIMatrix;ExpYZXMatrix;ExpYZZMatrix;\ -ExpYZYMatrix;ExpYYIMatrix;ExpYYXMatrix;ExpYYZMatrix;ExpYYYMatrix]\"\>"], \ -"Output", - CellChangeTimes->{3.718729670538804*^9}] -}, Open ]] -}, Open ]] -}, -WindowSize->{759, 833}, -WindowMargins->{{Automatic, 462}, {48, Automatic}}, -FrontEndVersion->"11.0 for Microsoft Windows (64-bit) (July 28, 2016)", -StyleDefinitions->"Default.nb" -] -(* End of Notebook Content *) - -(* Internal cache information *) -(*CellTagsOutline -CellTagsIndex->{} -*) -(*CellTagsIndex -CellTagsIndex->{} -*) -(*NotebookFileOutline -Notebook[{ -Cell[CellGroupData[{ -Cell[580, 22, 102, 1, 72, "Chapter"], -Cell[685, 25, 2677, 77, 240, "Input"], -Cell[3365, 104, 1523, 42, 107, "Input"], -Cell[4891, 148, 94, 1, 30, "Input"] -}, Open ]], -Cell[CellGroupData[{ -Cell[5022, 154, 106, 1, 72, "Chapter"], -Cell[CellGroupData[{ -Cell[5153, 159, 136, 2, 70, "Section"], -Cell[5292, 163, 1616, 54, 335, "Input"], -Cell[6911, 219, 1057, 28, 88, "Input"], -Cell[CellGroupData[{ -Cell[7993, 251, 423, 12, 30, "Input"], -Cell[8419, 265, 245, 3, 30, "Output"] -}, Open ]] -}, Open ]] -}, Open ]], -Cell[CellGroupData[{ -Cell[8725, 275, 153, 3, 72, "Chapter"], -Cell[8881, 280, 2558, 61, 88, "Input"], -Cell[11442, 343, 844, 25, 107, "Input"], -Cell[CellGroupData[{ -Cell[12311, 372, 169, 3, 30, "Input"], -Cell[12483, 377, 495, 6, 183, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[13015, 388, 170, 3, 30, "Input"], -Cell[13188, 393, 134, 2, 30, "Output"] -}, Open ]], -Cell[13337, 398, 896, 15, 259, "Input"], -Cell[CellGroupData[{ -Cell[14258, 417, 1287, 31, 88, "Input"], -Cell[15548, 450, 53253, 679, 30735, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[68838, 1134, 697, 22, 50, "Input"], -Cell[69538, 1158, 356, 5, 88, "Output"] -}, Open ]], -Cell[CellGroupData[{ -Cell[69931, 1168, 830, 26, 69, "Input"], -Cell[70764, 1196, 939, 13, 254, "Output"] -}, Open ]] -}, Open ]] -} -] -*) - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs deleted file mode 100644 index 3897780db25..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite.VeryLong { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Simulation.TestSuite; - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Math; - - - operation ExpTestHelper (pauliIds : Int[]) : Unit { - let pauli = PauliById(pauliIds); - - using (qubits = Qubit[Length(pauliIds)]) { - AssertUnitaryWithAdjoint(ExpMultiPauliMatrix(pauli, 0.1), Exp(pauli, 0.1, _), qubits); - } - } - - - operation ExpThreeQubitTest () : Unit { - if (IsFullSimulator()) { - IterateThroughCartesianPower(3, NumberOfPaulies(), ExpTestHelper); - } - } - - - operation OneQubitUnitariesWithTwoControlsTest () : Unit { - MultiControlledQubitOperationsTester(2); - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs b/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs deleted file mode 100644 index 00ebd9ba89f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumTestSuite/TwoQubitUnitaries.qs +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.TestSuite { - open Microsoft.Quantum.Simulation.TestSuite.Math; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Intrinsic; - - - operation TwoQubitUnitaryTestHelper (matrix : RowMajorMatrix, unitary : (Qubit[] => Unit : Adjoint)) : Unit { - let totalQubits = MaxQubitsToAllocateForTwoQubitTests(); - - using (qubits = Qubit[totalQubits]) { - for (i in 0 .. totalQubits - 1) { - for (j in 0 .. totalQubits - 1) { - if (i != j) { - AssertUnitaryWithAdjoint(matrix, unitary, [qubits[i], qubits[j]]); - } - } - } - } - } - - - operation CNOTTestHelper (qubits : Qubit[]) : Unit is Adj { - if (Length(qubits) != 2) { - fail $"operation expects 2 qubits"; - } - - CNOT(qubits[0], qubits[1]); - } - - - operation CNOTTwoQubitTest () : Unit { - TwoQubitUnitaryTestHelper(CNOTMatrix(), CNOTTestHelper); - } - - - operation SWAPTestHelper (qubits : Qubit[]) : Unit is Adj { - if (Length(qubits) != 2) { - fail $"operation expects 2 qubits"; - } - - SWAP(qubits[0], qubits[1]); - } - - - operation SWAPTwoQubitTest () : Unit { - TwoQubitUnitaryTestHelper(SWAPMatrix(), SWAPTestHelper); - } - - - operation ExpTwoQubitTestHelper (pauliIds : Int[]) : Unit { - - let pauli = PauliById(pauliIds); - Message($"{pauli}"); - TwoQubitUnitaryTestHelper(ExpMultiPauliMatrix(pauli, 0.1), Exp(pauli, 0.1, _)); - } - - - operation ExpTwoQubitTest () : Unit { - - - if (IsFullSimulator()) { - IterateThroughCartesianPower(2, NumberOfPaulies(), ExpTwoQubitTestHelper); - } - } - - - operation ControlledTestHelper (qubitOperation : (Qubit => Unit : Controlled, Adjoint), target : Qubit[]) : Unit { - - body (...) { - - if (Length(target) != 2) { - fail $"expecting 2 qubits as input"; - } - - Controlled qubitOperation([target[1]], target[0]); - } - - adjoint invert; - } - - - operation ControlledOneQubitOperationsTwoQubitTest () : Unit { - for (test in OneQubitTestList()) { - let shouldExecute = - IsFullSimulator() or - (IsStabilizerSimulator() and LevelOfCliffordHierarchy(test) <= 0) or - (IsReversibleSimulator() and FixesComputationalBasis(test)); - - if (shouldExecute) { - let map = OperationMap(test); - TwoQubitUnitaryTestHelper(ControlledMatrix(1, OperationMatrix(test)), ControlledTestHelper(map, _)); - Message($"Passed:{map}"); - } - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs b/src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs deleted file mode 100644 index 8ee972883a8..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QubitManagerTests.cs +++ /dev/null @@ -1,446 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Simulators.Exceptions; -using System; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class QubitManagerTests - { - /// - /// Test for QubitManager. - /// - [Fact] - public void TestQubitManager() - { - QubitManager qm = new QubitManager(20); - - // Test allocation of single qubit - Qubit q1 = qm.Allocate(); - Assert.True(q1.Id == 0); - - // Test allocation of multiple qubits - IQArray qa1 = qm.Allocate(4); - Assert.True(qa1.Length == 4); - Assert.True(qa1[0].Id == 1); - Assert.True(qa1[1].Id == 2); - Assert.True(qa1[2].Id == 3); - Assert.True(qa1[3].Id == 4); - - // Test reuse of deallocated qubits - qm.Release(qa1[1]); - - Qubit q2 = qm.Allocate(); - Assert.True(q2.Id == 2); - - IQArray qa2 = qm.Allocate(3); - Assert.True(qa2.Length == 3); - Assert.True(qa2[0].Id == 5); - Assert.True(qa2[1].Id == 6); - Assert.True(qa2[2].Id == 7); - - qm.Release(qa2); - - Qubit q3 = qm.Allocate(); - Assert.True(q3.Id == 5); - - Qubit q4 = qm.Allocate(); - Assert.True(q4.Id == 6); - - Qubit q5 = qm.Allocate(); - Assert.True(q5.Id == 7); - - // Test borrowing - Qubit[] exclusion = new Qubit[4]; - exclusion[0] = qa1[0]; - exclusion[1] = qa1[2]; - exclusion[2] = q4; - exclusion[3] = q3; - - long qubitsAvailable; - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qab = qm.Borrow(5, exclusion); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); - Assert.True(qab[0].Id == 0); - Assert.True(qab[1].Id == 2); - Assert.True(qab[2].Id == 4); - Assert.True(qab[3].Id == 5); - Assert.True(qab[4].Id == 8); - - Qubit q6 = qm.Allocate(); - Assert.True(q6.Id == 9); - - // Test borrowing of the same qubit again - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb1 = qm.Borrow(1, exclusion); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 0); - Assert.True(qb1[0].Id == 0); - qm.Return(qb1[0]); - - qm.Return(qab); - - // Test that qubit allocated for borrowing is freed after being returned - Qubit q7 = qm.Allocate(); - Assert.True(q7.Id == 8); - - // Test allocation of qubits out of order. - qm.Release(q4); - qm.Release(qa1[2]); - qm.Release(q1); - - IQArray qa3 = qm.Allocate(4); - Assert.True(qa3.Length == 4); - Assert.True(qa3[0].Id == 0); - Assert.True(qa3[1].Id == 3); - Assert.True(qa3[2].Id == 6); - Assert.True(qa3[3].Id == 10); - - // Test Disabling qubits - Qubit q8 = qm.Allocate(); - Assert.True(q8.Id == 11); - qm.Disable(q8); - IQArray qab2 = qm.Borrow(12, null); - Assert.True(qab2[11].Id == 12); // make sure 11 is not borrowed. - qm.Release(q8); - qm.Return(qab2); - - IQArray qa4 = qm.Allocate(2); - Assert.True(qa4[0].Id == 12); // make sure 11 is not reused. - Assert.True(qa4[1].Id == 13); // make sure 11 is not reused. - qm.Release(qa4); - - - { // Test allocating zero qubits - IQArray n_q; - n_q = qm.Allocate(0); - Assert.True(n_q.Length == 0); - n_q = qm.Borrow(0, exclusion); - Assert.True(n_q.Length == 0); - } - - // NOTE: The below tests trigger exceptions, which but the QubitManager into a bad - // state where it shouldn't be reused. Creating a separate QubitManager in a small - // scope to test the exceptions avoids having one test case pollute the other. - - // Test for over allocating and over borrowing. - { - QubitManager qm_small = new QubitManager(2); - IQArray n_q; - Assert.Throws(() => n_q = qm_small.Allocate(5)); - } - { - QubitManager qm_small = new QubitManager(2); - IQArray n_q; - Assert.Throws(() => n_q = qm_small.Borrow(5, null)); - } - - // Test for negative input to allocate and borrow. - { - QubitManager qm_small = new QubitManager(20); - IQArray n_q; - Assert.Throws(() => n_q = qm_small.Allocate(-2)); - } - { - QubitManager qm_small = new QubitManager(20); - IQArray n_q; - Assert.Throws(() => n_q = qm_small.Borrow(-2, null)); - } - } - - /// - /// Test for QubitManager. - /// - [Fact] - public void TestQubitManagerDiscouragingReuse() - { - { // BLOCK testing mayExtendCapacity:false - QubitManager qm = new QubitManager(10, mayExtendCapacity: false, disableBorrowing: false, encourageReuse: false); - - // Test allocation of single qubit - Qubit q1 = qm.Allocate(); - Assert.True(q1.Id == 0); - - // Test allocation of multiple qubits - IQArray qa1 = qm.Allocate(4); - Assert.True(qa1.Length == 4); - Assert.True(qa1[0].Id == 1); - Assert.True(qa1[1].Id == 2); - Assert.True(qa1[2].Id == 3); - Assert.True(qa1[3].Id == 4); - - // Test reuse of deallocated qubits - qm.Release(qa1[1]); - - Qubit q2 = qm.Allocate(); - Assert.True(q2.Id == 5); - - IQArray qa2 = qm.Allocate(3); - Assert.True(qa2.Length == 3); - Assert.True(qa2[0].Id == 6); - Assert.True(qa2[1].Id == 7); - Assert.True(qa2[2].Id == 8); - - qm.Release(qa2); - - Qubit q3 = qm.Allocate(); - Assert.True(q3.Id == 9); - - Qubit q4 = qm.Allocate(); - Assert.True(q4.Id == 2); - - Qubit q5 = qm.Allocate(); - Assert.True(q5.Id == 8); - } - - { // BLOCK testing mayExtendCapacity:true - QubitManager qm = new QubitManager(10, mayExtendCapacity: true, disableBorrowing: false, encourageReuse: false); - - // Test allocation of single qubit - Qubit q1 = qm.Allocate(); - Assert.True(q1.Id == 0); - - // Test allocation of multiple qubits - IQArray qa1 = qm.Allocate(4); - Assert.True(qa1.Length == 4); - Assert.True(qa1[0].Id == 1); - Assert.True(qa1[1].Id == 2); - Assert.True(qa1[2].Id == 3); - Assert.True(qa1[3].Id == 4); - - // Test reuse of deallocated qubits - qm.Release(qa1[1]); - - Qubit q2 = qm.Allocate(); - Assert.True(q2.Id == 5); - - IQArray qa2 = qm.Allocate(3); - Assert.True(qa2.Length == 3); - Assert.True(qa2[0].Id == 6); - Assert.True(qa2[1].Id == 7); - Assert.True(qa2[2].Id == 8); - - qm.Release(qa2); - - Qubit q3 = qm.Allocate(); - Assert.True(q3.Id == 9); - - Qubit q4 = qm.Allocate(); - Assert.True(q4.Id == 10); - - Qubit q5 = qm.Allocate(); - Assert.True(q5.Id == 11); - } - } - - /// - /// Test for QubitManagerTrackingScope. - /// - [Fact] - public void TestQubitManagerTrackingScope() - { - QubitManagerTrackingScope qm = new QubitManagerTrackingScope(20); - - Qubit q1 = qm.Allocate(); - Assert.True(q1.Id == 0); - - IQArray qa1 = qm.Allocate(4); - Assert.True(qa1.Length == 4); - Assert.True(qa1[0].Id == 1); - Assert.True(qa1[1].Id == 2); - Assert.True(qa1[2].Id == 3); - Assert.True(qa1[3].Id == 4); - - Qubit q2 = qm.Allocate(); - Assert.True(q2.Id == 5); - - qm.OnOperationStart(null, qa1); - - long qubitsAvailable; - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb1 = qm.Borrow(3); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); - Assert.True(qb1[0].Id == 0); - Assert.True(qb1[1].Id == 5); - Assert.True(qb1[2].Id == 6); - qm.Return(qb1[0]); - qm.Return(qb1[2]); - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb2 = qm.Borrow(3); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 2); - Assert.True(qb2[0].Id == 0); - Assert.True(qb2[1].Id == 6); - Assert.True(qb2[2].Id == 7); - - { - qm.OnOperationStart(null, qb2); - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb3 = qm.Borrow(3); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 0); - Assert.True(qb3[0].Id == 1); - Assert.True(qb3[1].Id == 2); - Assert.True(qb3[2].Id == 3); - - qm.OnOperationEnd(null, QVoid.Instance); - } - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb4 = qm.Borrow(1); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); - Assert.True(qb4[0].Id == 8); - - qm.OnOperationEnd(null, QVoid.Instance); - } - - [Fact] - public void TestQubitManagerDisabledBorrowing() - { - QubitManagerTrackingScope qm = new QubitManagerTrackingScope(20, mayExtendCapacity: true, disableBorrowing: true); - - Qubit q1 = qm.Allocate(); - Assert.True(q1.Id == 0); - - IQArray qa1 = qm.Allocate(4); - Assert.True(qa1.Length == 4); - Assert.True(qa1[0].Id == 1); - Assert.True(qa1[1].Id == 2); - Assert.True(qa1[2].Id == 3); - Assert.True(qa1[3].Id == 4); - - Qubit q2 = qm.Allocate(); - Assert.True(q2.Id == 5); - - qm.OnOperationStart(null, qa1); - - long qubitsAvailable; - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb1 = qm.Borrow(3); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 3); - Assert.True(qb1[0].Id == 6); - Assert.True(qb1[1].Id == 7); - Assert.True(qb1[2].Id == 8); - - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 11); - qm.Return(qb1[0]); - qm.Return(qb1[2]); - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 13); - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb2 = qm.Borrow(3); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 3); - Assert.True(qb2[0].Id == 8); - Assert.True(qb2[1].Id == 6); - Assert.True(qb2[2].Id == 9); - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 10); - - { - qm.OnOperationStart(null, qb2); - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb3 = qm.Borrow(3); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 3); - Assert.True(qb3[0].Id == 10); - Assert.True(qb3[1].Id == 11); - Assert.True(qb3[2].Id == 12); - - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 7); - - qm.OnOperationEnd(null, QVoid.Instance); - } - - qm.Release(qb2[1]); - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 8); - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb4 = qm.Borrow(1); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); - Assert.True(qb4[0].Id == 6); - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 7); - - qm.OnOperationEnd(null, QVoid.Instance); - } - - [Fact] - public void TestQubitManagerGrowth() - { - QubitManagerTrackingScope qm = new QubitManagerTrackingScope(7, mayExtendCapacity : true, disableBorrowing: false); - - Qubit q1 = qm.Allocate(); - Assert.True(q1.Id == 0); - - IQArray qa1 = qm.Allocate(4); - Assert.True(qa1.Length == 4); - Assert.True(qa1[0].Id == 1); - Assert.True(qa1[1].Id == 2); - Assert.True(qa1[2].Id == 3); - Assert.True(qa1[3].Id == 4); - - Qubit q2 = qm.Allocate(); - Assert.True(q2.Id == 5); - - qm.OnOperationStart(null, qa1); - - long qubitsAvailable; - - qubitsAvailable = qm.GetFreeQubitsCount(); - IQArray qb1 = qm.Borrow(3); - Assert.True(qubitsAvailable - qm.GetFreeQubitsCount() == 1); - Assert.True(qb1[0].Id == 0); - Assert.True(qb1[1].Id == 5); - Assert.True(qb1[2].Id == 6); - qm.Return(qb1[0]); - qm.Return(qb1[2]); - - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 1); - IQArray qb2 = qm.Borrow(3); // This should grow qubit capacity - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 6); - Assert.True(qb2[0].Id == 0); - Assert.True(qb2[1].Id == 6); - Assert.True(qb2[2].Id == 7); - - qm.OnOperationEnd(null, null); - - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 6); - IQArray qa2 = qm.Allocate(4); - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 2); - Assert.True(qa2.Length == 4); - Assert.True(qa2[0].Id == 8); - Assert.True(qa2[1].Id == 9); - Assert.True(qa2[2].Id == 10); - Assert.True(qa2[3].Id == 11); - - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 2); - qm.Release(qa2[0]); - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 3); - - IQArray qa3 = qm.Allocate(4); // This should grow qubit capacity - qubitsAvailable = qm.GetFreeQubitsCount(); - Assert.True(qubitsAvailable == 13); - Assert.True(qa3.Length == 4); - Assert.True(qa3[0].Id == 8); - Assert.True(qa3[1].Id == 12); - Assert.True(qa3[2].Id == 13); - Assert.True(qa3[3].Id == 14); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/RangeTests.cs b/src/Simulation/Simulators.Type2.Tests/RangeTests.cs deleted file mode 100644 index 516705c351f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/RangeTests.cs +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Tests.CoreOperations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - using Helper = Microsoft.Quantum.Simulation.Simulators.Tests.OperationsTestHelper; - - public class RangeTests - { - [Fact] - public void RangeConstructor() - { - // The SimulatorBase class only implements operations for Qubit management, - // i.e. Allocate/Release: - var subject = new QRange(1, 5, 10); - - Assert.Equal(1, subject.Start); - Assert.Equal(5, subject.Step); - Assert.Equal(10, subject.End); - - subject = new QRange(10, -5, 0); - - Assert.Equal(10, subject.Start); - Assert.Equal(-5, subject.Step); - Assert.Equal(0, subject.End); - } - - [Fact] - public void RangeSamples() - { - var subject = new QRange(1, 3); - var expected = new long[] { 1, 2, 3 }; - Assert.Equal(expected, subject); - - subject = new QRange(2, 2, 5); - expected = new long[] { 2, 4 }; - Assert.Equal(expected, subject); - - subject = new QRange(2, 2, 5); - expected = new long[] { 2, 4 }; - Assert.Equal(expected, subject); - - subject = new QRange(2, 2, 6); - expected = new long[] { 2, 4, 6 }; - Assert.Equal(expected, subject); - - subject = new QRange(6, -2, 2); - expected = new long[] { 6, 4, 2 }; - Assert.Equal(expected, subject); - - subject = new QRange(2, 6, 7); - expected = new long[] { 2 }; - Assert.Equal(expected, subject); - - subject = new QRange(-1, 2, 10); - expected = new long[] { -1, 1, 3, 5, 7, 9 }; - Assert.Equal(expected, subject); - - subject = new QRange(-1, -1, -5); - expected = new long[] { -1, -2, -3, -4, -5 }; - Assert.Equal(expected, subject); - - subject = new QRange(1, 1); - expected = new long[] { 1 }; - Assert.Equal(expected, subject); - } - - [Fact] - public void EmptyRangeSamples() - { - var subject = new QRange(2, 2, 1); - Assert.Empty(subject); - Assert.Empty(subject.Reverse()); - - subject = new QRange(2, 1); - Assert.Empty(subject); - Assert.Empty(subject.Reverse()); - - subject = new QRange(1, -1, 2); - Assert.Empty(subject); - Assert.Empty(subject.Reverse()); - - subject = new QRange(1, 2, 0); - Assert.Empty(subject); - Assert.Empty(subject.Reverse()); - } - - [Fact] - public void InvalidRangeStep() - { - Assert.Throws("step", () => { new QRange(1, 0, 10); }); - } - - [Fact] - public void RangeIteration() - { - var subject = new QRange(6, -2, 2); - var expected = new long[] { 6, 4, 2 }; - var actual = new List(); - - foreach (var i in subject) - { - actual.Add(i); - } - Assert.Equal(expected, actual); - - actual = new List(); - foreach (var j in new QRange(6, -(2L), 2)) - { - actual.Add(j); - } - Assert.Equal(expected, actual); - } - - [Fact] - public void RangeReversal() - { - var subject = new QRange(6, -2, 2); - var expected = new QRange(2, 2, 6); - Assert.Equal(expected, subject.Reverse()); - - subject = new QRange(1, 1, 0); - expected = new QRange(0, -1, 1); - Assert.Equal(expected, subject.Reverse()); - - subject = new QRange(1, 2, 2); - expected = new QRange(1, -2, 1); - Assert.Equal(expected, subject.Reverse()); - } - - [Fact] - public void SimpleRange() - { - Helper.RunWithMultipleSimulators((s) => - { - IgnorableAssert.Disable(); - try - { - //We have to call the method in the same thread for IgnorableAssert.Disable() to work - s.Get().Apply(QVoid.Instance); - } - finally - { - IgnorableAssert.Enable(); - } - - var tracer = s.GetTracer(); - - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (0L))); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1L))); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (2L))); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3L))); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (4L))); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (5L))); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (6L))); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (7L))); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (8L))); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (9L))); - Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (10L))); - Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (11L))); - - }); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs b/src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs deleted file mode 100644 index 2d8ee9a75cd..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/RuntimeMetadataTests.cs +++ /dev/null @@ -1,821 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Quantum.Simulation.Core; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class RuntimeMetadataEqualityTests - { - [Fact] - public void WrongType() - { - var a = new RuntimeMetadata { }; - var i = 5; - Assert.False(a.Equals(i)); - } - - [Fact] - public void NullEquality() - { - var a = new RuntimeMetadata { }; - RuntimeMetadata? b = null; - Assert.NotEqual(a, b); - Assert.NotEqual(b, a); - } - - [Fact] - public void CheckEquality() - { - var a = new RuntimeMetadata() - { - Label = "H", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { }, - }; - var b = new RuntimeMetadata() - { - Label = "H", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { }, - }; - Assert.Equal(a, b); - Assert.Equal(a.GetHashCode(), b.GetHashCode()); - - b.Label = "X"; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - b.Label = "H"; - - b.FormattedNonQubitArgs = "(1)"; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - b.FormattedNonQubitArgs = ""; - - b.IsAdjoint = true; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - b.IsAdjoint = false; - - b.IsControlled = true; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - b.IsControlled = false; - - b.IsMeasurement = true; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - b.IsMeasurement = false; - - b.IsComposite = true; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - b.IsComposite = false; - } - - [Fact] - public void ControlsEquality() - { - var a = new RuntimeMetadata() - { - Controls = new List() { }, - }; - var b = new RuntimeMetadata() - { - Controls = new List() { }, - }; - Assert.Equal(a, b); - Assert.Equal(a.GetHashCode(), b.GetHashCode()); - - b.Controls = new List() { new FreeQubit(1) }; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - - a.Controls = new List() { new FreeQubit(1) }; - Assert.Equal(a, b); - Assert.Equal(a.GetHashCode(), b.GetHashCode()); - } - - [Fact] - public void TargetsEquality() - { - var a = new RuntimeMetadata() - { - Targets = new List() { }, - }; - var b = new RuntimeMetadata() - { - Targets = new List() { }, - }; - Assert.Equal(a, b); - Assert.Equal(a.GetHashCode(), b.GetHashCode()); - - b.Targets = new List() { new FreeQubit(1) }; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - - a.Targets = new List() { new FreeQubit(1) }; - Assert.Equal(a, b); - Assert.Equal(a.GetHashCode(), b.GetHashCode()); - } - - [Fact] - public void ChildrenEquality() - { - var a = new RuntimeMetadata() - { - Children = new[] - { - new List(), - new List(), - }, - }; - var b = new RuntimeMetadata() - { - Children = new[] - { - new List(), - new List(), - }, - }; - Assert.Equal(a, b); - Assert.Equal(a.GetHashCode(), b.GetHashCode()); - - var aChildren = a.Children.ToList(); - aChildren[0] = new List() { new RuntimeMetadata() { Label = "H" } }; - a.Children = aChildren; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - - var bChildren = b.Children.ToList(); - bChildren[0] = new List() { new RuntimeMetadata() { Label = "X" } }; - b.Children = bChildren; - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - - bChildren[0] = new List() { new RuntimeMetadata() { Label = "H" } }; - Assert.Equal(a, b); - Assert.Equal(a.GetHashCode(), b.GetHashCode()); - - b.Children = b.Children.SkipLast(1); - Assert.NotEqual(a, b); - Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); - } - } - - public class IntrinsicTests - { - [Fact] - public void CNOT() - { - var control = new FreeQubit(1); - var target = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn((control, target)); - var expected = new RuntimeMetadata() - { - Label = "X", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { control }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void CCNOT() - { - var control1 = new FreeQubit(0); - var control2 = new FreeQubit(2); - var target = new FreeQubit(1); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn((control1, control2, target)); - var expected = new RuntimeMetadata() - { - Label = "X", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { control1, control2 }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void Swap() - { - var q1 = new FreeQubit(0); - var q2 = new FreeQubit(1); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn((q1, q2)); - var expected = new RuntimeMetadata() - { - Label = "SWAP", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { q1, q2 }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void Ry() - { - var target = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn((2.1, target)); - var expected = new RuntimeMetadata() - { - Label = "Ry", - FormattedNonQubitArgs = "(" + 2.1 + ")", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void M() - { - var measureQubit = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(measureQubit); - var expected = new RuntimeMetadata() - { - Label = "M", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = true, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { measureQubit }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void Reset() - { - var target = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(target); - var expected = new RuntimeMetadata() - { - Label = "Reset", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void ResetAll() - { - IQArray targets = new QArray(new[] { new FreeQubit(0) }); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(targets); - var expected = new RuntimeMetadata() - { - Label = "ResetAll", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = true, - Children = null, - Controls = new List() { }, - Targets = targets, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - } - - public class MeasurementTests - { - [Fact] - public void MResetX() - { - var measureQubit = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(measureQubit); - var expected = new RuntimeMetadata() - { - Label = "MResetX", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = true, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { measureQubit }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void MResetY() - { - var measureQubit = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(measureQubit); - var expected = new RuntimeMetadata() - { - Label = "MResetY", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = true, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { measureQubit }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void MResetZ() - { - var measureQubit = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(measureQubit); - var expected = new RuntimeMetadata() - { - Label = "MResetZ", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = true, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { measureQubit }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - } - - public class CustomCircuitTests - { - [Fact] - public void EmptyOperation() - { - var measureQubit = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(QVoid.Instance); - var expected = new RuntimeMetadata() - { - Label = "Empty", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void OperationAsArgument() - { - var q = new FreeQubit(0); - var opArg = new QuantumSimulator().Get(); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn((opArg, q)); - var expected = new RuntimeMetadata() - { - Label = "WrapperOp", - FormattedNonQubitArgs = "(HOp)", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { q }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void NestedOperation() - { - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(QVoid.Instance); - var expected = new RuntimeMetadata() - { - Label = "NestedOp", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void DuplicateQubitArgs() - { - var q = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn((q, q)); - var expected = new RuntimeMetadata() - { - Label = "TwoQubitOp", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { q }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void QArrayArgs() - { - var op = new QuantumSimulator().Get(); - IQArray bits = new QArray(new bool[] { false, true }); - var args = op.__dataIn(bits); - var expected = new RuntimeMetadata() - { - Label = "BoolArrayOp", - FormattedNonQubitArgs = "[False, True]", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - } - - public class UDTTests - { - [Fact] - public void FooUDTOp() - { - Qubit target = new FreeQubit(0); - var op = new QuantumSimulator().Get(); - var args = op.__dataIn(new Circuits.FooUDT(("bar", (target, 2.1)))); - var expected = new RuntimeMetadata() - { - Label = "FooUDTOp", - FormattedNonQubitArgs = "(\"bar\", (" + 2.1 + "))", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - } - - public class ControlledOpTests - { - [Fact] - public void ControlledH() - { - IQArray controls = new QArray(new[] { new FreeQubit(0) }); - Qubit target = new FreeQubit(1); - var op = new QuantumSimulator().Get().Controlled; - var args = op.__dataIn((controls, target)); - var expected = new RuntimeMetadata() - { - Label = "H", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = controls, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void ControlledX() - { - IQArray controls = new QArray(new[] { new FreeQubit(0) }); - Qubit target = new FreeQubit(1); - var op = new QuantumSimulator().Get().Controlled; - var args = op.__dataIn((controls, target)); - var expected = new RuntimeMetadata() - { - Label = "X", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = controls, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void ControlledCNOT() - { - IQArray controls = new QArray(new[] { new FreeQubit(0) }); - Qubit control = new FreeQubit(1); - Qubit target = new FreeQubit(2); - var op = new QuantumSimulator().Get().Controlled; - var args = op.__dataIn((controls, (control, target))); - var expected = new RuntimeMetadata() - { - Label = "X", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = controls.Append(control), - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void ControlledCCNOT() - { - Qubit control1 = new FreeQubit(0); - Qubit control2 = new FreeQubit(1); - Qubit control3 = new FreeQubit(2); - Qubit target = new FreeQubit(3); - IQArray controls = new QArray(new[] { control1 }); - var op = new QuantumSimulator().Get().Controlled; - var args = op.__dataIn((controls, (control2, control3, target))); - var expected = new RuntimeMetadata() - { - Label = "X", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { control1, control2, control3 }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - } - - public class AdjointTests - { - [Fact] - public void AdjointH() - { - Qubit target = new FreeQubit(0); - var op = new QuantumSimulator().Get().Adjoint; - var args = op.__dataIn(target); - var expected = new RuntimeMetadata() - { - Label = "H", - FormattedNonQubitArgs = "", - IsAdjoint = true, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void AdjointX() - { - Qubit target = new FreeQubit(0); - var op = new QuantumSimulator().Get().Adjoint; - var args = op.__dataIn(target); - var expected = new RuntimeMetadata() - { - Label = "X", - FormattedNonQubitArgs = "", - IsAdjoint = true, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void AdjointAdjointH() - { - Qubit target = new FreeQubit(0); - var op = new QuantumSimulator().Get().Adjoint.Adjoint; - var args = op.__dataIn(target); - var expected = new RuntimeMetadata() - { - Label = "H", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void ControlledAdjointH() - { - IQArray controls = new QArray(new[] { new FreeQubit(0) }); - Qubit target = new FreeQubit(1); - var op1 = new QuantumSimulator().Get().Controlled.Adjoint; - var op2 = new QuantumSimulator().Get().Adjoint.Controlled; - var args = op1.__dataIn((controls, target)); - var expected = new RuntimeMetadata() - { - Label = "H", - FormattedNonQubitArgs = "", - IsAdjoint = true, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = controls, - Targets = new List() { target }, - }; - - Assert.Equal(op1.GetRuntimeMetadata(args), expected); - Assert.Equal(op2.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void ControlledAdjointAdjointH() - { - IQArray controls = new QArray(new[] { new FreeQubit(0) }); - Qubit target = new FreeQubit(1); - var op1 = new QuantumSimulator().Get().Controlled.Adjoint.Adjoint; - var op2 = new QuantumSimulator().Get().Adjoint.Controlled.Adjoint; - var op3 = new QuantumSimulator().Get().Adjoint.Adjoint.Controlled; - var args = op1.__dataIn((controls, target)); - var expected = new RuntimeMetadata() - { - Label = "H", - FormattedNonQubitArgs = "", - IsAdjoint = false, - IsControlled = true, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = controls, - Targets = new List() { target }, - }; - - Assert.Equal(op1.GetRuntimeMetadata(args), expected); - Assert.Equal(op2.GetRuntimeMetadata(args), expected); - Assert.Equal(op3.GetRuntimeMetadata(args), expected); - } - } - - public class PartialOpTests - { - - [Fact] - public void PartialRy() - { - var target = new FreeQubit(0); - var op = new QuantumSimulator().Get().Partial((double d) => - new ValueTuple(d, target)); - var args = op.__dataIn(2.1); - var expected = new RuntimeMetadata() - { - Label = "Ry", - FormattedNonQubitArgs = "(" + 2.1 + ")", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { target }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - - [Fact] - public void PartialUDT() - { - var target = new FreeQubit(0); - var op = new QuantumSimulator().Get>(typeof(Circuits.FooUDT)) - .Partial((double d) => (("bar", (target, d)))); - var args = new QTuple(2.1); - var expected = new RuntimeMetadata() - { - Label = "FooUDT", - FormattedNonQubitArgs = "(\"bar\", (" + 2.1 + "))", - IsAdjoint = false, - IsControlled = false, - IsMeasurement = false, - IsComposite = false, - Children = null, - Controls = new List() { }, - Targets = new List() { }, - }; - - Assert.Equal(op.GetRuntimeMetadata(args), expected); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs b/src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs deleted file mode 100644 index f9b73e477e9..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/SimulatorBaseTests.cs +++ /dev/null @@ -1,481 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Xunit; -using Xunit.Abstractions; - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Common; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public static class Extensions - { - /// - /// This method is a wrapper to let the tests keep using a one Type parameter - /// method to fetch for Gates. - /// - public static T Get(this SimulatorBase sim) where T : AbstractCallable - { - return sim.Get(); - } - } - - public class SimulatorBaseTests - { - private readonly ITestOutputHelper output; - - public SimulatorBaseTests(ITestOutputHelper output) - { - this.output = output; - } - - /// - /// Verifies that built-in operations (Allocate/Relase) can be retrieved and succesfully applied from a TrivialSimulator. - /// - [Fact] - public void SimulatorBuiltInOperations() - { - // The SimulatorBase class only implements operations for Qubit management, - // i.e. Allocate/Release: - var subject = new TrivialSimulator(); - - Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); - - // Check whether our events for allocation and deallocation - // are actually called. - var calledOnAllocate = false; - var calledOnRelease = false; - subject.OnAllocateQubits += count => - { - output.WriteLine($"Allocate count = {count}"); - calledOnAllocate = true; - }; - subject.OnReleaseQubits += register => - { - output.WriteLine($"Release qubits = {register}"); - calledOnRelease = true; - }; - - var allocate = subject.Get(); - var release = subject.Get(); - - // Try the operations - var qubits = allocate.Apply(3); - Assert.True(calledOnAllocate); - Assert.Equal(3, qubits.Length); - - release.Apply(qubits); - Assert.True(calledOnRelease); - - subject.CheckNoQubitLeak(); - } - - /// - /// Verifies that operations are not built-in in the TrivialSimulator can't be retrieved. - /// - [Fact] - public void OperationWithNoBody() - { - var subject = new TrivialSimulator(); - Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); - - Assert.Throws(() => - { - subject.Get(); - }); - } - - /// - /// Verifies that operations that have dependencies on operations that - /// are not built-in in the TrivialSimulator can't be retrieved. - /// - [Fact] - public void OperationWithNotImplementedDependency() - { - var subject = new TrivialSimulator(); - - Assert.Throws(() => - { - subject.Get(); - }); - } - - /// - /// Verifies that operations that have dependencies on operations that - /// are not built-in in the TrivialSimulator can't be retrieved. - /// - [Fact] - public void OperationWithRecursiveDependencies() - { - var subject = new TrivialSimulator(); - - var a = subject.Get(); - var b = subject.Get(); - - // Make sure the last instance is correctly cached. - var a2 = subject.Get(); - var b2 = subject.Get(); - Assert.Same(a, a2); - Assert.Same(b, b2); - Assert.Same(a, b.A); - Assert.Same(b, a.B); - } - - private class Nothing { } - private class NothingSquared : Nothing { } - - /// - /// Verifies that users can provide their own operation definitions. - /// - [Fact] - public void UserDefinedOperations() - { - var subject = new TrivialSimulator(); - Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); - - Assert.Throws(() => - { - subject.Get(); - }); - - try - { - subject.Register(null, typeof(DummyX)); - } - catch (ArgumentNullException e) - { - Assert.Equal("original", e.ParamName); - } - - try - { - subject.Register(typeof(Intrinsic.Allocate), null); - } - catch (ArgumentNullException e) - { - Assert.Equal("replace", e.ParamName); - } - - // You can only register an override of a class that extends Operation: - Assert.Throws(() => - { - subject.Register(typeof(Nothing), typeof(NothingSquared)); - }); - - // By default, you can only register a Gate that is a subclass of the gate it's overriding: - Assert.Throws(() => - { - subject.Register(typeof(Intrinsic.Allocate), typeof(DummyX)); - }); - - subject.Register(typeof(Intrinsic.X), typeof(DummyX)); - var customX = subject.Get(); - Assert.Equal(typeof(DummyX), customX.GetType()); - - subject.Register(typeof(Intrinsic.M), typeof(DummyM)); - var customM = subject.Get(); - Assert.Equal(typeof(DummyM), customM.GetType()); - } - - /// - /// Verifies that user-defined operations can override Intrinsics just by following the interface. - /// - [Fact] - public void OverrideWithNoInheritance() - { - var subject = new TrivialSimulator(); - Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); - - // If providing an interface, the original gate must implement that interface - Assert.Throws(() => - { - subject.Register(typeof(Intrinsic.CNOT), typeof(LikeX), typeof(IUnitary)); - }); - - // If providing an interface, the replacement gate must implement that interface - Assert.Throws(() => - { - subject.Register(typeof(Intrinsic.CNOT), typeof(LikeX), typeof(IUnitary<(Qubit, Qubit)>)); - }); - - // You can override without inheritance, as long as both implement the same interface: - subject.Register(typeof(Intrinsic.X), typeof(LikeX), typeof(IUnitary)); - - // Verify the replacement work - var x = subject.Get, Intrinsic.X>(); - Assert.NotNull(x); - Assert.Equal(typeof(LikeX), x.GetType()); - } - - /// - /// Verifies that operations instances are cached by the Simulator - /// - [Fact] - public void OperationsCache() - { - var subject = new TrivialSimulator(); - Assert.Equal(typeof(TrivialSimulator).Name, subject.Name); - - var allocate1 = subject.Get(); - var allocate2 = subject.Get(); - - Assert.Same(allocate1, allocate2); - } - - [Fact] - public void GenericDependencies() - { - var subject = new TrivialSimulator(); - - // Can't get Gen because it depends on X - Assert.Throws(() => - { - subject.Get>(); - }); - - // TODO: because we can't check dependencies, this - // is not throwing an Exception, even though Gen depends on X: - var gen1 = subject.Get(); - Assert.NotNull(gen1); - - // Add an implementation of X: - subject.Register(typeof(Intrinsic.X), typeof(LikeX), typeof(IUnitary)); - var gen2 = subject.Get>(); - Assert.NotNull(gen1); - - // Asking for same T, should give same op, but asking for different T should not: - var gen2a = subject.Get>(); - var gen2b = subject.Get>(); - - Assert.Same(gen2, gen2a); - Assert.NotSame(gen2, gen2b); - } - - /// - /// Verifies that CheckQubits work as expected - /// - [Fact] - public void CheckQubits() - { - var sim = new TrivialSimulator(); - var allocate = sim.Get(); - var release = sim.Get(); - - var qubits = allocate.Apply(1); - var name = "foo"; - - // This should work: - sim.CheckQubits(qubits, name); - - // Calling with null will throw an Exception - Assert.Throws(name, () => sim.CheckQubits(null, name)); - - // Calling after release will throw an Exception - sim.CheckQubits(qubits, name); - release.Apply(qubits); - Assert.Throws($"{name}[0]", () => sim.CheckQubits(qubits, name)); - } - - /// - /// Verifies that GetQubitsAvailableToUse and GetQubitsAvailableToBorrow work correctly. - /// - [Fact] - public void TestQubitCounts() - { - var sim = new TrivialSimulator(); - - var baseCount = 32L; - var allocCount = 10L; - - var (initialUse, initialBorrow, afterUse, afterBorrow, subBorrow, innerBorrow) = - Circuits.GetAvailableTest.Run(sim, allocCount).Result; - - Assert.Equal(baseCount, initialUse); - Assert.Equal(baseCount, initialBorrow); - Assert.Equal(baseCount - allocCount, afterUse); - Assert.Equal(baseCount - allocCount, afterBorrow); - Assert.Equal(baseCount, subBorrow); - Assert.Equal(baseCount - 1, innerBorrow); - } - - /// - /// Verifies that recursive operations work as expected - /// - [Fact] - public void TextRecursion() - { - var sim = new TrivialSimulator(); - var res1 = Tests.Circuits.Factorial.Run(sim, 4L).Result; - var res2 = Tests.Circuits.OpFactorial.Run(sim, 4L).Result; - var res3 = Tests.Circuits.GenRecursion.Run(sim, 6L, 2L).Result; - var res4 = Tests.Circuits.GenRecursion.Run(sim, 6L, 2L).Result; - Assert.Equal(24L, res1); - Assert.Equal(24L, res2); - Assert.Equal(6L, res3); - Assert.Equal(6L, res4); - } - - - /// - // This class has no implementation, is just used to make sure - // a user can register their own Operation overrides: - /// - public class DummyX : Intrinsic.X - { - public DummyX(IOperationFactory m) : base(m) - { - } - - public override Func Body => throw new NotImplementedException(); - - public override Func<(IQArray, Qubit), QVoid> ControlledBody => throw new NotImplementedException(); - } - - /// - // This class has no implementation, is just used to make sure - // a user can register their own Operation overrides: - /// - public class DummyM : Intrinsic.M - { - public DummyM(IOperationFactory m) : base(m) - { - } - - public override Func Body => throw new NotImplementedException(); - - public override void Init() - { - } - } - - /// - /// This class is not abstract, but depends on X, which is. - /// - public class DependsOnX : Operation, ICallable - { - public DependsOnX(IOperationFactory m) : base(m) - { - } - - string ICallable.FullName => "DependsOnX"; - - public IUnitary X { get; set; } - - public override void Init() - { - this.X = this.Factory.Get, Intrinsic.X>(); - } - - public override Func Body => throw new NotImplementedException(); - } - - /// - // This class is a one qubit Unitary (like X), but - // it doesn't implement X. Still because it implmenets - // IUnitary we can use it to replace X.: - /// - public class LikeX : Unitary, ICallable - { - public LikeX(IOperationFactory m) : base(m) - { - } - - string ICallable.FullName => "LikeX"; - - public override void Init() { } - - public override Func<(IQArray, Qubit), QVoid> ControlledAdjointBody => throw new NotImplementedException(); - - public override Func AdjointBody => throw new NotImplementedException(); - - public override Func<(IQArray, Qubit), QVoid> ControlledBody => throw new NotImplementedException(); - - public override Func Body => throw new NotImplementedException(); - } - - - /// - /// This class has a recursive dependency with B - /// - public class A : Operation, ICallable - { - public A(IOperationFactory m) : base(m) - { - } - - public ICallable B { get; set; } - - public override void Init() - { - this.B = this.Factory.Get(); - } - - string ICallable.FullName => "A"; - - public override Func Body => (_) => { return QVoid.Instance; }; - } - - /// - /// This class has a recursive depdency with A - /// - public class B : Operation, ICallable - { - public B(IOperationFactory m) : base(m) - { - } - - string ICallable.FullName => "B"; - - public ICallable A { get; set; } - - public override void Init() - { - this.A = this.Factory.Get(); - } - - public override Func Body => (_) => { return QVoid.Instance; }; - } - - public class Gen : Operation, ICallable - { - public Gen(IOperationFactory m) : base(m) - { - } - - string ICallable.FullName => "Gen"; - - public override Func Body => (_) => { return QVoid.Instance; }; - - public ICallable A { get; set; } - - public IUnitary X { get; set; } - - public override void Init() - { - this.A = this.Factory.Get(); - this.X = this.Factory.Get, Intrinsic.X>(); - } - } - - - public class DependsOnGen : Operation, ICallable - { - public DependsOnGen(IOperationFactory m) : base(m) - { - } - - string ICallable.FullName => "DependsOnGen"; - - public ICallable Gen { get; set; } - - public override Func Body => (_) => { return QVoid.Instance; }; - - public override void Init() - { - this.Gen = this.Factory.Get(typeof(Gen<>)); - } - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs b/src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs deleted file mode 100644 index c85fac9bfac..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/StackTraceTests.cs +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#nullable enable - -using Xunit; - -using System; -using System.Threading.Tasks; - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; -using Microsoft.Quantum.Simulation.Simulators.Exceptions; -using Xunit.Abstractions; -using System.Text; -using System.Collections.Generic; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class StackTraceTests - { - const string namespacePrefix = "Microsoft.Quantum.Simulation.Simulators.Tests.Circuits."; - - private readonly ITestOutputHelper output; - public StackTraceTests(ITestOutputHelper output) - { - this.output = output; - } - - [Fact] - public void AllocateQubit2Test() - { - using var sim = new QuantumSimulator(); - try - { - IgnorableAssert.Disable(); - QVoid res = sim.Execute(QVoid.Instance); - } - catch (ExecutionFailException) - { - var stackFrames = sim.CallStack; - - // Make sure that the call stack isn't null before proceeding. - Assert.NotNull(stackFrames); - - // The following assumes that Assert is on Q# stack. - Assert.Equal(2, stackFrames!.Length); - - Assert.Equal("Microsoft.Quantum.Diagnostics.AssertMeasurement", stackFrames[0].Callable.FullName); - Assert.Equal(namespacePrefix + "AllocateQubit2", stackFrames[1].Callable.FullName); - - Assert.Equal(OperationFunctor.Body, stackFrames[0].Callable.Variant); - Assert.Equal(OperationFunctor.Body, stackFrames[1].Callable.Variant); - - Assert.Equal(94, stackFrames[1].FailedLineNumber); - } - finally - { - IgnorableAssert.Enable(); - } - } - - [Fact] - public void AlwaysFail4Test() - { - using (var sim = new QuantumSimulator()) - { - try - { - QVoid res = AlwaysFail4.Run(sim).Result; - } - catch (AggregateException ex) - { - Assert.True(ex.InnerException is ExecutionFailException); - - StackFrame[] stackFrames = sim.CallStack; - - Assert.Equal(5, stackFrames.Length); - - Assert.Equal(namespacePrefix + "AlwaysFail", stackFrames[0].Callable.FullName); - Assert.Equal(namespacePrefix + "AlwaysFail1", stackFrames[1].Callable.FullName); - Assert.Equal(namespacePrefix + "AlwaysFail2", stackFrames[2].Callable.FullName); - Assert.Equal(namespacePrefix + "AlwaysFail3", stackFrames[3].Callable.FullName); - Assert.Equal(namespacePrefix + "AlwaysFail4", stackFrames[4].Callable.FullName); - - Assert.Equal(OperationFunctor.Controlled, stackFrames[0].Callable.Variant); - Assert.Equal(OperationFunctor.Controlled, stackFrames[1].Callable.Variant); - Assert.Equal(OperationFunctor.Body, stackFrames[2].Callable.Variant); - Assert.Equal(OperationFunctor.Adjoint, stackFrames[3].Callable.Variant); - Assert.Equal(OperationFunctor.Body, stackFrames[4].Callable.Variant); - - Assert.Equal(14, stackFrames[2].FailedLineNumber); - Assert.Equal(21, stackFrames[4].FailedLineNumber); - - // For Adjoint and Controlled we expect failedLineNumber to be equal to declarationStartLineNumber - Assert.Equal(stackFrames[0].DeclarationStartLineNumber, stackFrames[0].FailedLineNumber); - Assert.Equal(stackFrames[1].DeclarationStartLineNumber, stackFrames[1].FailedLineNumber); - Assert.Equal(stackFrames[3].DeclarationStartLineNumber, stackFrames[3].FailedLineNumber); - - for (int i = 0; i < stackFrames.Length; ++i) - { - Assert.StartsWith(@"https://github.com/", stackFrames[i].GetURLFromPDB()); - Assert.EndsWith($"#L{stackFrames[i].FailedLineNumber}", stackFrames[i].GetURLFromPDB()); - } - - StringBuilder builder = new StringBuilder(); - builder.Append("13 ".PadLeft(PortablePDBEmbeddedFilesCache.lineNumberPaddingWidth)); - builder.AppendLine(" operation AlwaysFail2() : Unit is Adj + Ctl {"); - builder.Append("14 ".PadLeft(PortablePDBEmbeddedFilesCache.lineNumberPaddingWidth) + PortablePDBEmbeddedFilesCache.lineMarkPrefix); - builder.AppendLine(" Controlled AlwaysFail1(new Qubit[0],());"); - builder.Append("15 ".PadLeft(PortablePDBEmbeddedFilesCache.lineNumberPaddingWidth)); - builder.AppendLine(" }"); - Assert.Equal(builder.ToString(), stackFrames[2].GetOperationSourceFromPDB()); - - for (int i = 0; i < stackFrames.Length; ++i) - { - output.WriteLine($"operation:{stackFrames[i].Callable.FullName}"); - output.WriteLine(stackFrames[i].GetOperationSourceFromPDB()); - } - } - } - } - - [Fact] - public void UrlMappingTest() - { - const string rawUrl = @"https://raw.githubusercontent.com/microsoft/qsharp-runtime/af6262c05522d645d0a0952272443e84eeab677a/src/Xunit/TestCaseDiscoverer.cs"; - const string expectedURL = @"https://github.com/microsoft/qsharp-runtime/blob/af6262c05522d645d0a0952272443e84eeab677a/src/Xunit/TestCaseDiscoverer.cs#L13"; - Assert.Equal(expectedURL, PortablePdbSymbolReader.TryFormatGitHubUrl(rawUrl, 13)); - } - - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs b/src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs deleted file mode 100644 index d07af93db07..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/StartOperationTests.cs +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Tests.StartOperation; -using System; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - using Helper = Microsoft.Quantum.Simulation.Simulators.Tests.OperationsTestHelper; - - public class StartOperationTests - { - [Fact] - public void StartOperationCalls() - { - Helper.RunWithMultipleSimulators((s) => - { - var tracker = new StartTracker(s); - StartOperationTest.Run(s).Wait(); - - var q0 = new FreeQubit(0) as Qubit; - var q1 = new FreeQubit(1) as Qubit; - var q2 = new FreeQubit(2) as Qubit; - var q3 = new FreeQubit(3) as Qubit; - - Assert.Equal(1, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.StartOperationTest")); - - var allVariantsBody = 3; - var allVariantsAdjoint = 2; - var allVariantsCtrl = 2; - var allVariantsAdjointCtrl = 1; - var allVariants = allVariantsBody + allVariantsAdjoint + allVariantsCtrl + allVariantsAdjointCtrl; - Assert.Equal(allVariants, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants")); - Assert.Equal(allVariantsBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Body)); - Assert.Equal(allVariantsAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Adjoint)); - Assert.Equal(allVariantsCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Controlled)); - Assert.Equal(allVariantsAdjointCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.ControlledAdjoint)); - - var basicBody = 9; - var basicAdjoint = 7; - var basicCtrl = 9; - var basicCtrlAdjoint = 7; - var basic = basicBody + basicAdjoint + basicCtrl + basicCtrlAdjoint; - Assert.Equal(basic, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic")); - Assert.Equal(basicBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body)); - Assert.Equal(basicAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint)); - Assert.Equal(basicCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Controlled)); - Assert.Equal(basicCtrlAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.ControlledAdjoint)); - - var data1 = (0L, q1, (q2, q3), Result.One); - Assert.Equal(3, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body, data1)); - Assert.Equal(3, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint, data1)); - - var data2 = (1L, q1, (q2, q3), Result.Zero); - Assert.Equal(6, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body, data2)); - Assert.Equal(4, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint, data2)); - - Assert.Equal(basic * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X")); - Assert.Equal(basicBody * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body)); - Assert.Equal(basicAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint)); - Assert.Equal(basicCtrl * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled)); - Assert.Equal(basicCtrlAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint)); - }); - } - - [Fact] - public void StartUDTOperationCalls() - { - Helper.RunWithMultipleSimulators((s) => - { - var tracker = new StartTracker(s); - StartOperationUDTTest.Run(s).Wait(); - - Assert.Equal(1, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.StartOperationUDTTest")); - - var allVariantsBody = 3; - var allVariantsAdjoint = 2; - var allVariantsCtrl = 2; - var allVariantsAdjointCtrl = 1; - var allVariants = allVariantsBody + allVariantsAdjoint + allVariantsCtrl + allVariantsAdjointCtrl; - Assert.Equal(allVariants, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants")); - Assert.Equal(allVariantsBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Body)); - Assert.Equal(allVariantsAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Adjoint)); - Assert.Equal(allVariantsCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Controlled)); - Assert.Equal(allVariantsAdjointCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.ControlledAdjoint)); - - var basicBody = 12; - var basicAdjoint = 7; - var basicCtrl = 9; - var basicCtrlAdjoint = 7; - var basic = basicBody + basicAdjoint + basicCtrl + basicCtrlAdjoint; - Assert.Equal(basic, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic")); - Assert.Equal(basicBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body)); - Assert.Equal(basicAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint)); - Assert.Equal(basicCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Controlled)); - Assert.Equal(basicCtrlAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.ControlledAdjoint)); - - // Because of unwrapping, udts are not called directly, only their base operation: - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1")); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Body)); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Adjoint)); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Controlled)); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.ControlledAdjoint)); - - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2")); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Body)); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Adjoint)); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Controlled)); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.ControlledAdjoint)); - - Assert.Equal(basic * 4 + 2, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X")); - Assert.Equal(basicBody * 4 + 2, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body)); - Assert.Equal(basicAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint)); - Assert.Equal(basicCtrl * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled)); - Assert.Equal(basicCtrlAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint)); - - var b3Body = 8; - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT3")); - Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT3", OperationFunctor.Body)); - Assert.Equal(b3Body, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.B3")); - Assert.Equal(b3Body, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.B3", OperationFunctor.Body)); ; - }); - } - - - [Fact] - public void StartDataIn() - { - Helper. RunWithMultipleSimulators((s) => - { - var basic = s.Get(); - var q1 = new FreeQubit(1); - var q2 = new FreeQubit(2); - var q3 = new FreeQubit(3); - var expected = (1L, q1, (q2, q3), Result.One); - - var m1 = new Func<(Qubit, Qubit), (Int64, Qubit, (Qubit, Qubit), Result)>((_arg1) => (1L, q1, (_arg1.Item1, _arg1.Item2), Result.One)); - var m2 = new Func((_arg2) => (_arg2, q3)); - var p1 = basic.Partial(m1); - var p2 = p1.Partial(m2); - - AssertTuple(expected, p1.__dataIn((q2, q3)).Value); - AssertTuple(expected, p2.__dataIn((q2)).Value); - - Assert.Equal(new Qubit[] { q1, q2, q3 }, p1.__dataIn((q2, q3)).Qubits); - Assert.Equal(new Qubit[] { q1, q2, q3 }, p2.__dataIn(q2).Qubits); - - Assert.Null(((IApplyData)basic).Qubits); - Assert.Equal(new Qubit[] { q1, null, null }, ((IApplyData)p1).Qubits); - Assert.Equal(new Qubit[] { q1, null, q3 }, ((IApplyData)p2).Qubits); - }); - } - - [Fact] - public void StartUDTDataIn() - { - Helper.RunWithMultipleSimulators((s) => - { - var basic = new UDT1(s.Get()); - var q1 = new FreeQubit(1); - var q2 = new FreeQubit(2); - var q3 = new FreeQubit(3); - var expected = (1L, q1, (q2, q3), Result.One); - - var m1 = new Func<(Qubit, Qubit), (Int64, Qubit, (Qubit, Qubit), Result)>((_arg1) => (1L, q1, (_arg1.Item1, _arg1.Item2), Result.One)); - var m2 = new Func((_arg2) => (_arg2, q3)); - var p1 = ((Basic)basic.Data).Partial(m1); - var p2 = p1.Partial(m2); - - AssertTuple(expected, p1.__dataIn((q2, q3)).Value); - AssertTuple(expected, p2.__dataIn((q2)).Value); - - Assert.Equal(new Qubit[] { q1, q2, q3 }, p1.__dataIn((q2, q3)).Qubits); - Assert.Equal(new Qubit[] { q1, q2, q3 }, p2.__dataIn(q2).Qubits); - - Assert.Null(((IApplyData)basic).Qubits); - Assert.Equal(new Qubit[] { q1, null, null }, ((IApplyData)p1).Qubits); - Assert.Equal(new Qubit[] { q1, null, q3 }, ((IApplyData)p2).Qubits); - }); - } - - private static void AssertTuple(object expected, object actual) - { - var value = PartialMapper.CastTuple(expected.GetType(), actual); - Assert.Equal(expected, value); - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs b/src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs deleted file mode 100644 index f11afdea853..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TrivialSimulator.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Common; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - /// - /// This is a trivial implementation of a Simulator. Only used for unittesting. - /// Not apt to simulate any circuits as it implements no Intrinsic Gates. - /// - public class TrivialSimulator : SimulatorBase - { - public TrivialSimulator() : base(new QubitManagerTrackingScope(32)) - { - } - - public override string Name - { - get - { - return this.GetType().Name; - } - } - } - - /// - /// This is a trivial implementation of a Simulator. Only used for unittesting. - /// Not apt to simulate any circuits as it implements no Intrinsic Gates. - /// - public class ModifiedTrivialSimulator : TrivialSimulator - { } -} - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.UnitTests -{ - /// - /// This is a trivial implementation of a Simulator. Only used for unittesting. - /// Not apt to simulate any circuits as it implements no Intrinsic Gates. - /// - public class TrivialSimulator : Tests.TrivialSimulator - { } -} diff --git a/src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs b/src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs deleted file mode 100644 index 2707ca2b150..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TypeExtensionsTest.cs +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using Microsoft.Quantum.Simulation.Core; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class ApplyData : IApplyData - { - public T Data; - - public ApplyData(T data) - { - this.Data = data; - } - - object IApplyData.Value => this.Data; - - IEnumerable IApplyData.Qubits => QubitsExtractor.Get(typeof(T))?.Extract(Data); - } - - public class GetNonQubitArgumentsAsStringTests - { - [Fact] - public void BasicTypes() - { - Assert.Equal("3", 3.GetNonQubitArgumentsAsString()); - Assert.Equal("False", false.GetNonQubitArgumentsAsString()); - Assert.Equal("\"Foo\"", "Foo".GetNonQubitArgumentsAsString()); - Assert.Equal("\"\"", "".GetNonQubitArgumentsAsString()); - } - - [Fact] - public void OperationTypes() - { - var op = new QuantumSimulator().Get(); - Assert.Equal("H", op.GetNonQubitArgumentsAsString()); - - var op2 = new QuantumSimulator().Get(); - Assert.Equal("CNOT", op2.GetNonQubitArgumentsAsString()); - } - - [Fact] - public void QubitTypes() - { - var q = new FreeQubit(0); - Assert.Null(q.GetNonQubitArgumentsAsString()); - - var qs = new QArray(new[] { new FreeQubit(0) }); - Assert.Null(qs.GetNonQubitArgumentsAsString()); - - qs = new QArray(new[] { new FreeQubit(0), new FreeQubit(1) }); - Assert.Null(qs.GetNonQubitArgumentsAsString()); - - var qtuple = new QTuple(q); - Assert.Null(qtuple.GetNonQubitArgumentsAsString()); - } - - [Fact] - public void TupleTypes() - { - Assert.Equal("(1, 2)", (1, 2).GetNonQubitArgumentsAsString()); - Assert.Equal("(\"foo\", \"bar\")", ("foo", "bar").GetNonQubitArgumentsAsString()); - Assert.Equal("(\"foo\", \"bar\", \"\")", ("foo", "bar", "").GetNonQubitArgumentsAsString()); - Assert.Equal("(\"foo\", (\"bar\", \"car\"))", ("foo", ("bar", "car")).GetNonQubitArgumentsAsString()); - Assert.Equal("((\"foo\"), (\"bar\", \"car\"))", (("foo", new FreeQubit(0)), ("bar", "car")).GetNonQubitArgumentsAsString()); - - var op = new QuantumSimulator().Get(); - var opTuple = new QTuple<(ICallable, string)>((op, "foo")); - Assert.Equal("(H, \"foo\")", opTuple.GetNonQubitArgumentsAsString()); - - var qtuple = new QTuple<(Qubit, string)>((new FreeQubit(0), "foo")); - Assert.Equal("(\"foo\")", qtuple.GetNonQubitArgumentsAsString()); - } - - [Fact] - public void ArrayTypes() - { - Assert.Equal("[1, 2, 3]", new[] { 1, 2, 3 }.GetNonQubitArgumentsAsString()); - Assert.Equal("[\"foo\", \"bar\"]", new[] { "foo", "bar" }.GetNonQubitArgumentsAsString()); - - var opArr = new ICallable[] { - new QuantumSimulator().Get(), - new QuantumSimulator().Get(), - new QuantumSimulator().Get(), - }; - Assert.Equal("[H, CNOT, Ry]", opArr.GetNonQubitArgumentsAsString()); - - var qTupleArr = new[] { - (new FreeQubit(0), "foo"), - (new FreeQubit(1), "bar"), - }; - Assert.Equal("[(\"foo\"), (\"bar\")]", qTupleArr.GetNonQubitArgumentsAsString()); - - var qArrayBool = new QArray(new[] { false, true }); - Assert.Equal("[False, True]", qArrayBool.GetNonQubitArgumentsAsString()); - } - - [Fact] - public void IApplyDataTypes() - { - IApplyData data; - data = new ApplyData(3); - Assert.Equal("3", data.GetNonQubitArgumentsAsString()); - - data = new ApplyData(false); - Assert.Equal("False", data.GetNonQubitArgumentsAsString()); - - data = new ApplyData("Foo"); - Assert.Equal("\"Foo\"", data.GetNonQubitArgumentsAsString()); - - var op = new QuantumSimulator().Get(); - data = new ApplyData(op); - Assert.Equal("H", data.GetNonQubitArgumentsAsString()); - - data = new ApplyData>((1, "foo")); - Assert.Equal("(1, \"foo\")", data.GetNonQubitArgumentsAsString()); - - data = new ApplyData, ValueTuple>>((("foo", new FreeQubit(0)), ("bar", "car"))); - Assert.Equal("((\"foo\"), (\"bar\", \"car\"))", data.GetNonQubitArgumentsAsString()); - - data = new ApplyData(new[] { 1, 2, 3 }); - Assert.Equal("[1, 2, 3]", data.GetNonQubitArgumentsAsString()); - - var arr = new[] { - (new FreeQubit(0), "foo"), - (new FreeQubit(1), "bar"), - }; - data = new ApplyData<(FreeQubit, string)[]>(arr); - Assert.Equal("[(\"foo\"), (\"bar\")]", data.GetNonQubitArgumentsAsString()); - - var qtupleWithString = new QTuple<(Qubit, string)>((new FreeQubit(0), "foo")); - data = new ApplyData>(qtupleWithString); - Assert.Equal("(\"foo\")", data.GetNonQubitArgumentsAsString()); - - var q = new FreeQubit(0); - data = new ApplyData(q); - Assert.Null(data.GetNonQubitArgumentsAsString()); - - var qs = new QArray(new[] { new FreeQubit(0), new FreeQubit(1) }); - data = new ApplyData>(qs); - Assert.Null(data.GetNonQubitArgumentsAsString()); - - var qtuple = new QTuple(q); - data = new ApplyData>(qtuple); - Assert.Null(data.GetNonQubitArgumentsAsString()); - } - } -} diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj index a8ac8f18e82..7868f994fe0 100644 --- a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj +++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj @@ -1,5 +1,4 @@  - @@ -7,8 +6,6 @@ netstandard2.1 - false - false @@ -49,10 +46,6 @@ - - runtimes\win-x64\native\%(RecursiveDir)%(FileName)%(Extension) diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props index 6076e7bc662..a6960048494 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props @@ -36,6 +36,7 @@ + From 0212b67b291c88d116878058b6cc10a1f36912fc Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Sun, 23 Aug 2020 15:06:35 -0700 Subject: [PATCH 12/17] Adding implementation for new intrinsics --- .../Circuits/VerifyUnitary.qs | 2 +- .../OperationsTestHelper.cs | 2 +- .../Microsoft.Quantum.Simulators.Type2.csproj | 14 ++-- .../Simulators/QuantumSimulator/IsingXX.cs | 77 +++++++++++++++++++ .../Simulators/QuantumSimulator/IsingYY.cs | 77 +++++++++++++++++++ .../Simulators/QuantumSimulator/IsingZZ.cs | 77 +++++++++++++++++++ .../Simulators/QuantumSimulator/Rx.cs | 61 +++++++++++++++ .../Simulators/QuantumSimulator/Ry.cs | 61 +++++++++++++++ .../Simulators/QuantumSimulator/Rz.cs | 61 +++++++++++++++ .../Simulators/QuantumSimulator/SWAP.cs | 60 +++++++++++++++ 10 files changed, 483 insertions(+), 9 deletions(-) diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs index e4f2d61388e..d4748e596f3 100644 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs +++ b/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { /// then it tests Controlled with different number of control qubits, also verifying that /// Adjoint Controlled works. /// - operation VerifyUnitary (gate : (Qubit => Unit : Adjoint, Controlled), start : (Pauli, Result), expected : (Complex, Complex)) : Unit { + operation VerifyUnitary (gate : (Qubit => Unit is Adj + Ctl), start : (Pauli, Result), expected : (Complex, Complex)) : Unit { using (qubits = Qubit[1]) { diff --git a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs index b1dfbd7ae70..4797910628b 100644 --- a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs +++ b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs @@ -156,7 +156,7 @@ internal static void ctrlErrorConditionsTests(SimulatorBase sim, Action<(IQArray /// /// A shell for simple Controlled tests. It calls the controlled operation with 0..4 control qubits - /// set to all possible combination of 1 & 0. + /// set to all possible combination of 1 and 0. /// internal static void ctrlTestShell(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled, Action, Qubit> test) { diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj index 7868f994fe0..4c380a1c5c7 100644 --- a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj +++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj @@ -20,22 +20,22 @@ - - - + + + - - - + + + - + diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs index e69de29bb2d..b96a81be2f8 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + + public partial class QuantumSimulator + { + public class QSimIsingXX : Intrinsic.IsingXX + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Exp")] + private static extern void Exp(uint id, uint n, Pauli[] paulis, double angle, uint[] ids); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCExp")] + private static extern void MCExp(uint id, uint n, Pauli[] paulis, double angle, uint nc, uint[] ctrls, uint[] ids); + + private QuantumSimulator Simulator { get; } + + public QSimIsingXX(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(double, Qubit, Qubit), QVoid> Body => (args) => + { + var (angle, qubit1, qubit2) = args; + var paulis = new Pauli[]{ Pauli.PauliX, Pauli.PauliX }; + var targets = new QArray(new Qubit[]{ qubit1, qubit2 }); + CheckAngle(angle); + Simulator.CheckQubits(targets); + + Exp(Simulator.Id, (uint)targets.Length, paulis, angle, targets.GetIds()); + + return QVoid.Instance; + }; + + public override Func<(double, Qubit, Qubit), QVoid> AdjointBody => (args) => + { + var (angle, qubit1, qubit2) = args; + + return this.Body.Invoke((-angle, qubit1, qubit2)); + }; + + public override Func<(IQArray, (double, Qubit, Qubit)), QVoid> ControlledBody => (args) => + { + var (ctrls, (angle, qubit1, qubit2)) = args; + + if (ctrls == null || ctrls.Length == 0) + { + this.Body.Invoke((angle, qubit1, qubit2)); + } + else + { + var targets = new QArray(new Qubit[]{ qubit1, qubit2 }); + var paulis = new Pauli[]{ Pauli.PauliX, Pauli.PauliX }; + CheckAngle(angle); + Simulator.CheckQubits(QArray.Add(ctrls, targets)); + + MCExp(Simulator.Id, (uint)targets.Length, paulis, angle, (uint)ctrls.Length, ctrls.GetIds(), targets.GetIds()); + } + + return QVoid.Instance; + }; + + public override Func<(IQArray, (double, Qubit, Qubit)), QVoid> ControlledAdjointBody => (args) => + { + var (ctrls, (angle, qubit1, qubit2)) = args; + + return this.ControlledBody.Invoke((ctrls, (-angle, qubit1, qubit2))); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs index e69de29bb2d..83af3da0238 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + + public partial class QuantumSimulator + { + public class QSimIsingYY : Intrinsic.IsingYY + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Exp")] + private static extern void Exp(uint id, uint n, Pauli[] paulis, double angle, uint[] ids); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCExp")] + private static extern void MCExp(uint id, uint n, Pauli[] paulis, double angle, uint nc, uint[] ctrls, uint[] ids); + + private QuantumSimulator Simulator { get; } + + public QSimIsingYY(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(double, Qubit, Qubit), QVoid> Body => (args) => + { + var (angle, qubit1, qubit2) = args; + var paulis = new Pauli[]{ Pauli.PauliY, Pauli.PauliY }; + var targets = new QArray(new Qubit[]{ qubit1, qubit2 }); + CheckAngle(angle); + Simulator.CheckQubits(targets); + + Exp(Simulator.Id, (uint)targets.Length, paulis, angle, targets.GetIds()); + + return QVoid.Instance; + }; + + public override Func<(double, Qubit, Qubit), QVoid> AdjointBody => (args) => + { + var (angle, qubit1, qubit2) = args; + + return this.Body.Invoke((-angle, qubit1, qubit2)); + }; + + public override Func<(IQArray, (double, Qubit, Qubit)), QVoid> ControlledBody => (args) => + { + var (ctrls, (angle, qubit1, qubit2)) = args; + + if (ctrls == null || ctrls.Length == 0) + { + this.Body.Invoke((angle, qubit1, qubit2)); + } + else + { + var targets = new QArray(new Qubit[]{ qubit1, qubit2 }); + var paulis = new Pauli[]{ Pauli.PauliY, Pauli.PauliY }; + CheckAngle(angle); + Simulator.CheckQubits(QArray.Add(ctrls, targets)); + + MCExp(Simulator.Id, (uint)targets.Length, paulis, angle, (uint)ctrls.Length, ctrls.GetIds(), targets.GetIds()); + } + + return QVoid.Instance; + }; + + public override Func<(IQArray, (double, Qubit, Qubit)), QVoid> ControlledAdjointBody => (args) => + { + var (ctrls, (angle, qubit1, qubit2)) = args; + + return this.ControlledBody.Invoke((ctrls, (-angle, qubit1, qubit2))); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs index e69de29bb2d..c732509a9ce 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + + public partial class QuantumSimulator + { + public class QSimIsingZZ : Intrinsic.IsingZZ + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Exp")] + private static extern void Exp(uint id, uint n, Pauli[] paulis, double angle, uint[] ids); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCExp")] + private static extern void MCExp(uint id, uint n, Pauli[] paulis, double angle, uint nc, uint[] ctrls, uint[] ids); + + private QuantumSimulator Simulator { get; } + + public QSimIsingZZ(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(double, Qubit, Qubit), QVoid> Body => (args) => + { + var (angle, qubit1, qubit2) = args; + var paulis = new Pauli[]{ Pauli.PauliZ, Pauli.PauliZ }; + var targets = new QArray(new Qubit[]{ qubit1, qubit2 }); + CheckAngle(angle); + Simulator.CheckQubits(targets); + + Exp(Simulator.Id, (uint)targets.Length, paulis, angle, targets.GetIds()); + + return QVoid.Instance; + }; + + public override Func<(double, Qubit, Qubit), QVoid> AdjointBody => (args) => + { + var (angle, qubit1, qubit2) = args; + + return this.Body.Invoke((-angle, qubit1, qubit2)); + }; + + public override Func<(IQArray, (double, Qubit, Qubit)), QVoid> ControlledBody => (args) => + { + var (ctrls, (angle, qubit1, qubit2)) = args; + + if (ctrls == null || ctrls.Length == 0) + { + this.Body.Invoke((angle, qubit1, qubit2)); + } + else + { + var targets = new QArray(new Qubit[]{ qubit1, qubit2 }); + var paulis = new Pauli[]{ Pauli.PauliZ, Pauli.PauliZ }; + CheckAngle(angle); + Simulator.CheckQubits(QArray.Add(ctrls, targets)); + + MCExp(Simulator.Id, (uint)targets.Length, paulis, angle, (uint)ctrls.Length, ctrls.GetIds(), targets.GetIds()); + } + + return QVoid.Instance; + }; + + public override Func<(IQArray, (double, Qubit, Qubit)), QVoid> ControlledAdjointBody => (args) => + { + var (ctrls, (angle, qubit1, qubit2)) = args; + + return this.ControlledBody.Invoke((ctrls, (-angle, qubit1, qubit2))); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/Rx.cs b/src/Simulation/Simulators/QuantumSimulator/Rx.cs index e69de29bb2d..4d6c60ecc84 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Rx.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Rx.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + + public partial class QuantumSimulator + { + public class QSimRx : Intrinsic.Rx + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] + private static extern void R(uint id, Pauli basis, double angle, uint qubit); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCR")] + private static extern void MCR(uint id, Pauli basis, double angle, uint count, uint[] ctrls, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimRx(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(double, Qubit), QVoid> Body => (args) => + { + var (angle, target) = args; + Simulator.CheckQubit(target, nameof(target)); + CheckAngle(angle); + R(Simulator.Id, Pauli.PauliX, angle, (uint)target.Id); + return QVoid.Instance; + }; + + public override Func<(double, Qubit), QVoid> AdjointBody => (_args) => + { + var (angle, q1) = _args; + + return this.Body.Invoke((-angle, q1)); + }; + + public override Func<(IQArray, (double, Qubit)), QVoid> ControlledBody => (args) => + { + var (ctrls, (angle, target)) = args; + Simulator.CheckQubits(ctrls, target); + CheckAngle(angle); + MCR(Simulator.Id, Pauli.PauliX, angle, (uint)ctrls.Length, ctrls.GetIds(), (uint)target.Id); + return QVoid.Instance; + }; + + public override Func<(IQArray, (double, Qubit)), QVoid> ControlledAdjointBody => (_args) => + { + var (ctrls, (angle, q1)) = _args; + + return this.ControlledBody.Invoke((ctrls, (-angle, q1))); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/Ry.cs b/src/Simulation/Simulators/QuantumSimulator/Ry.cs index e69de29bb2d..f669deaafa2 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Ry.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Ry.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + + public partial class QuantumSimulator + { + public class QSimRy : Intrinsic.Ry + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] + private static extern void R(uint id, Pauli basis, double angle, uint qubit); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCR")] + private static extern void MCR(uint id, Pauli basis, double angle, uint count, uint[] ctrls, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimRy(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(double, Qubit), QVoid> Body => (args) => + { + var (angle, target) = args; + Simulator.CheckQubit(target, nameof(target)); + CheckAngle(angle); + R(Simulator.Id, Pauli.PauliY, angle, (uint)target.Id); + return QVoid.Instance; + }; + + public override Func<(double, Qubit), QVoid> AdjointBody => (_args) => + { + var (angle, q1) = _args; + + return this.Body.Invoke((-angle, q1)); + }; + + public override Func<(IQArray, (double, Qubit)), QVoid> ControlledBody => (args) => + { + var (ctrls, (angle, target)) = args; + Simulator.CheckQubits(ctrls, target); + CheckAngle(angle); + MCR(Simulator.Id, Pauli.PauliY, angle, (uint)ctrls.Length, ctrls.GetIds(), (uint)target.Id); + return QVoid.Instance; + }; + + public override Func<(IQArray, (double, Qubit)), QVoid> ControlledAdjointBody => (_args) => + { + var (ctrls, (angle, q1)) = _args; + + return this.ControlledBody.Invoke((ctrls, (-angle, q1))); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/Rz.cs b/src/Simulation/Simulators/QuantumSimulator/Rz.cs index e69de29bb2d..db91d1be5e7 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Rz.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Rz.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + + public partial class QuantumSimulator + { + public class QSimRz : Intrinsic.Rz + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] + private static extern void R(uint id, Pauli basis, double angle, uint qubit); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCR")] + private static extern void MCR(uint id, Pauli basis, double angle, uint count, uint[] ctrls, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimRz(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(double, Qubit), QVoid> Body => (args) => + { + var (angle, target) = args; + Simulator.CheckQubit(target, nameof(target)); + CheckAngle(angle); + R(Simulator.Id, Pauli.PauliZ, angle, (uint)target.Id); + return QVoid.Instance; + }; + + public override Func<(double, Qubit), QVoid> AdjointBody => (_args) => + { + var (angle, q1) = _args; + + return this.Body.Invoke((-angle, q1)); + }; + + public override Func<(IQArray, (double, Qubit)), QVoid> ControlledBody => (args) => + { + var (ctrls, (angle, target)) = args; + Simulator.CheckQubits(ctrls, target); + CheckAngle(angle); + MCR(Simulator.Id, Pauli.PauliZ, angle, (uint)ctrls.Length, ctrls.GetIds(), (uint)target.Id); + return QVoid.Instance; + }; + + public override Func<(IQArray, (double, Qubit)), QVoid> ControlledAdjointBody => (_args) => + { + var (ctrls, (angle, q1)) = _args; + + return this.ControlledBody.Invoke((ctrls, (-angle, q1))); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/SWAP.cs b/src/Simulation/Simulators/QuantumSimulator/SWAP.cs index e69de29bb2d..201fd564a31 100644 --- a/src/Simulation/Simulators/QuantumSimulator/SWAP.cs +++ b/src/Simulation/Simulators/QuantumSimulator/SWAP.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + + public partial class QuantumSimulator + { + public class QSimSWAP : Intrinsic.SWAP + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCX")] + private static extern void MCX(uint id, uint count, uint[] ctrls, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimSWAP(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(Qubit, Qubit), QVoid> Body => (args) => + { + var (qubit1, qubit2) = args; + var ctrls = new QArray(qubit1); + Simulator.CheckQubits(ctrls, qubit2); + + MCX(Simulator.Id, (uint)ctrls.Length, ctrls.GetIds(), (uint)qubit2.Id); + + return QVoid.Instance; + }; + + public override Func<(IQArray, (Qubit, Qubit)), QVoid> ControlledBody => (args) => + { + var (ctrls, (qubit1, qubit2)) = args; + + if ((ctrls == null) || (ctrls.Count == 0)) + { + this.Apply((qubit1, qubit2)); + } + else + { + var ctrls_1 = QArray.Add(ctrls, new QArray(qubit1)); + var ctrls_2 = QArray.Add(ctrls, new QArray(qubit2)); + Simulator.CheckQubits(ctrls_1, qubit2); + + MCX(Simulator.Id, (uint)ctrls_1.Length, ctrls_1.GetIds(), (uint)qubit2.Id); + MCX(Simulator.Id, (uint)ctrls_2.Length, ctrls_2.GetIds(), (uint)qubit1.Id); + MCX(Simulator.Id, (uint)ctrls_1.Length, ctrls_1.GetIds(), (uint)qubit2.Id); + } + + return QVoid.Instance; + }; + + } + } +} From d86183054610bcf00422c2e878af725caa5cc5b9 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Mon, 24 Aug 2020 15:02:05 -0700 Subject: [PATCH 13/17] Get input validation on decompositions working --- .../Microsoft.Quantum.Simulators.Type2.csproj | 2 + .../Simulators/QuantumSimulator/Checks.cs | 47 +++++++++++++++++++ .../Decompositions/ExpFracFromIsing.qs | 1 + .../Decompositions/ExpFromIsing.qs | 3 +- .../Decompositions/MeasureWithNoReuse.qs | 1 + .../TargetDefinitions/Decompositions/R.qs | 1 + .../TargetDefinitions/Intrinsic/Checks.qs | 18 +++++++ .../TargetPackages/Type2.Package.props | 2 + 8 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/Simulation/Simulators/QuantumSimulator/Checks.cs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/Checks.qs diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj index 4c380a1c5c7..0cb5040d5c9 100644 --- a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj +++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj @@ -40,6 +40,8 @@ + + diff --git a/src/Simulation/Simulators/QuantumSimulator/Checks.cs b/src/Simulation/Simulators/QuantumSimulator/Checks.cs new file mode 100644 index 00000000000..040c2161837 --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/Checks.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators +{ + public partial class QuantumSimulator + { + public class QSimCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness + { + private QuantumSimulator Simulator { get; } + public QSimCheckQubitUniqueness(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func, QVoid> Body => (qubits) => + { + Simulator.CheckQubits(qubits); + return QVoid.Instance; + }; + + public override Func<(IQArray, IQArray), QVoid> ControlledBody => (args) => + { + var (ctrls, qubits) = args; + Simulator.CheckQubits(QArray.Add(ctrls, qubits)); + return QVoid.Instance; + }; + } + + public class QSimRotationAngleValidation : Intrinsic.RotationAngleValidation + { + public QSimRotationAngleValidation(QuantumSimulator m) : base(m) + { + } + + public override Func Body => (angle) => + { + CheckAngle(angle); + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs index b5ea0012eed..58cc9d7dcc2 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs @@ -32,6 +32,7 @@ namespace Microsoft.Quantum.Intrinsic { @EnableTestingViaName("Test.TargetDefinitions.ExpFrac") operation ExpFrac (paulis : Pauli[], numerator : Int, power : Int, qubits : Qubit[]) : Unit is Adj + Ctl { body(...) { + CheckQubitUniqueness(qubits); if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'target' must have the same length"; } if (Length(paulis) != 0) { diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs index 0501dbca050..5a9fee5ab2e 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs @@ -26,11 +26,12 @@ namespace Microsoft.Quantum.Intrinsic { @EnableTestingViaName("Test.TargetDefinitions.Exp") operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit is Adj + Ctl { body(...) { + CheckQubitUniqueness(qubits); + RotationAngleValidation(theta); if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'qubits' must have the same length"; } let (newPaulis, newQubits) = RemovePauliI(paulis, qubits); if (Length(newPaulis) != 0) { - if (Length(newPaulis) == 2 and newPaulis[0] != newPaulis[1]) { fail $"Target Package supports only rotation around XX, YY, ZZ, given {paulis}"; } ExpNoIdUtil(newPaulis, theta , newQubits, R(_, -2.0 * theta, _)); } else { diff --git a/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs b/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs index f64e83b1d4b..770579cc087 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/MeasureWithNoReuse.qs @@ -46,6 +46,7 @@ namespace Microsoft.Quantum.Intrinsic { return M(qubits[0]); } else { + CheckQubitUniqueness(qubits); using (q = Qubit()) { within { H(q); diff --git a/src/Simulation/TargetDefinitions/Decompositions/R.qs b/src/Simulation/TargetDefinitions/Decompositions/R.qs index b5935a4ed7b..eb3bdb04f7f 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/R.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/R.qs @@ -40,6 +40,7 @@ namespace Microsoft.Quantum.Intrinsic { } } else { + RotationAngleValidation(theta); ApplyGlobalPhase( - theta / 2.0 ); } } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs new file mode 100644 index 00000000000..a07aeff323c --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + @EnableTestingViaName("Test.TargetDefinitions.CheckQubitUniqueness") + operation CheckQubitUniqueness (qubits : Qubit[]) : Unit is Adj + Ctl{ + body intrinsic; + adjoint self; + } + + @EnableTestingViaName("Test.TargetDefinitions.RotationAngleValidation") + function RotationAngleValidation (angle : Double) : Unit { + body intrinsic; + } + +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props index a6960048494..be0f1d9635e 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props @@ -17,6 +17,8 @@ + + From 6eb36f563b72597b3f948b449643e258d7a9acbc Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Mon, 24 Aug 2020 15:08:11 -0700 Subject: [PATCH 14/17] Adding doc comments for checks. --- .../TargetDefinitions/Intrinsic/Checks.qs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs index a07aeff323c..37bcc86889b 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs @@ -4,12 +4,36 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; + /// # Summary + /// Checks that all qubits operated on are unique. + /// + /// # Description + /// \begin{align} + /// e^{i \theta [P_0 \otimes P_1 \cdots P_{N-1}]}, + /// \end{align} + /// where $P_i$ is the $i$th element of `paulis`, and where + /// $N = $`Length(paulis)`. + /// + /// # Input + /// ## qubits + /// The array of qubits to verify for uniqueness. In the controlled variant + /// the full list of qubits among targets and controls are verified to be unique. @EnableTestingViaName("Test.TargetDefinitions.CheckQubitUniqueness") operation CheckQubitUniqueness (qubits : Qubit[]) : Unit is Adj + Ctl{ body intrinsic; adjoint self; } + + /// # Summary + /// Validates that the given angle is a Double that can be used for rotation. + /// + /// # Description + /// Validates that the value of theDouble representing a rotation angle is neither infinite nor NaN. + /// + /// # Input + /// ## angle + /// The Double to validate. @EnableTestingViaName("Test.TargetDefinitions.RotationAngleValidation") function RotationAngleValidation (angle : Double) : Unit { body intrinsic; From fc0f1c84eea858675f0b47baadc982e15fbda7f0 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 25 Aug 2020 11:28:05 -0700 Subject: [PATCH 15/17] Undoing rename to clean up diff --- .../{Simulators.Core.Tests => Simulators.Tests}/App.config | 0 .../Circuits/AssertEqual.cs | 0 .../Circuits/AssertEqual.qs | 0 .../Circuits/BitOperations.qs | 0 .../Circuits/Bug1514.qs | 0 .../Circuits/Bug2212.qs | 0 .../Circuits/Bug2248.qs | 0 .../Circuits/Bug2469.qs | 0 .../Circuits/Bug3059.qs | 0 .../Circuits/Bug3758.qs | 0 .../Circuits/CallableInterfacesTest.qs | 0 .../Circuits/ClassicalRotationsTest.qs | 0 .../Circuits/ClosedType.qs | 0 .../Circuits/ConditionalExpression.qs | 0 .../Circuits/Convert.qs | 0 .../Circuits/CoreOperations.qs | 0 .../Circuits/ExpTest.qs | 0 .../{Simulators.Core.Tests => Simulators.Tests}/Circuits/Fail.qs | 0 .../Circuits/Functions.qs | 0 .../Circuits/Generics.qs | 0 .../Circuits/GetAvailableTest.qs | 0 .../Circuits/Issue132.qs | 0 .../Circuits/Issue76.qs | 0 .../Circuits/JointMeasureTest.qs | 0 .../Circuits/Length.qs | 0 .../Circuits/NamedItems.qs | 0 .../Circuits/Namespaces.qs | 0 .../Circuits/NativeOperations.cs | 0 .../Circuits/NativeOperations.qs | 0 .../Circuits/PrimitiveEquivalences.qs | 0 .../Circuits/Recursion.qs | 0 .../Circuits/RepeatUntilSuccess.qs | 0 .../Circuits/ResourcesEstimator.qs | 0 .../Circuits/RuntimeMetadataTest.qs | 0 .../Circuits/SetQubit.qs | 0 .../Circuits/StartOperation.qs | 0 .../Circuits/SwapTest.qs | 0 .../Circuits/TeleportTest.qs | 0 .../Circuits/Tuples.qs | 0 .../Circuits/UnitTests.qs | 0 .../Circuits/UserDefinedTypes.qs | 0 .../Circuits/VerifyUnitary.qs | 0 .../Circuits/bug3223.qs | 0 .../{Simulators.Core.Tests => Simulators.Tests}/CoreTests.cs | 0 .../DebuggingToolsTests.cs | 0 .../DiagnosticsWrappers.qs | 0 .../{Simulators.Core.Tests => Simulators.Tests}/GenericsTests.cs | 0 .../{Simulators.Core.Tests => Simulators.Tests}/GetQubitsTests.cs | 0 .../NativeOperationsTests.cs | 0 .../OperationsTestHelper.cs | 0 .../PartialMapperTests.cs | 0 .../PrimitivesExtensionsTests.cs | 0 .../{Simulators.Core.Tests => Simulators.Tests}/QArrayTests.cs | 0 .../QCTraceSimulatorPrimitivesTests.cs | 0 .../QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs | 0 .../QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs | 0 .../ThreePlusQubitOperationsTests.qs | 0 .../QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs | 0 .../{Simulators.Core.Tests => Simulators.Tests}/QTupleTests.cs | 0 .../QuantumSimulatorTests/BasicTests.cs | 0 .../QuantumSimulatorTests/CircuitsTests.cs | 0 .../QuantumSimulatorTests/QubitReleaseTest.cs | 0 .../QuantumSimulatorTests/VerifyGates.cs | 0 .../QuantumTestSuite.cs | 0 .../QuantumTestSuite/AssertEqualInPlace.qs | 0 .../QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs | 0 .../QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs | 0 .../QuantumTestSuite/AssertProbMultiQubit.qs | 0 .../QuantumTestSuite/AssertProbOneQubit.qs | 0 .../QuantumTestSuite/AssertQubitUnitary.qs | 0 .../QuantumTestSuite/AssertState.qs | 0 .../QuantumTestSuite/AssertUnitary.qs | 0 .../QuantumTestSuite/Complex.qs | 0 .../QuantumTestSuite/Config.qs | 0 .../QuantumTestSuite/ControlledOperationTester.qs | 0 .../QuantumTestSuite/ControlledOperationsTestUtils.qs | 0 .../QuantumTestSuite/IterateThroughCartesianProduct.qs | 0 .../QuantumTestSuite/JointOneQubitTests.qs | 0 .../QuantumTestSuite/KnownIssues.qs | 0 .../QuantumTestSuite/LinearAlgebra.qs | 0 .../QuantumTestSuite/ManyControlQubitsTest.qs | 0 .../QuantumTestSuite/Math.qs | 0 .../QuantumTestSuite/Matrices.qs | 0 .../QuantumTestSuite/OneQubitTestList.qs | 0 .../QuantumTestSuite/OneQubitUnitaries.qs | 0 .../QuantumTestSuite/PauliExpectation.qs | 0 .../QuantumTestSuite/SelfTests.qs | 0 .../QuantumTestSuite/TestSuiteCalculations.nb | 0 .../QuantumTestSuite/ThreeQubitUnitaries.qs | 0 .../QuantumTestSuite/TwoQubitUnitaries.qs | 0 .../QubitManagerTests.cs | 0 .../{Simulators.Core.Tests => Simulators.Tests}/RangeTests.cs | 0 .../ResourcesEstimatorTests.cs | 0 .../RuntimeMetadataTests.cs | 0 .../SimulatorBaseTests.cs | 0 .../StackTraceTests.cs | 0 .../StartOperationTests.cs | 0 .../HoneywellExe/ClassicallyControlledSupportTests.qs | 0 .../TestProjects/HoneywellExe/HoneywellExe.csproj | 0 .../TestProjects/HoneywellExe/MeasurementSupportTests.qs | 0 .../TestProjects/IntrinsicTests/IntrinsicTests.csproj | 0 .../TestProjects/IntrinsicTests/Random/Tests.qs | 0 .../TestProjects/IonQExe/IonQExe.csproj | 0 .../TestProjects/IonQExe/MeasurementSupportTests.qs | 0 .../TestProjects/Library with Spaces/Library with Spaces.csproj | 0 .../TestProjects/Library with Spaces/Library.qs | 0 .../TestProjects/Library1/Library.qs | 0 .../TestProjects/Library1/Library1.csproj | 0 .../TestProjects/Library2/Library.qs | 0 .../TestProjects/Library2/Library2.csproj | 0 .../TestProjects/QCIExe/ClassicallyControlledSupportTests.qs | 0 .../TestProjects/QCIExe/MeasurementSupportTests.qs | 0 .../TestProjects/QCIExe/QCIExe.csproj | 0 .../TestProjects/QsharpExe/Main.qs | 0 .../TestProjects/QsharpExe/QsharpExe.csproj | 0 .../TestProjects/TargetedExe/Program.qs | 0 .../TestProjects/TargetedExe/TargetedExe.csproj | 0 .../TestProjects/UnitTests/Facts.qs | 0 .../TestProjects/UnitTests/Hello.qs | 0 .../TestProjects/UnitTests/HoneywellSimulation.qs | 0 .../TestProjects/UnitTests/IonQSimulation.qs | 0 .../TestProjects/UnitTests/QCISimulation.qs | 0 .../TestProjects/UnitTests/SpaceTests.qs | 0 .../TestProjects/UnitTests/TestNameTests.qs | 0 .../TestProjects/UnitTests/UnitTests.csproj | 0 .../Tests.Microsoft.Quantum.Simulators.csproj | 0 .../ToffoliSimulatorTests.cs | 0 .../TrivialSimulator.cs | 0 .../TypeExtensionsTest.cs | 0 129 files changed, 0 insertions(+), 0 deletions(-) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/App.config (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/AssertEqual.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/AssertEqual.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/BitOperations.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Bug1514.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Bug2212.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Bug2248.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Bug2469.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Bug3059.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Bug3758.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/CallableInterfacesTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/ClassicalRotationsTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/ClosedType.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/ConditionalExpression.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Convert.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/CoreOperations.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/ExpTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Fail.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Functions.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Generics.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/GetAvailableTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Issue132.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Issue76.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/JointMeasureTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Length.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/NamedItems.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Namespaces.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/NativeOperations.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/NativeOperations.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/PrimitiveEquivalences.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Recursion.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/RepeatUntilSuccess.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/ResourcesEstimator.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/RuntimeMetadataTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/SetQubit.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/StartOperation.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/SwapTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/TeleportTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/Tuples.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/UnitTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/UserDefinedTypes.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/VerifyUnitary.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Circuits/bug3223.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/CoreTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/DebuggingToolsTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/DiagnosticsWrappers.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/GenericsTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/GetQubitsTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/NativeOperationsTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/OperationsTestHelper.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/PartialMapperTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/PrimitivesExtensionsTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QArrayTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QCTraceSimulatorPrimitivesTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QTupleTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumSimulatorTests/BasicTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumSimulatorTests/CircuitsTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumSimulatorTests/QubitReleaseTest.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumSimulatorTests/VerifyGates.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertEqualInPlace.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertProbMultiQubit.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertProbOneQubit.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertQubitUnitary.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertState.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/AssertUnitary.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/Complex.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/Config.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/ControlledOperationTester.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/ControlledOperationsTestUtils.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/IterateThroughCartesianProduct.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/JointOneQubitTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/KnownIssues.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/LinearAlgebra.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/ManyControlQubitsTest.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/Math.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/Matrices.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/OneQubitTestList.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/OneQubitUnitaries.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/PauliExpectation.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/SelfTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/TestSuiteCalculations.nb (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/ThreeQubitUnitaries.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QuantumTestSuite/TwoQubitUnitaries.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/QubitManagerTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/RangeTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/ResourcesEstimatorTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/RuntimeMetadataTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/SimulatorBaseTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/StackTraceTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/StartOperationTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/HoneywellExe/HoneywellExe.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/HoneywellExe/MeasurementSupportTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/IntrinsicTests/IntrinsicTests.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/IntrinsicTests/Random/Tests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/IonQExe/IonQExe.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/IonQExe/MeasurementSupportTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/Library with Spaces/Library with Spaces.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/Library with Spaces/Library.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/Library1/Library.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/Library1/Library1.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/Library2/Library.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/Library2/Library2.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/QCIExe/MeasurementSupportTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/QCIExe/QCIExe.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/QsharpExe/Main.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/QsharpExe/QsharpExe.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/TargetedExe/Program.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/TargetedExe/TargetedExe.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/Facts.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/Hello.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/HoneywellSimulation.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/IonQSimulation.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/QCISimulation.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/SpaceTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/TestNameTests.qs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TestProjects/UnitTests/UnitTests.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/Tests.Microsoft.Quantum.Simulators.csproj (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/ToffoliSimulatorTests.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TrivialSimulator.cs (100%) rename src/Simulation/{Simulators.Core.Tests => Simulators.Tests}/TypeExtensionsTest.cs (100%) diff --git a/src/Simulation/Simulators.Core.Tests/App.config b/src/Simulation/Simulators.Tests/App.config similarity index 100% rename from src/Simulation/Simulators.Core.Tests/App.config rename to src/Simulation/Simulators.Tests/App.config diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.cs b/src/Simulation/Simulators.Tests/Circuits/AssertEqual.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.cs rename to src/Simulation/Simulators.Tests/Circuits/AssertEqual.cs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.qs b/src/Simulation/Simulators.Tests/Circuits/AssertEqual.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/AssertEqual.qs rename to src/Simulation/Simulators.Tests/Circuits/AssertEqual.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/BitOperations.qs b/src/Simulation/Simulators.Tests/Circuits/BitOperations.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/BitOperations.qs rename to src/Simulation/Simulators.Tests/Circuits/BitOperations.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Bug1514.qs b/src/Simulation/Simulators.Tests/Circuits/Bug1514.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Bug1514.qs rename to src/Simulation/Simulators.Tests/Circuits/Bug1514.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Bug2212.qs b/src/Simulation/Simulators.Tests/Circuits/Bug2212.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Bug2212.qs rename to src/Simulation/Simulators.Tests/Circuits/Bug2212.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Bug2248.qs b/src/Simulation/Simulators.Tests/Circuits/Bug2248.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Bug2248.qs rename to src/Simulation/Simulators.Tests/Circuits/Bug2248.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Bug2469.qs b/src/Simulation/Simulators.Tests/Circuits/Bug2469.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Bug2469.qs rename to src/Simulation/Simulators.Tests/Circuits/Bug2469.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Bug3059.qs b/src/Simulation/Simulators.Tests/Circuits/Bug3059.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Bug3059.qs rename to src/Simulation/Simulators.Tests/Circuits/Bug3059.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Bug3758.qs b/src/Simulation/Simulators.Tests/Circuits/Bug3758.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Bug3758.qs rename to src/Simulation/Simulators.Tests/Circuits/Bug3758.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/CallableInterfacesTest.qs b/src/Simulation/Simulators.Tests/Circuits/CallableInterfacesTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/CallableInterfacesTest.qs rename to src/Simulation/Simulators.Tests/Circuits/CallableInterfacesTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/ClassicalRotationsTest.qs b/src/Simulation/Simulators.Tests/Circuits/ClassicalRotationsTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/ClassicalRotationsTest.qs rename to src/Simulation/Simulators.Tests/Circuits/ClassicalRotationsTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/ClosedType.qs b/src/Simulation/Simulators.Tests/Circuits/ClosedType.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/ClosedType.qs rename to src/Simulation/Simulators.Tests/Circuits/ClosedType.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/ConditionalExpression.qs b/src/Simulation/Simulators.Tests/Circuits/ConditionalExpression.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/ConditionalExpression.qs rename to src/Simulation/Simulators.Tests/Circuits/ConditionalExpression.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Convert.qs b/src/Simulation/Simulators.Tests/Circuits/Convert.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Convert.qs rename to src/Simulation/Simulators.Tests/Circuits/Convert.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/CoreOperations.qs b/src/Simulation/Simulators.Tests/Circuits/CoreOperations.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/CoreOperations.qs rename to src/Simulation/Simulators.Tests/Circuits/CoreOperations.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/ExpTest.qs b/src/Simulation/Simulators.Tests/Circuits/ExpTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/ExpTest.qs rename to src/Simulation/Simulators.Tests/Circuits/ExpTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Fail.qs b/src/Simulation/Simulators.Tests/Circuits/Fail.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Fail.qs rename to src/Simulation/Simulators.Tests/Circuits/Fail.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Functions.qs b/src/Simulation/Simulators.Tests/Circuits/Functions.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Functions.qs rename to src/Simulation/Simulators.Tests/Circuits/Functions.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Generics.qs b/src/Simulation/Simulators.Tests/Circuits/Generics.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Generics.qs rename to src/Simulation/Simulators.Tests/Circuits/Generics.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/GetAvailableTest.qs b/src/Simulation/Simulators.Tests/Circuits/GetAvailableTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/GetAvailableTest.qs rename to src/Simulation/Simulators.Tests/Circuits/GetAvailableTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Issue132.qs b/src/Simulation/Simulators.Tests/Circuits/Issue132.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Issue132.qs rename to src/Simulation/Simulators.Tests/Circuits/Issue132.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Issue76.qs b/src/Simulation/Simulators.Tests/Circuits/Issue76.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Issue76.qs rename to src/Simulation/Simulators.Tests/Circuits/Issue76.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/JointMeasureTest.qs b/src/Simulation/Simulators.Tests/Circuits/JointMeasureTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/JointMeasureTest.qs rename to src/Simulation/Simulators.Tests/Circuits/JointMeasureTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Length.qs b/src/Simulation/Simulators.Tests/Circuits/Length.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Length.qs rename to src/Simulation/Simulators.Tests/Circuits/Length.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/NamedItems.qs b/src/Simulation/Simulators.Tests/Circuits/NamedItems.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/NamedItems.qs rename to src/Simulation/Simulators.Tests/Circuits/NamedItems.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Namespaces.qs b/src/Simulation/Simulators.Tests/Circuits/Namespaces.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Namespaces.qs rename to src/Simulation/Simulators.Tests/Circuits/Namespaces.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.cs b/src/Simulation/Simulators.Tests/Circuits/NativeOperations.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.cs rename to src/Simulation/Simulators.Tests/Circuits/NativeOperations.cs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.qs b/src/Simulation/Simulators.Tests/Circuits/NativeOperations.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/NativeOperations.qs rename to src/Simulation/Simulators.Tests/Circuits/NativeOperations.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/PrimitiveEquivalences.qs b/src/Simulation/Simulators.Tests/Circuits/PrimitiveEquivalences.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/PrimitiveEquivalences.qs rename to src/Simulation/Simulators.Tests/Circuits/PrimitiveEquivalences.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Recursion.qs b/src/Simulation/Simulators.Tests/Circuits/Recursion.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Recursion.qs rename to src/Simulation/Simulators.Tests/Circuits/Recursion.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/RepeatUntilSuccess.qs b/src/Simulation/Simulators.Tests/Circuits/RepeatUntilSuccess.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/RepeatUntilSuccess.qs rename to src/Simulation/Simulators.Tests/Circuits/RepeatUntilSuccess.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/ResourcesEstimator.qs b/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/ResourcesEstimator.qs rename to src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/RuntimeMetadataTest.qs b/src/Simulation/Simulators.Tests/Circuits/RuntimeMetadataTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/RuntimeMetadataTest.qs rename to src/Simulation/Simulators.Tests/Circuits/RuntimeMetadataTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/SetQubit.qs b/src/Simulation/Simulators.Tests/Circuits/SetQubit.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/SetQubit.qs rename to src/Simulation/Simulators.Tests/Circuits/SetQubit.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/StartOperation.qs b/src/Simulation/Simulators.Tests/Circuits/StartOperation.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/StartOperation.qs rename to src/Simulation/Simulators.Tests/Circuits/StartOperation.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/SwapTest.qs b/src/Simulation/Simulators.Tests/Circuits/SwapTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/SwapTest.qs rename to src/Simulation/Simulators.Tests/Circuits/SwapTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/TeleportTest.qs b/src/Simulation/Simulators.Tests/Circuits/TeleportTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/TeleportTest.qs rename to src/Simulation/Simulators.Tests/Circuits/TeleportTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/Tuples.qs b/src/Simulation/Simulators.Tests/Circuits/Tuples.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/Tuples.qs rename to src/Simulation/Simulators.Tests/Circuits/Tuples.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/UnitTests.qs b/src/Simulation/Simulators.Tests/Circuits/UnitTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/UnitTests.qs rename to src/Simulation/Simulators.Tests/Circuits/UnitTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/UserDefinedTypes.qs b/src/Simulation/Simulators.Tests/Circuits/UserDefinedTypes.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/UserDefinedTypes.qs rename to src/Simulation/Simulators.Tests/Circuits/UserDefinedTypes.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/VerifyUnitary.qs b/src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/VerifyUnitary.qs rename to src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs diff --git a/src/Simulation/Simulators.Core.Tests/Circuits/bug3223.qs b/src/Simulation/Simulators.Tests/Circuits/bug3223.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Circuits/bug3223.qs rename to src/Simulation/Simulators.Tests/Circuits/bug3223.qs diff --git a/src/Simulation/Simulators.Core.Tests/CoreTests.cs b/src/Simulation/Simulators.Tests/CoreTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/CoreTests.cs rename to src/Simulation/Simulators.Tests/CoreTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/DebuggingToolsTests.cs b/src/Simulation/Simulators.Tests/DebuggingToolsTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/DebuggingToolsTests.cs rename to src/Simulation/Simulators.Tests/DebuggingToolsTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/DiagnosticsWrappers.qs b/src/Simulation/Simulators.Tests/DiagnosticsWrappers.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/DiagnosticsWrappers.qs rename to src/Simulation/Simulators.Tests/DiagnosticsWrappers.qs diff --git a/src/Simulation/Simulators.Core.Tests/GenericsTests.cs b/src/Simulation/Simulators.Tests/GenericsTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/GenericsTests.cs rename to src/Simulation/Simulators.Tests/GenericsTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/GetQubitsTests.cs b/src/Simulation/Simulators.Tests/GetQubitsTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/GetQubitsTests.cs rename to src/Simulation/Simulators.Tests/GetQubitsTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/NativeOperationsTests.cs b/src/Simulation/Simulators.Tests/NativeOperationsTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/NativeOperationsTests.cs rename to src/Simulation/Simulators.Tests/NativeOperationsTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/OperationsTestHelper.cs b/src/Simulation/Simulators.Tests/OperationsTestHelper.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/OperationsTestHelper.cs rename to src/Simulation/Simulators.Tests/OperationsTestHelper.cs diff --git a/src/Simulation/Simulators.Core.Tests/PartialMapperTests.cs b/src/Simulation/Simulators.Tests/PartialMapperTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/PartialMapperTests.cs rename to src/Simulation/Simulators.Tests/PartialMapperTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/PrimitivesExtensionsTests.cs b/src/Simulation/Simulators.Tests/PrimitivesExtensionsTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/PrimitivesExtensionsTests.cs rename to src/Simulation/Simulators.Tests/PrimitivesExtensionsTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/QArrayTests.cs b/src/Simulation/Simulators.Tests/QArrayTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QArrayTests.cs rename to src/Simulation/Simulators.Tests/QArrayTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests.cs b/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests.cs rename to src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs b/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs rename to src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/InterfaceImpl.qs diff --git a/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs b/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs rename to src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/OneQubitOperationsTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs b/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs rename to src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/ThreePlusQubitOperationsTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs b/src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs rename to src/Simulation/Simulators.Tests/QCTraceSimulatorPrimitivesTests/TwoQubitOperationsTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/QTupleTests.cs b/src/Simulation/Simulators.Tests/QTupleTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QTupleTests.cs rename to src/Simulation/Simulators.Tests/QTupleTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/BasicTests.cs b/src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/BasicTests.cs rename to src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/CircuitsTests.cs b/src/Simulation/Simulators.Tests/QuantumSimulatorTests/CircuitsTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/CircuitsTests.cs rename to src/Simulation/Simulators.Tests/QuantumSimulatorTests/CircuitsTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/QubitReleaseTest.cs b/src/Simulation/Simulators.Tests/QuantumSimulatorTests/QubitReleaseTest.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/QubitReleaseTest.cs rename to src/Simulation/Simulators.Tests/QuantumSimulatorTests/QubitReleaseTest.cs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs b/src/Simulation/Simulators.Tests/QuantumSimulatorTests/VerifyGates.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumSimulatorTests/VerifyGates.cs rename to src/Simulation/Simulators.Tests/QuantumSimulatorTests/VerifyGates.cs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite.cs b/src/Simulation/Simulators.Tests/QuantumTestSuite.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite.cs rename to src/Simulation/Simulators.Tests/QuantumTestSuite.cs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertEqualInPlace.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertEqualInPlace.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertEqualInPlace.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertEqualInPlace.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndCliffordOneQubitTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbAndMeasureOneQubitTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbMultiQubit.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbMultiQubit.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbMultiQubit.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbMultiQubit.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbOneQubit.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbOneQubit.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertProbOneQubit.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertProbOneQubit.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertQubitUnitary.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertQubitUnitary.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertQubitUnitary.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertQubitUnitary.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertState.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertState.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertState.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertState.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertUnitary.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/AssertUnitary.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/AssertUnitary.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/AssertUnitary.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Complex.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/Complex.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Complex.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/Complex.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Config.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/Config.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Config.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/Config.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationTester.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationTester.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationTester.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationTester.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/ControlledOperationsTestUtils.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/IterateThroughCartesianProduct.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/JointOneQubitTests.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/JointOneQubitTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/JointOneQubitTests.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/JointOneQubitTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/KnownIssues.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/KnownIssues.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/KnownIssues.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/KnownIssues.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/LinearAlgebra.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/LinearAlgebra.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/LinearAlgebra.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/LinearAlgebra.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ManyControlQubitsTest.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/ManyControlQubitsTest.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ManyControlQubitsTest.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/ManyControlQubitsTest.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Math.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/Math.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Math.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/Math.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Matrices.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/Matrices.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/Matrices.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/Matrices.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitTestList.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitTestList.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitTestList.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitTestList.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitUnitaries.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitUnitaries.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/OneQubitUnitaries.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/OneQubitUnitaries.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/PauliExpectation.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/PauliExpectation.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/PauliExpectation.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/PauliExpectation.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/SelfTests.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/SelfTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/SelfTests.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/SelfTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TestSuiteCalculations.nb b/src/Simulation/Simulators.Tests/QuantumTestSuite/TestSuiteCalculations.nb similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TestSuiteCalculations.nb rename to src/Simulation/Simulators.Tests/QuantumTestSuite/TestSuiteCalculations.nb diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/ThreeQubitUnitaries.qs diff --git a/src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TwoQubitUnitaries.qs b/src/Simulation/Simulators.Tests/QuantumTestSuite/TwoQubitUnitaries.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QuantumTestSuite/TwoQubitUnitaries.qs rename to src/Simulation/Simulators.Tests/QuantumTestSuite/TwoQubitUnitaries.qs diff --git a/src/Simulation/Simulators.Core.Tests/QubitManagerTests.cs b/src/Simulation/Simulators.Tests/QubitManagerTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/QubitManagerTests.cs rename to src/Simulation/Simulators.Tests/QubitManagerTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/RangeTests.cs b/src/Simulation/Simulators.Tests/RangeTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/RangeTests.cs rename to src/Simulation/Simulators.Tests/RangeTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/ResourcesEstimatorTests.cs b/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/ResourcesEstimatorTests.cs rename to src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/RuntimeMetadataTests.cs b/src/Simulation/Simulators.Tests/RuntimeMetadataTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/RuntimeMetadataTests.cs rename to src/Simulation/Simulators.Tests/RuntimeMetadataTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/SimulatorBaseTests.cs b/src/Simulation/Simulators.Tests/SimulatorBaseTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/SimulatorBaseTests.cs rename to src/Simulation/Simulators.Tests/SimulatorBaseTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/StackTraceTests.cs b/src/Simulation/Simulators.Tests/StackTraceTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/StackTraceTests.cs rename to src/Simulation/Simulators.Tests/StackTraceTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/StartOperationTests.cs b/src/Simulation/Simulators.Tests/StartOperationTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/StartOperationTests.cs rename to src/Simulation/Simulators.Tests/StartOperationTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs rename to src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/ClassicallyControlledSupportTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj rename to src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs rename to src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/MeasurementSupportTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj rename to src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/Random/Tests.qs b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/IntrinsicTests/Random/Tests.qs rename to src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/IonQExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/IonQExe.csproj rename to src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs rename to src/Simulation/Simulators.Tests/TestProjects/IonQExe/MeasurementSupportTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj rename to src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library.qs b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/Library with Spaces/Library.qs rename to src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library.qs b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library.qs rename to src/Simulation/Simulators.Tests/TestProjects/Library1/Library.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/Library1/Library1.csproj rename to src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library.qs b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library.qs rename to src/Simulation/Simulators.Tests/TestProjects/Library2/Library.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/Library2/Library2.csproj rename to src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs rename to src/Simulation/Simulators.Tests/TestProjects/QCIExe/ClassicallyControlledSupportTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs rename to src/Simulation/Simulators.Tests/TestProjects/QCIExe/MeasurementSupportTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/QCIExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/QCIExe/QCIExe.csproj rename to src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/Main.qs b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/Main.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/Main.qs rename to src/Simulation/Simulators.Tests/TestProjects/QsharpExe/Main.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/QsharpExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/QsharpExe.csproj rename to src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/Program.qs b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/Program.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/Program.qs rename to src/Simulation/Simulators.Tests/TestProjects/TargetedExe/Program.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/TargetedExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/TargetedExe.csproj rename to src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Facts.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Facts.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Facts.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/Facts.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Hello.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/Hello.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/Hello.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/Hello.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/HoneywellSimulation.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/HoneywellSimulation.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/HoneywellSimulation.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/HoneywellSimulation.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/IonQSimulation.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/IonQSimulation.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/IonQSimulation.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/IonQSimulation.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/QCISimulation.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/QCISimulation.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/QCISimulation.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/QCISimulation.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/SpaceTests.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/SpaceTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/SpaceTests.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/SpaceTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/TestNameTests.qs b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/TestNameTests.qs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/TestNameTests.qs rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/TestNameTests.qs diff --git a/src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TestProjects/UnitTests/UnitTests.csproj rename to src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj diff --git a/src/Simulation/Simulators.Core.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj similarity index 100% rename from src/Simulation/Simulators.Core.Tests/Tests.Microsoft.Quantum.Simulators.csproj rename to src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj diff --git a/src/Simulation/Simulators.Core.Tests/ToffoliSimulatorTests.cs b/src/Simulation/Simulators.Tests/ToffoliSimulatorTests.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/ToffoliSimulatorTests.cs rename to src/Simulation/Simulators.Tests/ToffoliSimulatorTests.cs diff --git a/src/Simulation/Simulators.Core.Tests/TrivialSimulator.cs b/src/Simulation/Simulators.Tests/TrivialSimulator.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TrivialSimulator.cs rename to src/Simulation/Simulators.Tests/TrivialSimulator.cs diff --git a/src/Simulation/Simulators.Core.Tests/TypeExtensionsTest.cs b/src/Simulation/Simulators.Tests/TypeExtensionsTest.cs similarity index 100% rename from src/Simulation/Simulators.Core.Tests/TypeExtensionsTest.cs rename to src/Simulation/Simulators.Tests/TypeExtensionsTest.cs From 70032dfb056242bae55e14b33c40dbff9d31de12 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 25 Aug 2020 11:35:43 -0700 Subject: [PATCH 16/17] Adding Type2 to packaging scripts --- bootstrap.ps1 | 4 ++++ build/manifest.ps1 | 3 ++- build/pack.ps1 | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bootstrap.ps1 b/bootstrap.ps1 index 412e07618a8..251698dff4f 100644 --- a/bootstrap.ps1 +++ b/bootstrap.ps1 @@ -11,6 +11,10 @@ Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators.Core") .\FindNuspecReferences.ps1 Pop-Location +Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators.Type2") + .\FindNuspecReferences.ps1 +Pop-Location + # bootstrap native folder if ($Env:ENABLE_NATIVE -ne "false") { ## Run the right script based on the OS. diff --git a/build/manifest.ps1 b/build/manifest.ps1 index c45029d5026..09f7e3902c6 100644 --- a/build/manifest.ps1 +++ b/build/manifest.ps1 @@ -25,7 +25,8 @@ ".\src\Simulation\QsharpFoundation\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QSharp.Foundation.dll", ".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.Common.dll", ".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll", - ".\src\Simulation\Simulators\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.dll", + ".\src\Simulation\Simulators.Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.dll", + ".\src\Simulation\Simulators.Type2\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.Type2.dll", ".\src\Xunit\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Xunit.dll" ) | ForEach-Object { Get-Item (Join-Path $PSScriptRoot (Join-Path ".." $_)) }; } | Write-Output; diff --git a/build/pack.ps1 b/build/pack.ps1 index d2418f08729..7b97e404ffe 100644 --- a/build/pack.ps1 +++ b/build/pack.ps1 @@ -67,6 +67,7 @@ Pack-Dotnet '../src/Simulation/Core/Microsoft.Quantum.Runtime.Core.csproj' Pack-Dotnet '../src/Simulation/QSharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj' Pack-Dotnet '../src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj' Pack-One '../src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec' +Pack-One '../src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec' Pack-One '../src/Quantum.Development.Kit/Microsoft.Quantum.Development.Kit.nuspec' Pack-One '../src/Xunit/Microsoft.Quantum.Xunit.csproj' From 4af9ab0fab9132e4a8eeafdc3a8c724cd530ba19 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 28 Aug 2020 14:24:14 -0700 Subject: [PATCH 17/17] Clean up tests to minimize duplication --- .gitignore | 6 +- Simulation.sln | 106 +--- .../Circuits/VerifyUnitary.qs | 24 +- .../Simulators.Tests/OperationsTestHelper.cs | 86 +--- .../OperationsTestHelperSimSupport.cs | 41 ++ .../QuantumSimulatorTests/BasicTests.cs | 3 +- .../Simulators.Tests/SimulatorBaseTests.cs | 12 - .../Simulators.Tests/TracerHelper.cs | 51 ++ .../Circuits/AssertEqual.cs | 24 - .../Circuits/AssertEqual.qs | 12 - .../Circuits/JointMeasureTest.qs | 43 -- .../Circuits/VerifyUnitary.qs | 107 ---- .../OperationsTestHelper.cs | 345 ------------- .../OperationsTestHelperSimSupport.cs | 34 ++ .../QuantumSimulatorTests/BasicTests.cs | 387 --------------- .../QuantumSimulatorTests/VerifyGates.cs | 468 ------------------ .../IntrinsicTests/IntrinsicTests.csproj | 30 -- .../IntrinsicTests/Random/Tests.qs | 248 ---------- .../TestProjects/Library1/Library.qs | 43 -- .../TestProjects/Library1/Library1.csproj | 21 - .../TestProjects/Library2/Library.qs | 31 -- .../TestProjects/Library2/Library2.csproj | 21 - .../TestProjects/UnitTests/Facts.qs | 37 -- .../TestProjects/UnitTests/Hello.qs | 16 - .../TestProjects/UnitTests/TestNameTests.qs | 48 -- .../TestProjects/UnitTests/UnitTests.csproj | 32 -- ....Microsoft.Quantum.Simulators.Type2.csproj | 19 +- 27 files changed, 180 insertions(+), 2115 deletions(-) create mode 100644 src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs create mode 100644 src/Simulation/Simulators.Tests/TracerHelper.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs create mode 100644 src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs delete mode 100644 src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj diff --git a/.gitignore b/.gitignore index e38131def08..354f05b9d0d 100644 --- a/.gitignore +++ b/.gitignore @@ -335,7 +335,5 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ -/src/Simulation/Simulators.Core.Tests/TestProjects/QsharpExe/built -/src/Simulation/Simulators.Core.Tests/TestProjects/TargetedExe/built -/src/Simulation/Simulators.Type2.Tests/TestProjects/QsharpExe/built -/src/Simulation/Simulators.Type2.Tests/TestProjects/TargetedExe/built +/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/built +/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/built diff --git a/Simulation.sln b/Simulation.sln index 5ba0896306c..8b4957e793d 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.Simulator EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime", "src\Simulation\QCTraceSimulator.Tests\Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj", "{DD50D2D9-2765-449B-8C4B-835A428E160D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Microsoft.Quantum.Simulators", "src\Simulation\Simulators.Core.Tests\Tests.Microsoft.Quantum.Simulators.csproj", "{23461B29-F9DE-4F5B-BC30-50BBE1A10B48}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Microsoft.Quantum.Simulators", "src\Simulation\Simulators.Tests\Tests.Microsoft.Quantum.Simulators.csproj", "{23461B29-F9DE-4F5B-BC30-50BBE1A10B48}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "simulation", "simulation", "{34D419E9-CCF1-4E48-9FA4-3AD4B86BEEB4}" EndProject @@ -37,19 +37,19 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Microsoft.Quantum.CsharpGen EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{09C842CB-930C-4C7D-AD5F-E30DE4A55820}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QsharpExe", "src\Simulation\Simulators.Core.Tests\TestProjects\QsharpExe\QsharpExe.csproj", "{2F5796A7-4AF8-4B78-928A-0A3A80752F9D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QsharpExe", "src\Simulation\Simulators.Tests\TestProjects\QsharpExe\QsharpExe.csproj", "{2F5796A7-4AF8-4B78-928A-0A3A80752F9D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Quantum.EntryPointDriver", "src\Simulation\EntryPointDriver\Microsoft.Quantum.EntryPointDriver.csproj", "{944FE7EF-9220-4CC6-BB20-CE517195B922}" EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Tests.Microsoft.Quantum.EntryPointDriver", "src\Simulation\EntryPointDriver.Tests\Tests.Microsoft.Quantum.EntryPointDriver.fsproj", "{E2F30496-19D8-46A8-9BC0-26936FFE70D2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library1", "src\Simulation\Simulators.Core.Tests\TestProjects\Library1\Library1.csproj", "{7256B986-6705-42FC-9F57-485D72D9DE51}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library1", "src\Simulation\Simulators.Tests\TestProjects\Library1\Library1.csproj", "{7256B986-6705-42FC-9F57-485D72D9DE51}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library2", "src\Simulation\Simulators.Core.Tests\TestProjects\Library2\Library2.csproj", "{A85277B3-4E07-4E15-8F0C-07CC855A3BCB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library2", "src\Simulation\Simulators.Tests\TestProjects\Library2\Library2.csproj", "{A85277B3-4E07-4E15-8F0C-07CC855A3BCB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library with Spaces", "src\Simulation\Simulators.Core.Tests\TestProjects\Library with Spaces\Library with Spaces.csproj", "{418E79F7-9FCF-4128-AA35-1334A685377D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library with Spaces", "src\Simulation\Simulators.Tests\TestProjects\Library with Spaces\Library with Spaces.csproj", "{418E79F7-9FCF-4128-AA35-1334A685377D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "src\Simulation\Simulators.Core.Tests\TestProjects\UnitTests\UnitTests.csproj", "{46278108-D247-4EFC-AC34-23D4A676F62F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "src\Simulation\Simulators.Tests\TestProjects\UnitTests\UnitTests.csproj", "{46278108-D247-4EFC-AC34-23D4A676F62F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure", "Azure", "{37CDC768-16D4-4574-8553-07D99D0A72F7}" EndProject @@ -57,13 +57,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Quantum.Cli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Quantum.Client.Test", "src\Azure\Azure.Quantum.Client.Test\Microsoft.Azure.Quantum.Client.Test.csproj", "{4858E5E3-23FA-4928-B99A-54065875A2B9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoneywellExe", "src\Simulation\Simulators.Core.Tests\TestProjects\HoneywellExe\HoneywellExe.csproj", "{1448512E-132F-4DA8-BCBA-D98F16B31600}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoneywellExe", "src\Simulation\Simulators.Tests\TestProjects\HoneywellExe\HoneywellExe.csproj", "{1448512E-132F-4DA8-BCBA-D98F16B31600}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IonQExe", "src\Simulation\Simulators.Core.Tests\TestProjects\IonQExe\IonQExe.csproj", "{55833C6C-6E91-4413-9F77-96B3A09666B8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IonQExe", "src\Simulation\Simulators.Tests\TestProjects\IonQExe\IonQExe.csproj", "{55833C6C-6E91-4413-9F77-96B3A09666B8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QCIExe", "src\Simulation\Simulators.Core.Tests\TestProjects\QCIExe\QCIExe.csproj", "{C015FF41-9A51-4AF0-AEFC-2547D596B10A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QCIExe", "src\Simulation\Simulators.Tests\TestProjects\QCIExe\QCIExe.csproj", "{C015FF41-9A51-4AF0-AEFC-2547D596B10A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TargetedExe", "src\Simulation\Simulators.Core.Tests\TestProjects\TargetedExe\TargetedExe.csproj", "{D292BF18-3956-4827-820E-254C3F81EF09}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TargetedExe", "src\Simulation\Simulators.Tests\TestProjects\TargetedExe\TargetedExe.csproj", "{D292BF18-3956-4827-820E-254C3F81EF09}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BC562DAE-FE2B-4A8C-880C-C546F83F99E4}" EndProject @@ -77,23 +77,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Simulator EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Microsoft.Quantum.Simulators.Type2", "src\Simulation\Simulators.Type2.Tests\Tests.Microsoft.Quantum.Simulators.Type2.csproj", "{ED3D7040-4B3F-4217-A75E-9DF63DD84707}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulators.Type2.Tests", "Simulators.Type2.Tests", "{3DC13EC6-3C67-49D4-B2E2-6F9DD839F50C}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library1", "src\Simulation\Simulators.Type2.Tests\TestProjects\Library1\Library1.csproj", "{9BC3A273-9C36-4204-B06A-A92FBE05F63E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library2", "src\Simulation\Simulators.Type2.Tests\TestProjects\Library2\Library2.csproj", "{5D6148F0-37A6-42D6-B562-429666AFE3FE}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\Simulation\Simulators.Type2.Tests\TestProjects\UnitTests\UnitTests.csproj", "{3626EB54-E63A-48D1-BA67-3B249D0D3365}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulators.Core.Tests", "Simulators.Core.Tests", "{CF48986A-B487-407F-98A7-97AED29C6A43}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simulators.Tests", "Simulators.Tests", "{CF48986A-B487-407F-98A7-97AED29C6A43}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProjects", "{F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntrinsicTests", "src\Simulation\Simulators.Core.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntrinsicTests", "src\Simulation\Simulators.Type2.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntrinsicTests", "src\Simulation\Simulators.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -571,54 +559,6 @@ Global {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU {ED3D7040-4B3F-4217-A75E-9DF63DD84707}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|x64.ActiveCfg = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Debug|x64.Build.0 = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|Any CPU.Build.0 = Release|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|x64.ActiveCfg = Release|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.Release|x64.Build.0 = Release|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU - {9BC3A273-9C36-4204-B06A-A92FBE05F63E}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|x64.ActiveCfg = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Debug|x64.Build.0 = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|Any CPU.Build.0 = Release|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|x64.ActiveCfg = Release|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.Release|x64.Build.0 = Release|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU - {5D6148F0-37A6-42D6-B562-429666AFE3FE}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|x64.ActiveCfg = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Debug|x64.Build.0 = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|Any CPU.Build.0 = Release|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|x64.ActiveCfg = Release|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.Release|x64.Build.0 = Release|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU - {3626EB54-E63A-48D1-BA67-3B249D0D3365}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|Any CPU.Build.0 = Debug|Any CPU {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -635,22 +575,6 @@ Global {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU {4EF958CA-B4A6-4E5F-924A-100B5615BEC3}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|x64.ActiveCfg = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Debug|x64.Build.0 = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|Any CPU.Build.0 = Release|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|x64.ActiveCfg = Release|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.Release|x64.Build.0 = Release|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -687,15 +611,9 @@ Global {AF6CD304-8E03-433D-AAA2-6E0094B53071} = {9008B252-2DF7-404B-B626-D4497BB70A05} {E7163371-74D5-4DAD-AB04-8DA3FA1AD46F} = {9008B252-2DF7-404B-B626-D4497BB70A05} {ED3D7040-4B3F-4217-A75E-9DF63DD84707} = {9008B252-2DF7-404B-B626-D4497BB70A05} - {3DC13EC6-3C67-49D4-B2E2-6F9DD839F50C} = {9008B252-2DF7-404B-B626-D4497BB70A05} - {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} = {3DC13EC6-3C67-49D4-B2E2-6F9DD839F50C} - {9BC3A273-9C36-4204-B06A-A92FBE05F63E} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} - {5D6148F0-37A6-42D6-B562-429666AFE3FE} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} - {3626EB54-E63A-48D1-BA67-3B249D0D3365} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} {CF48986A-B487-407F-98A7-97AED29C6A43} = {9008B252-2DF7-404B-B626-D4497BB70A05} {F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3} = {CF48986A-B487-407F-98A7-97AED29C6A43} {4EF958CA-B4A6-4E5F-924A-100B5615BEC3} = {F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3} - {B2725EF4-E0E1-45DF-BB49-EDD94305CF5D} = {AFFCCF8F-F90F-4AF7-AEFA-5DB63BFB7C77} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821} diff --git a/src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs b/src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs index e44783a32d6..afde45b0c3b 100644 --- a/src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs +++ b/src/Simulation/Simulators.Tests/Circuits/VerifyUnitary.qs @@ -6,7 +6,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Math; open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Simulation.TestSuite; + open Microsoft.Quantum.Measurement; /// @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { /// then it tests Controlled with different number of control qubits, also verifying that /// Adjoint Controlled works. /// - operation VerifyUnitary (gate : (Qubit => Unit : Adjoint, Controlled), start : (Pauli, Result), expected : (Complex, Complex)) : Unit { + operation VerifyUnitary (gate : (Qubit => Unit is Adj + Ctl), start : (Pauli, Result), expected : (Complex, Complex)) : Unit { using (qubits = Qubit[1]) { @@ -28,14 +28,14 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { let q1 = qubits[0]; let (a, b) = expected; let (p, r) = start; - SetQubit(r, q1); + SetToBasisState(r, q1); if (p == PauliX) { H(q1); } // Make sure we start in correct state. - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // Apply the gate, make sure it's in the right state gate(q1); @@ -43,7 +43,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { // Apply Adjoint, back to Zero: Adjoint gate(q1); - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // When no control qubits, it should be equivalent to just calling the gate: Controlled gate(new Qubit[0], q1); @@ -51,7 +51,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { // Apply Adjoint, back to Zero: Controlled (Adjoint gate)(new Qubit[0], q1); - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // Now test control... We'll have 3 control qubits. // We will run the test with 1..3 controls at a time. @@ -62,18 +62,18 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { for (i in 0 .. ctrlsCount - 1) { // We're starting fresh - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // Get a subset for control and initialize them to zero: let c = ctrls[0 .. i]; for (j in 0 .. i) { - SetQubit(Zero, c[j]); + SetToBasisState(Zero, c[j]); } // Noop when ctrls are all zero. Controlled gate(c, q1); - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); // turn on each of the controls one by one for (j in 1 .. Length(c)) { @@ -85,7 +85,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); } else { - Assert([p], [q1], r, $"Qubit in invalid state."); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); } Adjoint Controlled gate(c, q1); @@ -96,8 +96,8 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { } // We're back where we started. - Assert([p], [q1], r, $"Qubit in invalid state."); - SetQubit(r, q1); + AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); + SetToBasisState(r, q1); ResetAll(qubits); } } diff --git a/src/Simulation/Simulators.Tests/OperationsTestHelper.cs b/src/Simulation/Simulators.Tests/OperationsTestHelper.cs index 7fa82ca1077..9f3febb14bb 100644 --- a/src/Simulation/Simulators.Tests/OperationsTestHelper.cs +++ b/src/Simulation/Simulators.Tests/OperationsTestHelper.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using Microsoft.Quantum.Simulation.Common; using Microsoft.Quantum.Simulation.Core; @@ -14,6 +13,18 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests { + public static class Extensions + { + /// + /// This method is a wrapper to let the tests keep using a one Type parameter + /// method to fetch for Gates. + /// + public static T Get(this SimulatorBase sim) where T : AbstractCallable + { + return sim.Get(); + } + } + public class Log { public Dictionary _log = new Dictionary(); @@ -88,75 +99,8 @@ private void OnStart(ICallable arg1, IApplyData arg2) } } - static class OperationsTestHelper + static partial class OperationsTestHelper { - public static TraceImpl GetTracer(this SimulatorBase s) - { - return s.Get(typeof(Tests.Circuits.Generics.Trace<>)).FindCallable(typeof(T), typeof(QVoid)) as TraceImpl; - } - - - public class TracerImpl : Tests.Circuits.ClosedType.Trace - { - public TracerImpl(IOperationFactory m) : base(m) - { - this.Log = new Log(); - } - - public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); - public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); - public override Func<(IQArray, string), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); - public override Func<(IQArray, string), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); - - public Log Log { get; } - } - - public class TraceImpl : Tests.Circuits.Generics.Trace - { - public TraceImpl(IOperationFactory m) : base(m) - { - this.Log = new Log(); - } - - public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); - public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); - public override Func<(IQArray, T), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); - public override Func<(IQArray, T), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); - - public int GetNumberOfCalls(OperationFunctor functor, T tag) => this.Log.GetNumberOfCalls(functor, tag); - - public Log Log { get; } - } - - private static void InitSimulator(SimulatorBase sim) - { - sim.InitBuiltinOperations(typeof(OperationsTestHelper)); - sim.Register(typeof(Tests.Circuits.Generics.Trace<>), typeof(TraceImpl<>), typeof(IUnitary)); - - // For Toffoli, replace H with I. - if (sim is ToffoliSimulator) - { - sim.Register(typeof(Intrinsic.H), typeof(Intrinsic.I), typeof(IUnitary)); - } - } - - public static void RunWithMultipleSimulators(Action test) - { - var simulators = new SimulatorBase[] { new QuantumSimulator(), new ToffoliSimulator() }; - - foreach (var s in simulators) - { - InitSimulator(s); - - test(s); - - if (s is IDisposable sim) - { - sim.Dispose(); - } - } - } - /// /// A shell for simple Apply tests. /// @@ -189,13 +133,13 @@ internal static void ctrlErrorConditionsTests(SimulatorBase sim, Action<(IQArray /// /// A shell for simple Controlled tests. It calls the controlled operation with 0..4 control qubits - /// set to all possible combination of 1 & 0. + /// set to all possible combination of 1 and 0. /// internal static void ctrlTestShell(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled, Action, Qubit> test) { var allocate = sim.Get(); var release = sim.Get(); - var set = sim.Get(); + var set = sim.Get(); // Number of control bits to use for (int n = 0; n < 4; n++) diff --git a/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs new file mode 100644 index 00000000000..477571f7024 --- /dev/null +++ b/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Microsoft.Quantum.Simulation.Common; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + static partial class OperationsTestHelper + { + private static void InitSimulator(SimulatorBase sim) + { + sim.InitBuiltinOperations(typeof(OperationsTestHelper)); + sim.Register(typeof(Tests.Circuits.Generics.Trace<>), typeof(TraceImpl<>), typeof(IUnitary)); + + // For Toffoli, replace H with I. + if (sim is ToffoliSimulator) + { + sim.Register(typeof(Intrinsic.H), typeof(Intrinsic.I), typeof(IUnitary)); + } + } + + public static void RunWithMultipleSimulators(Action test) + { + var simulators = new SimulatorBase[] { new QuantumSimulator(), new ToffoliSimulator() }; + + foreach (var s in simulators) + { + InitSimulator(s); + + test(s); + + if (s is IDisposable sim) + { + sim.Dispose(); + } + } + } + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs b/src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs index 092106269f0..64bb4ec919c 100644 --- a/src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs +++ b/src/Simulation/Simulators.Tests/QuantumSimulatorTests/BasicTests.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators.Exceptions; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; using Xunit; namespace Microsoft.Quantum.Simulation.Simulators.Tests @@ -60,7 +59,7 @@ public void QSimX() { var x = sim.Get(); var measure = sim.Get(); - var set = sim.Get(); + var set = sim.Get(); var ctrlX = x.ControlledBody.AsAction(); OperationsTestHelper.ctrlTestShell(sim, ctrlX, (enabled, ctrls, q) => diff --git a/src/Simulation/Simulators.Tests/SimulatorBaseTests.cs b/src/Simulation/Simulators.Tests/SimulatorBaseTests.cs index f9b73e477e9..48ee362dc99 100644 --- a/src/Simulation/Simulators.Tests/SimulatorBaseTests.cs +++ b/src/Simulation/Simulators.Tests/SimulatorBaseTests.cs @@ -10,18 +10,6 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests { - public static class Extensions - { - /// - /// This method is a wrapper to let the tests keep using a one Type parameter - /// method to fetch for Gates. - /// - public static T Get(this SimulatorBase sim) where T : AbstractCallable - { - return sim.Get(); - } - } - public class SimulatorBaseTests { private readonly ITestOutputHelper output; diff --git a/src/Simulation/Simulators.Tests/TracerHelper.cs b/src/Simulation/Simulators.Tests/TracerHelper.cs new file mode 100644 index 00000000000..73437a32ec5 --- /dev/null +++ b/src/Simulation/Simulators.Tests/TracerHelper.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Microsoft.Quantum.Simulation.Common; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + static partial class OperationsTestHelper + { + public static TraceImpl GetTracer(this SimulatorBase s) + { + return s.Get(typeof(Tests.Circuits.Generics.Trace<>)).FindCallable(typeof(T), typeof(QVoid)) as TraceImpl; + } + + + public class TracerImpl : Tests.Circuits.ClosedType.Trace + { + public TracerImpl(IOperationFactory m) : base(m) + { + this.Log = new Log(); + } + + public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); + public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); + public override Func<(IQArray, string), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); + public override Func<(IQArray, string), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); + + public Log Log { get; } + } + + public class TraceImpl : Tests.Circuits.Generics.Trace + { + public TraceImpl(IOperationFactory m) : base(m) + { + this.Log = new Log(); + } + + public override Func Body => (tag) => this.Log.Record(OperationFunctor.Body, tag); + public override Func AdjointBody => (tag) => this.Log.Record(OperationFunctor.Adjoint, tag); + public override Func<(IQArray, T), QVoid> ControlledBody => (args) => this.Log.Record(OperationFunctor.Controlled, args.Item2); + public override Func<(IQArray, T), QVoid> ControlledAdjointBody => (args) => this.Log.Record(OperationFunctor.ControlledAdjoint, args.Item2); + + public int GetNumberOfCalls(OperationFunctor functor, T tag) => this.Log.GetNumberOfCalls(functor, tag); + + public Log Log { get; } + } + + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs b/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs deleted file mode 100644 index 960c140c19f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Microsoft.Quantum.Simulation.Core; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits -{ - public partial class AssertEqual<__T__> - { - public class Native : AssertEqual<__T__> - { - public Native(IOperationFactory m) : base(m) { } - - public override Func<(__T__, __T__), QVoid> Body => (_args) => - { - var (expected, actual) = _args; - Assert.Equal(expected, actual); - return QVoid.Instance; - }; - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs deleted file mode 100644 index 1555e88958f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/AssertEqual.qs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - function AssertEqual<'T> (expected : 'T, actual : 'T) : Unit { - body intrinsic; - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs deleted file mode 100644 index d802d3a68da..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/JointMeasureTest.qs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Intrinsic; - - - operation JointMeasureTest () : Unit { - - - using (qubits = Qubit[3]) { - let q1 = qubits[0]; - let q2 = qubits[1]; - let q3 = qubits[2]; - let basis = [PauliZ, PauliZ, PauliZ]; - let r1 = Measure(basis, qubits); - AssertEqual(Zero, r1); - X(q1); - let r2 = Measure(basis, qubits); - AssertEqual(One, r2); - AssertEqual(One, Measure([PauliZ], [q1])); - AssertEqual(Zero, Measure([PauliZ], [q2])); - AssertEqual(Zero, Measure([PauliZ], [q3])); - X(q3); - let r3 = Measure(basis, qubits); - AssertEqual(Zero, r3); - AssertEqual(One, Measure([PauliZ], [q1])); - AssertEqual(Zero, Measure([PauliZ], [q2])); - AssertEqual(One, Measure([PauliZ], [q3])); - X(q2); - let r4 = Measure(basis, qubits); - AssertEqual(One, r4); - AssertEqual(One, Measure([PauliZ], [q1])); - AssertEqual(One, Measure([PauliZ], [q2])); - AssertEqual(One, Measure([PauliZ], [q3])); - ResetAll(qubits); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs b/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs deleted file mode 100644 index d4748e596f3..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/Circuits/VerifyUnitary.qs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Math; - open Microsoft.Quantum.Measurement; - open Microsoft.Quantum.Diagnostics; - - - /// - /// Verifies that all operations of the one-qubit Unitary work. - /// It receives as parameter the Unitary (notice that any gate can be converted to Unitary - /// using Partial Application), a start state that the qubit should be initialized with, - /// and the qubit state that the Qubit should be at - /// once the Unitary has been applied. - /// The verification applies the gate and asserts the qubit state. Then it applies - /// the Adjoint and verifies the qubit is back to Zero. - /// then it tests Controlled with different number of control qubits, also verifying that - /// Adjoint Controlled works. - /// - operation VerifyUnitary (gate : (Qubit => Unit is Adj + Ctl), start : (Pauli, Result), expected : (Complex, Complex)) : Unit { - - - using (qubits = Qubit[1]) { - let tolerance = 1E-05; - let q1 = qubits[0]; - let (a, b) = expected; - let (p, r) = start; - SetToBasisState(r, q1); - - if (p == PauliX) { - H(q1); - } - - // Make sure we start in correct state. - AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); - - // Apply the gate, make sure it's in the right state - gate(q1); - AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); - - // Apply Adjoint, back to Zero: - Adjoint gate(q1); - AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); - - // When no control qubits, it should be equivalent to just calling the gate: - Controlled gate(new Qubit[0], q1); - AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); - - // Apply Adjoint, back to Zero: - Controlled (Adjoint gate)(new Qubit[0], q1); - AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); - - // Now test control... We'll have 3 control qubits. - // We will run the test with 1..3 controls at a time. - let ctrlsCount = 3; - - using (ctrls = Qubit[ctrlsCount]) { - - for (i in 0 .. ctrlsCount - 1) { - - // We're starting fresh - AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); - - // Get a subset for control and initialize them to zero: - let c = ctrls[0 .. i]; - - for (j in 0 .. i) { - SetToBasisState(Zero, c[j]); - } - - // Noop when ctrls are all zero. - Controlled gate(c, q1); - AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); - - // turn on each of the controls one by one - for (j in 1 .. Length(c)) { - X(c[j - 1]); - Controlled gate(c, q1); - - // Only when all - if (j == Length(c)) { - AssertQubitIsInStateWithinTolerance(expected, q1, tolerance); - } - else { - AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); - } - - Adjoint Controlled gate(c, q1); - } - } - - ResetAll(ctrls); - } - - // We're back where we started. - AssertMeasurement([p], [q1], r, $"Qubit in invalid state."); - SetToBasisState(r, q1); - ResetAll(qubits); - } - } - -} - - diff --git a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs deleted file mode 100644 index 4797910628b..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelper.cs +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Simulators.Exceptions; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; - -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public static class Extensions - { - /// - /// This method is a wrapper to let the tests keep using a one Type parameter - /// method to fetch for Gates. - /// - public static T Get(this SimulatorBase sim) where T : AbstractCallable - { - return sim.Get(); - } - } - - public class Log - { - public Dictionary _log = new Dictionary(); - - public string Key(OperationFunctor functor, T tag) => $"{functor}:{tag}"; - - public int GetNumberOfCalls(OperationFunctor functor, T tag) - { - var key = Key(functor, tag); - - if (_log.ContainsKey(key)) - { - return _log[key]; - } - else - { - return 0; - } - } - - public QVoid Record(OperationFunctor functor, T tag) - { - var key = Key(functor, tag); - - if (_log.ContainsKey(key)) - { - _log[key] = _log[key] + 1; - } - else - { - _log[key] = 1; - } - - return QVoid.Instance; - } - } - - public class StartTracker - { - private List _log = new List(); - - private class Key - { - public ICallable callable; - public IApplyData data; - public Type dataType; - } - - public StartTracker(SimulatorBase s) - { - s.OnOperationStart += this.OnStart; - } - - public bool EqualData(object expected, object actual) - { - if (expected == null) return actual == null; - - var value = PartialMapper.CastTuple(expected.GetType(), actual); - return expected.Equals(value); - } - - - public int GetNumberOfCalls(string name) => _log.Where(r => r.callable.FullName == name).Count(); - - public int GetNumberOfCalls(string name, OperationFunctor variant) => _log.Where(r => r.callable.FullName == name && r.callable.Variant == variant).Count(); - - public int GetNumberOfCalls(string name, OperationFunctor variant, object data) => _log.Where(r =>r.callable.FullName == name && r.callable.Variant == variant && EqualData(data, r.data.Value)).Count(); - - private void OnStart(ICallable arg1, IApplyData arg2) - { - _log.Add(new Key { callable = arg1, data = arg2, dataType = arg2?.GetType() }); - } - } - - static class OperationsTestHelper - { - private static void InitSimulator(SimulatorBase sim) - { - sim.InitBuiltinOperations(typeof(OperationsTestHelper)); - } - - public static void RunWithMultipleSimulators(Action test) - { - var simulators = new SimulatorBase[] { new QuantumSimulator() }; - - foreach (var s in simulators) - { - InitSimulator(s); - - test(s); - - if (s is IDisposable sim) - { - sim.Dispose(); - } - } - } - - /// - /// A shell for simple Apply tests. - /// - internal static void applyTestShell(SimulatorBase sim, ICallable operation, Action test) - { - var allocate = sim.Get(); - var release = sim.Get(); - - var qbits = allocate.Apply(1); - - var q = qbits[0]; - operation.Apply(q); // this is ok. - - test(q); - - operation.Apply(q); // still ok. - release.Apply(qbits); - } - - - /// - /// Verifies general conditions that may cause errors on the Controlled method. - /// - internal static void ctrlErrorConditionsTests(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled) - { - ctrlOnReleasedQubitTest(sim, operationControlled); - - ctrlOnReleasedCtrlQubitTest(sim, operationControlled); - } - - /// - /// A shell for simple Controlled tests. It calls the controlled operation with 0..4 control qubits - /// set to all possible combination of 1 and 0. - /// - internal static void ctrlTestShell(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled, Action, Qubit> test) - { - var allocate = sim.Get(); - var release = sim.Get(); - var set = sim.Get(); - - // Number of control bits to use - for (int n = 0; n < 4; n++) - { - IQArray qbits = allocate.Apply(1); - IQArray ctrls = allocate.Apply(n); - - Qubit q = qbits[0]; - operationControlled((ctrls, q)); // this is ok. - - // Iterate through all possible combinations of ctrl values: - for (int i = 0; i < (1 << n); i++) - { - // set control bits to match i: - for (int j = 0; j < n; j++) - { - var value = (i & (1 << j)) == 0 - ? Result.Zero - : Result.One; - - set.Apply((value, ctrls[j])); - } - - // controlled is enabled only when all ctrls are 1 (e.g. last one): - bool enabled = (i == ((1 << n) - 1)); - test(enabled, ctrls, q); - } - - operationControlled((ctrls, q)); // still ok. - release.Apply(qbits); - release.Apply(ctrls); - - sim.CheckNoQubitLeak(); - } - } - - /// - /// Verifies that calling Controlled on a released qubit throws an Exception - /// - internal static void ctrlOnReleasedQubitTest(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled) - { - ctrlTestShell(sim, operationControlled, (enabled, ctrls, q) => - { - Intrinsic.Allocate allocate = sim.Get(); - Intrinsic.Release release = sim.Get(); - - IQArray qbits = allocate.Apply(1); - Qubit qfake = qbits[0]; - release.Apply(qbits); - - Assert.Throws("q1", () => - { - operationControlled((ctrls, qfake)); - }); - - }); - } - - /// - /// Verifies that calling Controlled using released qubits as control throws an Exception - /// - internal static void ctrlOnReleasedCtrlQubitTest(SimulatorBase sim, Action<(IQArray, Qubit)> operationControlled) - { - var random = new System.Random(); - - ctrlTestShell(sim, operationControlled, (enabled, ctrlQs, q) => - { - if (ctrlQs == null || ctrlQs.Length == 0) - { - return; - } - var ctrls = new QArray(ctrlQs); - - // Pass in a random released qubit - int index = random.Next((int)ctrls.Length); - Qubit released = ctrls[index]; - - Intrinsic.Allocate allocate = sim.Get(); - Intrinsic.Release release = sim.Get(); - - IQArray qbits = allocate.Apply(1); - Qubit qfake = qbits[0]; - release.Apply(qbits); - ctrls.Modify(index, qfake); - - Assert.Throws($"ctrls[{index}]", () => - { - operationControlled((ctrls, q)); - }); - - // Put real qubit back in place of released: - ctrls.Modify(index, released); - }); - } - - internal static void CheckNoQubitLeak(this SimulatorBase sim) - { - Assert.True(sim.QubitManager.GetAllocatedQubitsCount() == 0); - } - - /// - /// Verifies that multiple situations where over-allocating might happen throw an Exception. - /// - internal static void overAllocationTest(uint n, Func> allocate, Action> release) - { - // Allocating more than available - try - { - allocate(n + 1); - } - catch (NotEnoughQubits e) - { - Assert.Equal((int)n, e.Available); - Assert.Equal(n + 1, e.Requested); - } - - // Allocating max, then trying to allocate one more: - var qubits = allocate(n); - Assert.Throws(() => - { - allocate(1); - }); - release(qubits); - - // Allocating and releasing should be fine, - // then allocate one max (ok), and finally allocating one more: - qubits = allocate(n); - release(qubits); - - var qubits2 = allocate(1); - release(qubits2); - - qubits = allocate(n); - Assert.Throws(() => - { - allocate(1); - }); - release(qubits); - - - // Allocating max, release one in the middle. - // then re-allocate to max (ok), and finally allocating one more: - qubits = allocate(n); - release(new QArray(qubits[1])); - - qubits = new QArray(qubits.Where(q => q.Id != 1)); // Remove released qubit from qubits: - qubits2 = allocate(1); - - Assert.Throws(() => - { - allocate(1); - }); - release(qubits); - release(qubits2); - } - - public static Action AsAction(this Func gate) - { - return (q) => - { - gate.Invoke(q); - }; - } - - public static void IgnoreDebugAssert(this Action action) - { - IgnorableAssert.Disable(); - try - { - action.Invoke(); - } - finally - { - IgnorableAssert.Enable(); - } - } - - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs new file mode 100644 index 00000000000..d6abcc6ed50 --- /dev/null +++ b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Microsoft.Quantum.Simulation.Common; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Simulation.Simulators.Tests +{ + static partial class OperationsTestHelper + { + private static void InitSimulator(SimulatorBase sim) + { + sim.InitBuiltinOperations(typeof(OperationsTestHelper)); + } + + public static void RunWithMultipleSimulators(Action test) + { + var simulators = new SimulatorBase[] { new QuantumSimulator() }; + + foreach (var s in simulators) + { + InitSimulator(s); + + test(s); + + if (s is IDisposable sim) + { + sim.Dispose(); + } + } + } + } +} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs deleted file mode 100644 index 64bb4ec919c..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/BasicTests.cs +++ /dev/null @@ -1,387 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Simulators.Exceptions; -using Xunit; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public partial class QuantumSimulatorTests - { - [Fact] - public void QSimConstructor() - { - using (var subject = new QuantumSimulator()) - { - Assert.Equal("Quantum Simulator", subject.Name); - } - } - - [Fact] - public void QSimVerifyPrimitivesCompleteness() - { - using (var sim = new QuantumSimulator()) - { - var ops = - from op in typeof(Intrinsic.X).Assembly.GetExportedTypes() - where op.IsSubclassOf(typeof(AbstractCallable)) - where !op.IsNested - select op; - - var missing = new List(); - - foreach (var op in ops) - { - try - { - var i = sim.GetInstance(op); - Assert.NotNull(i); - } - catch (Exception) - { - missing.Add(op); - } - } - - Assert.Empty(missing); - } - } - - [Fact] - public void QSimX() - { - using (var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) - { - var x = sim.Get(); - var measure = sim.Get(); - var set = sim.Get(); - - var ctrlX = x.ControlledBody.AsAction(); - OperationsTestHelper.ctrlTestShell(sim, ctrlX, (enabled, ctrls, q) => - { - set.Apply((Result.Zero, q)); - var result = measure.Apply(q); - var expected = Result.Zero; - Assert.Equal(expected, result); - - x.ControlledBody((ctrls, q)); - result = measure.Apply(q); - expected = (enabled) ? Result.One : Result.Zero; - Assert.Equal(expected, result); - }); - } - } - - [Fact] - public void QSimMultithreading() - { - var count = 5; - var tasks = new Task[count]; - - for (int i = 0; i < count; i++) - { - tasks[i] = Task.Run(() => - { - QSimVerifyX(); - QSimVerifyY(); - QSimVerifyZ(); - QSimVerifyExp(); - }); - } - - Task.WaitAll(tasks); - } - - - [Fact] - public void QSimRandom() - { - using (var sim = new QuantumSimulator()) - { - var r = sim.Get(); - var probs = new QArray (0.0, 0.0, 0.0, 0.7, 0.0, 0.0); - var result = r.Apply(probs); - Assert.Equal(3, result); - } - } - - [Fact] - public void QSimAssert() - { - using (var sim = new QuantumSimulator()) - { - var assert = sim.Get(); - var h = sim.Get(); - - Func, IQArray, Result, string)> mapper = - (q) => (new QArray(Pauli.PauliZ), new QArray (q), Result.Zero, "Assert failed"); - var applyWithZero = new OperationPartial, IQArray, Result, string), QVoid>(assert, mapper); - - OperationsTestHelper.applyTestShell(sim, applyWithZero, (q) => - { - h.Apply(q); - assert.Apply((new QArray(Pauli.PauliX), new QArray (q), Result.Zero, "Assert failed")); - - OperationsTestHelper.IgnoreDebugAssert(() => - { - Assert.Throws(() => assert.Apply((new QArray (Pauli.PauliX), new QArray (q), Result.One, "Assert failed"))); - - h.Apply(q); - Assert.Throws(() => assert.Apply((new QArray (Pauli.PauliZ), new QArray (q), Result.One, "Assert failed"))); - }); - - assert.Apply((new QArray (Pauli.PauliZ), new QArray(q), Result.Zero, "Assert failed")); - }); - } - } - - - [Fact] - public void QSimAssertProb() - { - using (var sim = new QuantumSimulator()) - { - var tolerance = 0.02; - var assertProb = sim.Get(); - var h = sim.Get(); - var allocate = sim.Get(); - var release = sim.Get(); - - Func, IQArray, Result, double, string, double)> mapper = (q) => - { - return (new QArray(Pauli.PauliZ), new QArray(q), Result.Zero, 1.0, "Assert failed", tolerance); - }; - var applyWithZero = new OperationPartial, IQArray, Result, double, string, double), QVoid>(assertProb, mapper); - - OperationsTestHelper.applyTestShell(sim, applyWithZero, (q1) => - { - assertProb.Apply((new QArray (Pauli.PauliZ), new QArray(q1), Result.One, 0.01, "Assert failed", tolerance)); - - // Within tolerance - assertProb.Apply((new QArray (Pauli.PauliX), new QArray (q1), Result.Zero, 0.51, "Assert failed", tolerance)); - assertProb.Apply((new QArray (Pauli.PauliX), new QArray (q1), Result.One, 0.51, "Assert failed", tolerance)); - // Outside of tolerance - OperationsTestHelper.IgnoreDebugAssert(() => - { - Assert.Throws(() => assertProb.Apply((new QArray(Pauli.PauliX), new QArray(q1), Result.One, 0.51, "Assert failed", 0.0))); - Assert.Throws(() => assertProb.Apply((new QArray(Pauli.PauliX), new QArray(q1), Result.Zero, 0.51, "Assert failed", 0.0))); - }); - - // Add a qubit - var qubits = allocate.Apply(1); - var q2 = qubits[0]; - - assertProb.Apply((new QArray (Pauli.PauliZ), new QArray (q1), Result.Zero, 0.99, "Assert failed", tolerance)); - assertProb.Apply((new QArray (Pauli.PauliZ), new QArray (q1), Result.One, 0.01, "Assert failed", tolerance)); - assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.Zero, 0.99, "Assert failed", tolerance)); - assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.One, 0.01, "Assert failed", tolerance)); - - assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliX), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", tolerance)); - assertProb.Apply((new QArray (Pauli.PauliX, Pauli.PauliZ), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", tolerance)); - assertProb.Apply((new QArray (Pauli.PauliX, Pauli.PauliX), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", tolerance)); - - OperationsTestHelper.IgnoreDebugAssert(() => - { - // Outside of tolerance - Assert.Throws(() => assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.Zero, 0.51, "Assert failed", 0.0))); - Assert.Throws(() => assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1, q2), Result.One, 0.51, "Assert failed", 0.0))); - - // Missmatch number of arrays - Assert.Throws(() => assertProb.Apply((new QArray (Pauli.PauliZ, Pauli.PauliZ), new QArray (q1), Result.Zero, 0.51, "Assert failed", tolerance))); - }); - - release.Apply(qubits); - }); - } - } - - private static void TestCallable(ICallable gate, Qubit target) - { - gate.Apply(target); - Assert.Throws(() => gate.Apply(null)); - } - - private static void TestControllable(IControllable gate, IQArray ctrls, Qubit target) - { - var nullTarget = new Func, Qubit)>(q => (ctrls, q)); - var nullCtrl = new Func, Qubit)>(q => (new QArray(q, ctrls[1], ctrls[2]), target)); - - var dupeTarget = new QArray(target, ctrls[1], ctrls[2]); - var dupeCtrls1 = new QArray(ctrls[1], ctrls[1], ctrls[2]); - var dupeCtrls2 = new QArray(ctrls[0], ctrls[1], ctrls[0]); - - TestCallable(gate, target); - TestCallable(gate.Controlled.Partial(nullTarget), target); - TestCallable(gate.Controlled.Partial(nullCtrl), ctrls[0]); - - Assert.Throws(() => gate.Controlled.Apply((dupeTarget, target))); - Assert.Throws(() => gate.Controlled.Apply((dupeCtrls1, target))); - Assert.Throws(() => gate.Controlled.Apply((dupeCtrls2, target))); - } - - private static void TestUnitary(IUnitary gate, IQArray ctrls, IQArray target) - { - TestCallable(gate, target[0]); - TestCallable(gate.Adjoint, target[0]); - TestControllable(gate, ctrls, target[0]); - TestControllable(gate.Adjoint, ctrls, target[0]); - } - - private static void TestMultiCallable(ICallable, O> gate, IQArray targets) - { - var mapper = new Func>(q => new QArray(q, targets[1], targets[2])); - var dupTargets = new QArray(targets[0], targets[1], targets[0]); - - Assert.Throws(() => gate.Apply(null)); - Assert.Throws(() => gate.Apply(dupTargets)); - TestCallable(gate.Partial(mapper), targets[0]); - } - - private static void TestMultiControllable(IControllable> gate, IQArray ctrls, IQArray targets) - { - var mapper = new Func>(q => new QArray(q, targets[1], targets[2])); - - TestControllable(gate.Partial(mapper), ctrls, targets[0]); - } - - private static void TestMultiUnitary(IUnitary> gate, IQArray ctrls, IQArray targets) - { - TestMultiCallable(gate, targets); - TestMultiCallable(gate.Adjoint, targets); - TestMultiControllable(gate, ctrls, targets); - TestMultiControllable(gate.Adjoint, ctrls, targets); - } - - private void TestOne(QuantumSimulator qsim, T gate, Action, IQArray> action) - { - var allocate = qsim.Get(); - var release = qsim.Get(); - - var targets = allocate.Apply(3); - var ctrls = allocate.Apply(3); - - try - { - action(gate, ctrls, targets); - } - finally - { - release.Apply(ctrls); - release.Apply(targets); - } - } - - [Fact] - public void TestSimpleGateCheckQubits() - { - using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) - { - - // Single Qubit gates: - { - var gateTypes = new Type[] - { - typeof(Intrinsic.H), - typeof(Intrinsic.S), - typeof(Intrinsic.T), - typeof(Intrinsic.X), - typeof(Intrinsic.Y), - typeof(Intrinsic.Z) - }; - - foreach (var t in gateTypes) - { - var gate = qsim.Get>(t); - TestOne(qsim, gate, TestUnitary); - } - } - } - } - - [Fact] - public void TestRCheckQubits() - { - using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) - { - // R - var mapper = new Func(qubit => (Pauli.PauliZ, 1.0, qubit)); - var gate = qsim.Get(); - var p = gate.Partial(mapper); - TestOne(qsim, p, TestUnitary); - } - } - - [Fact] - public void TestExpCheckQubits() - { - using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) - { - // Exp - { - var mapper = new Func, (IQArray, Double, IQArray)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), 1.0, qubits)); - var gate = qsim.Get(); - var p = gate.Partial(mapper); - TestOne(qsim, p, TestMultiUnitary); - } - - // ExpFrac - { - var mapper = new Func, (IQArray, long, long, IQArray)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), 1, 2, qubits)); - var gate = qsim.Get(); - var p = gate.Partial(mapper); - TestOne(qsim, p, TestMultiUnitary); - } - } - } - - - [Fact] - public void TestMeasureCheckQubits() - { - using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) - { - // M - { - var gate = qsim.Get(); - TestOne(qsim, gate, (g, ctrls, t) => TestCallable(g, t[0])); - } - - // Measure - { - var gate = qsim.Get(); - var mapper = new Func, (IQArray, IQArray)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), qubits)); - var p = gate.Partial(mapper); - TestOne(qsim, p, (g, ctrls, t) => TestMultiCallable(p, t)); - } - } - } - - [Fact] - public void TestAssertCheckQubits() - { - using (var qsim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: false)) - { - // Assert - { - var gate = qsim.Get(); - var mapper = new Func, (IQArray, IQArray, Result, String)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), qubits, Result.Zero, "")); - var p = gate.Partial(mapper); - TestOne(qsim, gate, (g, ctrls, t) => TestMultiCallable(p, t)); - } - - // AssertProb - { - var gate = qsim.Get(); - var mapper = new Func, (IQArray, IQArray, Result, Double, String, Double)>(qubits => (new QArray(Pauli.PauliZ, Pauli.PauliI, Pauli.PauliI), qubits, Result.Zero, 1.000, "", 0.002)); - var p = gate.Partial(mapper); - TestOne(qsim, p, (g, ctrls, t) => TestMultiCallable(p, t)); - } - } - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs b/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs deleted file mode 100644 index 0cc32328fdf..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/QuantumSimulatorTests/VerifyGates.cs +++ /dev/null @@ -1,468 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Threading.Tasks; -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Simulators.Tests.Circuits; -using Xunit; - -using static System.Math; - -namespace Microsoft.Quantum.Simulation.Simulators.Tests -{ - public class State - { - public State((double, double) alpha, (double, double) beta) - { - Alpha = new Microsoft.Quantum.Math.Complex(alpha); - Beta = new Microsoft.Quantum.Math.Complex(beta); - } - - public Microsoft.Quantum.Math.Complex Alpha { get; } - - public Microsoft.Quantum.Math.Complex Beta { get; } - - public (Microsoft.Quantum.Math.Complex, Microsoft.Quantum.Math.Complex) Value => (Alpha, Beta); - - - } - - public partial class QuantumSimulatorTests - { - public const int seed = 19740212; - public static System.Random r = new System.Random(seed); - - public static double sqrt1_2 = Sqrt(1.0 / 2.0); - - public static (double, double) E_i(double angle) - { - return (Cos(angle), Sin(angle)); - } - - public static (double, double) times(double d, (double, double) c) - { - var (r, i) = c; - return ((d * r, d * i)); - } - - public static double Angle(int nom, int powerDen) - { - return (PI * nom / (1 << powerDen)); - } - - /// - /// It runs the circuit to verify that the given one-qubit unitary gate performs - /// the right operation. For it, it receives an array of the expected states that the - /// Qubit must be in if starting from: - /// |0>, |1>, |+>, |-> - /// accordingly. - /// - private static void VerifyGate(IOperationFactory sim, IUnitary gate, State[] expected) - { - OperationsTestHelper.IgnoreDebugAssert(() => - { - var starts = new ValueTuple[] { - (Pauli.PauliZ, Result.Zero), - (Pauli.PauliZ, Result.One), - (Pauli.PauliX, Result.Zero), - (Pauli.PauliX, Result.One) - }; - - for (int i = 0; i < expected.Length; i++) - { - VerifyUnitary.Run(sim, gate, starts[i], expected[i].Value).Wait(); - } - }); - } - - private static void VerifyInvalidAngles(IOperationFactory sim, IUnitary<(double, Qubit)> gate) - { - OperationsTestHelper.IgnoreDebugAssert(() => - { - var q = sim.Get(typeof(Intrinsic.Allocate)).Apply(1); - - Assert.Throws(() => gate.Apply((Double.NaN, q[0]))); - Assert.Throws(() => gate.Apply((Double.PositiveInfinity, q[0]))); - Assert.Throws(() => gate.Apply((Double.NegativeInfinity, q[0]))); - }); - } - - [Fact] - public void QSimVerifyH() - { - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get(); - VerifyGate(sim, gate, new State[] - { - new State((sqrt1_2, 0.0), (sqrt1_2, .0)), - new State((sqrt1_2, 0.0), (-1 * sqrt1_2, .0)), - new State((1.0, 0.0), (0.0, 0.0)), - new State((0.0, 0.0), (1.0, 0.0)), - }); - } - } - - [Fact] - public void QSimVerifyX() - { - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get(); - - VerifyGate(sim, gate, new State[] - { - new State((0.0, 0.0), (1.0, 0.0)), - new State((1.0, 0.0), (0.0, 0.0)), - new State((sqrt1_2, 0.0), (sqrt1_2, 0.0)), - new State((-sqrt1_2, 0.0), (sqrt1_2, 0.0)) - }); - } - } - - [Fact] - public void QSimVerifyY() - { - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get(); - - VerifyGate(sim, gate, new State[] - { - new State((0.0, 0.0), (0.0, 1.0)), - new State((0.0, -1.0), (0.0, 0.0)), - new State((0.0, -sqrt1_2), (0.0, sqrt1_2)), - new State((0.0, sqrt1_2), (0.0, sqrt1_2)), - }); - } - } - - [Fact] - public void QSimVerifyZ() - { - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get(); - - VerifyGate(sim, gate, new State[] - { - new State((1.0, 0.0), (0.0, 0.0)), - new State((0.0, 0.0), (-1.0, 0.0)), - new State((sqrt1_2, 0.0), (-sqrt1_2, 0.0)), - new State((sqrt1_2, 0.0), (sqrt1_2, 0.0)) - }); - } - } - - [Fact] - public void QSimVerifyS() - { - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get(); - - VerifyGate(sim, gate, new State[] - { - new State((1.0, 0.0), (0.0, 0.0)), - new State((0.0, 0.0), (0.0, 1.0)), - new State((sqrt1_2, 0.0), (0.0, sqrt1_2)), - new State((sqrt1_2, 0.0), (0.0, -sqrt1_2)) - }); - } - } - - [Fact] - public void QSimVerifyT() - { - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get(); - - VerifyGate(sim, gate, new State[] - { - new State((1.0, 0.0), (0.0, 0.0)), - new State((0.0, 0.0), E_i(PI / 4)), - new State((sqrt1_2, 0.0), times(sqrt1_2, E_i(PI / 4))), - new State((sqrt1_2, 0.0), times(-sqrt1_2, E_i(PI / 4))) - }); - } - } - - [Fact] - public void QSimVerifyR1() - { - using (var sim = new QuantumSimulator()) - { - var angle = PI * r.NextDouble(); - Func mapper = (q) => (angle, q); - - var gate = sim.Get().Partial(mapper); - - VerifyGate(sim, gate, new State[] - { - new State((1.0, 0.0), (0.0, 0.0)), - new State((0.0, 0.0), E_i(angle)), - new State((sqrt1_2, 0.0), times(sqrt1_2, E_i(angle))), - new State((sqrt1_2, 0.0), times(-sqrt1_2, E_i(angle))) - }); - } - } - - /// - /// Returns the expected states when applying a rotation with the given angle - /// to the Qubit starting from |0>,|1>,|+>,|-> accordingly - /// - public static State[] ExponentExpectedStates(Pauli basis, double angle) - { - switch (basis) - { - case Pauli.PauliX: - return new State[] - { - new State((Cos(angle), 0.0), (0.0, Sin(angle))), - new State((0.0, Sin(angle)), (Cos(angle), 0.0)), - new State((sqrt1_2 * Cos(angle), sqrt1_2 * Sin(angle)), (sqrt1_2 * Cos(angle), sqrt1_2 * Sin(angle))), - new State((sqrt1_2 * Cos(angle), -sqrt1_2 * Sin(angle)), (-sqrt1_2 * Cos(angle), sqrt1_2 * Sin(angle))), - }; - case Pauli.PauliY: - return new State[] - { - new State((Cos(angle), 0.0), (-Sin(angle), 0.0)), - new State((Sin(angle), 0.0), (Cos(angle), 0.0)), - new State((sqrt1_2 * (Cos(angle) + Sin(angle)), 0.0), (sqrt1_2 * (Cos(angle) - Sin(angle)), 0.0)), - new State((sqrt1_2 * (Cos(angle) - Sin(angle)), 0.0), (sqrt1_2 * (-Cos(angle) - Sin(angle)), 0.0)) - }; - case Pauli.PauliZ: - return new State[] - { - new State(E_i(angle), (0.0, 0.0)), - new State((0.0, 0.0), E_i(-angle)), - new State(times(sqrt1_2, E_i(angle)), times(sqrt1_2, E_i(-angle))), - new State(times(sqrt1_2, E_i(angle)), times(-sqrt1_2, E_i(-angle))) - }; - case Pauli.PauliI: - return new State[] - { - new State(E_i(angle), (0.0, 0.0)), - new State((0.0, 0.0), E_i(angle)), - new State(times(sqrt1_2, E_i(angle)), times(sqrt1_2, E_i(angle))), - new State(times(sqrt1_2, E_i(angle)), times(-sqrt1_2, E_i(angle))), - }; - default: - throw new InvalidOperationException(); - } - } - - public static State[] ExponentExpectedStates(Pauli basis, int nom, int powerDen) - { - return ExponentExpectedStates(basis, Angle(nom, powerDen)); - } - - public static State[] RExpectedStates(Pauli basis, double angle) - { - return ExponentExpectedStates(basis, (-angle / 2)); - } - - public static State[] RExpectedStates(Pauli basis, int nom, int powerDen) - { - return ExponentExpectedStates(basis, Angle(nom, powerDen)); - } - - [Fact] - public void QSimVerifyRx() - { - var angle = 2 * PI * r.NextDouble(); - Func mapper = (q) - => (angle, q); - - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get().Partial(mapper); - VerifyGate(sim, gate, RExpectedStates(Pauli.PauliX, angle)); - - VerifyInvalidAngles(sim, sim.Get()); - } - } - - [Fact] - public void QSimVerifyRy() - { - var angle = 2 * PI * r.NextDouble(); - Func mapper = (q) - => (angle, q); - - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get().Partial(mapper); - VerifyGate(sim, gate, RExpectedStates(Pauli.PauliY, angle)); - - VerifyInvalidAngles(sim, sim.Get()); - } - } - - [Fact] - public void QSimVerifyRz() - { - var angle = 2 * PI * r.NextDouble(); - Func mapper = (q) - => (angle, q); - - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get().Partial(mapper); - VerifyGate(sim, gate, RExpectedStates(Pauli.PauliZ, angle)); - - VerifyInvalidAngles(sim, sim.Get()); - } - } - - [Fact] - public void QSimVerifyR() - { - var angle = 2 * PI * r.NextDouble(); - Func mapper = (q) - => (Pauli.PauliI, angle, q); - Func<(double, Qubit), (Pauli, double, Qubit)> needsAngle = (__arg) - => (Pauli.PauliI, __arg.Item1, __arg.Item2); - - using (var sim = new QuantumSimulator()) - { - var gate = sim.Get().Partial(mapper); - VerifyGate(sim, gate, RExpectedStates(Pauli.PauliI, angle)); - - var angleGate = sim.Get().Partial(needsAngle); - VerifyInvalidAngles(sim, angleGate); - } - } - - [Fact] - public void QSimVerifyRFrac() - { - using (var sim = new QuantumSimulator()) - { - var allBases = new[] { Pauli.PauliI, Pauli.PauliX, Pauli.PauliZ, Pauli.PauliY }; - - for (var k = 0; k < 4; k++) - { - for (var n = 0; n < 3; n++) - { - foreach (var p in allBases) - { - Func mapper = (q) => (p, k, n, q); - var gate = sim.Get().Partial(mapper); - - VerifyGate(sim, gate, RExpectedStates(p, k, n)); - } - } - } - } - } - - private void VerifyExp(Pauli pauli) - { - using (var sim = new QuantumSimulator()) - { - var angle = 2 * PI * r.NextDouble(); - - Func, double, IQArray)> mapper = (q) - => (new QArray (pauli), angle, new QArray (q)); - var gate = sim.Get().Partial(mapper); - - VerifyGate(sim, gate, ExponentExpectedStates(pauli, angle)); - - Func<(double, Qubit), (IQArray, double, IQArray)> needsAngle = (__arg) - => (new QArray (pauli), __arg.Item1, new QArray (__arg.Item2)); - var angleGate = sim.Get().Partial(needsAngle); - - VerifyInvalidAngles(sim, angleGate); - } - } - - [Fact] - public void QSimVerifyExp() - { - VerifyExp(Pauli.PauliI); - } - - [Fact] - public void QSimVerifyExpY() - { - VerifyExp(Pauli.PauliY); - } - - [Fact] - public void QSimVerifyExpZ() - { - VerifyExp(Pauli.PauliZ); - } - - [Fact] - public void QSimVerifyExpX() - { - VerifyExp(Pauli.PauliX); - } - - [Fact] - public void QSimVerifyExpFrac() - { - using (var sim = new QuantumSimulator()) - { - var allBases = new[] { Pauli.PauliI, Pauli.PauliX, Pauli.PauliZ, Pauli.PauliY }; - - for (var k = 0; k < 4; k++) - { - for (var n = 0; n < 3; n++) - { - foreach (var p in allBases) - { - Func, long, long, IQArray)> mapper = (q) - => (new QArray (p), k, n, new QArray (q)); - var gate = sim.Get().Partial(mapper); - - VerifyGate(sim, gate, ExponentExpectedStates(p, k, n)); - } - } - } - } - } - - [Fact] - public void QSimMeasure() - { - using (var sim = new QuantumSimulator()) - { - var op = sim.Get, JointMeasureTest>(); - op.Apply(QVoid.Instance); - } - } - - [Fact] - public void QSimM() - { - using (var sim = new QuantumSimulator()) - { - var m = sim.Get(); - - var allocate = sim.Get(); - var release = sim.Get(); - var x = sim.Get(); - - var qbits = allocate.Apply(1); - Assert.Single(qbits); - - var q = qbits[0]; - var result = m.Apply(q); - Assert.Equal(Result.Zero, result); - - x.Apply(q); - result = m.Apply(q); - Assert.Equal(Result.One, result); - x.Apply(q); - - release.Apply(qbits); - sim.CheckNoQubitLeak(); - } - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj deleted file mode 100644 index ebff7c89f2f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - netcoreapp3.1 - false - true - - false - false - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs deleted file mode 100644 index 64cb257b421..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/IntrinsicTests/Random/Tests.qs +++ /dev/null @@ -1,248 +0,0 @@ -namespace Microsoft.Quantum.Tests { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Canon; - open Microsoft.Quantum.Random; - open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Math; - - // Uses Welford's method to compute the mean and variance of an array - // of samples. - internal function SampleMeanAndVariance(samples : Double[]) : (Double, Double) { - mutable meanAcc = 0.0; - mutable varAcc = 0.0; - for (idx in 0..Length(samples) - 1) { - let sample = samples[idx]; - let oldMeanAcc = meanAcc; - let delta = (sample - meanAcc); - set meanAcc += delta / IntAsDouble(idx + 1); - set varAcc += delta * (sample - oldMeanAcc); - } - - return (meanAcc, varAcc / IntAsDouble(Length(samples) - 1)); - } - - internal operation EstimateMeanAndVariance(dist : ContinuousDistribution, nSamples : Int) : (Double, Double) { - mutable samples = new Double[nSamples]; - for (idx in 0..nSamples - 1) { - set samples w/= idx <- dist::Sample(); - } - return SampleMeanAndVariance(samples); - } - - internal operation CheckMeanAndVariance( - name : String, - distribution : ContinuousDistribution, - nSamples : Int, - (expectedMean : Double, expectedVariance : Double), - tolerance : Double - ) : Unit { - let (mean, variance) = EstimateMeanAndVariance( - distribution, - nSamples - ); - Fact( - expectedMean - tolerance <= mean and - mean <= expectedMean + tolerance, - $"Mean of {name} distribution should be {expectedMean}, was {mean}." - ); - Fact( - expectedVariance - tolerance <= variance and - variance <= expectedVariance + tolerance, - $"Variance of {name} distribution should be {expectedVariance}, was {variance}." - ); - } - - /// # Summary - /// Checks that @"microsoft.quantum.random.drawrandomdouble" obeys ranges. - @Test("QuantumSimulator") - operation CheckDrawRandomDoubleObeysRanges() : Unit { - for (j in 0..10000) { - let random = DrawRandomDouble(0.0, 1.0); - if (random < 0.0 or random > 1.0) { - fail $"DrawRandomDouble(0.0, 1.0) returned {random}, outside the allowed interval."; - } - } - } - - /// # Summary - /// Checks that @"microsoft.quantum.random.drawrandomdint" obeys ranges. - @Test("QuantumSimulator") - operation CheckDrawRandomIntObeysRanges() : Unit { - let randomInt = DrawRandomInt(0, 45); - if (randomInt > 45 or randomInt < 0) { - fail $"DrawRandomInt(0, 45) returned {randomInt}, outside the allowed range."; - } - } - - /// # Summary - /// Checks that @"microsoft.quantum.random.continuousuniformdistribution" has the - /// expected moments. - @Test("QuantumSimulator") - operation CheckContinuousUniformDistributionHasRightMoments() : Unit { - CheckMeanAndVariance( - "uniform", - ContinuousUniformDistribution(0.0, 1.0), - 1000000, - (0.5, 1.0 / 12.0), - 0.02 - ); - } - - /// # Summary - /// Checks that @"microsoft.quantum.random.standardnormaldistribution" has the - /// expected moments. - @Test("QuantumSimulator") - operation CheckStandardNormalDistributionHasRightMoments() : Unit { - CheckMeanAndVariance( - "standard normal", - StandardNormalDistribution(), - 1000000, - (0.0, 1.0), - 0.02 - ); - } - - /// # Summary - /// Checks that @"microsoft.quantum.random.normaldistribution" has the - /// expected moments. - @Test("QuantumSimulator") - operation CheckNormalDistributionHasRightMoments() : Unit { - CheckMeanAndVariance( - "normal(-2.0, 5.0)", - NormalDistribution(-2.0, 5.0), - 1000000, - (-2.0, 5.0), - 0.02 - ); - } - - /// # Summary - /// Checks that @"microsoft.quantum.random.drawrandombool" has the right - /// first moment. Note that since DrawRandomBool represents a Bernoulli - /// trial, it is entirely characterized by its first moment; we don't need - /// to check variance here. - @Test("QuantumSimulator") - operation CheckDrawRandomBoolHasRightExpectation() : Unit { - // NB: DrawMany isn't available yet, since it's in the - // Microsoft.Quantum.Standard package, not QSharpCore. - let prHeads = 0.65; - let nFlips = 1000000; - let stdDev = Sqrt(IntAsDouble(nFlips) * prHeads * (1.0 - prHeads)); - let expected = IntAsDouble(nFlips) * prHeads; - let nAllowedStdDev = 4.0; - mutable nHeads = 0; - for (idx in 0..nFlips - 1) { - if (DrawRandomBool(prHeads)) { - set nHeads += 1; - } - } - - let delta = IntAsDouble(nHeads) - expected; - - Fact( - -nAllowedStdDev * stdDev <= delta and - delta <= nAllowedStdDev * stdDev, - "First moment of Bernoulli distribution was incorrect." - ); - } - - /// # Summary - /// Checks that DrawCategorical never draws elements with probability zero. - @Test("QuantumSimulator") - operation CheckImpossibleEventsAreNotDrawn() : Unit { - let distribution = CategoricalDistribution([0.5, 0.0, 0.5]); - let nTrials = 100000; - for (idxTrial in 0..nTrials - 1) { - let variate = distribution::Sample(); - Fact( - variate != 1, - "A variate of 1 was drawn from a categorical distribution, despite having a probability of 0." - ); - } - } - - // We define a couple callables to help us run continuous tests on discrete - // distributions as well. - - internal operation DrawDiscreteAsContinuous(discrete : DiscreteDistribution, delay : Unit) : Double { - return IntAsDouble(discrete::Sample()); - } - - internal function DiscreteAsContinuous(discrete : DiscreteDistribution) : ContinuousDistribution { - return ContinuousDistribution(DrawDiscreteAsContinuous(discrete, _)); - } - - @Test("QuantumSimulator") - operation CheckCategoricalMomentsAreCorrect() : Unit { - let categorical = DiscreteAsContinuous( - CategoricalDistribution([0.2, 0.5, 0.3]) - ); - let expected = 0.0 * 0.2 + 1.0 * 0.5 + 2.0 * 0.3; - let variance = PowD(0.0 - expected, 2.0) * 0.2 + - PowD(1.0 - expected, 2.0) * 0.5 + - PowD(2.0 - expected, 2.0) * 0.3; - - CheckMeanAndVariance( - "categorical([0.2, 0.5, 0.3])", - categorical, - 1000000, - (expected, variance), - 0.04 - ); - } - - @Test("QuantumSimulator") - operation CheckRescaledCategoricalMomentsAreCorrect() : Unit { - let categorical = DiscreteAsContinuous( - CategoricalDistribution([2.0, 5.0, 3.0]) - ); - let expected = 0.0 * 0.2 + 1.0 * 0.5 + 2.0 * 0.3; - let variance = PowD(0.0 - expected, 2.0) * 0.2 + - PowD(1.0 - expected, 2.0) * 0.5 + - PowD(2.0 - expected, 2.0) * 0.3; - - CheckMeanAndVariance( - "categorical([0.2, 0.5, 0.3])", - categorical, - 1000000, - (expected, variance), - 0.04 - ); - } - - @Test("QuantumSimulator") - operation CheckCategoricalHistogramIsCorrect() : Unit { - let categorical = CategoricalDistribution([0.2, 0.5, 0.3]); - mutable counts = new Int[3]; - let nSamples = 1000000; - - for (idx in 0..nSamples - 1) { - let sample = categorical::Sample(); - set counts w/= sample <- counts[sample] + 1; - } - - Fact(190000 <= counts[0] and counts[0] <= 210000, $"counts[0] was {counts[0]}, expected about 200000."); - Fact(490000 <= counts[1] and counts[1] <= 510000, $"counts[1] was {counts[1]}, expected about 500000."); - Fact(290000 <= counts[2] and counts[2] <= 310000, $"counts[2] was {counts[2]}, expected about 300000."); - } - - @Test("QuantumSimulator") - operation CheckDiscreteUniformMomentsAreCorrect() : Unit { - let (min, max) = (-3, 7); - let expected = 0.5 * (IntAsDouble(min + max)); - let variance = (1.0 / 12.0) * ( - PowD(IntAsDouble(max - min + 1), 2.0) - 1.0 - ); - CheckMeanAndVariance( - $"discrete uniform ({min}, {max})", - DiscreteAsContinuous( - DiscreteUniformDistribution(min, max) - ), - 1000000, - (expected, variance), - 0.1 - ); - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs deleted file mode 100644 index 15972e2efc4..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library.qs +++ /dev/null @@ -1,43 +0,0 @@ -// Used for a unit test; -// do not change the name of this namespace! -namespace Microsoft.Quantum.Library { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - // Used for a unit test; - // do not change the name or namespace of this type! - @EnableTestingViaName("Library1.MyInt") - newtype MyInt = (Value1 : Int); - - // Used for a unit test; - // do not change the name or namespace of this type! - newtype MyString = (Text : String); - - // Used for a unit test; - // do not change the name or namespace of this type! - @EnableTestingViaName("Library1.Token") - newtype Token = Unit; - - // Used for a unit test; - // do not change the name or namespace of this callable! - @EnableTestingViaName("Library1.LibraryId") - function LibraryId() : Int { - return 1; - } - - // Used for a unit test; - // do not change the name or namespace of this callable! - function DllName() : String { - return "Library1"; - } - - // Used for a unit test; - // do not change the name or namespace of this callable! - @EnableTestingViaName("Library1.Hello") - operation Hello(dummy : Token) : String { - return "Hello from Library1!"; - } - - -} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj deleted file mode 100644 index 265201bd85f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library1/Library1.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netstandard2.1 - - false - false - - - - - - - - - - - - - - diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs deleted file mode 100644 index 237186bb92a..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library.qs +++ /dev/null @@ -1,31 +0,0 @@ -// Used for a unit test; -// do not change the name of this namespace! -namespace Microsoft.Quantum.Library { - - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Diagnostics; - - // Used for a unit test; - // do not change the name or namespace of this type! - @EnableTestingViaName("Library2.MyInt") - newtype MyInt = (Value2 : Int); - - // Used for a unit test; - // do not change the name or namespace of this type! - @EnableTestingViaName("Library2.MyString") - newtype MyString = (Text : String); - - // Used for a unit test; - // do not change the name or namespace of this callable! - @EnableTestingViaName("Library2.LibraryId") - function LibraryId() : Int { - return 2; - } - - // Used for a unit test; - // do not change the name or namespace of this callable! - @EnableTestingViaName("Library2.DllName") - function DllName() : String { - return "Library2"; - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj deleted file mode 100644 index 265201bd85f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/Library2/Library2.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netstandard2.1 - - false - false - - - - - - - - - - - - - - diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs deleted file mode 100644 index 880bdf81a85..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Facts.qs +++ /dev/null @@ -1,37 +0,0 @@ -namespace Microsoft.Quantum.Testing { - internal function FactI(expected : Int, got : Int) : Unit { - if (expected != got) { - fail $"Expected: {expected}, got: {got}"; - } - } - - internal function FactS(expected : String, got : String) : Unit { - if (expected != got) { - fail $"Expected: {expected}, got: {got}"; - } - } - - internal function FactMyInt1(expected : Int, got : Library1.MyInt) : Unit { - if (expected != got::Value1) { - fail $"Expected: {expected}, got: {got::Value1}"; - } - } - - internal function FactMyInt2(expected : Int, got : Library2.MyInt) : Unit { - if (expected != got::Value2) { - fail $"Expected: {expected}, got: {got::Value2}"; - } - } - - internal function FactMyString1(expected : String, got : Microsoft.Quantum.Library.MyString) : Unit { - if (expected != got::Text) { - fail $"Expected: {expected}, got: {got::Text}"; - } - } - - internal function FactMyString2(expected : String, got : Library2.MyString) : Unit { - if (expected != got::Text) { - fail $"Expected: {expected}, got: {got::Text}"; - } - } -} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs deleted file mode 100644 index 4d8cd71c3b1..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/Hello.qs +++ /dev/null @@ -1,16 +0,0 @@ -// Used for a unit test; -// do not change the name of this namespace! -namespace Microsoft.Quantum.Library { - - open Microsoft.Quantum.Intrinsic; - - // Used for a unit test; - // do not change the name or namespace of this type! - newtype Token = Unit; - - // Used for a unit test; - // do not change the name or namespace of this callable! - operation Hello(dummy : Token) : Unit { - Message("Hello!"); - } -} \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs deleted file mode 100644 index 68a3ee38845..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/TestNameTests.qs +++ /dev/null @@ -1,48 +0,0 @@ -namespace Microsoft.Quantum.Testing.LoadViaTestName { - - open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Testing; - - @Test("QuantumSimulator") - operation BothCallables () : Unit { - - FactI(1, Library1.LibraryId()); - FactI(2, Library2.LibraryId()); - } - - @Test("QuantumSimulator") - operation OneCallable () : Unit { - - FactS("Library1", Microsoft.Quantum.Library.DllName()); - FactS("Library2", Library2.DllName()); - } - - @Test("QuantumSimulator") - operation BothTypes () : Unit { - - let i1 = Library1.MyInt(1); - let i2 = Library2.MyInt(2); - FactMyInt1(1, i1); - FactMyInt2(2, i2); - } - - @Test("QuantumSimulator") - operation OneType () : Unit { - - let s1 = Microsoft.Quantum.Library.MyString("Library1"); - let s2 = Library2.MyString("Library2"); - FactMyString1("Library1", s1); - FactMyString2("Library2", s2); - } - - @Test("QuantumSimulator") - operation ConflictingWithSource () : Unit { - - let h1 = Library1.Hello(Library1.Token()); - let h2 = Microsoft.Quantum.Library.Hello(Microsoft.Quantum.Library.Token()); - FactS("Hello from Library1!", h1); - return h2; - } - -} diff --git a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj deleted file mode 100644 index b181e10a11f..00000000000 --- a/src/Simulation/Simulators.Type2.Tests/TestProjects/UnitTests/UnitTests.csproj +++ /dev/null @@ -1,32 +0,0 @@ - - - - netcoreapp3.1 - false - true - - false - false - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj index 0480e675622..22586d82c91 100644 --- a/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj +++ b/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj @@ -11,12 +11,6 @@ false - - - - - - @@ -24,7 +18,18 @@ - + + + + + + + + + + + +