From 81f1bc7f69671f98a7c621c9d0116c0692b4abd6 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Thu, 3 Sep 2020 22:08:49 -0700 Subject: [PATCH 01/12] Type1 targeting package --- .../Decompositions/CCNOTFromCCZ.qs | 39 +++++++++ ...FracFromIsing.qs => ExpFracFromExpUtil.qs} | 4 +- .../{ExpFromIsing.qs => ExpFromExpUtil.qs} | 4 +- .../Decompositions/ExpUtil.qs | 31 +++++++ .../Decompositions/ExpUtilFromIsing.qs | 46 +++++++++++ .../Decompositions/HFromSinglyControlled.qs | 47 +++++++++++ .../Decompositions/MResetXExplicit.qs | 31 +++++++ .../Decompositions/MResetYExplicit.qs | 31 +++++++ .../Decompositions/MResetZExplicit.qs | 30 +++++++ .../Decompositions/Measure.qs | 69 ++++++++++++++++ .../Decompositions/PreparePostM.qs | 16 ++++ .../Decompositions/PreparePostMNoop.qs | 12 +++ .../Decompositions/RxFromSinglyControlled.qs | 56 +++++++++++++ .../Decompositions/RyFromSinglyControlled.qs | 56 +++++++++++++ .../Decompositions/RzFromSinglyControlled.qs | 54 ++++++++++++ .../Decompositions/SFromSinglyControlled.qs | 43 ++++++++++ .../Decompositions/TFromSinglyControlled.qs | 43 ++++++++++ .../TargetDefinitions/Decompositions/Utils.qs | 82 +++++++++---------- .../Decompositions/XFromSinglyControlled.qs | 43 ++++++++++ .../Decompositions/YFromSinglyControlled.qs | 53 ++++++++++++ .../Decompositions/ZFromSinglyControlled.qs | 56 +++++++++++++ .../Intrinsic/ApplyControlledX.qs | 13 +++ .../Intrinsic/ApplyControlledZ.qs | 13 +++ .../Intrinsic/ApplyUncontrolledH.qs | 13 +++ .../Intrinsic/ApplyUncontrolledRx.qs | 13 +++ .../Intrinsic/ApplyUncontrolledRy.qs | 13 +++ .../Intrinsic/ApplyUncontrolledRz.qs | 13 +++ .../Intrinsic/ApplyUncontrolledS.qs | 13 +++ .../Intrinsic/ApplyUncontrolledT.qs | 13 +++ .../Intrinsic/ApplyUncontrolledX.qs | 13 +++ .../Intrinsic/ApplyUncontrolledY.qs | 13 +++ .../Intrinsic/ApplyUncontrolledZ.qs | 13 +++ .../TargetDefinitions/Intrinsic/Reset.qs | 18 ++++ .../TargetPackages/Type1.Package.props | 59 +++++++++++++ .../TargetPackages/Type2.Package.props | 5 +- .../Microsoft.Quantum.Type1.Core.csproj | 47 +++++++++++ 36 files changed, 1071 insertions(+), 47 deletions(-) create mode 100644 src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs rename src/Simulation/TargetDefinitions/Decompositions/{ExpFracFromIsing.qs => ExpFracFromExpUtil.qs} (95%) rename src/Simulation/TargetDefinitions/Decompositions/{ExpFromIsing.qs => ExpFromExpUtil.qs} (93%) create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/Measure.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs create mode 100644 src/Simulation/TargetDefinitions/Intrinsic/Reset.qs create mode 100644 src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props create mode 100644 src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj diff --git a/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs b/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs new file mode 100644 index 00000000000..5b1601c799b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the doubly controlled–NOT (CCNOT) gate to three qubits. + /// + /// # Input + /// ## control1 + /// First control qubit for the CCNOT gate. + /// ## control2 + /// Second control qubit for the CCNOT gate. + /// ## target + /// Target qubit for the CCNOT gate. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// Controlled X([control1, control2], target); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.CCNOT") + operation CCNOT (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj + Ctl { + body (...) { + // [Page 15 of arXiv:1206.0758v3](https://arxiv.org/pdf/1206.0758v3.pdf#page=15) + within { + H(target); + } + apply { + Controlled Z([control1, control2], target); + } + } + controlled (ctls, ...) { + Controlled X (ctls + [control1, control2], target); + } + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs similarity index 95% rename from src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs rename to src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs index 229edf4c658..e447f0fc760 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromIsing.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFracFromExpUtil.qs @@ -31,7 +31,7 @@ namespace Microsoft.Quantum.Intrinsic { /// 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(...) { + body (...) { CheckQubitUniqueness(qubits); if (Length(paulis) != Length(qubits)) { fail "Arrays 'pauli' and 'target' must have the same length"; } @@ -44,7 +44,7 @@ namespace Microsoft.Quantum.Intrinsic { 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, _)); + ExpUtil(newPaulis, theta, newQubits, RFrac(_, numerator, power, _)); } else { ApplyGlobalPhaseFracWithR1Frac(numerator, power); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs similarity index 93% rename from src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs rename to src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs index 5a9fee5ab2e..5f6c7b8ad60 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ExpFromIsing.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpFromExpUtil.qs @@ -25,14 +25,14 @@ namespace Microsoft.Quantum.Intrinsic { /// Register to apply the given rotation to. @EnableTestingViaName("Test.TargetDefinitions.Exp") operation Exp (paulis : Pauli[], theta : Double, qubits : Qubit[]) : Unit is Adj + Ctl { - body(...) { + 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) { - ExpNoIdUtil(newPaulis, theta , newQubits, R(_, -2.0 * theta, _)); + ExpUtil(newPaulis, theta , newQubits, R(_, -2.0 * theta, _)); } else { ApplyGlobalPhase(theta); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs new file mode 100644 index 00000000000..5131ac27048 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpUtil.qs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + @EnableTestingViaName("Test.TargetDefinitions.ExpUtil") + internal operation ExpUtil (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]); + } + else { // Length(paulis) > 1 + within { + for (i in 0 .. Length(paulis) - 1) { + MapPauli(qubits[i], PauliZ, paulis[i]); + } + } + apply { + within { + SpreadZ(qubits[0], qubits[ 1 .. Length(qubits) - 1]); + } + apply { + rotation(PauliZ, qubits[0]); + } + } + } + } + + +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs b/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.qs new file mode 100644 index 00000000000..b1bbc9d0dc4 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ExpUtilFromIsing.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; + + @EnableTestingViaName("Test.TargetDefinitions.ExpUtil") + internal operation ExpUtil (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 as an input to Exp"; + } + } + } + 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 { + IsingZZ(theta / 2.0, qubits[0], qubits[1]); + } + } + } + } + +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs new file mode 100644 index 00000000000..ff638cc18d9 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Hadamard transformation to a single qubit. + /// + /// # Description + /// \begin{align} + /// H \mathrel{:=} + /// \frac{1}{\sqrt{2}} + /// \begin{bmatrix} + /// 1 & 1 \\\\ + /// 1 & -1 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.H") + operation H (qubit : Qubit) : Unit is Adj + Ctl { + body (...) { + ApplyUncontrolledH(qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledH(qubit); + } + elif (Length(ctls) == 1) { + within{ + S(qubit); + H(qubit); + T(qubit); + } apply { + CNOT(ctls[0], qubit); + } + } + else { + ApplyWithLessControlsA(Controlled H, (ctls, qubit)); + } + } + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs new file mode 100644 index 00000000000..d853dc9e8e5 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetXExplicit.qs @@ -0,0 +1,31 @@ +// 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 { + MapPauli(target, PauliZ, PauliX); + let result = M(target); + Reset(target); + return result; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs new file mode 100644 index 00000000000..1bb586cfb8e --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetYExplicit.qs @@ -0,0 +1,31 @@ +// 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 { + MapPauli(target, PauliZ, PauliY); + let result = M(target); + Reset(target); + return result; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs b/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs new file mode 100644 index 00000000000..53dac30786f --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/MResetZExplicit.qs @@ -0,0 +1,30 @@ +// 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 { + let result = M(target); + Reset(target); + return result; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/Measure.qs b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs new file mode 100644 index 00000000000..2baef4da9af --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs @@ -0,0 +1,69 @@ +// 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 { + mutable res = One; + if( Length(bases) == 1 ) { + within { + MapPauli(qubits[0], PauliZ, bases[0]); + } + apply { + set res = M(qubits[0]); + PreparePostM(res, qubits[0]); + } + } + else { + using( q = Qubit() ) { + H(q); + 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); } + } + H(q); + set res = M(q); + Reset(q); + } + } + return res; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs b/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs new file mode 100644 index 00000000000..680d9d74faf --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/PreparePostM.qs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + @EnableTestingViaName("Test.TargetDefinitions.PreparePostM") + internal operation PreparePostM(result : Result, qubit : Qubit) : Unit { + // This platform requires reset after measurement, and then must + // re-prepare the measured state in the qubit. + Reset(qubit); + if (result == One) { + X(qubit); + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs b/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs new file mode 100644 index 00000000000..fb5dc304282 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/PreparePostMNoop.qs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + @EnableTestingViaName("Test.TargetDefinitions.PreparePostM") + internal operation PreparePostM(result : Result, qubit : Qubit) : Unit { + // This platform does not require any post-measurement reset, so + // no additional work is needed. + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs new file mode 100644 index 00000000000..e964eb00297 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # SummaRx + /// 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 (...) { + ApplyUncontrolledRx(theta, qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledRx(theta, qubit); + } + elif (Length(ctls) == 1) { + within { + MapPauli(qubit, PauliZ, PauliX); + } + apply { + Controlled Rz(ctls, (theta, qubit)); + } + } + else { + ApplyWithLessControlsA(Controlled Rx, (ctls, (theta, qubit))); + } + } + adjoint (...) { + Rx(-theta, qubit); + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs new file mode 100644 index 00000000000..8f22cf3f781 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs @@ -0,0 +1,56 @@ +// 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 (...) { + ApplyUncontrolledRy(theta, qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledRy(theta, qubit); + } + elif (Length(ctls) == 1) { + within { + MapPauli(qubit, PauliZ, PauliY); + } + apply { + Controlled Rz(ctls, (theta, qubit)); + } + } + else { + ApplyWithLessControlsA(Controlled Ry, (ctls, (theta, qubit))); + } + } + adjoint (...) { + Rz(-theta, qubit); + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs new file mode 100644 index 00000000000..09bfa6aec51 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs @@ -0,0 +1,54 @@ +// 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 (...) { + ApplyUncontrolledRz(theta, qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + Rz(theta, qubit); + } + elif (Length(ctls) == 1) { + Rz(theta/2.0, qubit); + CNOT(ctls[0], qubit); + Rz(-theta/2.0, qubit); + CNOT(ctls[0], qubit); + } + else { + ApplyWithLessControlsA(Controlled Rz, (ctls, (theta, qubit))); + } + } + adjoint (...) { + Rz(-theta, qubit); + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs new file mode 100644 index 00000000000..09655566e04 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the π/4 phase gate to a single qubit. + /// + /// # Description + /// \begin{align} + /// S \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & i + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.S") + operation S (qubit : Qubit) : Unit is Adj + Ctl { + body (...) { + ApplyUncontrolledS(qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledS(qubit); + } + elif (Length(ctls) == 1) { + T(ctls[0]); + T(qubit); + CNOT(ctls[0], qubit); + Adjoint T(qubit); + CNOT(ctls[0], qubit); + } + else { + ApplyWithLessControlsA(Controlled S, (ctls, qubit)); + } + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs new file mode 100644 index 00000000000..222ef97d9e1 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the π/8 gate to a single qubit. + /// + /// # Description + /// \begin{align} + /// T \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & e^{i \pi / 4} + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.T") + operation T (qubit : Qubit) : Unit is Adj + Ctl { + body (...) { + ApplyUncontrolledT(qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledT(qubit); + } + elif (Length(ctls) == 1) { + R1Frac(1, 3, ctls[0]); + R1Frac(1, 3, qubit); + CNOT(ctls[0], qubit); + Adjoint R1Frac(1, 3, qubit); + CNOT(ctls[0], qubit); + } + else { + ApplyWithLessControlsA(Controlled T, (ctls, qubit)); + } + } + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs index f0c38c1bfc0..d2808323a0d 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Utils.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Utils.qs @@ -4,41 +4,6 @@ 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) { - 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 as an input to Exp"; - } - } - } - else { // Length(paulis) > 2 - within { - for (i in 0 .. Length(paulis) - 1) { - MapPauli(qubits[i], PauliZ, paulis[i]); - } - SpreadZ(qubits[1], qubits[2 .. Length(qubits) - 1]); - } - apply { - IsingZZ(theta / 2.0, qubits[0], qubits[1]); - } - } - } - @EnableTestingViaName("Test.TargetDefinitions.SpreadZ") internal operation SpreadZ (from : Qubit, to : Qubit[]) : Unit is Adj { if (Length(to) > 0) { @@ -53,8 +18,8 @@ namespace Microsoft.Quantum.Intrinsic { @EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhase") internal operation ApplyGlobalPhase (theta : Double) : Unit is Ctl + Adj { - body(...) {} - controlled(controls, (...)) { + body (...) {} + controlled (controls, (...)) { if (Length(controls) > 0) { let qubit = controls[0]; let rest = controls[1...]; @@ -67,8 +32,8 @@ namespace Microsoft.Quantum.Intrinsic { @EnableTestingViaName("Test.TargetDefinitions.ApplyGlobalPhaseFracWithR1Frac") internal operation ApplyGlobalPhaseFracWithR1Frac (numerator : Int, power : Int) : Unit is Adj + Ctl { - body(...) {} - controlled(ctrls, ... ) { + body (...) {} + controlled (ctrls, ...) { let numControls = Length(ctrls); if (numControls > 0 ) { // Invoke Controlled R1Frac, which will recursively call back into ApplyGlobalPhase. @@ -106,6 +71,41 @@ namespace Microsoft.Quantum.Intrinsic { } } + /// Given a multiply-controlled operation that requires k controls + /// applies it using ceiling(k/2) controls and using floor(k/2) temporary qubits + @EnableTestingViaName("Test.TargetDefinitions.ApplyWithLessControlsA") + internal operation ApplyWithLessControlsA<'T> (op : ((Qubit[],'T) => Unit is Adj), (controls : Qubit[], arg : 'T)) : Unit is Adj { + let numControls = Length(controls); + let numControlPairs = numControls / 2; + using (temps = Qubit[numControlPairs]) { + within { + for (numPair in 0 .. numControlPairs - 1) { // constant depth + PhaseCCX(controls[2*numPair], controls[2*numPair + 1], temps[numPair]); + } + } + apply { + let newControls = numControls % 2 == 0 ? temps | temps + [controls[numControls - 1]]; + op(newControls, arg); + } + } + } + + @EnableTestingViaName("Test.TargetDefinitions.PhaseCCX") + internal operation PhaseCCX (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj { + // https://arxiv.org/pdf/1210.0974.pdf#page=2 + H(target); + CNOT(target,control1); + CNOT(control1,control2); + T(control2); + Adjoint T(control1); + T(target); + CNOT(target,control1); + CNOT(control1,control2); + Adjoint T(control2); + CNOT(target,control2); + H(target); + } + @EnableTestingViaName("Test.TargetDefinitions.ReducedDyadicFraction") internal function ReducedDyadicFraction (numerator : Int, denominatorPowerOfTwo : Int) : (Int, Int) { if (numerator == 0) { return (0,0); } @@ -142,7 +142,7 @@ namespace Microsoft.Quantum.Intrinsic { } @EnableTestingViaName("Test.TargetDefinitions.IndicesOfNonIdentity") - internal function IndicesOfNonIdentity(paulies : Pauli[]) : Int[] { + internal function IndicesOfNonIdentity (paulies : Pauli[]) : Int[] { mutable nonIdPauliCount = 0; for (i in 0 .. Length(paulies) - 1) { @@ -163,7 +163,7 @@ namespace Microsoft.Quantum.Intrinsic { } @EnableTestingViaName("Test.TargetDefinitions.RemovePauliI") - internal function RemovePauliI(paulis : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) { + internal function RemovePauliI (paulis : Pauli[], qubits : Qubit[]) : (Pauli[], Qubit[]) { let indices = IndicesOfNonIdentity(paulis); let newPaulis = Subarray(indices, paulis); let newQubits = Subarray(indices, qubits); diff --git a/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs new file mode 100644 index 00000000000..e33e1c88263 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Pauli $X$ gate. + /// + /// # Description + /// \begin{align} + /// \sigma_x \mathrel{:=} + /// \begin{bmatrix} + /// 0 & 1 \\\\ + /// 1 & 0 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.X") + operation X (qubit : Qubit) : Unit is Adj + Ctl { + body (...) { + ApplyUncontrolledX(qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledX(qubit); + } + elif (Length(ctls) == 1) { + ApplyControlledX(ctls[0], qubit); + } + elif (Length(ctls) == 2) { + CCNOT(ctls[0], ctls[1], qubit); + } + else { + ApplyWithLessControlsA(Controlled X, (ctls, qubit)); + } + } + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs new file mode 100644 index 00000000000..7636e127f22 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Pauli $Y$ gate. + /// + /// # Description + /// \begin{align} + /// \sigma_y \mathrel{:=} + /// \begin{bmatrix} + /// 0 & -i \\\\ + /// i & 0 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.Y") + operation Y (qubit : Qubit) : Unit is Adj + Ctl { + body (...) { + ApplyUncontrolledY(qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledY(qubit); + } + elif (Length(ctls) == 1) { + within { + MapPauli(qubit, PauliX, PauliY); + } + apply { + CNOT(ctls[0], qubit); + } + } + elif (Length(ctls) == 2) { + within { + MapPauli(qubit, PauliZ, PauliY); + } + apply { + Controlled Z(ctls, qubit); + } + } + else { + ApplyWithLessControlsA(Controlled Y, (ctls, qubit)); + } + } + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs new file mode 100644 index 00000000000..146bfc5da6d --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Pauli $Z$ gate. + /// + /// # Description + /// \begin{align} + /// \sigma_z \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & -1 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.Z") + operation Z (qubit : Qubit) : Unit is Adj + Ctl { + body (...) { + ApplyUncontrolledZ(qubit); + } + controlled (ctls, ...) { + if (Length(ctls) == 0) { + ApplyUncontrolledZ(qubit); + } + elif (Length(ctls) == 1) { + ApplyControlledZ(ctls[0], qubit); + } + elif (Length(ctls) == 2) { + // [Page 15 of arXiv:1206.0758v3](https://arxiv.org/pdf/1206.0758v3.pdf#page=15) + Adjoint T(ctls[0]); + Adjoint T(ctls[1]); + CNOT(qubit, ctls[0]); + T(ctls[0]); + CNOT(ctls[1], qubit); + CNOT(ctls[1], ctls[0]); + T(qubit); + Adjoint T(ctls[0]); + CNOT(ctls[1], qubit); + CNOT(qubit, ctls[0]); + Adjoint T(qubit); + T(ctls[0]); + CNOT(ctls[1], ctls[0]); + } + else { + ApplyWithLessControlsA(Controlled Z, (ctls, qubit)); + } + } + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs new file mode 100644 index 00000000000..9242d9c160b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Controlled X. + @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX") + internal operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs new file mode 100644 index 00000000000..4e134a4790b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Controlled Z. + @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ") + internal operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs new file mode 100644 index 00000000000..5e727890d3f --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled H. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledH") + internal operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs new file mode 100644 index 00000000000..e5605fa07eb --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled Rx. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRx") + internal operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs new file mode 100644 index 00000000000..7563e697610 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled Ry. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRy") + internal operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs new file mode 100644 index 00000000000..b339e179831 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled Rz. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRz") + internal operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs new file mode 100644 index 00000000000..ef8a4099825 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled S. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS") + internal operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs new file mode 100644 index 00000000000..e8359f73cff --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled T. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT") + internal operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs new file mode 100644 index 00000000000..92a9a954ac6 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled X. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledX") + internal operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs new file mode 100644 index 00000000000..a7d158b906b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled Y. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledY") + internal operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs new file mode 100644 index 00000000000..4655776eb80 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// Helper for native Uncontrolled Z. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledZ") + internal operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { + body intrinsic; + adjoint self; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs b/src/Simulation/TargetDefinitions/Intrinsic/Reset.qs new file mode 100644 index 00000000000..7531b828982 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Intrinsic/Reset.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 { + body intrinsic; + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props new file mode 100644 index 00000000000..73bf1e40315 --- /dev/null +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props index be0f1d9635e..ec6db28ce45 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props @@ -26,8 +26,9 @@ - - + + + diff --git a/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj new file mode 100644 index 00000000000..f4f68b9383f --- /dev/null +++ b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj @@ -0,0 +1,47 @@ + + + + + + + + + netstandard2.1 + true + false + false + + + + Microsoft + Type1 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 dd3bbbbd37496b65879d6498e4a770fba52358d7 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 4 Sep 2020 15:15:50 -0700 Subject: [PATCH 02/12] Add Type1 simulator support and tests --- Simulation.sln | 38 +++++++ bootstrap.ps1 | 4 + build/manifest.ps1 | 7 ++ build/pack.ps1 | 2 + .../Common/Simulators.Type1.Dev.props | 42 +++++++ .../Simulators.Type1.Tests/App.config | 6 + .../OperationsTestHelperSimSupport.cs | 34 ++++++ ....Microsoft.Quantum.Simulators.Type1.csproj | 57 ++++++++++ src/Simulation/Simulators.Type1/.gitignore | 1 + .../Simulators.Type1/FindNuspecReferences.ps1 | 103 ++++++++++++++++++ .../Microsoft.Quantum.Simulators.Type1.csproj | 42 +++++++ ...t.Quantum.Simulators.Type1.nuspec.template | 31 ++++++ .../Properties/AssemblyInfo.cs | 9 ++ ...t.Quantum.Simulators.Type2.nuspec.template | 2 +- .../QuantumSimulator/ApplyControlledX.cs | 36 ++++++ .../QuantumSimulator/ApplyControlledZ.cs | 36 ++++++ .../QuantumSimulator/ApplyUncontrolledH.cs | 35 ++++++ .../QuantumSimulator/ApplyUncontrolledRx.cs | 42 +++++++ .../QuantumSimulator/ApplyUncontrolledRy.cs | 42 +++++++ .../QuantumSimulator/ApplyUncontrolledRz.cs | 42 +++++++ .../QuantumSimulator/ApplyUncontrolledS.cs | 47 ++++++++ .../QuantumSimulator/ApplyUncontrolledT.cs | 45 ++++++++ .../QuantumSimulator/ApplyUncontrolledX.cs | 35 ++++++ .../QuantumSimulator/ApplyUncontrolledY.cs | 35 ++++++ .../QuantumSimulator/ApplyUncontrolledZ.cs | 35 ++++++ .../Simulators/QuantumSimulator/Reset.cs | 43 ++++++++ .../Decompositions/ApplyControlledX.qs | 39 +++++++ .../Decompositions/ApplyControlledZ.qs | 36 ++++++ .../Decompositions/ApplyUncontrolledH.qs | 28 +++++ .../Decompositions/ApplyUncontrolledRx.qs | 36 ++++++ .../Decompositions/ApplyUncontrolledRy.qs | 36 ++++++ .../Decompositions/ApplyUncontrolledRz.qs | 36 ++++++ .../Decompositions/ApplyUncontrolledS.qs | 27 +++++ .../Decompositions/ApplyUncontrolledT.qs | 27 +++++ .../Decompositions/ApplyUncontrolledX.qs | 26 +++++ .../Decompositions/ApplyUncontrolledY.qs | 26 +++++ .../Decompositions/ApplyUncontrolledZ.qs | 26 +++++ .../Decompositions/HFromSinglyControlled.qs | 1 + .../Decompositions/Measure.qs | 2 + .../Decompositions/RxFromSinglyControlled.qs | 2 + .../Decompositions/RyFromSinglyControlled.qs | 4 +- .../Decompositions/RzFromSinglyControlled.qs | 2 + .../Decompositions/SFromSinglyControlled.qs | 1 + .../Decompositions/TFromSinglyControlled.qs | 1 + .../Decompositions/XFromSinglyControlled.qs | 1 + .../Decompositions/YFromSinglyControlled.qs | 1 + .../Decompositions/ZFromSinglyControlled.qs | 1 + .../Intrinsic/ApplyControlledX.qs | 31 +++++- .../Intrinsic/ApplyControlledZ.qs | 27 ++++- .../Intrinsic/ApplyUncontrolledH.qs | 20 +++- .../Intrinsic/ApplyUncontrolledRx.qs | 28 ++++- .../Intrinsic/ApplyUncontrolledRy.qs | 28 ++++- .../Intrinsic/ApplyUncontrolledRz.qs | 28 ++++- .../Intrinsic/ApplyUncontrolledS.qs | 19 +++- .../Intrinsic/ApplyUncontrolledT.qs | 19 +++- .../Intrinsic/ApplyUncontrolledX.qs | 18 ++- .../Intrinsic/ApplyUncontrolledY.qs | 18 ++- .../Intrinsic/ApplyUncontrolledZ.qs | 18 ++- .../TargetDefinitions/Intrinsic/Checks.qs | 8 +- .../TargetPackages/QsharpCore.Package.props | 11 ++ .../TargetPackages/Type2.Package.props | 11 ++ 61 files changed, 1464 insertions(+), 30 deletions(-) create mode 100644 src/Simulation/Common/Simulators.Type1.Dev.props create mode 100644 src/Simulation/Simulators.Type1.Tests/App.config create mode 100644 src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs create mode 100644 src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj create mode 100644 src/Simulation/Simulators.Type1/.gitignore create mode 100644 src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 create mode 100644 src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj create mode 100644 src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.nuspec.template create mode 100644 src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs create mode 100644 src/Simulation/Simulators/QuantumSimulator/Reset.cs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs create mode 100644 src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs diff --git a/Simulation.sln b/Simulation.sln index 8b4957e793d..be40121ab66 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -83,6 +83,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProject EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntrinsicTests", "src\Simulation\Simulators.Tests\TestProjects\IntrinsicTests\IntrinsicTests.csproj", "{4EF958CA-B4A6-4E5F-924A-100B5615BEC3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Simulators.Type1", "src\Simulation\Simulators.Type1\Microsoft.Quantum.Simulators.Type1.csproj", "{F995209F-FEE1-4083-ABD9-4998563E0070}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Microsoft.Quantum.Simulators.Type1", "src\Simulation\Simulators.Type1.Tests\Tests.Microsoft.Quantum.Simulators.Type1.csproj", "{EB6E3DBD-C884-4241-9BC4-8281191D1F53}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -575,6 +579,38 @@ 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 + {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|x64.ActiveCfg = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.Debug|x64.Build.0 = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|Any CPU.Build.0 = Release|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|x64.ActiveCfg = Release|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.Release|x64.Build.0 = Release|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {F995209F-FEE1-4083-ABD9-4998563E0070}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|x64.ActiveCfg = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Debug|x64.Build.0 = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|Any CPU.Build.0 = Release|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|x64.ActiveCfg = Release|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.Release|x64.Build.0 = Release|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -614,6 +650,8 @@ Global {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} + {F995209F-FEE1-4083-ABD9-4998563E0070} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {EB6E3DBD-C884-4241-9BC4-8281191D1F53} = {9008B252-2DF7-404B-B626-D4497BB70A05} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821} diff --git a/bootstrap.ps1 b/bootstrap.ps1 index 251698dff4f..2a74594cf2f 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.Type1") + .\FindNuspecReferences.ps1 +Pop-Location + Push-Location (Join-Path $PSScriptRoot "src/Simulation/Simulators.Type2") .\FindNuspecReferences.ps1 Pop-Location diff --git a/build/manifest.ps1 b/build/manifest.ps1 index fbe7f793736..f8cb1ec7c07 100644 --- a/build/manifest.ps1 +++ b/build/manifest.ps1 @@ -10,8 +10,12 @@ "Microsoft.Quantum.Development.Kit", "Microsoft.Quantum.EntryPointDriver", "Microsoft.Quantum.QSharp.Core", + "Microsoft.Quantum.Type1.Core", + "Microsoft.Quantum.Type2.Core", "Microsoft.Quantum.Runtime.Core", "Microsoft.Quantum.Simulators", + "Microsoft.Quantum.Simulators.Type1", + "Microsoft.Quantum.Simulators.Type2", "Microsoft.Quantum.Xunit" ); Assemblies = @( @@ -22,10 +26,13 @@ ".\src\Simulation\Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Runtime.Core.dll", ".\src\Simulation\EntryPointDriver\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.EntryPointDriver.dll", ".\src\Simulation\QsharpCore\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QSharp.Core.dll", + ".\src\Simulation\Type1Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Type1.Core.dll", + ".\src\Simulation\Type2Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Type2.Core.dll", ".\src\Simulation\QsharpFoundation\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.QSharp.Foundation.dll", ".\src\Simulation\Simulators.Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.Common.dll", ".\src\Simulation\Simulators.Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll", ".\src\Simulation\Simulators.Core\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.dll", + ".\src\Simulation\Simulators.Type1\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Simulators.Type1.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 ".." $_)) }; diff --git a/build/pack.ps1 b/build/pack.ps1 index 65dc7d01a94..283085f64ca 100644 --- a/build/pack.ps1 +++ b/build/pack.ps1 @@ -66,8 +66,10 @@ 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-Dotnet '../src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj' Pack-Dotnet '../src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj' Pack-One '../src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.nuspec' +Pack-One '../src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.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' diff --git a/src/Simulation/Common/Simulators.Type1.Dev.props b/src/Simulation/Common/Simulators.Type1.Dev.props new file mode 100644 index 00000000000..7016572f718 --- /dev/null +++ b/src/Simulation/Common/Simulators.Type1.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/Simulators.Type1.Tests/App.config b/src/Simulation/Simulators.Type1.Tests/App.config new file mode 100644 index 00000000000..94ce1a2b94f --- /dev/null +++ b/src/Simulation/Simulators.Type1.Tests/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs new file mode 100644 index 00000000000..d6abcc6ed50 --- /dev/null +++ b/src/Simulation/Simulators.Type1.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.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj b/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj new file mode 100644 index 00000000000..f9e6b67ad9a --- /dev/null +++ b/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj @@ -0,0 +1,57 @@ + + + + + + + + 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.Type1/.gitignore b/src/Simulation/Simulators.Type1/.gitignore new file mode 100644 index 00000000000..1624c7f7e14 --- /dev/null +++ b/src/Simulation/Simulators.Type1/.gitignore @@ -0,0 +1 @@ +Microsoft.Quantum.Simulators.Type1.nuspec \ No newline at end of file diff --git a/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 new file mode 100644 index 00000000000..8a96bf87970 --- /dev/null +++ b/src/Simulation/Simulators.Type1/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 +# identify 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.Type1.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.Type1.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.Type1 +Add-NuGetDependencyFromCsprojToNuspec "Microsoft.Quantum.Simulators.Type1.csproj" + +# Save into .nuspec file: +$nuspec.package.metadata.AppendChild($dep) +$nuspec.Save($target) diff --git a/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj new file mode 100644 index 00000000000..feb0ac3ee45 --- /dev/null +++ b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj @@ -0,0 +1,42 @@ + + + + + + + + netstandard2.1 + + + + 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.Type1/Microsoft.Quantum.Simulators.Type1.nuspec.template b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.nuspec.template new file mode 100644 index 00000000000..1d7a7445bfc --- /dev/null +++ b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.nuspec.template @@ -0,0 +1,31 @@ + + + + Microsoft.Quantum.Simulators.Type1 + $version$ + $title$ + Microsoft + QuantumEngineering, Microsoft + MIT + https://docs.microsoft.com/en-us/quantum + images\qdk-nuget-icon.png + false + Type1 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.Type1/Properties/AssemblyInfo.cs b/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..ed47130ca02 --- /dev/null +++ b/src/Simulation/Simulators.Type1/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.Type1" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template index 0259a979f74..aa78d359d19 100644 --- a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template +++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.nuspec.template @@ -1,7 +1,7 @@ - Microsoft.Quantum.Simulators + Microsoft.Quantum.Simulators.Type2 $version$ $title$ Microsoft diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs new file mode 100644 index 00000000000..78ab94834dd --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs @@ -0,0 +1,36 @@ +// 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 QSimApplyControlledX : Intrinsic.ApplyControlledX + { + [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 QSimApplyControlledX(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(Qubit, Qubit), QVoid> __Body__ => (args) => + { + var (control, target) = args; + + Simulator.CheckQubits(new QArray(new Qubit[]{ control, target })); + + MCX(Simulator.Id, 1, new uint[]{(uint)control.Id}, (uint)target.Id); + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs new file mode 100644 index 00000000000..2f76e962107 --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs @@ -0,0 +1,36 @@ +// 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 QSimApplyControlledZ : Intrinsic.ApplyControlledZ + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCZ")] + private static extern void MCZ(uint id, uint count, uint[] ctrls, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimApplyControlledZ(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func<(Qubit, Qubit), QVoid> __Body__ => (args) => + { + var (control, target) = args; + + Simulator.CheckQubits(new QArray(new Qubit[]{ control, target })); + + MCZ(Simulator.Id, 1, new uint[]{(uint)control.Id}, (uint)target.Id); + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs new file mode 100644 index 00000000000..79b6d22548e --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs @@ -0,0 +1,35 @@ +// 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 QSimApplyUncontrolledH : Intrinsic.ApplyUncontrolledH + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "H")] + private static extern void H(uint id, uint qubit); + + private QuantumSimulator Simulator { get; } + + + public QSimApplyUncontrolledH(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func __Body__ => (q1) => + { + Simulator.CheckQubit(q1); + + H(Simulator.Id, (uint)q1.Id); + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs new file mode 100644 index 00000000000..c2eb72680cc --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs @@ -0,0 +1,42 @@ +// 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 QSimApplyUncontrolledRx : Intrinsic.ApplyUncontrolledRx + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] + private static extern void R(uint id, Pauli basis, double angle, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimApplyUncontrolledRx(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)); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs new file mode 100644 index 00000000000..8a5187725ec --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs @@ -0,0 +1,42 @@ +// 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 QSimApplyUncontrolledRy : Intrinsic.ApplyUncontrolledRy + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] + private static extern void R(uint id, Pauli basis, double angle, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimApplyUncontrolledRy(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)); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs new file mode 100644 index 00000000000..55e71e21e45 --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs @@ -0,0 +1,42 @@ +// 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 QSimApplyUncontrolledRz : Intrinsic.ApplyUncontrolledRz + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] + private static extern void R(uint id, Pauli basis, double angle, uint qubit); + + private QuantumSimulator Simulator { get; } + + public QSimApplyUncontrolledRz(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)); + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs new file mode 100644 index 00000000000..632e70380bb --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.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 QSimApplyUncontrolledS : Intrinsic.ApplyUncontrolledS + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "S")] + private static extern void S(uint id, uint qubit); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AdjS")] + private static extern void AdjS(uint id, uint qubit); + + private QuantumSimulator Simulator { get; } + + + public QSimApplyUncontrolledS(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func __Body__ => (q1) => + { + Simulator.CheckQubit(q1); + + S(Simulator.Id, (uint)q1.Id); + + return QVoid.Instance; + }; + + public override Func __AdjointBody__ => (q1) => + { + Simulator.CheckQubit(q1); + + AdjS(Simulator.Id, (uint)q1.Id); + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs new file mode 100644 index 00000000000..293e0dd69f3 --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs @@ -0,0 +1,45 @@ +// 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 QSimApplyUncontrolledT : Intrinsic.ApplyUncontrolledT + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "T")] + private static extern void T(uint id, uint qubit); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AdjT")] + private static extern void AdjT(uint id, uint qubit); + + private QuantumSimulator Simulator { get; } + + + public QSimApplyUncontrolledT(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func __Body__ => (q1) => + { + Simulator.CheckQubit(q1); + + T(Simulator.Id, (uint)q1.Id); + return QVoid.Instance; + }; + + public override Func __AdjointBody__ => (q1) => + { + Simulator.CheckQubit(q1); + + AdjT(this.Simulator.Id, (uint)q1.Id); + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs new file mode 100644 index 00000000000..3cb09b9f994 --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs @@ -0,0 +1,35 @@ +// 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 QSimApplyUncontrolledX : Intrinsic.ApplyUncontrolledX + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "X")] + private static extern void X(uint id, uint qubit); + + private QuantumSimulator Simulator { get; } + + + public QSimApplyUncontrolledX(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func __Body__ => (q1) => + { + Simulator.CheckQubit(q1); + + X(Simulator.Id, (uint)q1.Id); + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs new file mode 100644 index 00000000000..cac1131d38d --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs @@ -0,0 +1,35 @@ +// 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 QSimApplyUncontrolledY : Intrinsic.ApplyUncontrolledY + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Y")] + private static extern void Y(uint id, uint qubit); + + private QuantumSimulator Simulator { get; } + + + public QSimApplyUncontrolledY(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func __Body__ => (q1) => + { + Simulator.CheckQubit(q1); + + Y(Simulator.Id, (uint)q1.Id); + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs new file mode 100644 index 00000000000..2dde7c53e3b --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs @@ -0,0 +1,35 @@ +// 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 QSimApplyUncontrolledZ : Intrinsic.ApplyUncontrolledZ + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Z")] + private static extern void Z(uint id, uint qubit); + + private QuantumSimulator Simulator { get; } + + + public QSimApplyUncontrolledZ(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func __Body__ => (q1) => + { + Simulator.CheckQubit(q1); ; + + Z(Simulator.Id, (uint)q1.Id); + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/Simulators/QuantumSimulator/Reset.cs b/src/Simulation/Simulators/QuantumSimulator/Reset.cs new file mode 100644 index 00000000000..9f6d2d6501e --- /dev/null +++ b/src/Simulation/Simulators/QuantumSimulator/Reset.cs @@ -0,0 +1,43 @@ +// 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 QSimReset : Intrinsic.Reset + { + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "X")] + private static extern void X(uint id, uint qubit); + + [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "M")] + private static extern uint M(uint id, uint q); + + private QuantumSimulator Simulator { get; } + + + public QSimReset(QuantumSimulator m) : base(m) + { + this.Simulator = m; + } + + public override Func __Body__ => (q1) => + { + // The native simulator doesn't have a reset operation, so simulate + // it via an M follow by a conditional X. + Simulator.CheckQubit(q1); + var res = M(Simulator.Id, (uint)q1.Id); + if (res == 1) + { + X(Simulator.Id, (uint)q1.Id); + } + + return QVoid.Instance; + }; + } + } +} diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs new file mode 100644 index 00000000000..fa7efcaffca --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the controlled-X (or CNOT) gate to a pair of qubits. Note that the Controlled + /// functor is not supported. + /// + /// # Description + /// \begin{align} + /// \operatorname{CNOT} \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 & 0 & 0 \\\\ + /// 0 & 1 & 0 & 0 \\\\ + /// 0 & 0 & 0 & 1 \\\\ + /// 0 & 0 & 1 & 0 + /// \end{bmatrix}, + /// \end{align} + /// + /// where rows and columns are ordered as in the quantum concepts guide. + /// + /// # Input + /// ## control + /// Control qubit for the CNOT gate. + /// ## target + /// Target qubit for the CNOT gate. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// CNOT(control, target); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX") + operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { + CNOT(control, target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs new file mode 100644 index 00000000000..45a85e98c93 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.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 + /// Applies the controlled-Z (CZ) gate to a pair of qubits. Note that the Controlled + /// functor is not supported. + /// + /// $$ + /// \begin{align} + /// 1 & 0 & 0 & 0 \\\\ + /// 0 & 1 & 0 & 0 \\\\ + /// 0 & 0 & 1 & 0 \\\\ + /// 0 & 0 & 0 & -1 + /// \end{align}, + /// $$ + /// where rows and columns are organized as in the quantum concepts guide. + /// + /// # Input + /// ## control + /// Control qubit for the CZ gate. + /// ## target + /// Target qubit for the CZ gate. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// Controlled Z([control], target); + /// ``` + @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ") + operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { + Controlled Z([control], target); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs new file mode 100644 index 00000000000..d9dca0ca172 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Hadamard transformation to a single qubit. Note that the Controlled + /// functor is not supported. + /// + /// # Description + /// \begin{align} + /// H \mathrel{:=} + /// \frac{1}{\sqrt{2}} + /// \begin{bmatrix} + /// 1 & 1 \\\\ + /// 1 & -1 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledH") + operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { + H(qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs new file mode 100644 index 00000000000..7f306de3c61 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.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 + /// Applies a rotation about the $x$-axis by a given angle. Note that the Controlled + /// functor is not supported. + /// + /// # 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.ApplyUncontrolledRx") + operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { + Rx(theta, qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs new file mode 100644 index 00000000000..f7f6ba15d3c --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.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 + /// Applies a rotation about the $y$-axis by a given angle. Note that the Controlled + /// functor is not supported. + /// + /// # 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.ApplyUncontrolledRy") + operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { + Ry(theta, qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs new file mode 100644 index 00000000000..683e8b09188 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.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 + /// Applies a rotation about the $z$-axis by a given angle. Note that the Controlled + /// functor is not supported. + /// + /// # 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.ApplyUncontrolledRz") + operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { + Rz(theta, qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs new file mode 100644 index 00000000000..659337cd5f5 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the π/4 phase gate to a single qubit. Note that the Controlled functor + /// is not supported. + /// + /// # Description + /// \begin{align} + /// S \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & i + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS") + operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { + S(qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs new file mode 100644 index 00000000000..35eaecf3b3b --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the π/8 gate to a single qubit. Note that the Controlled functor is + /// not supported. + /// + /// # Description + /// \begin{align} + /// T \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & e^{i \pi / 4} + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT") + operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { + T(qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs new file mode 100644 index 00000000000..82b91e5cca4 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Pauli $X$ gate. Note that the Controlled functor is not supported. + /// + /// # Description + /// \begin{align} + /// \sigma_x \mathrel{:=} + /// \begin{bmatrix} + /// 0 & 1 \\\\ + /// 1 & 0 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledX") + operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { + X(qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs new file mode 100644 index 00000000000..6986fafd45a --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Pauli $Y$ gate. Note that the Controlled functor is not supported. + /// + /// # Description + /// \begin{align} + /// \sigma_y \mathrel{:=} + /// \begin{bmatrix} + /// 0 & -i \\\\ + /// i & 0 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledY") + operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { + Y(qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs new file mode 100644 index 00000000000..376ae775245 --- /dev/null +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Intrinsic { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Applies the Pauli $Z$ gate. Note that the Controlled functor is not supported. + /// + /// # Description + /// \begin{align} + /// \sigma_z \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & -1 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. + @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledZ") + operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { + Z(qubit); + } +} \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs index ff638cc18d9..dd07dd4eced 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/HFromSinglyControlled.qs @@ -26,6 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledH(qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); if (Length(ctls) == 0) { ApplyUncontrolledH(qubit); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/Measure.qs b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs index 2baef4da9af..e450a547657 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/Measure.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/Measure.qs @@ -41,6 +41,8 @@ namespace Microsoft.Quantum.Intrinsic { /// operation will fail. @EnableTestingViaName("Test.TargetDefinitions.Measure") operation Measure (bases : Pauli[], qubits : Qubit[]) : Result { + CheckQubitUniqueness(qubits); + if (Length(bases) != Length(qubits)) { fail "Arrays 'bases' and 'qubits' must be of the same length."; } mutable res = One; if( Length(bases) == 1 ) { within { diff --git a/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs index e964eb00297..3ca0d96e0fb 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RxFromSinglyControlled.qs @@ -34,6 +34,8 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledRx(theta, qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); + RotationAngleValidation(theta); if (Length(ctls) == 0) { ApplyUncontrolledRx(theta, qubit); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs index 8f22cf3f781..a3b70b732a2 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RyFromSinglyControlled.qs @@ -34,6 +34,8 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledRy(theta, qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); + RotationAngleValidation(theta); if (Length(ctls) == 0) { ApplyUncontrolledRy(theta, qubit); } @@ -50,7 +52,7 @@ namespace Microsoft.Quantum.Intrinsic { } } adjoint (...) { - Rz(-theta, qubit); + Ry(-theta, qubit); } } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs index 09bfa6aec51..4806f04134e 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/RzFromSinglyControlled.qs @@ -34,6 +34,8 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledRz(theta, qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); + RotationAngleValidation(theta); if (Length(ctls) == 0) { Rz(theta, qubit); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs index 09655566e04..315b3f3b6f7 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/SFromSinglyControlled.qs @@ -25,6 +25,7 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledS(qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); if (Length(ctls) == 0) { ApplyUncontrolledS(qubit); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs index 222ef97d9e1..c4f23981e90 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/TFromSinglyControlled.qs @@ -25,6 +25,7 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledT(qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); if (Length(ctls) == 0) { ApplyUncontrolledT(qubit); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs index e33e1c88263..05fd24f9a3a 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/XFromSinglyControlled.qs @@ -25,6 +25,7 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledX(qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); if (Length(ctls) == 0) { ApplyUncontrolledX(qubit); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs index 7636e127f22..de7c394852b 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/YFromSinglyControlled.qs @@ -25,6 +25,7 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledY(qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); if (Length(ctls) == 0) { ApplyUncontrolledY(qubit); } diff --git a/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs index 146bfc5da6d..cce75a840e5 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ZFromSinglyControlled.qs @@ -25,6 +25,7 @@ namespace Microsoft.Quantum.Intrinsic { ApplyUncontrolledZ(qubit); } controlled (ctls, ...) { + CheckQubitUniqueness(ctls + [qubit]); if (Length(ctls) == 0) { ApplyUncontrolledZ(qubit); } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs index 9242d9c160b..64f1c6039b0 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs @@ -4,9 +4,36 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Controlled X. + /// # Summary + /// Applies the controlled-X (or CNOT) gate to a pair of qubits. Does not support + /// the Controlled functor. + /// + /// # Description + /// \begin{align} + /// \operatorname{CNOT} \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 & 0 & 0 \\\\ + /// 0 & 1 & 0 & 0 \\\\ + /// 0 & 0 & 0 & 1 \\\\ + /// 0 & 0 & 1 & 0 + /// \end{bmatrix}, + /// \end{align} + /// + /// where rows and columns are ordered as in the quantum concepts guide. + /// + /// # Input + /// ## control + /// Control qubit for the CNOT gate. + /// ## target + /// Target qubit for the CNOT gate. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// CNOT(control, target); + /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX") - internal operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { + operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs index 4e134a4790b..6d2e43ba235 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs @@ -4,9 +4,32 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Controlled Z. + /// # Summary + /// Applies the controlled-Z (CZ) gate to a pair of qubits. + /// + /// $$ + /// \begin{align} + /// 1 & 0 & 0 & 0 \\\\ + /// 0 & 1 & 0 & 0 \\\\ + /// 0 & 0 & 1 & 0 \\\\ + /// 0 & 0 & 0 & -1 + /// \end{align}, + /// $$ + /// where rows and columns are organized as in the quantum concepts guide. + /// + /// # Input + /// ## control + /// Control qubit for the CZ gate. + /// ## target + /// Target qubit for the CZ gate. + /// + /// # Remarks + /// Equivalent to: + /// ```qsharp + /// Controlled Z([control], target); + /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ") - internal operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { + operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs index 5e727890d3f..aacc0a20edb 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs @@ -4,9 +4,25 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled H. + /// # Summary + /// Applies the Hadamard transformation to a single qubit. Note that the Controlled + /// functor is not supported. + /// + /// # Description + /// \begin{align} + /// H \mathrel{:=} + /// \frac{1}{\sqrt{2}} + /// \begin{bmatrix} + /// 1 & 1 \\\\ + /// 1 & -1 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledH") - internal operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs index e5605fa07eb..978b6dfc353 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs @@ -4,9 +4,33 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled Rx. + /// # Summary + /// Applies a rotation about the $x$-axis by a given angle. Note that the Controlled + /// functor is not supported. + /// + /// # 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.ApplyUncontrolledRx") - internal operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs index 7563e697610..8eb17ca1019 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs @@ -4,9 +4,33 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled Ry. + /// # Summary + /// Applies a rotation about the $y$-axis by a given angle. Note that the Controlled + /// functor is not supported. + /// + /// # 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.ApplyUncontrolledRy") - internal operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs index b339e179831..16186efa358 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs @@ -4,9 +4,33 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled Rz. + /// # Summary + /// Applies a rotation about the $z$-axis by a given angle. Note that the Controlled + /// functor is not supported. + /// + /// # 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.ApplyUncontrolledRz") - internal operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs index ef8a4099825..720958de15c 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs @@ -4,9 +4,24 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled S. + /// # Summary + /// Applies the π/4 phase gate to a single qubit. Note that the Controlled functor + /// is not supported. + /// + /// # Description + /// \begin{align} + /// S \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & i + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS") - internal operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs index e8359f73cff..6b3748907ca 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs @@ -4,9 +4,24 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled T. + /// # Summary + /// Applies the π/8 gate to a single qubit. Note that the Controlled functor is + /// not supported. + /// + /// # Description + /// \begin{align} + /// T \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & e^{i \pi / 4} + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT") - internal operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs index 92a9a954ac6..1fad799be4c 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs @@ -4,9 +4,23 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled X. + /// # Summary + /// Applies the Pauli $X$ gate. Note that the Controlled functor is not supported. + /// + /// # Description + /// \begin{align} + /// \sigma_x \mathrel{:=} + /// \begin{bmatrix} + /// 0 & 1 \\\\ + /// 1 & 0 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledX") - internal operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs index a7d158b906b..5a119d13be7 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs @@ -4,9 +4,23 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled Y. + /// # Summary + /// Applies the Pauli $Y$ gate. Note that the Controlled functor is not supported. + /// + /// # Description + /// \begin{align} + /// \sigma_y \mathrel{:=} + /// \begin{bmatrix} + /// 0 & -i \\\\ + /// i & 0 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledY") - internal operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs index 4655776eb80..9ec2e2fce51 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs @@ -4,9 +4,23 @@ namespace Microsoft.Quantum.Intrinsic { open Microsoft.Quantum.Diagnostics; - /// Helper for native Uncontrolled Z. + /// # Summary + /// Applies the Pauli $Z$ gate. Note that the Controlled functor is not supported. + /// + /// # Description + /// \begin{align} + /// \sigma_z \mathrel{:=} + /// \begin{bmatrix} + /// 1 & 0 \\\\ + /// 0 & -1 + /// \end{bmatrix}. + /// \end{align} + /// + /// # Input + /// ## qubit + /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledZ") - internal operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { + operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs index 37bcc86889b..6c61789e023 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs @@ -8,11 +8,7 @@ namespace Microsoft.Quantum.Intrinsic { /// 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)`. + /// Will fail if any qubits are repeated or null. /// /// # Input /// ## qubits @@ -29,7 +25,7 @@ namespace Microsoft.Quantum.Intrinsic { /// 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. + /// Validates that the value of the Double representing a rotation angle is neither infinite nor NaN. /// /// # Input /// ## angle diff --git a/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props index bf9a8f3b89c..e75450e2a61 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props @@ -17,6 +17,17 @@ + + + + + + + + + + + diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props index ec6db28ce45..5b3e0d76e97 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props @@ -22,6 +22,17 @@ + + + + + + + + + + + From 6f3c932ab925b29a2120224ee04e61fb09d2fc27 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 4 Sep 2020 15:32:46 -0700 Subject: [PATCH 03/12] Fix solution file --- Simulation.sln | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Simulation.sln b/Simulation.sln index be40121ab66..ef74245467b 100644 --- a/Simulation.sln +++ b/Simulation.sln @@ -87,6 +87,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Simulator EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Microsoft.Quantum.Simulators.Type1", "src\Simulation\Simulators.Type1.Tests\Tests.Microsoft.Quantum.Simulators.Type1.csproj", "{EB6E3DBD-C884-4241-9BC4-8281191D1F53}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Quantum.Type1.Core", "src\Simulation\Type1Core\Microsoft.Quantum.Type1.Core.csproj", "{E1A463D7-2E23-4134-BE04-1EFF7A546813}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -611,6 +613,22 @@ Global {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU {EB6E3DBD-C884-4241-9BC4-8281191D1F53}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|x64.ActiveCfg = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Debug|x64.Build.0 = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|Any CPU.Build.0 = Release|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|x64.ActiveCfg = Release|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.Release|x64.Build.0 = Release|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU + {E1A463D7-2E23-4134-BE04-1EFF7A546813}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -652,6 +670,7 @@ Global {4EF958CA-B4A6-4E5F-924A-100B5615BEC3} = {F5F80AEA-34F4-4E1D-8145-0634E9DCF2C3} {F995209F-FEE1-4083-ABD9-4998563E0070} = {9008B252-2DF7-404B-B626-D4497BB70A05} {EB6E3DBD-C884-4241-9BC4-8281191D1F53} = {9008B252-2DF7-404B-B626-D4497BB70A05} + {E1A463D7-2E23-4134-BE04-1EFF7A546813} = {9008B252-2DF7-404B-B626-D4497BB70A05} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {929C0464-86D8-4F70-8835-0A5EAF930821} From f29879ef69e97de339aeae969ed8c3b6dd46e02a Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 4 Sep 2020 20:32:48 -0700 Subject: [PATCH 04/12] Apply suggestions from code review Co-authored-by: Chris Granade --- .../Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs | 4 ++-- src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs index d6abcc6ed50..ff53abcd677 100644 --- a/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs +++ b/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; @@ -31,4 +31,4 @@ public static void RunWithMultipleSimulators(Action test) } } } -} \ No newline at end of file +} diff --git a/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 index 8a96bf87970..b3d6bc18510 100644 --- a/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 +++ b/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 @@ -1,4 +1,4 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. ######################################## @@ -45,7 +45,7 @@ function Add-PackageReferenceIfNew($ref) $id = [System.IO.Path]::GetFileNameWithoutExtension($id) } - if ($version -eq $null -or $version -eq "") { + if ("$version" -eq "") { $version = '$version$' } From d8772368a7a57213e8328b4b04c1f78226137425 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Fri, 4 Sep 2020 21:08:06 -0700 Subject: [PATCH 05/12] More CR feedback --- .../OperationsTestHelperSimSupport.cs | 15 ++++++++++----- .../OperationsTestHelperSimSupport.cs | 15 ++++++++++----- .../Simulators.Type1/FindNuspecReferences.ps1 | 10 ++++------ .../OperationsTestHelperSimSupport.cs | 15 ++++++++++----- .../Simulators.Type2/FindNuspecReferences.ps1 | 12 +++++------- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs index 477571f7024..e35e7f207a2 100644 --- a/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs +++ b/src/Simulation/Simulators.Tests/OperationsTestHelperSimSupport.cs @@ -27,13 +27,18 @@ public static void RunWithMultipleSimulators(Action test) foreach (var s in simulators) { - InitSimulator(s); + try + { + InitSimulator(s); - test(s); - - if (s is IDisposable sim) + test(s); + } + finally { - sim.Dispose(); + if (s is IDisposable sim) + { + sim.Dispose(); + } } } } diff --git a/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs index ff53abcd677..cce2bfaa09a 100644 --- a/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs +++ b/src/Simulation/Simulators.Type1.Tests/OperationsTestHelperSimSupport.cs @@ -20,13 +20,18 @@ public static void RunWithMultipleSimulators(Action test) foreach (var s in simulators) { - InitSimulator(s); - - test(s); + try + { + InitSimulator(s); - if (s is IDisposable sim) + test(s); + } + finally { - sim.Dispose(); + if (s is IDisposable sim) + { + sim.Dispose(); + } } } } diff --git a/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 index b3d6bc18510..9f0fdbaa3d0 100644 --- a/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 +++ b/src/Simulation/Simulators.Type1/FindNuspecReferences.ps1 @@ -2,6 +2,7 @@ # Licensed under the MIT License. ######################################## +# .Description # 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. @@ -31,8 +32,7 @@ if (Test-Path $target) { $nuspec = [xml](Get-Content (Join-Path $PSScriptRoot "Microsoft.Quantum.Simulators.Type1.nuspec.template")) $dep = $nuspec.CreateElement('dependencies', $nuspec.package.metadata.NamespaceURI) -function Add-PackageReferenceIfNew($ref) -{ +function Add-PackageReferenceIfNew($ref) { # Identify package's id either from "Include" or "Update" attribute: $id = $ref.Include $version = $ref.Version @@ -40,8 +40,7 @@ function Add-PackageReferenceIfNew($ref) if ($id -eq $null -or $id -eq "") { $id = $ref.Update } - if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj')) - { + if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj')) { $id = [System.IO.Path]::GetFileNameWithoutExtension($id) } @@ -60,8 +59,7 @@ function Add-PackageReferenceIfNew($ref) } # Recursively find PackageReferences on all ProjectReferences: -function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) -{ +function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) { Write-Host "`nFinding dependencies for $PathToCsproj" $csproj = [xml](Get-Content $PathToCsproj) diff --git a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs index d6abcc6ed50..b89d8ba181f 100644 --- a/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs +++ b/src/Simulation/Simulators.Type2.Tests/OperationsTestHelperSimSupport.cs @@ -20,13 +20,18 @@ public static void RunWithMultipleSimulators(Action test) foreach (var s in simulators) { - InitSimulator(s); - - test(s); + try + { + InitSimulator(s); - if (s is IDisposable sim) + test(s); + } + finally { - sim.Dispose(); + if (s is IDisposable sim) + { + sim.Dispose(); + } } } } diff --git a/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 b/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 index 3c86d876ef3..80ec6dd6238 100644 --- a/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 +++ b/src/Simulation/Simulators.Type2/FindNuspecReferences.ps1 @@ -1,7 +1,8 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. ######################################## +# .Description # 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. @@ -31,8 +32,7 @@ if (Test-Path $target) { $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) -{ +function Add-PackageReferenceIfNew($ref) { # Identify package's id either from "Include" or "Update" attribute: $id = $ref.Include $version = $ref.Version @@ -40,8 +40,7 @@ function Add-PackageReferenceIfNew($ref) if ($id -eq $null -or $id -eq "") { $id = $ref.Update } - if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj')) - { + if ($id.EndsWith('.csproj') -or $id.EndsWith('.fsproj')) { $id = [System.IO.Path]::GetFileNameWithoutExtension($id) } @@ -60,8 +59,7 @@ function Add-PackageReferenceIfNew($ref) } # Recursively find PackageReferences on all ProjectReferences: -function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) -{ +function Add-NuGetDependencyFromCsprojToNuspec($PathToCsproj) { Write-Host "`nFinding dependencies for $PathToCsproj" $csproj = [xml](Get-Content $PathToCsproj) From e8d73b20aa3167d6fe20eed005c2a03d1e1c42bd Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 8 Sep 2020 15:45:42 -0700 Subject: [PATCH 06/12] Rework added intrinsics to be internal only --- src/Simulation/QsharpCore/Properties/AssemblyInfo.cs | 9 +++++++++ .../QCTraceSimulator/Circuits/Primitive.IsingXX.qs | 2 +- .../QCTraceSimulator/Circuits/Primitive.IsingYY.qs | 2 +- .../QCTraceSimulator/Circuits/Primitive.IsingZZ.qs | 2 +- .../QCTraceSimulator/QCTraceSimulator.Checks.cs | 4 ++-- .../Simulators/QuantumSimulator/ApplyControlledX.cs | 2 +- .../Simulators/QuantumSimulator/ApplyControlledZ.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledH.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledRx.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledRy.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledRz.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledS.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledT.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledX.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledY.cs | 2 +- .../Simulators/QuantumSimulator/ApplyUncontrolledZ.cs | 2 +- src/Simulation/Simulators/QuantumSimulator/Checks.cs | 4 ++-- src/Simulation/Simulators/QuantumSimulator/Extensions.cs | 6 +++++- src/Simulation/Simulators/QuantumSimulator/IsingXX.cs | 2 +- src/Simulation/Simulators/QuantumSimulator/IsingYY.cs | 2 +- src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs | 2 +- .../TargetDefinitions/Decompositions/ApplyControlledX.qs | 2 +- .../TargetDefinitions/Decompositions/ApplyControlledZ.qs | 2 +- .../Decompositions/ApplyUncontrolledH.qs | 2 +- .../Decompositions/ApplyUncontrolledRx.qs | 2 +- .../Decompositions/ApplyUncontrolledRy.qs | 2 +- .../Decompositions/ApplyUncontrolledRz.qs | 2 +- .../Decompositions/ApplyUncontrolledS.qs | 2 +- .../Decompositions/ApplyUncontrolledT.qs | 2 +- .../Decompositions/ApplyUncontrolledX.qs | 2 +- .../Decompositions/ApplyUncontrolledY.qs | 2 +- .../Decompositions/ApplyUncontrolledZ.qs | 2 +- .../TargetDefinitions/Decompositions/IsingXX.qs | 2 +- .../TargetDefinitions/Decompositions/IsingYY.qs | 2 +- .../TargetDefinitions/Decompositions/IsingZZ.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyControlledX.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyControlledZ.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs | 2 +- .../TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs | 2 +- src/Simulation/TargetDefinitions/Intrinsic/Checks.qs | 4 ++-- src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs | 2 +- src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs | 2 +- src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs | 2 +- src/Simulation/Type1Core/Properties/AssemblyInfo.cs | 9 +++++++++ src/Simulation/Type2Core/Properties/AssemblyInfo.cs | 9 +++++++++ 52 files changed, 83 insertions(+), 52 deletions(-) create mode 100644 src/Simulation/QsharpCore/Properties/AssemblyInfo.cs create mode 100644 src/Simulation/Type1Core/Properties/AssemblyInfo.cs create mode 100644 src/Simulation/Type2Core/Properties/AssemblyInfo.cs diff --git a/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs b/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..d0ea7cdcc8a --- /dev/null +++ b/src/Simulation/QsharpCore/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("Microsoft.Quantum.Simulators" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file diff --git a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs index 5f75f95fb02..3a3a2fb9899 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs +++ b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingXX.qs @@ -2,7 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Circuits { - operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { Exp([PauliX, PauliX], theta * 2.0, [qubit0, qubit1]); } } \ No newline at end of file diff --git a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs index 9315f86ef86..78484a19d3d 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs +++ b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingYY.qs @@ -2,7 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Circuits { - operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { Exp([PauliY, PauliY], theta * 2.0, [qubit0, qubit1]); } } \ No newline at end of file diff --git a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs index c6f7a753326..797f7986f71 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs +++ b/src/Simulation/Simulators/QCTraceSimulator/Circuits/Primitive.IsingZZ.qs @@ -2,7 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Circuits { - operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { Exp([PauliZ, PauliZ], theta * 2.0, [qubit0, qubit1]); } } \ No newline at end of file diff --git a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs index cd6b69c4de8..c86ca5d553a 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs +++ b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulator.Checks.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Implementati { public partial class QCTraceSimulatorImpl { - public class QCTracesimulatorImplCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness + internal class QCTracesimulatorImplCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness { public QCTracesimulatorImplCheckQubitUniqueness(QCTraceSimulatorImpl m) : base(m) { @@ -28,7 +28,7 @@ public QCTracesimulatorImplCheckQubitUniqueness(QCTraceSimulatorImpl m) : base(m }; } - public class QCTracesimulatorImplRotationAngleValidation : Intrinsic.RotationAngleValidation + internal class QCTracesimulatorImplRotationAngleValidation : Intrinsic.RotationAngleValidation { public QCTracesimulatorImplRotationAngleValidation(QCTraceSimulatorImpl m) : base(m) { diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs index 78ab94834dd..835f6fa80cb 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledX.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyControlledX : Intrinsic.ApplyControlledX + internal class QSimApplyControlledX : Intrinsic.ApplyControlledX { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCX")] private static extern void MCX(uint id, uint count, uint[] ctrls, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs index 2f76e962107..5bf1b755cab 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyControlledZ.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyControlledZ : Intrinsic.ApplyControlledZ + internal class QSimApplyControlledZ : Intrinsic.ApplyControlledZ { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MCZ")] private static extern void MCZ(uint id, uint count, uint[] ctrls, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs index 79b6d22548e..de3859e9f69 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledH.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyUncontrolledH : Intrinsic.ApplyUncontrolledH + internal class QSimApplyUncontrolledH : Intrinsic.ApplyUncontrolledH { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "H")] private static extern void H(uint id, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs index c2eb72680cc..067f1294654 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRx.cs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators public partial class QuantumSimulator { - public class QSimApplyUncontrolledRx : Intrinsic.ApplyUncontrolledRx + internal class QSimApplyUncontrolledRx : Intrinsic.ApplyUncontrolledRx { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] private static extern void R(uint id, Pauli basis, double angle, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs index 8a5187725ec..25e79b98468 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRy.cs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators public partial class QuantumSimulator { - public class QSimApplyUncontrolledRy : Intrinsic.ApplyUncontrolledRy + internal class QSimApplyUncontrolledRy : Intrinsic.ApplyUncontrolledRy { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] private static extern void R(uint id, Pauli basis, double angle, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs index 55e71e21e45..4b1f3196daf 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledRz.cs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators public partial class QuantumSimulator { - public class QSimApplyUncontrolledRz : Intrinsic.ApplyUncontrolledRz + internal class QSimApplyUncontrolledRz : Intrinsic.ApplyUncontrolledRz { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "R")] private static extern void R(uint id, Pauli basis, double angle, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs index 632e70380bb..19c92deb736 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledS.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyUncontrolledS : Intrinsic.ApplyUncontrolledS + internal class QSimApplyUncontrolledS : Intrinsic.ApplyUncontrolledS { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "S")] private static extern void S(uint id, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs index 293e0dd69f3..94d626d53bb 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledT.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyUncontrolledT : Intrinsic.ApplyUncontrolledT + internal class QSimApplyUncontrolledT : Intrinsic.ApplyUncontrolledT { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "T")] private static extern void T(uint id, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs index 3cb09b9f994..e2f9efa7347 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledX.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyUncontrolledX : Intrinsic.ApplyUncontrolledX + internal class QSimApplyUncontrolledX : Intrinsic.ApplyUncontrolledX { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "X")] private static extern void X(uint id, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs index cac1131d38d..8aa4c4b641e 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledY.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyUncontrolledY : Intrinsic.ApplyUncontrolledY + internal class QSimApplyUncontrolledY : Intrinsic.ApplyUncontrolledY { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Y")] private static extern void Y(uint id, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs index 2dde7c53e3b..e1c55bab5c2 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimApplyUncontrolledZ : Intrinsic.ApplyUncontrolledZ + internal class QSimApplyUncontrolledZ : Intrinsic.ApplyUncontrolledZ { [DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Z")] private static extern void Z(uint id, uint qubit); diff --git a/src/Simulation/Simulators/QuantumSimulator/Checks.cs b/src/Simulation/Simulators/QuantumSimulator/Checks.cs index 544c18ad998..7fef67d5700 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Checks.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Checks.cs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Simulation.Simulators { public partial class QuantumSimulator { - public class QSimCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness + internal class QSimCheckQubitUniqueness : Intrinsic.CheckQubitUniqueness { private QuantumSimulator Simulator { get; } public QSimCheckQubitUniqueness(QuantumSimulator m) : base(m) @@ -31,7 +31,7 @@ public QSimCheckQubitUniqueness(QuantumSimulator m) : base(m) }; } - public class QSimRotationAngleValidation : Intrinsic.RotationAngleValidation + internal class QSimRotationAngleValidation : Intrinsic.RotationAngleValidation { public QSimRotationAngleValidation(QuantumSimulator m) : base(m) { diff --git a/src/Simulation/Simulators/QuantumSimulator/Extensions.cs b/src/Simulation/Simulators/QuantumSimulator/Extensions.cs index d2d098812d0..f3fda609b3f 100644 --- a/src/Simulation/Simulators/QuantumSimulator/Extensions.cs +++ b/src/Simulation/Simulators/QuantumSimulator/Extensions.cs @@ -39,8 +39,12 @@ public static void InitBuiltinOperations(this AbstractFactory factory, Typ InitBuiltinOperations(factory, t.BaseType); + var overrideTypes = t.GetNestedTypes( + System.Reflection.BindingFlags.Public | + System.Reflection.BindingFlags.NonPublic); + var ops = - from op in t.GetNestedTypes() + from op in overrideTypes where op.IsSubclassOf(typeof(T)) select op; diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs index a2822981eb4..16672d025b0 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingXX.cs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators public partial class QuantumSimulator { - public class QSimIsingXX : Intrinsic.IsingXX + internal 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); diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs index a73ea00ff9f..1a22e5a1a62 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingYY.cs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators public partial class QuantumSimulator { - public class QSimIsingYY : Intrinsic.IsingYY + internal 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); diff --git a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs index 20bb062470a..faf9df00312 100644 --- a/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/IsingZZ.cs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.Simulation.Simulators public partial class QuantumSimulator { - public class QSimIsingZZ : Intrinsic.IsingZZ + internal 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); diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs index fa7efcaffca..4bf60fd83dd 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledX.qs @@ -33,7 +33,7 @@ namespace Microsoft.Quantum.Intrinsic { /// CNOT(control, target); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX") - operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { + internal operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { CNOT(control, target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs index 45a85e98c93..70cb2a6d068 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyControlledZ.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Intrinsic { /// Controlled Z([control], target); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ") - operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { + internal operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { Controlled Z([control], target); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs index d9dca0ca172..74a4e5f61fa 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledH.qs @@ -22,7 +22,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledH") - operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { H(qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs index 7f306de3c61..8db8b3733a1 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRx.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliX, theta, qubit); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRx") - operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { Rx(theta, qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs index f7f6ba15d3c..bd72cde1e7e 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRy.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliY, theta, qubit); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRy") - operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { Ry(theta, qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs index 683e8b09188..5c864aae74f 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledRz.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliZ, theta, qubit); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRz") - operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { Rz(theta, qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs index 659337cd5f5..1b64c5e7839 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledS.qs @@ -21,7 +21,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS") - operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { S(qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs index 35eaecf3b3b..60cf1ecd7b8 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledT.qs @@ -21,7 +21,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT") - operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { T(qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs index 82b91e5cca4..08a566bc840 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledX.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledX") - operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { X(qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs index 6986fafd45a..bee6d1fb7b3 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledY.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledY") - operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { Y(qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs index 376ae775245..ffb10e7e364 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/ApplyUncontrolledZ.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledZ") - operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { Z(qubit); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs b/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs index a527a86a634..2c4b93c4ad1 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/IsingXX.qs @@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit1 /// The second qubit input to the gate. @EnableTestingViaName("Test.TargetDefinitions.IsingXX") - operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { Exp([PauliX, PauliX], theta * 2.0, [qubit0, qubit1]); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs b/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs index fe33783729a..51d3a76c929 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/IsingYY.qs @@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit1 /// The second qubit input to the gate. @EnableTestingViaName("Test.TargetDefinitions.IsingYY") - operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { Exp([PauliY, PauliY], theta * 2.0, [qubit0, qubit1]); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs b/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs index 3534019b726..16649bcffd6 100644 --- a/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs +++ b/src/Simulation/TargetDefinitions/Decompositions/IsingZZ.qs @@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit1 /// The second qubit input to the gate. @EnableTestingViaName("Test.TargetDefinitions.IsingZZ") - operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { Exp([PauliZ, PauliZ], theta * 2.0, [qubit0, qubit1]); } } \ No newline at end of file diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs index 64f1c6039b0..0c5417ada18 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledX.qs @@ -33,7 +33,7 @@ namespace Microsoft.Quantum.Intrinsic { /// CNOT(control, target); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledX") - operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { + internal operation ApplyControlledX (control : Qubit, target : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs index 6d2e43ba235..c91154afdab 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyControlledZ.qs @@ -29,7 +29,7 @@ namespace Microsoft.Quantum.Intrinsic { /// Controlled Z([control], target); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyControlledZ") - operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { + internal operation ApplyControlledZ (control : Qubit, target : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs index aacc0a20edb..8b0f82af9c2 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledH.qs @@ -22,7 +22,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledH") - operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledH (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs index 978b6dfc353..215b8014710 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRx.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliX, theta, qubit); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRx") - operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledRx (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs index 8eb17ca1019..7f70a7f60d5 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRy.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliY, theta, qubit); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRy") - operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledRy (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs index 16186efa358..14e5d95a414 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledRz.qs @@ -30,7 +30,7 @@ namespace Microsoft.Quantum.Intrinsic { /// R(PauliZ, theta, qubit); /// ``` @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledRz") - operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledRz (theta : Double, qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs index 720958de15c..530c0e3397b 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledS.qs @@ -21,7 +21,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledS") - operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledS (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs index 6b3748907ca..820b5cb7eda 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledT.qs @@ -21,7 +21,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledT") - operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledT (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs index 1fad799be4c..45a27d9a5f6 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledX.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledX") - operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledX (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs index 5a119d13be7..8e9a2fe20bb 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledY.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledY") - operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledY (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs index 9ec2e2fce51..302252cf68e 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledZ.qs @@ -20,7 +20,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit /// Qubit to which the gate should be applied. @EnableTestingViaName("Test.TargetDefinitions.ApplyUncontrolledZ") - operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { + internal operation ApplyUncontrolledZ (qubit : Qubit) : Unit is Adj { body intrinsic; adjoint self; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs index 6c61789e023..3f772bb6819 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/Checks.qs @@ -15,7 +15,7 @@ namespace Microsoft.Quantum.Intrinsic { /// 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{ + internal operation CheckQubitUniqueness (qubits : Qubit[]) : Unit is Adj + Ctl{ body intrinsic; adjoint self; } @@ -31,7 +31,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## angle /// The Double to validate. @EnableTestingViaName("Test.TargetDefinitions.RotationAngleValidation") - function RotationAngleValidation (angle : Double) : Unit { + internal function RotationAngleValidation (angle : Double) : Unit { body intrinsic; } diff --git a/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs index 51a88e4ac9a..c20f4c56731 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingXX.qs @@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit1 /// The second qubit input to the gate. @EnableTestingViaName("Test.TargetDefinitions.IsingXX") - operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingXX (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + 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 index 03e1e7b7fa2..39fe3a24ff5 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingYY.qs @@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit1 /// The second qubit input to the gate. @EnableTestingViaName("Test.TargetDefinitions.IsingYY") - operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingYY (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + 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 index ae5c0f86ec7..c800c2b92f2 100644 --- a/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs +++ b/src/Simulation/TargetDefinitions/Intrinsic/IsingZZ.qs @@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic { /// ## qubit1 /// The second qubit input to the gate. @EnableTestingViaName("Test.TargetDefinitions.IsingZZ") - operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { + internal operation IsingZZ (theta : Double, qubit0 : Qubit, qubit1 : Qubit) : Unit is Adj + Ctl { body intrinsic; } } \ No newline at end of file diff --git a/src/Simulation/Type1Core/Properties/AssemblyInfo.cs b/src/Simulation/Type1Core/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..01e1c4fd4ae --- /dev/null +++ b/src/Simulation/Type1Core/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("Microsoft.Quantum.Simulators.Type1" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file diff --git a/src/Simulation/Type2Core/Properties/AssemblyInfo.cs b/src/Simulation/Type2Core/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..5767632e578 --- /dev/null +++ b/src/Simulation/Type2Core/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("Microsoft.Quantum.Simulators.Type2" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file From 703a8b97f875294bc2e61d3a6f9efac3ec6de45e Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Thu, 10 Sep 2020 20:23:45 -0700 Subject: [PATCH 07/12] Cleaning up config and assembly info files --- src/Simulation/Core/Properties/AssemblyInfo.cs | 1 - src/Simulation/QsharpCore/Properties/AssemblyInfo.cs | 2 +- src/Simulation/Simulators.Tests/App.config | 5 ++++- src/Simulation/Simulators.Type1.Tests/App.config | 5 ++++- src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs | 2 +- src/Simulation/Simulators.Type2.Tests/App.config | 5 ++++- src/Simulation/Type1Core/Properties/AssemblyInfo.cs | 2 +- src/Simulation/Type2Core/Properties/AssemblyInfo.cs | 2 +- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Simulation/Core/Properties/AssemblyInfo.cs b/src/Simulation/Core/Properties/AssemblyInfo.cs index 4ecfaf27ed6..c2a5d12dced 100644 --- a/src/Simulation/Core/Properties/AssemblyInfo.cs +++ b/src/Simulation/Core/Properties/AssemblyInfo.cs @@ -7,4 +7,3 @@ // 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/Properties/AssemblyInfo.cs b/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs index d0ea7cdcc8a..109c9a91f80 100644 --- a/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs +++ b/src/Simulation/QsharpCore/Properties/AssemblyInfo.cs @@ -5,5 +5,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// Allow the test assembly to use our internal methods +// Allow the simulator assembly to use our internal methods [assembly: InternalsVisibleTo("Microsoft.Quantum.Simulators" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file diff --git a/src/Simulation/Simulators.Tests/App.config b/src/Simulation/Simulators.Tests/App.config index 94ce1a2b94f..b65f2762470 100644 --- a/src/Simulation/Simulators.Tests/App.config +++ b/src/Simulation/Simulators.Tests/App.config @@ -3,4 +3,7 @@ - + + + + diff --git a/src/Simulation/Simulators.Type1.Tests/App.config b/src/Simulation/Simulators.Type1.Tests/App.config index 94ce1a2b94f..b65f2762470 100644 --- a/src/Simulation/Simulators.Type1.Tests/App.config +++ b/src/Simulation/Simulators.Type1.Tests/App.config @@ -3,4 +3,7 @@ - + + + + diff --git a/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs b/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs index ed47130ca02..358c7c8bacf 100644 --- a/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs +++ b/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs @@ -5,5 +5,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// Allow the test assembly to use our internal methods +// Allow the simulator assembly to use our internal methods [assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators.Type1" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file diff --git a/src/Simulation/Simulators.Type2.Tests/App.config b/src/Simulation/Simulators.Type2.Tests/App.config index 94ce1a2b94f..b65f2762470 100644 --- a/src/Simulation/Simulators.Type2.Tests/App.config +++ b/src/Simulation/Simulators.Type2.Tests/App.config @@ -3,4 +3,7 @@ - + + + + diff --git a/src/Simulation/Type1Core/Properties/AssemblyInfo.cs b/src/Simulation/Type1Core/Properties/AssemblyInfo.cs index 01e1c4fd4ae..0420d9b3e57 100644 --- a/src/Simulation/Type1Core/Properties/AssemblyInfo.cs +++ b/src/Simulation/Type1Core/Properties/AssemblyInfo.cs @@ -5,5 +5,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// Allow the test assembly to use our internal methods +// Allow the simulator assembly to use our internal methods [assembly: InternalsVisibleTo("Microsoft.Quantum.Simulators.Type1" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file diff --git a/src/Simulation/Type2Core/Properties/AssemblyInfo.cs b/src/Simulation/Type2Core/Properties/AssemblyInfo.cs index 5767632e578..39993b2efbb 100644 --- a/src/Simulation/Type2Core/Properties/AssemblyInfo.cs +++ b/src/Simulation/Type2Core/Properties/AssemblyInfo.cs @@ -5,5 +5,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// Allow the test assembly to use our internal methods +// Allow the simulator assembly to use our internal methods [assembly: InternalsVisibleTo("Microsoft.Quantum.Simulators.Type2" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file From 0bc266b67a232effce8dc0f0ff1c6db1e29bb659 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 16 Sep 2020 11:03:01 -0700 Subject: [PATCH 08/12] Refactoring the csproj and props files --- AdvantageBenchmark/privateBuild/host.csproj | 4 ++ src/Simulation/Common/Simulators.Dev.props | 3 -- src/Simulation/Common/Simulators.Impl.props | 53 +++++++++++++++++++ src/Simulation/Common/Simulators.Test.props | 49 +++++++++++++++++ .../Common/Simulators.Type1.Dev.props | 42 --------------- .../Common/Simulators.Type2.Dev.props | 42 --------------- ....Simulation.QCTraceSimulatorRuntime.csproj | 1 + .../Microsoft.Quantum.Simulators.csproj | 41 ++------------ .../Tests.Microsoft.Quantum.Simulators.csproj | 39 +------------- ....Microsoft.Quantum.Simulators.Type1.csproj | 39 +------------- .../Microsoft.Quantum.Simulators.Type1.csproj | 37 +------------ ....Microsoft.Quantum.Simulators.Type2.csproj | 39 +------------- .../Microsoft.Quantum.Simulators.Type2.csproj | 37 +------------ 13 files changed, 120 insertions(+), 306 deletions(-) create mode 100644 src/Simulation/Common/Simulators.Impl.props create mode 100644 src/Simulation/Common/Simulators.Test.props delete mode 100644 src/Simulation/Common/Simulators.Type1.Dev.props delete mode 100644 src/Simulation/Common/Simulators.Type2.Dev.props diff --git a/AdvantageBenchmark/privateBuild/host.csproj b/AdvantageBenchmark/privateBuild/host.csproj index 73723279d53..9eac18bfca4 100644 --- a/AdvantageBenchmark/privateBuild/host.csproj +++ b/AdvantageBenchmark/privateBuild/host.csproj @@ -8,4 +8,8 @@ false + + + + diff --git a/src/Simulation/Common/Simulators.Dev.props b/src/Simulation/Common/Simulators.Dev.props index ee61a11c722..80151763c82 100644 --- a/src/Simulation/Common/Simulators.Dev.props +++ b/src/Simulation/Common/Simulators.Dev.props @@ -20,10 +20,7 @@ - - - diff --git a/src/Simulation/Common/Simulators.Impl.props b/src/Simulation/Common/Simulators.Impl.props new file mode 100644 index 00000000000..8c1e60b1926 --- /dev/null +++ b/src/Simulation/Common/Simulators.Impl.props @@ -0,0 +1,53 @@ + + + + + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\)) + + + + + + + + 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/Common/Simulators.Test.props b/src/Simulation/Common/Simulators.Test.props new file mode 100644 index 00000000000..420b011a88c --- /dev/null +++ b/src/Simulation/Common/Simulators.Test.props @@ -0,0 +1,49 @@ + + + + + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\)) + + + + + + + + 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/Common/Simulators.Type1.Dev.props b/src/Simulation/Common/Simulators.Type1.Dev.props deleted file mode 100644 index 7016572f718..00000000000 --- a/src/Simulation/Common/Simulators.Type1.Dev.props +++ /dev/null @@ -1,42 +0,0 @@ - - - - - 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/Common/Simulators.Type2.Dev.props b/src/Simulation/Common/Simulators.Type2.Dev.props deleted file mode 100644 index ce27923c3fd..00000000000 --- a/src/Simulation/Common/Simulators.Type2.Dev.props +++ /dev/null @@ -1,42 +0,0 @@ - - - - - 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/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj index ba121246d35..9b472054974 100644 --- a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj +++ b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj index e8f9263ae20..8226d6b2192 100644 --- a/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Core/Microsoft.Quantum.Simulators.csproj @@ -1,23 +1,9 @@  - - - - - - netstandard2.1 - false - false - - - - 8.0 - enable - + - @@ -25,29 +11,8 @@ - - - - - - - - - - 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.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj index 6fa960aef8f..ca30761a396 100644 --- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj @@ -1,15 +1,6 @@  - - - - - - netcoreapp3.1 - false - false - false - + @@ -18,8 +9,7 @@ - - + false @@ -28,31 +18,6 @@ - - - - - - - - - - - - - <_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\ - <_TargetedExeDir>$(MSBuildThisFileDirectory)TestProjects\TargetedExe\built\ - - - <_ExeFiles Include="$(_ExeDir)*" /> - <_TargetedExeFiles Include="$(_TargetedExeDir)*" /> - - - - - - - diff --git a/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj b/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj index f9e6b67ad9a..5c0863c42af 100644 --- a/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj +++ b/src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj @@ -1,23 +1,9 @@  - - - - - - netcoreapp3.1 - false - false - false - - - - - - + - + @@ -31,27 +17,6 @@ - - - - - - - - - <_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\ - <_TargetedExeDir>$(MSBuildThisFileDirectory)TestProjects\TargetedExe\built\ - - - <_ExeFiles Include="$(_ExeDir)*" /> - <_TargetedExeFiles Include="$(_TargetedExeDir)*" /> - - - - - - - diff --git a/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj index feb0ac3ee45..d9cec682ccc 100644 --- a/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj +++ b/src/Simulation/Simulators.Type1/Microsoft.Quantum.Simulators.Type1.csproj @@ -1,42 +1,9 @@  - - - - - - netstandard2.1 - - - - 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.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj index adf546c4aab..90dc3a3bc22 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 @@ -1,23 +1,9 @@  - - - - - - netcoreapp3.1 - false - false - false - - - - - - + - + @@ -31,27 +17,6 @@ - - - - - - - - - <_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\ - <_TargetedExeDir>$(MSBuildThisFileDirectory)TestProjects\TargetedExe\built\ - - - <_ExeFiles Include="$(_ExeDir)*" /> - <_TargetedExeFiles Include="$(_TargetedExeDir)*" /> - - - - - - - diff --git a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj index a10fef46f36..3fb63e0fb7d 100644 --- a/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj +++ b/src/Simulation/Simulators.Type2/Microsoft.Quantum.Simulators.Type2.csproj @@ -1,42 +1,9 @@  - - - - - - netstandard2.1 - - - - 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 - + From 3f08cfc0a4bea36e19b9982c2132f6b0dcc3a6c8 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 16 Sep 2020 20:06:20 -0700 Subject: [PATCH 09/12] Reworking core package props --- .../Microsoft.Quantum.QSharp.Core.csproj | 39 +--------------- .../TargetPackages/Common.Package.props | 44 +++++++++++++++++++ .../TargetPackages/QsharpCore.Package.props | 2 + .../TargetPackages/Type1.Package.props | 2 + .../TargetPackages/Type2.Package.props | 2 + .../Microsoft.Quantum.Type1.Core.csproj | 39 +--------------- .../Microsoft.Quantum.Type2.Core.csproj | 39 +--------------- 7 files changed, 53 insertions(+), 114 deletions(-) create mode 100644 src/Simulation/TargetDefinitions/TargetPackages/Common.Package.props diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index 472d183c70a..d8c9fcea638 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -1,47 +1,10 @@  - - - - netstandard2.1 - true - false - false - - - - Microsoft Core 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 - + - - - - - - - - - - - - - - - - - - - - diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Common.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Common.Package.props new file mode 100644 index 00000000000..a53c8f9abbe --- /dev/null +++ b/src/Simulation/TargetDefinitions/TargetPackages/Common.Package.props @@ -0,0 +1,44 @@ + + + + + + + + netstandard2.1 + true + false + false + + + + Microsoft + See: https://docs.microsoft.com/en-us/quantum/relnotes/ + MIT + https://github.com/microsoft/qsharp-runtime + qdk-nuget-icon.png + Quantum Q# Qsharp + true + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props index e75450e2a61..1cd2cc765e2 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/QsharpCore.Package.props @@ -1,6 +1,8 @@ + + diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props index 73bf1e40315..f6bbf7afc2e 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type1.Package.props @@ -1,6 +1,8 @@ + + diff --git a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props index 5b3e0d76e97..dcd2ce6ca94 100644 --- a/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props +++ b/src/Simulation/TargetDefinitions/TargetPackages/Type2.Package.props @@ -1,6 +1,8 @@ + + diff --git a/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj index f4f68b9383f..b10dbda60de 100644 --- a/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj +++ b/src/Simulation/Type1Core/Microsoft.Quantum.Type1.Core.csproj @@ -1,47 +1,10 @@  - - - - netstandard2.1 - true - false - false - - - - Microsoft Type1 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 - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj index c4bff35d9b4..487b58c4c69 100644 --- a/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj +++ b/src/Simulation/Type2Core/Microsoft.Quantum.Type2.Core.csproj @@ -1,47 +1,10 @@  - - - - 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 3f4c2d38ad5882173d1193a275ecedccb55f9b07 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 16 Sep 2020 21:23:58 -0700 Subject: [PATCH 10/12] Fixing bug in exe project references. --- src/Simulation/Common/Simulators.Impl.props | 6 ++--- src/Simulation/Common/Simulators.Test.props | 25 ++++--------------- .../Tests.Microsoft.Quantum.Simulators.csproj | 15 +++++++++++ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Simulation/Common/Simulators.Impl.props b/src/Simulation/Common/Simulators.Impl.props index 8c1e60b1926..07f50298499 100644 --- a/src/Simulation/Common/Simulators.Impl.props +++ b/src/Simulation/Common/Simulators.Impl.props @@ -5,9 +5,9 @@ $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\)) - - - + + + netstandard2.1 diff --git a/src/Simulation/Common/Simulators.Test.props b/src/Simulation/Common/Simulators.Test.props index 420b011a88c..6e2cf7b766f 100644 --- a/src/Simulation/Common/Simulators.Test.props +++ b/src/Simulation/Common/Simulators.Test.props @@ -5,9 +5,9 @@ $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory)..\..\..\)) - - - + + + netcoreapp3.1 @@ -21,7 +21,7 @@ - + @@ -29,21 +29,6 @@ - - - - - <_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\ - <_TargetedExeDir>$(MSBuildThisFileDirectory)TestProjects\TargetedExe\built\ - - - <_ExeFiles Include="$(_ExeDir)*" /> - <_TargetedExeFiles Include="$(_TargetedExeDir)*" /> - - - - - - + diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj index ca30761a396..9a97d67614a 100644 --- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj @@ -18,6 +18,21 @@ + + + <_ExeDir>$(MSBuildThisFileDirectory)TestProjects\QsharpExe\built\ + <_TargetedExeDir>$(MSBuildThisFileDirectory)TestProjects\TargetedExe\built\ + + + <_ExeFiles Include="$(_ExeDir)*" /> + <_TargetedExeFiles Include="$(_TargetedExeDir)*" /> + + + + + + + From e84a020a6b875f06970c9408625189cc130167c4 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Mon, 21 Sep 2020 09:40:57 -0700 Subject: [PATCH 11/12] Update src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs Co-authored-by: Sarah Marshall <33814365+samarsha@users.noreply.github.com> --- .../Simulators/QuantumSimulator/ApplyUncontrolledZ.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs index e1c55bab5c2..1dc626a959b 100644 --- a/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs +++ b/src/Simulation/Simulators/QuantumSimulator/ApplyUncontrolledZ.cs @@ -24,7 +24,7 @@ public QSimApplyUncontrolledZ(QuantumSimulator m) : base(m) public override Func __Body__ => (q1) => { - Simulator.CheckQubit(q1); ; + Simulator.CheckQubit(q1); Z(Simulator.Id, (uint)q1.Id); From ce9ceb4ff42524e4122291f89047a9a6c3dd55e2 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Mon, 21 Sep 2020 10:08:53 -0700 Subject: [PATCH 12/12] Fixing typo --- src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs b/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs index 358c7c8bacf..ed47130ca02 100644 --- a/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs +++ b/src/Simulation/Simulators.Type1/Properties/AssemblyInfo.cs @@ -5,5 +5,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// Allow the simulator assembly to use our internal methods +// Allow the test assembly to use our internal methods [assembly: InternalsVisibleTo("Tests.Microsoft.Quantum.Simulators.Type1" + SigningConstants.PUBLIC_KEY)] \ No newline at end of file