From 551acb8c6c7e6246b1a98db17488144e2709ec8b Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Tue, 3 Dec 2019 10:04:10 -0800 Subject: [PATCH 01/17] Clarify the restriction on the number of bits for IntAsBoolArray (#171) * Clarify the restriction on the number of bits for IntAsBoolArray This should fix #166 by providing a more specific error message. * Update Standard/src/Convert/Convert.qs Co-Authored-By: Chris Granade * Allow to have bits = 0 Looks like our tests assume that number = 0 with bits = 0 is a valid scenario; updating the change to account for that --- Standard/src/Convert/Convert.qs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Standard/src/Convert/Convert.qs b/Standard/src/Convert/Convert.qs index b69b24bd51d..85a89b88367 100644 --- a/Standard/src/Convert/Convert.qs +++ b/Standard/src/Convert/Convert.qs @@ -76,8 +76,10 @@ namespace Microsoft.Quantum.Convert { /// An array of boolean values representing `number`. /// /// # Remarks - /// The input `number` must be at most $2^{\texttt{bits}} - 1$. + /// The input `bits` must be between 0 and 63. + /// The input `number` must be between 0 and $2^{\texttt{bits}} - 1$. function IntAsBoolArray(number : Int, bits : Int) : Bool[] { + Fact(bits >= 0 and bits <= 63, $"`bits` must be between 0 and 63 {2^bits}"); EqualityFactB(number >= 0 and number < 2 ^ bits, true, $"`number` must be between 0 and 2^`bits` - 1"); mutable outputBits = new Bool[bits]; mutable tempInt = number; From d746df20ce7e3673b4c4e7fb66a0e6baa447d5a6 Mon Sep 17 00:00:00 2001 From: bettinaheim <34236215+bettinaheim@users.noreply.github.com> Date: Thu, 12 Dec 2019 20:27:22 -0800 Subject: [PATCH 02/17] Package updates (#188) --- Chemistry/src/DataModel/DataModel.csproj | 8 ++++---- Chemistry/src/Jupyter/Jupyter.csproj | 8 ++++---- Chemistry/src/Runtime/Runtime.csproj | 2 +- Chemistry/tests/ChemistryTests/QSharpTests.csproj | 13 ++++++++----- Chemistry/tests/DataModelTests/CSharpTests.csproj | 15 +++++++++------ Chemistry/tests/JupyterTests/JupyterTests.csproj | 9 ++++++--- Chemistry/tests/SamplesTests/SamplesTests.csproj | 15 +++++++++------ .../SerializationTests/SerializationTests.csproj | 11 +++++++---- Chemistry/tests/SystemTests/SystemTests.csproj | 13 ++++++++----- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 13 ++++++++----- Standard/src/Standard.csproj | 7 ++----- Standard/tests/Standard.Tests.csproj | 10 +++++----- 13 files changed, 73 insertions(+), 55 deletions(-) diff --git a/Chemistry/src/DataModel/DataModel.csproj b/Chemistry/src/DataModel/DataModel.csproj index 14086f84be6..6c787137998 100644 --- a/Chemistry/src/DataModel/DataModel.csproj +++ b/Chemistry/src/DataModel/DataModel.csproj @@ -35,9 +35,9 @@ - - - + + + @@ -53,6 +53,6 @@ - + diff --git a/Chemistry/src/Jupyter/Jupyter.csproj b/Chemistry/src/Jupyter/Jupyter.csproj index 57c676d8836..da3e74cc8e6 100644 --- a/Chemistry/src/Jupyter/Jupyter.csproj +++ b/Chemistry/src/Jupyter/Jupyter.csproj @@ -26,9 +26,9 @@ - - - + + + @@ -38,6 +38,6 @@ - + diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index 442a13d14c9..2dfbcf8f9c0 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -15,7 +15,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index 66e2888e2c0..573b654a2b9 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -10,11 +10,14 @@ - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Chemistry/tests/DataModelTests/CSharpTests.csproj b/Chemistry/tests/DataModelTests/CSharpTests.csproj index 9c3df4a3cce..f8af284a8e0 100644 --- a/Chemistry/tests/DataModelTests/CSharpTests.csproj +++ b/Chemistry/tests/DataModelTests/CSharpTests.csproj @@ -23,12 +23,15 @@ - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Chemistry/tests/JupyterTests/JupyterTests.csproj b/Chemistry/tests/JupyterTests/JupyterTests.csproj index 4b322d832da..bb21b47bf52 100644 --- a/Chemistry/tests/JupyterTests/JupyterTests.csproj +++ b/Chemistry/tests/JupyterTests/JupyterTests.csproj @@ -17,10 +17,13 @@ - + - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Chemistry/tests/SamplesTests/SamplesTests.csproj b/Chemistry/tests/SamplesTests/SamplesTests.csproj index af9581bbb83..cdbfc4688ae 100644 --- a/Chemistry/tests/SamplesTests/SamplesTests.csproj +++ b/Chemistry/tests/SamplesTests/SamplesTests.csproj @@ -17,12 +17,15 @@ - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Chemistry/tests/SerializationTests/SerializationTests.csproj b/Chemistry/tests/SerializationTests/SerializationTests.csproj index daab1c45c20..ff8ea481ff9 100644 --- a/Chemistry/tests/SerializationTests/SerializationTests.csproj +++ b/Chemistry/tests/SerializationTests/SerializationTests.csproj @@ -16,10 +16,13 @@ - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index 0da8e8b4d71..f5970bf9457 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -17,11 +17,14 @@ - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index fe72ffe01c3..53c33d5ee9c 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -30,10 +30,10 @@ - + - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index 3f1f62f3317..e8c9b86e785 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -15,11 +15,14 @@ - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index f32f4c1fdf1..5a44aad43cb 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -30,10 +30,7 @@ - - - - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index 771ff3c378a..0be3d1c80a1 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -20,11 +20,11 @@ - - - - - + + + + + From 6c9561ac8143b5b2b1790b2525c2a8071afc90ff Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 19 Dec 2019 02:47:55 +0100 Subject: [PATCH 03/17] Quantum AND gates (a.k.a. CCNOT with constant target) (#186) * Two AND gate implementations. * Added test case. * Formatting. * Code formatting. * Update Standard/src/Canon/And.qs Co-Authored-By: Chris Granade * Assertion for 0-target. * Added DOI to references. * Named application for CCNOTop. * Rename operations. * Add Test attribute. * Add links to arXiv. * Rename operations. * Better assertion for 0-target. * Fix bug in LowDepthAnd. * Docs. * Doc string convention. * Controlled variant for `ApplyAnd`. * Controlled AndLowDepth. * Adjoint Controlled LowDepthAnd. * References. * Simplify code. * Apply suggestions from code review Co-Authored-By: Chris Granade * Integrate comment. --- Standard/src/Canon/And.qs | 367 ++++++++++++++++++ .../Canon/Combinators/ApplyMultiControlled.qs | 6 +- Standard/tests/ANDTests.qs | 73 ++++ 3 files changed, 443 insertions(+), 3 deletions(-) create mode 100644 Standard/src/Canon/And.qs create mode 100644 Standard/tests/ANDTests.qs diff --git a/Standard/src/Canon/And.qs b/Standard/src/Canon/And.qs new file mode 100644 index 00000000000..c1c3eec25d2 --- /dev/null +++ b/Standard/src/Canon/And.qs @@ -0,0 +1,367 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Canon { + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Measurement; + + /// # Summary + /// Inverts a given target qubit if and only if both control qubits are in the 1 state, + /// using measurement to perform the adjoint operation. + /// + /// # Description + /// Inverts `target` if and only if both controls are 1, but assumes that + /// `target` is in state 0. The operation has T-count 4, T-depth 2 and + /// requires no helper qubit, and may therefore be preferable to a CCNOT + /// operation, if `target` is known to be 0. The adjoint of this operation + /// is measurement based and requires no T gates. + /// + /// The controlled application of this operation requires no helper qubit, + /// `2^c` `Rz` gates and is not optimized for depth, where `c` is the number + /// of overall control qubits including the two controls from the `ApplyAnd` + /// operation. The adjoint controlled application requires `2^c - 1` `Rz` + /// gates (with an angle twice the size of the non-adjoint operation), no + /// helper qubit and is not optimized for depth. + /// + /// # Input + /// ## control1 + /// First control qubit + /// ## control2 + /// Second control qubit + /// ## target + /// Target auxillary qubit; must be in state 0 + /// + /// # References + /// - Cody Jones: "Novel constructions for the fault-tolerant Toffoli gate", + /// Phys. Rev. A 87, 022328, 2013 + /// [arXiv:1212.5069](https://arxiv.org/abs/1212.5069) + /// doi:10.1103/PhysRevA.87.022328 + /// - Craig Gidney: "Halving the cost of quantum addition", Quantum 2, page + /// 74, 2018 + /// [arXiv:1709.06648](https://arxiv.org/abs/1709.06648) + /// doi:10.1103/PhysRevA.85.044302 + /// - Mathias Soeken: "Quantum Oracle Circuits and the Christmas Tree Pattern", + /// [Blog article from Decemer 19, 2019](https://msoeken.github.io/blog_qac.html) + /// (note: explains the multiple controlled construction) + operation ApplyAnd(control1 : Qubit, control2 : Qubit, target : Qubit) : Unit { + body (...) { + AssertAllZero([target]); + H(target); + T(target); + CNOT(control1, target); + CNOT(control2, target); + within { + CNOT(target, control1); + CNOT(target, control2); + } + apply { + Adjoint T(control1); + Adjoint T(control2); + T(target); + } + HY(target); + } + adjoint (...) { + H(target); + AssertProb([PauliZ], [target], One, 0.5, "Probability of the measurement must be 0.5", 1e-10); + if (IsResultOne(MResetZ(target))) { + CZ(control1, control2); + } + } + controlled (controls, ...) { + _ApplyMultipleControlledAnd(controls + [control1, control2], target); + } + adjoint controlled (controls, ...) { + Adjoint _ApplyMultipleControlledAnd(controls + [control1, control2], target); + } + } + + /// # Summary + /// Inverts a given target qubit if and only if both control qubits are in + /// the 1 state, with T-depth 1, using measurement to perform the adjoint + /// operation. + /// + /// # Description + /// Inverts `target` if and only if both controls are 1, but assumes that + /// `target` is in state 0. The operation has T-count 4, T-depth 1 and + /// requires one helper qubit, and may therefore be preferable to a CCNOT + /// operation, if `target` is known to be 0. The adjoint of this operation + /// is measurement based and requires no T gates, and no helper qubit. + /// + /// # Input + /// ## control1 + /// First control qubit + /// ## control2 + /// Second control qubit + /// ## target + /// Target auxillary qubit; must be in state 0 + /// + /// # References + /// - Cody Jones: "Novel constructions for the fault-tolerant Toffoli gate", + /// Phys. Rev. A 87, 022328, 2013 + /// [arXiv:1212.5069](https://arxiv.org/abs/1212.5069) + /// doi:10.1103/PhysRevA.87.022328 + /// - Peter Selinger: "Quantum circuits of T-depth one", + /// Phys. Rev. A 87, 042302, 2013 + /// [arXiv:1210.0974](https://arxiv.org/abs/1210.0974) + /// doi:10.1103/PhysRevA.87.042302 + operation ApplyLowDepthAnd(control1 : Qubit, control2 : Qubit, target : Qubit) : Unit { + body (...) { + using (helper = Qubit()) { + AssertAllZero([target]); + H(target); + within { + CNOT(target, control1); + CNOT(control1, helper); + CNOT(control2, helper); + CNOT(target, control2); + } + apply { + Adjoint T(control1); + Adjoint T(control2); + T(target); + T(helper); + } + HY(target); + } + } + adjoint (...) { + Adjoint ApplyAnd(control1, control2, target); + } + controlled (controls, ...) { + _ApplyMultipleControlledLowDepthAnd(controls + [control1, control2], target); + } + adjoint controlled (controls, ...) { + Adjoint _ApplyMultipleControlledLowDepthAnd(controls + [control1, control2], target); + } + } + + /// # Summary + /// Creates Gray code sequences + /// + /// # Input + /// ## n + /// Number of bits + /// + /// # Output + /// Array of tuples. First value in tuple is value in GrayCode sequence + /// Second value in tuple is position to change in current value to get + /// next one. + /// + /// # Example + /// ```Q# + /// _GrayCode(2); // [(0, 0),(1, 1),(3, 0),(2, 1)] + /// ``` + function _GrayCode(n : Int) : (Int, Int)[] { + let N = 1 <<< n; + + mutable res = new (Int, Int)[N]; + mutable j = 0; + mutable current = IntAsBoolArray(0, n); + + for (i in 0..N - 1) { + if (i % 2 == 0) { + set j = 0; + } else { + let e = Zip(current, RangeAsIntArray(0..N - 1)); + set j = Snd(Head(Filtered(Fst, e))) + 1; + } + + set j = MaxI(0, Min([j, n - 1])); + set res w/= i <- (BoolArrayAsInt(current), j); + if (j < n) { + set current w/= j <- not current[j]; + } + } + + return res; + } + + /// # Summary + /// Computes the Hamming weight of an integer, i.e., the number of 1s in its + /// binary expansion. + /// + /// # Input + /// ## number + /// Number to compute Hamming weight + /// # Output + /// Hamming weight of the number + function _HammingWeightI(number : Int) : Int { + mutable cnt = number; + set cnt = (cnt &&& 0x5555555555555555) + ((cnt >>> 1) &&& 0x5555555555555555); + set cnt = (cnt &&& 0x3333333333333333) + ((cnt >>> 2) &&& 0x3333333333333333); + set cnt = (cnt &&& 0x0f0f0f0f0f0f0f0f) + ((cnt >>> 4) &&& 0x0f0f0f0f0f0f0f0f); + set cnt = (cnt &&& 0x00ff00ff00ff00ff) + ((cnt >>> 8) &&& 0x00ff00ff00ff00ff); + set cnt = (cnt &&& 0x0000ffff0000ffff) + ((cnt >>> 16) &&& 0x0000ffff0000ffff); + set cnt = (cnt &&& 0x00000000ffffffff) + ((cnt >>> 32) &&& 0x00000000ffffffff); + return cnt; + } + + /// # Summary + /// Returns 1, if `index` has an odd number of 1s and -1, if `index` has an + /// even number of 1s. + /// + /// # Description + /// Value corresponds to the sign of the coefficient of the Rademacher-Walsh + /// spectrum of the n-variable AND function for a given assignment that + /// decides the angle of the rotation. + /// + /// # Input + /// ## index + /// Input assignment as integer (from 0 to 2^n - 1) + function _Angle(index : Int) : Int { + return _HammingWeightI(index) % 2 == 1 ? 1 | -1; + } + + /// # Summary + /// Implements a multiple-controlled Toffoli gate, assuming that target + /// qubit is initialized 0. The adjoint operation assumes that the target + /// qubit will be released to 0. + /// + /// # Input + /// ## controls + /// Control qubits + /// ## target + /// Target qubit + operation _ApplyMultipleControlledAnd(controls : Qubit[], target : Qubit) : Unit { + body (...) { + let vars = Length(controls); + + AssertAllZero([target]); + + H(target); + + let code = _GrayCode(vars); + for (j in 0..Length(code) - 1) { + let (offset, ctrl) = code[j]; + RFrac(PauliZ, _Angle(offset), vars + 1, target); + CNOT(controls[ctrl], target); + } + + HY(target); + } + adjoint (...) { + let vars = Length(controls); + + H(target); + AssertProb([PauliZ], [target], One, 0.5, "Probability of the measurement must be 0.5", 1e-10); + if (IsResultOne(MResetZ(target))) { + for (i in 0..vars - 1) { + let start = 1 <<< i; + let code = _GrayCode(i); + for (j in 0..Length(code) - 1) { + let (offset, ctrl) = code[j]; + RFrac(PauliZ, -_Angle(start + offset), vars, controls[i]); + if (i != 0) { + CNOT(controls[ctrl], controls[i]); + } + } + } + } + } + } + + /// # Summary + /// Arrange control, target, and helper qubits according to an index + /// + /// # Description + /// Returns a Qubit array with target at index 0, and control i at index + /// 2^i. The helper qubits are inserted to all other positions in the + /// array. + function _ArrangeQubits(controls : Qubit[], target : Qubit, helper : Qubit[]) : Qubit[] { + let numControls = Length(controls); + mutable qs = new Qubit[2^numControls] w/ 0 <- target; + mutable cntC = 0; + mutable cntH = 0; + for (i in 1..2^numControls - 1) { + if (i == (i &&& -i)) { + set qs w/= i <- controls[cntC]; + set cntC += 1; + } else { + set qs w/= i <- helper[cntH]; + set cntH += 1; + } + } + return qs; + } + + /// # Summary + /// Implements a multiple-controlled Toffoli gate, assuming that target + /// qubit is initialized 0. The adjoint operation assumes that the target + /// qubit will be released to 0. Requires a Rz depth of 1, while the number + /// of helper qubits are exponential in the number of qubits. + /// + /// # Input + /// ## controls + /// Control qubits + /// ## target + /// Target qubit + operation _ApplyMultipleControlledLowDepthAnd(controls : Qubit[], target : Qubit) : Unit { + body (...) { + let vars = Length(controls); + using (helper = Qubit[2^vars - vars - 1]) { + let qs = _ArrangeQubits(controls, target, helper); + + AssertAllZero([target]); + H(target); + + within { + // initialize helper lines with control lines based on LSB + for (i in 3..2^vars - 1) { + let lsb = i &&& -i; + if (i != lsb) { // i is power of 2 + CNOT(qs[lsb], qs[i]); + } + } + // target to control + ApplyToEachA(CNOT(target, _), controls); + // copy remainder (without LSB) + for (i in 3..2^vars - 1) { + let lsb = i &&& -i; + if (i != lsb) { + CNOT(qs[i - lsb], qs[i]); + } + } + } apply { + for (i in IndexRange(qs)) { + RFrac(PauliZ, _Angle(i), vars + 1, qs[i]); + } + } + + HY(target); + } + } + adjoint (...) { + let vars = Length(controls); + + H(target); + AssertProb([PauliZ], [target], One, 0.5, "Probability of the measurement must be 0.5", 1e-10); + if (IsResultOne(MResetZ(target))) { + using (helper = Qubit[2^vars - vars - 1]) { + let qs = _ArrangeQubits(controls, target, helper); + within { + // this is a bit easier than in the compute part, since + // the target qubit does not have to be copied over to + // the control lines. Therefore, the two LSB CNOT parts + // can be merged into a single loop. + for (i in 3..2^vars - 1) { + let lsb = i &&& -i; + if (i != lsb) { + CNOT(qs[lsb], qs[i]); + CNOT(qs[i - lsb], qs[i]); + } + } + } apply { + for (i in 1..2^vars - 1) { + RFrac(PauliZ, -_Angle(i), vars, qs[i]); + } + } + } + } + } + } +} diff --git a/Standard/src/Canon/Combinators/ApplyMultiControlled.qs b/Standard/src/Canon/Combinators/ApplyMultiControlled.qs index 89bddccafab..ab207594dff 100644 --- a/Standard/src/Canon/Combinators/ApplyMultiControlled.qs +++ b/Standard/src/Canon/Combinators/ApplyMultiControlled.qs @@ -11,7 +11,7 @@ namespace Microsoft.Quantum.Canon { /// # Summary /// The signature type of CCNOT gate. - newtype CCNOTop = ((Qubit, Qubit, Qubit) => Unit is Adj); + newtype CCNOTop = (Apply : ((Qubit, Qubit, Qubit) => Unit is Adj)); /// # Summary @@ -170,10 +170,10 @@ namespace Microsoft.Quantum.Canon { operation AndLadder (ccnot : CCNOTop, controls : Qubit[], targets : Qubit[]) : Unit is Adj { EqualityFactI(Length(controls), Length(targets) + 1, $"Length(controls) must be equal to Length(target) + 1"); Fact(Length(controls) >= 2, $"The operation is not defined for less than 2 controls"); - ccnot!(controls[0], controls[1], targets[0]); + ccnot::Apply(controls[0], controls[1], targets[0]); for (k in 1 .. Length(targets) - 1) { - ccnot!(controls[k + 1], targets[k - 1], targets[k]); + ccnot::Apply(controls[k + 1], targets[k - 1], targets[k]); } } diff --git a/Standard/tests/ANDTests.qs b/Standard/tests/ANDTests.qs new file mode 100644 index 00000000000..4cefc1304f3 --- /dev/null +++ b/Standard/tests/ANDTests.qs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +namespace Microsoft.Quantum.Tests { + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Logical; + open Microsoft.Quantum.Measurement; + + operation AndTestHelper(polarity1 : Bool, polarity2 : Bool, gate : CCNOTop) : Unit { + using ((control1, control2, target, output) = (Qubit(), Qubit(), Qubit(), Qubit())) { + within { + ApplyPauliFromBitString(PauliX, true, [polarity1, polarity2], [control1, control2]); + gate::Apply(control1, control2, target); + } + apply { + CNOT(target, output); + } + let expected = BoolAsResult(polarity1 and polarity2); + if (MResetZ(output) != expected) { + fail $"Expected output register to be {expected}"; + } + AssertAllZero([control1, control2, target]); + } + } + + operation ControlledAndTestHelper(polarities : Bool[], gate : ((Qubit, Qubit, Qubit) => Unit is Adj+Ctl)) : Unit { + let numControls = Length(polarities); + using ((controls, target, output) = (Qubit[numControls], Qubit(), Qubit())) { + within { + ApplyPauliFromBitString(PauliX, true, polarities, controls); + Controlled gate(controls[0..numControls - 3], (controls[numControls - 2], controls[numControls - 1], target)); + } + apply { + CNOT(target, output); + } + let expected = BoolAsResult(All(EqualB(true, _), polarities)); + if (MResetZ(output) != expected) { + fail $"Expected output register to be {expected}"; + } + AssertAllZero(controls + [target]); + } + } + + @Test("QuantumSimulator") + operation ApplyAndTest() : Unit { + for (p1 in [false, true]) { + for (p2 in [false, true]) { + for (op in [ApplyAnd, ApplyLowDepthAnd]) { + AndTestHelper(p1, p2, CCNOTop(op)); + } + } + } + } + + @Test("QuantumSimulator") + operation ControlledApplyAndTest() : Unit { + for (numControls in 3..5) { + for (assignment in 0..2^numControls - 1) { + ControlledAndTestHelper(IntAsBoolArray(assignment, numControls), ApplyAnd); + } + } + for (numControls in 3..4) { + for (assignment in 0..2^numControls - 1) { + ControlledAndTestHelper(IntAsBoolArray(assignment, numControls), ApplyLowDepthAnd); + } + } + } +} + + From a01973adf9f67d80153acdc90cae80ed748c8288 Mon Sep 17 00:00:00 2001 From: numpde <21158052+numpde@users.noreply.github.com> Date: Tue, 31 Dec 2019 01:59:42 +0100 Subject: [PATCH 04/17] Removed comment ref to IncrementByIntegerPhaseLE (#189) There appears to be no function IncrementByIntegerPhaseLE, and I guess it is covered by ApplyLEOperationOnPhaseLE. Co-authored-by: Chris Granade --- Standard/src/Arithmetic/Increment.qs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Standard/src/Arithmetic/Increment.qs b/Standard/src/Arithmetic/Increment.qs index f6dd2ae2ec6..53066a5b388 100644 --- a/Standard/src/Arithmetic/Increment.qs +++ b/Standard/src/Arithmetic/Increment.qs @@ -70,9 +70,6 @@ namespace Microsoft.Quantum.Arithmetic { /// encoding. /// ## increment /// The integer by which the `target` is incremented by. - /// - /// # See Also - /// - IncrementByIntegerPhaseLE operation IncrementByInteger(increment : Int, target : LittleEndian) : Unit is Adj + Ctl { ApplyPhaseLEOperationOnLECA(IncrementPhaseByInteger(increment, _), target); } From 39358f70b72f6c7695708ceb7fcfd76f97166581 Mon Sep 17 00:00:00 2001 From: Chris Granade Date: Thu, 2 Jan 2020 12:23:36 -0800 Subject: [PATCH 05/17] New Hadamard and SWAP test operations. (#196) * First work on Hadamard and SWAP test operations. * (c) header and typo fix. * Fixed typo with placement of phase shift. * Put public operations above private. * Added tests for new operations. * Added API documentation comments. * Newline at end of file. --- .../Characterization/Distinguishability.qs | 234 ++++++++++++++++++ .../DistinguishabilityTests.qs | 60 +++++ 2 files changed, 294 insertions(+) create mode 100644 Standard/src/Characterization/Distinguishability.qs create mode 100644 Standard/tests/Characterization/DistinguishabilityTests.qs diff --git a/Standard/src/Characterization/Distinguishability.qs b/Standard/src/Characterization/Distinguishability.qs new file mode 100644 index 00000000000..483cdbed803 --- /dev/null +++ b/Standard/src/Characterization/Distinguishability.qs @@ -0,0 +1,234 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Characterization { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Arrays; + + /// # Summary + /// Given two operations which each prepare copies of a state, estimates + /// the real part of the overlap between the states prepared by each + /// operation. + /// + /// # Input + /// ## commonPreparation + /// An operation that prepares a fixed input state. + /// ## preparation1 + /// The first of the two state preparation operations to be compared. + /// ## preparation2 + /// The second of the two state preparation operations to be compared. + /// ## nQubits + /// The number of qubits on which `commonPreparation`, `preparation1`, and + /// `preparation2` all act. + /// ## nMeasurements + /// The number of measurements to use in estimating the overlap. + /// + /// # Remarks + /// This operation uses the Hadamard test to find the real part of + /// $$ + /// \begin{align} + /// \braket{\psi | V^{\dagger} U | \psi} + /// \end{align} + /// $$ + /// where $\ket{\psi}$ is the state prepared by `commonPreparation`, + /// $U$ is the unitary representation of the action of `preparation1`, + /// and where $V$ corresponds to `preparation2`. + /// + /// # References + /// - Aharonov *et al.* [quant-ph/0511096](https://arxiv.org/abs/quant-ph/0511096). + /// + /// # See Also + /// - Microsoft.Quantum.Characterization.EstimateImagOverlapBetweenStates + /// - Microsoft.Quantum.Characterization.EstimateOverlapBetweenStates + operation EstimateRealOverlapBetweenStates( + commonPreparation : (Qubit[] => Unit is Adj), + preparation1 : (Qubit[] => Unit is Adj + Ctl), + preparation2 : (Qubit[] => Unit is Adj + Ctl), + nQubits : Int, nMeasurements : Int + ) + : Double { + return 2.0 * EstimateFrequencyA( + _ApplyHadamardTestOnSingleRegister(false, commonPreparation, preparation1, preparation2, _), + _HeadMeasurement(nQubits + 1), + nQubits + 1, nMeasurements + ) - 1.0; + } + + /// # Summary + /// Given two operations which each prepare copies of a state, estimates + /// the imaginary part of the overlap between the states prepared by each + /// operation. + /// + /// # Input + /// ## commonPreparation + /// An operation that prepares a fixed input state. + /// ## preparation1 + /// The first of the two state preparation operations to be compared. + /// ## preparation2 + /// The second of the two state preparation operations to be compared. + /// ## nQubits + /// The number of qubits on which `commonPreparation`, `preparation1`, and + /// `preparation2` all act. + /// ## nMeasurements + /// The number of measurements to use in estimating the overlap. + /// + /// # Remarks + /// This operation uses the Hadamard test to find the imaginary part of + /// $$ + /// \begin{align} + /// \braket{\psi | V^{\dagger} U | \psi} + /// \end{align} + /// $$ + /// where $\ket{\psi}$ is the state prepared by `commonPreparation`, + /// $U$ is the unitary representation of the action of `preparation1`, + /// and where $V$ corresponds to `preparation2`. + /// + /// # References + /// - Aharonov *et al.* [quant-ph/0511096](https://arxiv.org/abs/quant-ph/0511096). + /// + /// # See Also + /// - Microsoft.Quantum.Characterization.EstimateRealOverlapBetweenStates + /// - Microsoft.Quantum.Characterization.EstimateOverlapBetweenStates + operation EstimateImagOverlapBetweenStates( + commonPreparation : (Qubit[] => Unit is Adj), + preparation1 : (Qubit[] => Unit is Adj + Ctl), + preparation2 : (Qubit[] => Unit is Adj + Ctl), + nQubits : Int, nMeasurements : Int + ) + : Double { + return 2.0 * EstimateFrequencyA( + _ApplyHadamardTestOnSingleRegister(true, commonPreparation, preparation1, preparation2, _), + _HeadMeasurement(nQubits + 1), + nQubits + 1, nMeasurements + ) - 1.0; + } + + + /// # Summary + /// Given two operations which each prepare copies of a state, estimates + /// the squared overlap between the states prepared by each + /// operation. + /// + /// # Input + /// ## preparation1 + /// The first of the two state preparation operations to be compared. + /// ## preparation2 + /// The second of the two state preparation operations to be compared. + /// ## nQubits + /// The number of qubits on which `commonPreparation`, `preparation1`, and + /// `preparation2` all act. + /// ## nMeasurements + /// The number of measurements to use in estimating the overlap. + /// + /// # Remarks + /// This operation uses the SWAP test to find + /// $$ + /// \begin{align} + /// \left| \braket{00\cdots 0 | V^{\dagger} U | 00\cdots 0} \right|^2 + /// \end{align} + /// $$ + /// where $U$ is the unitary representation of the action of `preparation1`, + /// and where $V$ corresponds to `preparation2`. + /// + /// # See Also + /// - Microsoft.Quantum.Characterization.EstimateRealOverlapBetweenStates + /// - Microsoft.Quantum.Characterization.EstimateImagOverlapBetweenStates + operation EstimateOverlapBetweenStates( + preparation1 : (Qubit[] => Unit is Adj), + preparation2 : (Qubit[] => Unit is Adj), + nQubits : Int, nMeasurements : Int + ) + : Double { + let nTotalQubits = 2 * nQubits + 1; + return 2.0 * EstimateFrequencyA( + _ApplySwapTestOnSingleRegister(preparation1, preparation2, _), + _HeadMeasurement(nTotalQubits), + nTotalQubits, nMeasurements + ) - 1.0; + } + + + operation _ApplyHadamardTest( + phaseShift : Bool, + commonPreparation : (Qubit[] => Unit is Adj), + preparation1 : (Qubit[] => Unit is Adj + Ctl), + preparation2 : (Qubit[] => Unit is Adj + Ctl), + control : Qubit, + target : Qubit[] + ) + : Unit is Adj + { + within { + H(control); + } apply { + commonPreparation(target); + Controlled preparation1([control], target); + within { X(control); } + apply { Controlled preparation2([control], target); } + + (phaseShift ? S | I)(control); + } + } + + operation _ApplyHadamardTestOnSingleRegister( + phaseShift : Bool, + commonPreparation : (Qubit[] => Unit is Adj), + preparation1 : (Qubit[] => Unit is Adj + Ctl), + preparation2 : (Qubit[] => Unit is Adj + Ctl), + register : Qubit[] + ) + : Unit is Adj + { + let control = Head(register); + let target = Rest(register); + _ApplyHadamardTest( + phaseShift, + commonPreparation, + preparation1, preparation2, + control, target + ); + } + + + operation _ApplySwapTest( + preparation1 : (Qubit[] => Unit is Adj), + preparation2 : (Qubit[] => Unit is Adj), + control : Qubit, + target1 : Qubit[], + target2 : Qubit[] + ) + : Unit is Adj { + within { + H(control); + } apply { + preparation1(target1); + preparation2(target2); + ApplyToEachCA(Controlled SWAP([control], _), Zip(target1, target2)); + } + } + + operation _ApplySwapTestOnSingleRegister( + preparation1 : (Qubit[] => Unit is Adj), + preparation2 : (Qubit[] => Unit is Adj), + register : Qubit[] + ) + : Unit is Adj { + let control = Head(register); + let targets = Rest(register); + _ApplySwapTest( + preparation1, preparation2, + control, + targets[...Length(targets) / 2 - 1], + targets[Length(targets) / 2...] + ); + } + + function _HeadMeasurement(nQubits : Int) : (Qubit[] => Result) { + return Measure( + ConstantArray(nQubits, PauliI) w/ 0 <- PauliZ, + _ + ); + } + +} diff --git a/Standard/tests/Characterization/DistinguishabilityTests.qs b/Standard/tests/Characterization/DistinguishabilityTests.qs new file mode 100644 index 00000000000..f9f04bb853d --- /dev/null +++ b/Standard/tests/Characterization/DistinguishabilityTests.qs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Tests { + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Characterization; + open Microsoft.Quantum.Diagnostics; + + @Test("QuantumSimulator") + operation CheckOverlapBetweenPlusAndOne() : Unit { + let prep1 = ApplyToEachCA(H, _); + let prep2 = ApplyToEachCA(X, _); + + EqualityWithinToleranceFact( + EstimateRealOverlapBetweenStates( + NoOp, prep1, prep2, 1, 1000000 + ), + 1.0 / Sqrt(2.0), + 0.02 + ); + EqualityWithinToleranceFact( + EstimateImagOverlapBetweenStates( + NoOp, prep1, prep2, 1, 1000000 + ), + 0.0, + 0.02 + ); + EqualityWithinToleranceFact( + 0.5, + EstimateOverlapBetweenStates( + prep1, prep2, 1, 1000000 + ), + 0.02 + ); + } + + @Test("QuantumSimulator") + operation CheckOverlapWithCommonPreparation() : Unit { + let common = ApplyToEachCA(H, _); + let prep1 = ApplyToEachCA(S, _); + let prep2 = ApplyToEachCA(Z, _); + + EqualityWithinToleranceFact( + EstimateRealOverlapBetweenStates( + common, prep1, prep2, 1, 1000000 + ), + 0.5, + 0.02 + ); + EqualityWithinToleranceFact( + EstimateImagOverlapBetweenStates( + common, prep1, prep2, 1, 1000000 + ), + 0.5, + 0.02 + ); + } +} From f1bd9d272de16382adb5d1356afe5e5d801cef52 Mon Sep 17 00:00:00 2001 From: Chris Granade Date: Thu, 2 Jan 2020 13:38:14 -0800 Subject: [PATCH 06/17] Refactor AA namespace to use Q# style guide (#197) * Began simplifying AA interface. * Expose traditional AA as new public operation. * Removed rest of "AmpAmp" prefix. * Resolve deprecation warning. --- .../AmplitudeAmplification.qs | 389 ++++++++---------- .../CommonOracles.qs | 19 +- .../src/AmplitudeAmplification/Convert.qs | 47 +++ .../src/AmplitudeAmplification/Deprecated.qs | 112 +++++ .../StandardAlgorithms.qs | 78 ++++ Standard/src/AmplitudeAmplification/Types.qs | 9 +- Standard/src/Oracles/Convert.qs | 71 ++-- Standard/src/Oracles/Types.qs | 14 +- .../src/Preparation/UniformSuperposition.qs | 12 +- 9 files changed, 456 insertions(+), 295 deletions(-) rename Standard/src/{Oracles => AmplitudeAmplification}/CommonOracles.qs (69%) create mode 100644 Standard/src/AmplitudeAmplification/Convert.qs create mode 100644 Standard/src/AmplitudeAmplification/Deprecated.qs create mode 100644 Standard/src/AmplitudeAmplification/StandardAlgorithms.qs diff --git a/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs b/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs index f6564b569ce..dde60e11be4 100644 --- a/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs +++ b/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs @@ -2,161 +2,44 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.AmplitudeAmplification { + open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Convert; open Microsoft.Quantum.Math; open Microsoft.Quantum.Canon; open Microsoft.Quantum.Oracles; - /// # Summary - /// Converts phases specified as single-qubit rotations to phases - /// specified as partial reflections. - /// - /// # Input - /// ## rotPhases - /// Array of single-qubit rotations to be converted to partial - /// reflections. - /// - /// # Output - /// An operation that implements phases specified as partial reflections. - /// - /// # References - /// We use the convention in - /// - [ *G.H. Low, I. L. Chuang* ](https://arxiv.org/abs/1707.05391) - /// for relating single-qubit rotation phases to reflection operator phases. - function AmpAmpRotationToReflectionPhases (rotPhases : RotationPhases) : ReflectionPhases - { - let nPhasesRot = Length(rotPhases!); - let nPhasesRef = (nPhasesRot + 1) / 2; - - if (nPhasesRot % 2 == 0) - { - fail $"Number of rotations must be odd."; - } - - mutable phasesTarget = new Double[nPhasesRef]; - mutable phasesStart = new Double[nPhasesRef]; - set phasesTarget w/= 0 <- ((rotPhases!)[0] - (rotPhases!)[1]) - PI(); - set phasesStart w/= 0 <- -(rotPhases!)[0] + 0.5 * PI(); - - for (idxPhases in 1 .. nPhasesRef - 2) - { - set phasesTarget w/= idxPhases <- ((rotPhases!)[2 * idxPhases] - (rotPhases!)[2 * idxPhases + 1]) - PI(); - set phasesStart w/= idxPhases <- ((rotPhases!)[2 * idxPhases - 1] - (rotPhases!)[2 * idxPhases]) + PI(); - } - - set phasesTarget w/= nPhasesRef - 1 <- (rotPhases!)[2 * nPhasesRef - 2] - 0.5 * PI(); - set phasesStart w/= nPhasesRef - 1 <- ((rotPhases!)[2 * nPhasesRef - 3] - (rotPhases!)[2 * nPhasesRef - 2]) + PI(); - return ReflectionPhases(phasesStart, phasesTarget); - } - - - /// # Summary - /// Computes partial reflection phases for standard amplitude - /// amplification. - /// - /// # Input - /// ## nIterations - /// Number of amplitude amplification iterations to generate partial - /// reflection phases for. - /// - /// # Output - /// An operation that implements phases specified as partial reflections - /// - /// # Remarks - /// All phases are $\pi$, except for the first reflection about the start - /// state and the last reflection about the target state, which are $0$. - function AmpAmpPhasesStandard (nIterations : Int) : ReflectionPhases - { - mutable phasesTarget = new Double[nIterations + 1]; - mutable phasesStart = new Double[nIterations + 1]; - - for (idxPhases in 0 .. nIterations) - { - set phasesTarget w/= idxPhases <- PI(); - set phasesStart w/= idxPhases <- PI(); - } - - set phasesTarget w/= nIterations <- 0.0; - set phasesStart w/= 0 <- 0.0; - return ReflectionPhases(phasesStart, phasesTarget); - } - - - // We use the phases in "Fixed-Point Amplitude Amplification with an - // Optimal Number of Queires" [YoderLowChuang2014] - // See also "Methodology of composite quantum gates" [LowYoderChuang2016] - // for phases in the `RotationPhases` format - - /// # Summary - /// Computes partial reflection phases for fixed-point amplitude - /// amplification. - /// - /// # Input - /// ## nQueries - /// Number of queries to the state preparation oracle. Must be an odd - /// integer. - /// ## successMin - /// Target minimum success probability. - /// - /// # Output - /// Array of phases that can be used in fixed-point amplitude amplification - /// quantum algorithm implementation. - /// - /// # References - /// We use the phases in "Fixed-Point Amplitude Amplification with - /// an Optimal Number of Queries" - /// - [YoderLowChuang2014](https://arxiv.org/abs/1409.3305) - /// See also "Methodology of composite quantum gates" - /// - [LowYoderChuang2016](https://arxiv.org/abs/1603.03996) - /// for phases in the `RotationPhases` format. - function AmpAmpPhasesFixedPoint (nQueries : Int, successMin : Double) : ReflectionPhases - { - mutable phasesRot = new Double[nQueries]; - let nQueriesDouble = IntAsDouble(nQueries); - set phasesRot w/= 0 <- 0.0; - let beta = Cosh((1.0 / nQueriesDouble) * ArcCosh(Sqrt(successMin))); - - for (idxPhases in 1 .. nQueries - 1) - { - set phasesRot w/= idxPhases <- phasesRot[idxPhases - 1] + 2.0 * ArcTan(Tan((((2.0 * 1.0) * IntAsDouble(idxPhases)) * PI()) / nQueriesDouble) * Sqrt(1.0 - beta * beta)); - } - - return AmpAmpRotationToReflectionPhases(RotationPhases(phasesRot)); - } - - /// # Summary /// Oblivious amplitude amplification by specifying partial reflections. /// /// # Input /// ## phases /// Phases of partial reflections - /// ## ancillaReflection - /// Reflection operator about start state of ancilla register + /// ## startStateReflection + /// Reflection operator about start state of auxiliary register /// ## targetStateReflection - /// Reflection operator about target state of ancilla register + /// Reflection operator about target state of auxiliary register /// ## signalOracle /// Unitary oracle $O$ of type `ObliviousOracle` that acts jointly on the - /// ancilla and system registers. - /// ## ancillaRegister - /// Ancilla register + /// auxiliary and system registers. + /// ## auxiliaryRegister + /// Auxiliary register /// ## systemRegister /// System register /// /// # Remarks - /// Given a particular ancilla start state $\ket{\text{start}}\_a$, a - /// particular ancilla target state $\ket{\text{target}}\_a$, and any + /// Given a particular auxiliary start state $\ket{\text{start}}\_a$, a + /// particular auxiliary target state $\ket{\text{target}}\_a$, and any /// system state $\ket{\psi}\_s$, suppose that /// \begin{align} /// O\ket{\text{start}}\_a\ket{\psi}\_s= \lambda\ket{\text{target}}\_a U \ket{\psi}\_s + \sqrt{1-|\lambda|^2}\ket{\text{target}^\perp}\_a\cdots /// \end{align} /// for some unitary $U$. /// By a sequence of reflections about the start and target states on the - /// ancilla register interleaved by applications of `signalOracle` and its + /// auxiliary register interleaved by applications of `signalOracle` and its /// adjoint, the success probability of applying U may be altered. /// - /// In most cases, `ancillaRegister` is initialized in the state $\ket{\text{start}}\_a$. + /// In most cases, `auxiliaryRegister` is initialized in the state $\ket{\text{start}}\_a$. /// /// # References /// See @@ -165,69 +48,67 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// See /// - [ *G.H. Low, I.L. Chuang* ](https://arxiv.org/abs/1610.06546) /// for a generalization to partial reflections. - operation AmpAmpObliviousByReflectionPhasesImpl (phases : ReflectionPhases, ancillaReflection : ReflectionOracle, targetStateReflection : ReflectionOracle, signalOracle : ObliviousOracle, ancillaRegister : Qubit[], systemRegister : Qubit[]) : Unit - { - body (...) - { - let (phasesAncilla, phasesTarget) = phases!; - let nphases = 2 * Length(phasesTarget); - - //FailOn(nphases != Length(phasesAncilla), "Phase array lengths not equal.") - if (phasesAncilla[0] != 0.0) - { - ancillaReflection!(phasesAncilla[0], ancillaRegister); + operation ApplyObliviousAmplitudeAmplification( + phases : ReflectionPhases, + startStateReflection : ReflectionOracle, + targetStateReflection : ReflectionOracle, + signalOracle : ObliviousOracle, + auxiliaryRegister : Qubit[], + systemRegister : Qubit[] + ) + : Unit is Adj + Ctl { + for ((startPhase, targetPhase) in Zip(phases!)) { + if (startPhase != 0.0) { + startStateReflection::ApplyReflection( + startPhase, auxiliaryRegister + ); } - - for (idxPhases in 1 .. nphases - 1) - { - let idxPhaseAncilla = idxPhases / 2; - let idxPhaseTarget = idxPhases / 2; - - if (idxPhases % 2 == 1) - { - signalOracle!(ancillaRegister, systemRegister); - - if (phasesTarget[idxPhaseTarget] != 0.0) - { - targetStateReflection!(phasesTarget[idxPhaseTarget], ancillaRegister); - } - } - else - { - Adjoint signalOracle!(ancillaRegister, systemRegister); - - if (phasesAncilla[idxPhaseAncilla] != 0.0) - { - ancillaReflection!(phasesAncilla[idxPhaseAncilla], ancillaRegister); - } + + within { + signalOracle!(auxiliaryRegister, systemRegister); + } apply { + if (targetPhase != 0.0) { + targetStateReflection!(targetPhase, auxiliaryRegister); } } } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; + // This gives us one extra application of Adjoint signalOracle!, so we + // apply the forward direction at the end. + signalOracle!(auxiliaryRegister, systemRegister); } - - + + + // NB [STYLE]: The name of this operation uses "From" as it is not a type + // conversion function ("As"), but something that constructs + // an operation from given information in a deterministic + // fashion. /// # Summary /// Returns a unitary that implements oblivious amplitude amplification by specifying for partial reflections. - function AmpAmpObliviousByReflectionPhases (phases : ReflectionPhases, ancillaReflection : ReflectionOracle, targetStateReflection : ReflectionOracle, signalOracle : ObliviousOracle) : ((Qubit[], Qubit[]) => Unit is Adj + Ctl) - { - return AmpAmpObliviousByReflectionPhasesImpl(phases, ancillaReflection, targetStateReflection, signalOracle, _, _); + function ObliviousAmplitudeAmplificationFromPartialReflections( + phases : ReflectionPhases, + startStateReflection : ReflectionOracle, + targetStateReflection : ReflectionOracle, + signalOracle : ObliviousOracle + ) + : ((Qubit[], Qubit[]) => Unit is Adj + Ctl) { + return ApplyObliviousAmplitudeAmplification( + phases, startStateReflection, targetStateReflection, signalOracle, + _, _ + ); } - - + + /// # Summary /// Oblivious amplitude amplification by oracles for partial reflections. /// /// # Input /// ## phases /// Phases of partial reflections - /// ## ancillaOracle - /// Unitary oracle $A$ that prepares ancilla start state + /// ## startStateOracle + /// Unitary oracle $A$ that prepares auxiliary start state /// ## signalOracle - /// Unitary oracle $O$ of type `ObliviousOracle` that acts jointly on the ancilla and system register + /// Unitary oracle $O$ of type `ObliviousOracle` that acts jointly on the + /// auxiliary and system register /// ## idxFlagQubit /// Index to single-qubit flag register /// @@ -235,23 +116,65 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// An operation that implements oblivious amplitude amplification based on partial reflections. /// /// # Remarks - /// This imposes stricter conditions on form of the ancilla start and target states than in `AmpAmpObliviousByReflectionPhases`. - /// It is assumed that $A\ket{0}\_f\ket{0}\_a= \ket{\text{start}}\_{fa}$ prepares the ancilla start state $\ket{\text{start}}\_{fa}$ from the computational basis $\ket{0}\_f\ket{0}$. + /// This imposes stricter conditions on form of the auxiliary start and target states than in `AmpAmpObliviousByReflectionPhases`. + /// It is assumed that $A\ket{0}\_f\ket{0}\_a= \ket{\text{start}}\_{fa}$ prepares the auxiliary start state $\ket{\text{start}}\_{fa}$ from the computational basis $\ket{0}\_f\ket{0}$. /// It is assumed that the target state is marked by $\ket{1}\_f$. /// It is assumed that /// \begin{align} /// O\ket{\text{start}}\_{fa}\ket{\psi}\_s= \lambda\ket{1}\_f\ket{\text{anything}}\_a\ket{\text{target}}\_s U \ket{\psi}\_s + \sqrt{1-|\lambda|^2}\ket{0}\_f\cdots, /// \end{align} /// for some unitary $U$. - function AmpAmpObliviousByOraclePhases (phases : ReflectionPhases, ancillaOracle : DeterministicStateOracle, signalOracle : ObliviousOracle, idxFlagQubit : Int) : ((Qubit[], Qubit[]) => Unit is Adj + Ctl) - { - let ancillaReflection = ReflectionStart(); + function ObliviousAmplitudeAmplificationFromStatePreparation( + phases : ReflectionPhases, + startStateOracle : DeterministicStateOracle, + signalOracle : ObliviousOracle, + idxFlagQubit : Int + ) + : ((Qubit[], Qubit[]) => Unit is Adj + Ctl) { + let startStateReflection = ReflectionStart(); let targetStateReflection = TargetStateReflectionOracle(idxFlagQubit); - let oracleObliviousNew = ObliviousOracleFromDeterministicStateOracle(ancillaOracle, signalOracle); - return AmpAmpObliviousByReflectionPhases(phases, ancillaReflection, targetStateReflection, oracleObliviousNew); + let obliviousSignalOracle = ObliviousOracleFromDeterministicStateOracle( + startStateOracle, signalOracle + ); + return ObliviousAmplitudeAmplificationFromPartialReflections( + phases, startStateReflection, targetStateReflection, obliviousSignalOracle + ); } - - + + /// # Summary + /// Applies amplitude amplification on a given register, using a given set + /// of phases and oracles to reflect about the initial and final states. + /// + /// # Input + /// ## phases + /// A set of phases describing the partial reflections at each step of the + /// amplitude amplification algorithm. See + /// @"microsoft.quantum.amplitudeamplification.standardreflectionphases" + /// for an example. + /// ## startStateReflection + /// An oracle that reflects about the initial state. + /// ## targetStateReflection + /// An oracle that reflects about the desired final state. + /// ## target + /// A register to perform amplitude amplification on. + operation ApplyAmplitudeAmplification( + phases : ReflectionPhases, + startStateReflection : ReflectionOracle, + targetStateReflection : ReflectionOracle, + target : Qubit[] + ) + : Unit is Adj + Ctl { + // Pass empty qubit array using fact that NoOp does nothing. + let systemRegister = new Qubit[0]; + let signalOracle = ObliviousOracle(NoOp<(Qubit[], Qubit[])>); + let op = ObliviousAmplitudeAmplificationFromPartialReflections( + phases, startStateReflection, targetStateReflection, signalOracle + ); + + op(target, systemRegister); + } + + /// # Summary /// Amplitude amplification by partial reflections. /// @@ -271,15 +194,25 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// # Remarks /// Amplitude amplification is a special case of oblivious amplitude amplification where there are no system qubits and the oblivious oracle is set to identity. /// In most cases, `startQubits` is initialized in the state $\ket{\text{start}}\_1$, which is the $-1$ eigenstate of `startStateReflection`. - function AmpAmpByReflectionsPhases (phases : ReflectionPhases, startStateReflection : ReflectionOracle, targetStateReflection : ReflectionOracle) : (Qubit[] => Unit is Adj + Ctl) - { + function AmplitudeAmplificationFromPartialReflections( + phases : ReflectionPhases, + startStateReflection : ReflectionOracle, + targetStateReflection : ReflectionOracle + ) + : (Qubit[] => Unit is Adj + Ctl) { // Pass empty qubit array using fact that NoOp does nothing. let qubitEmpty = new Qubit[0]; let signalOracle = ObliviousOracle(NoOp<(Qubit[], Qubit[])>); - return (AmpAmpObliviousByReflectionPhases(phases, startStateReflection, targetStateReflection, signalOracle))(_, qubitEmpty); + return (ObliviousAmplitudeAmplificationFromPartialReflections( + phases, startStateReflection, targetStateReflection, signalOracle + ))(_, qubitEmpty); } - - + + + // NB [STYLE]: The name of this operation uses "From" as it is not a type + // conversion function ("As"), but something that constructs + // an operation from given information in a deterministic + // fashion. /// # Summary /// Amplitude amplification by oracles for partial reflections. /// @@ -304,16 +237,22 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// \begin{align} /// A\ket{0}\_{f}\ket{0}\_s= \lambda\ket{1}\_f\ket{\text{target}}\_s + \sqrt{1-|\lambda|^2}\ket{0}\_f\cdots, /// \end{align} - /// In most cases, `flagQubit` and `ancillaRegister` is initialized in the state $\ket{0}\_{f}\ket{0}\_s$. - function AmpAmpByOraclePhases (phases : ReflectionPhases, stateOracle : StateOracle, idxFlagQubit : Int) : (Qubit[] => Unit is Adj + Ctl) - { - let qubitEmpty = new Qubit[0]; + /// In most cases, `flagQubit` and `auxiliaryRegister` are initialized in the state $\ket{0}\_{f}\ket{0}\_s$. + function AmplitudeAmplificationFromStatePreparation( + phases : ReflectionPhases, + stateOracle : StateOracle, + idxFlagQubit : Int + ) + : (Qubit[] => Unit is Adj + Ctl) { + let systemRegister = new Qubit[0]; let signalOracle = ObliviousOracle(NoOp<(Qubit[], Qubit[])>); - let ancillaOracle = DeterministicStateOracleFromStateOracle(idxFlagQubit, stateOracle); - return (AmpAmpObliviousByOraclePhases(phases, ancillaOracle, signalOracle, idxFlagQubit))(_, qubitEmpty); + let startStateOracle = DeterministicStateOracleFromStateOracle(idxFlagQubit, stateOracle); + return (ObliviousAmplitudeAmplificationFromStatePreparation( + phases, startStateOracle, signalOracle, idxFlagQubit + ))(_, systemRegister); } - - + + /// # Summary /// Standard Amplitude Amplification algorithm /// @@ -340,17 +279,21 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// \begin{align} /// \operatorname{AmpAmpByOracle}\ket{0}\_{f}\ket{0}\_s= \sin((2n+1)\sin^{-1}(\lambda))\ket{1}\_f\ket{\text{target}}\_s + \cdots\ket{0}\_f /// \end{align} - /// In most cases, `flagQubit` and `ancillaRegister` is initialized in the state $\ket{0}\_f\ket{0}\_a$. + /// In most cases, `flagQubit` and `auxiliaryRegister` is initialized in the state $\ket{0}\_f\ket{0}\_a$. /// /// # References /// - [ *G. Brassard, P. Hoyer, M. Mosca, A. Tapp* ](https://arxiv.org/abs/quant-ph/0005055) - function AmpAmpByOracle (nIterations : Int, stateOracle : StateOracle, idxFlagQubit : Int) : (Qubit[] => Unit is Adj + Ctl) - { - let phases = AmpAmpPhasesStandard(nIterations); - return AmpAmpByOraclePhases(phases, stateOracle, idxFlagQubit); + function StandardAmplitudeAmplification( + nIterations : Int, + stateOracle : StateOracle, + idxFlagQubit : Int + ) + : (Qubit[] => Unit is Adj + Ctl) { + let phases = StandardReflectionPhases(nIterations); + return AmplitudeAmplificationFromStatePreparation(phases, stateOracle, idxFlagQubit); } - - + + /// # Summary /// Fixed-Point Amplitude Amplification algorithm /// @@ -363,56 +306,50 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// # Remarks /// The startQubits must be in the $\ket{0 \cdots 0}$ state. This operation iterates over a number of queries in powers of $2$ until either a maximal number of queries /// is reached, or the target state is found. - operation AmpAmpRUSByOracle (statePrepOracle : StateOracle, startQubits : Qubit[]) : Unit - { + operation ApplyFixedPointAmplification(statePrepOracle : StateOracle, startQubits : Qubit[]) + : Unit { // Should be a power of 2 let queriesMax = 999; let successMin = 0.99; mutable finished = Zero; mutable exponentMax = 0; mutable exponentCurrent = 0; - + //Complexity: Let \theta = \mathcal{O}(\sqrt{lambda}) // Number of Measurements = O( Log^2(1/\theta) ) // Number of Queries = O(1/\theta) - using (flagQubit = Qubit[1]) - { + using (flagQubit = Qubit[1]) { let qubits = flagQubit + startQubits; let idxFlagQubit = 0; - - repeat - { - if (2 ^ exponentMax > queriesMax) - { + + repeat { + if (2 ^ exponentMax > queriesMax) { fail $"Target state not found. Maximum number of queries exceeded."; } - - repeat - { + + repeat { let queries = 2 ^ exponentCurrent; - let phases = AmpAmpPhasesFixedPoint(queries, successMin); - (AmpAmpByOraclePhases(phases, statePrepOracle, idxFlagQubit))(qubits); + let phases = FixedPointReflectionPhases(queries, successMin); + (AmplitudeAmplificationFromStatePreparation(phases, statePrepOracle, idxFlagQubit))(qubits); set finished = M(flagQubit[0]); set exponentCurrent = exponentCurrent + 1; } until (finished == One or exponentCurrent > exponentMax) - fixup - { + fixup { // flagQubit is already in Zero for fixup to apply ResetAll(startQubits); } - + set exponentCurrent = 0; set exponentMax = exponentMax + 1; } until (finished == One) - fixup - { + fixup { ResetAll(startQubits); } } } - + } diff --git a/Standard/src/Oracles/CommonOracles.qs b/Standard/src/AmplitudeAmplification/CommonOracles.qs similarity index 69% rename from Standard/src/Oracles/CommonOracles.qs rename to Standard/src/AmplitudeAmplification/CommonOracles.qs index ba169bb7ae4..7bd2bc4e6fb 100644 --- a/Standard/src/Oracles/CommonOracles.qs +++ b/Standard/src/AmplitudeAmplification/CommonOracles.qs @@ -20,20 +20,15 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// # Summary /// Implementation of . - operation TargetStateReflectionOracleImpl (phase : Double, idxFlagQubit : Int, qubits : Qubit[]) : Unit { - body (...) { - R1(phase, qubits[idxFlagQubit]); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; + operation _TargetStateReflectionOracle(phase : Double, idxFlagQubit : Int, qubits : Qubit[]) + : Unit is Adj + Ctl { + R1(phase, qubits[idxFlagQubit]); } /// # Summary /// Constructs a `ReflectionOracle` about the target state uniquely marked by the flag qubit. - /// - /// The target state has a single qubit set to 1, and all others 0: $\ket{1}_f$. + /// + /// The target state has a single qubit set to 1, and all others 0: $\ket{1}_f$. /// /// # Input /// ## idxFlagQubit @@ -44,8 +39,8 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// /// # See Also /// - Microsoft.Quantum.Canon.ReflectionOracle - function TargetStateReflectionOracle (idxFlagQubit : Int) : ReflectionOracle { - return ReflectionOracle(TargetStateReflectionOracleImpl(_, idxFlagQubit, _)); + function TargetStateReflectionOracle(idxFlagQubit : Int) : ReflectionOracle { + return ReflectionOracle(_TargetStateReflectionOracle(_, idxFlagQubit, _)); } } diff --git a/Standard/src/AmplitudeAmplification/Convert.qs b/Standard/src/AmplitudeAmplification/Convert.qs new file mode 100644 index 00000000000..72bb061bbd3 --- /dev/null +++ b/Standard/src/AmplitudeAmplification/Convert.qs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.AmplitudeAmplification { + open Microsoft.Quantum.Math; + + /// # Summary + /// Converts phases specified as single-qubit rotations to phases + /// specified as partial reflections. + /// + /// # Input + /// ## rotPhases + /// Array of single-qubit rotations to be converted to partial + /// reflections. + /// + /// # Output + /// An operation that implements phases specified as partial reflections. + /// + /// # References + /// We use the convention in + /// - [ *G.H. Low, I. L. Chuang* ](https://arxiv.org/abs/1707.05391) + /// for relating single-qubit rotation phases to reflection operator phases. + function RotationPhasesAsReflectionPhases(rotPhases : RotationPhases) + : ReflectionPhases { + let nPhasesRot = Length(rotPhases!); + let nPhasesRef = (nPhasesRot + 1) / 2; + + if (nPhasesRot % 2 == 0) { + fail $"Number of rotations must be odd."; + } + + mutable phasesTarget = new Double[nPhasesRef]; + mutable phasesStart = new Double[nPhasesRef]; + set phasesTarget w/= 0 <- ((rotPhases!)[0] - (rotPhases!)[1]) - PI(); + set phasesStart w/= 0 <- -(rotPhases!)[0] + 0.5 * PI(); + + for (idxPhases in 1 .. nPhasesRef - 2) { + set phasesTarget w/= idxPhases <- ((rotPhases!)[2 * idxPhases] - (rotPhases!)[2 * idxPhases + 1]) - PI(); + set phasesStart w/= idxPhases <- ((rotPhases!)[2 * idxPhases - 1] - (rotPhases!)[2 * idxPhases]) + PI(); + } + + set phasesTarget w/= nPhasesRef - 1 <- (rotPhases!)[2 * nPhasesRef - 2] - 0.5 * PI(); + set phasesStart w/= nPhasesRef - 1 <- ((rotPhases!)[2 * nPhasesRef - 3] - (rotPhases!)[2 * nPhasesRef - 2]) + PI(); + return ReflectionPhases(phasesStart, phasesTarget); + } + +} diff --git a/Standard/src/AmplitudeAmplification/Deprecated.qs b/Standard/src/AmplitudeAmplification/Deprecated.qs new file mode 100644 index 00000000000..6f0f2158ac4 --- /dev/null +++ b/Standard/src/AmplitudeAmplification/Deprecated.qs @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.AmplitudeAmplification { + open Microsoft.Quantum.Oracles; + + + /// # Deprecated + /// Please use + /// @"microsoft.quantum.amplitudeamplification.rotationphasesasreflectionphases". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.RotationPhasesAsReflectionPhases") + function AmpAmpRotationToReflectionPhases (rotPhases : RotationPhases) + : ReflectionPhases { + return RotationPhasesAsReflectionPhases(rotPhases); + } + + /// # Deprecated + /// Please use + /// @"microsoft.quantum.amplitudeamplification.standardreflectionphases". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.StandardReflectionPhases") + function AmpAmpPhasesStandard(nIterations : Int) : ReflectionPhases { + return StandardReflectionPhases(nIterations); + } + + /// # Deprecated + /// Please use + /// @"microsoft.quantum.amplitudeamplification.fixedpointreflectionphases". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.FixedPointReflectionPhases") + function AmpAmpPhasesFixedPoint(nQueries : Int, successMin : Double) : ReflectionPhases { + return FixedPointReflectionPhases(nQueries, successMin); + } + + /// # Deprecated + /// Please use @"microsoft.quantum.amplitudeamplification.obliviousamplitudeamplificationfrompartialreflections". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.ObliviousAmplitudeAmplificationFromPartialReflections") + function AmpAmpObliviousByReflectionPhases( + phases : ReflectionPhases, + startStateReflection : ReflectionOracle, + targetStateReflection : ReflectionOracle, + signalOracle : ObliviousOracle + ) + : ((Qubit[], Qubit[]) => Unit is Adj + Ctl) { + return ObliviousAmplitudeAmplificationFromPartialReflections( + phases, startStateReflection, targetStateReflection, signalOracle + ); + } + + /// # Deprecated + /// Please use @"microsoft.quantum.amplitudeamplification.obliviousamplitudeamplificationfromstatepreparation". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.ObliviousAmplitudeAmplificationFromStatePreparation") + function AmpAmpObliviousByOraclePhases( + phases : ReflectionPhases, + startStateOracle : DeterministicStateOracle, + signalOracle : ObliviousOracle, + idxFlagQubit : Int + ) + : ((Qubit[], Qubit[]) => Unit is Adj + Ctl) { + return ObliviousAmplitudeAmplificationFromStatePreparation( + phases, startStateOracle, signalOracle, idxFlagQubit + ); + } + + /// # Deprecated + /// Please use @"microsoft.quantum.amplitudeamplification.amplitudeamplificationfrompartialreflections". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.AmplitudeAmplificationFromPartialReflections") + function AmpAmpByReflectionPhases( + phases : ReflectionPhases, + startStateReflection : ReflectionOracle, + targetStateReflection : ReflectionOracle + ) + : (Qubit[] => Unit is Adj + Ctl) { + return AmplitudeAmplificationFromPartialReflections( + phases, startStateReflection, targetStateReflection + ); + } + + /// # Deprecated + /// Please use @"microsoft.quantum.amplitudeamplification.amplitudeamplificationfromstatepreparation". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.AmplitudeAmplificationFromStatePreparation") + function AmpAmpByOraclePhases( + phases : ReflectionPhases, + stateOracle : StateOracle, + idxFlagQubit : Int + ) + : (Qubit[] => Unit is Adj + Ctl) { + return AmplitudeAmplificationFromStatePreparation( + phases, stateOracle, idxFlagQubit + ); + } + + /// # Deprecated + /// Please use @"microsoft.quantum.amplitudeamplification.standardamplitudeamplification". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.StandardAmplitudeAmplification") + function AmpAmpByOracle( + nIterations : Int, + stateOracle : StateOracle, + idxFlagQubit : Int + ) + : (Qubit[] => Unit is Adj + Ctl) { + return StandardAmplitudeAmplification(nIterations, stateOracle, idxFlagQubit); + } + + + /// # Deprecated + /// Please use @"microsoft.quantum.amplitudeamplification.applyfixedpointamplification". + @Deprecated("Microsoft.Quantum.AmplitudeAmplification.ApplyFixedPointAmplification") + operation AmpAmpRUSByOracle(statePrepOracle : StateOracle, startQubits : Qubit[]) + : Unit { + ApplyFixedPointAmplification(statePrepOracle, startQubits); + } + +} diff --git a/Standard/src/AmplitudeAmplification/StandardAlgorithms.qs b/Standard/src/AmplitudeAmplification/StandardAlgorithms.qs new file mode 100644 index 00000000000..9bedaeee3d8 --- /dev/null +++ b/Standard/src/AmplitudeAmplification/StandardAlgorithms.qs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.AmplitudeAmplification { + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Math; + + /// # Summary + /// Computes partial reflection phases for standard amplitude + /// amplification. + /// + /// # Input + /// ## nIterations + /// Number of amplitude amplification iterations to generate partial + /// reflection phases for. + /// + /// # Output + /// An operation that implements phases specified as partial reflections + /// + /// # Remarks + /// All phases are $\pi$, except for the first reflection about the start + /// state and the last reflection about the target state, which are $0$. + function StandardReflectionPhases(nIterations : Int) : ReflectionPhases { + let commonPhases = ConstantArray(nIterations, PI()); + let targetPhases = commonPhases + [0.0]; + let startPhases = [0.0] + commonPhases; + return ReflectionPhases(startPhases, targetPhases); + } + + // We use the phases in "Fixed-Point Amplitude Amplification with an + // Optimal Number of Queires" [YoderLowChuang2014] + // See also "Methodology of composite quantum gates" [LowYoderChuang2016] + // for phases in the `RotationPhases` format + + /// # Summary + /// Computes partial reflection phases for fixed-point amplitude + /// amplification. + /// + /// # Input + /// ## nQueries + /// Number of queries to the state preparation oracle. Must be an odd + /// integer. + /// ## successMin + /// Target minimum success probability. + /// + /// # Output + /// Array of phases that can be used in fixed-point amplitude amplification + /// quantum algorithm implementation. + /// + /// # References + /// We use the phases in "Fixed-Point Amplitude Amplification with + /// an Optimal Number of Queries" + /// - [YoderLowChuang2014](https://arxiv.org/abs/1409.3305) + /// See also "Methodology of composite quantum gates" + /// - [LowYoderChuang2016](https://arxiv.org/abs/1603.03996) + /// for phases in the `RotationPhases` format. + function FixedPointReflectionPhases(nQueries : Int, successMin : Double) + : ReflectionPhases { + let twoPi = 2.0 * PI(); + mutable phasesRot = new Double[nQueries]; + let nQueriesDouble = IntAsDouble(nQueries); + set phasesRot w/= 0 <- 0.0; + let beta = Cosh((1.0 / nQueriesDouble) * ArcCosh(Sqrt(successMin))); + let alpha = Sqrt(1.0 - beta * beta); + + for (idxPhases in 1 .. nQueries - 1) { + set phasesRot w/= idxPhases <- + phasesRot[idxPhases - 1] + + 2.0 * ArcTan( + Tan(twoPi * IntAsDouble(idxPhases) / nQueriesDouble) * alpha + ); + } + + return RotationPhasesAsReflectionPhases(RotationPhases(phasesRot)); + } + +} diff --git a/Standard/src/AmplitudeAmplification/Types.qs b/Standard/src/AmplitudeAmplification/Types.qs index 57f3fa2d007..5addb42ddfa 100644 --- a/Standard/src/AmplitudeAmplification/Types.qs +++ b/Standard/src/AmplitudeAmplification/Types.qs @@ -7,9 +7,14 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// Phases for a sequence of partial reflections in amplitude amplification. /// /// # Remarks - /// The first parameter is an array of phases for reflection about the start state. The second parameter is an array of phases for reflection about the target state. + /// The first parameter is an array of phases for reflection about the + /// start state. The second parameter is an array of phases for reflection + /// about the target state. /// Both arrays must be of equal length. Note that in many cases, the first phase about the start state and last phase about the target state introduces a global phase shift and may be set to $0$. - newtype ReflectionPhases = (Double[], Double[]); + newtype ReflectionPhases = ( + AboutStart: Double[], + AboutTarget: Double[] + ); /// # Summary /// Phases for a sequence of single-qubit rotations in amplitude amplification. diff --git a/Standard/src/Oracles/Convert.qs b/Standard/src/Oracles/Convert.qs index 0f9650c653a..3b804227e36 100644 --- a/Standard/src/Oracles/Convert.qs +++ b/Standard/src/Oracles/Convert.qs @@ -6,20 +6,13 @@ namespace Microsoft.Quantum.Oracles { /// # Summary /// Implementation of . - operation _ObliviousOracleFromDeterministicStateOracle (ancillaOracle : DeterministicStateOracle, signalOracle : ObliviousOracle, ancillaRegister : Qubit[], systemRegister : Qubit[]) : Unit - { - body (...) - { - ancillaOracle!(ancillaRegister); - signalOracle!(ancillaRegister, systemRegister); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; + operation _ObliviousOracleFromDeterministicStateOracle(ancillaOracle : DeterministicStateOracle, signalOracle : ObliviousOracle, ancillaRegister : Qubit[], systemRegister : Qubit[]) + : Unit is Adj + Ctl { + ancillaOracle!(ancillaRegister); + signalOracle!(ancillaRegister, systemRegister); } - - + + /// # Summary /// Combines the oracles `DeterministicStateOracle` and `ObliviousOracle`. /// @@ -35,27 +28,19 @@ namespace Microsoft.Quantum.Oracles { /// # See Also /// - Microsoft.Quantum.Canon.DeterministicStateOracle /// - Microsoft.Quantum.Canon.ObliviousOracle - function ObliviousOracleFromDeterministicStateOracle (ancillaOracle : DeterministicStateOracle, signalOracle : ObliviousOracle) : ObliviousOracle - { + function ObliviousOracleFromDeterministicStateOracle (ancillaOracle : DeterministicStateOracle, signalOracle : ObliviousOracle) : ObliviousOracle { return ObliviousOracle(_ObliviousOracleFromDeterministicStateOracle(ancillaOracle, signalOracle, _, _)); } - - + + /// # Summary /// Implementation of . - operation _DeterministicStateOracleFromStateOracle (idxFlagQubit : Int, stateOracle : StateOracle, startQubits : Qubit[]) : Unit - { - body (...) - { - stateOracle!(idxFlagQubit, startQubits); - } - - adjoint invert; - controlled distribute; - controlled adjoint distribute; + operation _DeterministicStateOracleFromStateOracle (idxFlagQubit : Int, stateOracle : StateOracle, startQubits : Qubit[]) + : Unit is Adj + Ctl { + stateOracle!(idxFlagQubit, startQubits); } - - + + /// # Summary /// Converts an oracle of type `StateOracle` to `DeterministicStateOracle`. /// @@ -79,8 +64,8 @@ namespace Microsoft.Quantum.Oracles { { return DeterministicStateOracle(_DeterministicStateOracleFromStateOracle(idxFlagQubit, stateOracle, _)); } - - + + /// # Summary /// Implementation of . operation _StateOracleFromDeterministicStateOracle (idxFlagQubit : Int, oracleStateDeterministic : DeterministicStateOracle, qubits : Qubit[]) : Unit @@ -89,13 +74,13 @@ namespace Microsoft.Quantum.Oracles { { oracleStateDeterministic!(qubits); } - + adjoint invert; controlled distribute; controlled adjoint distribute; } - - + + /// # Summary /// Converts an oracle of type `DeterministicStateOracle` to `StateOracle`. /// @@ -115,8 +100,8 @@ namespace Microsoft.Quantum.Oracles { { return StateOracle(_StateOracleFromDeterministicStateOracle(_, deterministicStateOracle, _)); } - - + + /// # Summary /// Implementation of . operation ReflectionOracleFromDeterministicStateOracleImpl (phase : Double, oracle : DeterministicStateOracle, systemRegister : Qubit[]) : Unit @@ -125,20 +110,20 @@ namespace Microsoft.Quantum.Oracles { { ApplyWithCA(Adjoint oracle!, RAll0(phase, _), systemRegister); } - + adjoint invert; controlled distribute; controlled adjoint distribute; } - - + + /// # Summary /// Constructs reflection about a given state from an oracle. - /// - /// Given the oracle $O$ of type + /// + /// Given the oracle $O$ of type /// , - /// the result of this function is a reflection around the state $\ket{\psi}$ - /// where $O\ket{0} = \ket{\psi}$. + /// the result of this function is a reflection around the state $\ket{\psi}$ + /// where $O\ket{0} = \ket{\psi}$. /// /// # Input /// ## oracle diff --git a/Standard/src/Oracles/Types.qs b/Standard/src/Oracles/Types.qs index a3c395ffd95..0350cd20125 100644 --- a/Standard/src/Oracles/Types.qs +++ b/Standard/src/Oracles/Types.qs @@ -14,7 +14,9 @@ namespace Microsoft.Quantum.Oracles { /// This oracle $O = \boldone - (1 - e^{i \phi}) \ket{\psi}\bra{\psi}$ /// performs a partial reflection by a phase $\phi$ about a single pure state /// $\ket{\psi}$. - newtype ReflectionOracle = ((Double, Qubit[]) => Unit is Adj + Ctl); + newtype ReflectionOracle = ( + ApplyReflection: ((Double, Qubit[]) => Unit is Adj + Ctl) + ); // This oracle O|s>_a|ψ>_s = λ |t>_a U |ψ>_s + ... acts on the ancilla state |s>_a to implement the unitary U on any system state |ψ>_s with amplitude λ in the |t>_a basis. @@ -28,7 +30,7 @@ namespace Microsoft.Quantum.Oracles { /// # Remarks /// This oracle defined by /// $$ - ///O\ket{s}\_a\ket{\psi}\_s= \lambda\ket{t}\_a U \ket{\psi}\_s + \sqrt{1-|\lambda|^2}\ket{t^\perp}\_a\cdots + /// O\ket{s}\_a\ket{\psi}\_s= \lambda\ket{t}\_a U \ket{\psi}\_s + \sqrt{1-|\lambda|^2}\ket{t^\perp}\_a\cdots /// $$ /// acts on the ancilla state $\ket{s}\_a$ to implement the unitary $U$ on any system state $\ket{\psi}\_s$ with amplitude $\lambda$ in the basis flagged by $\ket{t}\_a$. /// The first parameter is the qubit register of $\ket{s}\_a$. The second parameter is the qubit register of $\ket{\psi}\_s$. @@ -64,15 +66,15 @@ namespace Microsoft.Quantum.Oracles { /// # Summary /// Represents a discrete-time oracle. - /// - /// This is an oracle that implements $U^m$ for a fixed operation $U$ + /// + /// This is an oracle that implements $U^m$ for a fixed operation $U$ /// and a non-negative integer $m$. newtype DiscreteOracle = ((Int, Qubit[]) => Unit is Adj + Ctl); /// # Summary /// Represents a continuous-time oracle. - /// - /// This is an oracle that implements + /// + /// This is an oracle that implements /// $U(\delta t) : \ket{\psi(t)} \mapsto \ket{\psi(t + \delta t)}$ /// for all times $t$, where $U$ is a fixed operation, and where /// $\delta t$ is a non-negative real number. diff --git a/Standard/src/Preparation/UniformSuperposition.qs b/Standard/src/Preparation/UniformSuperposition.qs index 6cd27f4fdb8..177c43dcef9 100644 --- a/Standard/src/Preparation/UniformSuperposition.qs +++ b/Standard/src/Preparation/UniformSuperposition.qs @@ -9,12 +9,12 @@ namespace Microsoft.Quantum.Preparation { open Microsoft.Quantum.AmplitudeAmplification; open Microsoft.Quantum.Oracles; open Microsoft.Quantum.Math; - + /// # Summary - /// Creates a uniform superposition over states that encode 0 through `nIndices`. - /// + /// Creates a uniform superposition over states that encode 0 through `nIndices`. + /// /// That is, this unitary $U$ creates a uniform superposition over all number states - /// $0$ to $M-1$, given an input state $\ket{0\cdots 0}$. In other words, + /// $0$ to $M-1$, given an input state $\ket{0\cdots 0}$. In other words, /// $$ /// \begin{align} /// U\ket{0}=\frac{1}{\sqrt{M}}\sum_{j=0}^{M-1}\ket{j}. @@ -57,7 +57,7 @@ namespace Microsoft.Quantum.Preparation { let qubits = flagQubit + targetQubits; let stateOracle = StateOracle(PrepareUniformSuperposition_(nIndices, nQubits, _, _)); - (AmpAmpByOracle(1, stateOracle, 0))(qubits); + (StandardAmplitudeAmplification(1, stateOracle, 0))(qubits); ApplyToEachCA(X, flagQubit); } @@ -88,5 +88,5 @@ namespace Microsoft.Quantum.Preparation { controlled auto; adjoint controlled auto; } - + } From 747ef78745ad38aac69b4a86142acfb79b063aee Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 2 Jan 2020 13:39:37 -0800 Subject: [PATCH 07/17] Begin moving classifier structure creation to Q#. --- MachineLearning/src/Runtime/Convert.qs | 109 ++++++++++++----------- MachineLearning/src/Runtime/Structure.qs | 75 ++++++++++++++++ 2 files changed, 131 insertions(+), 53 deletions(-) create mode 100644 MachineLearning/src/Runtime/Structure.qs diff --git a/MachineLearning/src/Runtime/Convert.qs b/MachineLearning/src/Runtime/Convert.qs index bcebf05d77e..9149c146e3b 100644 --- a/MachineLearning/src/Runtime/Convert.qs +++ b/MachineLearning/src/Runtime/Convert.qs @@ -1,63 +1,66 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon; - open Microsoft.Quantum.Math; + open Microsoft.Quantum.Math; - function unFlattenSchedule(sc : Int[][]) : SamplingSchedule - { - mutable ret = new Range[0]; - for (flattenedRange in sc) { - set ret += [flattenedRange[0]..flattenedRange[1]..flattenedRange[2]]; - } - return SamplingSchedule(ret); - } + function unFlattenSchedule(sc : Int[][]) : SamplingSchedule + { + mutable ret = new Range[0]; + for (flattenedRange in sc) { + set ret += [flattenedRange[0]..flattenedRange[1]..flattenedRange[2]]; + } + return SamplingSchedule(ret); + } - function unFlattenLabeledSamples(dat:Double[][], labs:Int[]) : LabeledSample[] { - mutable cnt = MinI(Length(dat), Length(labs)); - mutable ret = new LabeledSample[cnt]; - for (j in 0..(cnt - 1)) { - set ret w/= j <- LabeledSample(dat[j], labs[j]); - } - return ret; - } + function unFlattenLabeledSamples(dat:Double[][], labs:Int[]) : LabeledSample[] { + mutable cnt = MinI(Length(dat), Length(labs)); + mutable ret = new LabeledSample[cnt]; + for (j in 0..(cnt - 1)) { + set ret w/= j <- LabeledSample(dat[j], labs[j]); + } + return ret; + } - /// Debugging prop - operation unFlattenPauli(p:Int): Pauli - { - if (p==1) - { - return PauliX; - } - if (p==2) - { - return PauliY; - } - if (p==3) - { - return PauliZ; - } - return PauliI; - } + /// Debugging prop + operation unFlattenPauli(p:Int): Pauli + { + if (p==1) + { + return PauliX; + } + if (p==2) + { + return PauliY; + } + if (p==3) + { + return PauliZ; + } + return PauliI; + } - /// Debugging prop - /// upcasting controlled rotation in flat representation (paramIx,pauliIx,gateSpan) - operation unFlattenControlledRotation(cod:Int[]): ControlledRotation { - return ControlledRotation( - GateSpan( - cod[2], cod[3...] - ), - unFlattenPauli(cod[1]), - cod[0] - ); - } + /// Debugging prop + /// upcasting controlled rotation in flat representation (paramIx,pauliIx,gateSpan) + operation unFlattenControlledRotation(cod:Int[]): ControlledRotation { + return ControlledRotation( + GateSpan( + cod[2], cod[3...] + ), + unFlattenPauli(cod[1]), + cod[0] + ); + } - /// Debugging prop - operation unFlattenGateSequence(seq: Int[][]) : GateSequence { - mutable tmp = new ControlledRotation[Length(seq)]; - for (icr in 0..(Length(seq) - 1)) { - set tmp w/= icr <- unFlattenControlledRotation(seq[icr]); - } - return GateSequence(tmp); - } + /// Debugging prop + operation unFlattenGateSequence(seq: Int[][]) : GateSequence { + mutable tmp = new ControlledRotation[Length(seq)]; + for (icr in 0..(Length(seq) - 1)) { + set tmp w/= icr <- unFlattenControlledRotation(seq[icr]); + } + return GateSequence(tmp); + } } \ No newline at end of file diff --git a/MachineLearning/src/Runtime/Structure.qs b/MachineLearning/src/Runtime/Structure.qs new file mode 100644 index 00000000000..e0793e24b3a --- /dev/null +++ b/MachineLearning/src/Runtime/Structure.qs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.MachineLearning { + + open Microsoft.Quantum.Arrays; + + function _UncontrolledSpanSequence(idxsQubits : Int[]) : GateSpan[] { + return Mapped( + GateSpan(_, new Int[0]), + idxsQubits + ); + } + + function _CallFlipped<'TInput1, 'TInput2, 'TOutput>( + fn : (('TInput1, 'TInput2) -> 'TOutput), + y : 'TInput2, x : 'TInput1 + ) : 'TOutput { + return fn(x, y); + } + + function _Flipped<'TInput1, 'TInput2, 'TOutput>( + fn : (('TInput1, 'TInput2) -> 'TOutput) + ) : (('TInput2, 'TInput1) -> 'TOutput) { + return _CallFlipped(fn, _, _); + } + + function LocalRotationsLayer(nQubits : Int, axis : Pauli) : GateSequence { + // [parameterIndex, pauliCode, targetQubit\,sequence of control qubits\] + return GateSequence(Mapped( + _Flipped(ControlledRotation(_, axis, _)), + Enumerated( + _UncontrolledSpanSequence(SequenceI(0, nQubits - 1)) + ) + )); + } + + + function PartialRotationsLayer(idxsQubits : Int[], axis : Pauli) : GateSequence { + // [parameterIndex, pauliCode, targetQubit\,sequence of control qubits\] + return GateSequence(Mapped( + _Flipped(ControlledRotation(_, axis, _)), + Enumerated( + _UncontrolledSpanSequence(idxsQubits) + ) + )); + } + + function CyclicEntanglingLayer(nQubits : Int, axis : Pauli, stride : Int) : GateSequence { + mutable rotations = new ControlledRotation[0]; + for (idxTarget in 0..nQubits - 1) { + set rotations += [ControlledRotation( + GateSpan( + idxTarget, + [idxTarget + stride % nQubits] + ), + axis, idxTarget + )]; + } + return GateSequence(rotations); + } + + function CombinedGateSequence(layers : GateSequence[]) : GateSequence { + mutable combined = (Head(layers))!; + mutable offset = Length(combined); + for (layer in Rest(layers)) { + for (gate in layer!) { + set combined += [gate w/ Index <- gate::Index + offset]; + } + set offset += Length(layer!); + } + return GateSequence(combined); + } + +} \ No newline at end of file From 3553ad74390140858225afbce97a955d54c05a83 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 2 Jan 2020 11:56:28 -0800 Subject: [PATCH 08/17] Moving example datasets into new namespace. --- MachineLearning/src/Runtime/{ => Datasets}/Examples.qs | 5 ++++- .../src/Runtime/Datasets/Properties/NamespaceInfo.qs | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) rename MachineLearning/src/Runtime/{ => Datasets}/Examples.qs (97%) create mode 100644 MachineLearning/src/Runtime/Datasets/Properties/NamespaceInfo.qs diff --git a/MachineLearning/src/Runtime/Examples.qs b/MachineLearning/src/Runtime/Datasets/Examples.qs similarity index 97% rename from MachineLearning/src/Runtime/Examples.qs rename to MachineLearning/src/Runtime/Datasets/Examples.qs index b7c3ccd4129..dd2e688b52c 100644 --- a/MachineLearning/src/Runtime/Examples.qs +++ b/MachineLearning/src/Runtime/Datasets/Examples.qs @@ -1,4 +1,7 @@ -namespace Microsoft.Quantum.MachineLearning { +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.MachineLearning.Datasets { open Microsoft.Quantum.Primitive; open Microsoft.Quantum.Convert; open Microsoft.Quantum.Math; diff --git a/MachineLearning/src/Runtime/Datasets/Properties/NamespaceInfo.qs b/MachineLearning/src/Runtime/Datasets/Properties/NamespaceInfo.qs new file mode 100644 index 00000000000..b1559562869 --- /dev/null +++ b/MachineLearning/src/Runtime/Datasets/Properties/NamespaceInfo.qs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/// # Summary +/// TODO +namespace Microsoft.Quantum.MachineLearning.Datasets { } From b1e762daa1e181f21290ca9dcf302c8fe4b80501 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 2 Jan 2020 16:59:53 -0800 Subject: [PATCH 09/17] Fix datasets used in layered structure demo. --- .../Datasets/{Examples.qs => IrisDataset.qs} | 8 +- .../src/Runtime/Datasets/WineDataset.qs | 190 ++++++++++++++++++ 2 files changed, 191 insertions(+), 7 deletions(-) rename MachineLearning/src/Runtime/Datasets/{Examples.qs => IrisDataset.qs} (97%) create mode 100644 MachineLearning/src/Runtime/Datasets/WineDataset.qs diff --git a/MachineLearning/src/Runtime/Datasets/Examples.qs b/MachineLearning/src/Runtime/Datasets/IrisDataset.qs similarity index 97% rename from MachineLearning/src/Runtime/Datasets/Examples.qs rename to MachineLearning/src/Runtime/Datasets/IrisDataset.qs index dd2e688b52c..0f7cc0101db 100644 --- a/MachineLearning/src/Runtime/Datasets/Examples.qs +++ b/MachineLearning/src/Runtime/Datasets/IrisDataset.qs @@ -2,9 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.MachineLearning.Datasets { - open Microsoft.Quantum.Primitive; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Math; + open Microsoft.Quantum.MachineLearning; operation IrisTrainingData() : LabeledSample[] { return [LabeledSample(([0.581557, 0.562824, 0.447721, 0.380219], 1)), @@ -90,8 +88,4 @@ namespace Microsoft.Quantum.MachineLearning.Datasets { ]; } - operation Examples () : Unit - { - - } } diff --git a/MachineLearning/src/Runtime/Datasets/WineDataset.qs b/MachineLearning/src/Runtime/Datasets/WineDataset.qs new file mode 100644 index 00000000000..3c944183a8f --- /dev/null +++ b/MachineLearning/src/Runtime/Datasets/WineDataset.qs @@ -0,0 +1,190 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.MachineLearning.Datasets { + open Microsoft.Quantum.MachineLearning; + + operation WineData() : LabeledSample[] { + return [ + LabeledSample([0.363205411076437,0.0638668636484459,0.178532471398649,-0.0288976056473681,0.433507480753481,0.26765452507215,0.295933366591769,0.0407618624310926,0.335961380122613,0.183046369886591,0.197761713895692,0.42801676498221,0.286786326879289,0.102563320682669,0.102563320682669,0.102563320682669], 1), + LabeledSample([0.249938938530866,0.103806961963521,0.0288119563511447,-0.316327610625978,0.213915431364644,0.331181226646993,0.358247971682033,0.0243452672750831,0.102474003311389,0.142145109786172,0.289810795079708,0.452985093276961,0.397496120059943,0.145592040692672,0.145592040692672,0.145592040692672], 1), + LabeledSample([0.18017551770934,0.159954186450334,0.330335005051653,0.11029657222382,0.172026075662364,0.285685353685049,0.3437678958266,0.0687101235918643,0.503546189307832,0.198186899162854,0.204255658590153,0.289189504133849,0.363892624800524,0.109472606661304,0.109472606661304,0.109472606661304], 1), + LabeledSample([0.3478185280261,0.0855741081675129,0.193962405871525,0.0214750733479136,0.256731607736543,0.454743707959586,0.32073047384103,-0.00578276910401499,0.274962030580035,0.291023282748096,0.0739296574471514,0.294961529988612,0.424228072429038,0.091790139403591,0.091790139403591,0.091790139403591], 1), + LabeledSample([0.362297632590457,0.0713765952097998,0.1918508326995,-0.0471194731007316,0.279898551657966,0.380054980216169,0.348218985017828,0.113013918394729,0.255594598610856,0.259339012361842,0.206751611476739,0.206506348822603,0.466330974472638,0.103865658362098,0.103865658362098,0.103865658362098], 1), + LabeledSample([0.456363512237805,0.0989267315498482,0.220396293818176,-0.0848977157377709,0.126570706690875,0.231455369932631,0.253057526681058,0.0748906926624935,0.296662776679902,0.183096193491806,0.215186020544714,0.415101672494017,0.45173680541366,0.119319816525617,0.119319816525617,0.119319816525617], 1), + LabeledSample([0.365824230547686,0.134384795182974,0.304649953841435,0.0652321211089234,0.408030734314465,0.244219941368521,0.237852026774996,0.0838599153918433,0.0708419429859215,0.158763660222825,0.231785452457851,0.392781508852428,0.429930004244632,0.112903947819199,0.112903947819199,0.112903947819199], 1), + LabeledSample([0.566183478055546,0.0654724741578849,0.0439622864967305,-0.119206110391732,0.143004569028705,0.320916045012887,0.340893691950237,0.0630283295835976,0.305745022199024,0.184756786750361,0.267797291682324,0.244495204044942,0.333036138702624,0.122972758364531,0.122972758364531,0.122972758364531], 1), + LabeledSample([0.337713046108315,0.122718945059575,0.10700561052042,0.0764645126338355,0.201946721703765,0.300339986693404,0.331847112159928,-0.0299072363915305,0.357482732812817,0.189234861665545,0.330277114346835,0.269442761691643,0.484863724448287,0.10199748278123,0.10199748278123,0.10199748278123], 1), + LabeledSample([0.466701129863441,0.0454693396504955,0.161149317242173,0.0326284696596175,0.133694628665751,0.177107619792893,0.278006483001738,0.0233203461257999,0.201144615896292,0.191636316683084,0.381999714367244,0.268736937921384,0.521861643126541,0.139462703109841,0.139462703109841,0.139462703109841], 1), + LabeledSample([0.352356775250346,0.0849147066288441,0.213994619198652,-0.0143836459418002,0.0452884898165237,0.283231761082382,0.322192973337249,0.0671114837383224,0.268871309289799,0.230329073599442,0.342318391134332,0.273703498451036,0.513006853430941,0.130939282823474,0.130939282823474,0.130939282823474], 1), + LabeledSample([0.43089413940549,0.0626199622575399,0.147535243701546,-0.201497441491844,0.0531208270245816,0.316671679326467,0.364741512975659,0.205099273306104,0.444154125496589,0.157464852880314,0.312671915003017,0.168320603210868,0.306105868416982,0.096560575593511,0.096560575593511,0.096560575593511], 1), + LabeledSample([0.272726407517705,0.0827168324333284,0.3496106940634,0.0446612423026689,0.296538163194931,0.299452238244459,0.294137889421737,0.0690664590267155,0.12788722340928,0.313586218717624,0.376912296280345,0.225524110093736,0.426286381219746,0.110040339141755,0.110040339141755,0.110040339141755], 1), + LabeledSample([0.383572208467366,0.0935136576220856,0.343620408177357,0.168402125357628,0.367514242898029,0.27310051209359,0.313807941452454,0.101821494321014,0.257525175254316,0.224370057363687,0.22136861749585,0.165326053699488,0.391595143068333,0.104650184385657,0.104650184385657,0.104650184385657], 1), + LabeledSample([0.316013513913644,0.0493226285823722,0.306955303083295,0.179519413042103,0.334809905839043,0.328494083962476,0.375590411592675,0.198432370679759,0.203509333335944,0.267811707061401,0.277734218718739,0.158015615196535,0.343836981820164,0.111558803879491,0.111558803879491,0.111558803879491], 1), + LabeledSample([0.31870497106277,0.0429712614071499,0.184285151711081,0.00964542259308528,0.209961702784,0.342183874334946,0.378094966508491,0.0787814637408952,0.20026575558015,0.344191686729784,0.285912288149745,0.176960266353846,0.505227332666082,0.0918346293577422,0.0918346293577422,0.0918346293577422], 1), + LabeledSample([0.356307758352805,0.0571295107798862,0.103665767801926,-0.012079833971045,0.453569690442849,0.336083659933176,0.334421582101246,-0.00692790241244995,0.307010347549411,0.196965160324229,0.246333773806227,0.41175624147722,0.169625166567189,0.109966889006815,0.109966889006815,0.109966889006815], 1), + LabeledSample([0.161217748043416,0.432012087856065,0.378968684463582,0.131159855324296,0.217860878028004,0.226361121435969,0.255816095501333,0.00678340496692604,0.323664339685322,0.137120494937026,0.242891887659839,0.436933255666067,0.195077722155152,0.130180031547429,0.130180031547429,0.130180031547429], 1), + LabeledSample([0.33387321962864,0.104003734911291,0.174357166514354,0.0188598420614302,0.200238000417398,0.278477279672617,0.335197145956839,0.0359753128735102,0.222720512525599,0.076991773708088,0.301339874113075,0.552589883968051,0.339490864618573,0.127425890371198,0.127425890371198,0.127425890371198], 1), + LabeledSample([0.164804886510591,0.0722538432783593,0.333530926538808,0.0997386246383389,0.144057309090506,0.28478622392534,0.286789335102904,0.0251279078559012,0.174644396421027,0.103329402020434,0.336621180516676,0.538126003301765,0.387138650464392,0.150272467405704,0.150272467405704,0.150272467405704], 1), + LabeledSample([0.138045034940391,0.10096733243651,0.565457577461934,0.357529010586571,0.372975197652389,0.212164465546768,0.223324251871177,0.245882968670251,0.222005459488057,0.0440548078915432,0.236854156367615,0.257151478091355,0.167676962473548,0.0951383178498998,0.0951383178498998,0.0951383178498998], 1), + LabeledSample([0.27706228465463,0.0944690423993351,0.371279295793269,-0.0090237059702085,0.101794091444167,0.367202038390134,0.366416680746154,0.14682141141967,0.153385221675984,0.16810232470317,0.159181546018473,0.370233800319128,0.454471601718924,0.134936499639745,0.134936499639745,0.134936499639745], 1), + LabeledSample([0.317210982002182,0.106460924648269,0.033146499020418,0.0535834830689089,0.143461867556865,0.287506074549938,0.276972889518789,0.0472878373297268,0.147745460243886,0.117321269850464,0.302067517823741,0.305652499113775,0.63044189160374,0.167495270900221,0.167495270900221,0.167495270900221], 1), + LabeledSample([0.323782804937267,0.0967686336582948,0.413611657738741,0.150690255678227,0.243561977694651,0.328356719570779,0.307544863864273,0.15984164703184,0.214782154388153,0.117457351693143,0.361086484054943,0.346951270439723,0.238229898839817,0.111512154006688,0.111512154006688,0.111512154006688], 1), + LabeledSample([0.279349555106746,0.0370104144183211,0.334213378417837,0.282297751914523,0.165302668712666,0.321496686499494,0.331821540835722,0.0539160322994988,0.368686009342752,0.191790839601492,0.301258189226166,0.179073860160303,0.395943808377124,0.105194017606742,0.105194017606742,0.105194017606742], 1), + LabeledSample([0.27005015291199,0.0630772889648215,0.154616485583782,0.138130446588243,0.235268666883373,0.310026088106195,0.346841534612754,-0.0331329802316931,0.27231483724987,0.293017836931826,0.253125380319702,0.23158729460557,0.539645635992194,0.112998758441953,0.112998758441953,0.112998758441953], 1), + LabeledSample([0.346713411485213,0.105012869661639,0.184811072491187,0.0548181961587539,0.253625600781446,0.237872750892395,0.318961201449689,0.271339376712739,0.332372860697775,0.0850741828543554,0.420506007983091,0.274055170038427,0.333109503610011,0.135065944999207,0.135065944999207,0.135065944999207], 1), + LabeledSample([0.271022354903467,0.0390745208209509,0.317889164962927,0.139509100089267,0.474001987855805,0.294622995319019,0.243367356561056,0.29314414864518,0.0882580916700038,0.163164893944254,0.323990267781163,0.229579697508733,0.354597817947863,0.100055953996837,0.100055953996837,0.100055953996837], 1), + LabeledSample([0.296171884335753,0.100614775138648,0.218752326936746,0.244152694965527,0.196663727926573,0.319415898270834,0.37104777890512,0.0223818870342515,0.291890527888441,0.19251205199505,0.258089258396546,0.435586076048342,0.288896417266678,0.133850434708707,0.133850434708707,0.133850434708707], 1), + LabeledSample([0.252373671257443,0.0723018808380158,0.532596533272876,-0.044098308106594,0.338217719219032,0.293745858093293,0.3187720066088,0.147760962531924,0.123245390734908,0.151752742109324,0.304201799039272,0.250586710453292,0.269209619708056,0.135799995890695,0.135799995890695,0.135799995890695], 1), + LabeledSample([0.231647849319649,0.0870580778073824,0.379819510930802,0.119683262892996,0.201958323330672,0.291859534446306,0.318243685177281,0.0818257194381086,0.177409914789709,0.142552607383287,0.38749726469097,0.206569993185964,0.474496045065283,0.159647804264275,0.159647804264275,0.159647804264275], 1), + LabeledSample([0.255247226696605,0.06041599445067,-0.00255968322164522,-0.0557623660678594,0.217229013118827,0.294756572623486,0.393362717775018,0.0682465918139527,0.160216510643726,0.0927370291446394,0.481064257912117,0.285307935542058,0.446167701011294,0.171719265613694,0.171719265613694,0.171719265613694], 1), + LabeledSample([0.275026515547499,0.0727400792013697,0.128762793923213,-0.00279155677458797,0.374437692908058,0.396130353966779,0.375086796481439,0.127101363132371,0.397509763863738,0.245200476434608,0.159660362687242,0.358672446067021,0.187892640693357,0.116812751455572,0.116812751455572,0.116812751455572], 1), + LabeledSample([0.311461752837503,0.502549497625733,0.0136433770988428,0.163056233779351,0.0668046663611401,0.272607631039843,0.350031792999902,0.0420992128778312,0.1808955506979,0.136019537594797,0.166608583769084,0.34215084378215,0.397280719417458,0.149116970955777,0.149116970955777,0.149116970955777], 1), + LabeledSample([0.335978144067938,0.0983210378580677,0.298097188286758,-0.0620608660613614,0.180728542341856,0.415699424320707,0.413265127196523,-0.0999159645032936,0.203949116092578,0.189765659712172,0.106979744949575,0.395413251109613,0.336768787203074,0.115010614246019,0.115010614246019,0.115010614246019], 1), + LabeledSample([0.267254400330717,0.530864539992977,0.148894591250536,0.0799552165600163,0.265475033620942,0.336749597682553,0.340364890972572,0.128256883977383,0.249894873995414,0.144049494069581,0.0831136106174955,0.343047025915129,0.164850715568234,0.14950754712276,0.14950754712276,0.14950754712276], 1), + LabeledSample([0.409535358236058,0.423821376417793,0.209554705754144,0.132754750116135,0.302864073191331,0.3178875886134,0.26924524714014,0.0733184371664153,0.0732958296204928,0.178502810621827,0.101371504171095,0.346751724293268,0.334343976936978,0.116814815828549,0.116814815828549,0.116814815828549], 1), + LabeledSample([0.411838215785579,0.329697985039249,0.101980670189617,-0.0118834750397091,0.181041987677738,0.391008260201782,0.328985525228739,0.0305415683419268,0.326811408573422,0.141709171615972,0.208590524286652,0.345418151382434,0.302489845499348,0.108179366027653,0.108179366027653,0.108179366027653], 1), + LabeledSample([0.365420884131811,0.0721780607230944,0.0113078420011285,-0.0135763788382327,0.194210964330357,0.405316516129519,0.414348135414213,-0.0504648498369757,0.357633344975218,0.257048685083646,0.13808777164507,0.366864443994308,0.3020895160535,0.123590452351992,0.123590452351992,0.123590452351992], 1), + LabeledSample([0.4006706465907,0.123743705191569,0.191332850350624,0.13232426073567,0.214876890555312,0.302289422501197,0.325178974246259,0.103811797461618,0.424125864699886,0.259450220277008,0.255979506564098,0.215885956908381,0.335711269129357,0.121012196145575,0.121012196145575,0.121012196145575], 1), + LabeledSample([0.165010086109523,0.0737493375917614,-0.0379955147007807,-0.188436093151012,0.0741761269601386,0.276461086643119,0.361942753242732,-0.0987966298943638,0.552050688643421,0.316782308151838,0.276026551516262,0.240036696328028,0.360509719502187,0.113722177892932,0.113722177892932,0.113722177892932], 1), + LabeledSample([0.322538934941513,0.0620906870973839,0.30117864344653,0.0462124741572112,0.0975246212047387,0.208157123222826,0.317250883177015,-0.0333862138801274,0.372973198362888,0.200289943745998,0.361594501059424,0.347288303861623,0.41855376578972,0.113862402088516,0.113862402088516,0.113862402088516], 1), + LabeledSample([0.285886366617401,0.0684810811583678,0.171380327231864,-0.0984477110534525,0.263309088994922,0.509940512787294,0.390809494758036,0.0871231538320202,0.224056703303123,0.27312555178283,0.176819633724361,0.286947787961415,0.33981923310787,0.101558439774049,0.101558439774049,0.101558439774049], 1), + LabeledSample([0.297296105273249,0.0946255708393242,0.334838488001863,0.0395700727110477,0.327258215505474,0.333258754902954,0.272944821496624,0.181405049197193,0.187812762259515,0.240783305911936,0.271469879527389,0.23461272684689,0.453599279540649,0.109042577429231,0.109042577429231,0.109042577429231], 1), + LabeledSample([0.269540789063922,0.0742425940934737,0.217552306967554,0.208824725336092,0.355277219636782,0.339660238719292,0.28494135945769,-0.0599238355949813,0.421647315225907,0.249123651029931,0.17789873992421,0.269695620986192,0.347813079058712,0.114482784095866,0.114482784095866,0.114482784095866], 1), + LabeledSample([0.404625688519658,0.0700267657079979,0.120472577645772,0.00219084178798748,0.379823180206969,0.402241148897651,0.321584301076104,0.0192020687698115,0.300130523389213,0.259466069761067,0.149793101053706,0.336182443721132,0.273109601918351,0.114834162473097,0.114834162473097,0.114834162473097], 1), + LabeledSample([0.227072284249524,0.115957953910278,0.37165420977739,0.0283164248068712,0.202551129726376,0.369900783939047,0.378352967053039,0.0898969763675667,0.202299134157373,0.243962099768371,0.256021152092969,0.238164818457677,0.447570516715675,0.121031883725162,0.121031883725162,0.121031883725162], 1), + LabeledSample([0.290513586918522,0.0288038623450319,0.232722173051494,0.021033401910653,0.251796587067657,0.434955256846487,0.412889359036101,-0.0703239873536929,0.290647100154398,0.27851991038108,0.109312082995173,0.223464411693962,0.414532651593511,0.110132685819811,0.110132685819811,0.110132685819811], 1), + LabeledSample([0.0273732600379447,-0.02558983433752,0.146982261055396,-0.0171273637178906,0.245008029292831,0.145781322353099,0.0150027880856774,0.690117179315347,-0.235663375971501,0.0411885264630709,0.504871112162429,-0.0657043501474764,0.171917154578638,0.155916290692338,0.155916290692338,0.155916290692338], 0), + LabeledSample([0.14521829713485,0.0343145533427399,-0.0882700952843158,0.046881072753417,0.294417347555922,0.173933905048393,0.11006649526536,0.656276502917861,-0.195721607174358,0.371766803766992,0.311380637843488,-0.117177743753181,0.0182118464611618,0.200382095730729,0.200382095730729,0.200382095730729], 0), + LabeledSample([0.486150877899874,0.00559857896218937,-0.185459353006127,0.142963157333992,0.163338134268417,0.199595799090423,0.207347908114734,0.163595452807656,-0.132850998237727,0.115223299672758,0.593717710005564,0.227279405422781,0.168328497429296,0.190701302816799,0.190701302816799,0.190701302816799], 0), + LabeledSample([0.0347134978427943,-0.0176692432854786,0.0428663618372316,0.166147230327836,0.0199498801884673,0.587805806576238,0.414442262124174,-0.089951397936977,0.310786812212336,0.14386213316866,0.429791189469868,0.285833283598367,-0.00578702083956967,0.140870696057391,0.140870696057391,0.140870696057391], 0), + LabeledSample([0.0386819482458521,-0.00349076506069984,0.381811856855455,0.124425737980637,0.198577221607227,0.276458187744415,0.361810145149105,0.225008209783446,0.430255529024555,0.175415277085379,0.449550455932021,0.135796133960852,0.171703541737192,0.156975047542789,0.156975047542789,0.156975047542789], 0), + LabeledSample([0.20899462334405,-0.0376063196642258,-0.287590562504126,-0.072418354993873,-0.104348662777656,0.404167598140499,0.410032520012738,0.0224411784874926,0.4361911298395,0.210242686845805,0.325742509559517,0.357264669291933,0.0428954946477981,0.134205015481038,0.134205015481038,0.134205015481038], 0), + LabeledSample([0.046621360661699,-0.0139688049328171,-0.183993426989613,0.271925965129567,-0.147104300632575,0.202242593318163,0.261960196367961,0.0534138805587944,0.0175423400165548,0.221129648306528,0.459211673437115,0.619552478506155,0.0671293292709748,0.189193942866217,0.189193942866217,0.189193942866217], 0), + LabeledSample([0.314015665359685,-0.0592175725353615,0.218693323692968,0.0511307060843809,0.398061338436536,0.320739392818663,0.0628993958736532,0.560252330340949,-0.237506347153332,0.0319676779103333,0.288240416391407,0.0175050328255241,0.225444912746704,0.15982819660882,0.15982819660882,0.15982819660882], 0), + LabeledSample([0.0235926642263124,0.111245261182021,0.128500316085317,0.401319090478726,0.400095170724106,-0.267283460172638,-0.000649706679643489,0.322976171567117,0.26186531561982,0.0277197647424217,0.246130186898388,-0.0259347325599058,0.436765374770623,0.225321555758923,0.225321555758923,0.225321555758923], 0), + LabeledSample([0.327691388188431,0.0414153506641207,0.342641752798106,0.426723895901174,0.00448419769970425,0.334360409171912,0.295483669866123,-0.0463655278288402,0.25051461407531,0.038010598277653,0.445600271509613,0.297644597218037,-0.00965967754349107,0.113551047440284,0.113551047440284,0.113551047440284], 0), + LabeledSample([0.422832528521326,0.105823154490609,0.138370598941533,0.630949920317877,0.0268473229561604,0.105291751147652,0.219543560563568,0.0535214977909612,0.0127504537131134,0.107245196764506,0.294587317177946,0.349815971415001,0.0355757901953409,0.18957512708764,0.18957512708764,0.18957512708764], 0), + LabeledSample([0.116234412828698,0.0493659607663372,0.228639262369261,0.510574000617481,0.471285231806449,0.322077243645769,0.228602419449592,-0.0352948257915518,0.21050837692503,0.0272710878325413,0.312245752193203,0.28658980023543,0.211279670444006,0.0864384517016141,0.0864384517016141,0.0864384517016141], 0), + LabeledSample([-0.230097079442458,0.191575291088469,-0.221273190981361,-0.024993826160744,0.264590786561978,-0.0107999042204516,0.176518708860926,0.247567524019548,0.0848265496512535,0.137473935828681,0.708369840105813,0.122490218181156,-0.00134001086000318,0.227527407567209,0.227527407567209,0.227527407567209], 0), + LabeledSample([0.286238576503558,-0.0853526847535509,-0.422558143311451,-0.0222125055212697,0.00798531641040375,0.143913549631955,0.288568394280582,-0.0127390882156346,0.235003191664602,0.225961949494622,0.579090368332931,0.249251651644526,-0.0332123980409943,0.202208087882306,0.202208087882306,0.202208087882306], 0), + LabeledSample([-0.138505618757149,0.429011756390478,0.135357513344437,0.149953928005861,0.539033862170768,0.0396351468199451,0.0843831548165318,0.424865680367432,-0.0272934605640143,-0.0267253148275226,0.285874188645398,0.262900953134214,0.0621739904835329,0.200026426154027,0.200026426154027,0.200026426154027], 0), + LabeledSample([0.0224877987223024,-0.0391969361451446,-0.104125007708806,-0.0801276173941065,0.659130786498865,0.0768619382257438,0.150151104777339,0.154114867140806,0.572869061092601,0.0445206947102069,0.26295955953503,0.113423019904689,0.180675371790576,0.128089024024065,0.128089024024065,0.128089024024065], 0), + LabeledSample([-0.0680713313894235,-0.0659572584062495,-0.0910223567594807,0.196293086038722,0.00657243295002523,0.293110509849117,0.291706321935055,0.104459472373553,0.180709201308787,-0.038253343288553,0.673873365895924,0.422659657301139,-0.110795904520421,0.166430361836103,0.166430361836103,0.166430361836103], 0), + LabeledSample([0.154066808923888,0.133666304199433,0.0919500790875897,0.194442098264837,0.00702220610633866,0.225818299748987,0.379643742496216,0.029734242478354,0.347024253511723,0.118848713104271,0.475971046401783,0.458845965840934,0.222663411373826,0.17781973769107,0.17781973769107,0.17781973769107], 0), + LabeledSample([-0.0412832096727263,-0.0193723491657681,0.334583955863749,0.514041914199186,-0.120088975443408,0.127166135539843,0.122010212151076,0.274722145723124,0.155901468269603,-0.065226883999393,0.557923375925209,0.266075448964717,0.136329230955618,0.154448963498702,0.154448963498702,0.154448963498702], 0), + LabeledSample([0.209152318262746,0.489509227021142,0.166558864454062,0.386824290404889,-0.0090287938267186,0.00603222107702054,0.115910607692672,0.60482754083883,0.226248773221092,0.179573248602189,0.0981144078333417,0.0393351999435281,0.0543152687428254,0.144144262359866,0.144144262359866,0.144144262359866], 0), + LabeledSample([0.146186351364834,-0.0599352177829581,0.137174545434296,0.140890443318893,0.256937704693468,0.238665823116693,0.24425412536107,0.117957710687414,0.218416932214424,-0.0287272780306666,0.585109848781112,0.492626674133014,0.0170807183110501,0.187936469761787,0.187936469761787,0.187936469761787], 0), + LabeledSample([-0.0212751800674024,0.0836439194336721,0.186747903160102,0.476487066856997,0.0758988721598699,0.0562669129630701,0.160218896806228,0.359848645202163,0.240032469855216,-0.0443743970083499,0.633126267164003,0.132720714645898,0.048933326900439,0.169416457441109,0.169416457441109,0.169416457441109], 0), + LabeledSample([-0.135415771949136,0.0751572759773452,0.362094316487182,0.551101202585419,0.0320765927245714,0.0848446078532958,0.1095484360509,0.234077186184729,0.112730289622787,-0.0218042564883484,0.516421980073012,0.35838738679105,0.0767953381865317,0.131598341625362,0.131598341625362,0.131598341625362], 0), + LabeledSample([-0.188460509151474,0.193401975555393,0.342146668362078,0.413536016302811,-0.0296656431400048,0.128142138561582,0.170273453960699,0.48605573213843,0.15881824790758,-0.00672874339900442,0.302244543532862,0.321206300340771,0.198525603613385,0.18004820867773,0.18004820867773,0.18004820867773], 0), + LabeledSample([-0.053714274484023,0.156242047612459,0.232205043379324,0.193832368392874,-0.0946801554375718,-0.0140257551300867,0.135988244942012,0.635024922675372,0.325654714375167,-0.0590818970692274,0.437621371413818,0.161532484103856,0.0447833885724345,0.200956129257143,0.200956129257143,0.200956129257143], 0), + LabeledSample([-0.0742634161790091,0.0662236988168258,0.306399592365841,0.448243013125216,0.00717029200860015,-0.0734859433802067,0.058602185896295,0.53196312467187,0.289615015487018,0.0864075791618671,0.361426640278499,0.286843185709196,0.0165020653068763,0.181569641339172,0.181569641339172,0.181569641339172], 0), + LabeledSample([0.151644500925181,0.0728178984707065,0.155936965367273,0.356144317534378,-0.106893503746568,-0.104609511219261,0.115619398241339,0.717997739810603,0.292668707947211,0.0229389859916003,0.266486361251246,0.0699209184017578,0.0538563063648312,0.186460745940225,0.186460745940225,0.186460745940225], 0), + LabeledSample([0.017251058258794,0.34061380107735,0.102725067313048,0.12351280000404,0.0401586689477961,0.301198241391264,0.286439164137179,0.0085850903260407,0.413825461579023,-0.074865004679771,0.430726677111447,0.47896687514064,-0.10098443502038,0.164756097406929,0.164756097406929,0.164756097406929], 0), + LabeledSample([0.0384095923980801,0.0342440150682099,0.0468913629984613,0.10695304663162,0.707428075964548,0.175903871921294,0.16022417436721,0.0777925992961381,0.525640169223502,-0.0150248996627851,0.242728786479052,0.139555500489966,0.202504809321555,0.090681921659038,0.090681921659038,0.090681921659038], 0), + LabeledSample([-0.102766049465399,0.158724029733518,0.467244884595389,0.310654099786137,0.681122886039951,-0.00962012483589027,-0.00625183963419078,-0.167340922687806,0.195285550280335,-0.0316805383269013,0.1883920491779,0.107978882227297,0.118631768157831,0.137833794477422,0.137833794477422,0.137833794477422], 0), + LabeledSample([0.019453115347372,0.043797394473083,-0.121376435441619,-0.0204086342530653,-0.0116371676846372,0.381129313559749,0.388762239761525,0.0952229866709675,0.362572432076403,0.00497650745663331,0.578417281517633,0.327650151753602,-0.00109418187359779,0.18578682646359,0.18578682646359,0.18578682646359], 0), + LabeledSample([0.0342405440321611,-0.0281824199791365,-0.00207123863927224,0.134025669553407,0.0338688736281274,0.586002464956269,0.536669558217335,-0.00875392381573298,0.334857918368746,0.146359507633643,0.267924904020169,0.25356443636761,0.140986680270676,0.138951404235846,0.138951404235846,0.138951404235846], 0), + LabeledSample([-0.0459776013701822,0.189206877746516,-0.368607134739602,0.0919901953133355,0.200031712125804,0.229964841814475,0.279570519661187,0.0287630387813438,0.173629318503823,0.0487512267493663,0.578448189961138,0.380632750540371,0.212363975757494,0.172011646673697,0.172011646673697,0.172011646673697], 0), + LabeledSample([0.171749946888126,0.0382054996412482,-0.283403382645723,0.253363284763606,0.0640260116010568,-0.106311359911027,0.125687986849022,0.134631138413371,0.231702239325847,-0.0688011193206196,0.506487555546021,0.479340403307816,0.153286206420282,0.262674936204522,0.262674936204522,0.262674936204522], 0), + LabeledSample([0.0336575027844327,0.274658266727067,0.330919770580883,0.355063482285362,0.220291637262679,0.361125499634068,0.268237175708898,0.189478160002826,0.135870102624656,-0.00650795237187516,0.0750829255153591,0.53469603668777,0.00663460638019215,0.174140266203267,0.174140266203267,0.174140266203267], 0), + LabeledSample([-0.17022115141536,0.148644983823566,-0.277201667417559,0.326078507065425,0.00923541000562605,0.453646179918048,0.20461185897608,0.335220303446187,0.247972853926978,-0.119771170340383,0.305058603820466,0.269169352595279,-0.0147508749961993,0.233863569340058,0.233863569340058,0.233863569340058], 0), + LabeledSample([0.0484946781518587,0.246997373535612,0.128767048138348,0.357379244643778,0.0648542975285742,0.0157552855302677,0.167648001620963,0.690742807613556,0.153497250272026,-0.0146978241744509,0.116595475501532,0.420845818394984,-0.072810427233968,0.144763486260763,0.144763486260763,0.144763486260763], 0), + LabeledSample([0.00724477043421416,0.138798808762658,0.0195824755550168,0.252432476912075,-0.122697772506,0.00895679579556293,0.305437969275691,0.306789523059073,0.341389863690145,0.0743914115188658,0.359287780985842,0.565392249180727,0.0759412712591187,0.214029079268603,0.214029079268603,0.214029079268603], 0), + LabeledSample([0.170557475573451,0.132738292033316,0.185573118907713,0.528272513717373,-0.0324344546741652,-0.110439744394134,0.205675203400676,0.531421231582964,0.313992645721549,0.0557916662885854,0.183107137106059,0.218531534014374,0.0507963922157862,0.196852818459459,0.196852818459459,0.196852818459459], 0), + LabeledSample([-0.00371590736778159,0.0155916049981286,-0.166812891661853,0.227158091846741,0.125624617211269,0.31339598835668,0.277583346796089,0.320412189049738,0.527899928421857,-0.0195546380052403,0.155123798558197,0.449788649460149,-0.0994118874493321,0.192599771000564,0.192599771000564,0.192599771000564], 0), + LabeledSample([-0.145401127281845,0.345107148052225,-0.160194422185549,0.148460286249223,0.232561585933487,0.368208351419031,0.234862362090247,-0.00670796080071491,0.69852658030737,0.0028520716799073,0.0127007121252476,0.202998608065508,0.0621348328391241,0.106475746469619,0.106475746469619,0.106475746469619], 0), + LabeledSample([0.107473565308119,0.325572766950317,0.0750219250582412,0.427881638813811,0.0511510625860875,0.430501117120413,0.370786722414011,0.0350908396323849,0.115642656346118,-0.115553062312517,0.221380050659666,0.387235464354543,-0.0963171493402314,0.209853804189988,0.209853804189988,0.209853804189988], 0), + LabeledSample([-0.105163594933397,0.236247321829009,0.548103393579171,0.202874910831642,0.223862494933951,0.0334263541064524,0.179916507439689,0.514487206885038,0.014899877628873,0.0761741154009069,0.392506736796903,0.160552241706305,0.0985266980933294,0.12607261803061,0.12607261803061,0.12607261803061], 0), + LabeledSample([-0.260684457823998,-0.112668045693411,0.378814930734517,0.365521021903169,0.0436961696223554,0.339738773764387,0.250756320579299,0.360140958998214,0.199214292163835,0.0255047188665542,0.412757961642129,0.15874309551013,0.00367568909960073,0.179269148286986,0.179269148286986,0.179269148286986], 0), + LabeledSample([-0.241748520287807,0.0414482707742813,0.058763595432437,0.256128316868812,-0.00711817390653469,0.210290393383608,0.184701209154332,0.359108538645612,0.291225483966834,-0.0698659966847082,0.694052272792579,0.230583568583409,-0.0111670343359772,0.113641306557511,0.113641306557511,0.113641306557511], 0), + LabeledSample([-0.153882847897414,0.0662016195816666,-0.12687324761113,0.412896588533035,0.00834896945150008,0.164629397167468,0.1729995904174,0.132694992919367,0.283389025047269,-0.123195679919954,0.288965585286903,0.627566808270024,0.0610644447721535,0.211416688057106,0.211416688057106,0.211416688057106], 0), + LabeledSample([0.0591785841682163,0.0872184373644866,0.0819503684103717,0.474073740755973,0.403890028673706,0.145450761132863,0.267110751972313,0.192215974310117,0.27278162753235,-0.0904730522376757,0.362665772366751,0.390910938027966,-0.0655387164868738,0.176656459691106,0.176656459691106,0.176656459691106], 0), + LabeledSample([0.224889272955833,0.669095465403597,-0.153846675880603,-0.0258682875936601,-0.134999621099271,-0.000661472488168805,0.0760044874046187,0.50018761028079,-0.104088082113815,0.0818499974610029,-0.0453545371648244,0.117158252403706,-0.0593961618189751,0.235487931160887,0.235487931160887,0.235487931160887], 0), + LabeledSample([-0.209103241158248,0.228669181795995,0.255088683830861,0.243250541631366,0.160349228073623,0.428236250356188,0.37837723230132,0.129677256434085,0.318097577546011,0.0379932474265926,0.0651760786736684,0.467232175843078,0.130104265959122,0.151163258655871,0.151163258655871,0.151163258655871], 0), + LabeledSample([-0.0949455004501372,0.0847859117075642,0.479085360309945,0.420399017918024,0.272405231651456,0.276274767241364,0.458999158117131,0.206476799663682,0.176254495135719,0.16103521244277,0.0992290020450245,0.29587858257189,0.0125324001646888,0.0798910778622389,0.0798910778622389,0.0798910778622389], 0), + LabeledSample([0.0390776074332029,0.481914025011933,0.389235123540663,0.513576685188268,0.195221567237419,0.148139913148615,0.182988505577128,0.247774833808009,0.209830507186548,-0.0582455614924274,0.137611964957276,0.296245087249184,-0.0330146696405289,0.116652195711977,0.116652195711977,0.116652195711977], 0), + LabeledSample([0.175361217812057,0.712851209890314,0.0174872350745221,0.272389026452382,0.00477267472932331,0.26681797174273,0.278559739216107,0.0758548756338079,0.309714392479613,-0.0200243808111048,-0.000661039907090557,0.301985034467809,-0.0262299830144248,0.120856003882741,0.120856003882741,0.120856003882741], 0), + LabeledSample([-0.0515550360938761,0.217638869678391,0.0646674386583323,0.368825641431328,-0.0113304374665257,0.391278781291545,0.416931222704819,0.25928777642477,0.159560687159559,-0.0114024132991685,0.14569242322842,0.518482157017735,-0.0408508589759248,0.180889893176408,0.180889893176408,0.180889893176408], 0), + LabeledSample([0.0590584496010962,0.0653911498014063,0.166756993142791,0.377389338957649,0.00661244171476956,0.414536345971713,0.504472951325259,0.278561769633665,0.326774465916968,0.116210711360602,-0.0426937852259151,0.329492903733875,-0.0569648157818169,0.167443483345846,0.167443483345846,0.167443483345846], 0), + LabeledSample([-0.0917905323242946,0.136856969328066,0.423421071914423,0.618451685458719,0.0766586823653196,0.130882678776999,0.202666553402918,0.452561937469748,0.226369730901658,0.0106885068356884,0.175300271549197,0.135271218254247,0.0189534851807265,0.117528275878727,0.117528275878727,0.117528275878727], 0), + LabeledSample([0.0410725034645433,0.0865908543801398,0.174860032199159,0.590552204556892,0.0406266742761109,0.21911007344103,0.336973706175648,0.296470940048156,0.380450847672745,-0.0789455576012649,0.165434239058747,0.30756133466462,-0.0640356262452383,0.16667614937775,0.16667614937775,0.16667614937775], 0), + LabeledSample([0.231247021143954,0.0328575941432753,0.239771237867592,0.155559724420754,0.771104178545808,-0.0561824850255899,0.0669726177113016,-0.0847287418745489,-0.0335975478083005,0.165314845980509,0.037694955276207,-0.248462360894268,0.183160019410365,0.20750410571554,0.20750410571554,0.20750410571554], 0), + LabeledSample([0.241553862856675,0.477659290517776,0.332149184931846,0.338049550466755,0.394475485720108,-0.155382829819071,0.0588793688880362,-0.0132346547036292,-0.0928549679630124,0.342575719203705,0.0119545925013105,-0.195772238397477,0.0930197904312452,0.210074235777643,0.210074235777643,0.210074235777643], 0), + LabeledSample([0.195334098839262,0.265936942134869,0.301061082717328,0.633735089605007,0.240875720732619,-0.204614328497058,0.0183220768801773,0.0537577549439433,-0.0841640397111417,0.347161086293148,-0.0841816583990839,-0.200778379378044,0.109441334344513,0.190411958672153,0.190411958672153,0.190411958672153], 0), + LabeledSample([0.154448016907517,0.556854469068016,0.254312229828219,0.418896273907283,0.386968433915166,0.0285279899342927,0.0468296875626629,-0.161466370113012,-0.0774192519320793,0.255390569404737,0.0569494729175185,-0.222545610887232,0.139527712855628,0.185859652149587,0.185859652149587,0.185859652149587], 0), + LabeledSample([0.107628604769279,0.261746278972036,0.0851180912768023,0.158772315991637,0.140988491850029,-0.00413784948643965,-0.0843738206441276,0.728586430979596,-0.026652050091825,0.447966709849224,-0.000900345468261859,-0.0996191659016783,0.192361642089446,0.164607543721497,0.164607543721497,0.164607543721497], 0), + LabeledSample([0.00486083688270077,0.64696412497406,0.334004131433736,0.292796584476603,0.0496680469899061,-0.0805643593285377,-0.112236101061606,0.470313172913834,-0.0744431293863573,0.0913718514970689,0.017129180316594,-0.177811231073042,0.183606006071121,0.143601574670483,0.143601574670483,0.143601574670483], 0), + LabeledSample([0.0593012658050308,0.618282924898504,0.319860123970287,0.420597881670929,0.118722187593532,0.039670437030364,-0.066875474833392,0.495384719941719,0.0274768048222377,0.153791027572778,0.0622186086857226,-0.0425934013405588,0.0421731300357924,0.111920917655756,0.111920917655756,0.111920917655756], 0), + LabeledSample([0.35706949199178,0.487907587838099,0.0742654982178638,0.223215994867022,0.0390214609130473,-0.00402430294131187,-0.122856975826827,0.616454988141533,-0.0503794065110105,0.29187878481142,0.0790110377216966,-0.0184265802938717,0.106098116652602,0.160090555379413,0.160090555379413,0.160090555379413], 0), + LabeledSample([0.199679080715689,0.329178457633655,0.5122675888719,0.328753885712996,0.171034892353202,-0.0328548041171417,-0.11917098819282,0.528070651417679,-0.104113418370725,0.180177634599645,0.0393474158856868,0.14277539827214,0.121042935048185,0.161236770407746,0.161236770407746,0.161236770407746], 0), + LabeledSample([0.399234374525672,0.343140964574117,0.262499129603519,0.321200298372581,0.0690376898799216,-0.103069220489572,-0.147528123918692,0.28611202467628,-0.184796038719915,0.351113212604546,-0.0384432817619214,0.241965234417974,0.30789080407244,0.199603599883522,0.199603599883522,0.199603599883522], 0), + LabeledSample([0.326297251446263,0.358072912503018,0.469179487893646,0.44486497839985,0.166165578623474,-0.0259256728784585,-0.101564268085728,0.418637721491455,-0.165035262442682,0.13675622140151,0.141824742886277,0.0535821051312442,0.0569851850404429,0.14288941736166,0.14288941736166,0.14288941736166], 0), + LabeledSample([0.359120502088139,0.700805409310182,0.191928580932408,0.234848464278066,0.0951917123491453,0.120161856543908,-0.0458786085683259,0.37718388873341,0.00609959082291796,0.144359407159952,0.163061132284603,0.0517465740033583,0.0774619267888505,0.145941953150503,0.145941953150503,0.145941953150503], 0), + LabeledSample([0.291195303142619,0.534655572500114,0.0444255612049878,0.360745440250476,0.296093533980492,-0.0518541691097636,-0.118242939814779,0.375801337996739,0.133539219783322,0.129603302294616,-0.144436062691931,-0.0709454867315089,0.311825750270044,0.176926972586679,0.176926972586679,0.176926972586679], 0), + LabeledSample([0.413805146571906,0.69664978134007,0.0958556630778741,0.227945149088853,-0.0812057308285977,-0.205986954415187,-0.136784207696217,0.251959916491281,-0.116715813654797,0.185556559428288,-0.133310433179743,-0.158041650685777,-0.00893465922483392,0.141652023876218,0.141652023876218,0.141652023876218], 0), + LabeledSample([0.158291913315117,0.61007562639357,0.280571854551608,0.31512409624496,0.00552145888671505,0.021460818836787,-0.0736463801656978,0.361354290332944,-0.0511199237943532,0.429838510746757,-0.166468560337299,-0.00467256799448173,0.120338758614208,0.13981708255778,0.13981708255778,0.13981708255778], 0), + LabeledSample([0.294612172286633,0.396460478068849,0.225195794572686,0.344173187654909,0.0996035097194735,0.101862847125905,-0.0566530274920627,0.359509762226072,0.0958157698038399,0.544901562229702,-0.172288930624776,-0.0799430591765561,0.148225261470161,0.15270584371661,0.15270584371661,0.15270584371661], 0), + LabeledSample([0.280112301373465,0.304198697282866,0.342831597197724,0.414689543234349,0.475740782606101,-0.0643383875261756,0.0966644031984621,-0.0365339289604027,0.0781791396244117,0.458991625305328,-0.109488356402631,-0.146646948787543,0.0387285214557376,0.124597563656019,0.124597563656019,0.124597563656019], 0), + LabeledSample([0.133853155365226,0.251509825278989,0.271201745583724,0.333640610110787,0.364197773553594,-0.0456447486371128,0.0646671540303931,-0.00851428995732382,0.0882401692122618,0.688613848871636,-0.211489063016041,-0.112147850666851,0.0301178737450273,0.13514768583147,0.13514768583147,0.13514768583147], 0), + LabeledSample([0.207271251693883,0.115500830559941,0.458273039159486,0.528782719588034,0.413047389853592,0.169025360544143,0.0486111900689069,0.0222561283164266,0.188576295848358,0.362216900330744,-0.100353981302315,-0.148498298059799,-0.00254032130971227,0.133098359648033,0.133098359648033,0.133098359648033], 0), + LabeledSample([0.217169576879935,0.328067883566794,0.115674032839654,0.118355240622035,0.15522485184217,0.0462327273246561,-0.0333619921336167,0.51486888362252,0.270710043500941,0.603172249037944,-0.130786950489933,-0.0917999683842816,0.132598808030938,0.122705052979048,0.122705052979048,0.122705052979048], 0), + LabeledSample([0.194334002827861,0.597116623596196,0.134983141140157,0.288389492055361,0.0881256370367682,0.0283641866903432,-0.0648397385418245,0.490166173851522,0.162535151452483,0.377869101053486,-0.0953653778297959,-0.0945519515505388,0.15193019485309,0.116817831188036,0.116817831188036,0.116817831188036], 0), + LabeledSample([0.382049935071895,0.500121566084578,0.197658523253673,0.186883314209102,0.0463584394822235,0.0505007692652614,-0.0364418533031411,0.361833015451648,0.189900157465683,0.52900592480994,-0.134500290724354,-0.0646934845425211,0.0298694084733732,0.13403274967237,0.13403274967237,0.13403274967237], 0), + LabeledSample([0.0454604271711028,0.272358209831245,0.334733475377532,0.540826974410863,0.136204453040618,0.0702829081012277,-0.0733016984179067,0.518419885844916,0.0406840934257617,0.348805231475169,-0.0444755533797833,-0.0350069750344801,0.232188724319112,0.117125189815264,0.117125189815264,0.117125189815264], 0), + LabeledSample([0.335674295704234,0.0524705458011824,0.285448708675593,0.337637839798896,0.113656453675324,0.234464885964899,0.0366300952166488,0.294254582587596,0.388100051183445,0.584600415570291,-0.0901586894505694,0.0153442661214017,0.0911612850972567,0.0898452857524493,0.0898452857524493,0.0898452857524493], 0), + LabeledSample([0.0350118075919132,0.513951347877797,0.225756494796119,0.312134977782114,0.0373141409575358,0.22859045944533,-0.0221155204801056,0.44851185516087,0.014194363756837,0.470631206937074,-0.163168980713227,-0.0926464538757241,0.0610516676999834,0.153086055970812,0.153086055970812,0.153086055970812], 0), + LabeledSample([0.381787211515927,0.387300689840662,0.343559965487082,0.237693597788473,0.32262439324557,0.0655486033329805,-0.0966255085017079,0.432761090491005,-0.0765729419362027,0.286364640913038,0.211104496257327,-0.0170015668142093,0.162868701584034,0.147710005340067,0.147710005340067,0.147710005340067], 0), + LabeledSample([0.155945886743743,0.374673392583335,0.360990966123492,0.351037530117177,0.296055870377592,0.00595063273222534,-0.0849647675134255,0.580279283002605,-0.0157815952502789,0.248303270443573,0.123396039021296,0.0678399740301173,0.0879828660502218,0.142194650164373,0.142194650164373,0.142194650164373], 0), + LabeledSample([0.247099012520518,0.548529233743003,0.251602210677838,0.184535531479979,0.398332162863828,-0.103062467167249,-0.0872299639676222,0.340301314244126,-0.0309767493029768,0.297259141024446,-0.0607147335296098,-0.0493683988668593,0.206743625250552,0.191317613379529,0.191317613379529,0.191317613379529], 0), + LabeledSample([0.368840866448451,0.561256609671349,0.116156562908135,0.372733535848356,0.0338547729259747,-0.108936188248542,-0.108556407075164,0.438906088118794,0.0517821615670243,0.335214628337197,0.042558536063148,-0.0358406749243028,0.0553916100892464,0.138893554294146,0.138893554294146,0.138893554294146], 0), + LabeledSample([0.252099424680132,0.372340119658059,0.308780202110509,0.338356586210174,0.302660291604557,0.0179180881380311,-0.0168642544568776,0.247953299406305,0.135669071925625,0.58581498194311,0.0867401818600983,-0.0754154369541946,0.136418841562815,0.116736217174449,0.116736217174449,0.116736217174449], 0), + LabeledSample([0.160514905930226,0.42513020108958,0.161366460219075,0.214464679117517,0.0374916013451409,-0.0519491424865503,-0.0788413692144921,0.273592916298358,-0.0131545583493555,0.730434903489431,-0.0104356432008383,-0.0396908376594602,0.17298227627428,0.15381411000428,0.15381411000428,0.15381411000428], 0), + LabeledSample([0.312208384295773,0.227953784866742,0.408105848561651,0.46286958294019,0.258655167682807,-0.0237030251637096,-0.0336696067073982,0.217333697465091,0.178439191727198,0.486277022560919,0.00743422653111901,-0.0203721388066285,0.184272635196624,0.130639288369846,0.130639288369846,0.130639288369846], 0), + LabeledSample([-0.0121138629979706,0.51476715301201,0.255794413329181,0.261091726026612,0.234823356715931,-0.188453187961464,-0.166750701853882,0.393757950236957,-0.154216849192256,0.375200433991031,-0.0978687227599553,-0.0209595193756307,0.0785463020933106,0.221370967831489,0.221370967831489,0.221370967831489], 0), + LabeledSample([0.15164440851627,0.238159903687439,0.149692397812484,0.221404230777602,0.00627075628692431,-0.0855405218580231,-0.115115238684532,0.428670482407951,-0.147011261148233,0.717394074369177,-0.159345062630204,-0.0798861946499534,0.028401848780963,0.158791157818479,0.158791157818479,0.158791157818479], 0), + LabeledSample([0.479353368202618,0.232098810359438,0.281487506769595,0.225726645614505,0.0771685321261895,0.0152666061652778,-0.0639566924507687,0.314093910034917,0.0844431404637428,0.615734357611464,-0.0970141128064776,-0.0476545173116696,0.142328018096663,0.140273378582059,0.140273378582059,0.140273378582059], 0), + LabeledSample([0.30805302990898,0.670729182344314,0.217166727339904,0.214458524080411,0.112708704299647,0.0127958405947736,-0.0685871682117966,0.371527606547604,0.0168889271955423,0.365220269768971,-0.0666459323845712,-0.0327394701982652,0.160667936689163,0.11757136934001,0.11757136934001,0.11757136934001], 0), + LabeledSample([0.220644600430142,0.47201243250483,0.100246722942253,0.192892834023419,0.42096181212692,-0.0110428333219897,-0.0563507871054082,0.254608441867765,0.105735328552683,0.564623622127601,-0.105333595654027,-0.0774396103688061,0.213900912573913,0.119869452979611,0.119869452979611,0.119869452979611], 0), + LabeledSample([0.21584998670774,0.228078314592705,0.184442119623237,0.208794925485675,0.455665917504659,0.00542990534202975,-0.0628333846009199,0.424952422931548,0.15079523110219,0.536249827391934,-0.105923900281999,-0.0679262243981786,0.234388707705015,0.129751494551881,0.129751494551881,0.129751494551881], 0), + LabeledSample([0.362999772634019,0.39983821564658,0.365781340492783,0.382311657116397,0.114459892044237,0.100888832191619,-0.0400313439069322,0.390656550007052,0.0951796929833985,0.439028538569296,-0.0813569403810565,-0.060895058821727,0.0620183007783841,0.107902797379616,0.107902797379616,0.107902797379616], 0), + LabeledSample([0.391844552693735,0.0224505345360546,0.128147149095695,0.00959245823497324,0.147402239960384,0.36111662558123,0.382155151656564,0.0127068479152497,0.218005687475965,0.324055673723351,0.222576956644604,0.364244640009045,0.389785541991087,0.121679173532834,0.121679173532834,0.121679173532834], 1), + LabeledSample([0.356888874277264,0.0720162195877543,0.136996189058879,-0.140909810519905,0.136677215809854,0.32796172094906,0.334588448755052,0.0813885300036874,0.383135189111009,0.242506953404048,0.26235074418908,0.164272964522333,0.51022872786026,0.0861361717713044,0.0861361717713044,0.0861361717713044], 1), + LabeledSample([0.356743024162847,0.299694889353212,0.311343800463449,-0.0332955728202061,0.365655578392927,0.281510298420893,0.372971600707102,-0.0625154967079762,0.168543951699275,0.190470770336807,0.190242024720102,0.330066123959551,0.26721886250174,0.126066127781679,0.126066127781679,0.126066127781679], 1), + LabeledSample([0.342818794892513,0.101052809398138,0.360430132766183,0.23819990844026,0.135958671633598,0.237320808409532,0.308254717340488,0.109542475248431,0.177557689560361,0.0866011436890782,0.336473881100679,0.468385700630219,0.281509738880536,0.132808149773745,0.132808149773745,0.132808149773745], 1), + LabeledSample([0.471825455298159,0.0805157625548287,0.102338403158557,0.0106143299846797,0.13783550627248,0.282993959641305,0.255288568929083,0.0787232630337918,0.283117434475593,0.174153574685115,0.272150764672242,0.413684819363966,0.424013222162737,0.134641493192199,0.134641493192199,0.134641493192199], 1), + LabeledSample([0.34641200164034,0.099744551278731,0.38776203448908,0.181916386282477,0.311546673657173,0.175216256169144,0.293174280061248,0.125937342360261,0.139917604026267,0.136174356784758,0.320610477987196,0.219965569994473,0.463069568846749,0.133283652542607,0.133283652542607,0.133283652542607], 1), + LabeledSample([0.404853350133791,0.366370427401772,0.233457215510936,-0.117646343734435,0.422400124731543,0.316834280568532,0.311952030312985,-0.0142353771929971,0.245689562716628,0.158495894279496,0.111287504351714,0.309881505730385,0.174043923126029,0.10490304431372,0.10490304431372,0.10490304431372], 1), + LabeledSample([0.25251240458689,0.100686161713017,0.0315578727081392,0.0718934503369092,0.291240948285929,0.427841821532188,0.412648557737393,0.116841462722393,0.314820284876223,0.209407419028952,0.141208499852881,0.368089079182708,0.330970427145695,0.141657365746273,0.141657365746273,0.141657365746273], 1), + LabeledSample([0.350364491958287,0.0688422581963099,0.109742569360303,0.0707531010098024,0.224015978099777,0.28190906228017,0.388953246261309,0.135993554782958,0.244051253148224,0.3726688048422,0.264003118925063,0.219311926596273,0.455200762754877,0.104203528797661,0.104203528797661,0.104203528797661], 1), + LabeledSample([0.397327283049911,0.0773527405250614,0.126236452283931,0.0330706981684607,0.408012616077325,0.260360655336735,0.364814158384692,-0.00206578487920926,0.163991130541285,0.253478466473427,0.165540214451542,0.30416373966438,0.433971873268533,0.132120542922879,0.132120542922879,0.132120542922879], 1), + LabeledSample([0.107297174901783,-0.0613762696733566,-0.632314571586212,-0.416852421444992,0.0508952503409911,0.064074731214031,-0.144536144592534,0.153765312304364,-0.303969426648252,-0.0375252361713336,0.388754164139066,-0.078967037248287,0.0668579337914334,0.186423454283019,0.186423454283019,0.186423454283019], 1), + LabeledSample([0.0337268344229458,-0.00184814410831371,-0.171994660095448,0.0487910037701937,0.715459227632856,0.00029799084750352,0.034974910385745,-0.0990313039755913,0.387197494235993,0.033304059568937,0.411585327770438,0.236608730976454,0.165595696405405,0.115678798001455,0.115678798001455,0.115678798001455], 1), + LabeledSample([-0.0223561749320937,-0.0207526232365009,0.176225433251552,0.326430295003409,0.219297804670973,0.590124842186138,0.236154622574307,-0.143389150319129,0.192871802948094,0.0710337180025261,0.249885838045267,0.317860451806615,0.343996729607254,0.146892033179513,0.146892033179513,0.146892033179513], 1), + LabeledSample([0.032885091939905,0.0461926134522565,0.34638380929578,0.203505193733194,0.264570166804038,0.0160341545388597,0.151445308394402,0.427311190150461,-0.0254549665189148,0.0510306773298033,0.692797615252923,0.0575883314039526,-0.0798332036067795,0.149101002314511,0.149101002314511,0.149101002314511], 0), + LabeledSample([0.142629866189693,0.410472062836346,0.207336198359131,0.378232988385718,0.183357859335752,0.316154994878092,0.273883001957771,0.322495142977759,0.249438841565115,0.0166674724899229,0.366212353243424,0.265767421147697,0.00611339840415559,0.122818414884191,0.122818414884191,0.122818414884191], 0), + LabeledSample([-0.0679233939259161,-0.072886846046031,0.477512324840591,0.174125713388414,0.155497662993969,0.17129901382616,0.318776243273762,0.0194230007106634,0.555783444679686,0.0737664378133595,0.0782223803712395,0.384101054511456,0.0667032731300068,0.185992205916374,0.185992205916374,0.185992205916374], 0), + LabeledSample([0.00999269298689842,0.0262030266834996,0.197155588375633,0.548367414525349,-0.232718880830273,0.151355729009093,0.127012275111873,0.411786294151836,0.109592670067503,-0.0518380454362711,0.363744240593521,0.381580392735396,0.15243777913074,0.164338283611199,0.164338283611199,0.164338283611199], 0), + LabeledSample([-0.131400682086754,0.171521987350065,0.191616648663646,0.162786759491588,0.210638981678084,0.534289546493504,0.311213752749673,-0.0862263866819605,0.103472561468339,0.0878652293863465,0.485065843433271,0.317875059263178,-0.102522755165598,0.173880513696912,0.173880513696912,0.173880513696912], 0), + LabeledSample([0.0506049151151188,0.287715578010986,0.0887170666404207,0.109273692933807,0.0318657512060172,0.306583832312144,0.338235987285259,0.334511582631667,0.477276067209907,-0.00128966778775066,0.519921454232635,0.183408801865957,-0.0302403142292243,0.116720585385637,0.116720585385637,0.116720585385637], 0), + LabeledSample([0.155537012760084,0.12469512047752,-0.0685853167040014,0.378983217011539,-0.0016059855847115,0.173834869196373,0.240415288132954,0.246327374233871,0.171038483773879,0.0635733414875313,0.381511309986817,0.572462983878879,0.223146044444717,0.188745574564891,0.188745574564891,0.188745574564891], 0), + LabeledSample([-0.106888248404423,0.0254982746554491,0.435809951544879,0.247866151735291,0.115539233295032,0.323105832423766,0.385789333857532,0.130580401233695,0.459264529749233,0.0247638879079171,0.20854914148463,0.334532005981271,0.169375895367498,0.138197555234402,0.138197555234402,0.138197555234402], 0), + LabeledSample([0.0100012070121382,0.0385909848160964,0.358005307896772,0.471274773272444,-0.0168340126254455,0.306861704693128,0.301875027533534,0.431885187577969,-0.024144046014302,0.0518235705697981,0.216614240137034,0.375408000771501,-0.0613295291494424,0.164478303953699,0.164478303953699,0.164478303953699], 0), + LabeledSample([-0.0156009038121407,0.536226598008622,-0.0510488844092566,0.262251476208149,0.0344260697722476,0.0761242352448198,0.163083120634928,0.366107933805052,0.353446929363601,-0.108649979874075,0.253047115727131,0.385416407008332,0.114718978391023,0.192142309706158,0.192142309706158,0.192142309706158], 0), + LabeledSample([-0.0370723732585497,0.462706141337283,0.194819679329056,0.264097858693995,-0.0344675209732017,0.315276508881407,0.351600930409003,-0.00185817840721325,0.514394278278426,0.030985137447176,0.0195438132713035,0.376880126062964,-0.0475330499513248,0.118842742281355,0.118842742281355,0.118842742281355], 0), + LabeledSample([-0.0016596349541218,0.631802778994405,0.258923690167821,0.431565727191915,-0.0777693312326763,0.107217718812087,0.165357588010325,0.407926583994051,0.0968775514246654,0.0247476673279324,0.068467607179257,0.172207746838557,0.111312979635777,0.16279792602384,0.16279792602384,0.16279792602384], 0), + LabeledSample([0.143710241385037,0.00813969645743141,0.166626922787307,0.125887427831217,-0.00148386915721329,0.0690924636334773,-0.132562337719547,0.813875842290254,0.0620432660245373,0.296664745393943,0.0286792231349211,-0.180653988476775,0.185389155342318,0.174393680319152,0.174393680319152,0.174393680319152], 0), + LabeledSample([0.194304705256292,0.30346843378612,0.374041666089729,0.48352572078128,0.205759387922832,0.170334766020302,-0.100580387509185,0.527373130970181,-0.0960922066168464,0.194750484480948,0.146211633441668,0.031454392555221,0.10170488371806,0.137823608782152,0.137823608782152,0.137823608782152], 0), + LabeledSample([0.0570260846145295,0.52764742101151,0.111869455738976,0.180967382649137,0.397178358074248,-0.193581548022407,-0.0718130900746043,0.148619617280605,0.014552586962639,0.503530729139833,-0.0748446558522674,-0.0107044561285139,0.341924057887159,0.157289053900933,0.157289053900933,0.157289053900933], 0), + LabeledSample([0.248098725379752,0.456746224327013,0.201739035375683,0.329290659490806,0.353941083012747,-0.155688188640652,0.0634239539879236,0.208825572195049,0.0125037152349941,0.520052128663407,-0.13353266010295,-0.188043841093254,0.0704360793068273,0.135144187394862,0.135144187394862,0.135144187394862], 0), + LabeledSample([0.154461249938759,0.0178069859154663,0.0362860191116435,0.292137716451667,0.273737481826492,-0.157722750938907,-0.123811269772362,0.623254105885853,0.116416845998361,0.467427306225011,-0.150509693940165,-0.155859335652357,0.164324900252044,0.162881127264595,0.162881127264595,0.162881127264595], 0), + LabeledSample([0.283967248673866,0.0653052200973657,0.31906371675043,0.319600990343548,0.0409193502319166,0.21981005179708,0.00324997177552983,0.413419912003247,0.317297662817938,0.571709617497126,-0.110212961327936,-0.0560612150021478,0.100443678932404,0.111543056863857,0.111543056863857,0.111543056863857], 0), + LabeledSample([0.437022295249671,0.277016772723886,0.170318463731936,0.376347873321372,0.0654029814959019,-0.18590177141098,-0.0863664388167373,0.338687920702156,-0.0242372506105056,0.560202129237804,-0.0221037853452648,-0.0993942479877979,0.123995050925897,0.141968301419256,0.141968301419256,0.141968301419256], 0), + LabeledSample([0.273452627665534,0.484246176255015,0.447645208017183,0.447862902118889,0.287256166753207,0.0390992590174893,-0.0208585770470468,0.0801713198810822,0.00235790979876691,0.382106195445461,-0.0395631261301076,-0.0257173942959117,0.108602367051486,0.11375808821732,0.11375808821732,0.11375808821732], 0), + LabeledSample([0.323768883858918,0.456898831708986,0.280009612342141,0.414792798825381,0.213720336482119,-0.0173248427920594,-0.0676281609721251,0.35366736131149,0.0994909525019752,0.364562841125483,-0.020970585691538,-0.12622312846499,0.216164946371533,0.13468998110011,0.13468998110011,0.13468998110011], 0) + + ]; + } + +} From 097d4858f871b943ae7068328b40ffaec8b320de Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Thu, 2 Jan 2020 21:34:33 -0800 Subject: [PATCH 10/17] Fixed bug with cyclic entangling layer. --- MachineLearning/src/Runtime/Structure.qs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MachineLearning/src/Runtime/Structure.qs b/MachineLearning/src/Runtime/Structure.qs index e0793e24b3a..c50e4acab6f 100644 --- a/MachineLearning/src/Runtime/Structure.qs +++ b/MachineLearning/src/Runtime/Structure.qs @@ -52,7 +52,7 @@ namespace Microsoft.Quantum.MachineLearning { set rotations += [ControlledRotation( GateSpan( idxTarget, - [idxTarget + stride % nQubits] + [(idxTarget + stride) % nQubits] ), axis, idxTarget )]; From 10283d9b19d771168831b02147d39213e0e6440b Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Fri, 3 Jan 2020 17:02:12 -0800 Subject: [PATCH 11/17] Use new Hadamard test operation to simplify grad est. --- .../src/Runtime/GradientEstimation.qs | 56 +++++++------------ 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/MachineLearning/src/Runtime/GradientEstimation.qs b/MachineLearning/src/Runtime/GradientEstimation.qs index 92b340a6e19..56764f8733c 100644 --- a/MachineLearning/src/Runtime/GradientEstimation.qs +++ b/MachineLearning/src/Runtime/GradientEstimation.qs @@ -13,40 +13,25 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Characterization; // NOTE: the last qubit of 'reg' in this context is the auxillary qubit used in the Hadamard test. - operation _endToEndHTcircuit(enc: (LittleEndian => Unit is Adj + Ctl), param1 : Double[], gates1: GateSequence, param2 : Double[], gates2: GateSequence, reg: Qubit[]): Unit is Adj + Ctl { - let L = Length(reg) - 1; - let g1 = _ApplyGates(param1, gates1, _); - let g2 = _ApplyGates(param2, gates2, _); - - enc(LittleEndian(reg[0..(L-1)])); - within { - H(Tail(reg)); - } apply { - (Controlled g1) ([reg[L]], reg[0..(L-1)]); - within { - X(Tail(reg)); - } apply { - (Controlled g2) ([reg[L]], reg[0..(L-1)]); - (Controlled Z) ([reg[L]], reg[(L-1)]); - } - } - } - - operation endToEndHTcircuit(enc: (LittleEndian => Unit is Adj + Ctl),param1 : Double[], gates1: GateSequence, param2 : Double[], gates2: GateSequence) : (Qubit[] => Unit is Adj) { - return _endToEndHTcircuit(enc,param1, gates1, param2, gates2, _); + operation _ApplyLEOperationToRawRegister(op : (LittleEndian => Unit is Adj), target : Qubit[]) : Unit is Adj { + op(LittleEndian(target)); } - operation HardamardTestPhysical(enc2: (LittleEndian => Unit is Adj + Ctl), param1 : Double[], gates1: GateSequence, param2 : Double[], gates2: GateSequence, nQubits: Int, nMeasurements : Int): Double { - return 1.0 - EstimateFrequencyA( - endToEndHTcircuit(enc2,param1,gates1,param2,gates2), - _TailMeasurement(nQubits), - nQubits, - nMeasurements + operation _EstimateFiniteDifference( + inputEncoder : StateGenerator, + gates : GateSequence, + parameters : (Double[], Double[]), + nQubits : Int, + nMeasurements : Int + ) : Double { + return EstimateRealOverlapBetweenStates( + _ApplyLEOperationToRawRegister(inputEncoder::Apply, _), + _ApplyGates(Fst(parameters), gates, _), + _ApplyGates(Snd(parameters), gates, _), + nQubits, nMeasurements ); } - - /// # Summary /// polymorphic classical/quantum gradient estimator /// @@ -96,9 +81,9 @@ namespace Microsoft.Quantum.MachineLearning { w/ gate::Index <- (param[gate::Index] + PI()); // NB: This the *antiderivative* of the bracket - let newDer = 2.0 * HardamardTestPhysical( - sg::Apply, param, gates, paramShift, gates, nQubits + 1, nMeasurements - ) - 1.0; + let newDer = _EstimateFiniteDifference( + sg, gates, (param, paramShift), nQubits, nMeasurements + ); if (IsEmpty(gate::Span::ControlIndices)) { //uncontrolled gate set grad w/= gate::Index <- grad[gate::Index] + newDer; @@ -108,10 +93,9 @@ namespace Microsoft.Quantum.MachineLearning { w/ gate::Index <- (param[gate::Index] + 3.0 * PI()); //Assumption: any rotation R has the property that R(\theta+2 Pi)=(-1).R(\theta) // NB: This the *antiderivative* of the bracket - let newDer1 = 2.0 * HardamardTestPhysical( - sg::Apply, param, gates, controlledShift, gates, nQubits + 1, - nMeasurements - ) - 1.0; + let newDer1 = _EstimateFiniteDifference( + sg, gates, (param, controlledShift), nQubits, nMeasurements + ); set grad w/= gate::Index <- (grad[gate::Index] + 0.5 * (newDer - newDer1)); } } From 809f4b824c6d0594531e683ca712a83796c5dc70 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Fri, 3 Jan 2020 21:06:58 -0800 Subject: [PATCH 12/17] Simplify input encoder logic. --- MachineLearning/src/Runtime/InputEncoding.qs | 21 ++++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/MachineLearning/src/Runtime/InputEncoding.qs b/MachineLearning/src/Runtime/InputEncoding.qs index 730fa2d98e8..b7abf571e1d 100644 --- a/MachineLearning/src/Runtime/InputEncoding.qs +++ b/MachineLearning/src/Runtime/InputEncoding.qs @@ -105,23 +105,18 @@ namespace Microsoft.Quantum.MachineLearning { /// The vector of 'coefficients' does not have to be unitary function InputEncoder(coefficients : Double[]): (LittleEndian => Unit is Adj + Ctl) { //default implementation, does not respect sparcity - let nCoefficients = Length(coefficients); - mutable coefficientsComplexPolar = new ComplexPolar[nCoefficients]; - mutable allPositive = true; - for (idx in 0 .. nCoefficients - 1) { - mutable coef = coefficients[idx]; - mutable ang = 0.0; - if (coef < 0.0) { - set allPositive = false; - set coef = -coef; - set ang = PI(); - } - set coefficientsComplexPolar w/= idx<-ComplexPolar(coef,ang); + mutable complexCoefficients = new ComplexPolar[0]; + for (coefficient in coefficients) { + set complexCoefficients += [ComplexPolar( + coefficient >= 0.0 + ? (coefficient, 0.0) + | (-coefficient, PI()) + )]; } if (_CanApplyTwoQubitCase(coefficients)) { return _ApplyTwoQubitCase(coefficients, _); } - return ApproximatelyPrepareArbitraryState(1E-12, coefficientsComplexPolar, _); //this is preparing the state almost exactly so far + return ApproximatelyPrepareArbitraryState(1E-12, complexCoefficients, _); //this is preparing the state almost exactly so far } } \ No newline at end of file From 7a2ab9c58274cd973b8e67d253cf15fdf985f32a Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Fri, 3 Jan 2020 21:15:27 -0800 Subject: [PATCH 13/17] Removed layer construction methods moved out to Q#. --- MachineLearning/src/DataModel/Interop.cs | 80 ------------------------ 1 file changed, 80 deletions(-) diff --git a/MachineLearning/src/DataModel/Interop.cs b/MachineLearning/src/DataModel/Interop.cs index a59d812d233..87781964328 100644 --- a/MachineLearning/src/DataModel/Interop.cs +++ b/MachineLearning/src/DataModel/Interop.cs @@ -140,86 +140,6 @@ public double Bias get { return _bias; } } - /// - /// Creates a layer of nQubits Pauli rotations - /// - /// Number of qubits to rotate - /// Type of Pauli gate - /// Sequence of nQubits rotation templates - public static List LocalRotationsLayer(long nQubits, char pauli) - { - List ret = new List((int)nQubits); - for (long iq = 0; iq < nQubits; iq++) - { - long[] localRp = new long[] { -1, Qonvert.ToC(pauli), iq }; - ret.Add(localRp); - } - return ret; - } - - /// - /// Creates a layer of nQubits Pauli rotations - /// - /// Number of qubits to rotate - /// Type of Pauli gate - /// Sequence of nQubits rotation templates - public static List PartialLocalLayer(long[] indices, char pauli) - { - List ret = new List(indices.Length); - foreach (long iq in indices) - { - long[] localRp = new long[] { -1, Qonvert.ToC(pauli), iq }; - ret.Add(localRp); - } - return ret; - } - - /// - /// Creates a cyclic block of nQubits controlled rotations that starts - /// with control qubit (nQubits-1), target qubit (cspan-1) % nQubits , followed by a - /// ladder of entanglers with control qubits iq and target qubit (iq+cspan) % nQubits - /// - /// Number of qubits to entangle - /// - /// index offset between control and target qubits - /// - public static List CyclicEntanglerLayer(long nQubits, char pauli, long cspan) - { - List ret = new List((int)nQubits); - ret.Add(new long[] { -1, Qonvert.ToC(pauli), (long) ((cspan-1) % nQubits), nQubits - 1 }); - for (long iq = 1; iq < nQubits; iq++) - { - long[] entRp = new long[] { -1, Qonvert.ToC(pauli), (long)(((iq + 1) * cspan - 1) % nQubits), (long)((iq*cspan - 1) % nQubits) }; - ret.Add(entRp); - } - return ret; - } - - public static List CyclicEntanglerLayer(long nQubits, char pauli) - { - return CyclicEntanglerLayer(nQubits, pauli, 1L); - } - - public static List JoinLayers(List> layers) - { - List structure = new List(layers.Count * layers[0].Count); - for (int ila = 0; ila < layers.Count; ila++) - { - structure.AddRange(layers[ila]); - } - return structure; - } - - public static void reindex(List struc) - { - for (int ix=0; ix < struc.Count; ix++) - { - long[] gt = struc[ix]; - gt[0] = ix; - struc[ix] = gt; - } - } - public long CountMisclassifications(double tolerance, IQArray> samples, IQArray knownLabels, IQArray> validationSchedule, long nMeasurements, uint randomizationSeed) { if (this.isTrained) From 25806caf0b435f7e1b14b6f35afbe12879a6d9b6 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Fri, 3 Jan 2020 21:15:56 -0800 Subject: [PATCH 14/17] Revised name of approximate input encoder. --- MachineLearning/src/Runtime/Classification.qs | 4 ++-- MachineLearning/src/Runtime/InputEncoding.qs | 11 ++++++----- MachineLearning/src/Runtime/Training.qs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/MachineLearning/src/Runtime/Classification.qs b/MachineLearning/src/Runtime/Classification.qs index aa3d9fae7e2..771270819ca 100644 --- a/MachineLearning/src/Runtime/Classification.qs +++ b/MachineLearning/src/Runtime/Classification.qs @@ -7,7 +7,7 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; - + operation _PrepareClassification( encoder : (LittleEndian => Unit is Adj + Ctl), parameters : Double[], @@ -28,7 +28,7 @@ namespace Microsoft.Quantum.MachineLearning { ) : Double { let nQubits = FeatureRegisterSize(sample); - let circEnc = NoisyInputEncoder(tolerance / IntAsDouble(Length(gates!)), sample); + let circEnc = ApproximateInputEncoder(tolerance / IntAsDouble(Length(gates!)), sample); let encodedSample = StateGenerator(nQubits, circEnc); return 1.0 - EstimateFrequencyA( _PrepareClassification(encodedSample::Apply, parameters, gates, _), diff --git a/MachineLearning/src/Runtime/InputEncoding.qs b/MachineLearning/src/Runtime/InputEncoding.qs index b7abf571e1d..b74e6d36823 100644 --- a/MachineLearning/src/Runtime/InputEncoding.qs +++ b/MachineLearning/src/Runtime/InputEncoding.qs @@ -64,10 +64,11 @@ namespace Microsoft.Quantum.MachineLearning { } } - function NoisyInputEncoder(tolerance: Double,coefficients : Double[]) : (LittleEndian => Unit is Adj + Ctl) { + function ApproximateInputEncoder(tolerance : Double,coefficients : Double[]) + : (LittleEndian => Unit is Adj + Ctl) { //First quantize the coefficients: for a coef x find such y*tolerance, where y is integer and |x-y*tolerance| \neq tolerance/2 let nCoefficients = Length(coefficients); - mutable coefficientsComplexPolar = new ComplexPolar[nCoefficients]; + mutable complexCoefficients = new ComplexPolar[0]; mutable cNegative = 0; for (idx in 0 .. nCoefficients - 1) { mutable coef = coefficients[idx]; @@ -80,7 +81,7 @@ namespace Microsoft.Quantum.MachineLearning { set coef = -coef; set ang = PI(); } - set coefficientsComplexPolar w/= idx <- ComplexPolar(coef, ang); + set complexCoefficients += [ComplexPolar(coef, ang)]; } // Check if we can apply the explicit two-qubit case. @@ -92,11 +93,11 @@ namespace Microsoft.Quantum.MachineLearning { // Here, by a "few," we mean fewer than the number of qubits required // to encode features. if ((cNegative > 0) and (IntAsDouble(cNegative) < Lg(IntAsDouble(Length(coefficients))) + 1.0)) { - return _EncodeSparseNegativeInput(cNegative, tolerance, coefficientsComplexPolar, _); //TODO:MORE:ACCEPTANCE ("Wines" passing soi far) + return _EncodeSparseNegativeInput(cNegative, tolerance, complexCoefficients, _); //TODO:MORE:ACCEPTANCE ("Wines" passing soi far) } // Finally, we fall back to arbitrary state preparation. - return ApproximatelyPrepareArbitraryState(tolerance, coefficientsComplexPolar, _); + return ApproximatelyPrepareArbitraryState(tolerance, complexCoefficients, _); } //EncodeNoisyInput //TODO:REVIEW: Design consideration! The implicit qubit count must be read off from the state encoder, NOT from the gate sequence! diff --git a/MachineLearning/src/Runtime/Training.qs b/MachineLearning/src/Runtime/Training.qs index 9acea0d7dc6..24d43a2c138 100644 --- a/MachineLearning/src/Runtime/Training.qs +++ b/MachineLearning/src/Runtime/Training.qs @@ -129,7 +129,7 @@ namespace Microsoft.Quantum.MachineLearning { } let stateGenerator = StateGenerator( nQubits, - NoisyInputEncoder(effectiveTolerance, sample::Features) + ApproximateInputEncoder(effectiveTolerance, sample::Features) ); let grad = EstimateGradient( gates, param, stateGenerator, From 7aec2623c405de66e7483b8800839361ffa71d3c Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Wed, 8 Jan 2020 16:05:57 -0800 Subject: [PATCH 15/17] Removed unused interop library. --- MachineLearning.sln | 76 +++----- .../src/{Runtime => }/Classification.qs | 0 MachineLearning/src/{Runtime => }/Convert.qs | 0 MachineLearning/src/DataModel/Interop.cs | 167 ------------------ .../src/{Runtime => }/Datasets/IrisDataset.qs | 0 .../Datasets/Properties/NamespaceInfo.qs | 0 .../src/{Runtime => }/Datasets/WineDataset.qs | 0 MachineLearning/src/{Runtime => }/Features.qs | 0 .../src/{Runtime => }/GradientEstimation.qs | 0 .../src/{Runtime => }/InputEncoding.qs | 0 ...ataModel.csproj => MachineLearning.csproj} | 38 ++-- .../{Runtime => }/Properties/NamespaceInfo.qs | 0 .../src/{Runtime => }/RotationSequences.qs | 24 +-- MachineLearning/src/Runtime/Runtime.csproj | 18 -- .../src/{Runtime => }/Structure.qs | 0 MachineLearning/src/{Runtime => }/Training.qs | 0 MachineLearning/src/{Runtime => }/Types.qs | 0 MachineLearning/src/{Runtime => }/Utils.qs | 4 +- .../src/{Runtime => }/Validation.qs | 0 .../tests/MachineLearningTests.csproj | 3 +- 20 files changed, 62 insertions(+), 268 deletions(-) rename MachineLearning/src/{Runtime => }/Classification.qs (100%) rename MachineLearning/src/{Runtime => }/Convert.qs (100%) delete mode 100644 MachineLearning/src/DataModel/Interop.cs rename MachineLearning/src/{Runtime => }/Datasets/IrisDataset.qs (100%) rename MachineLearning/src/{Runtime => }/Datasets/Properties/NamespaceInfo.qs (100%) rename MachineLearning/src/{Runtime => }/Datasets/WineDataset.qs (100%) rename MachineLearning/src/{Runtime => }/Features.qs (100%) rename MachineLearning/src/{Runtime => }/GradientEstimation.qs (100%) rename MachineLearning/src/{Runtime => }/InputEncoding.qs (100%) rename MachineLearning/src/{DataModel/DataModel.csproj => MachineLearning.csproj} (58%) rename MachineLearning/src/{Runtime => }/Properties/NamespaceInfo.qs (100%) rename MachineLearning/src/{Runtime => }/RotationSequences.qs (68%) delete mode 100644 MachineLearning/src/Runtime/Runtime.csproj rename MachineLearning/src/{Runtime => }/Structure.qs (100%) rename MachineLearning/src/{Runtime => }/Training.qs (100%) rename MachineLearning/src/{Runtime => }/Types.qs (100%) rename MachineLearning/src/{Runtime => }/Utils.qs (87%) rename MachineLearning/src/{Runtime => }/Validation.qs (100%) diff --git a/MachineLearning.sln b/MachineLearning.sln index 2e787d25cc1..a083c3f402f 100644 --- a/MachineLearning.sln +++ b/MachineLearning.sln @@ -3,15 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MachineLearning", "MachineLearning", "{A16B06ED-70E8-4494-B040-D446F0F74588}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MachineLearning", "MachineLearning", "{D067C787-94C3-4DB8-9012-1F22AE784BEF}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E540364C-047F-446E-B8C1-CD41224E2282}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearningTests", "MachineLearning\tests\MachineLearningTests.csproj", "{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runtime", "MachineLearning\src\Runtime\Runtime.csproj", "{4C399D64-0435-47E0-99D3-AA898E640717}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModel", "MachineLearning\src\DataModel\DataModel.csproj", "{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearningTests", "MachineLearning\tests\MachineLearningTests.csproj", "{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearning", "MachineLearning\src\MachineLearning.csproj", "{B045BF35-6BE6-4982-9618-8725C70D3F91}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -26,47 +22,33 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4C399D64-0435-47E0-99D3-AA898E640717}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x64.ActiveCfg = Debug|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x64.Build.0 = Debug|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x86.ActiveCfg = Debug|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x86.Build.0 = Debug|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Release|Any CPU.Build.0 = Release|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Release|x64.ActiveCfg = Release|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Release|x64.Build.0 = Release|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Release|x86.ActiveCfg = Release|Any CPU - {4C399D64-0435-47E0-99D3-AA898E640717}.Release|x86.Build.0 = Release|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x64.ActiveCfg = Debug|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x64.Build.0 = Debug|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x86.ActiveCfg = Debug|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x86.Build.0 = Debug|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|Any CPU.Build.0 = Release|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x64.ActiveCfg = Release|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x64.Build.0 = Release|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x86.ActiveCfg = Release|Any CPU - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x86.Build.0 = Release|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x64.ActiveCfg = Debug|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x64.Build.0 = Debug|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x86.ActiveCfg = Debug|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x86.Build.0 = Debug|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|Any CPU.Build.0 = Release|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x64.ActiveCfg = Release|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x64.Build.0 = Release|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x86.ActiveCfg = Release|Any CPU - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x86.Build.0 = Release|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x64.ActiveCfg = Debug|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x64.Build.0 = Debug|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x86.ActiveCfg = Debug|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x86.Build.0 = Debug|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|Any CPU.Build.0 = Release|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x64.ActiveCfg = Release|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x64.Build.0 = Release|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x86.ActiveCfg = Release|Any CPU + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x86.Build.0 = Release|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x64.ActiveCfg = Debug|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x64.Build.0 = Debug|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x86.ActiveCfg = Debug|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x86.Build.0 = Debug|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|Any CPU.Build.0 = Release|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x64.ActiveCfg = Release|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x64.Build.0 = Release|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x86.ActiveCfg = Release|Any CPU + {B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution - {E540364C-047F-446E-B8C1-CD41224E2282} = {A16B06ED-70E8-4494-B040-D446F0F74588} - {4C399D64-0435-47E0-99D3-AA898E640717} = {E540364C-047F-446E-B8C1-CD41224E2282} - {E4A725A7-3525-4FC5-9794-4317B5DB9C9B} = {E540364C-047F-446E-B8C1-CD41224E2282} - {0F1A243B-5263-4F97-ACAE-A7A6BAB8163B} = {A16B06ED-70E8-4494-B040-D446F0F74588} + {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C} = {D067C787-94C3-4DB8-9012-1F22AE784BEF} + {B045BF35-6BE6-4982-9618-8725C70D3F91} = {D067C787-94C3-4DB8-9012-1F22AE784BEF} EndGlobalSection EndGlobal diff --git a/MachineLearning/src/Runtime/Classification.qs b/MachineLearning/src/Classification.qs similarity index 100% rename from MachineLearning/src/Runtime/Classification.qs rename to MachineLearning/src/Classification.qs diff --git a/MachineLearning/src/Runtime/Convert.qs b/MachineLearning/src/Convert.qs similarity index 100% rename from MachineLearning/src/Runtime/Convert.qs rename to MachineLearning/src/Convert.qs diff --git a/MachineLearning/src/DataModel/Interop.cs b/MachineLearning/src/DataModel/Interop.cs deleted file mode 100644 index 87781964328..00000000000 --- a/MachineLearning/src/DataModel/Interop.cs +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.Core; -using Microsoft.Quantum.Simulation.Simulators; -using System; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - - - -/// -/// This code space provides suggested interoperability classes for running the -/// Q# Qccc (quantum circuit-centric classifier) code on Microsoft quantum simulator -/// -namespace Microsoft.Quantum.MachineLearning.Interop -{ - using Microsoft.Quantum.Logical; - using Microsoft.Quantum.MachineLearning; - using System.Runtime.CompilerServices; - using System.Runtime.ExceptionServices; - using System.Runtime.InteropServices.ComTypes; - using System.Xml; - - - /// - /// Quick conversions into IQArray format - /// - public class Qonvert - { - - public static long ToC(char pauli) - { - if (pauli.Equals('I')) - { - return 0L; - } - if (pauli.Equals('X')) - { - return 1L; - } - if (pauli.Equals('Y')) - { - return 2L; - } - if (pauli.Equals('Z')) - { - return 3L; - } - return -1L; - } - - public static IQArray> ToQ(List src) - { - List> tmp = new List>(src.Count); - for (int ix = 0; ix < src.Count; ix++) - { - tmp.Add(new QArray(src[ix])); - } - return new QArray>(tmp.ToArray()); - } - - public static IQArray ToQ(List src) - { - return new QArray(src.ToArray()); - } - - public static IQArray> ToQ(List src) - { - List> tmp = new List>(src.Count); - for (int ix = 0; ix < src.Count; ix++) - { - tmp.Add(new QArray(src[ix])); - } - return new QArray>(tmp.ToArray()); - } - } //Qonvert - - public class ClassificationModel - { - long _nQubits; - IQArray> _structure; - IQArray _cachedParameters; - double _bias; - - public ClassificationModel(long nQubits) - { - _nQubits = nQubits; - _structure = null; - _cachedParameters = null; - _bias = -2.0; - } - - public ClassificationModel(long nQubits, List structure) - { - _nQubits = nQubits; - _structure = Qonvert.ToQ(structure); - _cachedParameters = null; - _bias = -2.0; - } - - public ClassificationModel(long nQubits, List structure,double[] parameters) - { - _nQubits = nQubits; - _structure = Qonvert.ToQ(structure); - _cachedParameters = new QArray(parameters); - _bias = -2.0; - } - - public ClassificationModel(long nQubits, List structure, double[] parameters, double bias) - { - _nQubits = nQubits; - _structure = Qonvert.ToQ(structure); - _cachedParameters = new QArray(parameters); - _bias = bias; - } - - public bool isTrained - { - get { return (_bias > -1.5) && (_structure != null) && (_cachedParameters != null); } - } - - public IQArray> CircuitStructure - { - get { return _structure; } - set { _structure = value; } - } - - public IQArray CachedParameters - { - get { return _cachedParameters; } - } - - public double Bias - { - get { return _bias; } - } - - public long CountMisclassifications(double tolerance, IQArray> samples, IQArray knownLabels, IQArray> validationSchedule, long nMeasurements, uint randomizationSeed) - { - if (this.isTrained) - { - var sim = new QuantumSimulator(false, randomizationSeed); - return CountValidationMisses.Run(sim, tolerance, this._nQubits, samples, knownLabels, validationSchedule, this._structure, this.CachedParameters, this.Bias, nMeasurements).Result; - } - return long.MaxValue; - } - - public long CountMisclassifications(double tolerance, List samples, List knownLabels, List validationSchedule, long nMeasurements, uint randomizationSeed) - { - return CountMisclassifications(tolerance, Qonvert.ToQ(samples), Qonvert.ToQ(knownLabels), Qonvert.ToQ(validationSchedule), nMeasurements, randomizationSeed); - } - - public long CountMisclassifications(double tolerance, List samples, List knownLabels, long nMeasurements, uint randomizationSeed) - { - var validationSchedule = new List(1); - validationSchedule.Add(new long[] { 0L, 1L, ((long)(samples.Count - 1)) }); - return CountMisclassifications(tolerance, Qonvert.ToQ(samples), Qonvert.ToQ(knownLabels), Qonvert.ToQ(validationSchedule), nMeasurements, randomizationSeed); - } - - } //class ClassificationModel - -} diff --git a/MachineLearning/src/Runtime/Datasets/IrisDataset.qs b/MachineLearning/src/Datasets/IrisDataset.qs similarity index 100% rename from MachineLearning/src/Runtime/Datasets/IrisDataset.qs rename to MachineLearning/src/Datasets/IrisDataset.qs diff --git a/MachineLearning/src/Runtime/Datasets/Properties/NamespaceInfo.qs b/MachineLearning/src/Datasets/Properties/NamespaceInfo.qs similarity index 100% rename from MachineLearning/src/Runtime/Datasets/Properties/NamespaceInfo.qs rename to MachineLearning/src/Datasets/Properties/NamespaceInfo.qs diff --git a/MachineLearning/src/Runtime/Datasets/WineDataset.qs b/MachineLearning/src/Datasets/WineDataset.qs similarity index 100% rename from MachineLearning/src/Runtime/Datasets/WineDataset.qs rename to MachineLearning/src/Datasets/WineDataset.qs diff --git a/MachineLearning/src/Runtime/Features.qs b/MachineLearning/src/Features.qs similarity index 100% rename from MachineLearning/src/Runtime/Features.qs rename to MachineLearning/src/Features.qs diff --git a/MachineLearning/src/Runtime/GradientEstimation.qs b/MachineLearning/src/GradientEstimation.qs similarity index 100% rename from MachineLearning/src/Runtime/GradientEstimation.qs rename to MachineLearning/src/GradientEstimation.qs diff --git a/MachineLearning/src/Runtime/InputEncoding.qs b/MachineLearning/src/InputEncoding.qs similarity index 100% rename from MachineLearning/src/Runtime/InputEncoding.qs rename to MachineLearning/src/InputEncoding.qs diff --git a/MachineLearning/src/DataModel/DataModel.csproj b/MachineLearning/src/MachineLearning.csproj similarity index 58% rename from MachineLearning/src/DataModel/DataModel.csproj rename to MachineLearning/src/MachineLearning.csproj index 3aadd057759..6239e0d5313 100644 --- a/MachineLearning/src/DataModel/DataModel.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,26 +1,36 @@ - - + netstandard2.1 x64 - Microsoft.Quantum.MachineLearning.DataModel - bin\$(BuildConfiguration)\$(PlatformTarget)\$(AssemblyName).xml + Microsoft.Quantum.MachineLearning true + + false + + + + + + + + + - True Microsoft Microsoft's Quantum ML Libraries. © Microsoft Corporation. All rights reserved. Microsoft.Quantum.MachineLearning - See: https://docs.microsoft.com/en-us/quantum/relnotes/ + See: https://docs.microsoft.com/quantum/relnotes/ https://github.com/Microsoft/QuantumLibraries/raw/master/LICENSE.txt - https://github.com/Microsoft/QuantumLibraries/tree/master/Chemistry + https://github.com/Microsoft/QuantumLibraries/tree/master/MachineLearning https://secure.gravatar.com/avatar/bd1f02955b2853ba0a3b1cdc2434e8ec.png Quantum Q# Qsharp 1591 - true true true true @@ -28,16 +38,4 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb;.xml - - - - - - - - - - - - diff --git a/MachineLearning/src/Runtime/Properties/NamespaceInfo.qs b/MachineLearning/src/Properties/NamespaceInfo.qs similarity index 100% rename from MachineLearning/src/Runtime/Properties/NamespaceInfo.qs rename to MachineLearning/src/Properties/NamespaceInfo.qs diff --git a/MachineLearning/src/Runtime/RotationSequences.qs b/MachineLearning/src/RotationSequences.qs similarity index 68% rename from MachineLearning/src/Runtime/RotationSequences.qs rename to MachineLearning/src/RotationSequences.qs index 1687d8c99dc..31fa95373fd 100644 --- a/MachineLearning/src/Runtime/RotationSequences.qs +++ b/MachineLearning/src/RotationSequences.qs @@ -7,12 +7,12 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon; - /// What is the minimum number of qubits - /// to support the subject gate sequence? - /// Find the maximum qubit index m occuring - /// in a gate sequence and return m+1 - function NQubitsRequired(seq : GateSequence) : Int { - mutable nQubitsRequired = 0; + /// What is the minimum number of qubits + /// to support the subject gate sequence? + /// Find the maximum qubit index m occuring + /// in a gate sequence and return m+1 + function NQubitsRequired(seq : GateSequence) : Int { + mutable nQubitsRequired = 0; for (gate in seq!) { set nQubitsRequired = Fold( MaxI, 0, @@ -23,11 +23,11 @@ namespace Microsoft.Quantum.MachineLearning { ); } return nQubitsRequired; - } + } - /// Apply parameterized gate sequence to subject qubit register - /// - operation _ApplyGates(parameters : Double[], gates: GateSequence, qubits : Qubit[]) : (Unit) is Adj + Ctl { + /// Apply parameterized gate sequence to subject qubit register + /// + operation _ApplyGates(parameters : Double[], gates: GateSequence, qubits : Qubit[]) : (Unit) is Adj + Ctl { //dumpRegisterToConsole(qubits); for (gate in gates!) { // let (gsp,p,ix) = gt!; @@ -44,8 +44,8 @@ namespace Microsoft.Quantum.MachineLearning { } } - operation ApplyGates(parameters : Double[], gates: GateSequence): (Qubit[] => Unit is Adj + Ctl) { + operation ApplyGates(parameters : Double[], gates: GateSequence): (Qubit[] => Unit is Adj + Ctl) { return _ApplyGates(parameters,gates,_); - } + } } diff --git a/MachineLearning/src/Runtime/Runtime.csproj b/MachineLearning/src/Runtime/Runtime.csproj deleted file mode 100644 index 60fa28844d9..00000000000 --- a/MachineLearning/src/Runtime/Runtime.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - netstandard2.1 - x64 - Microsoft.Quantum.MachineLearning.Runtime - true - - false - - - - - - - diff --git a/MachineLearning/src/Runtime/Structure.qs b/MachineLearning/src/Structure.qs similarity index 100% rename from MachineLearning/src/Runtime/Structure.qs rename to MachineLearning/src/Structure.qs diff --git a/MachineLearning/src/Runtime/Training.qs b/MachineLearning/src/Training.qs similarity index 100% rename from MachineLearning/src/Runtime/Training.qs rename to MachineLearning/src/Training.qs diff --git a/MachineLearning/src/Runtime/Types.qs b/MachineLearning/src/Types.qs similarity index 100% rename from MachineLearning/src/Runtime/Types.qs rename to MachineLearning/src/Types.qs diff --git a/MachineLearning/src/Runtime/Utils.qs b/MachineLearning/src/Utils.qs similarity index 87% rename from MachineLearning/src/Runtime/Utils.qs rename to MachineLearning/src/Utils.qs index c412f05461d..0b710c8bf29 100644 --- a/MachineLearning/src/Runtime/Utils.qs +++ b/MachineLearning/src/Utils.qs @@ -5,9 +5,9 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Math; - function _AllNearlyEqualD(v1: Double[], v2: Double[]):Bool { + function _AllNearlyEqualD(v1: Double[], v2: Double[]):Bool { return Length(v1) == Length(v2) and All(NearlyEqualD, Zip(v1, v2)); - } + } operation _TailMeasurement(nQubits : Int) : (Qubit[] => Result) { let paulis = ConstantArray(nQubits, PauliI) w/ (nQubits - 1) <- PauliZ; diff --git a/MachineLearning/src/Runtime/Validation.qs b/MachineLearning/src/Validation.qs similarity index 100% rename from MachineLearning/src/Runtime/Validation.qs rename to MachineLearning/src/Validation.qs diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index d2f2b5afd76..794fb415906 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -14,7 +14,6 @@ - - + From 427bddc7560b9a81c7a471fbc1fdb5e35a0e54fd Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Wed, 8 Jan 2020 16:09:58 -0800 Subject: [PATCH 16/17] Update pack script for new layout. --- Build/pack.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/pack.ps1 b/Build/pack.ps1 index a69ed719b75..d6892b6f3f7 100644 --- a/Build/pack.ps1 +++ b/Build/pack.ps1 @@ -14,7 +14,7 @@ function Pack-One() { -c $Env:BUILD_CONFIGURATION ` -v $Env:BUILD_VERBOSITY ` -o $Env:NUGET_OUTDIR ` - /property:PackageVersion=$Env:NUGET_VERSION + /property:PackageVersion=$Env:NUGET_VERSION if ($LastExitCode -ne 0) { Write-Host "##vso[task.logissue type=error;]Failed to pack $project." @@ -29,7 +29,7 @@ Write-Host "##[info]Pack Chemistry library" Pack-One '../Chemistry/src/DataModel/DataModel.csproj' Write-Host "##[info]Pack QML library" -Pack-One '../MachineLearning/src/DataModel/DataModel.csproj' +Pack-One '../MachineLearning/src/MachineLearning.csproj' Write-Host "##[info]Pack Numerics library" Pack-One '../Numerics/src/Numerics.csproj' From 7e25c47836988baff9822de067683bb23f147ba4 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Mon, 13 Jan 2020 10:38:28 -0800 Subject: [PATCH 17/17] Addressing feedback. --- MachineLearning/src/GradientEstimation.qs | 6 +++--- MachineLearning/src/InputEncoding.qs | 24 +++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/MachineLearning/src/GradientEstimation.qs b/MachineLearning/src/GradientEstimation.qs index 56764f8733c..26fd7d039e4 100644 --- a/MachineLearning/src/GradientEstimation.qs +++ b/MachineLearning/src/GradientEstimation.qs @@ -17,7 +17,7 @@ namespace Microsoft.Quantum.MachineLearning { op(LittleEndian(target)); } - operation _EstimateFiniteDifference( + operation _EstimateDerivativeWithParameterShift( inputEncoder : StateGenerator, gates : GateSequence, parameters : (Double[], Double[]), @@ -81,7 +81,7 @@ namespace Microsoft.Quantum.MachineLearning { w/ gate::Index <- (param[gate::Index] + PI()); // NB: This the *antiderivative* of the bracket - let newDer = _EstimateFiniteDifference( + let newDer = _EstimateDerivativeWithParameterShift( sg, gates, (param, paramShift), nQubits, nMeasurements ); if (IsEmpty(gate::Span::ControlIndices)) { @@ -93,7 +93,7 @@ namespace Microsoft.Quantum.MachineLearning { w/ gate::Index <- (param[gate::Index] + 3.0 * PI()); //Assumption: any rotation R has the property that R(\theta+2 Pi)=(-1).R(\theta) // NB: This the *antiderivative* of the bracket - let newDer1 = _EstimateFiniteDifference( + let newDer1 = _EstimateDerivativeWithParameterShift( sg, gates, (param, controlledShift), nQubits, nMeasurements ); set grad w/= gate::Index <- (grad[gate::Index] + 0.5 * (newDer - newDer1)); diff --git a/MachineLearning/src/InputEncoding.qs b/MachineLearning/src/InputEncoding.qs index b74e6d36823..1eb4b1db7d3 100644 --- a/MachineLearning/src/InputEncoding.qs +++ b/MachineLearning/src/InputEncoding.qs @@ -68,20 +68,20 @@ namespace Microsoft.Quantum.MachineLearning { : (LittleEndian => Unit is Adj + Ctl) { //First quantize the coefficients: for a coef x find such y*tolerance, where y is integer and |x-y*tolerance| \neq tolerance/2 let nCoefficients = Length(coefficients); - mutable complexCoefficients = new ComplexPolar[0]; + mutable complexCoefficients = new ComplexPolar[Length(coefficients)]; mutable cNegative = 0; - for (idx in 0 .. nCoefficients - 1) { - mutable coef = coefficients[idx]; + for ((idx, coef) in Enumerated(coefficients)) { + mutable magnitude = coef; if (tolerance > 1E-9) { - set coef = tolerance * IntAsDouble(Round(coefficients[idx] / tolerance)); //quantization + set magnitude = tolerance * IntAsDouble(Round(coefficients[idx] / tolerance)); //quantization } mutable ang = 0.0; - if (coef < 0.0) { + if (magnitude < 0.0) { set cNegative += 1; - set coef = -coef; + set magnitude = -magnitude; set ang = PI(); } - set complexCoefficients += [ComplexPolar(coef, ang)]; + set complexCoefficients w/= idx <- ComplexPolar(magnitude, ang); } // Check if we can apply the explicit two-qubit case. @@ -106,13 +106,13 @@ namespace Microsoft.Quantum.MachineLearning { /// The vector of 'coefficients' does not have to be unitary function InputEncoder(coefficients : Double[]): (LittleEndian => Unit is Adj + Ctl) { //default implementation, does not respect sparcity - mutable complexCoefficients = new ComplexPolar[0]; - for (coefficient in coefficients) { - set complexCoefficients += [ComplexPolar( + mutable complexCoefficients = new ComplexPolar[Length(coefficients)]; + for ((idx, coefficient) in Enumerated(coefficients)) { + set complexCoefficients w/= idx <- ComplexPolar( coefficient >= 0.0 ? (coefficient, 0.0) | (-coefficient, PI()) - )]; + ); } if (_CanApplyTwoQubitCase(coefficients)) { return _ApplyTwoQubitCase(coefficients, _); @@ -120,4 +120,4 @@ namespace Microsoft.Quantum.MachineLearning { return ApproximatelyPrepareArbitraryState(1E-12, complexCoefficients, _); //this is preparing the state almost exactly so far } -} \ No newline at end of file +}