From 4ed1278a40ad88a10641ce0e6fb1a3d9d7f7d0ec Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Fri, 25 Feb 2022 15:06:53 -0800 Subject: [PATCH 01/66] Started work on updating to BB 0.3. --- .../OrbitalIntegral/OrbitalIntegral.cs | 80 +++- .../OrbitalIntegralExtensions.cs | 23 +- .../Broombridge/BroombridgeData.cs | 18 +- .../BroombridgeDataStructurev0.1.cs | 2 +- .../BroombridgeDataStructurev0.3.cs | 408 ++++++++++++++++++ .../Broombridge/BroombridgeSerializer.cs | 64 ++- .../Broombridge/BroombridgeVersionUpdater.cs | 38 +- .../SamplesTests/DocsSecondQuantization.cs | 2 +- 8 files changed, 580 insertions(+), 55 deletions(-) create mode 100644 Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs diff --git a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs index eaff2be4cff..43fa2e39c0f 100644 --- a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs +++ b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs @@ -24,6 +24,17 @@ public enum Convention Dirac, Mulliken } + // NB [Design note]: this intentionally duplicates the corresponding + // enum in the V0_3 class, allowing forward versions + // to add or modify permutation symmetries without + // retroactively changing the definition of V0_3. + public enum PermutationSymmetry + { + Eightfold, + Fourfold, + Trivial + } + /// /// Indices of orbitals in the overlap integral. /// @@ -107,6 +118,41 @@ public void ResetSign() /// Length of orbital indices. public int Length => OrbitalIndices.Length; + private static int[][] EnumerateTwoBodyPermutations(PermutationSymmetry symmetry, int i, int j, int k, int l) => + symmetry switch + { + // (ij|kl) = (ij|lk) = (ji|kl) = (ji|lk) = + // (kl|ij) = (lk|ij) = (kl|ji) = (lk|ji) + PermutationSymmetry.Eightfold => new int[][] + { + new int[] { i, j, k, l }, // 0123 + new int[] { j, i, l, k }, // 1032 + new int[] { k, l, i, j }, // 2301 + new int[] { l, k, j, i }, // 3210 + new int[] { i, k, j, l }, // 0213 + new int[] { k, i, l, j }, // 2031 + new int[] { j, l, i, k }, // 1302 + new int[] { l, j, k, i } // 3120 + }, + // (ij|kl) = (ji|lk) = (kl|ij) = (lk|ji) + PermutationSymmetry.Fourfold => new int[][] + { + new int[] { i, j, k, l }, + new int[] { j, i, l, k }, + new int[] { k, l, i, j }, + new int[] { l, k, j, i } + }, + PermutationSymmetry.Trivial => new int[][] + { + new int[] { i, j, k, l } + }, + _ => throw new Exception($"Permutation symmetry {symmetry} is not valid for two-body permutations.") + }; + + [Obsolete("Permutation symmetries must be specified explicitly as of Broombridge 0.3.", false)] + public OrbitalIntegral[] EnumerateOrbitalSymmetries() => + EnumerateOrbitalSymmetries(PermutationSymmetry.Eightfold); + /// /// Enumerates over all orbital integrals with the same coefficient @@ -116,7 +162,7 @@ public void ResetSign() /// - Orbitals are assumed to be real. /// /// Array of orbital integrals with the same coefficient. - public OrbitalIntegral[] EnumerateOrbitalSymmetries() + public OrbitalIntegral[] EnumerateOrbitalSymmetries(PermutationSymmetry symmetry) { var coefficient = Coefficient; if (OrbitalIndices.Length == 2) @@ -132,21 +178,9 @@ public OrbitalIntegral[] EnumerateOrbitalSymmetries() } else if (OrbitalIndices.Length == 4) { - var i = OrbitalIndices[0]; - var j = OrbitalIndices[1]; - var k = OrbitalIndices[2]; - var l = OrbitalIndices[3]; - var symmetries = new int[][] { - new int[] { i, j, k, l }, // 0123 - new int[] { j, i, l, k }, // 1032 - new int[] { k, l, i, j }, // 2301 - new int[] { l, k, j, i }, // 3210 - new int[] { i, k, j, l }, // 0213 - new int[] { k, i, l, j }, // 2031 - new int[] { j, l, i, k }, // 1302 - new int[] { l, j, k, i } // 3120 - }; - return symmetries.Distinct(new ArrayEqualityComparer()).Select(o => new OrbitalIntegral(o, coefficient)).ToArray(); + return EnumerateTwoBodyPermutations(symmetry, OrbitalIndices[0], OrbitalIndices[1], OrbitalIndices[2], OrbitalIndices[3]) + .Distinct(new ArrayEqualityComparer()) + .Select(o => new OrbitalIntegral(o, coefficient)).ToArray(); } else { @@ -163,14 +197,18 @@ public OrbitalIntegral Clone() return new OrbitalIntegral(newArray, Coefficient); } + [Obsolete("Permutation symmetries must be specified explicitly as of Broombridge 0.3.", false)] + public OrbitalIntegral ToCanonicalForm() => + ToCanonicalForm(PermutationSymmetry.Eightfold); + /// /// Returns orbital indices sorted in a canonical form that generates /// the same set of orbital integrals through . /// /// An in canonical form. - public OrbitalIntegral ToCanonicalForm() + public OrbitalIntegral ToCanonicalForm(PermutationSymmetry symmetry) { - var symmetries = EnumerateOrbitalSymmetries().Select(o => o.OrbitalIndices).ToList(); + var symmetries = EnumerateOrbitalSymmetries(symmetry).Select(o => o.OrbitalIndices).ToList(); symmetries.Sort(new ArrayLexicographicComparer()); return new OrbitalIntegral(symmetries.First(), Coefficient); } @@ -179,13 +217,13 @@ public OrbitalIntegral ToCanonicalForm() /// Checks of this orbital integral has indices sorted in canonical order. /// /// Returns if the orbital integral indices are canonically sorted - /// and otherwise. + /// and false otherwise. /// - public bool IsInCanonicalOrder() + public bool IsInCanonicalOrder(PermutationSymmetry symmetry) { if (Length == 2 || Length == 4) { - var canonicalOrder = ToCanonicalForm(); + var canonicalOrder = ToCanonicalForm(symmetry); return canonicalOrder.OrbitalIndices.SequenceEqual(OrbitalIndices); } else diff --git a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs index 694bdf89527..7ea73da05d0 100644 --- a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs +++ b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs @@ -20,6 +20,15 @@ namespace Microsoft.Quantum.Chemistry.OrbitalIntegrals /// public static partial class Extensions { + internal static OrbitalIntegral.PermutationSymmetry FromBroombridgeV0_3(this Broombridge.V0_3.PermutationSymmetry symmetry) => + symmetry switch + { + Broombridge.V0_3.PermutationSymmetry.Eightfold => OrbitalIntegral.PermutationSymmetry.Eightfold, + Broombridge.V0_3.PermutationSymmetry.Fourfold => OrbitalIntegral.PermutationSymmetry.Fourfold, + Broombridge.V0_3.PermutationSymmetry.Trivial => OrbitalIntegral.PermutationSymmetry.Trivial, + _ => throw new Exception($"Broombridge v0.3 permutation symmetry kind {symmetry} is not supported.") + }; + /// /// Method for constructing a fermion Hamiltonian from an orbital integral Hamiltonian. @@ -60,7 +69,8 @@ public static partial class Extensions public static IEnumerable<(HermitianFermionTerm, double)> ToHermitianFermionTerms( this OrbitalIntegral orbitalIntegral, int nOrbitals, - IndexConvention indexConvention = IndexConvention.UpDown) + IndexConvention indexConvention = IndexConvention.UpDown, + OrbitalIntegral.PermutationSymmetry symmetry = OrbitalIntegral.PermutationSymmetry.Eightfold) { var termType = orbitalIntegral.TermType; if (termType == TermType.OrbitalIntegral.OneBody) @@ -69,7 +79,7 @@ public static partial class Extensions } else if (termType == TermType.OrbitalIntegral.TwoBody) { - return orbitalIntegral.ToTwoBodySpinOrbitalTerms(nOrbitals, indexConvention); + return orbitalIntegral.ToTwoBodySpinOrbitalTerms(nOrbitals, indexConvention, symmetry); } else if(termType == TermType.OrbitalIntegral.Identity) { @@ -95,7 +105,9 @@ public static partial class Extensions { // One-electron orbital integral symmetries // ij = ji - var pqSpinOrbitals = orbitalIntegral.EnumerateOrbitalSymmetries().EnumerateSpinOrbitals(); + var pqSpinOrbitals = orbitalIntegral + .EnumerateOrbitalSymmetries(OrbitalIntegral.PermutationSymmetry.Eightfold) + .EnumerateSpinOrbitals(); var coefficient = orbitalIntegral.Coefficient; @@ -124,11 +136,12 @@ public static partial class Extensions private static IEnumerable<(HermitianFermionTerm, double)> ToTwoBodySpinOrbitalTerms( this OrbitalIntegral orbitalIntegral, int nOrbitals, - IndexConvention indexConvention) + IndexConvention indexConvention, + OrbitalIntegral.PermutationSymmetry symmetry) { // Two-electron orbital integral symmetries // ijkl = lkji = jilk = klij = ikjl = ljki = kilj = jlik. - var pqrsSpinOrbitals = orbitalIntegral.EnumerateOrbitalSymmetries().EnumerateSpinOrbitals(); + var pqrsSpinOrbitals = orbitalIntegral.EnumerateOrbitalSymmetries(symmetry).EnumerateSpinOrbitals(); var coefficient = orbitalIntegral.Coefficient; diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeData.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeData.cs index f438ce9fc69..cbf370b9d12 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeData.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeData.cs @@ -22,6 +22,8 @@ namespace Microsoft.Quantum.Chemistry.Broombridge /// /// Latest Broombridge format. /// + // NB: When obsoleted, this should likely be made internal rather than + // removed. [Obsolete( "Please use collections of ElectronicStructureProblem instead.", error: false @@ -39,7 +41,7 @@ public Data() /// /// Raw deserialized Broombridge data. /// - public V0_2.Data Raw { get; set; } + public V0_3.Data Raw { get; set; } // Root of Broombridge data structure @@ -62,12 +64,12 @@ public Data() /// /// Deserialized Broombridge data /// - /// Broombridge data structure. - internal Data(Broombridge.V0_2.Data broombridgeV0_2) + /// Broombridge data structure. + internal Data(Broombridge.V0_3.Data broombridgeV0_3) { - Raw = broombridgeV0_2; - Schema = broombridgeV0_2.Schema; - VersionNumber = VersionNumber.v0_2; + Raw = broombridgeV0_3; + Schema = broombridgeV0_3.Schema; + VersionNumber = VersionNumber.v0_3; ProblemDescriptions = Raw.ProblemDescriptions.Select(problem => ProblemDescription.ProcessRawProblemDescription(problem)); } @@ -114,14 +116,14 @@ public struct ProblemDescription /// /// Problem description to be converted /// The internal problem description data structure. - public static ProblemDescription ProcessRawProblemDescription(Broombridge.V0_2.ProblemDescription problem) + public static ProblemDescription ProcessRawProblemDescription(Broombridge.V0_3.ProblemDescription problem) { var problemDescription = new ProblemDescription { EnergyOffset = problem.EnergyOffset.Value + problem.CoulombRepulsion.Value, NElectrons = problem.NElectrons, NOrbitals = problem.NOrbitals, - OrbitalIntegralHamiltonian = V0_2.ToOrbitalIntegralHamiltonian(problem), + OrbitalIntegralHamiltonian = V0_3.ToOrbitalIntegralHamiltonian(problem), Wavefunctions = problem.InitialStates?.FromBroombridgeV0_2() ?? new Dictionary>() }; return problemDescription; diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs index 456af264f23..b3d68d045af 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs @@ -92,7 +92,7 @@ internal static class BroombridgeExtensionsV0_1 ConvertIndices( term .Key - .ToCanonicalForm() + .ToCanonicalForm(OrbitalIntegral.PermutationSymmetry.Eightfold) .OrbitalIndices, OrbitalIntegral.Convention.Dirac, OrbitalIntegral.Convention.Mulliken diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs new file mode 100644 index 00000000000..6b889b29495 --- /dev/null +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs @@ -0,0 +1,408 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#nullable enable + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Linq; +using System.Text.RegularExpressions; +using YamlDotNet.Core; +using YamlDotNet.Serialization; +using System.Numerics; + +using Microsoft.Quantum.Chemistry.OrbitalIntegrals; +using Microsoft.Quantum.Chemistry.Fermion; +using Microsoft.Quantum.Chemistry.LadderOperators; +using Newtonsoft.Json; +using System.Runtime.Serialization; + +using static Microsoft.Quantum.Chemistry.OrbitalIntegrals.IndexConventionConversions; + +namespace Microsoft.Quantum.Chemistry.Broombridge +{ + // What data structures are unmodified from previous versions? + using Format = V0_1.Format; + using Generator = V0_1.Generator; + using BibliographyItem = V0_1.BibliographyItem; + using Geometry = V0_1.Geometry; + using HasUnits = V0_1.HasUnits; + using BasisSet = V0_1.BasisSet; + using SimpleQuantity = V0_1.SimpleQuantity; + using BoundedQuantity = V0_1.BoundedQuantity; + using State = V0_2.State; + using ClusterOperator = V0_2.ClusterOperator; + + internal static class BroombridgeExtensionsV0_3 + { + internal static V0_3.ProblemDescription ToBroombridgeV0_3( + this ElectronicStructureProblem problem + ) => new V0_3.ProblemDescription + { + BasisSet = problem.BasisSet != null + ? new V0_1.BasisSet + { + Name = problem.BasisSet?.Name, + Type = problem.BasisSet?.Type + } + : null, + CoulombRepulsion = problem.CoulombRepulsion.ToBroombridgeV0_2(), + EnergyOffset = problem.EnergyOffset.ToBroombridgeV0_2(), + FciEnergy = problem.FciEnergy?.ToBroombridgeV0_2(), + Geometry = problem.Geometry?.ToBroombridgeV0_2(), + Hamiltonian = problem.OrbitalIntegralHamiltonian.ToBroombridgeV0_3(), + InitialStates = problem.InitialStates?.ToBroombridgeV0_2(), + Metadata = problem.Metadata, + NElectrons = problem.NElectrons, + NOrbitals = problem.NOrbitals, + ScfEnergy = problem.ScfEnergy?.ToBroombridgeV0_2(), + ScfEnergyOffset = problem.ScfEnergyOffset?.ToBroombridgeV0_2() + }; + + internal static V0_3.ArrayQuantityWithSymmetry TransformKeys( + this V0_3.ArrayQuantityWithSymmetry arrayQuantity, + Func transform + ) => + new V0_3.ArrayQuantityWithSymmetry + { + Format = arrayQuantity.Format, + IndexConvention = arrayQuantity.IndexConvention, + Symmetry = arrayQuantity.Symmetry, + Units = arrayQuantity.Units, + Values = arrayQuantity + .Values + .Select(item => new V0_3.ArrayQuantityWithSymmetry.Item + { + Key = transform(item.Key), + Value = item.Value + }) + .ToList() + }; + + internal static V0_3.ArrayQuantityWithSymmetry WithSymmetry( + this V0_3.ArrayQuantity arrayQuantity, + V0_3.Symmetry symmetry + ) => + new V0_3.ArrayQuantityWithSymmetry + { + Format = arrayQuantity.Format, + IndexConvention = arrayQuantity.IndexConvention, + Symmetry = symmetry, + Units = arrayQuantity.Units, + Values = arrayQuantity.Values + }; + + internal static V0_3.HamiltonianData ToBroombridgeV0_3(this OrbitalIntegralHamiltonian hamiltonian) + { + var twoElectronIntegrals = hamiltonian + .Terms[TermType.OrbitalIntegral.TwoBody] + .ToBroombridgeV0_3(new V0_3.Symmetry + { + // List terms explicitly with no compression. + Permutation = V0_3.PermutationSymmetry.Trivial + }); + twoElectronIntegrals.IndexConvention = OrbitalIntegral.Convention.Mulliken; + return new V0_3.HamiltonianData + { + OneElectronIntegrals = hamiltonian + .Terms[TermType.OrbitalIntegral.OneBody] + .ToBroombridgeV0_3(new V0_3.Symmetry + { + // List terms explicitly with no compression. + Permutation = V0_3.PermutationSymmetry.Trivial + }) + .TransformKeys(idxs => (idxs[0], idxs[1])), + TwoElectronIntegrals = twoElectronIntegrals + .TransformKeys(idxs => (idxs[0], idxs[1], idxs[2], idxs[3])) + }; + } + + internal static V0_3.ArrayQuantityWithSymmetry ToBroombridgeV0_3( + this Dictionary terms, + V0_3.Symmetry symmetry + ) => + new V0_3.ArrayQuantityWithSymmetry() + { + Format = V0_3.ArrayFormat.Sparse, + Units = "hartree", + Values = terms.Select(term => + { + var idxs = ConvertIndices( + term + .Key + .ToCanonicalForm(symmetry.Permutation.FromBroombridgeV0_3()) + .OrbitalIndices, + OrbitalIntegral.Convention.Dirac, + OrbitalIntegral.Convention.Mulliken + ) + .ToOneBasedIndices() + .Select(idx => (long)idx) + .ToArray(); + return new V0_3.ArrayQuantity.Item + { + Key = idxs, + Value = term.Value.Value + }; + }).ToList(), + Symmetry = symmetry + }; + + internal static V0_3.HamiltonianData ToBroombridgeV0_3(this V0_1.HamiltonianData hamiltonianData) => + new V0_3.HamiltonianData + { + ParticleHoleRepresentation = hamiltonianData.ParticleHoleRepresentation?.ToBroombridgeV0_3(), + OneElectronIntegrals = hamiltonianData + .OneElectronIntegrals + .ToBroombridgeV0_3() + .WithSymmetry(new V0_3.Symmetry + { + Permutation = V0_3.PermutationSymmetry.Eightfold + }) + .TransformKeys(key => (key[0], key[1])), + TwoElectronIntegrals = hamiltonianData + .TwoElectronIntegrals + .ToBroombridgeV0_3() + .WithSymmetry(new V0_3.Symmetry + { + Permutation = V0_3.PermutationSymmetry.Eightfold + }) + .TransformKeys(key => (key[0], key[1], key[2], key[3])), + }; + + internal static V0_3.ArrayQuantity ToBroombridgeV0_3(this V0_1.ArrayQuantity array) => + new V0_3.ArrayQuantity + { + Format = Enum.TryParse(array.Format, out var format) + ? format + : throw new Exception($"Invalid array format {array.Format} when converting 0.1 array quantity to 0.3 array quantity."), + IndexConvention = array.IndexConvention, + Units = array.Units, + Values = array + .Values + .Select(item => new V0_3.ArrayQuantity.Item + { + Key = item.Item1, + Value = item.Item2 + }) + .ToList() + }; + + internal static (O, O) Select(this (I, I) value, Func func) => + (func(value.Item1), func(value.Item2)); + internal static (O, O, O) Select(this (I, I, I) value, Func func) => + (func(value.Item1), func(value.Item2), func(value.Item3)); + internal static (O, O, O, O) Select(this (I, I, I, I) value, Func func) => + (func(value.Item1), func(value.Item2), func(value.Item3), func(value.Item4)); + + internal static T[] ToArray(this (T, T) value) => + new T[] { value.Item1, value.Item2 }; + internal static T[] ToArray(this (T, T, T) value) => + new T[] { value.Item1, value.Item2, value.Item3 }; + internal static T[] ToArray(this (T, T, T, T) value) => + new T[] { value.Item1, value.Item2, value.Item3, value.Item4 }; + } + + /// + /// Broombridge v0.3 format. + /// + /// Changes from v0.2: + /// + /// Addition of new symmetry key in HamiltonianData. + /// Sparse-format arrays are now represented with separate keys and values to simplify parsing logic. + /// + /// + #region Broombridge v0.3 format + public static class V0_3 + { + // TODO: This URL is not yet valid! + public static string SchemaUrl = "https://raw.githubusercontent.com/microsoft/Quantum/main/Chemistry/Schema/broombridge-0.3.schema.json"; + + // Root of Broombridge data structure + public struct Data + { + public static readonly Format DefaultFormat = new Broombridge.V0_1.Format + { + Version = "0.3" + }; + + [YamlMember(Alias = "$schema", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "$schema")] + public string Schema { get; set; } + + [YamlMember(Alias = "format", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "format")] + public Format Format { get; set; } + + [YamlMember(Alias = "generator", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "generator")] + public Generator Generator { get; set; } + + [YamlMember(Alias = "bibliography", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "bibliography")] + public List Bibliography { get; set; } + + [YamlMember(Alias = "problem_description", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "problem_description")] + public List ProblemDescriptions { get; set; } + + } + + public struct ProblemDescription + { + [YamlMember(Alias = "metadata", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "metadata")] + public Dictionary Metadata { get; set; } + + [YamlMember(Alias = "basis_set", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "basis_set")] + public BasisSet? BasisSet { get; set; } + + [YamlMember(Alias = "geometry", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "geometry")] + public Geometry? Geometry { get; set; } + + [YamlMember(Alias = "coulomb_repulsion", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "coulomb_repulsion")] + public SimpleQuantity CoulombRepulsion { get; set; } + + [YamlMember(Alias = "scf_energy", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "scf_energy")] + public SimpleQuantity? ScfEnergy { get; set; } + + [YamlMember(Alias = "scf_energy_offset", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "scf_energy_offset")] + public SimpleQuantity? ScfEnergyOffset { get; set; } + + [YamlMember(Alias = "fci_energy", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "fci_energy")] + public BoundedQuantity? FciEnergy { get; set; } + + [YamlMember(Alias = "n_orbitals", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "n_orbitals")] + public int NOrbitals { get; set; } + + [YamlMember(Alias = "n_electrons", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "n_electrons")] + public int NElectrons { get; set; } + + [YamlMember(Alias = "energy_offset", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "energy_offset")] + public SimpleQuantity EnergyOffset { get; set; } + + [YamlMember(Alias = "hamiltonian", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "hamiltonian")] + public HamiltonianData Hamiltonian { get; set; } + + [YamlMember(Alias = "initial_state_suggestions", ApplyNamingConventions = false)] + [JsonProperty(PropertyName = "initial_state_suggestions")] + public List? InitialStates { get; set; } + } + + public struct HamiltonianData + { + [YamlMember(Alias = "particle_hole_representation", ApplyNamingConventions = false)] + // TODO: Placeholder object for ParticleHoleRepresentation, which we do not + // yet support. + // NB: Array quantity no longer implicitly adds [], so the type declaration is different + // from in 0.1. + public ArrayQuantity? ParticleHoleRepresentation { get; set; } + + [YamlMember(Alias = "one_electron_integrals", ApplyNamingConventions = false)] + public ArrayQuantity<(long, long), double> OneElectronIntegrals { get; set; } + + [YamlMember(Alias = "two_electron_integrals", ApplyNamingConventions = false)] + public ArrayQuantityWithSymmetry<(long, long, long, long), double> TwoElectronIntegrals { get; set; } + + } + + public enum ArrayFormat + { + [EnumMember(Value = "sparse")] + Sparse + } + + public class ArrayQuantity : HasUnits + { + public struct Item + { + [YamlMember(Alias = "key", ApplyNamingConventions = false)] + public TIndex Key { get; set; } + + [YamlMember(Alias = "value", ApplyNamingConventions = false)] + public TValue Value { get; set; } + } + + // TODO: make this an enum. + public ArrayFormat Format { get; set; } + public List Values { get; set; } + public OrbitalIntegral.Convention? IndexConvention { get; set; } = null; + } + + public enum PermutationSymmetry + { + [EnumMember(Value = "eightfold")] + Eightfold, + [EnumMember(Value = "fourfold")] + Fourfold, + [EnumMember(Value = "trivial")] + Trivial + } + + public struct Symmetry + { + [YamlMember(Alias = "permutation")] + public PermutationSymmetry Permutation { get; set; } + } + + public class ArrayQuantityWithSymmetry : ArrayQuantity + { + [YamlMember(Alias = "symmetry")] + public Symmetry Symmetry { get; set; } + } + + /// + /// Builds Hamiltonian from Broombridge if data is available. + /// + internal static OrbitalIntegralHamiltonian ToOrbitalIntegralHamiltonian(ProblemDescription broombridge) + { + // Add the identity terms + var identityterm = broombridge.CoulombRepulsion.Value + broombridge.EnergyOffset.Value; + var hamiltonian = new OrbitalIntegralHamiltonian(); + var hamiltonianData = broombridge.Hamiltonian; + + // This will convert from Broombridge 1-indexing to 0-indexing. + hamiltonian.Add + (hamiltonianData.OneElectronIntegrals.Values + .Select(o => + new OrbitalIntegral( + o.Key.Select(k => (int)(k - 1)).ToArray(), + o.Value, + OrbitalIntegral.Convention.Mulliken + ) + .ToCanonicalForm(PermutationSymmetry.Eightfold.FromBroombridgeV0_3())) + .Distinct()); + + // This will convert from Broombridge 1-indexing to 0-indexing. + // This will convert to Dirac-indexing. + hamiltonian.Add + (hamiltonianData.TwoElectronIntegrals.Values + .Select(o => + new OrbitalIntegral( + o.Key.Select(k => (int)(k - 1)).ToArray(), + o.Value, + OrbitalIntegral.Convention.Mulliken + ) + .ToCanonicalForm(hamiltonianData.TwoElectronIntegrals.Symmetry.Permutation.FromBroombridgeV0_3())) + .Distinct()); + + hamiltonian.Add(new OrbitalIntegral(), identityterm); + return hamiltonian; + } + + } + #endregion + +} diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs index 7179c881410..55aeec7ca27 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs @@ -11,6 +11,8 @@ using YamlDotNet.Core; using YamlDotNet.Serialization; using YamlDotNet.Core.Events; +using System.Reflection; +using System.Runtime.Serialization; namespace Microsoft.Quantum.Chemistry.Broombridge { @@ -19,7 +21,35 @@ namespace Microsoft.Quantum.Chemistry.Broombridge /// public enum VersionNumber { - NotRecognized = -1, v0_1 = 0, v0_2 = 1 + NotRecognized = -1, v0_1 = 0, v0_2 = 1, v0_3 + } + + internal class YamlStringEnumConverter : IYamlTypeConverter + { + public bool Accepts(Type type) => type.IsEnum; + + public object ReadYaml(IParser parser, Type type) + { + var parsedEnum = parser.Consume(); + var serializableValues = type.GetMembers() + .Select(m => new KeyValuePair(m.GetCustomAttributes(true).Select(ema => ema.Value).FirstOrDefault(), m)) + .Where(pa => !string.IsNullOrEmpty(pa.Key)) + .ToDictionary(pa => pa.Key, pa => pa.Value); + + if (!serializableValues.ContainsKey(parsedEnum.Value)) + { + throw new YamlException(parsedEnum.Start, parsedEnum.End, $"Value '{parsedEnum.Value}' not found in enum '{type.Name}'"); + } + + return Enum.Parse(type, serializableValues[parsedEnum.Value].Name); + } + + public void WriteYaml(IEmitter emitter, object value, Type type) + { + var enumMember = type.GetMember(value.ToString()).FirstOrDefault(); + var yamlValue = enumMember?.GetCustomAttributes(true).Select(ema => ema.Value).FirstOrDefault() ?? value.ToString(); + emitter.Emit(new Scalar(yamlValue)); + } } public static class BroombridgeSerializer @@ -42,7 +72,7 @@ public static IEnumerable Deserialize(TextReader rea Metadata = problem.Metadata, NElectrons = problem.NElectrons, NOrbitals = problem.NOrbitals, - OrbitalIntegralHamiltonian = V0_2.ToOrbitalIntegralHamiltonian(problem), + OrbitalIntegralHamiltonian = V0_3.ToOrbitalIntegralHamiltonian(problem), ScfEnergy = problem.ScfEnergy?.FromBroombridgeV0_1(), ScfEnergyOffset = problem.ScfEnergyOffset?.FromBroombridgeV0_1() } @@ -51,8 +81,8 @@ public static IEnumerable Deserialize(TextReader rea public static void Serialize(TextWriter writer, IEnumerable problems) { - Serializers.SerializeBroombridgev0_2( - new Broombridge.V0_2.Data + Serializers.SerializeData( + new Broombridge.V0_3.Data { // TODO: fix additional properties by converting IEnumerable to // new problem collection class. See https://github.com/microsoft/QuantumLibraries/issues/287. @@ -69,7 +99,7 @@ public static void Serialize(TextWriter writer, IEnumerable problem.ToBroombridgeV0_2() + problem => problem.ToBroombridgeV0_3() ) .ToList() }, @@ -97,7 +127,10 @@ public static class Deserializers ["broombridge-0.1.schema"] = VersionNumber.v0_1, // TODO: URL of 0.2 schema. ["0.2"] = VersionNumber.v0_2, - ["broombridge-0.2.schema"] = VersionNumber.v0_2 + ["broombridge-0.2.schema"] = VersionNumber.v0_2, + // TODO: Update actual schema for 0.3. + ["0.3"] = VersionNumber.v0_3, + ["broombridge-0.3.schema"] = VersionNumber.v0_3 }; @@ -122,8 +155,8 @@ public static VersionNumber GetVersionNumber(TextReader reader) var deserializer = new DeserializerBuilder().Build(); var data = deserializer.Deserialize>(reader); var schema = data["$schema"] as string; - VersionNumber versionNumber = VersionNumber.NotRecognized; - if(schema != null) + var versionNumber = VersionNumber.NotRecognized; + if (schema != null) { foreach (var kv in VersionNumberDict) { @@ -161,10 +194,14 @@ versionNumber switch VersionNumber.v0_1 => DataStructures.Update( Deserialize(stringReader) ), - VersionNumber.v0_2 => Deserialize(stringReader), - _ => throw new System.InvalidOperationException( + VersionNumber.v0_2 => DataStructures.Update( + Deserialize(stringReader) + ), + VersionNumber.v0_3 => Deserialize(stringReader), + VersionNumber.NotRecognized => throw new System.InvalidOperationException( "Unrecognized Broombridge version number." - ) + ), + _ => throw new System.Exception($"Internal error occurred; version {versionNumber} is valid but was not deserialized.") } ); } @@ -189,6 +226,7 @@ public static Data DeserializeBroombridge(string filename) /// public static TData Deserialize(TextReader reader) => new DeserializerBuilder() + .WithTypeConverter(new YamlStringEnumConverter()) .Build() .Deserialize(reader); @@ -215,7 +253,7 @@ public static class Serializers /// /// Broombridge v0.2 data to be serialized. /// Name of the file to write serialized data to. - internal static void SerializeBroombridgev0_2(V0_2.Data data, string filename) + internal static void SerializeData(TData data, string filename) { using var writer = new StreamWriter(File.OpenWrite(filename)); var stringBuilder = new StringBuilder(); @@ -228,7 +266,7 @@ internal static void SerializeBroombridgev0_2(V0_2.Data data, string filename) /// /// Broombridge v0.2 data to be serialized. /// Text writer to write serialized Broombridge data to. - internal static void SerializeBroombridgev0_2(V0_2.Data data, TextWriter writer) + internal static void SerializeData(TData data, TextWriter writer) { var stringBuilder = new StringBuilder(); var serializer = diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeVersionUpdater.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeVersionUpdater.cs index 3abc2515e77..b2fd29e8f93 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeVersionUpdater.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeVersionUpdater.cs @@ -16,26 +16,52 @@ namespace Microsoft.Quantum.Chemistry.Broombridge internal static partial class DataStructures { - + public static V0_3.Data Update(V0_2.Data input) => + new V0_3.Data + { + Bibliography = input.Bibliography, + Format = input.Format, + Generator = input.Generator, + Schema = V0_3.SchemaUrl, + ProblemDescriptions = input + .ProblemDescriptions + .Select(problem => new V0_3.ProblemDescription + { + BasisSet = problem.BasisSet, + CoulombRepulsion = problem.CoulombRepulsion, + EnergyOffset = problem.EnergyOffset, + FciEnergy = problem.FciEnergy, + Geometry = problem.Geometry, + InitialStates = problem.InitialStates, + Metadata = problem.Metadata, + NElectrons = problem.NElectrons, + NOrbitals = problem.NOrbitals, + ScfEnergy = problem.ScfEnergy, + ScfEnergyOffset = problem.ScfEnergyOffset, + Hamiltonian = problem.Hamiltonian.ToBroombridgeV0_3() + }) + .ToList() + }; + /// /// Converts v0.1 Broombridge to v0.2. /// /// Source Broombridge in v0.1 format. /// Converted Broombridge in v0.2 format. - public static V0_2.Data Update(V0_1.Data input) + public static V0_3.Data Update(V0_1.Data input) { - var output = new V0_2.Data() + var output = new V0_3.Data() { Schema = input.Schema, Format = input.Format, Generator = input.Generator, Bibliography = input.Bibliography, - ProblemDescriptions = new List() + ProblemDescriptions = new List() }; foreach (var integralSet in input.IntegralSets) { - var problemDescription = new V0_2.ProblemDescription() + var problemDescription = new V0_3.ProblemDescription() { Metadata = integralSet.Metadata, BasisSet = integralSet.BasisSet, @@ -47,7 +73,7 @@ public static V0_2.Data Update(V0_1.Data input) NOrbitals = integralSet.NOrbitals, NElectrons = integralSet.NElectrons, EnergyOffset = integralSet.EnergyOffset, - Hamiltonian = integralSet.Hamiltonian, + Hamiltonian = integralSet.Hamiltonian.ToBroombridgeV0_3(), InitialStates = new List() }; diff --git a/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs b/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs index dd9aa2b062b..3c0e44bfc8c 100644 --- a/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs +++ b/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs @@ -1,6 +1,6 @@  -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. // This test ensures that any chemistry library syntax changes From f94dcb37c9675b202418a20b5cea2810be4fb2d9 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Fri, 25 Feb 2022 20:10:32 -0800 Subject: [PATCH 02/66] Added v0.3 support to qdk-chem convert. --- .../BroombridgeDataStructurev0.3.cs | 142 +++++++++++++++- .../Broombridge/BroombridgeSerializer.cs | 9 +- Chemistry/src/Jupyter/ChemistryEncodeMagic.cs | 2 +- Chemistry/src/Tools/ExportJW.cs | 155 ++++++++++++++++++ Chemistry/src/Tools/Program.cs | 3 +- 5 files changed, 298 insertions(+), 13 deletions(-) create mode 100644 Chemistry/src/Tools/ExportJW.cs diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs index 6b889b29495..41a5c08d8ad 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs @@ -21,6 +21,9 @@ using System.Runtime.Serialization; using static Microsoft.Quantum.Chemistry.OrbitalIntegrals.IndexConventionConversions; +using YamlDotNet.Core.Events; +using System.Reflection; +using System.Collections.Immutable; namespace Microsoft.Quantum.Chemistry.Broombridge { @@ -133,7 +136,7 @@ V0_3.Symmetry symmetry var idxs = ConvertIndices( term .Key - .ToCanonicalForm(symmetry.Permutation.FromBroombridgeV0_3()) + .ToCanonicalForm(symmetry.Permutation.Value.FromBroombridgeV0_3()) .OrbitalIndices, OrbitalIntegral.Convention.Dirac, OrbitalIntegral.Convention.Mulliken @@ -175,7 +178,7 @@ V0_3.Symmetry symmetry internal static V0_3.ArrayQuantity ToBroombridgeV0_3(this V0_1.ArrayQuantity array) => new V0_3.ArrayQuantity { - Format = Enum.TryParse(array.Format, out var format) + Format = Enum.TryParse(array.Format, true, out var format) ? format : throw new Exception($"Invalid array format {array.Format} when converting 0.1 array quantity to 0.3 array quantity."), IndexConvention = array.IndexConvention, @@ -310,7 +313,12 @@ public struct HamiltonianData // from in 0.1. public ArrayQuantity? ParticleHoleRepresentation { get; set; } - [YamlMember(Alias = "one_electron_integrals", ApplyNamingConventions = false)] + [YamlMember( + Alias = "one_electron_integrals", + ApplyNamingConventions = false, + // Don't allow subclasses here. + SerializeAs = typeof(ArrayQuantity<(long, long), double>) + )] public ArrayQuantity<(long, long), double> OneElectronIntegrals { get; set; } [YamlMember(Alias = "two_electron_integrals", ApplyNamingConventions = false)] @@ -318,6 +326,49 @@ public struct HamiltonianData } + // TODO: move out of v0.3. + // TODO: finish. + public struct StringEnum : IYamlConvertible + where T: struct, Enum + { + public T Value; + public StringEnum(T value) + { + Value = value; + } + private static ImmutableDictionary EnumValues; + + static StringEnum() + { + EnumValues = typeof(T).GetMembers() + .Select(m => new KeyValuePair( + m + .GetCustomAttributes(true) + .Select(ema => ema.Value) + .FirstOrDefault(), + m + )) + .Where(pa => !string.IsNullOrEmpty(pa.Key)) + .ToImmutableDictionary(pa => pa.Key, pa => Enum.Parse(pa.Value.Name)); + } + + public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer) + { + var field = (string)nestedObjectDeserializer(typeof(string)); + Value = EnumValues[field]; + } + + public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer) + { + var value = Value; + var name = EnumValues.Where(pair => pair.Value.Equals(value)).Single().Key; + nestedObjectSerializer(name); + } + + public static implicit operator T(StringEnum e) => e.Value; + public static implicit operator StringEnum(T e) => new StringEnum(e); + } + public enum ArrayFormat { [EnumMember(Value = "sparse")] @@ -326,18 +377,93 @@ public enum ArrayFormat public class ArrayQuantity : HasUnits { - public struct Item + public struct Item : IYamlConvertible { [YamlMember(Alias = "key", ApplyNamingConventions = false)] public TIndex Key { get; set; } [YamlMember(Alias = "value", ApplyNamingConventions = false)] public TValue Value { get; set; } + + public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer) + { + parser.Consume(); + var readKey = false; + var readValue = false; + while (!readKey || !readValue) + { + var name = nestedObjectDeserializer(typeof(string)); + switch (name) + { + case "key": + this.Key = ReadKey(parser, nestedObjectDeserializer); + readKey = true; + break; + + case "value": + this.Value = (TValue)nestedObjectDeserializer(typeof(TValue)); + readValue = true; + break; + }; + } + parser.Consume(); + } + + private TIndex ReadKey(IParser parser, ObjectDeserializer nestedObjectDeserializer) + { + if (typeof(TIndex).FullName.StartsWith("System.ValueTuple`")) + { + // TODO [perf]: Cache the create method. + var createMethod = typeof(ValueTuple).GetMethods( + BindingFlags.Static | BindingFlags.Public + ) + .Where(meth => meth.Name == "Create") + .Where(meth => meth.GetParameters().Length == typeof(TIndex).GenericTypeArguments.Length) + .Single(); + var args = new List(); + parser.Consume(); + foreach (var elementType in typeof(TIndex).GenericTypeArguments) + { + var element = nestedObjectDeserializer(elementType); + args.Add(element); + } + parser.Consume(); + return (TIndex)createMethod.MakeGenericMethod(typeof(TIndex).GenericTypeArguments).Invoke(null, args.ToArray()); + } + else return (TIndex)nestedObjectDeserializer(typeof(TIndex)); + } + + public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer) + { + emitter.Emit(new MappingStart(null, null, true, MappingStyle.Flow)); + nestedObjectSerializer("key"); + if (typeof(TIndex).FullName.StartsWith("System.ValueTuple`")) + { + emitter.Emit(new SequenceStart(null, null, true, SequenceStyle.Flow)); + foreach (var (_, idx) in typeof(TIndex).GenericTypeArguments.Select((_, idx) => (_, idx))) + { + var field = typeof(TIndex).GetField($"Item{idx + 1}"); + nestedObjectSerializer(field.GetValue(Key)); + } + emitter.Emit(new SequenceEnd()); + } + else + { + nestedObjectSerializer(Key); + } + nestedObjectSerializer("value"); + nestedObjectSerializer(Value); + emitter.Emit(new MappingEnd()); + } } - // TODO: make this an enum. - public ArrayFormat Format { get; set; } + [YamlMember(Alias = "format")] + public StringEnum Format { get; set; } + + [YamlMember(Alias = "values")] public List Values { get; set; } + + [YamlMember(Alias = "index_convention")] public OrbitalIntegral.Convention? IndexConvention { get; set; } = null; } @@ -354,7 +480,7 @@ public enum PermutationSymmetry public struct Symmetry { [YamlMember(Alias = "permutation")] - public PermutationSymmetry Permutation { get; set; } + public StringEnum Permutation { get; set; } } public class ArrayQuantityWithSymmetry : ArrayQuantity @@ -395,7 +521,7 @@ internal static OrbitalIntegralHamiltonian ToOrbitalIntegralHamiltonian(ProblemD o.Value, OrbitalIntegral.Convention.Mulliken ) - .ToCanonicalForm(hamiltonianData.TwoElectronIntegrals.Symmetry.Permutation.FromBroombridgeV0_3())) + .ToCanonicalForm(hamiltonianData.TwoElectronIntegrals.Symmetry.Permutation.Value.FromBroombridgeV0_3())) .Distinct()); hamiltonian.Add(new OrbitalIntegral(), identityterm); diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs index 55aeec7ca27..6ff6f4687c9 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeSerializer.cs @@ -26,7 +26,10 @@ public enum VersionNumber internal class YamlStringEnumConverter : IYamlTypeConverter { - public bool Accepts(Type type) => type.IsEnum; + public bool Accepts(Type type) + { + return type.IsEnum; + } public object ReadYaml(IParser parser, Type type) { @@ -89,14 +92,14 @@ public static void Serialize(TextWriter writer, IEnumerable problem.ToBroombridgeV0_3() diff --git a/Chemistry/src/Jupyter/ChemistryEncodeMagic.cs b/Chemistry/src/Jupyter/ChemistryEncodeMagic.cs index 55d15bf2297..126f1f3dbce 100644 --- a/Chemistry/src/Jupyter/ChemistryEncodeMagic.cs +++ b/Chemistry/src/Jupyter/ChemistryEncodeMagic.cs @@ -43,7 +43,7 @@ public Task Run(string input, IChannel channel) // We target a qubit quantum computer, which requires a Pauli representation of the fermion Hamiltonian. // A number of mappings from fermions to qubits are possible. Let us choose the Jordan-Wigner encoding. - PauliHamiltonian pauliHamiltonian = args.Hamiltonian.ToPauliHamiltonian(QubitEncoding.JordanWigner); + var pauliHamiltonian = args.Hamiltonian.ToPauliHamiltonian(QubitEncoding.JordanWigner); // We now convert this Hamiltonian and a selected state to a format that than be passed onto the QSharp component // of the library that implements quantum simulation algorithms. diff --git a/Chemistry/src/Tools/ExportJW.cs b/Chemistry/src/Tools/ExportJW.cs new file mode 100644 index 00000000000..ccc3267b4c1 --- /dev/null +++ b/Chemistry/src/Tools/ExportJW.cs @@ -0,0 +1,155 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +#nullable enable + +using System.Collections.Generic; +using System.Linq; +using System.CommandLine; +using System.IO; +using System; + +using Microsoft.Quantum.Chemistry.Broombridge; +using Microsoft.Quantum.Chemistry.OrbitalIntegrals; +using Microsoft.Quantum.Chemistry.Fermion; +using Microsoft.Quantum.Chemistry.QSharpFormat; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Chemistry.Tools +{ + + public static class ExportJW + { + public static Command CreateCommand() => + new Command("export-jw") + { + new Argument( + "path", + "Input data to be loaded, or - to load from stdin." + ), + new Option( + "--from", + "Format to use in loading problem description data." + ), + new Option( + "--out", + "Path to write output to. Data will be written to stdout by default." + ) + } + .WithDescription( + "Exports a JSON representation of the Jordan–Wigner transformation of " + + "the fermionic Hamiltonian for a particular electronic structure problem." + ) + .WithHandler( + (path, from, @out) => + { + using var reader = + path.Name == "-" + ? System.Console.In + : File.OpenText(path.FullName); + using var writer = + @out == null + ? System.Console.Out + : new StreamWriter(File.OpenWrite(@out.FullName)); + ExportJwData(reader, from, writer); + } + ); + + public static void ExportJwData( + TextReader reader, SerializationFormat from, + TextWriter writer, + IndexConvention indexConvention = IndexConvention.UpDown + ) + { + var data = Load(reader, from).ToList(); + if (data.Count != 1) + { + System.Console.Error.WriteLine($"Expected a single problem description, but got a list of {data.Count}."); + } + var problem = data.Single(); + + var fermionHamiltonian = problem + .OrbitalIntegralHamiltonian + .ToFermionHamiltonian(indexConvention); + var jwHamiltonian = fermionHamiltonian + .ToPauliHamiltonian(Paulis.QubitEncoding.JordanWigner) + .ToQSharpFormat(); + var wavefunction = ( + (problem.InitialStates?.Count ?? 0) == 0 + ? fermionHamiltonian.CreateHartreeFockState(problem.NElectrons) + : problem + .InitialStates + .First() + .Value + .ToIndexing(indexConvention) + ) + .ToQSharpFormat(); + + // var encoded = JsonSerializer.Serialize( + // QSharpFormat.Convert.ToQSharpFormat(jwHamiltonian, wavefunction), + // options + // ); + var qsData = QSharpFormat.Convert.ToQSharpFormat(jwHamiltonian, wavefunction); + var encoded = JsonSerializer.Serialize(Flatten(qsData)); + + writer.Write(encoded); + writer.Close(); + } + + // TODO: Move into common class. + internal static IEnumerable Load(TextReader reader, SerializationFormat from) => + (from switch + { + SerializationFormat.Broombridge => + BroombridgeSerializer.Deserialize(reader), + SerializationFormat.LiQuiD => + LiQuiDSerializer.Deserialize(reader), + SerializationFormat.FciDump => + FciDumpSerializer.Deserialize(reader), + _ => throw new ArgumentException($"Invalid format {from}.") + }) + .ToList(); + + internal static object[] Flatten(JordanWigner.JordanWignerEncodingData data) => + new object[] + { + data.Item1, + Flatten(data.Item2), + new object[] + { + data.Item3.Item1, + data.Item3.Item2.Select(s => Flatten(s)).ToArray() + }, + data.Item4 + }; + + internal static object[] Flatten(JordanWigner.JWOptimizedHTerms data) => + new object[] + { + data.Item1.Select(s => Flatten(s)).ToArray(), + data.Item2.Select(s => Flatten(s)).ToArray(), + data.Item3.Select(s => Flatten(s)).ToArray(), + data.Item4.Select(s => Flatten(s)).ToArray(), + }; + + internal static object[] Flatten(HTerm term) => + new object[] + { + term.Item1.ToArray(), + term.Item2.ToArray() + }; + + internal static object[] Flatten(JordanWigner.JordanWignerInputState data) => + new object[] + { + new object[] + { + data.Item1.Item1, + data.Item1.Item2 + }, + data.Item2.ToArray() + }; + } + +} diff --git a/Chemistry/src/Tools/Program.cs b/Chemistry/src/Tools/Program.cs index e71910b2248..ee0c3306704 100644 --- a/Chemistry/src/Tools/Program.cs +++ b/Chemistry/src/Tools/Program.cs @@ -23,7 +23,8 @@ public class Program new RootCommand { Convert.CreateCommand(), - Normalize.CreateCommand() + Normalize.CreateCommand(), + ExportJW.CreateCommand() } .WithDescription("Tools for working with quantum chemistry data."); From d3908f14a6cbbbb9711be9b3a57d613c1d3b16b8 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Mon, 28 Feb 2022 09:58:51 -0800 Subject: [PATCH 03/66] =?UTF-8?q?--from=20=E2=86=92=20--format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chemistry/src/Tools/ExportJW.cs | 2 +- Chemistry/src/Tools/Normalize.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Chemistry/src/Tools/ExportJW.cs b/Chemistry/src/Tools/ExportJW.cs index ccc3267b4c1..6456b119149 100644 --- a/Chemistry/src/Tools/ExportJW.cs +++ b/Chemistry/src/Tools/ExportJW.cs @@ -29,7 +29,7 @@ public static class ExportJW "Input data to be loaded, or - to load from stdin." ), new Option( - "--from", + "--format", "Format to use in loading problem description data." ), new Option( diff --git a/Chemistry/src/Tools/Normalize.cs b/Chemistry/src/Tools/Normalize.cs index 9ada49653e5..7c287082744 100644 --- a/Chemistry/src/Tools/Normalize.cs +++ b/Chemistry/src/Tools/Normalize.cs @@ -56,6 +56,6 @@ public static class Normalize Convert.ConvertProblemDescription(reader, format, writer, format); } ); - } + } } From ba071beb5bea3c50c68f127394730b7415dbf192 Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Thu, 3 Mar 2022 01:39:24 -0800 Subject: [PATCH 04/66] Fix formulas in PurifiedMixedState(WithData) (#534) * Fix formulas in PurifiedMixedState(WithData) This fixes #485. * Update NuGet version. Co-authored-by: Mathias Soeken --- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- .../tests/ChemistryTests/QSharpTests.csproj | 2 +- .../tests/SystemTests/SystemTests.csproj | 2 +- MachineLearning/src/MachineLearning.csproj | 2 +- .../tests/MachineLearningTests.csproj | 2 +- NOTICE.txt | 20 +++++++++---------- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 2 +- Standard/src/Preparation/QuantumROM.qs | 12 ++++++++--- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 2 +- Visualization/src/Visualization.csproj | 4 ++-- 12 files changed, 34 insertions(+), 28 deletions(-) diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index 4822fafd9e7..d4f0c7da347 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index 6d2636c9795..4d7d9bc011f 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index d4bfa3ccba9..5a12cf93568 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index adcb5683acd..10547bfa5fc 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index 45c3aa884e3..45343fbe972 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/NOTICE.txt b/NOTICE.txt index 26a8ab826b0..dfc2ff2482e 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -5293,7 +5293,7 @@ Copyright (c) Microsoft Corporation. --------------------------------------------------------- -Microsoft.Quantum.Compiler 0.22.191200-beta - MIT +Microsoft.Quantum.Compiler 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5313,7 +5313,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.CSharpGeneration 0.22.191200-beta - MIT +Microsoft.Quantum.CSharpGeneration 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5333,7 +5333,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.DocumentationGenerator 0.22.191200-beta - MIT +Microsoft.Quantum.DocumentationGenerator 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5353,7 +5353,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Core 0.22.191200-beta - MIT +Microsoft.Quantum.IQSharp.Core 0.23.195645-beta - MIT (c) by W3C @@ -5760,7 +5760,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Jupyter 0.22.191200-beta - MIT +Microsoft.Quantum.IQSharp.Jupyter 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5780,7 +5780,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Core 0.22.191200-beta - MIT +Microsoft.Quantum.QSharp.Core 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5800,7 +5800,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Foundation 0.22.191200-beta - MIT +Microsoft.Quantum.QSharp.Foundation 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5820,7 +5820,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Runtime.Core 0.22.191200-beta - MIT +Microsoft.Quantum.Runtime.Core 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5840,7 +5840,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Simulators 0.22.191200-beta - MIT +Microsoft.Quantum.Simulators 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. @@ -5860,7 +5860,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Targets.Interfaces 0.22.191200-beta - MIT +Microsoft.Quantum.Targets.Interfaces 0.23.195645-beta - MIT (c) 2008 VeriSign, Inc. diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index e7930e6df17..b13933eebac 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index c62cc6449c5..a533ac818ad 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Standard/src/Preparation/QuantumROM.qs b/Standard/src/Preparation/QuantumROM.qs index 8b91dab73aa..562fad35f72 100644 --- a/Standard/src/Preparation/QuantumROM.qs +++ b/Standard/src/Preparation/QuantumROM.qs @@ -32,7 +32,7 @@ namespace Microsoft.Quantum.Preparation { /// of the mixed state /// $$ /// \begin{align} - /// \rho = \sum_{j = 0}^{N-1} \frac{|alpha_j|}{\sum_k |\alpha_k|} \ket{j}\bra{j}, + /// \rho = \sum_{j = 0}^{N-1} \frac{|\alpha_j|}{\sum_k |\alpha_k|} \ket{j}\bra{j}, /// \end{align} /// $$ /// where each $p_j$ is an approximation to the given coefficient $\alpha_j$ @@ -73,7 +73,7 @@ namespace Microsoft.Quantum.Preparation { /// /// # Example /// The following code snippet prepares an purification of the $3$-qubit state - /// $\rho=\sum_{j=0}^{4}\frac{|alpha_j|}{\sum_k |\alpha_k|}\ket{j}\bra{j}$, where + /// $\rho=\sum_{j=0}^{4}\frac{|\alpha_j|}{\sum_k |\alpha_k|}\ket{j}\bra{j}$, where /// $\vec\alpha=(1.0, 2.0, 3.0, 4.0, 5.0)$, and the target error is /// $10^{-3}$: /// ```qsharp @@ -127,24 +127,30 @@ namespace Microsoft.Quantum.Preparation { /// bitstring $\vec{x}_j$ associated with each coefficient, this /// function returns an operation that uses the Quantum ROM technique to /// prepare an approximation + /// /// $$ /// \begin{align} /// \tilde\rho = \sum_{j = 0}^{N - 1} p_j \ket{j}\bra{j} \otimes \ket{\vec{x}_j}\bra{\vec{x}_j} /// \end{align} /// $$ + /// /// of the mixed state + /// /// $$ /// \begin{align} - /// \rho = \sum_{j = 0}^{N-1}\ frac{|alpha_j|}{\sum_k |\alpha_k|} \ket{j}\bra{j} \otimes \ket{\vec{x}_j}\bra{\vec{x}_j}, + /// \rho = \sum_{j = 0}^{N-1} \frac{|\alpha_j|}{\sum_k |\alpha_k|} \ket{j}\bra{j} \otimes \ket{\vec{x}_j}\bra{\vec{x}_j}, /// \end{align} /// $$ + /// /// where each $p_j$ is an approximation to the given coefficient $\alpha_j$ /// such that + /// /// $$ /// \begin{align} /// \left| p_j - \frac{ |\alpha_j| }{ \sum_k |\alpha_k| } \right| \le \frac{\epsilon}{N} /// \end{align} /// $$ + /// /// for each $j$. /// /// When passed an index register and a register of garbage qubits, diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index aacaf4ebbeb..67ce64edc74 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index 9d47d421b39..7adfe497eb2 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index b386823d3a7..b713d9984fd 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + From 45f7fa969e2cddaa31494a6d800dc0c6e3f58dfe Mon Sep 17 00:00:00 2001 From: Robin Kuzmin <9372582+kuzminrobin@users.noreply.github.com> Date: Tue, 8 Mar 2022 18:04:40 -0800 Subject: [PATCH 05/66] Fixed the SDK version. (#536) --- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- .../tests/ChemistryTests/QSharpTests.csproj | 2 +- .../tests/SystemTests/SystemTests.csproj | 2 +- MachineLearning/src/MachineLearning.csproj | 2 +- .../tests/MachineLearningTests.csproj | 2 +- NOTICE.txt | 20 +++++++++---------- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 2 +- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 2 +- Visualization/src/Visualization.csproj | 4 ++-- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index d4f0c7da347..6d351fcd312 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index 4d7d9bc011f..5e0742ec959 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index 5a12cf93568..061dfc07de3 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index 10547bfa5fc..514a049ccc2 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index 45343fbe972..27c351b5b52 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/NOTICE.txt b/NOTICE.txt index dfc2ff2482e..c1f965acb49 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -5293,7 +5293,7 @@ Copyright (c) Microsoft Corporation. --------------------------------------------------------- -Microsoft.Quantum.Compiler 0.23.195645-beta - MIT +Microsoft.Quantum.Compiler 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5313,7 +5313,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.CSharpGeneration 0.23.195645-beta - MIT +Microsoft.Quantum.CSharpGeneration 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5333,7 +5333,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.DocumentationGenerator 0.23.195645-beta - MIT +Microsoft.Quantum.DocumentationGenerator 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5353,7 +5353,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Core 0.23.195645-beta - MIT +Microsoft.Quantum.IQSharp.Core 0.23.195983 - MIT (c) by W3C @@ -5760,7 +5760,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Jupyter 0.23.195645-beta - MIT +Microsoft.Quantum.IQSharp.Jupyter 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5780,7 +5780,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Core 0.23.195645-beta - MIT +Microsoft.Quantum.QSharp.Core 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5800,7 +5800,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Foundation 0.23.195645-beta - MIT +Microsoft.Quantum.QSharp.Foundation 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5820,7 +5820,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Runtime.Core 0.23.195645-beta - MIT +Microsoft.Quantum.Runtime.Core 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5840,7 +5840,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Simulators 0.23.195645-beta - MIT +Microsoft.Quantum.Simulators 0.23.195983 - MIT (c) 2008 VeriSign, Inc. @@ -5860,7 +5860,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Targets.Interfaces 0.23.195645-beta - MIT +Microsoft.Quantum.Targets.Interfaces 0.23.195983 - MIT (c) 2008 VeriSign, Inc. diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index b13933eebac..57b89fcef7c 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index a533ac818ad..029de58862b 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index 67ce64edc74..3fee8d27a50 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index 7adfe497eb2..21c0f4e1376 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index b713d9984fd..d31a9b1b87c 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + From 845decf5075be4e96cd9e1e22901a39d387b69ee Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Wed, 9 Mar 2022 10:31:47 +0100 Subject: [PATCH 06/66] Fix #511 for fixed point amplitude amplification (#525) * Optimization and formatting. * Use array API. * Fix errors and add comments with refs to paper. * Add corner case in conversion of rotation phases. * Add test case. --- .../src/AmplitudeAmplification/Convert.qs | 5 ++++ .../StandardAlgorithms.qs | 25 +++++++++++++++---- Standard/tests/AmplitudeAmplificationTests.qs | 20 ++++++++++++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Standard/src/AmplitudeAmplification/Convert.qs b/Standard/src/AmplitudeAmplification/Convert.qs index 70c5ace858c..f86be6d0585 100644 --- a/Standard/src/AmplitudeAmplification/Convert.qs +++ b/Standard/src/AmplitudeAmplification/Convert.qs @@ -31,6 +31,11 @@ namespace Microsoft.Quantum.AmplitudeAmplification { mutable phasesTarget = [0.0, size = nPhasesRef]; mutable phasesStart = [0.0, size = nPhasesRef]; + + if nPhasesRot == 1 { + return ReflectionPhases(phasesStart, phasesTarget); + } + set phasesTarget w/= 0 <- ((rotPhases!)[0] - (rotPhases!)[1]) - PI(); set phasesStart w/= 0 <- -(rotPhases!)[0] + 0.5 * PI(); diff --git a/Standard/src/AmplitudeAmplification/StandardAlgorithms.qs b/Standard/src/AmplitudeAmplification/StandardAlgorithms.qs index 8b92e3a013c..b2ea3633e6d 100644 --- a/Standard/src/AmplitudeAmplification/StandardAlgorithms.qs +++ b/Standard/src/AmplitudeAmplification/StandardAlgorithms.qs @@ -2,8 +2,9 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.AmplitudeAmplification { - open Microsoft.Quantum.Convert; open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Math; /// # Summary @@ -52,13 +53,27 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// for phases in the `RotationPhases` format. function FixedPointReflectionPhases(nQueries : Int, successMin : Double) : ReflectionPhases { - let twoPi = 2.0 * PI(); + // In this implementation `nQueries` corresponds to $L$ in + // arXiv:1409.3305. + Fact(nQueries % 2 == 1, "nQueries must be odd"); + + // Initializes L rotation phases, this also initializes the first + // rotation phase with 0.0. mutable phasesRot = [0.0, size = 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); + // The success probability `successMin` is $1 - \delta^2$ in + // arXiv:1409.3305. Variable `beta` corresponds to $\gamma^{-1}$ in + // arXiv:1409.3305, right below Eq. (11) + let beta = Cosh((1.0 / nQueriesDouble) * ArcCosh(Sqrt(1.0 / (1.0 - successMin)))); + + // `alpha` is $\sqrt(1 - \gamma^2)$ in Eq. (11) in arXiv:1409.3305, + // therefore it is $\sqrt(1 - (1 / \beta^2))$ + let alpha = Sqrt(1.0 - 1.0 / (beta * beta)); + + // Iterative computation of rotation phases is described in Eq. (30) in + // arXiv:1603.03996. In there, we can set $j = 1$. + let twoPi = 2.0 * PI(); for idxPhases in 1 .. nQueries - 1 { set phasesRot w/= idxPhases <- phasesRot[idxPhases - 1] + diff --git a/Standard/tests/AmplitudeAmplificationTests.qs b/Standard/tests/AmplitudeAmplificationTests.qs index 16d6dcdc4e6..07f6ce32f6d 100644 --- a/Standard/tests/AmplitudeAmplificationTests.qs +++ b/Standard/tests/AmplitudeAmplificationTests.qs @@ -2,13 +2,15 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Tests { - open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.AmplitudeAmplification; + open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.AmplitudeAmplification; - open Microsoft.Quantum.Oracles; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Logical; open Microsoft.Quantum.Math; + open Microsoft.Quantum.Oracles; ///Here we consider the smallest example of amplitude amplification ///Suppose we have a single-qubit oracle that prepares the state @@ -94,6 +96,18 @@ namespace Microsoft.Quantum.Tests { } } + @Test("QuantumSimulator") + operation TestRotationPhasesAsReflectionPhases() : Unit { + let rotationPhases = RotationPhases([0.1, 0.2, 0.3, 0.4, 0.5]); + let reflectionPhases = RotationPhasesAsReflectionPhases(rotationPhases); + + EqualityFactI(Length(reflectionPhases::AboutStart), 3, "Unexpected length of reflection phases"); + EqualityFactI(Length(reflectionPhases::AboutTarget), 3, "Unexpected length of reflection phases"); + + Fact(All(NearlyEqualD, Zipped(reflectionPhases::AboutStart, [1.4707963267948965,3.041592653589793,3.041592653589793])), "Unexpected reflection phases"); + Fact(All(NearlyEqualD, Zipped(reflectionPhases::AboutTarget, [-3.241592653589793,-3.241592653589793,-1.0707963267948966])), "Unexpected reflection phases"); + } + } From ab0f4919413ddfaf844a88721d016ea4e8ce2bc2 Mon Sep 17 00:00:00 2001 From: Hyunjin Song Date: Wed, 9 Mar 2022 22:09:58 +0900 Subject: [PATCH 07/66] Fix overestimation in MachineLearning.NQubitsRequired (#282) Co-authored-by: Chris Granade Co-authored-by: Mathias Soeken --- MachineLearning/src/Structure.qs | 13 +++++-------- MachineLearning/tests/StructureTests.qs | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/MachineLearning/src/Structure.qs b/MachineLearning/src/Structure.qs index b76f1e00663..b6bf2503339 100644 --- a/MachineLearning/src/Structure.qs +++ b/MachineLearning/src/Structure.qs @@ -20,17 +20,14 @@ namespace Microsoft.Quantum.MachineLearning { /// may be applied. function NQubitsRequired(model : SequentialModel) : Int { - mutable nQubitsRequired = 0; + mutable lastQubitIndex = -1; // Need to return 0 if there are no gates for gate in model::Structure { - set nQubitsRequired = 1 + Fold( - MaxI, 0, - gate::ControlIndices + [ - gate::TargetIndex, - nQubitsRequired - ] + set lastQubitIndex = Fold( + MaxI, lastQubitIndex, + gate::ControlIndices + [gate::TargetIndex] ); } - return nQubitsRequired; + return lastQubitIndex + 1; } /// # Summary diff --git a/MachineLearning/tests/StructureTests.qs b/MachineLearning/tests/StructureTests.qs index 94802e9f237..7187e8da9db 100644 --- a/MachineLearning/tests/StructureTests.qs +++ b/MachineLearning/tests/StructureTests.qs @@ -12,7 +12,8 @@ namespace Microsoft.Quantum.MachineLearning.Tests { function NQubitsRequiredFact() : Unit { let model = Default() w/ Structure <- [ - ML.ControlledRotation((3, [7, 9]), PauliX, 0) + ML.ControlledRotation((3, [7, 9]), PauliX, 0), + ML.ControlledRotation((8, new Int[0]), PauliY, 1) ]; let actual = ML.NQubitsRequired(model); EqualityFactI(actual, 10, "Wrong output from NQubitsRequired."); From 947a5522e05fc4ba18a995361baa6c4e6bffb126 Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Fri, 11 Mar 2022 00:26:47 -0800 Subject: [PATCH 08/66] Chunks: Add check that chunk size is positive (#540) Fixes #538. --- Standard/src/Arrays/Arrays.qs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Standard/src/Arrays/Arrays.qs b/Standard/src/Arrays/Arrays.qs index 23d4d4e5668..7506b9efcbd 100644 --- a/Standard/src/Arrays/Arrays.qs +++ b/Standard/src/Arrays/Arrays.qs @@ -283,7 +283,7 @@ namespace Microsoft.Quantum.Arrays { /// /// # Input /// ## nElements - /// The length of each chunk. + /// The length of each chunk. Must be positive. /// ## arr /// The array to be split. /// @@ -294,6 +294,7 @@ namespace Microsoft.Quantum.Arrays { /// Note that the last element of the output may be shorter /// than `nElements` if `Length(arr)` is not divisible by `nElements`. function Chunks<'T>(nElements : Int, arr : 'T[]) : 'T[][] { + Fact(nElements > 0, "nElements must be positive"); mutable output = []; mutable remaining = arr; while (not IsEmpty(remaining)) { From 76b7276505d9d44c0b1a7c0f4b9aa9f472e7adb7 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Mon, 14 Mar 2022 19:28:27 +0100 Subject: [PATCH 09/66] Fixes #444 (#537) * Fixes #444. * Add other test. * Update Standard/tests/QcvvTests.qs Co-authored-by: Mariia Mykhailova Co-authored-by: Mariia Mykhailova --- Standard/tests/QcvvTests.cs | 20 +++++++++++++------ Standard/tests/QcvvTests.qs | 39 +++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Standard/tests/QcvvTests.cs b/Standard/tests/QcvvTests.cs index 190ff00fd8f..fea185ab484 100644 --- a/Standard/tests/QcvvTests.cs +++ b/Standard/tests/QcvvTests.cs @@ -2,15 +2,9 @@ // Licensed under the MIT License. using System; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.Quantum.Intrinsic; -using Microsoft.Quantum.Simulation; using Microsoft.Quantum.Simulation.Common; -using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators; -using Microsoft.Quantum.Standard.Emulation; using Xunit; using Assert = Xunit.Assert; @@ -36,5 +30,19 @@ void TestOne(SimulatorBase sim, int expected) TestOne(new QuantumSimulator(), 1); TestOne(new ToffoliSimulator(), 2000); } + + [Fact] + public void TestEstimateFrequencyBinomial() + { + using var sim = new QuantumSimulator(randomNumberGeneratorSeed: 655321); + TestEstimateFrequencyBinomialInner.Run(sim).Wait(); + } + + [Fact] + public void TestRobustPhaseEstimation() + { + using var sim = new QuantumSimulator(randomNumberGeneratorSeed: 655321); + TestRobustPhaseEstimationInner.Run(sim).Wait(); + } } } diff --git a/Standard/tests/QcvvTests.qs b/Standard/tests/QcvvTests.qs index 1655d411684..3c00e88a6f2 100644 --- a/Standard/tests/QcvvTests.qs +++ b/Standard/tests/QcvvTests.qs @@ -2,16 +2,16 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Tests { - open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Canon; - open Microsoft.Quantum.Convert; - open Microsoft.Quantum.Oracles; open Microsoft.Quantum.Characterization; - open Microsoft.Quantum.Preparation; + open Microsoft.Quantum.Convert; open Microsoft.Quantum.Diagnostics; - open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Math; open Microsoft.Quantum.Measurement as Meas; + open Microsoft.Quantum.Oracles; + open Microsoft.Quantum.Preparation; @Test("QuantumSimulator") operation TestChoiState() : Unit { @@ -20,8 +20,8 @@ namespace Microsoft.Quantum.Tests { // As usual, the same confusion about {+1, -1} and {0, 1} // labeling bites us here. - AssertMeasurement([PauliX, PauliX], register, Zero, $"XX"); - AssertMeasurement([PauliZ, PauliZ], register, Zero, $"ZZ"); + AssertMeasurement([PauliX, PauliX], register, Zero, "XX"); + AssertMeasurement([PauliZ, PauliZ], register, Zero, "ZZ"); ResetAll(register); } @@ -38,7 +38,7 @@ namespace Microsoft.Quantum.Tests { EqualityWithinToleranceFact(freq2, 0.5, 0.1); } - operation PrepareBiasedCoin(successProbability : Double, qubit : Qubit) : Unit is Adj { + internal operation PrepareBiasedCoin(successProbability : Double, qubit : Qubit) : Unit is Adj { let rotationAngle = 2.0 * ArcCos(Sqrt(successProbability)); Ry(rotationAngle, qubit); } @@ -57,8 +57,7 @@ namespace Microsoft.Quantum.Tests { EqualityWithinToleranceFact(expectation, actualFreq, tolerance); } - @Test("QuantumSimulator") - operation TestEstimateFrequencyBinomial() : Unit { + operation TestEstimateFrequencyBinomialInner() : Unit { // If this is larger, tests fail less often, but more false negatives // slip through. let nStdDevs = 3.0; @@ -90,7 +89,7 @@ namespace Microsoft.Quantum.Tests { Exp([PauliZ], phase * IntAsDouble(power), qubits); } - operation RobustPhaseEstimationDemoImpl (phaseSet : Double, bitsPrecision : Int) : Double { + internal operation RobustPhaseEstimationDemoImpl (phaseSet : Double, bitsPrecision : Int) : Double { let op = DiscreteOracle(RobustPhaseEstimationTestOp(phaseSet, _, _)); use q = Qubit(); @@ -99,9 +98,7 @@ namespace Microsoft.Quantum.Tests { return phaseEst; } - // Probabilistic test. Might fail occasionally - @Test("QuantumSimulator") - operation TestRobustPhaseEstimation() : Unit { + operation TestRobustPhaseEstimationInner() : Unit { let bitsPrecision = 10; for idxTest in 0 .. 9 { @@ -125,13 +122,13 @@ namespace Microsoft.Quantum.Tests { @Test("QuantumSimulator") operation TestSingleQubitProcessTomographyMeasurement() : Unit { - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliI, PauliI, H), Zero, $"Failed at ⟪I | H | I⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliI, H), Zero, $"Failed at ⟪I | H | X⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliI, H), Zero, $"Failed at ⟪I | H | Y⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliZ, PauliI, H), Zero, $"Failed at ⟪I | H | Z⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, $"Failed at ⟪Z | H | X⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliY, H), One, $"Failed at -⟪Y | H | Y⟫."); - EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, $"Failed at ⟪Z | H | X⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliI, PauliI, H), Zero, "Failed at ⟪I | H | I⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliI, H), Zero, "Failed at ⟪I | H | X⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliI, H), Zero, "Failed at ⟪I | H | Y⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliZ, PauliI, H), Zero, "Failed at ⟪I | H | Z⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, "Failed at ⟪Z | H | X⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliY, PauliY, H), One, "Failed at -⟪Y | H | Y⟫."); + EqualityFactR(SingleQubitProcessTomographyMeasurement(PauliX, PauliZ, H), Zero, "Failed at ⟪Z | H | X⟫."); } } From c360e778f5527fe948097f30ecee3097f7a51df8 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Mon, 14 Mar 2022 18:18:03 -0700 Subject: [PATCH 10/66] Add --flatten option. --- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- Chemistry/src/Tools/ExportJW.cs | 18 +++++++++++++----- Standard/src/Standard.csproj | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index 4822fafd9e7..6d351fcd312 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/src/Tools/ExportJW.cs b/Chemistry/src/Tools/ExportJW.cs index 6456b119149..040ea81500c 100644 --- a/Chemistry/src/Tools/ExportJW.cs +++ b/Chemistry/src/Tools/ExportJW.cs @@ -35,14 +35,19 @@ public static class ExportJW new Option( "--out", "Path to write output to. Data will be written to stdout by default." + ), + new Option( + "--flatten", + "If true, flattens resulting JSON (often easier for use in " + + "native code)." ) } .WithDescription( "Exports a JSON representation of the Jordan–Wigner transformation of " + "the fermionic Hamiltonian for a particular electronic structure problem." ) - .WithHandler( - (path, from, @out) => + .WithHandler( + (path, from, @out, flatten) => { using var reader = path.Name == "-" @@ -52,14 +57,15 @@ public static class ExportJW @out == null ? System.Console.Out : new StreamWriter(File.OpenWrite(@out.FullName)); - ExportJwData(reader, from, writer); + ExportJwData(reader, from, writer, flatten: flatten); } ); public static void ExportJwData( TextReader reader, SerializationFormat from, TextWriter writer, - IndexConvention indexConvention = IndexConvention.UpDown + IndexConvention indexConvention = IndexConvention.UpDown, + bool flatten = true ) { var data = Load(reader, from).ToList(); @@ -91,7 +97,9 @@ public static class ExportJW // options // ); var qsData = QSharpFormat.Convert.ToQSharpFormat(jwHamiltonian, wavefunction); - var encoded = JsonSerializer.Serialize(Flatten(qsData)); + var encoded = flatten + ? JsonSerializer.Serialize(Flatten(qsData)) + : JsonSerializer.Serialize(qsData); writer.Write(encoded); writer.Close(); diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index aacaf4ebbeb..3fee8d27a50 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + From ce280afaac20abe7617d62d4030f57a8519bc240 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Thu, 17 Mar 2022 15:25:05 -0700 Subject: [PATCH 11/66] Adopt .NET6 + VS2022 in Quantum Development Kit (#542) With this change, we're migrating the main release train of the QDK to the most recent Long Time Support version of the .NET framework. For details about this change, refer to the original issue microsoft/qsharp-compiler#1224. As part of this change, we're: - Re-targeting all .NetCoreApp3.1 binaries to .NET6.0 - Updating Docker images, samples and templates. - Libraries using .NetStandard2.1 are not affected by this change. - The minimum supported .NET version in the QDK will also be updated from 3.1 to 6.0 - The Visual Studio extension will now target Visual Studio 2022. --- Build/manifest.ps1 | 2 +- Build/props/tests.props | 2 +- Chemistry/src/DataModel/DataModel.csproj | 2 +- Chemistry/src/Jupyter/Jupyter.csproj | 2 +- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- Chemistry/src/Tools/Tools.csproj | 2 +- Chemistry/tests/ChemistryTests/QSharpTests.csproj | 4 ++-- Chemistry/tests/DataModelTests/DataModelTests.csproj | 4 ++-- Chemistry/tests/JupyterTests/JupyterTests.csproj | 2 +- Chemistry/tests/SamplesTests/SamplesTests.csproj | 4 ++-- Chemistry/tests/SystemTests/SystemTests.csproj | 4 ++-- MachineLearning/src/MachineLearning.csproj | 2 +- MachineLearning/tests/MachineLearningTests.csproj | 4 ++-- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 4 ++-- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 4 ++-- Visualization/src/Visualization.csproj | 4 ++-- 18 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Build/manifest.ps1 b/Build/manifest.ps1 index 9765de673a3..f5093f0cff9 100644 --- a/Build/manifest.ps1 +++ b/Build/manifest.ps1 @@ -38,7 +38,7 @@ $artifacts = @{ ".\Chemistry\src\DataModel\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Chemistry.DataModel.dll", ".\Chemistry\src\Jupyter\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Chemistry.Jupyter.dll", ".\Chemistry\src\Runtime\bin\$Env:BUILD_CONFIGURATION\netstandard2.1\Microsoft.Quantum.Chemistry.Runtime.dll", - ".\Chemistry\src\Tools\bin\$Env:BUILD_CONFIGURATION\netcoreapp3.1\qdk-chem.dll" + ".\Chemistry\src\Tools\bin\$Env:BUILD_CONFIGURATION\net6.0\qdk-chem.dll" ) | ForEach-Object { Join-Path $PSScriptRoot (Join-Path ".." $_) }; } diff --git a/Build/props/tests.props b/Build/props/tests.props index 8f87d98579e..f8bb40d23f7 100644 --- a/Build/props/tests.props +++ b/Build/props/tests.props @@ -7,7 +7,7 @@ - + diff --git a/Chemistry/src/DataModel/DataModel.csproj b/Chemistry/src/DataModel/DataModel.csproj index 4703d3c27ae..0287a45010d 100644 --- a/Chemistry/src/DataModel/DataModel.csproj +++ b/Chemistry/src/DataModel/DataModel.csproj @@ -34,7 +34,7 @@ - + diff --git a/Chemistry/src/Jupyter/Jupyter.csproj b/Chemistry/src/Jupyter/Jupyter.csproj index 140e06eed7a..659de7258f2 100644 --- a/Chemistry/src/Jupyter/Jupyter.csproj +++ b/Chemistry/src/Jupyter/Jupyter.csproj @@ -26,7 +26,7 @@ - + diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index 6d351fcd312..e276d844aa9 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/src/Tools/Tools.csproj b/Chemistry/src/Tools/Tools.csproj index e65f8d76c4c..d78d510888c 100644 --- a/Chemistry/src/Tools/Tools.csproj +++ b/Chemistry/src/Tools/Tools.csproj @@ -3,7 +3,7 @@ Exe x64 - netcoreapp3.1 + net6.0 Microsoft.Quantum.Chemistry.Tools qdk-chem enable diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index 5e0742ec959..336ef833a3d 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,9 +1,9 @@ - + - netcoreapp3.1 + net6.0 false diff --git a/Chemistry/tests/DataModelTests/DataModelTests.csproj b/Chemistry/tests/DataModelTests/DataModelTests.csproj index dc2619f9852..0853e952b36 100644 --- a/Chemistry/tests/DataModelTests/DataModelTests.csproj +++ b/Chemistry/tests/DataModelTests/DataModelTests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 x64 false Microsoft.Quantum.Chemistry.Tests.CSharp @@ -21,7 +21,7 @@ - + all diff --git a/Chemistry/tests/JupyterTests/JupyterTests.csproj b/Chemistry/tests/JupyterTests/JupyterTests.csproj index 44f4635616e..b738ecce54b 100644 --- a/Chemistry/tests/JupyterTests/JupyterTests.csproj +++ b/Chemistry/tests/JupyterTests/JupyterTests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 x64 false diff --git a/Chemistry/tests/SamplesTests/SamplesTests.csproj b/Chemistry/tests/SamplesTests/SamplesTests.csproj index 2e664ada69a..b6183aa6c44 100644 --- a/Chemistry/tests/SamplesTests/SamplesTests.csproj +++ b/Chemistry/tests/SamplesTests/SamplesTests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 x64 false @@ -14,7 +14,7 @@ - + all diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index 061dfc07de3..1dd0a325ef0 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,9 +1,9 @@ - + - netcoreapp3.1 + net6.0 false diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index 514a049ccc2..5cb5403a883 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index 27c351b5b52..e5c02c4b3a7 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,9 +1,9 @@ - + - netcoreapp3.1 + net6.0 Microsoft.Quantum.Standard.Tests false diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index 57b89fcef7c..b1398e6513c 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index 029de58862b..1638055db81 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,9 +1,9 @@ - + - netcoreapp3.1 + net6.0 false diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index 3fee8d27a50..f952f0f8a0a 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index 21c0f4e1376..3860da2d1f5 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,9 +1,9 @@ - + - netcoreapp3.1 + net6.0 Microsoft.Quantum.Standard.Tests false diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index d31a9b1b87c..893fa6284de 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + From dd2c4caae7b31d1b2ed8f9bb01c44b161b85cf47 Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Mon, 21 Mar 2022 15:07:04 -0700 Subject: [PATCH 12/66] Update CI build settings to use .NET6 (#543) --- Build/steps.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/steps.yml b/Build/steps.yml index 4e6aebbfbe2..219d5d5194c 100644 --- a/Build/steps.yml +++ b/Build/steps.yml @@ -1,10 +1,10 @@ steps: - task: UseDotNet@2 - displayName: 'Use .NET Core SDK 3.1.300' + displayName: 'Use .NET Core SDK 6.0.x' inputs: packageType: sdk - version: '3.1.300' + version: '6.0.x' - task: UsePythonVersion@0 From fbbc60013200f9c433bdea4d320c607f9f37d76d Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Tue, 22 Mar 2022 07:46:35 +0100 Subject: [PATCH 13/66] Fixes #367 (#541) * Fixes #367. * Apply suggestions from code review Co-authored-by: Mariia Mykhailova * Addressing Mariia's comments. Co-authored-by: Mariia Mykhailova --- Standard/src/Diagnostics/Allows.qs | 34 +++++++++++++----- .../Emulation/AllowOperationCalls.cs | 15 +++++++- Standard/tests/Diagnostics/AllowTests.qs | 35 +++++++++++++++++++ 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/Standard/src/Diagnostics/Allows.qs b/Standard/src/Diagnostics/Allows.qs index 1b5bccf8f11..766aff73457 100644 --- a/Standard/src/Diagnostics/Allows.qs +++ b/Standard/src/Diagnostics/Allows.qs @@ -7,6 +7,11 @@ namespace Microsoft.Quantum.Diagnostics { /// Between a call to this operation and its adjoint, asserts that /// a given operation is called at most a certain number of times. /// + /// Operation calls are considered, if they contain the the specified + /// variant. For example, if `op` is `X`, `Adjoint X` or `Controlled X` + /// are also counted, but if `op` is `Controlled X`, only `Controlled X` + /// or `Controlled Adjoint X` are counted. + /// /// # Input /// ## nTimes /// The maximum number of times that `op` may be called. @@ -19,14 +24,27 @@ namespace Microsoft.Quantum.Diagnostics { /// The following snippet will fail when executed on machines which /// support this diagnostic: /// ```qsharp - /// using (register = Qubit[4]) { - /// within { - /// AllowAtMostNCallsCA(3, H, "Too many calls to H."); - /// } apply { - /// // Fails since this calls H four times, rather than the - /// // allowed maximum of three. - /// ApplyToEach(H, register); - /// } + /// within { + /// AllowAtMostNCallsCA(3, H, "Too many calls to H."); + /// } apply { + /// use register = Qubit[4]; + /// // Fails since this calls H four times, rather than the + /// // allowed maximum of three. + /// ApplyToEach(H, register); + /// } + /// ``` + /// + /// Another example illustrates how restricted calls are handled. + /// ```qsharp + /// within { + /// // Both tests will pass in this case + /// AllowAtMostNCallsCA(1, Controlled H, "Too many calls to Controlled H."); + /// AllowAtMostNCallsCA(2, H, "Too many calls to H or Controlled H."); + /// } apply { + /// use (a, b) = (Qubit(), Qubit()); + /// H(a); + /// Controlled H([a], b); + /// ResetAll([a, b]); /// } /// ``` /// diff --git a/Standard/src/Diagnostics/Emulation/AllowOperationCalls.cs b/Standard/src/Diagnostics/Emulation/AllowOperationCalls.cs index e8907d71bb6..5d2a784e983 100644 --- a/Standard/src/Diagnostics/Emulation/AllowOperationCalls.cs +++ b/Standard/src/Diagnostics/Emulation/AllowOperationCalls.cs @@ -55,6 +55,15 @@ public Native(IOperationFactory m) : base(m) bool IsSelf(ICallable callable) => callable.FullName == "Microsoft.Quantum.Diagnostics.AllowAtMostNCallsCA"; + // Partial ordering on two variants; returns true, if `lhs` is included in `rhs`. + // For example, Body <= Body, and Body <= Adjoint, but Controlled is not less than or equal Adjoint. + bool LessThanOrEqual(OperationFunctor lhs, OperationFunctor rhs) => lhs switch { + OperationFunctor.ControlledAdjoint => rhs == OperationFunctor.ControlledAdjoint, + OperationFunctor.Controlled => rhs == OperationFunctor.ControlledAdjoint || rhs == OperationFunctor.Controlled, + OperationFunctor.Adjoint => rhs == OperationFunctor.ControlledAdjoint || rhs == OperationFunctor.Adjoint, + _ => true // OperationFunctor.Body + }; + // Record whether or not the condition checked by this allow // has failed, so that we can property unwind in the endOperation // handler below. @@ -65,7 +74,11 @@ public Native(IOperationFactory m) : base(m) { if (IsSelf(callable)) return; callStack = callStack.Push(callable.FullName); - if (callable.FullName == op.FullName) + // `callable` is callable we just entered on the call stack, `op` is the callable + // that we are monitoring with AllowAtMostNCallsCA. We only increment the counter, + // if both callables have the same fully qualified name and if the variant of `op` + // is less restrictive than the one of `callable`. + if (callable.FullName == op.FullName && LessThanOrEqual(op.Variant, callable.Variant)) { callSites = callSites.Add(callStack); if (callSites.Count > nTimes) diff --git a/Standard/tests/Diagnostics/AllowTests.qs b/Standard/tests/Diagnostics/AllowTests.qs index 43385c0b749..f728cd371ce 100644 --- a/Standard/tests/Diagnostics/AllowTests.qs +++ b/Standard/tests/Diagnostics/AllowTests.qs @@ -64,6 +64,41 @@ namespace Microsoft.Quantum.Tests { } } + @Diag.Test("QuantumSimulator") + operation CheckAllowNCallsDistinguishControlled() : Unit { + within { + Diag.AllowAtMostNCallsCA(1, Controlled X, "Too many calls to Controlled X."); + } apply { + use (q1, q2) = (Qubit(), Qubit()); + // Should use one Controlled X, exactly as many times as allowed. + // X will not be accounted for. + X(q2); + Controlled X([q1], q2); + X(q2); + } + } + + @Diag.Test("QuantumSimulator") + operation CheckAllowNCallsDistinguishAdjoint() : Unit { + within { + Diag.AllowAtMostNCallsCA(4, S, "Too many calls to S."); + Diag.AllowAtMostNCallsCA(2, Adjoint S, "Too many calls to Adjoint S."); + Diag.AllowAtMostNCallsCA(2, Controlled S, "Too many calls to Controlled S."); + Diag.AllowAtMostNCallsCA(1, Adjoint Controlled S, "Too many calls to Adjoint Controlled S."); + } apply { + use (q1, q2) = (Qubit(), Qubit()); + // Should use two Adjoint S (one via Adjoint Controlled S), but exactly + // one Adjoint Controlled S. + S(q1); + Controlled S([q1], q2); + Adjoint Controlled S([q2], q1); + Adjoint S(q1); + + Reset(q1); + Reset(q2); + } + } + @Diag.Test("ToffoliSimulator") operation CheckAllowNQubitsWithNestedCalls() : Unit { // Here, the total number of allocated qubits exceeds our policy, From daa7e59a1fa5800f2ef83d4c2cc0e7bf27824ffb Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Tue, 22 Mar 2022 11:54:11 +0100 Subject: [PATCH 14/66] Improve code quality in MachineLearning library (#539) * Improve code quality. * Update MachineLearning/tests/StructureTests.qs Co-authored-by: Cassandra Granade Co-authored-by: Cassandra Granade --- MachineLearning/src/Classification.qs | 6 ++-- MachineLearning/src/GradientEstimation.qs | 17 ++++-------- MachineLearning/src/InputEncoding.qs | 34 +++++++++++------------ MachineLearning/src/Private.qs | 6 ++-- MachineLearning/src/Structure.qs | 27 +++++------------- MachineLearning/src/Training.qs | 34 +++++++++++------------ MachineLearning/tests/StructureTests.qs | 2 +- 7 files changed, 54 insertions(+), 72 deletions(-) diff --git a/MachineLearning/src/Classification.qs b/MachineLearning/src/Classification.qs index f9968cc4c40..2b696de553b 100644 --- a/MachineLearning/src/Classification.qs +++ b/MachineLearning/src/Classification.qs @@ -10,7 +10,7 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; - internal operation _PrepareClassification( + internal operation PrepareClassification( encoder : (LittleEndian => Unit is Adj + Ctl), model : SequentialModel, target : Qubit[] @@ -48,8 +48,8 @@ namespace Microsoft.Quantum.MachineLearning { : Double { let encodedSample = ApproximateInputEncoder(tolerance / IntAsDouble(Length(model::Structure)), sample); return 1.0 - EstimateFrequencyA( - _PrepareClassification(encodedSample::Prepare, model, _), - _TailMeasurement(encodedSample::NQubits), + PrepareClassification(encodedSample::Prepare, model, _), + TailMeasurement(encodedSample::NQubits), encodedSample::NQubits, nMeasurements ); diff --git a/MachineLearning/src/GradientEstimation.qs b/MachineLearning/src/GradientEstimation.qs index b3a56242684..b99f6f31aaf 100644 --- a/MachineLearning/src/GradientEstimation.qs +++ b/MachineLearning/src/GradientEstimation.qs @@ -12,12 +12,7 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Preparation; open Microsoft.Quantum.Characterization; - // NOTE: the last qubit of 'reg' in this context is the auxiliary qubit used in the Hadamard test. - internal operation _ApplyLEOperationToRawRegister(op : (LittleEndian => Unit is Adj), target : Qubit[]) : Unit is Adj { - op(LittleEndian(target)); - } - - internal operation _EstimateDerivativeWithParameterShift( + internal operation EstimateDerivativeWithParameterShift( inputEncoder : StateGenerator, model : SequentialModel, parameters : (Double[], Double[]), @@ -25,7 +20,7 @@ namespace Microsoft.Quantum.MachineLearning { nMeasurements : Int ) : Double { return EstimateRealOverlapBetweenStates( - _ApplyLEOperationToRawRegister(inputEncoder::Prepare, _), + target => inputEncoder::Prepare(LittleEndian(target)), ApplySequentialClassifier(model w/ Parameters <- Fst(parameters), _), ApplySequentialClassifier(model w/ Parameters <- Snd(parameters), _), nQubits, nMeasurements @@ -71,7 +66,7 @@ namespace Microsoft.Quantum.MachineLearning { // Now, suppose a gate at which we differentiate is the (Controlled R(\theta))([k0,k1,...,kr],[target]) // and we want a unitary description of its \theta-derivative. It can be written as // 1/2 {(Controlled R(\theta'))([k0,k1,...,kr],[target]) - (Controlled Z)([k1,...,kr],[k0])(Controlled R(\theta'))([k0,k1,...,kr],[target])} - mutable grad = ConstantArray(Length(model::Parameters), 0.0); + mutable grad = [0.0, size = Length(model::Parameters)]; let nQubits = MaxI(NQubitsRequired(model), encodedInput::NQubits); for gate in model::Structure { @@ -80,10 +75,10 @@ namespace Microsoft.Quantum.MachineLearning { w/ gate::ParameterIndex <- (model::Parameters[gate::ParameterIndex] + PI()); // NB: This the *antiderivative* of the bracket - let newDer = _EstimateDerivativeWithParameterShift( + let newDer = EstimateDerivativeWithParameterShift( encodedInput, model, (model::Parameters, paramShift), nQubits, nMeasurements ); - if (IsEmpty(gate::ControlIndices)) { + if IsEmpty(gate::ControlIndices) { //uncontrolled gate set grad w/= gate::ParameterIndex <- grad[gate::ParameterIndex] + newDer; } else { @@ -92,7 +87,7 @@ namespace Microsoft.Quantum.MachineLearning { w/ gate::ParameterIndex <- (model::Parameters[gate::ParameterIndex] + 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 = _EstimateDerivativeWithParameterShift( + let newDer1 = EstimateDerivativeWithParameterShift( encodedInput, model, (model::Parameters, controlledShift), nQubits, nMeasurements ); set grad w/= gate::ParameterIndex <- (grad[gate::ParameterIndex] + 0.5 * (newDer - newDer1)); diff --git a/MachineLearning/src/InputEncoding.qs b/MachineLearning/src/InputEncoding.qs index 0f9294cbd8e..c00e85afd3d 100644 --- a/MachineLearning/src/InputEncoding.qs +++ b/MachineLearning/src/InputEncoding.qs @@ -10,11 +10,11 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon; - internal function _CanApplyTwoQubitCase(datum: Double[]) : Bool { - return((Length(datum)==4) and (Microsoft.Quantum.Math.AbsD(datum[0]*datum[3]-datum[1]*datum[2])< 1E-12) and (Microsoft.Quantum.Math.AbsD(datum[0])> 1E-4)); + internal function CanApplyTwoQubitCase(datum: Double[]) : Bool { + return ((Length(datum)==4) and (Microsoft.Quantum.Math.AbsD(datum[0]*datum[3]-datum[1]*datum[2])< 1E-12) and (Microsoft.Quantum.Math.AbsD(datum[0])> 1E-4)); } - internal operation _ApplyTwoQubitCase(datum: Double[], reg: LittleEndian) : Unit is Adj + Ctl { + internal operation ApplyTwoQubitCase(datum: Double[], reg: LittleEndian) : Unit is Adj + Ctl { let x = datum[1]/datum[0]; let y = datum[2]/datum[0]; // we now encoding [1,x,y,x*y] @@ -24,7 +24,7 @@ namespace Microsoft.Quantum.MachineLearning { R(PauliY, ax, (reg!)[0]); } - internal function _Unnegate(negLocs: Int[], coefficients : ComplexPolar[]) : ComplexPolar[] { + internal function Unnegate(negLocs: Int[], coefficients : ComplexPolar[]) : ComplexPolar[] { mutable ret = coefficients; for idxNegative in negLocs { if idxNegative >= Length(coefficients) { @@ -36,10 +36,10 @@ namespace Microsoft.Quantum.MachineLearning { return ret; } - internal function _NegativeLocations(cNegative: Int, coefficients : ComplexPolar[]) : Int[] { + internal function NegativeLocations(cNegative: Int, coefficients : ComplexPolar[]) : Int[] { mutable negLocs = []; for (idx, coefficient) in Enumerated(coefficients) { - if (AbsD(coefficient::Argument - PI()) < 1E-9) { + if AbsD(coefficient::Argument - PI()) < 1E-9 { set negLocs += [idx]; } } @@ -47,7 +47,7 @@ namespace Microsoft.Quantum.MachineLearning { } /// Do special processing on the first cNegative entries - internal operation _ReflectAboutNegativeCoefficients( + internal operation ReflectAboutNegativeCoefficients( negLocs : Int[], coefficients : ComplexPolar[], reg: LittleEndian @@ -96,11 +96,11 @@ namespace Microsoft.Quantum.MachineLearning { mutable cNegative = 0; for (idx, coef) in Enumerated(coefficients) { mutable magnitude = coef; - if (tolerance > 1E-9) { + if tolerance > 1E-9 { set magnitude = tolerance * IntAsDouble(Round(coefficients[idx] / tolerance)); //quantization } mutable ang = 0.0; - if (magnitude < 0.0) { + if magnitude < 0.0 { set cNegative += 1; set magnitude = -magnitude; set ang = PI(); @@ -109,8 +109,8 @@ namespace Microsoft.Quantum.MachineLearning { } // Check if we can apply the explicit two-qubit case. - if (_CanApplyTwoQubitCase(coefficients)) { - return StateGenerator(2, _ApplyTwoQubitCase(coefficients, _)); + if CanApplyTwoQubitCase(coefficients) { + return StateGenerator(2, ApplyTwoQubitCase(coefficients, _)); } let nQubits = FeatureRegisterSize(coefficients); @@ -119,18 +119,18 @@ namespace Microsoft.Quantum.MachineLearning { // there are only a few negative coefficients. // 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)) { - let negLocs = _NegativeLocations(cNegative, complexCoefficients); + if (cNegative > 0) and (IntAsDouble(cNegative) < Lg(IntAsDouble(Length(coefficients))) + 1.0) { + let negLocs = NegativeLocations(cNegative, complexCoefficients); return StateGenerator( nQubits, BoundCA([ // Prepare the state disregarding the sign of negative components. _CompileApproximateArbitraryStatePreparation( - tolerance, _Unnegate(negLocs, complexCoefficients), nQubits + tolerance, Unnegate(negLocs, complexCoefficients), nQubits ), // Reflect about the negative coefficients to apply the negative signs // at the end. - _ReflectAboutNegativeCoefficients(negLocs, complexCoefficients, _) + ReflectAboutNegativeCoefficients(negLocs, complexCoefficients, _) ]) ); } @@ -165,8 +165,8 @@ namespace Microsoft.Quantum.MachineLearning { | (-coefficient, PI()) ); } - if (_CanApplyTwoQubitCase(coefficients)) { - return StateGenerator(2, _ApplyTwoQubitCase(coefficients, _)); + if CanApplyTwoQubitCase(coefficients) { + return StateGenerator(2, ApplyTwoQubitCase(coefficients, _)); } //this is preparing the state almost exactly so far return StateGenerator( diff --git a/MachineLearning/src/Private.qs b/MachineLearning/src/Private.qs index 4feba8ae094..79f77a085e7 100644 --- a/MachineLearning/src/Private.qs +++ b/MachineLearning/src/Private.qs @@ -8,12 +8,12 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Math; - internal function _AllNearlyEqualD(v1 : Double[], v2 : Double[]) : Bool { + internal function AllNearlyEqualD(v1 : Double[], v2 : Double[]) : Bool { return Length(v1) == Length(v2) and All(NearlyEqualD, Zipped(v1, v2)); } - internal function _TailMeasurement(nQubits : Int) : (Qubit[] => Result) { - let paulis = ConstantArray(nQubits, PauliI) w/ (nQubits - 1) <- PauliZ; + internal function TailMeasurement(nQubits : Int) : (Qubit[] => Result) { + let paulis = [PauliI, size = nQubits] w/ (nQubits - 1) <- PauliZ; return Measure(paulis, _); } diff --git a/MachineLearning/src/Structure.qs b/MachineLearning/src/Structure.qs index b6bf2503339..06d874c63dc 100644 --- a/MachineLearning/src/Structure.qs +++ b/MachineLearning/src/Structure.qs @@ -44,7 +44,7 @@ namespace Microsoft.Quantum.MachineLearning { model : SequentialModel, qubits : Qubit[] ) - : (Unit) is Adj + Ctl { + : Unit is Adj + Ctl { for gate in model::Structure { if gate::ParameterIndex < Length(model::Parameters) { let input = (gate::Axis, model::Parameters[gate::ParameterIndex], qubits[gate::TargetIndex]); @@ -58,26 +58,13 @@ namespace Microsoft.Quantum.MachineLearning { } } - function _UncontrolledSpanSequence(idxsQubits : Int[]) : (Int, Int[])[] { + internal function UncontrolledSpanSequence(idxsQubits : Int[]) : (Int, Int[])[] { return Zipped( idxsQubits, - ConstantArray(Length(idxsQubits), []) + [[], size = Length(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, _, _); - } - /// # Summary /// Returns an array of uncontrolled (single-qubit) rotations along a given /// axis, with one rotation for each qubit in a register, parameterized by @@ -95,9 +82,9 @@ namespace Microsoft.Quantum.MachineLearning { function LocalRotationsLayer(nQubits : Int, axis : Pauli) : ControlledRotation[] { // [parameterIndex, pauliCode, targetQubit\,sequence of control qubits\] return Mapped( - _Flipped(ControlledRotation(_, axis, _)), + (idx, seq) -> ControlledRotation(seq, axis, idx), Enumerated( - _UncontrolledSpanSequence(SequenceI(0, nQubits - 1)) + UncontrolledSpanSequence(SequenceI(0, nQubits - 1)) ) ); } @@ -118,9 +105,9 @@ namespace Microsoft.Quantum.MachineLearning { /// `nQubits` qubits. function PartialRotationsLayer(idxsQubits : Int[], axis : Pauli) : ControlledRotation[] { return Mapped( - _Flipped(ControlledRotation(_, axis, _)), + (idx, seq) -> ControlledRotation(seq, axis, idx), Enumerated( - _UncontrolledSpanSequence(idxsQubits) + UncontrolledSpanSequence(idxsQubits) ) ); } diff --git a/MachineLearning/src/Training.qs b/MachineLearning/src/Training.qs index 0d6fe44488a..807f27f4d62 100644 --- a/MachineLearning/src/Training.qs +++ b/MachineLearning/src/Training.qs @@ -11,14 +11,14 @@ namespace Microsoft.Quantum.MachineLearning { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Optimization; - internal function _MisclassificationRate(probabilities : Double[], labels : Int[], bias : Double) : Double { + internal function MisclassificationRate(probabilities : Double[], labels : Int[], bias : Double) : Double { let proposedLabels = InferredLabels(bias, probabilities); return IntAsDouble(NMisclassifications(proposedLabels, labels)) / IntAsDouble(Length(probabilities)); } /// # Summary /// Returns a bias value that leads to near-minimum misclassification score. - internal function _UpdatedBias(labeledProbabilities: (Double, Int)[], bias: Double, tolerance: Double) : Double { + internal function UpdatedBias(labeledProbabilities: (Double, Int)[], bias: Double, tolerance: Double) : Double { mutable (min1, max0) = (1.0, 0.0); // Find the range of classification probabilities for each class. @@ -42,7 +42,7 @@ namespace Microsoft.Quantum.MachineLearning { // If we can't find a perfect classification, minimize to find // the best feasible bias. let optimum = LocalUnivariateMinimum( - _MisclassificationRate(Mapped(Fst, labeledProbabilities), Mapped(Snd, labeledProbabilities), _), + MisclassificationRate(Mapped(Fst, labeledProbabilities), Mapped(Snd, labeledProbabilities), _), (0.5 - max0, 0.5 - min1), tolerance ); @@ -122,13 +122,13 @@ namespace Microsoft.Quantum.MachineLearning { /// /// # Output /// (utility, (new)parameters) pair - internal operation _RunSingleTrainingStep( + internal operation RunSingleTrainingStep( miniBatch : (LabeledSample, StateGenerator)[], options : TrainingOptions, model : SequentialModel ) : (Double, SequentialModel) { - mutable batchGradient = ConstantArray(Length(model::Parameters), 0.0); + mutable batchGradient = [0.0, size = Length(model::Parameters)]; for (idxSample, (sample, stateGenerator)) in Enumerated(miniBatch) { mutable err = IntAsDouble(sample::Label); @@ -179,7 +179,7 @@ namespace Microsoft.Quantum.MachineLearning { /// - The smallest number of misclassifications observed through to this /// epoch. /// - The new best sequential model found. - internal operation _RunSingleTrainingEpoch( + internal operation RunSingleTrainingEpoch( encodedSamples : (LabeledSample, StateGenerator)[], schedule : SamplingSchedule, periodScore: Int, options : TrainingOptions, @@ -212,7 +212,7 @@ namespace Microsoft.Quantum.MachineLearning { ); for (idxMinibatch, minibatch) in Enumerated(minibatches) { options::VerboseMessage($" Beginning minibatch {idxMinibatch} of {Length(minibatches)}."); - let (utility, updatedModel) = _RunSingleTrainingStep( + let (utility, updatedModel) = RunSingleTrainingStep( minibatch, options, bestSoFar ); if utility > 1e-7 { @@ -224,7 +224,7 @@ namespace Microsoft.Quantum.MachineLearning { options::Tolerance, updatedModel, features, options::NMeasurements ); - let updatedBias = _UpdatedBias( + let updatedBias = UpdatedBias( Zipped(probabilities, actualLabels), model::Bias, options::Tolerance ); let updatedLabels = InferredLabels( @@ -246,13 +246,13 @@ namespace Microsoft.Quantum.MachineLearning { /// # Summary /// Randomly rescales an input to either grow or shrink by a given factor. - internal operation _RandomlyRescale(scale : Double, value : Double) : Double { + internal operation RandomlyRescale(scale : Double, value : Double) : Double { return value * ( 1.0 + scale * (DrawRandomBool(0.5) ? 1.0 | -1.0) ); } - internal function _EncodeSample(effectiveTolerance : Double, nQubits : Int, sample : LabeledSample) + internal function EncodeSample(effectiveTolerance : Double, nQubits : Int, sample : LabeledSample) : (LabeledSample, StateGenerator) { return ( sample, @@ -313,7 +313,7 @@ namespace Microsoft.Quantum.MachineLearning { options::NMeasurements ); // Find the best bias for the new classification parameters. - let localBias = _UpdatedBias( + let localBias = UpdatedBias( Zipped(probabilities, Sampled(validationSchedule, labels)), 0.0, options::Tolerance @@ -342,7 +342,7 @@ namespace Microsoft.Quantum.MachineLearning { features, options::NMeasurements ); mutable bestSoFar = model - w/ Bias <- _UpdatedBias( + w/ Bias <- UpdatedBias( Zipped(probabilities, actualLabels), model::Bias, options::Tolerance ); @@ -358,7 +358,7 @@ namespace Microsoft.Quantum.MachineLearning { options::VerboseMessage(" Pre-encoding samples..."); let effectiveTolerance = options::Tolerance / IntAsDouble(Length(model::Structure)); let nQubits = MaxI(FeatureRegisterSize(samples[0]::Features), NQubitsRequired(model)); - let encodedSamples = Mapped(_EncodeSample(effectiveTolerance, nQubits, _), samples); + let encodedSamples = Mapped(EncodeSample(effectiveTolerance, nQubits, _), samples); //reintroducing learning rate heuristics mutable lrate = options::LearningRate; @@ -369,7 +369,7 @@ namespace Microsoft.Quantum.MachineLearning { for ep in 1..options::MaxEpochs { options::VerboseMessage($" Beginning epoch {ep}."); - let (nMisses, proposedUpdate) = _RunSingleTrainingEpoch( + let (nMisses, proposedUpdate) = RunSingleTrainingEpoch( encodedSamples, schedule, options::ScoringPeriod, options w/ LearningRate <- lrate w/ MinibatchSize <- batchSize, @@ -389,7 +389,7 @@ namespace Microsoft.Quantum.MachineLearning { if NearlyEqualD(current::Bias, proposedUpdate::Bias) and - _AllNearlyEqualD(current::Parameters, proposedUpdate::Parameters) + AllNearlyEqualD(current::Parameters, proposedUpdate::Parameters) { set nStalls += 1; // If we're more than halfway through our maximum allowed number of stalls, @@ -408,8 +408,8 @@ namespace Microsoft.Quantum.MachineLearning { if nStalls > options::MaxStalls / 2 { set current = SequentialModel( model::Structure, - ForEach(_RandomlyRescale(options::StochasticRescaleFactor, _), proposedUpdate::Parameters), - _RandomlyRescale(options::StochasticRescaleFactor, proposedUpdate::Bias) + ForEach(RandomlyRescale(options::StochasticRescaleFactor, _), proposedUpdate::Parameters), + RandomlyRescale(options::StochasticRescaleFactor, proposedUpdate::Bias) ); } } else { diff --git a/MachineLearning/tests/StructureTests.qs b/MachineLearning/tests/StructureTests.qs index 7187e8da9db..f62c2c2726f 100644 --- a/MachineLearning/tests/StructureTests.qs +++ b/MachineLearning/tests/StructureTests.qs @@ -13,7 +13,7 @@ namespace Microsoft.Quantum.MachineLearning.Tests { let model = Default() w/ Structure <- [ ML.ControlledRotation((3, [7, 9]), PauliX, 0), - ML.ControlledRotation((8, new Int[0]), PauliY, 1) + ML.ControlledRotation((8, []), PauliY, 1) ]; let actual = ML.NQubitsRequired(model); EqualityFactI(actual, 10, "Wrong output from NQubitsRequired."); From 4422ad5a94a0663e47e9aeeda5bc16544e69b4c3 Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Wed, 30 Mar 2022 05:08:26 -0700 Subject: [PATCH 15/66] Add note: SignedLittleEndian uses two's complement (#544) Fixes #467. --- Numerics/src/Integer/Types.qs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Numerics/src/Integer/Types.qs b/Numerics/src/Integer/Types.qs index 51632f972df..a8385183430 100644 --- a/Numerics/src/Integer/Types.qs +++ b/Numerics/src/Integer/Types.qs @@ -4,5 +4,6 @@ namespace Microsoft.Quantum.Arithmetic { /// # Summary /// Type of a signed integer stored in little endian (see LittleEndian). + /// Negative numbers are stored using two's complement. newtype SignedLittleEndian = LittleEndian; -} \ No newline at end of file +} From 7d0f9f74e2ead8809eede3bdc669467594cc1728 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Wed, 30 Mar 2022 18:46:43 +0200 Subject: [PATCH 16/66] Some code simplification in amplitude amplification test. (#545) --- Standard/tests/AmplitudeAmplificationTests.qs | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/Standard/tests/AmplitudeAmplificationTests.qs b/Standard/tests/AmplitudeAmplificationTests.qs index 07f6ce32f6d..2067e120e4d 100644 --- a/Standard/tests/AmplitudeAmplificationTests.qs +++ b/Standard/tests/AmplitudeAmplificationTests.qs @@ -12,35 +12,31 @@ namespace Microsoft.Quantum.Tests { open Microsoft.Quantum.Math; open Microsoft.Quantum.Oracles; - ///Here we consider the smallest example of amplitude amplification - ///Suppose we have a single-qubit oracle that prepares the state - /// O |0> = \lambda |1> + \sqrt{1-|\lambda|^2} |0> - /// The goal is to amplify the |1> state - /// We can do this either by synthesizing the reflection about the start and target states ourselves, - /// We can also do it by passing the oracle for state preparation - operation ExampleStatePrepImpl (lambda : Double, idxFlagQubit : Int, qubitStart : Qubit[]) : Unit is Adj + Ctl { + // Here we consider the smallest example of amplitude amplification + // Suppose we have a single-qubit oracle that prepares the state + // O |0> = \lambda |1> + \sqrt{1-|\lambda|^2} |0> + // The goal is to amplify the |1> state + // We can do this either by synthesizing the reflection about the start and target states ourselves, + // We can also do it by passing the oracle for state preparation + internal operation ExampleStatePrepImpl(lambda : Double, idxFlagQubit : Int, qubitStart : Qubit[]) : Unit is Adj + Ctl { let rotAngle = 2.0 * ArcSin(lambda); Ry(rotAngle, qubitStart[idxFlagQubit]); } - function ExampleStatePrep (lambda : Double) : StateOracle { - + internal function ExampleStatePrep(lambda : Double) : StateOracle { return StateOracle(ExampleStatePrepImpl(lambda, _, _)); } - /// In this minimal example, there are no system qubits, only a single flag qubit. - /// ExampleStatePrep is already of type StateOracle, so we call - /// StandardAmplitudeAmplification(iterations: Int, stateOracle : StateOracle, idxFlagQubit : Int startQubits: Qubit[]) : () + // In this minimal example, there are no system qubits, only a single flag qubit. + // ExampleStatePrep is already of type StateOracle, so we call + // StandardAmplitudeAmplification(iterations: Int, stateOracle : StateOracle, idxFlagQubit : Int startQubits: Qubit[]) : () @Test("QuantumSimulator") - operation CheckAmpAmpByOracle () : Unit { - + operation CheckAmpAmpByOracle() : Unit { use qubits = Qubit[1]; - ResetAll(qubits); for nIterations in 0 .. 5 { - for idx in 1 .. 20 { let lambda = IntAsDouble(idx) / 20.0; let rotAngle = ArcSin(lambda); @@ -50,16 +46,15 @@ namespace Microsoft.Quantum.Tests { (StandardAmplitudeAmplification(nIterations, stateOracle, idxFlag))(startQubits); let successAmplitude = Sin(IntAsDouble(2 * nIterations + 1) * rotAngle); let successProbability = successAmplitude * successAmplitude; - AssertMeasurementProbability([PauliZ], [startQubits[idxFlag]], One, successProbability, $"Error: Success probability does not match theory", 1E-10); + AssertMeasurementProbability([PauliZ], [startQubits[idxFlag]], One, successProbability, "Error: Success probability does not match theory", 1E-10); ResetAll(qubits); } } } @Test("QuantumSimulator") - operation CheckAmpAmpObliviousByOraclePhases () : Unit { + operation CheckAmpAmpObliviousByOraclePhases() : Unit { use qubits = Qubit[1]; - ResetAll(qubits); for nIterations in 0 .. 5 { let phases = StandardReflectionPhases(nIterations); @@ -74,16 +69,15 @@ namespace Microsoft.Quantum.Tests { (ObliviousAmplitudeAmplificationFromStatePreparation(phases, ancillaOracle, signalOracle, idxFlag))(auxRegister, systemRegister); let successAmplitude = Sin((IntAsDouble(2 * nIterations + 1) * rotAngle) * 0.5); let successProbability = successAmplitude * successAmplitude; - AssertMeasurementProbability([PauliZ], [auxRegister[idxFlag]], One, successProbability, $"Error: Success probability does not match theory", 1E-10); + AssertMeasurementProbability([PauliZ], [auxRegister[idxFlag]], One, successProbability, "Error: Success probability does not match theory", 1E-10); ResetAll(qubits); } } } @Test("QuantumSimulator") - operation CheckAmpAmpTargetStateReflectionOracle () : Unit { + operation CheckAmpAmpTargetStateReflectionOracle() : Unit { use qubits = Qubit[1]; - ResetAll(qubits); for idx in 0 .. 20 { let rotangle = (IntAsDouble(idx) * PI()) / 20.0; @@ -91,7 +85,7 @@ namespace Microsoft.Quantum.Tests { let success = Cos(0.5 * rotangle) * Cos(0.5 * rotangle); H(qubits[0]); targetStateReflection!(rotangle, qubits); - AssertMeasurementProbability([PauliX], qubits, Zero, success, $"Error: Success probability does not match theory", 1E-10); + AssertMeasurementProbability([PauliX], qubits, Zero, success, "Error: Success probability does not match theory", 1E-10); ResetAll(qubits); } } @@ -109,5 +103,3 @@ namespace Microsoft.Quantum.Tests { } } - - From 9c209c2a52f2ee86d3a9ad851a567c6f6b65d401 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Fri, 1 Apr 2022 04:19:09 -0700 Subject: [PATCH 17/66] Updating projects and other components to build 0.24.201332 (#548) * Build 0.24.201332. * Fixing QDK version in Notice.txt --- Build/props/tests.props | 2 +- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- .../tests/ChemistryTests/QSharpTests.csproj | 2 +- .../tests/SystemTests/SystemTests.csproj | 2 +- MachineLearning/src/MachineLearning.csproj | 2 +- .../tests/MachineLearningTests.csproj | 2 +- NOTICE.txt | 20 +++++++++---------- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 2 +- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 2 +- Visualization/src/Visualization.csproj | 4 ++-- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Build/props/tests.props b/Build/props/tests.props index f8bb40d23f7..e14e3d4d195 100644 --- a/Build/props/tests.props +++ b/Build/props/tests.props @@ -7,7 +7,7 @@ - + diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index e276d844aa9..17d48d5157b 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index 336ef833a3d..baa4992beb6 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index 1dd0a325ef0..6f9abc5936e 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index 5cb5403a883..ae520453bf1 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index e5c02c4b3a7..a28ba82d009 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/NOTICE.txt b/NOTICE.txt index c1f965acb49..739a3ab9ead 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -5293,7 +5293,7 @@ Copyright (c) Microsoft Corporation. --------------------------------------------------------- -Microsoft.Quantum.Compiler 0.23.195983 - MIT +Microsoft.Quantum.Compiler 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5313,7 +5313,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.CSharpGeneration 0.23.195983 - MIT +Microsoft.Quantum.CSharpGeneration 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5333,7 +5333,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.DocumentationGenerator 0.23.195983 - MIT +Microsoft.Quantum.DocumentationGenerator 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5353,7 +5353,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Core 0.23.195983 - MIT +Microsoft.Quantum.IQSharp.Core 0.24.201332 - MIT (c) by W3C @@ -5760,7 +5760,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Jupyter 0.23.195983 - MIT +Microsoft.Quantum.IQSharp.Jupyter 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5780,7 +5780,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Core 0.23.195983 - MIT +Microsoft.Quantum.QSharp.Core 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5800,7 +5800,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Foundation 0.23.195983 - MIT +Microsoft.Quantum.QSharp.Foundation 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5820,7 +5820,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Runtime.Core 0.23.195983 - MIT +Microsoft.Quantum.Runtime.Core 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5840,7 +5840,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Simulators 0.23.195983 - MIT +Microsoft.Quantum.Simulators 0.24.201332 - MIT (c) 2008 VeriSign, Inc. @@ -5860,7 +5860,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Targets.Interfaces 0.23.195983 - MIT +Microsoft.Quantum.Targets.Interfaces 0.24.201332 - MIT (c) 2008 VeriSign, Inc. diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index b1398e6513c..61f716e1f4e 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index 1638055db81..872a5aabf21 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index f952f0f8a0a..5255fac0895 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index 3860da2d1f5..c32ab953110 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index 893fa6284de..58851a9ec46 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + From 2a892a9569b6e101351783829cfb4ac8af468a9e Mon Sep 17 00:00:00 2001 From: IsraelMiles <96441245+IsraelMiles@users.noreply.github.com> Date: Fri, 1 Apr 2022 12:00:48 -0700 Subject: [PATCH 18/66] add gh-sync workflow (#547) Co-authored-by: Mathias Soeken --- .github/workflows/gh-sync.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/gh-sync.yml diff --git a/.github/workflows/gh-sync.yml b/.github/workflows/gh-sync.yml new file mode 100644 index 00000000000..2e0beb45122 --- /dev/null +++ b/.github/workflows/gh-sync.yml @@ -0,0 +1,34 @@ +name: Sync GitHub with ADO + +on: + issues: + types: [closed, edited, deleted, reopened, assigned, unassigned, labeled, unlabeled] + issue_comment: + +jobs: + sync-issues: + name: Run gh-sync from GitHub action + if: ${{ github.event.label.name == 'tracking' || contains(github.event.issue.labels.*.name, 'tracking') }} + runs-on: ubuntu-latest + steps: + - name: Login to Azure + uses: Azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - id: AzureKeyVault + uses: Azure/get-keyvault-secrets@v1 + with: + keyvault: 'kv-qdk-build' + secrets: 'ghSyncBuildPAT' + + - name: 'Trigger gh-sync' + uses: microsoft/gh-sync@main + with: + ado-organization-url: ${{ secrets.ADO_URL }} + ado-project: ${{ secrets.ADO_PROJECT }} + ado-area-path: ${{ secrets.ADO_AREA_PATH }} + github-repo: 'microsoft/QuantumLibraries' + issue-number: ${{ github.event.issue.number }} + ado-token: ${{ steps.AzureKeyVault.outputs.ghSyncBuildPAT }} + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 9ea44b526b1f19eab6ec0e123c93869c2e9b75c6 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Mon, 4 Apr 2022 19:43:21 +0200 Subject: [PATCH 19/66] API review March 2022 (#535) * API review meeting notes. * Update Design/meetings/2022/api-design-2022-03.md Co-authored-by: Mariia Mykhailova * Apply suggestions from code review * Update consensus. Co-authored-by: Mariia Mykhailova --- Design/meetings/2022/api-design-2022-03.md | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Design/meetings/2022/api-design-2022-03.md diff --git a/Design/meetings/2022/api-design-2022-03.md b/Design/meetings/2022/api-design-2022-03.md new file mode 100644 index 00000000000..5d4d53edf02 --- /dev/null +++ b/Design/meetings/2022/api-design-2022-03.md @@ -0,0 +1,59 @@ +# Q# API Design Discussions / March 2022 + +Reviewers (in order by username): . + +## Agenda + +- https://github.com/microsoft/QuantumLibraries/issues/471 +- https://github.com/microsoft/QuantumLibraries/issues/442 +- https://github.com/microsoft/QuantumLibraries/issues/423 +- https://github.com/microsoft/QuantumLibraries/issues/515 + +## Discussion + +### Multivariate stochastic optimization + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/471 + +**Reviews**: +* @msoeken, *approve* +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved (incl. implicit approval from proposal author) + +--- + +### New functions for singly controlled operations + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/442 + +**Reviews**: +* @tcNickolas, *approve*, left a couple of small comments in the issue +* @msoeken, *approve* +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved (incl. implicit approval from proposal author) + +--- + +### Simple and consistent arithmetic API + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/423 + +**Reviews**: + +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Postponed (no additional review was provided) + +--- + +### New operation: AmplitudeTransduction + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/515 + +**Reviews**: +@msoeken, *approve* +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved (incl. implicit approval from proposal author) From c24686877a1d4382a6faa7963c37521cc0a1e68c Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 7 Apr 2022 08:34:41 +0200 Subject: [PATCH 20/66] Implements #442 (#552) * Implements #442. * Address reviewer feedback. --- .../src/Canon/Combinators/SinglyControlled.qs | 60 +++++++++++++++++++ .../Canon/Combinators/SinglyControlled.qs | 36 +++++++++++ 2 files changed, 96 insertions(+) create mode 100644 Standard/src/Canon/Combinators/SinglyControlled.qs create mode 100644 Standard/tests/Canon/Combinators/SinglyControlled.qs diff --git a/Standard/src/Canon/Combinators/SinglyControlled.qs b/Standard/src/Canon/Combinators/SinglyControlled.qs new file mode 100644 index 00000000000..29dc8c2d789 --- /dev/null +++ b/Standard/src/Canon/Combinators/SinglyControlled.qs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Canon { + + /// # Summary + /// Given a controllable operation, returns a controlled version of that operation + /// accepting exactly one control qubit. + /// + /// # Input + /// ## op + /// The operation to be controlled. + /// + /// # Output + /// A controlled variant of `op` accepting exactly one control qubit. + /// + /// # Example + /// To add the weight (number of "1" bits) of a control register to + /// a target register: + /// ```qsharp + /// ApplyToEachCA( + /// SinglyControlled(IncrementByInteger)(_, (1, target)), + /// controls) + /// ); + /// ``` + /// + /// # See Also + /// - Microsoft.Quantum.Canon.SinglyControlledA + function SinglyControlled<'T>(op : 'T => Unit is Ctl) : (Qubit, 'T) => Unit is Ctl { + return (ctrl, originalInput) => Controlled op([ctrl], originalInput); + } + + /// # Summary + /// Given a controllable operation, returns a controlled version of that operation + /// accepting exactly one control qubit. + /// + /// # Input + /// ## op + /// The operation to be controlled. + /// + /// # Output + /// A controlled variant of `op` accepting exactly one control qubit. + /// + /// # Example + /// To add the weight (number of "1" bits) of a control register to + /// a target register: + /// ```qsharp + /// ApplyToEachCA( + /// SinglyControlledA(IncrementByInteger)(_, (1, target)), + /// controls) + /// ); + /// ``` + /// + /// # See Also + /// - Microsoft.Quantum.Canon.SinglyControlled + function SinglyControlledA<'T>(op : 'T => Unit is Adj + Ctl) : (Qubit, 'T) => Unit is Adj + Ctl { + return (ctrl, originalInput) => Controlled op([ctrl], originalInput); + } + +} diff --git a/Standard/tests/Canon/Combinators/SinglyControlled.qs b/Standard/tests/Canon/Combinators/SinglyControlled.qs new file mode 100644 index 00000000000..a3649328b66 --- /dev/null +++ b/Standard/tests/Canon/Combinators/SinglyControlled.qs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Tests { + open Microsoft.Quantum.Arithmetic; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Intrinsic; + + @Test("ToffoliSimulator") + operation TestSinglyControlledWithSimulation() : Unit { + use ctl = Qubit(); + use target = Qubit[3]; + let targetLE = LittleEndian(target); + let value = 5; + + for singlyControlled in [SinglyControlled, SinglyControlledA] { + for enableControl in [false, true] { + within { + ApplyIfA(enableControl, X, ctl); + } apply { + singlyControlled(ApplyXorInPlace(value, _))(ctl, targetLE); + EqualityFactI(MeasureInteger(targetLE), enableControl ? value | 0, "Unexpected measurement result for SinglyControlled"); + } + } + } + } + + @Test("QuantumSimulator") + operation TestSinglyControlledWithEquivalenceCheck() : Unit { + AssertOperationsEqualReferenced(2, + qs => SinglyControlled(H)(qs[0], qs[1]), + qs => Controlled H([qs[0]], qs[1]) + ); + } +} From 53fb7677b47d6cac37b56cd071b26eaa7b30f34b Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Fri, 8 Apr 2022 08:10:52 +0200 Subject: [PATCH 21/66] Fix #546. (#553) --- .../Molecules/MoleculeTestHelpers.cs | 2 +- MachineLearning/src/Training.qs | 3 +- MachineLearning/tests/StructureTests.qs | 130 ++++-------------- Standard/src/Arrays/Arrays.qs | 32 ++--- Standard/src/Arrays/DrawMany.qs | 9 +- Standard/src/Arrays/Interleaved.qs | 10 +- Standard/src/Arrays/Map.qs | 52 ++++--- Standard/src/Arrays/Reductions.qs | 3 +- Standard/src/Arrays/Subarray.qs | 9 +- Standard/src/Arrays/Windows.qs | 2 +- Standard/src/Arrays/Zip.qs | 39 ++++-- Standard/tests/SimulatorTestTargets.cs | 2 +- 12 files changed, 129 insertions(+), 164 deletions(-) diff --git a/Chemistry/tests/SystemTests/Molecules/MoleculeTestHelpers.cs b/Chemistry/tests/SystemTests/Molecules/MoleculeTestHelpers.cs index 4773c2f4b08..a408474bfad 100644 --- a/Chemistry/tests/SystemTests/Molecules/MoleculeTestHelpers.cs +++ b/Chemistry/tests/SystemTests/Molecules/MoleculeTestHelpers.cs @@ -32,7 +32,7 @@ namespace SystemTests.Molecules public static class Helper { - private static readonly SHA256Managed hashMethod = new SHA256Managed(); + private static readonly SHA256 hashMethod = SHA256.Create(); /// /// Returns a seed to use for the test run based on the class diff --git a/MachineLearning/src/Training.qs b/MachineLearning/src/Training.qs index 807f27f4d62..56d6df0953c 100644 --- a/MachineLearning/src/Training.qs +++ b/MachineLearning/src/Training.qs @@ -87,8 +87,7 @@ namespace Microsoft.Quantum.MachineLearning { trainingSchedule : SamplingSchedule, validationSchedule : SamplingSchedule ) : (SequentialModel, Int) { - mutable bestSoFar = Default() - w/ Structure <- (Head(models))::Structure; + mutable bestSoFar = SequentialModel((Head(models))::Structure, [], 0.0); mutable bestValidation = Length(samples) + 1; let features = Mapped(_Features, samples); diff --git a/MachineLearning/tests/StructureTests.qs b/MachineLearning/tests/StructureTests.qs index f62c2c2726f..57f7298bf00 100644 --- a/MachineLearning/tests/StructureTests.qs +++ b/MachineLearning/tests/StructureTests.qs @@ -10,33 +10,20 @@ namespace Microsoft.Quantum.MachineLearning.Tests { @Test("QuantumSimulator") function NQubitsRequiredFact() : Unit { - let model = Default() - w/ Structure <- [ - ML.ControlledRotation((3, [7, 9]), PauliX, 0), - ML.ControlledRotation((8, []), PauliY, 1) - ]; + let model = ML.SequentialModel([ + ML.ControlledRotation((3, [7, 9]), PauliX, 0), + ML.ControlledRotation((8, []), PauliY, 1) + ], [], 0.); let actual = ML.NQubitsRequired(model); EqualityFactI(actual, 10, "Wrong output from NQubitsRequired."); } function ExampleModel() : ML.SequentialModel { - return Default() - w/ Structure <- [ - Default() - w/ TargetIndex <- 2 - w/ ControlIndices <- [0] - w/ Axis <- PauliX - w/ ParameterIndex <- 0, - Default() - w/ TargetIndex <- 0 - w/ ControlIndices <- [1, 2] - w/ Axis <- PauliZ - w/ ParameterIndex <- 1 - ] - w/ Parameters <- [ - 1.234, - 2.345 - ]; + return ML.SequentialModel([ + ML.ControlledRotation((2, [0]), PauliX, 0), + ML.ControlledRotation((0, [1, 2]), PauliZ, 1)], + [1.234, 2.345], + 0.0); } operation ApplyExampleModelManually(register : Qubit[]) : Unit is Adj + Ctl { @@ -64,23 +51,9 @@ namespace Microsoft.Quantum.MachineLearning.Tests { Fact(All(EqualCR, Zipped( ML.LocalRotationsLayer(3, PauliY), [ - Default() - w/ TargetIndex <- 0 - w/ ControlIndices <- [] - w/ Axis <- PauliY - w/ ParameterIndex <- 0, - - Default() - w/ TargetIndex <- 1 - w/ ControlIndices <- [] - w/ Axis <- PauliY - w/ ParameterIndex <- 1, - - Default() - w/ TargetIndex <- 2 - w/ ControlIndices <- [] - w/ Axis <- PauliY - w/ ParameterIndex <- 2 + ML.ControlledRotation((0, []), PauliY, 0), + ML.ControlledRotation((1, []), PauliY, 1), + ML.ControlledRotation((2, []), PauliY, 2) ] )), "LocalRotationsLayer returned wrong output."); } @@ -90,23 +63,9 @@ namespace Microsoft.Quantum.MachineLearning.Tests { Fact(All(EqualCR, Zipped( ML.PartialRotationsLayer([4, 5, 6], PauliY), [ - Default() - w/ TargetIndex <- 4 - w/ ControlIndices <- [] - w/ Axis <- PauliY - w/ ParameterIndex <- 0, - - Default() - w/ TargetIndex <- 5 - w/ ControlIndices <- [] - w/ Axis <- PauliY - w/ ParameterIndex <- 1, - - Default() - w/ TargetIndex <- 6 - w/ ControlIndices <- [] - w/ Axis <- PauliY - w/ ParameterIndex <- 2 + ML.ControlledRotation((4, []), PauliY, 0), + ML.ControlledRotation((5, []), PauliY, 1), + ML.ControlledRotation((6, []), PauliY, 2) ] )), "PartialRotationsLayer returned wrong output."); } @@ -116,23 +75,9 @@ namespace Microsoft.Quantum.MachineLearning.Tests { Fact(All(EqualCR, Zipped( ML.CyclicEntanglingLayer(3, PauliX, 2), [ - Default() - w/ TargetIndex <- 0 - w/ ControlIndices <- [2] - w/ Axis <- PauliX - w/ ParameterIndex <- 0, - - Default() - w/ TargetIndex <- 1 - w/ ControlIndices <- [0] - w/ Axis <- PauliX - w/ ParameterIndex <- 1, - - Default() - w/ TargetIndex <- 2 - w/ ControlIndices <- [1] - w/ Axis <- PauliX - w/ ParameterIndex <- 2 + ML.ControlledRotation((0, [2]), PauliX, 0), + ML.ControlledRotation((1, [0]), PauliX, 1), + ML.ControlledRotation((2, [1]), PauliX, 2) ] )), "CyclicEntanglingLayer returned wrong output."); } @@ -141,46 +86,19 @@ namespace Microsoft.Quantum.MachineLearning.Tests { function CombinedStructureFact() : Unit { let combined = ML.CombinedStructure([ [ - Default() - w/ TargetIndex <- 0 - w/ ControlIndices <- [2] - w/ Axis <- PauliX - w/ ParameterIndex <- 0, - - Default() - w/ TargetIndex <- 1 - w/ ControlIndices <- [0] - w/ Axis <- PauliX - w/ ParameterIndex <- 1 + ML.ControlledRotation((0, [2]), PauliX, 0), + ML.ControlledRotation((1, [0]), PauliX, 1) ], [ - Default() - w/ TargetIndex <- 2 - w/ ControlIndices <- [1] - w/ Axis <- PauliZ - w/ ParameterIndex <- 0 + ML.ControlledRotation((2, [1]), PauliZ, 0) ] ]); Fact(All(EqualCR, Zipped( combined, [ - Default() - w/ TargetIndex <- 0 - w/ ControlIndices <- [2] - w/ Axis <- PauliX - w/ ParameterIndex <- 0, - - Default() - w/ TargetIndex <- 1 - w/ ControlIndices <- [0] - w/ Axis <- PauliX - w/ ParameterIndex <- 1, - - Default() - w/ TargetIndex <- 2 - w/ ControlIndices <- [1] - w/ Axis <- PauliZ - w/ ParameterIndex <- 2 + ML.ControlledRotation((0, [2]), PauliX, 0), + ML.ControlledRotation((1, [0]), PauliX, 1), + ML.ControlledRotation((2, [1]), PauliZ, 2) ] )), "CombinedStructure returned wrong output."); } diff --git a/Standard/src/Arrays/Arrays.qs b/Standard/src/Arrays/Arrays.qs index 7506b9efcbd..96dca783ce0 100644 --- a/Standard/src/Arrays/Arrays.qs +++ b/Standard/src/Arrays/Arrays.qs @@ -211,23 +211,23 @@ namespace Microsoft.Quantum.Arrays { let nSliced = Length(remove); let nElements = Length(array); + if nElements - nSliced <= 0 { + return []; + } + //Would be better with sort function //Or way to add elements to array - mutable arrayKeep = [0, size = nElements]; - mutable sliced = [Default<'T>(), size = nElements - nSliced]; + mutable arrayKeep = SequenceI(0, nElements - 1); + mutable sliced = [array[0], size = nElements - nSliced]; mutable counter = 0; - for idx in 0 .. nElements - 1 { - set arrayKeep w/= idx <- idx; - } - - for idx in 0 .. nSliced - 1 { - set arrayKeep w/= remove[idx] <- -1; + for idx in remove { + set arrayKeep w/= idx <- -1; } - for idx in 0 .. nElements - 1 { - if (arrayKeep[idx] >= 0) { - set sliced w/= counter <- array[arrayKeep[idx]]; + for idx in arrayKeep { + if idx >= 0 { + set sliced w/= counter <- array[idx]; set counter += 1; } } @@ -331,16 +331,16 @@ namespace Microsoft.Quantum.Arrays { /// let split = Partitioned([2,2], [1,5,3,7]); /// ``` function Partitioned<'T>(nElements: Int[], arr: 'T[]) : 'T[][] { - mutable output = [Default<'T[]>(), size = Length(nElements) + 1]; + mutable output = [[], size = Length(nElements) + 1]; mutable currIdx = 0; for idx in IndexRange(nElements) { - if(currIdx + nElements[idx] > Length(arr)) { + if currIdx + nElements[idx] > Length(arr) { fail "Partitioned argument out of bounds."; } - set output w/= idx <- arr[currIdx..currIdx + nElements[idx]-1]; + set output w/= idx <- arr[currIdx..currIdx + nElements[idx] - 1]; set currIdx = currIdx + nElements[idx]; } - set output w/= Length(nElements) <- arr[currIdx..Length(arr)-1]; + set output w/= Length(nElements) <- arr[currIdx..Length(arr) - 1]; return output; } @@ -483,7 +483,7 @@ namespace Microsoft.Quantum.Arrays { /// TupleArrayAsNestedArray([(2, 3), (4, 5)]); /// ``` function TupleArrayAsNestedArray<'T>(tupleList : ('T, 'T)[]) : 'T[][] { - mutable newArray = [Default<'T[]>(), size = Length(tupleList)]; + mutable newArray = [[], size = Length(tupleList)]; for idx in IndexRange(tupleList) { let (tupleLeft, tupleRight) = tupleList[idx]; set newArray w/= idx <- [tupleLeft, tupleRight]; diff --git a/Standard/src/Arrays/DrawMany.qs b/Standard/src/Arrays/DrawMany.qs index 68eece54e0c..295c2dd4727 100644 --- a/Standard/src/Arrays/DrawMany.qs +++ b/Standard/src/Arrays/DrawMany.qs @@ -32,8 +32,13 @@ namespace Microsoft.Quantum.Arrays { /// - Microsoft.Quantum.Canon.Repeat operation DrawMany<'TInput, 'TOutput>(op : ('TInput => 'TOutput), nSamples : Int, input : 'TInput) : 'TOutput[] { - mutable outputs = [Default<'TOutput>(), size = nSamples]; - for idx in 0..nSamples - 1 { + if nSamples == 0 { + return []; + } + + let first = op(input); + mutable outputs = [first, size = nSamples]; + for idx in 1..nSamples - 1 { set outputs w/= idx <- op(input); } return outputs; diff --git a/Standard/src/Arrays/Interleaved.qs b/Standard/src/Arrays/Interleaved.qs index f944bbc919c..540e722d1f3 100644 --- a/Standard/src/Arrays/Interleaved.qs +++ b/Standard/src/Arrays/Interleaved.qs @@ -43,8 +43,12 @@ namespace Microsoft.Quantum.Arrays { Fact(lFirst >= lSecond and lFirst - lSecond <= 1, "Array `first` is either of same size as `second`, or has one more element"); - return [Default<'T>(), size = lFirst + lSecond] - w/ 0..2..(lFirst + lSecond - 1) <- first - w/ 1..2..(lFirst + lSecond - 1) <- second; + if lFirst == 0 { + return []; + } else { + return [first[0], size = lFirst + lSecond] + w/ 0..2..(lFirst + lSecond - 1) <- first + w/ 1..2..(lFirst + lSecond - 1) <- second; + } } } diff --git a/Standard/src/Arrays/Map.qs b/Standard/src/Arrays/Map.qs index 989aeb679a6..f3ff61f0ce0 100644 --- a/Standard/src/Arrays/Map.qs +++ b/Standard/src/Arrays/Map.qs @@ -32,13 +32,16 @@ namespace Microsoft.Quantum.Arrays { /// # See Also /// - Microsoft.Quantum.Arrays.ForEach function Mapped<'T, 'U> (mapper : ('T -> 'U), array : 'T[]) : 'U[] { - mutable resultArray = [Default<'U>(), size = Length(array)]; - - for idxElement in IndexRange(array) { - set resultArray w/= idxElement <- mapper(array[idxElement]); + let length = Length(array); + if length == 0 { + return []; } - - return resultArray; + let first = mapper(array[0]); + mutable retval = [first, size = length]; + for idx in 1..length - 1 { + set retval w/= idx <- mapper(array[idx]); + } + return retval; } /// # Summary @@ -80,13 +83,16 @@ namespace Microsoft.Quantum.Arrays { /// # See Also /// - Microsoft.Quantum.Arrays.Mapped function MappedByIndex<'T, 'U> (mapper : ((Int, 'T) -> 'U), array : 'T[]) : 'U[] { - mutable resultArray = [Default<'U>(), size = Length(array)]; - - for idxElement in IndexRange(array) { - set resultArray w/= idxElement <- mapper(idxElement, array[idxElement]); + let length = Length(array); + if length == 0 { + return []; } - - return resultArray; + let first = mapper(0, array[0]); + mutable retval = [first, size = length]; + for idx in 1..length - 1 { + set retval w/= idx <- mapper(idx, array[idx]); + } + return retval; } /// # Summary @@ -127,10 +133,13 @@ namespace Microsoft.Quantum.Arrays { let end = RangeEnd(range); if ((end - start) / step >= 0) { let nTerms = (end - start) / step + 1; - mutable resultArray = [Default<'T>(), size = nTerms]; + let first = mapper(start); + mutable resultArray = [first, size = nTerms]; mutable idxElement = 0; for elem in range { - set resultArray w/= idxElement <- mapper(elem); + if idxElement != 0 { + set resultArray w/= idxElement <- mapper(elem); + } set idxElement += 1; } return resultArray; @@ -220,13 +229,16 @@ namespace Microsoft.Quantum.Arrays { /// # See Also /// - Microsoft.Quantum.Arrays.Mapped operation ForEach<'T, 'U> (action : ('T => 'U), array : 'T[]) : 'U[] { - mutable resultArray = [Default<'U>(), size = Length(array)]; - - for idxElement in IndexRange(array) { - set resultArray w/= idxElement <- action(array[idxElement]); + let length = Length(array); + if length == 0 { + return []; } - - return resultArray; + let first = action(array[0]); + mutable retval = [first, size = length]; + for idx in 1..length - 1 { + set retval w/= idx <- action(array[idx]); + } + return retval; } } diff --git a/Standard/src/Arrays/Reductions.qs b/Standard/src/Arrays/Reductions.qs index 4603bc9d141..34e43624ede 100644 --- a/Standard/src/Arrays/Reductions.qs +++ b/Standard/src/Arrays/Reductions.qs @@ -43,7 +43,8 @@ namespace Microsoft.Quantum.Arrays { /// ``` function CumulativeFolded<'State, 'T>(fn : (('State, 'T) -> 'State), state : 'State, array : 'T[]) : 'State[] { mutable current = state; - mutable result = [Default<'State>(), size = Length(array)]; + // initialize with current, and then overwrite in loop + mutable result = [current, size = Length(array)]; for (i, elem) in Enumerated(array) { set current = fn(current, elem); diff --git a/Standard/src/Arrays/Subarray.qs b/Standard/src/Arrays/Subarray.qs index 1071dd4a104..f0a0dad9645 100644 --- a/Standard/src/Arrays/Subarray.qs +++ b/Standard/src/Arrays/Subarray.qs @@ -47,9 +47,14 @@ namespace Microsoft.Quantum.Arrays { /// ``` function Subarray<'T> (indices : Int[], array : 'T[]) : 'T[] { let nSliced = Length(indices); - mutable sliced = [Default<'T>(), size = nSliced]; - for idx in 0 .. nSliced - 1 { + if nSliced == 0 { + return []; + } + + mutable sliced = [array[indices[0]], size = nSliced]; + + for idx in 1 .. nSliced - 1 { set sliced w/= idx <- array[indices[idx]]; } diff --git a/Standard/src/Arrays/Windows.qs b/Standard/src/Arrays/Windows.qs index cf8f9551c6d..34837baae6f 100644 --- a/Standard/src/Arrays/Windows.qs +++ b/Standard/src/Arrays/Windows.qs @@ -37,7 +37,7 @@ namespace Microsoft.Quantum.Arrays { return []; } - mutable result = [Default<'T[]>(), size = n + 1 - size]; + mutable result = [[], size = n + 1 - size]; for i in 0..n - size { set result w/= i <- array[i..i + size - 1]; diff --git a/Standard/src/Arrays/Zip.qs b/Standard/src/Arrays/Zip.qs index 10965085658..b6634c14b52 100644 --- a/Standard/src/Arrays/Zip.qs +++ b/Standard/src/Arrays/Zip.qs @@ -2,6 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Arrays { + open Microsoft.Quantum.Canon; open Microsoft.Quantum.Math; /// # Summary @@ -40,9 +41,14 @@ namespace Microsoft.Quantum.Arrays { let nElements = Length(left) < Length(right) ? Length(left) | Length(right); - mutable output = [Default<('T, 'U)>(), size = nElements]; - for idxElement in 0 .. nElements - 1 { + if nElements == 0 { + return []; + } + + mutable output = [(left[0], right[0]), size = nElements]; + + for idxElement in 1 .. nElements - 1 { set output w/= idxElement <- (left[idxElement], right[idxElement]); } @@ -79,9 +85,14 @@ namespace Microsoft.Quantum.Arrays { /// - Microsoft.Quantum.Arrays.Zipped4 function Zipped3<'T1, 'T2, 'T3> (first : 'T1[], second : 'T2[], third : 'T3[]) : ('T1, 'T2, 'T3)[] { let nElements = Min([Length(first), Length(second), Length(third)]); - mutable output = [Default<('T1, 'T2, 'T3)>(), size = nElements]; - for idxElement in 0 .. nElements - 1 { + if nElements == 0 { + return []; + } + + mutable output = [(first[0], second[0], third[0]), size = nElements]; + + for idxElement in 1 .. nElements - 1 { set output w/= idxElement <- (first[idxElement], second[idxElement], third[idxElement]); } @@ -122,9 +133,14 @@ namespace Microsoft.Quantum.Arrays { /// - Microsoft.Quantum.Arrays.Zipped3 function Zipped4<'T1, 'T2, 'T3, 'T4> (first : 'T1[], second : 'T2[], third : 'T3[], fourth : 'T4[]) : ('T1, 'T2, 'T3, 'T4)[] { let nElements = Min([Length(first), Length(second), Length(third), Length(fourth)]); - mutable output = [Default<('T1, 'T2, 'T3, 'T4)>(), size = nElements]; - for idxElement in 0 .. nElements - 1 { + if nElements == 0 { + return []; + } + + mutable output = [(first[0], second[0], third[0], fourth[0]), size = nElements]; + + for idxElement in 1 .. nElements - 1 { set output w/= idxElement <- (first[idxElement], second[idxElement], third[idxElement], fourth[idxElement]); } @@ -162,9 +178,14 @@ namespace Microsoft.Quantum.Arrays { /// - Microsoft.Quantum.Arrays.Zipped function Unzipped<'T, 'U>(arr : ('T, 'U)[]) : ('T[], 'U[]) { let nElements = Length(arr); - mutable first = [Default<'T>(), size = nElements]; - mutable second = [Default<'U>(), size = nElements]; - for idxElement in 0 .. nElements - 1 { + + if nElements == 0 { + return ([], []); + } + + mutable first = [Fst(arr[0]), size = nElements]; + mutable second = [Snd(arr[0]), size = nElements]; + for idxElement in 1 .. nElements - 1 { let (left, right) = arr[idxElement]; set first w/= idxElement <- left; set second w/= idxElement <- right; diff --git a/Standard/tests/SimulatorTestTargets.cs b/Standard/tests/SimulatorTestTargets.cs index c49bea1de67..12f2d1dce12 100644 --- a/Standard/tests/SimulatorTestTargets.cs +++ b/Standard/tests/SimulatorTestTargets.cs @@ -214,6 +214,6 @@ private void LogSimulatorSeed(TestOperation opData, QuantumSimulator sim) return seed; } - private static readonly SHA256Managed hashMethod = new SHA256Managed(); + private static readonly SHA256 hashMethod = SHA256.Create(); } } From 30d1abd319f8968874e264fb32a92d303c27f128 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Sat, 9 Apr 2022 19:55:08 +0200 Subject: [PATCH 22/66] Fix documentation for Padded function. (#556) --- Standard/src/Arrays/Arrays.qs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Standard/src/Arrays/Arrays.qs b/Standard/src/Arrays/Arrays.qs index 96dca783ce0..4a5cd020812 100644 --- a/Standard/src/Arrays/Arrays.qs +++ b/Standard/src/Arrays/Arrays.qs @@ -261,9 +261,9 @@ namespace Microsoft.Quantum.Arrays { /// ```qsharp /// let array = [10, 11, 12]; /// // The following line returns [10, 12, 15, 2, 2, 2]. - /// let output = Padded(-6, array, 2); + /// let output = Padded(-6, 2, array); /// // The following line returns [2, 2, 2, 10, 12, 15]. - /// let output = Padded(6, array, 2); + /// let output = Padded(6, 2, array); /// ``` function Padded<'T> (nElementsTotal : Int, defaultElement : 'T, inputArray : 'T[]) : 'T[] { let nElementsInitial = Length(inputArray); From e838b63c9038c4a5faca3316020a0e14864eefaf Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Wed, 13 Apr 2022 14:00:05 +0200 Subject: [PATCH 23/66] Fixes #560 (#562) * Fixes #560. * Apply suggestions from code review Co-authored-by: Cassandra Granade Co-authored-by: Cassandra Granade --- Numerics/src/FixedPoint/Convert.qs | 22 ++++++++++++++++++++ Numerics/src/FixedPoint/Measurement.qs | 21 ++++++------------- Numerics/tests/FixedPointTests.qs | 28 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 Numerics/src/FixedPoint/Convert.qs diff --git a/Numerics/src/FixedPoint/Convert.qs b/Numerics/src/FixedPoint/Convert.qs new file mode 100644 index 00000000000..a91ffe0ddb8 --- /dev/null +++ b/Numerics/src/FixedPoint/Convert.qs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Convert { + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Math; + + /// # Summary + /// Returns the double value of a fixed-point approximation from of a `Bool` array. + /// + /// # Input + /// ## integerBits + /// Assumed number of integerBits (including the sign big) + /// ## bits + /// Bit-string representation of approximated number + internal function BoolArrayAsFixedPoint(integerBits : Int, bits : Bool[]) : Double { + let numBits = Length(bits); + let intPart = (Tail(bits) ? -(1 <<< (numBits - 1)) | 0) + BoolArrayAsInt(Most(bits)); + return IntAsDouble(intPart) / PowD(2.0, IntAsDouble(numBits - integerBits)); + } + +} diff --git a/Numerics/src/FixedPoint/Measurement.qs b/Numerics/src/FixedPoint/Measurement.qs index e6b928dd624..e746c34c5b6 100644 --- a/Numerics/src/FixedPoint/Measurement.qs +++ b/Numerics/src/FixedPoint/Measurement.qs @@ -2,9 +2,10 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Arithmetic { + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; open Microsoft.Quantum.Measurement; - open Microsoft.Quantum.Math; /// # Summary /// Measure a fixed-point number, returns its value as Double, and resets @@ -15,18 +16,8 @@ namespace Microsoft.Quantum.Arithmetic { /// Fixed-point number to measure. operation MeasureFxP(fp : FixedPoint) : Double { let (p, xs) = fp!; - let n = Length(xs); - let sign = MResetZ(xs[n-1]) == One; - mutable keepAdding = sign; - mutable fpAsDouble = 0.; - for i in 0..n - 2 { - mutable currentRes = MResetZ(xs[i]) == (sign ? Zero | One); - if keepAdding { - set keepAdding = currentRes; - set currentRes = not currentRes; - } - set fpAsDouble = fpAsDouble * 0.5 + (currentRes == true ? 1. | 0.); - } - return (sign ? -1.0 | 1.0) * fpAsDouble * PowD(2.0, IntAsDouble(p-2)); + + let bits = ForEach(q => MResetZ(q) == One, xs); + return BoolArrayAsFixedPoint(p, bits); } -} \ No newline at end of file +} diff --git a/Numerics/tests/FixedPointTests.qs b/Numerics/tests/FixedPointTests.qs index b420cdf00f3..0ecf6254e1d 100644 --- a/Numerics/tests/FixedPointTests.qs +++ b/Numerics/tests/FixedPointTests.qs @@ -3,6 +3,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; open Microsoft.Quantum.Math; open Microsoft.Quantum.Intrinsic; @@ -21,6 +22,33 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + internal operation PrepareAsSignedAndMeasure(value : Int, fxp : FixedPoint) : Double { + ApplyXorInPlace(value, LittleEndian(Snd(fxp!))); + return MeasureFxP(fxp); + } + + operation MeasureFxPTest() : Unit { + use qs = Qubit[4]; + let qsFxP = FixedPoint(2, qs); + + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0000, qsFxP), 0.0); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0001, qsFxP), 0.25); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0010, qsFxP), 0.5); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0011, qsFxP), 0.75); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0100, qsFxP), 1.0); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0101, qsFxP), 1.25); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0110, qsFxP), 1.5); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b0111, qsFxP), 1.75); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1000, qsFxP), -2.0); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1001, qsFxP), -1.75); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1010, qsFxP), -1.5); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1011, qsFxP), -1.25); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1100, qsFxP), -1.00); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1101, qsFxP), -0.75); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1110, qsFxP), -0.5); + NearEqualityFactD(PrepareAsSignedAndMeasure(0b1111, qsFxP), -0.25); + } + operation CompareGreaterThanFxPTest() : Unit { for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { for b in [1.1, 3.95, 3.14259, -0.4, -4.6, -3.931, 0.1] { From c8f8d67f8f916e40e61bdfc38dab50738ba8c74a Mon Sep 17 00:00:00 2001 From: IsraelMiles <96441245+IsraelMiles@users.noreply.github.com> Date: Wed, 13 Apr 2022 23:06:10 -0700 Subject: [PATCH 24/66] prevent race condition by enforcing concurrency cancellation on issue number (#565) --- .github/workflows/gh-sync.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/gh-sync.yml b/.github/workflows/gh-sync.yml index 2e0beb45122..68f04b52b89 100644 --- a/.github/workflows/gh-sync.yml +++ b/.github/workflows/gh-sync.yml @@ -5,6 +5,10 @@ on: types: [closed, edited, deleted, reopened, assigned, unassigned, labeled, unlabeled] issue_comment: +concurrency: + group: ${{ github.event.issue.number }} + cancel-in-progress: true + jobs: sync-issues: name: Run gh-sync from GitHub action From abe71ccf28dc78685f178e7802f6887a41e0c7f9 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 14 Apr 2022 11:01:32 +0200 Subject: [PATCH 25/66] Fixes #563. (#564) Co-authored-by: Mariia Mykhailova --- Standard/src/Canon/Parity.qs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Standard/src/Canon/Parity.qs b/Standard/src/Canon/Parity.qs index 59607868c88..af4c703ab9a 100644 --- a/Standard/src/Canon/Parity.qs +++ b/Standard/src/Canon/Parity.qs @@ -73,7 +73,7 @@ namespace Microsoft.Quantum.Canon { /// # Remarks /// The following are equivalent: /// ```qsharp - /// ApplyCNOTChainWithTarget(Most(qs), Last(qs)); + /// ApplyCNOTChainWithTarget(Most(qs), Tail(qs)); /// ``` /// and /// ```qsharp From eee471f94185fb2d5942fa9441fbebb0150e2a6b Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Wed, 20 Apr 2022 18:56:00 +0200 Subject: [PATCH 26/66] Removed C# test driver. (#566) --- Numerics/tests/FixedPointTests.qs | 22 +++++++++-- Numerics/tests/IntegerHighLevelTests.qs | 31 +++++++++------ Numerics/tests/NumericsTests.cs | 52 ------------------------- 3 files changed, 37 insertions(+), 68 deletions(-) delete mode 100644 Numerics/tests/NumericsTests.cs diff --git a/Numerics/tests/FixedPointTests.qs b/Numerics/tests/FixedPointTests.qs index 0ecf6254e1d..77fb825399a 100644 --- a/Numerics/tests/FixedPointTests.qs +++ b/Numerics/tests/FixedPointTests.qs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -namespace Microsoft.Quantum.Numerics.ToffoliTests { +namespace Microsoft.Quantum.Tests { open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; @@ -10,6 +10,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { open Microsoft.Quantum.Arithmetic; open Microsoft.Quantum.Diagnostics; + @Test("ToffoliSimulator") operation PrepareFxPTest() : Unit { for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { use xs = Qubit[10]; @@ -27,6 +28,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { return MeasureFxP(fxp); } + @Test("ToffoliSimulator") operation MeasureFxPTest() : Unit { use qs = Qubit[4]; let qsFxP = FixedPoint(2, qs); @@ -49,6 +51,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { NearEqualityFactD(PrepareAsSignedAndMeasure(0b1111, qsFxP), -0.25); } + @Test("ToffoliSimulator") operation CompareGreaterThanFxPTest() : Unit { for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { for b in [1.1, 3.95, 3.14259, -0.4, -4.6, -3.931, 0.1] { @@ -69,6 +72,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation AddConstantFxPTest() : Unit { for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { for b in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { @@ -82,6 +86,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation AddFxPTest() : Unit { for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { for b in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { @@ -99,6 +104,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation MultiplyFxPTest() : Unit { for pos in 5..8 { for a in [1.2, 3.9, 3.14159, -0.6, -3.5, -3.1931, 0.0] { @@ -123,6 +129,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation SquareFxPTest() : Unit { for pos in 5..8 { for a in [1.2, 3.9, 3.14159, -0.6, -3.5, -3.1931, 0.0] { @@ -141,7 +148,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } - function _computeReciprocal(a : Double, n : Int, pos : Int, pos2 : Int) : Double { + internal function ComputeReciprocal(a : Double, n : Int, pos : Int, pos2 : Int) : Double { let p = pos; let intA = a >= 0. ? Floor(AbsD(a) * IntAsDouble(2^(n-p)) + 0.5) | Ceiling(AbsD(a) * IntAsDouble(2^(n-p)) - 0.5); @@ -150,6 +157,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { return (a >= 0. ? 1. | -1.) * aReciprUnsigned; } + @Test("ToffoliSimulator") operation ComputeReciprocalFxPTest() : Unit { for pos in 5..8 { for pos2 in pos - 1..pos + 3 { @@ -166,8 +174,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { let eps2 = 1./IntAsDouble(2^(n-pos2)); let aEpsLarger = a + (a>=0. ? eps | -eps); let aEpsSmaller = a - (a>=0. ? eps | -eps); - let res1 = _computeReciprocal(a+eps,n,pos,pos2); - let res2 = _computeReciprocal(a-eps,n,pos,pos2); + let res1 = ComputeReciprocal(a+eps,n,pos,pos2); + let res2 = ComputeReciprocal(a-eps,n,pos,pos2); let minRes = MinD(res1, res2) - eps2; let maxRes = MaxD(res1, res2) + eps2; let isWithinTol = minRes <= measured and @@ -180,6 +188,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation SquareFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 5..8 { @@ -210,6 +219,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation MultiplyFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 5..8 { @@ -244,6 +254,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation EvaluatePolynomialFxPTest() : Unit { for pos in 4..5 { for coeffs in [[1.3, -2.4, 1.9], @@ -278,6 +289,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation EvaluatePolynomialFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 4..5 { @@ -323,6 +335,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation EvaluateOddPolynomialFxPTest() : Unit { for pos in 4..5 { for coeffs in [[1.3, -2.4, 1.9], @@ -360,6 +373,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } + @Test("ToffoliSimulator") operation EvaluateOddPolynomialFxPCtrlTest() : Unit { for ctrl in 0..3 { for pos in 4..5 { diff --git a/Numerics/tests/IntegerHighLevelTests.qs b/Numerics/tests/IntegerHighLevelTests.qs index fe531b4e029..9950eb50937 100644 --- a/Numerics/tests/IntegerHighLevelTests.qs +++ b/Numerics/tests/IntegerHighLevelTests.qs @@ -1,42 +1,49 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -namespace Microsoft.Quantum.Numerics.ToffoliTests { +namespace Microsoft.Quantum.Tests { open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Arithmetic; open Microsoft.Quantum.Extensions.Math; + @Test("ToffoliSimulator") operation MultiplyIExhaustiveTest() : Unit { ExhaustiveTestHelper2Args(IntegerMultiplicationRun(false, _, _, _, _)); } + @Test("ToffoliSimulator") operation SquareIExhaustiveTest() : Unit { ExhaustiveTestHelper1Arg(IntegerSquareRun(false, _, _, _)); } + @Test("ToffoliSimulator") operation DivideIExhaustiveTest() : Unit { ExhaustiveTestHelper2Args(IntegerDivisionRun); } + @Test("ToffoliSimulator") operation SquareSIExhaustiveTest() : Unit { ExhaustiveTestHelper1Arg(IntegerSquareRun(true, _, _, _)); } + @Test("ToffoliSimulator") operation CompareGTSIExhaustiveTest() : Unit { ExhaustiveTestHelper2Args(IntegerGreaterThanRun(true, _, _, _, _)); } + @Test("ToffoliSimulator") operation MultiplySIExhaustiveTest() : Unit { ExhaustiveTestHelper2Args(IntegerMultiplicationRun(true, _, _, _, _)); } + @Test("ToffoliSimulator") operation ComputeReciprocalIExhaustiveTest() : Unit { ExhaustiveTestHelper1Arg(IntegerReciprocalRun(false, _, _, _)); } - operation IntegerGreaterThanRun(signed: Bool, a: Int, b: Int, - n: Int, numCtrl: Int) : Unit { + internal operation IntegerGreaterThanRun(signed: Bool, a: Int, b: Int, + n: Int, numCtrl: Int) : Unit { use aqs = Qubit[n]; use bqs = Qubit[n]; use result = Qubit(); @@ -94,8 +101,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } - operation IntegerMultiplicationRun(signed: Bool, a: Int, b: Int, - n: Int, numCtrl: Int) : Unit { + internal operation IntegerMultiplicationRun(signed: Bool, a: Int, b: Int, + n: Int, numCtrl: Int) : Unit { use aqs = Qubit[n]; use bqs = Qubit[n]; use cqs = Qubit[2 * n]; @@ -159,8 +166,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } - operation IntegerSquareRun(signed: Bool, a: Int, - n: Int, numCtrl: Int) : Unit { + internal operation IntegerSquareRun(signed: Bool, a: Int, + n: Int, numCtrl: Int) : Unit { use aqs = Qubit[n]; use cqs = Qubit[2 * n]; use ctrlqs = Qubit[numCtrl]; @@ -209,8 +216,8 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } - operation IntegerReciprocalRun(signed: Bool, a: Int, - n: Int, numCtrl: Int) : Unit { + internal operation IntegerReciprocalRun(signed: Bool, a: Int, + n: Int, numCtrl: Int) : Unit { use aqs = Qubit[n]; use cqs = Qubit[2 * n]; use ctrlqs = Qubit[numCtrl]; @@ -245,7 +252,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } - operation IntegerDivisionRun(a: Int, b: Int, n: Int, numCtrl: Int): Unit { + internal operation IntegerDivisionRun(a: Int, b: Int, n: Int, numCtrl: Int): Unit { use aqs = Qubit[n]; use bqs = Qubit[n]; use cqs = Qubit[n]; @@ -296,7 +303,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } - operation ExhaustiveTestHelper1Arg(TestFunction: ((Int, Int, Int) => Unit)) : Unit { + internal operation ExhaustiveTestHelper1Arg(TestFunction: ((Int, Int, Int) => Unit)) : Unit { for numCtrlQubits in 0..2 { for numQubits in 1..5 { for a in 0..2^numQubits - 1 { @@ -306,7 +313,7 @@ namespace Microsoft.Quantum.Numerics.ToffoliTests { } } - operation ExhaustiveTestHelper2Args(TestFunction: ((Int, Int, Int, Int) => Unit)) : Unit { + internal operation ExhaustiveTestHelper2Args(TestFunction: ((Int, Int, Int, Int) => Unit)) : Unit { for numCtrlQubits in 0..2 { for numQubits in 1..5 { for a in 0..2^numQubits - 1 { diff --git a/Numerics/tests/NumericsTests.cs b/Numerics/tests/NumericsTests.cs deleted file mode 100644 index 64a2590c41c..00000000000 --- a/Numerics/tests/NumericsTests.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Quantum.Simulation.XUnit; -using Microsoft.Quantum.Simulation.Simulators; -using Xunit.Abstractions; -using System.Diagnostics; - -namespace Microsoft.Quantum.Numerics.Tests -{ - public class NumericsTests - { - private readonly ITestOutputHelper output; - - public NumericsTests(ITestOutputHelper output) - { - this.output = output; - } - - /// - /// This driver will run all Q# tests (operations named "...Test") - /// that are located inside Microsoft.Quantum.Numerics.Tests using the quantum - /// simulator. - /// - [OperationDriver(TestNamespace = "Microsoft.Quantum.Numerics.Tests", - TestCasePrefix = "QSim:")] - public void QSimTests(TestOperation op) - { - var sim = new QuantumSimulator(); - // OnLog defines action(s) performed when Q# test calls function Message - sim.OnLog += (msg) => { output.WriteLine(msg); }; - sim.OnLog += (msg) => { Debug.WriteLine(msg); }; - op.TestOperationRunner(sim); - } - - /// - /// This driver will run all Q# tests (operations named "...Test") - /// that are located inside Microsoft.Quantum.Numerics.ToffoliTests using the - /// Toffoli simulator. - /// - [OperationDriver(TestNamespace = "Microsoft.Quantum.Numerics.ToffoliTests", - TestCasePrefix = "ToffSim:")] - public void ToffoliSimTests(TestOperation op) - { - var sim = new ToffoliSimulator(); - // OnLog defines action(s) performed when Q# test calls function Message - sim.OnLog += (msg) => { output.WriteLine(msg); }; - sim.OnLog += (msg) => { Debug.WriteLine(msg); }; - op.TestOperationRunner(sim); - } - } -} From 17b2c487b05bf4f7c1858fe1fa7deda80081caae Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Wed, 20 Apr 2022 22:43:22 +0200 Subject: [PATCH 27/66] Implements #465 (#568) * Implements #465. * Code refactoring. * Fix recursion error. * Adress reviewer comments. --- Numerics/src/Integer/Multiplication.qs | 196 +++++++++++++++--------- Numerics/tests/IntegerHighLevelTests.qs | 108 +++++++------ 2 files changed, 185 insertions(+), 119 deletions(-) diff --git a/Numerics/src/Integer/Multiplication.qs b/Numerics/src/Integer/Multiplication.qs index 01383d19bfc..4b5d7a7f5ae 100644 --- a/Numerics/src/Integer/Multiplication.qs +++ b/Numerics/src/Integer/Multiplication.qs @@ -3,6 +3,7 @@ namespace Microsoft.Quantum.Arithmetic { open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Diagnostics; @@ -12,82 +13,142 @@ namespace Microsoft.Quantum.Arithmetic { /// /// # Input /// ## xs - /// $n$-bit multiplicand (LittleEndian) + /// 𝑛₁-bit multiplicand /// ## ys - /// $n$-bit multiplier (LittleEndian) + /// 𝑛₂-bit multiplier /// ## result - /// $2n$-bit result (LittleEndian), must be in state $\ket{0}$ initially. + /// (𝑛₁+𝑛₂)-bit result, must be in state |0⟩ initially. /// /// # Remarks /// Uses a standard shift-and-add approach to implement the multiplication. - /// The controlled version was improved by copying out $x_i$ to an ancilla + /// The controlled version was improved by copying out 𝑥ᵢ to an ancilla /// qubit conditioned on the control qubits, and then controlling the /// addition on the ancilla qubit. - operation MultiplyI (xs: LittleEndian, ys: LittleEndian, - result: LittleEndian) : Unit is Adj + Ctl { + operation MultiplyI(xs: LittleEndian, ys: LittleEndian, result: LittleEndian) : Unit is Adj + Ctl { body (...) { - let n = Length(xs!); + let na = Length(xs!); + let nb = Length(ys!); - EqualityFactI(n, Length(ys!), "Integer multiplication requires - equally-sized registers xs and ys."); - EqualityFactI(2 * n, Length(result!), "Integer multiplication - requires a 2n-bit result registers."); + EqualityFactI(na + nb, Length(result!), "Integer multiplication requires a register as long as both input registers added"); AssertAllZero(result!); - for i in 0..n-1 { - Controlled AddI([xs![i]], (ys, LittleEndian(result![i..i+n]))); + for (idx, actl) in Enumerated(xs!) { + Controlled AddI([actl], (ys, LittleEndian(result![idx..idx + nb]))); } } controlled (controls, ...) { - let n = Length(xs!); + let na = Length(xs!); + let nb = Length(ys!); - EqualityFactI(n, Length(ys!), "Integer multiplication requires - equally-sized registers xs and ys."); - EqualityFactI(2 * n, Length(result!), "Integer multiplication - requires a 2n-bit result registers."); + EqualityFactI(na + nb, Length(result!), "Integer multiplication requires a register as long as both input registers added"); AssertAllZero(result!); - use aux = Qubit(); - for i in 0..n - 1 { - (Controlled CNOT) (controls, (xs![i], aux)); - (Controlled AddI) ([aux], (ys, LittleEndian(result![i..i+n]))); - (Controlled CNOT) (controls, (xs![i], aux)); + // Perform various optimizations based on number of controls + let numControls = Length(controls); + if numControls == 0 { + MultiplyI(xs, ys, result); + } elif numControls == 1 { + use aux = Qubit(); + for (idx, actl) in Enumerated(xs!) { + within { + ApplyAnd(controls[0], actl, aux); + } apply { + Controlled AddI([aux], (ys, LittleEndian(result![idx..idx + nb]))); + } + } + } else { + use helper = Qubit[numControls]; + within { + ApplyAndLadder(controls, Most(helper)); + } apply { + for (idx, actl) in Enumerated(xs!) { + within { + ApplyAnd(Tail(Most(helper)), actl, Tail(helper)); + } apply { + Controlled AddI([Tail(helper)], (ys, LittleEndian(result![idx..idx + nb]))); + } + } + } } } } + /// # Summary + /// Applies AND of at least 2 inputs on a target in |0⟩ state. + /// + /// # Inputs + /// ## controls + /// At least two control qubits + /// ## targets + /// All intermediate targets and the final AND in the last qubit of that register. + /// The size of `targets` must be one less than the size of `controls`. + internal operation ApplyAndLadder(controls : Qubit[], targets : Qubit[]) : Unit is Adj { + // TODO: This operation should be moved to M.Q.Canon in Standard after API review + EqualityFactI(Length(controls), Length(targets) + 1, "there must be one more control qubit than target qubits"); + Fact(Length(controls) >= 2, "there must be at least 2 control qubits"); + + let controls1 = [Head(controls)] + Most(targets); + let controls2 = Rest(controls); + ApplyToEachA(ApplyAnd, Zipped3(controls1, controls2, targets)); + } + /// # Summary /// Computes the square of the integer `xs` into `result`, /// which must be zero initially. /// /// # Input /// ## xs - /// $n$-bit number to square (LittleEndian) + /// 𝑛-bit number to square /// ## result - /// $2n$-bit result (LittleEndian), must be in state $\ket{0}$ initially. + /// 2𝑛-bit result, must be in state |0⟩ initially. /// /// # Remarks /// Uses a standard shift-and-add approach to compute the square. Saves - /// $n-1$ qubits compared to the straight-forward solution which first - /// copies out xs before applying a regular multiplier and then undoing + /// 𝑛-1 qubits compared to the straight-forward solution which first + /// copies out `xs` before applying a regular multiplier and then undoing /// the copy operation. - operation SquareI (xs: LittleEndian, result: LittleEndian) : Unit { + operation SquareI(xs: LittleEndian, result: LittleEndian) : Unit { body (...) { Controlled SquareI([], (xs, result)); } controlled (controls, ...) { let n = Length(xs!); - EqualityFactI(2 * n, Length(result!), "Integer multiplication - requires a 2n-bit result registers."); + EqualityFactI(2 * n, Length(result!), "Integer multiplication requires a 2n-bit result registers."); AssertAllZero(result!); - use aux = Qubit(); - for i in 0..n - 1 { - (Controlled CNOT) (controls, (xs![i], aux)); - (Controlled AddI) ([aux], (xs, - LittleEndian(result![i..i+n]))); - (Controlled CNOT) (controls, (xs![i], aux)); + let numControls = Length(controls); + if numControls == 0 { + use aux = Qubit(); + for (idx, ctl) in Enumerated(xs!) { + within { + CNOT(ctl, aux); + } apply { + Controlled AddI([aux], (xs, LittleEndian(result![idx..idx + n]))); + } + } + } elif numControls == 1 { + use aux = Qubit(); + for (idx, ctl) in Enumerated(xs!) { + within { + ApplyAnd(controls[0], ctl, aux); + } apply { + Controlled AddI([aux], (xs, LittleEndian(result![idx..idx + n]))); + } + } + } else { + use helper = Qubit[numControls]; + within { + ApplyAndLadder(controls, Most(helper)); + } apply { + for (idx, ctl) in Enumerated(xs!) { + within { + ApplyAnd(Tail(Most(helper)), ctl, Tail(helper)); + } apply { + Controlled AddI([Tail(helper)], (xs, LittleEndian(result![idx..idx + n]))); + } + } + } } } adjoint auto; @@ -100,39 +161,35 @@ namespace Microsoft.Quantum.Arithmetic { /// /// # Input /// ## xs - /// n-bit multiplicand (SignedLittleEndian) + /// 𝑛₁-bit multiplicand /// ## ys - /// n-bit multiplier (SignedLittleEndian) + /// 𝑛₂-bit multiplier /// ## result - /// 2n-bit result (SignedLittleEndian), must be in state $\ket{0}$ + /// (𝑛₁+𝑛₂)-bit result, must be in state |0⟩ /// initially. - operation MultiplySI (xs: SignedLittleEndian, - ys: SignedLittleEndian, - result: SignedLittleEndian): Unit { + operation MultiplySI(xs: SignedLittleEndian, ys: SignedLittleEndian, result: SignedLittleEndian): Unit { body (...) { Controlled MultiplySI([], (xs, ys, result)); } controlled (controls, ...) { - let n = Length(xs!!); use signx = Qubit(); use signy = Qubit(); - CNOT(Tail(xs!!), signx); - CNOT(Tail(ys!!), signy); - (Controlled Invert2sSI)([signx], xs); - (Controlled Invert2sSI)([signy], ys); - - (Controlled MultiplyI) (controls, (xs!, ys!, result!)); - CNOT(signx, signy); - // No controls required since `result` will still be zero - // if we did not perform the multiplication above. - (Controlled Invert2sSI)([signy], result); - CNOT(signx, signy); - - (Controlled Adjoint Invert2sSI)([signx], xs); - (Controlled Adjoint Invert2sSI)([signy], ys); - CNOT(Tail(xs!!), signx); - CNOT(Tail(ys!!), signy); + within { + CNOT(Tail(xs!!), signx); + CNOT(Tail(ys!!), signy); + Controlled Invert2sSI([signx], xs); + Controlled Invert2sSI([signy], ys); + } apply { + Controlled MultiplyI(controls, (xs!, ys!, result!)); + within { + CNOT(signx, signy); + } apply { + // No controls required since `result` will still be zero + // if we did not perform the multiplication above. + Controlled Invert2sSI([signy], result); + } + } } adjoint auto; adjoint controlled auto; @@ -144,15 +201,14 @@ namespace Microsoft.Quantum.Arithmetic { /// /// # Input /// ## xs - /// n-bit integer to square (SignedLittleEndian) + /// 𝑛-bit integer to square /// ## result - /// 2n-bit result (SignedLittleEndian), must be in state $\ket{0}$ + /// 2𝑛-bit result, must be in state |0⟩ /// initially. /// /// # Remarks - /// The implementation relies on IntegerSquare. - operation SquareSI (xs: SignedLittleEndian, - result: SignedLittleEndian): Unit is Adj + Ctl { + /// The implementation relies on `SquareI`. + operation SquareSI (xs: SignedLittleEndian, result: SignedLittleEndian): Unit is Adj + Ctl { body (...) { Controlled SquareSI([], (xs, result)); } @@ -160,13 +216,13 @@ namespace Microsoft.Quantum.Arithmetic { let n = Length(xs!!); use signx = Qubit(); use signy = Qubit(); - CNOT(Tail(xs!!), signx); - (Controlled Invert2sSI)([signx], xs); - - (Controlled SquareI) (controls, (xs!, result!)); - (Controlled Adjoint Invert2sSI)([signx], xs); - CNOT(Tail(xs!!), signx); + within { + CNOT(Tail(xs!!), signx); + Controlled Invert2sSI([signx], xs); + } apply { + Controlled SquareI(controls, (xs!, result!)); + } } } } diff --git a/Numerics/tests/IntegerHighLevelTests.qs b/Numerics/tests/IntegerHighLevelTests.qs index 9950eb50937..be4a64dff5b 100644 --- a/Numerics/tests/IntegerHighLevelTests.qs +++ b/Numerics/tests/IntegerHighLevelTests.qs @@ -9,7 +9,7 @@ namespace Microsoft.Quantum.Tests { @Test("ToffoliSimulator") operation MultiplyIExhaustiveTest() : Unit { - ExhaustiveTestHelper2Args(IntegerMultiplicationRun(false, _, _, _, _)); + ExhaustiveTestHelper2NonRegularArgs(IntegerMultiplicationRun(false, _, _, _, _, _)); } @Test("ToffoliSimulator") @@ -19,7 +19,7 @@ namespace Microsoft.Quantum.Tests { @Test("ToffoliSimulator") operation DivideIExhaustiveTest() : Unit { - ExhaustiveTestHelper2Args(IntegerDivisionRun); + ExhaustiveTestHelper2RegularArgs(IntegerDivisionRun); } @Test("ToffoliSimulator") @@ -29,12 +29,12 @@ namespace Microsoft.Quantum.Tests { @Test("ToffoliSimulator") operation CompareGTSIExhaustiveTest() : Unit { - ExhaustiveTestHelper2Args(IntegerGreaterThanRun(true, _, _, _, _)); + ExhaustiveTestHelper2RegularArgs(IntegerGreaterThanRun(true, _, _, _, _)); } @Test("ToffoliSimulator") operation MultiplySIExhaustiveTest() : Unit { - ExhaustiveTestHelper2Args(IntegerMultiplicationRun(true, _, _, _, _)); + ExhaustiveTestHelper2NonRegularArgs(IntegerMultiplicationRun(true, _, _, _, _, _)); } @Test("ToffoliSimulator") @@ -102,63 +102,57 @@ namespace Microsoft.Quantum.Tests { } internal operation IntegerMultiplicationRun(signed: Bool, a: Int, b: Int, - n: Int, numCtrl: Int) : Unit { - use aqs = Qubit[n]; - use bqs = Qubit[n]; - use cqs = Qubit[2 * n]; + na: Int, nb : Int, numCtrl: Int) : Unit { + let nc = na + nb; + use aqs = Qubit[na]; + use bqs = Qubit[nb]; + use cqs = Qubit[nc]; use ctrlqs = Qubit[numCtrl]; - ApplyXorInPlace(a, LittleEndian(aqs)); - ApplyXorInPlace(b, LittleEndian(bqs)); - if (signed) { - MultiplySI( - SignedLittleEndian(LittleEndian(aqs)), - SignedLittleEndian(LittleEndian(bqs)), - SignedLittleEndian(LittleEndian(cqs))); - } - else { - MultiplyI (LittleEndian(aqs), - LittleEndian(bqs), - LittleEndian(cqs)); - } - mutable asigned = a; - mutable bsigned = b; - if (signed and a >= 2^(n-1)) { - set asigned = -2^n+a; - } - if (signed and b >= 2^(n-1)) { - set bsigned = -2^n+b; + + let aLE = LittleEndian(aqs); + let bLE = LittleEndian(bqs); + let cLE = LittleEndian(cqs); + + ApplyXorInPlace(a, aLE); + ApplyXorInPlace(b, bLE); + if signed { + MultiplySI(SignedLittleEndian(aLE), + SignedLittleEndian(bLE), + SignedLittleEndian(cLE)); + } else { + MultiplyI(aLE, bLE, cLE); } + + let asigned = signed and a >= 2^(na - 1) ? -2^na + a | a; + let bsigned = signed and b >= 2^(nb - 1) ? -2^nb + b | b; mutable c = asigned * bsigned; - mutable cMeasured = MeasureInteger(LittleEndian(cqs)); - if (signed and cMeasured >= 2^(2*n-1)){ - set cMeasured = -2^(2*n) + cMeasured; + mutable cMeasured = MeasureInteger(cLE); + if signed and cMeasured >= 2^(nc-1) { + set cMeasured = -2^nc + cMeasured; } EqualityFactI(c, cMeasured, $"Multiplication did not yield the correct result: - {asigned} * {bsigned} = {c} != {cMeasured} [n={n}]"); + {asigned} * {bsigned} = {c} != {cMeasured} [na={na}, nb={nb}]"); ResetAll(aqs + bqs + cqs); for ctrlState in 0..2^numCtrl - 1 { ApplyXorInPlace(ctrlState, LittleEndian(ctrlqs)); - ApplyXorInPlace(a, LittleEndian(aqs)); - ApplyXorInPlace(b, LittleEndian(bqs)); + ApplyXorInPlace(a, aLE); + ApplyXorInPlace(b, bLE); if signed { - (Controlled MultiplySI) (ctrlqs, - (SignedLittleEndian(LittleEndian(aqs)), - SignedLittleEndian(LittleEndian(bqs)), - SignedLittleEndian(LittleEndian(cqs)))); + Controlled MultiplySI(ctrlqs, + (SignedLittleEndian(aLE), + SignedLittleEndian(bLE), + SignedLittleEndian(cLE))); } else { - (Controlled MultiplyI) (ctrlqs, - (LittleEndian(aqs), - LittleEndian(bqs), - LittleEndian(cqs))); + Controlled MultiplyI(ctrlqs, (aLE, bLE, cLE)); } set c = asigned * bsigned; - if ctrlState != 2^numCtrl-1 { + if ctrlState != 2^numCtrl - 1 { set c = 0; } - set cMeasured = MeasureInteger(LittleEndian(cqs)); - if signed and cMeasured >= 2^(2*n-1) { - set cMeasured = -2^(2*n) + cMeasured; + set cMeasured = MeasureInteger(cLE); + if signed and cMeasured >= 2^(nc - 1) { + set cMeasured = -2^nc + cMeasured; } EqualityFactI(c, cMeasured, "Controlled multiplication did not yield the correct result."); @@ -303,7 +297,7 @@ namespace Microsoft.Quantum.Tests { } } - internal operation ExhaustiveTestHelper1Arg(TestFunction: ((Int, Int, Int) => Unit)) : Unit { + internal operation ExhaustiveTestHelper1Arg(TestFunction: (Int, Int, Int) => Unit) : Unit { for numCtrlQubits in 0..2 { for numQubits in 1..5 { for a in 0..2^numQubits - 1 { @@ -313,7 +307,8 @@ namespace Microsoft.Quantum.Tests { } } - internal operation ExhaustiveTestHelper2Args(TestFunction: ((Int, Int, Int, Int) => Unit)) : Unit { + // Tests an operation that expects two input arguments with the same number of bits + internal operation ExhaustiveTestHelper2RegularArgs(TestFunction: (Int, Int, Int, Int) => Unit) : Unit { for numCtrlQubits in 0..2 { for numQubits in 1..5 { for a in 0..2^numQubits - 1 { @@ -324,4 +319,19 @@ namespace Microsoft.Quantum.Tests { } } } -} \ No newline at end of file + + // Tests an operation that expects two input arguments with a different number of bits + internal operation ExhaustiveTestHelper2NonRegularArgs(TestFunction: (Int, Int, Int, Int, Int) => Unit) : Unit { + for numCtrlQubits in 0..2 { + for numQubitsA in 1..4 { + for numQubitsB in 1..4 { + for a in 0..2^numQubitsA - 1 { + for b in 0..2^numQubitsB - 1 { + TestFunction(a, b, numQubitsA, numQubitsB, numCtrlQubits); + } + } + } + } + } + } +} From bd99e8225b349f073352fc8154ed079914b30a2a Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 21 Apr 2022 02:04:11 +0200 Subject: [PATCH 28/66] Refactor and remove duplicate internal operation. (#569) --- Numerics/src/Integer/Multiplication.qs | 23 +------- .../Canon/Combinators/ApplyMultiControlled.qs | 59 ++++++++++--------- 2 files changed, 32 insertions(+), 50 deletions(-) diff --git a/Numerics/src/Integer/Multiplication.qs b/Numerics/src/Integer/Multiplication.qs index 4b5d7a7f5ae..a3cf0620e71 100644 --- a/Numerics/src/Integer/Multiplication.qs +++ b/Numerics/src/Integer/Multiplication.qs @@ -59,7 +59,7 @@ namespace Microsoft.Quantum.Arithmetic { } else { use helper = Qubit[numControls]; within { - ApplyAndLadder(controls, Most(helper)); + AndLadder(CCNOTop(ApplyAnd), controls, Most(helper)); } apply { for (idx, actl) in Enumerated(xs!) { within { @@ -73,25 +73,6 @@ namespace Microsoft.Quantum.Arithmetic { } } - /// # Summary - /// Applies AND of at least 2 inputs on a target in |0⟩ state. - /// - /// # Inputs - /// ## controls - /// At least two control qubits - /// ## targets - /// All intermediate targets and the final AND in the last qubit of that register. - /// The size of `targets` must be one less than the size of `controls`. - internal operation ApplyAndLadder(controls : Qubit[], targets : Qubit[]) : Unit is Adj { - // TODO: This operation should be moved to M.Q.Canon in Standard after API review - EqualityFactI(Length(controls), Length(targets) + 1, "there must be one more control qubit than target qubits"); - Fact(Length(controls) >= 2, "there must be at least 2 control qubits"); - - let controls1 = [Head(controls)] + Most(targets); - let controls2 = Rest(controls); - ApplyToEachA(ApplyAnd, Zipped3(controls1, controls2, targets)); - } - /// # Summary /// Computes the square of the integer `xs` into `result`, /// which must be zero initially. @@ -139,7 +120,7 @@ namespace Microsoft.Quantum.Arithmetic { } else { use helper = Qubit[numControls]; within { - ApplyAndLadder(controls, Most(helper)); + AndLadder(CCNOTop(ApplyAnd), controls, Most(helper)); } apply { for (idx, ctl) in Enumerated(xs!) { within { diff --git a/Standard/src/Canon/Combinators/ApplyMultiControlled.qs b/Standard/src/Canon/Combinators/ApplyMultiControlled.qs index 18a6ccb3fea..b2078fd046b 100644 --- a/Standard/src/Canon/Combinators/ApplyMultiControlled.qs +++ b/Standard/src/Canon/Combinators/ApplyMultiControlled.qs @@ -2,8 +2,8 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Canon { - open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Diagnostics; /////////////////////////////////////////////////////////////////////////////////////////////// // Combinators for constructing multiply controlled versions of operations @@ -11,7 +11,7 @@ namespace Microsoft.Quantum.Canon { /// # Summary /// The signature type of CCNOT gate. - newtype CCNOTop = (Apply : ((Qubit, Qubit, Qubit) => Unit is Adj)); + newtype CCNOTop = (Apply : (Qubit, Qubit, Qubit) => Unit is Adj); /// # Summary @@ -45,26 +45,25 @@ namespace Microsoft.Quantum.Canon { /// /// # See Also /// - Microsoft.Quantum.Canon.ApplyMultiControlledCA - operation ApplyMultiControlledC (singlyControlledOp : (Qubit[] => Unit), ccnot : CCNOTop, controls : Qubit[], targets : Qubit[]) : Unit - { - body (...) - { - Fact(Length(controls) >= 1, $"Length of controls must be at least 1"); + operation ApplyMultiControlledC(singlyControlledOp : Qubit[] => Unit, ccnot : CCNOTop, controls : Qubit[], targets : Qubit[]) : Unit is Ctl { + body (...) { + let numControls = Length(controls); + + Fact(numControls >= 1, "Length of controls must be at least 1"); - if (Length(controls) == 1) { + if numControls == 1 { singlyControlledOp(controls + targets); - } - else - { - use aux = Qubit[Length(controls) - 1]; - AndLadder(ccnot, controls, aux); - singlyControlledOp([Tail(aux)] + targets); - Adjoint AndLadder(ccnot, controls, aux); + } else { + use aux = Qubit[numControls - 1]; + within { + AndLadder(ccnot, controls, aux); + } apply { + singlyControlledOp([Tail(aux)] + targets); + } } } - controlled (extraControls, ...) - { + controlled (extraControls, ...) { ApplyMultiControlledC(singlyControlledOp, ccnot, extraControls + controls, targets); } } @@ -102,17 +101,20 @@ namespace Microsoft.Quantum.Canon { /// /// # See Also /// - Microsoft.Quantum.Canon.ApplyMultiControlledC - operation ApplyMultiControlledCA (singlyControlledOp : (Qubit[] => Unit is Adj), ccnot : CCNOTop, controls : Qubit[], targets : Qubit[]) : Unit { + operation ApplyMultiControlledCA(singlyControlledOp : Qubit[] => Unit is Adj, ccnot : CCNOTop, controls : Qubit[], targets : Qubit[]) : Unit is Adj + Ctl { body (...) { - Fact(Length(controls) >= 1, $"Length of controls must be at least 1"); + let numControls = Length(controls); + Fact(numControls >= 1, $"Length of controls must be at least 1"); - if Length(controls) == 1 { + if numControls == 1 { singlyControlledOp(controls + targets); } else { - use ladderRegister = Qubit[Length(controls) - 1]; - AndLadder(ccnot, controls, ladderRegister); - singlyControlledOp([Tail(ladderRegister)] + targets); - Adjoint AndLadder(ccnot, controls, ladderRegister); + use ladderRegister = Qubit[numControls - 1]; + within { + AndLadder(ccnot, controls, ladderRegister); + } apply { + singlyControlledOp([Tail(ladderRegister)] + targets); + } } } @@ -164,14 +166,13 @@ namespace Microsoft.Quantum.Canon { /// - Used as a part of /// and . /// - For the explanation and circuit diagram see Figure 4.10, Section 4.3 in Nielsen & Chuang. - operation AndLadder (ccnot : CCNOTop, controls : Qubit[], targets : Qubit[]) : Unit is Adj { + 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::Apply(controls[0], controls[1], targets[0]); - for k in 1 .. Length(targets) - 1 { - ccnot::Apply(controls[k + 1], targets[k - 1], targets[k]); - } + let controls1 = [Head(controls)] + Most(targets); + let controls2 = Rest(controls); + ApplyToEachA(ccnot::Apply, Zipped3(controls1, controls2, targets)); } } From 488fb7c4254991fd23e7902b1b4d7410119943ea Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 21 Apr 2022 20:11:38 +0200 Subject: [PATCH 29/66] Fixes #570. (#572) --- Standard/src/Preparation/QuantumROM.qs | 60 +++++++++----------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/Standard/src/Preparation/QuantumROM.qs b/Standard/src/Preparation/QuantumROM.qs index 562fad35f72..242373d395f 100644 --- a/Standard/src/Preparation/QuantumROM.qs +++ b/Standard/src/Preparation/QuantumROM.qs @@ -2,12 +2,13 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Preparation { - open Microsoft.Quantum.Intrinsic; - open Microsoft.Quantum.Canon; open Microsoft.Quantum.Arithmetic; + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Math; - open Microsoft.Quantum.Arrays; /// # Summary /// Returns an operation that prepares a a purification of a given mixed state. @@ -107,10 +108,6 @@ namespace Microsoft.Quantum.Preparation { return MixedStatePreparation(qubitCounts, oneNorm, op); } - internal function SplitSign(coefficient : Double) : (Double, Int) { - return (AbsD(coefficient), coefficient < 0.0 ? 1 | 0); - } - /// # Summary /// Returns an operation that prepares a a purification of a given mixed /// state, entangled with a register representing a given collection of data. @@ -221,6 +218,9 @@ namespace Microsoft.Quantum.Preparation { /// - Microsoft.Quantum.Preparation.PurifiedMixedState function PurifiedMixedStateRequirements(targetError : Double, nCoefficients : Int) : MixedStatePreparationRequirements { + Fact(targetError > 0.0, "targetError must be positive"); + Fact(nCoefficients > 0, "nCoefficients must be positive"); + let nBitsPrecision = -Ceiling(Lg(0.5*targetError)) + 1; let nIndexQubits = Ceiling(Lg(IntAsDouble(nCoefficients))); let nGarbageQubits = nIndexQubits + 2 * nBitsPrecision + 1; @@ -235,21 +235,15 @@ namespace Microsoft.Quantum.Preparation { : (Double, Int[], Int[]) { let oneNorm = PNorm(1.0, coefficients); let nCoefficients = Length(coefficients); - if (bitsPrecision > 31) { - fail $"Bits of precision {bitsPrecision} unsupported. Max is 31."; - } - if (nCoefficients <= 1) { - fail $"Cannot prepare state with less than 2 coefficients."; - } - if (oneNorm == 0.0) { - fail $"State must have at least one coefficient > 0"; - } + Fact(bitsPrecision <= 31, $"Bits of precision {bitsPrecision} unsupported. Max is 31."); + Fact(nCoefficients > 1, "Cannot prepare state with less than 2 coefficients."); + Fact(oneNorm != 0.0, "State must have at least one coefficient > 0"); let barHeight = 2 ^ bitsPrecision - 1; mutable altIndex = RangeAsIntArray(0..nCoefficients - 1); mutable keepCoeff = Mapped( - RoundedDiscretizationCoefficients(_, oneNorm, nCoefficients, barHeight), + coefficient -> Round((AbsD(coefficient) / oneNorm) * IntAsDouble(nCoefficients) * IntAsDouble(barHeight)), coefficients ); @@ -268,15 +262,15 @@ namespace Microsoft.Quantum.Preparation { mutable barSource = []; for idxCoeff in IndexRange(keepCoeff) { - if (keepCoeff[idxCoeff] > barHeight) { + if keepCoeff[idxCoeff] > barHeight { set barSource += [idxCoeff]; - } elif (keepCoeff[idxCoeff] < barHeight) { + } elif keepCoeff[idxCoeff] < barHeight { set barSink += [idxCoeff]; } } for rep in 0..nCoefficients * 10 { - if (Length(barSink) > 0 and Length(barSource) > 0) { + if Length(barSink) > 0 and Length(barSource) > 0 { let idxSink = Tail(barSink); let idxSource = Tail(barSource); set barSink = Most(barSink); @@ -285,12 +279,12 @@ namespace Microsoft.Quantum.Preparation { set keepCoeff w/= idxSource <- keepCoeff[idxSource] - barHeight + keepCoeff[idxSink]; set altIndex w/= idxSink <- idxSource; - if (keepCoeff[idxSource] < barHeight) { + if keepCoeff[idxSource] < barHeight { set barSink += [idxSource]; - } elif (keepCoeff[idxSource] > barHeight) { + } elif keepCoeff[idxSource] > barHeight { set barSource += [idxSource]; } - } elif (Length(barSource) > 0) { + } elif Length(barSource) > 0 { let idxSource = Tail(barSource); set barSource = Most(barSource); set keepCoeff w/= idxSource <- barHeight; @@ -302,12 +296,6 @@ namespace Microsoft.Quantum.Preparation { return (oneNorm, keepCoeff, altIndex); } - // Used in QuantumROM implementation. - internal function RoundedDiscretizationCoefficients(coefficient: Double, oneNorm: Double, nCoefficients: Int, barHeight: Int) - : Int { - return Round((AbsD(coefficient) / oneNorm) * IntAsDouble(nCoefficients) * IntAsDouble(barHeight)); - } - // Used in QuantumROM implementation. internal operation PrepareQuantumROMState( nBitsPrecision: Int, nCoeffs: Int, nBitsIndices: Int, @@ -332,7 +320,7 @@ namespace Microsoft.Quantum.Preparation { ApplyToEachCA(H, uniformKeepCoeffRegister!); // Write bitstrings to altIndex and keepCoeff register. - let unitaryGenerator = (nCoeffs, QuantumROMBitStringWriterByIndex(_, keepCoeff, altIndex, data)); + let unitaryGenerator = (nCoeffs, idx -> WriteQuantumROMBitString(idx, keepCoeff, altIndex, data, _, _, _, _)); MultiplexOperationsFromGenerator(unitaryGenerator, indexRegister, (keepCoeffRegister, altIndexRegister, dataRegister, altDataRegister)); // Perform comparison @@ -341,23 +329,17 @@ namespace Microsoft.Quantum.Preparation { let indexRegisterSize = Length(indexRegister!); // Swap in register based on comparison - ApplyToEachCA((Controlled SWAP)([flagQubit], _), Zipped(indexRegister! + dataRegister, altIndexRegister! + altDataRegister)); - } - - // Used in QuantumROM implementation. - internal function QuantumROMBitStringWriterByIndex(idx : Int, keepCoeff : Int[], altIndex : Int[], data : Bool[][]) - : ((LittleEndian, LittleEndian, Qubit[], Qubit[]) => Unit is Adj + Ctl) { - return WriteQuantumROMBitString(idx, keepCoeff, altIndex, data, _, _, _, _); + ApplyToEachCA(Controlled SWAP([flagQubit], _), Zipped(indexRegister! + dataRegister, altIndexRegister! + altDataRegister)); } // Used in QuantumROM implementation. internal operation WriteQuantumROMBitString(idx: Int, keepCoeff: Int[], altIndex: Int[], data : Bool[][], keepCoeffRegister: LittleEndian, altIndexRegister: LittleEndian, dataRegister : Qubit[], altDataRegister : Qubit[]) : Unit is Adj + Ctl { - if (keepCoeff[idx] >= 0) { + if keepCoeff[idx] >= 0 { ApplyXorInPlace(keepCoeff[idx], keepCoeffRegister); } ApplyXorInPlace(altIndex[idx], altIndexRegister); - if (Length(dataRegister) > 0) { + if Length(dataRegister) > 0 { ApplyToEachCA(CControlledCA(X), Zipped(data[idx], dataRegister)); ApplyToEachCA(CControlledCA(X), Zipped(data[altIndex[idx]], altDataRegister)); } From 74a3d27447cc63d70b7fc460e917f0b548c383ad Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 21 Apr 2022 22:17:48 +0200 Subject: [PATCH 30/66] Fixes #571. (#573) --- Standard/src/Math/Functions.qs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Standard/src/Math/Functions.qs b/Standard/src/Math/Functions.qs index 7a19d4ec9fa..ab1e1662e18 100644 --- a/Standard/src/Math/Functions.qs +++ b/Standard/src/Math/Functions.qs @@ -751,7 +751,7 @@ namespace Microsoft.Quantum.Math { /// /// # Description /// Returns the factorial as `Double`, given an input of $n$ as a `Double`. - /// The domain of inputs for this function is `AbsD(n) < 170.0`. + /// The domain of inputs for this function is `n < 170`. /// /// # Remarks /// For $n \ge 10$, this function uses the Ramanujan approximation with a @@ -759,7 +759,7 @@ namespace Microsoft.Quantum.Math { /// /// # Input /// ## n - /// The number to take the approximate factorial of. + /// The number to take the approximate factorial of. Must not be negative. /// /// # Output /// The approximate factorial of `n`. From aeedcdd00ca78126e28c234d2f3fe1638545e928 Mon Sep 17 00:00:00 2001 From: Angela Burton Date: Sat, 23 Apr 2022 08:18:13 -0700 Subject: [PATCH 31/66] Add DevSkim scanning (#576) --- .github/workflows/devskim.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/devskim.yml diff --git a/.github/workflows/devskim.yml b/.github/workflows/devskim.yml new file mode 100644 index 00000000000..73414bb059b --- /dev/null +++ b/.github/workflows/devskim.yml @@ -0,0 +1,31 @@ +name: DevSkim + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + schedule: + # set schedule to run at 2AM PT on Saturdays + - cron: '0 9 * * Sat' + +jobs: + lint: + name: DevSkim + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run DevSkim scanner + uses: microsoft/DevSkim-Action@v1 + + - name: Upload DevSkim scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: devskim-results.sarif From b79847777e277eadbd7e605b9d640e0b16d0c351 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Wed, 4 May 2022 19:06:13 +0200 Subject: [PATCH 32/66] API review April 2022 (#561) * API review April 2022 * Apply suggestions from code review Co-authored-by: Mariia Mykhailova * Update api-design-2022-04.md * Update api-design-2022-04.md Co-authored-by: Mariia Mykhailova --- Design/meetings/2022/api-design-2022-04.md | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Design/meetings/2022/api-design-2022-04.md diff --git a/Design/meetings/2022/api-design-2022-04.md b/Design/meetings/2022/api-design-2022-04.md new file mode 100644 index 00000000000..bd1f6494167 --- /dev/null +++ b/Design/meetings/2022/api-design-2022-04.md @@ -0,0 +1,59 @@ +# Q# API Design Discussions / April 2022 + +Reviewers (in order by username): tcNickolas, msoeken + +## Agenda + +- https://github.com/microsoft/QuantumLibraries/issues/423 +- https://github.com/microsoft/QuantumLibraries/issues/549 +- https://github.com/microsoft/QuantumLibraries/issues/555 +- https://github.com/microsoft/QuantumLibraries/issues/559 + +## Discussion + +### Simple and consistent arithmetic API + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/423 + +**Reviews**: + +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Postponed (no additional review was provided) + +--- + +### Add names to tuple fields of FixedPoint UDT + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/549 + +**Reviews**: +* @tcNickolas, *approve* +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved (incl. implicit approval from proposal author) + +--- + +### Add SubtractFxP and InvertFxP to the Numerics package + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/555 + +**Reviews**: +* @tcNickoas, *approve* - I had a comment about the order of arguments for `SubtractFxP`, but I see you've already incorporated it in the proposal +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved (incl. implicit approval from proposal author) + +--- + +### FixedPoint conversion functions + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/559 + +**Reviews**: +* @tcNickolas, *approve*, left a comment +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved (incl. implicit approval from proposal author) + From 049ad5244dabb466c846a885d54e1db0100dce48 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 5 May 2022 09:45:39 +0200 Subject: [PATCH 33/66] Fixes #580. (#581) --- .../AmplitudeAmplification.qs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs b/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs index 6320789bec6..f71aecce202 100644 --- a/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs +++ b/Standard/src/AmplitudeAmplification/AmplitudeAmplification.qs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. namespace Microsoft.Quantum.AmplitudeAmplification { @@ -129,16 +129,16 @@ namespace Microsoft.Quantum.AmplitudeAmplification { /// 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, + /// O\ket{\text{start}}\_{fa}\ket{\psi}\_s= \lambda\ket{1}\_f\ket{\text{anything}}\_a\ket{\text{target}}\_s + \sqrt{1-|\lambda|^2}\ket{0}\_f\cdots, /// \end{align} - /// for some unitary $U$. + /// where $\ket{\text{target}}\_s = U \ket{\psi}\_s$ for some unitary $U$. function ObliviousAmplitudeAmplificationFromStatePreparation( phases : ReflectionPhases, startStateOracle : DeterministicStateOracle, signalOracle : ObliviousOracle, idxFlagQubit : Int ) - : ((Qubit[], Qubit[]) => Unit is Adj + Ctl) { + : (Qubit[], Qubit[]) => Unit is Adj + Ctl { let startStateReflection = ReflectionStart(); let targetStateReflection = TargetStateReflectionOracle(idxFlagQubit); let obliviousSignalOracle = ObliviousOracleFromDeterministicStateOracle( @@ -205,7 +205,7 @@ namespace Microsoft.Quantum.AmplitudeAmplification { startStateReflection : ReflectionOracle, targetStateReflection : ReflectionOracle ) - : (Qubit[] => Unit is Adj + Ctl) { + : Qubit[] => Unit is Adj + Ctl { // Pass empty qubit array using fact that NoOp does nothing. let qubitEmpty = []; let signalOracle = ObliviousOracle(NoOp); @@ -247,7 +247,7 @@ namespace Microsoft.Quantum.AmplitudeAmplification { stateOracle : StateOracle, idxFlagQubit : Int ) - : (Qubit[] => Unit is Adj + Ctl) { + : Qubit[] => Unit is Adj + Ctl { let systemRegister = []; let signalOracle = ObliviousOracle(NoOp); let startStateOracle = DeterministicStateOracleFromStateOracle(idxFlagQubit, stateOracle); @@ -290,7 +290,7 @@ namespace Microsoft.Quantum.AmplitudeAmplification { stateOracle : StateOracle, idxFlagQubit : Int ) - : (Qubit[] => Unit is Adj + Ctl) { + : Qubit[] => Unit is Adj + Ctl { let phases = StandardReflectionPhases(nIterations); return AmplitudeAmplificationFromStatePreparation(phases, stateOracle, idxFlagQubit); } @@ -317,7 +317,7 @@ namespace Microsoft.Quantum.AmplitudeAmplification { mutable exponentMax = 0; mutable exponentCurrent = 0; - //Complexity: Let \theta = \mathcal{O}(\sqrt{lambda}) + // Complexity: Let \theta = \mathcal{O}(\sqrt{lambda}) // Number of Measurements = O( Log^2(1/\theta) ) // Number of Queries = O(1/\theta) use flagQubit = Qubit(); @@ -325,7 +325,7 @@ namespace Microsoft.Quantum.AmplitudeAmplification { let idxFlagQubit = 0; repeat { - if 2 ^ exponentMax > queriesMax { + if 2^exponentMax > queriesMax { fail $"Target state not found. Maximum number of queries exceeded."; } From ad3a6f19aa2769a54069444c954afffb5cd0b6f4 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 21 Apr 2022 20:36:13 +0200 Subject: [PATCH 34/66] Implements #549. (#574) --- Numerics/src/FixedPoint/Addition.qs | 10 +-- Numerics/src/FixedPoint/Comparison.qs | 7 +- Numerics/src/FixedPoint/Facts.qs | 15 ++-- Numerics/src/FixedPoint/Init.qs | 7 +- Numerics/src/FixedPoint/Measurement.qs | 6 +- Numerics/src/FixedPoint/Multiplication.qs | 39 +++++----- Numerics/src/FixedPoint/Polynomial.qs | 88 ++++++++++------------- Numerics/src/FixedPoint/Types.qs | 2 +- 8 files changed, 74 insertions(+), 100 deletions(-) diff --git a/Numerics/src/FixedPoint/Addition.qs b/Numerics/src/FixedPoint/Addition.qs index d29cea9f75b..c6505f93b09 100644 --- a/Numerics/src/FixedPoint/Addition.qs +++ b/Numerics/src/FixedPoint/Addition.qs @@ -14,10 +14,9 @@ namespace Microsoft.Quantum.Arithmetic { /// Fixed-point number to which the constant will /// be added. operation AddConstantFxP(constant : Double, fp : FixedPoint) : Unit is Adj + Ctl { - let (px, xs) = fp!; - let n = Length(xs); + let n = Length(fp::Register); use ys = Qubit[n]; - let tmpFp = FixedPoint(px, ys); + let tmpFp = FixedPoint(fp::IntegerBits, ys); ApplyWithCA(PrepareFxP(constant, _), AddFxP(_, fp), tmpFp); } @@ -40,11 +39,8 @@ namespace Microsoft.Quantum.Arithmetic { /// to have the same point position counting from the least-significant /// bit, i.e., $n_i$ and $p_i$ must be equal. operation AddFxP(fp1 : FixedPoint, fp2 : FixedPoint) : Unit is Adj + Ctl { - let (px, xs) = fp1!; - let (py, ys) = fp2!; - IdenticalPointPosFactFxP([fp1, fp2]); - AddI(LittleEndian(xs), LittleEndian(ys)); + AddI(LittleEndian(fp1::Register), LittleEndian(fp2::Register)); } } diff --git a/Numerics/src/FixedPoint/Comparison.qs b/Numerics/src/FixedPoint/Comparison.qs index 1c1376e4b08..902d17bbd97 100644 --- a/Numerics/src/FixedPoint/Comparison.qs +++ b/Numerics/src/FixedPoint/Comparison.qs @@ -20,12 +20,9 @@ namespace Microsoft.Quantum.Arithmetic { /// to have the same point position and the same number of qubits. operation CompareGreaterThanFxP(fp1 : FixedPoint, fp2 : FixedPoint, result : Qubit) : Unit is Adj + Ctl { - let (px, xs) = fp1!; - let (py, ys) = fp2!; - IdenticalFormatFactFxP([fp1, fp2]); - CompareGTSI(SignedLittleEndian(LittleEndian(xs)), - SignedLittleEndian(LittleEndian(ys)), + CompareGTSI(SignedLittleEndian(LittleEndian(fp1::Register)), + SignedLittleEndian(LittleEndian(fp2::Register)), result); } } diff --git a/Numerics/src/FixedPoint/Facts.qs b/Numerics/src/FixedPoint/Facts.qs index 5277dda956d..2ba13d824a7 100644 --- a/Numerics/src/FixedPoint/Facts.qs +++ b/Numerics/src/FixedPoint/Facts.qs @@ -13,8 +13,7 @@ namespace Microsoft.Quantum.Arithmetic { /// This assertion succeeds when all qubits are in state $\ket{0}$, /// representing that the register encodes the fixed-point number $0.0$. operation AssertAllZeroFxP(fp : FixedPoint) : Unit is Adj + Ctl { - let (p, xs) = fp!; - AssertAllZero(xs); + AssertAllZero(fp::Register); } /// # Summary @@ -26,17 +25,16 @@ namespace Microsoft.Quantum.Arithmetic { /// Array of quantum fixed-point numbers that will be checked for /// compatibility (using assertions). function IdenticalFormatFactFxP(fixedPoints : FixedPoint[]) : Unit { - if (Length(fixedPoints) == 0) { + if IsEmpty(fixedPoints) { return (); } let (position, register) = fixedPoints[0]!; Fact(position > 0, "Point position must be greater than zero."); let n = Length(register); for fp in Most(fixedPoints) { - let (pos, reg) = fp!; - EqualityFactI(pos, position, + EqualityFactI(fp::IntegerBits, position, "FixedPoint numbers must have identical binary point position."); - EqualityFactI(Length(reg), n, + EqualityFactI(Length(fp::Register), n, "FixedPoint numbers must have identical number of qubits."); } } @@ -52,15 +50,14 @@ namespace Microsoft.Quantum.Arithmetic { /// Array of quantum fixed-point numbers that will be checked for /// compatibility (using assertions). function IdenticalPointPosFactFxP(fixedPoints : FixedPoint[]) : Unit { - if (Length(fixedPoints) == 0) { + if IsEmpty(fixedPoints) { return (); } let (position, register) = fixedPoints[0]!; Fact(position > 0, "Point position must be greater than zero."); let n = Length(register); for fp in Most(fixedPoints) { - let (pos, reg) = fp!; - EqualityFactI(Length(reg) - pos, n - position, + EqualityFactI(Length(fp::Register) - fp::IntegerBits, n - position, "FixedPoint numbers must have identical point alignment."); } } diff --git a/Numerics/src/FixedPoint/Init.qs b/Numerics/src/FixedPoint/Init.qs index 727ec8c8094..0f4ec690ad5 100644 --- a/Numerics/src/FixedPoint/Init.qs +++ b/Numerics/src/FixedPoint/Init.qs @@ -19,10 +19,9 @@ namespace Microsoft.Quantum.Arithmetic { // NB: We can't omit the body (...) declaration here, as the `set` // statements below prevent automatic adjoint generation. body (...) { - let (p, q) = fp!; - let n = Length(q); + let n = Length(fp::Register); let sign = constant < 0.; - mutable rescaledConstant = PowD(2., IntAsDouble(n-p)) * AbsD(constant) + 0.5; + mutable rescaledConstant = PowD(2., IntAsDouble(n - fp::IntegerBits)) * AbsD(constant) + 0.5; mutable keepAdding = sign; for i in 0..n - 1 { let intConstant = Floor(rescaledConstant); @@ -33,7 +32,7 @@ namespace Microsoft.Quantum.Arithmetic { set currentBit = not currentBit; } if currentBit { - X(q[i]); + X(fp::Register[i]); } } } diff --git a/Numerics/src/FixedPoint/Measurement.qs b/Numerics/src/FixedPoint/Measurement.qs index e746c34c5b6..f52408efda1 100644 --- a/Numerics/src/FixedPoint/Measurement.qs +++ b/Numerics/src/FixedPoint/Measurement.qs @@ -15,9 +15,7 @@ namespace Microsoft.Quantum.Arithmetic { /// ## fp /// Fixed-point number to measure. operation MeasureFxP(fp : FixedPoint) : Double { - let (p, xs) = fp!; - - let bits = ForEach(q => MResetZ(q) == One, xs); - return BoolArrayAsFixedPoint(p, bits); + let bits = ForEach(q => MResetZ(q) == One, fp::Register); + return BoolArrayAsFixedPoint(fp::IntegerBits, bits); } } diff --git a/Numerics/src/FixedPoint/Multiplication.qs b/Numerics/src/FixedPoint/Multiplication.qs index b440ef2ff16..e6150cbfbba 100644 --- a/Numerics/src/FixedPoint/Multiplication.qs +++ b/Numerics/src/FixedPoint/Multiplication.qs @@ -29,21 +29,20 @@ namespace Microsoft.Quantum.Arithmetic { controlled (controls, ...) { IdenticalFormatFactFxP([fp1, fp2, result]); AssertAllZeroFxP(result); - let (px, xs) = fp1!; - let (py, ys) = fp2!; - let (pz, zs) = result!; - let n = Length(xs); + let n = Length(fp1::Register); use tmpResult = Qubit[2*n]; - let xsInt = SignedLittleEndian(LittleEndian(xs)); - let ysInt = SignedLittleEndian(LittleEndian(ys)); + let xsInt = SignedLittleEndian(LittleEndian(fp1::Register)); + let ysInt = SignedLittleEndian(LittleEndian(fp2::Register)); let tmpResultInt = SignedLittleEndian( LittleEndian(tmpResult)); - MultiplySI(xsInt, ysInt, tmpResultInt); - (Controlled ApplyToEachCA)(controls, - (CNOT, - Zipped(tmpResult[n-px..2*n-px-1], zs))); - (Adjoint MultiplySI)(xsInt, ysInt, tmpResultInt); + within { + MultiplySI(xsInt, ysInt, tmpResultInt); + } apply { + Controlled ApplyToEachCA(controls, + (CNOT, + Zipped(tmpResult[n - fp1::IntegerBits..2 * n - fp1::IntegerBits - 1], result::Register))); + } } } @@ -63,19 +62,19 @@ namespace Microsoft.Quantum.Arithmetic { controlled (controls, ...) { IdenticalFormatFactFxP([fp, result]); AssertAllZeroFxP(result); - let (px, xs) = fp!; - let (py, ys) = result!; - let n = Length(xs); + let n = Length(fp::Register); use tmpResult = Qubit[2*n]; - let xsInt = SignedLittleEndian(LittleEndian(xs)); + let xsInt = SignedLittleEndian(LittleEndian(fp::Register)); let tmpResultInt = SignedLittleEndian( LittleEndian(tmpResult)); - SquareSI(xsInt, tmpResultInt); - (Controlled ApplyToEachCA)(controls, - (CNOT, - Zipped(tmpResult[n-px..2*n-px-1], ys))); - (Adjoint SquareSI)(xsInt, tmpResultInt); + within { + SquareSI(xsInt, tmpResultInt); + } apply { + Controlled ApplyToEachCA(controls, + (CNOT, + Zipped(tmpResult[n - fp::IntegerBits..2 * n - fp::IntegerBits - 1], result::Register))); + } } } } diff --git a/Numerics/src/FixedPoint/Polynomial.qs b/Numerics/src/FixedPoint/Polynomial.qs index ddc3399d40e..70949d27aa0 100644 --- a/Numerics/src/FixedPoint/Polynomial.qs +++ b/Numerics/src/FixedPoint/Polynomial.qs @@ -26,40 +26,30 @@ namespace Microsoft.Quantum.Arithmetic { IdenticalFormatFactFxP([fpx, result]); AssertAllZeroFxP(result); let degree = Length(coefficients) - 1; - let (p, q) = fpx!; - let n = Length(q); - if (degree == 0){ - (Controlled PrepareFxP)(controls, - (coefficients[0], result)); - } - elif (degree > 0) { + let p = fpx::IntegerBits; + let n = Length(fpx::Register); + if degree == 0 { + Controlled PrepareFxP(controls, (coefficients[0], result)); + } elif degree > 0 { // initialize ancillary register to a_d use qubits = Qubit[n * degree]; - let firstIterate = FixedPoint(p, - qubits[(degree-1)*n..degree*n-1]); - PrepareFxP(coefficients[degree], firstIterate); - for d in degree..(-1)..2 { - let currentIterate = FixedPoint(p, qubits[(d-1)*n..d*n-1]); - let nextIterate = FixedPoint(p, qubits[(d-2)*n..(d-1)*n-1]); - // multiply by x and then add current coefficient - MultiplyFxP(currentIterate, fpx, nextIterate); - AddConstantFxP(coefficients[d-1], nextIterate); - } - let finalIterate = FixedPoint(p, qubits[0..n-1]); - // final multiplication into the result register - Controlled MultiplyFxP(controls, (finalIterate, fpx, result)); - // add a_0 to complete polynomial evaluation and - Controlled AddConstantFxP(controls, - (coefficients[0], result)); - // uncompute intermediate results - for d in 2..degree { - let currentIterate = FixedPoint(p, qubits[(d-1)*n..d*n-1]); - let nextIterate = FixedPoint(p, qubits[(d-2)*n..(d-1)*n-1]); - Adjoint AddConstantFxP(coefficients[d-1], nextIterate); - Adjoint MultiplyFxP(currentIterate, fpx, - nextIterate); + within { + let firstIterate = FixedPoint(p, qubits[(degree - 1) * n..degree * n - 1]); + PrepareFxP(coefficients[degree], firstIterate); + for d in degree..(-1)..2 { + let currentIterate = FixedPoint(p, qubits[(d - 1) * n..d * n - 1]); + let nextIterate = FixedPoint(p, qubits[(d - 2) * n..(d - 1) * n - 1]); + // multiply by x and then add current coefficient + MultiplyFxP(currentIterate, fpx, nextIterate); + AddConstantFxP(coefficients[d-1], nextIterate); + } + } apply { + let finalIterate = FixedPoint(p, qubits[0..n-1]); + // final multiplication into the result register + Controlled MultiplyFxP(controls, (finalIterate, fpx, result)); + // add a_0 to complete polynomial evaluation and + Controlled AddConstantFxP(controls, (coefficients[0], result)); } - PrepareFxP(coefficients[degree], firstIterate); } } } @@ -86,21 +76,19 @@ namespace Microsoft.Quantum.Arithmetic { IdenticalFormatFactFxP([fpx, result]); AssertAllZeroFxP(result); let halfDegree = Length(coefficients) - 1; - let (p, q) = fpx!; - let n = Length(q); + let n = Length(fpx::Register); - if (halfDegree == 0){ - (Controlled PrepareFxP)(controls, - (coefficients[0], result)); - } - elif (halfDegree > 0) { + if halfDegree == 0 { + Controlled PrepareFxP(controls, (coefficients[0], result)); + } elif halfDegree > 0 { // initialize auxiliary register to a_d use xsSquared = Qubit[n]; - let fpxSquared = FixedPoint(p, xsSquared); - ApplyWithCA(SquareFxP(fpx, _), - Controlled EvaluatePolynomialFxP(controls, - (coefficients, _, result)), - fpxSquared); + let fpxSquared = FixedPoint(fpx::IntegerBits, xsSquared); + within { + SquareFxP(fpx, fpxSquared); + } apply { + Controlled EvaluatePolynomialFxP(controls, (coefficients, fpxSquared, result)); + } } } } @@ -127,15 +115,15 @@ namespace Microsoft.Quantum.Arithmetic { IdenticalFormatFactFxP([fpx, result]); AssertAllZeroFxP(result); let halfDegree = Length(coefficients) - 1; - let (p, q) = fpx!; - let n = Length(q); + let n = Length(fpx::Register); if halfDegree >= 0 { use tmpResult = Qubit[n]; - let tmpResultFp = FixedPoint(p, tmpResult); - ApplyWithCA(EvaluateEvenPolynomialFxP(coefficients, _, _), - Controlled MultiplyFxP(controls, - (_, _, result)), - (fpx, tmpResultFp)); + let tmpResultFp = FixedPoint(fpx::IntegerBits, tmpResult); + within { + EvaluateEvenPolynomialFxP(coefficients, fpx, tmpResultFp); + } apply { + Controlled MultiplyFxP(controls, (fpx, tmpResultFp, result)); + } } } } diff --git a/Numerics/src/FixedPoint/Types.qs b/Numerics/src/FixedPoint/Types.qs index c211316936b..267483ba823 100644 --- a/Numerics/src/FixedPoint/Types.qs +++ b/Numerics/src/FixedPoint/Types.qs @@ -6,5 +6,5 @@ namespace Microsoft.Quantum.Arithmetic { /// Represents a register of qubits encoding a fixed-point number. Consists of an integer that is equal to the number of /// qubits to the left of the binary point, i.e., qubits of weight greater /// than or equal to 1, and a quantum register. - newtype FixedPoint = (Int, Qubit[]); + newtype FixedPoint = (IntegerBits: Int, Register: Qubit[]); } From 7b5cfc4e4cc71bb29a70a346b7ccb233c39ac883 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Fri, 22 Apr 2022 01:19:55 +0200 Subject: [PATCH 35/66] Implements #555 (#557) * Implements #555. * Apply suggestions from code review Co-authored-by: Mariia Mykhailova * Change order of arguments. Co-authored-by: Mariia Mykhailova --- Numerics/src/FixedPoint/Addition.qs | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Numerics/src/FixedPoint/Addition.qs b/Numerics/src/FixedPoint/Addition.qs index c6505f93b09..08218d0c6a5 100644 --- a/Numerics/src/FixedPoint/Addition.qs +++ b/Numerics/src/FixedPoint/Addition.qs @@ -43,4 +43,46 @@ namespace Microsoft.Quantum.Arithmetic { AddI(LittleEndian(fp1::Register), LittleEndian(fp2::Register)); } + + /// # Summary + /// Computes the additive inverse of `fp`. + /// + /// # Input + /// ## fp + /// Fixed-point number to invert. + /// + /// # Remarks + /// Numerical inaccuracies may occur depending on the + /// bit-precision of the fixed-point number. + /// + /// # See also + /// - Microsoft.Quantum.Arithmetic.SubtractFxP + operation InvertFxP(fp: FixedPoint) : Unit is Adj + Ctl { + let (_, reg) = fp!; + Invert2sSI(SignedLittleEndian(LittleEndian(reg))); + } + + /// # Summary + /// Computes `minuend - subtrahend` and stores the difference in `minuend`. + /// + /// # Input + /// ## subtrahend + /// The subtrahend of the subtraction - the number to be subtracted. + /// ## minuend + /// The minuend of the subtraction - the number from which the other is subtracted. + /// + /// # Remarks + /// Computes the difference by inverting `subtrahend` before and after adding + /// it to `minuend`. Notice that `minuend`, the first argument is updated. + /// + /// # See also + /// - Microsoft.Quantum.Arithmetic.AddFxP + /// - Microsoft.Quantum.Arithmetic.InvertFxP + operation SubtractFxP(minuend : FixedPoint, subtrahend : FixedPoint) : Unit is Adj + Ctl { + within { + InvertFxP(subtrahend); + } apply { + AddFxP(subtrahend, minuend); + } + } } From 81fe6defd41d7e58fb24c92a7d2f116cadc6e567 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Fri, 22 Apr 2022 17:39:53 +0200 Subject: [PATCH 36/66] Implements fixed-point conversion functions (#575) * Implements #559. * Apply suggestions from code review Co-authored-by: Mariia Mykhailova * Use new UDT fields. Co-authored-by: Mariia Mykhailova --- Numerics/src/FixedPoint/Convert.qs | 54 ++++++++++++++++++++++++++++-- Numerics/src/FixedPoint/Init.qs | 28 +++------------- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/Numerics/src/FixedPoint/Convert.qs b/Numerics/src/FixedPoint/Convert.qs index a91ffe0ddb8..b8fa5f2368b 100644 --- a/Numerics/src/FixedPoint/Convert.qs +++ b/Numerics/src/FixedPoint/Convert.qs @@ -5,18 +5,66 @@ namespace Microsoft.Quantum.Convert { open Microsoft.Quantum.Arrays; open Microsoft.Quantum.Math; + /// # Summary + /// Computes fixed-point approximation for a double and returns it as `Bool` array. + /// + /// # Input + /// ## integerBits + /// Assumed number of integer bits (including the sign bit). + /// ## fractionalBits + /// Assumed number of fractional bits. + /// ## value + /// Value to be approximated. + function FixedPointAsBoolArray(integerBits : Int, fractionalBits : Int, value : Double) : Bool[] { + let numBits = integerBits + fractionalBits; + let sign = value < 0.0; + + mutable result = [false, size = numBits]; + mutable rescaledConstant = PowD(2.0, IntAsDouble(fractionalBits)) * AbsD(value) + 0.5; + mutable keepAdding = sign; + + for idx in 0..numBits - 1 { + let intConstant = Floor(rescaledConstant); + set rescaledConstant = rescaledConstant / 2.0; + mutable currentBit = (intConstant &&& 1) == (sign ? 0 | 1); + if keepAdding { + set keepAdding = currentBit; + set currentBit = not currentBit; + } + if currentBit { + set result w/= idx <- true; + } + } + + return result; + } + /// # Summary /// Returns the double value of a fixed-point approximation from of a `Bool` array. /// /// # Input /// ## integerBits - /// Assumed number of integerBits (including the sign big) + /// Assumed number of integer bits (including the sign bit). /// ## bits - /// Bit-string representation of approximated number - internal function BoolArrayAsFixedPoint(integerBits : Int, bits : Bool[]) : Double { + /// Bit-string representation of approximated number. + function BoolArrayAsFixedPoint(integerBits : Int, bits : Bool[]) : Double { let numBits = Length(bits); let intPart = (Tail(bits) ? -(1 <<< (numBits - 1)) | 0) + BoolArrayAsInt(Most(bits)); return IntAsDouble(intPart) / PowD(2.0, IntAsDouble(numBits - integerBits)); } + /// # Summary + /// Discretizes a double value as a fixed-point approximation and returns its value as a double. + /// + /// # Input + /// ## integerBits + /// Assumed number of integer bits (including the sign bit). + /// ## fractionalBits + /// Assumed number of fractional bits. + /// ## value + /// Value to be approximated. + function DoubleAsFixedPoint(integerBits : Int, fractionalBits : Int, value : Double) : Double { + return BoolArrayAsFixedPoint(integerBits, FixedPointAsBoolArray(integerBits, fractionalBits, value)); + } + } diff --git a/Numerics/src/FixedPoint/Init.qs b/Numerics/src/FixedPoint/Init.qs index 0f4ec690ad5..e8fb63fbebb 100644 --- a/Numerics/src/FixedPoint/Init.qs +++ b/Numerics/src/FixedPoint/Init.qs @@ -2,6 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Arithmetic { + open Microsoft.Quantum.Canon; open Microsoft.Quantum.Convert; open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Math; @@ -16,28 +17,7 @@ namespace Microsoft.Quantum.Arithmetic { /// Fixed-point number (of type FixedPoint) to initialize. operation PrepareFxP(constant : Double, fp : FixedPoint) : Unit is Adj + Ctl { - // NB: We can't omit the body (...) declaration here, as the `set` - // statements below prevent automatic adjoint generation. - body (...) { - let n = Length(fp::Register); - let sign = constant < 0.; - mutable rescaledConstant = PowD(2., IntAsDouble(n - fp::IntegerBits)) * AbsD(constant) + 0.5; - mutable keepAdding = sign; - for i in 0..n - 1 { - let intConstant = Floor(rescaledConstant); - set rescaledConstant = 0.5 * rescaledConstant; - mutable currentBit = (intConstant &&& 1) == (sign ? 0 | 1); - if keepAdding { - set keepAdding = currentBit; - set currentBit = not currentBit; - } - if currentBit { - X(fp::Register[i]); - } - } - } - controlled auto; - adjoint self; - adjoint controlled auto; + let bits = FixedPointAsBoolArray(fp::IntegerBits, Length(fp::Register) - fp::IntegerBits, constant); + ApplyPauliFromBitString(PauliX, true, bits, fp::Register); } -} \ No newline at end of file +} From 690d7423e6b418b74cb9da80b483e7380e590926 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Sun, 8 May 2022 13:46:27 +0200 Subject: [PATCH 37/66] Feature branch cleanup (#582) * Fixes #570. (#572) * Fixes #571. (#573) * Add DevSkim scanning (#576) * Examples in fixed-point conversion functions. * API review April 2022 (#561) * API review April 2022 * Apply suggestions from code review Co-authored-by: Mariia Mykhailova * Update api-design-2022-04.md * Update api-design-2022-04.md Co-authored-by: Mariia Mykhailova * Fixes #580. (#581) * Address reviewer's feedback. Co-authored-by: Angela Burton Co-authored-by: Mariia Mykhailova --- Numerics/src/FixedPoint/Convert.qs | 21 +++++++++++++++++++++ Numerics/tests/FixedPointTests.qs | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Numerics/src/FixedPoint/Convert.qs b/Numerics/src/FixedPoint/Convert.qs index b8fa5f2368b..76ebf640d47 100644 --- a/Numerics/src/FixedPoint/Convert.qs +++ b/Numerics/src/FixedPoint/Convert.qs @@ -15,6 +15,14 @@ namespace Microsoft.Quantum.Convert { /// Assumed number of fractional bits. /// ## value /// Value to be approximated. + /// + /// # Example + /// Note that the first element in the Boolean array is the least-significant bit. + /// ```qsharp + /// let bits = FixedPointAsBoolArray(2, 2, 1.25); // bits = [true, false, true, false] + /// let bits = FixedPointAsBoolArray(2, 2, 1.3); // bits = [true, false, true, false], approximated + /// let bits = FixedPointAsBoolArray(2, 2, -1.75); // bits = [true, false, false, true], two's complement + /// ``` function FixedPointAsBoolArray(integerBits : Int, fractionalBits : Int, value : Double) : Bool[] { let numBits = integerBits + fractionalBits; let sign = value < 0.0; @@ -47,6 +55,13 @@ namespace Microsoft.Quantum.Convert { /// Assumed number of integer bits (including the sign bit). /// ## bits /// Bit-string representation of approximated number. + /// + /// # Example + /// Note that the first element in the Boolean array is the least-significant bit. + /// ```qsharp + /// let value = BoolArrayAsFixedPoint(2, [true, false, true, false]); // value = 1.25 + /// let value = BoolArrayAsFixedPoint(2, [true, false, false, true]); // value = -1.75 + /// ``` function BoolArrayAsFixedPoint(integerBits : Int, bits : Bool[]) : Double { let numBits = Length(bits); let intPart = (Tail(bits) ? -(1 <<< (numBits - 1)) | 0) + BoolArrayAsInt(Most(bits)); @@ -63,6 +78,12 @@ namespace Microsoft.Quantum.Convert { /// Assumed number of fractional bits. /// ## value /// Value to be approximated. + /// + /// # Example + /// ```qsharp + /// let value = DoubleAsFixedPoint(2, 2, 1.3); // value = 1.25 + /// let value = DoubleAsFixedPoint(2, 2, 0.8); // value = 0.75 + /// ``` function DoubleAsFixedPoint(integerBits : Int, fractionalBits : Int, value : Double) : Double { return BoolArrayAsFixedPoint(integerBits, FixedPointAsBoolArray(integerBits, fractionalBits, value)); } diff --git a/Numerics/tests/FixedPointTests.qs b/Numerics/tests/FixedPointTests.qs index 77fb825399a..48e774997cb 100644 --- a/Numerics/tests/FixedPointTests.qs +++ b/Numerics/tests/FixedPointTests.qs @@ -51,6 +51,19 @@ namespace Microsoft.Quantum.Tests { NearEqualityFactD(PrepareAsSignedAndMeasure(0b1111, qsFxP), -0.25); } + @Test("QuantumSimulator") + operation FixedPointConversionTest() : Unit { + AllEqualityFactB(FixedPointAsBoolArray(2, 2, 1.25), [true, false, true, false], "FixedPointAsBoolArray failed"); + AllEqualityFactB(FixedPointAsBoolArray(2, 2, 1.3), [true, false, true, false], "FixedPointAsBoolArray failed"); + AllEqualityFactB(FixedPointAsBoolArray(2, 2, -1.75), [true, false, false, true], "FixedPointAsBoolArray failed"); + + NearEqualityFactD(BoolArrayAsFixedPoint(2, [true, false, true, false]), 1.25); + NearEqualityFactD(BoolArrayAsFixedPoint(2, [true, false, false, true]), -1.75); + + NearEqualityFactD(DoubleAsFixedPoint(2, 2, 1.3), 1.25); + NearEqualityFactD(DoubleAsFixedPoint(2, 2, 0.8), 0.75); + } + @Test("ToffoliSimulator") operation CompareGreaterThanFxPTest() : Unit { for a in [1.2, 3.9, 3.14159, -0.6, -4.5, -3.1931, 0.0] { From 025a8126023602cd3c57c2d0e07d1c682954c557 Mon Sep 17 00:00:00 2001 From: Andres Paz Date: Fri, 13 May 2022 21:24:00 -0700 Subject: [PATCH 38/66] Creating global.json (#586) --- global.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 00000000000..93f1cbe4cac --- /dev/null +++ b/global.json @@ -0,0 +1,9 @@ +{ + "sdk": { + "version": "6.0.100", + "rollForward": "latestMinor" + }, + "msbuild-sdks": { + "Microsoft.Quantum.Sdk": "0.24.201332" + } +} From dda01531f87b2850ea52f2b738d469475ad57e29 Mon Sep 17 00:00:00 2001 From: "microsoft-github-policy-service[bot]" <77245923+microsoft-github-policy-service[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 07:01:27 -0700 Subject: [PATCH 39/66] Microsoft mandatory file (#587) Co-authored-by: microsoft-github-policy-service[bot] <77245923+microsoft-github-policy-service[bot]@users.noreply.github.com> --- SECURITY.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000000..f7b89984f0f --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,41 @@ + + +## Security + +Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). + +If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. + +## Reporting Security Issues + +**Please do not report security vulnerabilities through public GitHub issues.** + +Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). + +If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). + +You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). + +Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: + + * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) + * Full paths of source file(s) related to the manifestation of the issue + * The location of the affected source code (tag/branch/commit or direct URL) + * Any special configuration required to reproduce the issue + * Step-by-step instructions to reproduce the issue + * Proof-of-concept or exploit code (if possible) + * Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. + +## Preferred Languages + +We prefer all communications to be in English. + +## Policy + +Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). + + \ No newline at end of file From 0730cda6eefe75ef4469347d82fabb04aa13ee23 Mon Sep 17 00:00:00 2001 From: Robin Kuzmin <9372582+kuzminrobin@users.noreply.github.com> Date: Wed, 25 May 2022 08:28:39 -0700 Subject: [PATCH 40/66] Updated to the latest QDK. (#591) --- Build/props/tests.props | 2 +- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- .../tests/ChemistryTests/QSharpTests.csproj | 2 +- .../tests/SystemTests/SystemTests.csproj | 2 +- MachineLearning/src/MachineLearning.csproj | 2 +- .../tests/MachineLearningTests.csproj | 2 +- NOTICE.txt | 20 +++++++++---------- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 2 +- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 2 +- Visualization/src/Visualization.csproj | 4 ++-- global.json | 2 +- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Build/props/tests.props b/Build/props/tests.props index e14e3d4d195..d181ff7708e 100644 --- a/Build/props/tests.props +++ b/Build/props/tests.props @@ -7,7 +7,7 @@ - + diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index 17d48d5157b..91363e18937 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index baa4992beb6..75a7c4227eb 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index 6f9abc5936e..d9b9de76ad8 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index ae520453bf1..8868514fa27 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index a28ba82d009..e56d38bc059 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/NOTICE.txt b/NOTICE.txt index 739a3ab9ead..ac4b1dc0200 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -5293,7 +5293,7 @@ Copyright (c) Microsoft Corporation. --------------------------------------------------------- -Microsoft.Quantum.Compiler 0.24.201332 - MIT +Microsoft.Quantum.Compiler 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5313,7 +5313,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.CSharpGeneration 0.24.201332 - MIT +Microsoft.Quantum.CSharpGeneration 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5333,7 +5333,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.DocumentationGenerator 0.24.201332 - MIT +Microsoft.Quantum.DocumentationGenerator 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5353,7 +5353,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Core 0.24.201332 - MIT +Microsoft.Quantum.IQSharp.Core 0.24.210930 - MIT (c) by W3C @@ -5760,7 +5760,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.IQSharp.Jupyter 0.24.201332 - MIT +Microsoft.Quantum.IQSharp.Jupyter 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5780,7 +5780,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Core 0.24.201332 - MIT +Microsoft.Quantum.QSharp.Core 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5800,7 +5800,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.QSharp.Foundation 0.24.201332 - MIT +Microsoft.Quantum.QSharp.Foundation 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5820,7 +5820,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Runtime.Core 0.24.201332 - MIT +Microsoft.Quantum.Runtime.Core 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5840,7 +5840,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Simulators 0.24.201332 - MIT +Microsoft.Quantum.Simulators 0.24.210930 - MIT (c) 2008 VeriSign, Inc. @@ -5860,7 +5860,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI --------------------------------------------------------- -Microsoft.Quantum.Targets.Interfaces 0.24.201332 - MIT +Microsoft.Quantum.Targets.Interfaces 0.24.210930 - MIT (c) 2008 VeriSign, Inc. diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index 61f716e1f4e..ac3774c491f 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index 872a5aabf21..6cf9efea43e 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index 5255fac0895..42168d3257a 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index c32ab953110..bb1a8f9d1bb 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index 58851a9ec46..f41a2146392 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + diff --git a/global.json b/global.json index 93f1cbe4cac..659878fdc04 100644 --- a/global.json +++ b/global.json @@ -4,6 +4,6 @@ "rollForward": "latestMinor" }, "msbuild-sdks": { - "Microsoft.Quantum.Sdk": "0.24.201332" + "Microsoft.Quantum.Sdk": "0.24.210930" } } From 5f9ba1c5e5a9194d5f4ba440464d7a49c33553b4 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Mon, 6 Jun 2022 16:23:34 +0200 Subject: [PATCH 41/66] API review May 2022 (#584) * API review May 2022 * Apply suggestions from code review Co-authored-by: Cassandra Granade * Apply suggestions from code review * Update api-design-2022-05.md Co-authored-by: Cassandra Granade --- Design/meetings/2022/api-design-2022-05.md | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Design/meetings/2022/api-design-2022-05.md diff --git a/Design/meetings/2022/api-design-2022-05.md b/Design/meetings/2022/api-design-2022-05.md new file mode 100644 index 00000000000..3cde840925f --- /dev/null +++ b/Design/meetings/2022/api-design-2022-05.md @@ -0,0 +1,52 @@ +# Q# API Design Discussions / May 2022 + +Reviewers (in order by username): cgranade + +## Agenda + +- https://github.com/microsoft/QuantumLibraries/issues/579 +- https://github.com/microsoft/qsharp-runtime/issues/1005 +- https://github.com/microsoft/QuantumLibraries/issues/423 + +## Discussion + +### Move Exp into libraries instead of intrinsics + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/579 + +**Reviews**: +- **Approved with suggestions.** I think this makes a lot of sense; Exp is extremely useful, but it's much higher-level than any other intrinsic, making it an odd fit for the Microsoft.Quantum.Intrinsics namespace. If I understand correctly, we did so due to the full-state simulator having some nice shortcuts for simulating `Exp`, but I don't think that implementation detail justifies including `Exp` in the basic set of intrinsics. + I would suggest, however, that if we move `Exp` and make a breaking change that way, we also take the opportunity to give it a more clear name that reflects its action a bit better. In particular, `Exp` simulates evolution under a Pauli Hamiltonian such that `Microsoft.Quantum.Simulation.EvolveUnderPauli` may make sense; alternatively, it can be thought of as applying a joint rotation, perhaps justifying `Microsoft.Quantum.Canon.ApplyJointRotation`? + +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved with suggestions + +--- + +### Add MeasureEachZ operation to runtime implementation + +**Proposal**: https://github.com/microsoft/qsharp-runtime/issues/1005 + +**Reviews**: +- **Approved.** I think this is a pretty straightforward one, and works great for replacing the old `MultiM` with something more maintainable and easier to use. +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved + +--- + +### Simple and consistent arithmetic API + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/423 + +**Reviews**: + +- **Comment.** + - I'm a bit concerned that names like `GreaterThan` read like functions (noun or adjective) rather than as operations. + - How does it look to chain carry-out qubits to the `carryIn` of subsequent calls? The asymmetry that carry inputs are separate arguments while carry outputs are the MSB of LE registers feels like it could make that difficult to chain such that an example may be helpful. + - I'd personally recommend staging this together with https://github.com/microsoft/QuantumLibraries/issues/337 to minimize the number of breaking changes and to make sure that both APIs are as consistent with each other as possible. #337 in particular feels like it could be helpful in making the input data types consistent not only across arithmetic APIs but other places where arithmetic data is used in general-purpose APIs. + +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Re-schedule after addressing comments From d46f8b8d5b17885c85c4b003ca97ec06f118003c Mon Sep 17 00:00:00 2001 From: Filip W Date: Mon, 13 Jun 2022 21:40:39 +0200 Subject: [PATCH 42/66] improve diagnostics message when swapping array elements (#597) --- Standard/src/Arrays/Arrays.qs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Standard/src/Arrays/Arrays.qs b/Standard/src/Arrays/Arrays.qs index 4a5cd020812..901fccead0a 100644 --- a/Standard/src/Arrays/Arrays.qs +++ b/Standard/src/Arrays/Arrays.qs @@ -462,6 +462,8 @@ namespace Microsoft.Quantum.Arrays { /// Swapped(1, 3, [0, 1, 2, 3, 4]); /// ``` function Swapped<'T>(firstIndex : Int, secondIndex : Int, arr : 'T[]) : 'T[] { + Fact(firstIndex >= 0 and firstIndex < Length(arr), "First index is out of bounds"); + Fact(secondIndex >= 0 and secondIndex < Length(arr), "Second index is out of bounds"); return arr w/ firstIndex <- arr[secondIndex] w/ secondIndex <- arr[firstIndex]; From 2117bf285078735516f3cb238ebcbfdc37e6bcf4 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Tue, 5 Jul 2022 18:07:45 +0200 Subject: [PATCH 43/66] Improves MultiplexOperations implementation (#599) * Resource estimation tests. * Improved implementation. * Ergonomic changes. --- Standard/src/Canon/Utils/Multiplexer.qs | 181 +++++++++--------- .../tests/Canon/Utils/MultiplexerTests.cs | 32 ++++ Standard/tests/MultiplexerTests.qs | 11 ++ 3 files changed, 138 insertions(+), 86 deletions(-) create mode 100644 Standard/tests/Canon/Utils/MultiplexerTests.cs diff --git a/Standard/src/Canon/Utils/Multiplexer.qs b/Standard/src/Canon/Utils/Multiplexer.qs index 7d1a8366da2..83e4ea97ea5 100644 --- a/Standard/src/Canon/Utils/Multiplexer.qs +++ b/Standard/src/Canon/Utils/Multiplexer.qs @@ -3,8 +3,10 @@ namespace Microsoft.Quantum.Canon { open Microsoft.Quantum.Arithmetic; - open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Math; /// # Summary @@ -92,16 +94,16 @@ namespace Microsoft.Quantum.Canon { /// - Microsoft.Quantum.Canon.MultiplexPauli operation ApproximatelyMultiplexPauli(tolerance : Double, coefficients : Double[], pauli : Pauli, control : LittleEndian, target : Qubit) : Unit is Adj + Ctl { - if (pauli == PauliZ) { + if pauli == PauliZ { let op = ApproximatelyMultiplexZ(tolerance, coefficients, control, _); op(target); - } elif (pauli == PauliX) { + } elif pauli == PauliX { let op = ApproximatelyMultiplexPauli(tolerance, coefficients, PauliZ, control, _); ApplyWithCA(H, op, target); - } elif (pauli == PauliY) { + } elif pauli == PauliY { let op = ApproximatelyMultiplexPauli(tolerance, coefficients, PauliX, control, _); ApplyWithCA(Adjoint S, op, target); - } elif (pauli == PauliI) { + } elif pauli == PauliI { ApproximatelyApplyDiagonalUnitary(tolerance, coefficients, control); } else { fail $"MultiplexPauli failed. Invalid pauli {pauli}."; @@ -155,7 +157,7 @@ namespace Microsoft.Quantum.Canon { // NB: We don't currently use Any / Mapped for this, as we want to be // able to short-circuit. for coefficient in coefficients { - if (AbsD(coefficient) >= tolerance) { + if AbsD(coefficient) >= tolerance { return true; } } @@ -164,7 +166,7 @@ namespace Microsoft.Quantum.Canon { internal function AnyOutsideToleranceCP(tolerance : Double, coefficients : ComplexPolar[]) : Bool { for coefficient in coefficients { - if (AbsComplexPolar(coefficient) > tolerance) { + if AbsComplexPolar(coefficient) > tolerance { return true; } } @@ -218,20 +220,20 @@ namespace Microsoft.Quantum.Canon { // pad coefficients length at tail to a power of 2. let coefficientsPadded = Padded(-2 ^ Length(control!), 0.0, coefficients); - if (Length(coefficientsPadded) == 1) { + if Length(coefficientsPadded) == 1 { // Termination case - if (AbsD(coefficientsPadded[0]) > tolerance) { + if AbsD(coefficientsPadded[0]) > tolerance { Exp([PauliZ], coefficientsPadded[0], [target]); } } else { // Compute new coefficients. let (coefficients0, coefficients1) = MultiplexZCoefficients(coefficientsPadded); - ApproximatelyMultiplexZ(tolerance,coefficients0, LittleEndian((control!)[0 .. Length(control!) - 2]), target); - if (AnyOutsideToleranceD(tolerance, coefficients1)) { + ApproximatelyMultiplexZ(tolerance, coefficients0, LittleEndian(Most(control!)), target); + if AnyOutsideToleranceD(tolerance, coefficients1) { within { - CNOT((control!)[Length(control!) - 1], target); + CNOT(Tail(control!), target); } apply { - ApproximatelyMultiplexZ(tolerance,coefficients1, LittleEndian((control!)[0 .. Length(control!) - 2]), target); + ApproximatelyMultiplexZ(tolerance,coefficients1, LittleEndian(Most(control!)), target); } } } @@ -242,7 +244,7 @@ namespace Microsoft.Quantum.Canon { let coefficientsPadded = Padded(2 ^ (Length(control!) + 1), 0.0, Padded(-2 ^ Length(control!), 0.0, coefficients)); let (coefficients0, coefficients1) = MultiplexZCoefficients(coefficientsPadded); ApproximatelyMultiplexZ(tolerance,coefficients0, control, target); - if (AnyOutsideToleranceD(tolerance,coefficients1)) { + if AnyOutsideToleranceD(tolerance,coefficients1) { within { Controlled X(controlRegister, target); } apply { @@ -331,7 +333,7 @@ namespace Microsoft.Quantum.Canon { /// - Microsoft.Quantum.Canon.ApplyDiagonalUnitary operation ApproximatelyApplyDiagonalUnitary(tolerance : Double, coefficients : Double[], qubits : LittleEndian) : Unit is Adj + Ctl { - if (IsEmpty(qubits!)) { + if IsEmpty(qubits!) { fail "operation ApplyDiagonalUnitary -- Number of qubits must be greater than 0."; } @@ -340,11 +342,11 @@ namespace Microsoft.Quantum.Canon { // Compute new coefficients. let (coefficients0, coefficients1) = MultiplexZCoefficients(coefficientsPadded); - ApproximatelyMultiplexZ(tolerance,coefficients1, LittleEndian((qubits!)[0 .. Length(qubits!) - 2]), (qubits!)[Length(qubits!) - 1]); + ApproximatelyMultiplexZ(tolerance,coefficients1, LittleEndian(Most(qubits!)), Tail(qubits!)); - if (Length(coefficientsPadded) == 2) { + if Length(coefficientsPadded) == 2 { // Termination case - if (AbsD(coefficients0[0]) > tolerance) { + if AbsD(coefficients0[0]) > tolerance { Exp([PauliI], 1.0 * coefficients0[0], qubits!); } } else { @@ -389,88 +391,95 @@ namespace Microsoft.Quantum.Canon { /// ## target /// Generic qubit register that $V_j$ acts on. /// - /// # Remarks - /// `coefficients` will be padded with identity elements if - /// fewer than $2^n$ are specified. This implementation uses - /// $n - 1$ auxiliary qubits. - /// /// # References - /// - Toward the first quantum simulation with quantum speedup - /// Andrew M. Childs, Dmitri Maslov, Yunseong Nam, Neil J. Ross, Yuan Su - /// https://arxiv.org/abs/1711.10980 - operation MultiplexOperations<'T> (unitaries : ('T => Unit is Adj + Ctl)[], index : LittleEndian, target : 'T) + /// - Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity + /// Ryan Babbush, Craig Gidney, Dominic W. Berry, Nathan Wiebe, Jarrod McClean, Alexandru Paler, Austin Fowler, Hartmut Neven + /// https://arxiv.org/abs/1805.03662 + operation MultiplexOperations<'T>(unitaries : ('T => Unit is Adj + Ctl)[], index : LittleEndian, target : 'T) : Unit is Adj + Ctl { - if (Length(index!) == 0) { - fail $"MultiplexOperations failed. Number of index qubits must be greater than 0."; - } + body (...) { + let (N, n) = DimensionsForMultiplexer(Length(unitaries), index); + + if N == 1 { // base case + Head(unitaries)(target); + } else { + let (most, tail) = MostAndTail(index![...n - 1]); + let parts = Partitioned([2^(n - 1)], unitaries); + + within { + X(tail); + } apply { + Controlled MultiplexOperations([tail], (parts[0], LittleEndian(most), target)); + } - if (Length(unitaries) > 0) { - let auxillaryRegister = []; - MultiplexOperationsWithAuxRegister(unitaries, auxillaryRegister, index, target); + Controlled MultiplexOperations([tail], (parts[1], LittleEndian(most), target)); + } } - } - /// # Summary - /// Implementation step of MultiplexOperations. - /// # See Also - /// - Microsoft.Quantum.Canon.MultiplexOperations - internal operation MultiplexOperationsWithAuxRegister<'T>( - unitaries : ('T => Unit is Adj + Ctl)[], - auxillaryRegister : Qubit[], - index : LittleEndian, - target : 'T - ) - : Unit is Adj + Ctl { - body (...) { - let nIndex = Length(index!); - let nStates = 2 ^ nIndex; - let nUnitaries = Length(unitaries); - let nUnitariesRight = MinI(nUnitaries, nStates / 2); - let nUnitariesLeft = MinI(nUnitaries, nStates); - let rightUnitaries = unitaries[0 .. nUnitariesRight - 1]; - let leftUnitaries = unitaries[nUnitariesRight .. nUnitariesLeft - 1]; - let newControls = LittleEndian((index!)[0 .. nIndex - 2]); - - if (nUnitaries > 0) { - if (Length(auxillaryRegister) == 1 and nIndex == 0) { - // Termination case - Controlled unitaries[0](auxillaryRegister, target); - } elif (Length(auxillaryRegister) == 0 and nIndex >= 1) { - // Start case - let newAuxQubit = Tail(index!); - - if (nUnitariesLeft > 0) { - MultiplexOperationsWithAuxRegister(leftUnitaries, [newAuxQubit], newControls, target); - } + controlled (ctls, ...) { + let nCtls = Length(ctls); - within { - X(newAuxQubit); - } apply { - MultiplexOperationsWithAuxRegister(rightUnitaries, [newAuxQubit], newControls, target); - } + if nCtls == 0 { + MultiplexOperations(unitaries, index, target); + } elif nCtls == 1 { + let (N, n) = DimensionsForMultiplexer(Length(unitaries), index); + + let ctl = Head(ctls); + + if N == 1 { // base case + Controlled (Head(unitaries))(ctls, target); } else { - // Recursion that reduces nIndex by 1 & sets Length(auxillaryRegister) to 1. - use newAuxQubit = Qubit(); + use helper = Qubit(); + + let (most, tail) = MostAndTail(index![...n - 1]); + let parts = Partitioned([2^(n - 1)], unitaries); + within { - Controlled X(auxillaryRegister + [(index!)[Length(index!) - 1]], newAuxQubit); + X(tail); } apply { - if (nUnitariesLeft > 0) { - MultiplexOperationsWithAuxRegister(leftUnitaries, [newAuxQubit], newControls, target); - } - - within { - Controlled X(auxillaryRegister, newAuxQubit); - } apply { - MultiplexOperationsWithAuxRegister(rightUnitaries, [newAuxQubit], newControls, target); - } + ApplyAnd(ctl, tail, helper); } + + Controlled MultiplexOperations([helper], (parts[0], LittleEndian(most), target)); + + CNOT(ctl, helper); + + Controlled MultiplexOperations([helper], (parts[1], LittleEndian(most), target)); + + Adjoint ApplyAnd(ctl, tail, helper); + } + } else { + use helper = Qubit(); + within { + Controlled X(ctls, helper); + } apply { + Controlled MultiplexOperations([helper], (unitaries, index, target)); } } } + } - controlled (controlRegister, ...) { - MultiplexOperationsWithAuxRegister(unitaries, controlRegister, index, target); - } + /// # Summary + /// Validates and adjusts dimensions for address register + /// + /// # Description + /// Given $N$ unitaries in `numUnitaries` and an address register of length $n'$, + /// this function first checks whether $N \neq 0$ and $\lceil\log_2 N\rceil = n \le n'$, + /// and then returns the tuple $(N, n)$. + /// + /// # Input + /// ## numUnitaries + /// The number of unitaries to multiplex. + /// ## address + /// The address register. + internal function DimensionsForMultiplexer(numUnitaries : Int, address : LittleEndian) : (Int, Int) { + let N = numUnitaries; + Fact(N > 0, "data cannot be empty"); + + let n = Ceiling(Lg(IntAsDouble(N))); + Fact(Length(address!) >= n, $"address register is too small, requires at least {n} qubits"); + + return (N, n); } } diff --git a/Standard/tests/Canon/Utils/MultiplexerTests.cs b/Standard/tests/Canon/Utils/MultiplexerTests.cs new file mode 100644 index 00000000000..05338c1acf7 --- /dev/null +++ b/Standard/tests/Canon/Utils/MultiplexerTests.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + + +using Microsoft.Quantum.Simulation.Simulators; +using Xunit; + +namespace Microsoft.Quantum.Tests +{ + public class MultiplexerTests + { + [Fact] + public void TestMultiplexerResources() + { + foreach (var (numControls, expectedTCount, expectedWidth) in new [] { + (1, 0, 6), + (2, 8, 8), + (3, 24, 10), + (4, 56, 12), + (5, 120, 14), + (6, 248, 16) + }) { + var estimator = new ResourcesEstimator(); + EstimateMultiplexOperationsCosts.Run(estimator, numControls, 1 << numControls).Wait(); + var tcount = (double)estimator.Data.Rows.Find("T")[1]; + var width = (double)estimator.Data.Rows.Find("Width")[1]; + Assert.Equal(expectedTCount, tcount); + Assert.Equal(expectedWidth, width); + } + } + } +} diff --git a/Standard/tests/MultiplexerTests.qs b/Standard/tests/MultiplexerTests.qs index acb5df2d7d6..692837fa02a 100644 --- a/Standard/tests/MultiplexerTests.qs +++ b/Standard/tests/MultiplexerTests.qs @@ -497,6 +497,17 @@ namespace Microsoft.Quantum.Tests { } } + internal operation EstimateMultiplexOperationsCosts(numControls : Int, numData : Int) : Unit { + Diag.Fact(numData <= 2^numControls, "Too few address bits"); + + use address = Qubit[numControls]; + use target = Qubit[5]; + + let unitaries = [ApplyPauliFromBitString(PauliX, true, [true, size = 5], _), size = numData]; + + MultiplexOperations(unitaries, LittleEndian(address), target); + } + } From 34964117ba2991974deb04fdd309b99a1dc7075b Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Thu, 7 Jul 2022 09:54:53 +0200 Subject: [PATCH 44/66] API review June 2022 (#596) * API review June 2022 * Apply suggestions from code review Co-authored-by: Mariia Mykhailova * Apply suggestions from code review Co-authored-by: Cassandra Granade * Apply suggestions from code review Co-authored-by: Mariia Mykhailova Co-authored-by: Cassandra Granade --- Design/meetings/2022/api-design-2022-06.md | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Design/meetings/2022/api-design-2022-06.md diff --git a/Design/meetings/2022/api-design-2022-06.md b/Design/meetings/2022/api-design-2022-06.md new file mode 100644 index 00000000000..3e390a9dbb9 --- /dev/null +++ b/Design/meetings/2022/api-design-2022-06.md @@ -0,0 +1,47 @@ +# Q# API Design Discussions / June 2022 + +Reviewers (in order by username): @tcNickolas, @cgranade + +## Agenda + +- https://github.com/microsoft/QuantumLibraries/issues/593 +- https://github.com/microsoft/QuantumLibraries/issues/594 +- https://github.com/microsoft/QuantumLibraries/issues/595 + +## Discussion + +### Comparison operations + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/593 + +**Reviews**: +- @cgranade, *comment*: Does the `action` input to `ApplyControlledOnLessThanFxP` need to be adjointable? Should there be a separate `Adj` variant? We may also want to describe quickly how this proposal works with the outstanding proposal for numerics refactoring all-up (https://github.com/microsoft/QuantumLibraries/issues/337). +* @tcNickolas, *approve*, left a comment +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: *approve* subject to comments to be addressed in the issue, discussion will be deferred to issue. + +--- + +### Functions for smallest and largest representable fixed point + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/594 + +**Reviews**: @cgranade, *approve*, same comment as above (https://github.com/microsoft/QuantumLibraries/issues/337). +* @tcNickolas, *approve*, left a comment +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: *approve* + +--- + +### Conversion functions for signed integers + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/595 + +**Reviews**: +* @cgranade: *comment*. We should coordinate this with the Q# language discussion around bit vectors in general. @swernli and @bettinaheim in particular may want to provide input here. +* @tcNickolas, *approve*, left a comment +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: *approve* subject to comments to be addressed in the issue, discussion will be deferred to issue. From 131a8e7b4463fefeaecbe41c76d5819c87b7b48c Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Mon, 18 Jul 2022 03:04:36 +0200 Subject: [PATCH 45/66] Add functions for smallest and largest representable fixed point (#606) * Add functions for smallest and largest representable fixed point Implements #594 * New line. * Apply suggestions from code review Co-authored-by: Mariia Mykhailova Co-authored-by: Mariia Mykhailova --- Numerics/src/FixedPoint/Math.qs | 38 +++++++++++++++++++++++++++++++ Numerics/tests/FixedPointTests.qs | 12 ++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Numerics/src/FixedPoint/Math.qs diff --git a/Numerics/src/FixedPoint/Math.qs b/Numerics/src/FixedPoint/Math.qs new file mode 100644 index 00000000000..32327a22339 --- /dev/null +++ b/Numerics/src/FixedPoint/Math.qs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Math { + open Microsoft.Quantum.Convert; + + /// # Summary + /// Returns the smallest representable number for specific fixed point dimensions. + /// + /// # Input + /// ## integerBits + /// Number of integer bits (including the sign bit). + /// ## fractionalBits + /// Number of fractional bits. + /// + /// # Remark + /// The value can be computed as $-2^{p-1}$, where $p$ is the number of integer bits. + function SmallestFixedPoint(integerBits : Int, fractionalBits : Int) : Double { + return -PowD(2.0, IntAsDouble(integerBits - 1)); + } + + /// # Summary + /// Returns the largest representable number for specific fixed point dimensions. + /// + /// # Input + /// ## integerBits + /// Number of integer bits (including the sign bit). + /// ## fractionalBits + /// Number of fractional bits. + /// + /// # Remark + /// The value can be computed as $2^{p-1} - 2^{-q}$, where $p$ + /// is the number of integer bits and $q$ is the number of fractional bits. + function LargestFixedPoint(integerBits : Int, fractionalBits : Int) : Double { + return PowD(2.0, IntAsDouble(integerBits - 1)) - PowD(2.0, -IntAsDouble(fractionalBits)); + } + +} diff --git a/Numerics/tests/FixedPointTests.qs b/Numerics/tests/FixedPointTests.qs index 48e774997cb..d32596e41f9 100644 --- a/Numerics/tests/FixedPointTests.qs +++ b/Numerics/tests/FixedPointTests.qs @@ -435,4 +435,16 @@ namespace Microsoft.Quantum.Tests { } } } + + @Test("QuantumSimulator") + operation TestFixedPointLimits() : Unit { + for numBits in 1..6 { + for integerBits in 0..numBits { + let fractionalBits = numBits - integerBits; + + NearEqualityFactD(SmallestFixedPoint(integerBits, fractionalBits), BoolArrayAsFixedPoint(integerBits, [false, size = numBits] w/ numBits - 1 <- true)); + NearEqualityFactD(LargestFixedPoint(integerBits, fractionalBits), BoolArrayAsFixedPoint(integerBits, [true, size = numBits] w/ numBits - 1 <- false)); + } + } + } } From 0ac7ac1370f1610b865c3e6f5d8d7cc436ebc93a Mon Sep 17 00:00:00 2001 From: Adrian Lehmann <26521502+adrianleh@users.noreply.github.com> Date: Wed, 20 Jul 2022 10:59:27 -0500 Subject: [PATCH 46/66] ApplyWindowed (#603) * Add ApplyWindowed operation Applies an operation windowing over input but with const target qubits * Simplify ApplyWindowed * Update ApplyWindowed to be more idiomatic See comment on #602 by @cgranade * Fix documentation style issues for ApplyWindowed * Improve ApplyWindowed documentation and add example * Change name of ApplyWindowed to ApplyToEachWindow * Fix example being in code block Co-authored-by: Mariia Mykhailova Co-authored-by: Mathias Soeken Co-authored-by: Mariia Mykhailova --- Standard/src/Arrays/Windows.qs | 90 ++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/Standard/src/Arrays/Windows.qs b/Standard/src/Arrays/Windows.qs index 34837baae6f..2c696ad9f4e 100644 --- a/Standard/src/Arrays/Windows.qs +++ b/Standard/src/Arrays/Windows.qs @@ -2,6 +2,7 @@ // Licensed under the MIT License. namespace Microsoft.Quantum.Arrays { + open Microsoft.Quantum.Canon; /// # Summary /// Returns all consecutive subarrays of length `size`. @@ -73,4 +74,93 @@ namespace Microsoft.Quantum.Arrays { internal function Prefix<'T>(to : Int, array : 'T[]) : 'T[] { return array[0..to]; } + + /// # Summary + /// Applies an operation windowing over an input register. + /// + /// # Input + /// ## windowLen + /// The size of each window. + /// ## op + /// An operation on a register that will be provided with the current window and its index. + /// ## register + /// The register the operation windows over. + /// + /// # Example + /// The example below shows how to use `ApplyToEachWindow` to construct a parity function + /// ```qsharp + /// operation Parity(qubits : Qubit[], target : Qubit) : Unit { + /// ApplyToEachWindow(1, (_, q) => CNOT(q[0], target), qubits); + /// } + /// ``` + /// + /// # Type Parameters + /// ## 'T + /// The type of register elements. + operation ApplyToEachWindow<'T>(windowLen : Int, op : (Int, 'T[]) => Unit, register : 'T[]) : Unit { + ApplyToEach(op, Enumerated(Windows(windowLen, register))); + } + + /// # Summary + /// Applies an operation windowing over an input register. The modifier `A` indicates that the single-qubit operation is adjointable. + /// + /// # Input + /// ## windowLen + /// The size of each window. + /// ## op + /// An operation on a register that will be provided with the current window and its index. + /// ## register + /// The register the operation windows over. + //// + /// # Type Parameters + /// ## 'T + /// The type of register elements. + /// + /// # See Also + /// - Microsoft.Quantum.Arrays.ApplyToEachWindow + operation ApplyToEachWindowA<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Adj, register : 'T[]) : Unit is Adj { + ApplyToEachA(op, Enumerated(Windows(windowLen, register))); + } + + /// # Summary + /// Applies an operation windowing over an input register. The modifier `C` indicates that the single-qubit operation is controllable. + /// + /// # Input + /// ## windowLen + /// The size of each window. + /// ## op + /// An operation on a register that will be provided with the current window and its index. + /// ## register + /// The register the operation windows over. + //// + /// # Type Parameters + /// ## 'T + /// The type of register elements. + /// + /// # See Also + /// - Microsoft.Quantum.Arrays.ApplyToEachWindow + operation ApplyToEachWindowC<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Ctl, register : 'T[]) : Unit is Ctl { + ApplyToEachC(op, Enumerated(Windows(windowLen, register))); + } + + /// # Summary + /// Applies an operation windowing over an input register. The modifier `CA` indicates that the single-qubit operation is controllable and adjointable. + /// + /// # Input + /// ## windowLen + /// The size of each window. + /// ## op + /// An operation on a register that will be provided with the current window and its index. + /// ## register + /// The register the operation windows over. + //// + /// # Type Parameters + /// ## 'T + /// The type of register elements. + /// + /// # See Also + /// - Microsoft.Quantum.Arrays.ApplyToEachWindow + operation ApplyToEachWindowCA<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Adj + Ctl, register : 'T[]) : Unit is Adj + Ctl { + ApplyToEachCA(op, Enumerated(Windows(windowLen, register))); + } } From 3f661797f040f85d092a304d37729e75f2b76485 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Wed, 27 Jul 2022 16:03:14 -0700 Subject: [PATCH 47/66] Updating QDK version to 0.25.222597. (#609) --- Build/props/tests.props | 2 +- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- Chemistry/tests/ChemistryTests/QSharpTests.csproj | 2 +- Chemistry/tests/SystemTests/SystemTests.csproj | 2 +- MachineLearning/src/MachineLearning.csproj | 2 +- MachineLearning/tests/MachineLearningTests.csproj | 2 +- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 2 +- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 2 +- Visualization/src/Visualization.csproj | 4 ++-- global.json | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Build/props/tests.props b/Build/props/tests.props index d181ff7708e..0c1857d11f0 100644 --- a/Build/props/tests.props +++ b/Build/props/tests.props @@ -7,7 +7,7 @@ - + diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index 91363e18937..c96b57bd353 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index 75a7c4227eb..c894e694b5c 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index d9b9de76ad8..28ee132073d 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index 8868514fa27..1328cd228b9 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index e56d38bc059..9fb245ab0fd 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index ac3774c491f..7834b95127c 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index 6cf9efea43e..677cb9a1d81 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index 42168d3257a..da274692ef2 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index bb1a8f9d1bb..5cc44825bd1 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index f41a2146392..bcac36a31ec 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + diff --git a/global.json b/global.json index 659878fdc04..172cc360c51 100644 --- a/global.json +++ b/global.json @@ -4,6 +4,6 @@ "rollForward": "latestMinor" }, "msbuild-sdks": { - "Microsoft.Quantum.Sdk": "0.24.210930" + "Microsoft.Quantum.Sdk": "0.25.222597" } } From 59438bfe6acbadcf616442a27eaad0e437a1062c Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Fri, 19 Aug 2022 11:04:59 +0200 Subject: [PATCH 48/66] API review July 2022 (#608) * API review July 2022 * Apply suggestions from code review Co-authored-by: Mariia Mykhailova * Apply suggestions from code review * Apply suggestions from code review * Update api-design-2022-07.md * Update api-design-2022-07.md Co-authored-by: Mariia Mykhailova --- Design/meetings/2022/api-design-2022-07.md | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Design/meetings/2022/api-design-2022-07.md diff --git a/Design/meetings/2022/api-design-2022-07.md b/Design/meetings/2022/api-design-2022-07.md new file mode 100644 index 00000000000..1f4c665c1df --- /dev/null +++ b/Design/meetings/2022/api-design-2022-07.md @@ -0,0 +1,60 @@ +# Q# API Design Discussions / July 2022 + +Reviewers (in order by username): @tcNickolas, @msoeken, @cgranade + +## Agenda + +- https://github.com/microsoft/QuantumLibraries/issues/598 +- https://github.com/microsoft/QuantumLibraries/issues/601 +- https://github.com/microsoft/QuantumLibraries/issues/602 +- https://github.com/microsoft/QuantumLibraries/issues/607 + +## Discussion + +### Fixed point truncation + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/598 + +**Reviews**: +* @tcNickolas, *approve*, left a comment +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved + +--- + +### Table lookup + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/601 + +**Reviews**: +* @tcNickolas, *approve*, left comments +* @msoeken, *approve*, left comments +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Postponed, requires more discussion + +--- + +### Windowed unitary application + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/602 + +**Reviews**: +* @tcNickolas, *approve* +* @msoeken, *approve*, left comments +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. + +**Consensus**: Approved as `ApplyToEachWindow` without `argumentTransform`, without `target` argument, with type parameter for input array, and with all 4 functor variants. + +--- + +### New operation: Apply arithmetic function via table lookup + +**Proposal**: https://github.com/microsoft/QuantumLibraries/issues/607 + +**Reviews**: +> Please add a bullet point including your alias, your review result (*approve*, *reject*, *comment*), and a comment (optional when result is *approve*). Alternatively, add a line to the PR discussion incl. a reference to this issue. +* @msoeken, *approve*, left comments + +**Consensus**: Approved after comments From 2991f67eb0ca406080ca743966c7090d3b3d3162 Mon Sep 17 00:00:00 2001 From: Rajiv Krishnakumar Date: Tue, 23 Aug 2022 08:30:33 +0200 Subject: [PATCH 49/66] lookup table code (#611) * lookup table code * Update Numerics/tests/LookupTableTests.qs Co-authored-by: Mathias Soeken * Update Numerics/src/FixedPoint/LookupTable.qs Co-authored-by: Mathias Soeken * Update Numerics/src/FixedPoint/LookupTable.qs Co-authored-by: Mathias Soeken * Update Numerics/src/FixedPoint/LookupTable.qs Co-authored-by: Mathias Soeken * Update Numerics/tests/LookupTableTests.qs Co-authored-by: Mathias Soeken * Update Numerics/tests/LookupTableTests.qs Co-authored-by: Mathias Soeken * Update Numerics/tests/LookupTableTests.qs Co-authored-by: Mathias Soeken * Update Numerics/src/FixedPoint/LookupTable.qs Co-authored-by: Mathias Soeken * Update Numerics/src/FixedPoint/LookupTable.qs Co-authored-by: Mathias Soeken * Update Numerics/src/FixedPoint/LookupTable.qs Co-authored-by: Mathias Soeken * Update Numerics/tests/LookupTableTests.qs Co-authored-by: Mathias Soeken * Moved potential efficiency comments Moved potential efficiency comments of fanning out control qubits from summary to inside the code * Split summary into summary and remarks Split original summary to summary and remarks * Added latex formatting * Update Numerics/src/FixedPoint/LookupTable.qs * Update Numerics/tests/LookupTableTests.qs Co-authored-by: Krishnakumar, Rajiv [Engineering] Co-authored-by: Mathias Soeken Co-authored-by: Mathias Soeken --- Numerics/src/FixedPoint/LookupTable.qs | 365 +++++++++++++++++++++++++ Numerics/tests/LookupTableTests.qs | 96 +++++++ 2 files changed, 461 insertions(+) create mode 100755 Numerics/src/FixedPoint/LookupTable.qs create mode 100755 Numerics/tests/LookupTableTests.qs diff --git a/Numerics/src/FixedPoint/LookupTable.qs b/Numerics/src/FixedPoint/LookupTable.qs new file mode 100755 index 00000000000..9a4024d1c3d --- /dev/null +++ b/Numerics/src/FixedPoint/LookupTable.qs @@ -0,0 +1,365 @@ +namespace Microsoft.Quantum.Arithmetic { + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Math; + + /// # Summary + /// The return type when making a lookup table. This contains the operation that + /// makes the lookup table circuit, as well as all the parameters required to make + /// the two FixedPoint registers that need to be used as inputs and outputs to the + /// operator. + /// + /// # Remarks + /// The reason we have this return type structure is so that the operator is similar + /// to the other typical Q# arithmetic function implementations (a larger discussion + /// can had as to whether that can be changed) + newtype FunctionWithLookupTable = ( + IntegerBitsIn: Int, + FractionalBitsIn: Int, + IntegerBitsOut: Int, + FractionalBitsOut: Int, + Apply: (FixedPoint, FixedPoint) => Unit is Adj + ); + + /// # Summary + /// This function creates a select-swap lookup table operator for the function that you want to approximate, as well as + /// the parameters required to make the two FixedPoint registers that need to be used as inputs to the operator. + /// This is so that it is in similar to the other typical Q# arithmetic function (a larger discussion can be had + /// as to whether that can be changed). The circuit for the operator can be found in Fig. 1c in arXiv:1812.00954. + /// + /// # Remarks + /// The operator guarantees that given an input value $x$ and a function $f(x)$, + /// it will compute $\hat{f}(\hat{x})$ where $\hat{f}$ is an approximation of $f$ with a maximum error of epsOut and $\hat{x}$ is an + /// approximation of the input value $\hat{x}$ with a maximum error of epsIn. This is useful for most reasonably behaved + /// functions, but note that it computes $\hat{f}(\hat{x})$ and not $\hat{f}(x)$ so if the domain function is very oscillatory and/or + /// has funky derivatives then it may have high errors. + /// + /// # Input + /// ## func + /// The Q# arithmetic function that you want to implement with the lookup table + /// ## domain + /// A tuple consisting of the minimum and maximum values of the input values to the function + /// ## epsIn + /// The maximum allowed error of the input value to the computation (i.e. |x'-x|) + /// ## epsOut + /// The maximum allowed error of the output without taking into account the error in input value (i.e. |f'(x')-f(x')|) + /// ## numSwapBits + /// The number of bits of the input register that will be used in the SWAP section of the circuits. Another way of looking + /// at this is that in step in the SELECT section of the circuit in Fig 1c of arXiv:1812.00954, we will encode 2^numSwapBits + /// encoded + /// + /// # Example + /// The following code creates a quantum operation based on `ExpD` in the (inclusive) range from `-5.0` to `5.0` with an input error of `1e-3` and an output error of `1e-4`. It uses `2` SWAP bits for the implementation. + /// + /// ```qsharp + /// // Create operation from lookup table + /// let domain = (-5.0, 5.0); + /// let epsIn = 1e-3; + /// let epsOut = 1e-4; + /// + /// let lookup = ApplyFunctionWithLookupTable(ExpD, domain, epsIn, epsOut, 2); + /// + /// // Allocate qubits + /// use input = Qubit[lookup::IntegerBitsIn + lookup::FractionalBitsIn]; + /// use output = Qubit[lookup::IntegerBitsOut + lookup::FractionalBitsOut]; + /// + /// // Represent qubit registers as fixed points + /// let inputFxP = FixedPoint(lookup::IntegerBitsIn, input); + /// let outputFxP = FixedPoint(lookup::IntegerBitsOut, output); + /// + /// // Apply operation + /// lookup::Apply(inputFxP, outputFxP); + /// ``` + function ApplyFunctionWithLookupTable(func: Double -> Double, domain: (Double, Double), epsIn: Double, epsOut: Double, numSwapBits: Int): FunctionWithLookupTable { + + // First step is to find the number of integer bits (pIn) and fractional bits (qIn) required for the input based on the + // domain and error tolerance (espIn). To find the value of pIn, we have to check both the + // lower and upper bound of the domain to see which one requires more bits, then assign the larger one as pIn. + // To find qIn we compute minimum number of fractional bits required to represent epsIn. + let (minIn, maxIn) = domain; + + let pLower = BitSizeI(Ceiling(AbsD(minIn))); + let pUpper = BitSizeI(Ceiling(AbsD(maxIn))); + let pIn = MaxI(pLower, pUpper) + 1; // The +1 is for the sign bit + + let qIn = Ceiling(Lg(1.0/epsIn)); + + // We have now computed the number of integer and fractional bits required for the input of our lookup table. Next we compute + // The output number of integer and fractional bits required. For the number of fractional bits (qOut), we can + // simply look at the minimum number of bits required to represent epsOut + let qOut = Ceiling(Lg(1.0/epsOut)); + + + // For the number of integer bits required for the output, we have to iterate through all the possible values of the function + // and find the one with the largest absolute value. For that we first create the fixed point approximations of minIn and maxIn + // given epsIn (using the previously computed pIn and qIn). Then we compute how many different input values (numValues) are there between + // minIn and maxIn (given our number of input qubits). And finally we evaluate the function at all those values to get the number with + // the largest absolute value + + // Compute approximations of minIn and maxIn + let minInFxP = DoubleAsFixedPoint(pIn, qIn, minIn); + let maxInFxP = DoubleAsFixedPoint(pIn, qIn, maxIn); + + // Compute number of values in between minIn and maxIn + let deltaIn = 1.0/PowD(2.0, IntAsDouble(qIn)); + let numValues = Truncate((maxInFxP - minInFxP) / deltaIn) + 1; + + // Go through each value, compute the number of integer bits required, and update pOut if it's bigger than + // current pOut. We also store the output values since we will be using them when creating the output part of the + // lookup table circuit + mutable outValues = [0.0, size=numValues]; // List to store all the output values (initialized at all 0s) + mutable inValueFxP = minInFxP; // Starting input value + mutable pOut = 0; // Set initial pOut value which will be updated in loop below + for i in 0..numValues-1 { + // First a quick check to see that the enumaration is going correctly, i.e. that we are hitting all the values in order + let inAddress = BoolArrayAsInt(FixedPointAsBoolArray(pIn, qIn, inValueFxP - minInFxP)); + EqualityFactI(inAddress, i, $"Unexpected address in enumeration"); + + // Now we compute the output value, compute the number of integer bits it has and see if it is bigger than our current pOut + let outValue = func(inValueFxP); + set outValues w/= i <- outValue; // this is the syntax to say "outValues = outValues but with the ith index as outValue" + set pOut = MaxI(pOut, BitSizeI(Ceiling(AbsD(outValue)))+1); //the +1 is for the sign bit + set inValueFxP += deltaIn; + } + + //So we have now computed the number of integer bits for the output values. Now all that's left is to make the circuit! + + // We first create a list of FixedPoints with all the outValues + let outValuesFxP = Mapped(DoubleAsFixedPoint(pOut, qOut, _), outValues); + + // Next we map outValuesFP to bitstrings + let outBits = Mapped(FixedPointAsBoolArray(pOut, qOut, _), outValues); + // Message($"{outBits}"); + + // Now we use the fixed point approximation of the minimum value of the input + // and the list of output bit values to make the operation lookupOperation: (FixedPoint, FixedPoint) => Unit + // More comments on how that's done in within the function + let lookupOperation = LookupOperationWrapper(minInFxP, outBits, numSwapBits, _, _); + + + return FunctionWithLookupTable( + pIn, qIn, + pOut, qOut, + lookupOperation + ); + } + + /// # Summary + /// Creates a lookup table operation. This operation will require the minimum input value as a FixedPoint register, + /// the list of output values in bits,the FixedPoint register with the input value and the FixedPoint register that + /// will store the output value. Note that this imples that the bit size requirement of these registers are pre-computed + /// beforehand + /// + /// # Input + /// ## minInFxp + /// The minimum possible value of the input to the lookup table + /// ## outBits + /// The list of output values in bits in order, where the first value is the output for the smallest input value and + /// the last value is the output for the largest input value + /// ## numSwapBits + /// The number of bits of the input register that will be used in the SWAP section of the circuits. Another way of looking + /// at this is that in step in the SELECT section of the circuit in Fig 1c of arXiv:1812.00954, we will encode 2^numSawpBits + /// encoded + /// ## input + /// Qubit FixedPoint register containing input values + /// ## output + /// Qubit FixedPoint register containing where output values will be stored + internal operation LookupOperationWrapper(minInFxP: Double, outBits: Bool[][], numSwapBits : Int, input: FixedPoint, output: FixedPoint) : Unit is Adj { + + let integerBitsIn = input::IntegerBits; + let registerIn = input::Register; + let fractionalBitsIn = Length(registerIn) - integerBitsIn; + + // We are now creating the lookup table. If the smallest value (i.e. minInFxP) happens to be 0, then we can just use + // the Select operation which implements the lookup table in ##. However, if the minimum value is not 0, then we want to first subtract + // it, because the lookup table always assumes that the miminum value is 00...0 and the maximum value is 11...1 in incrementing order, + // so we are re-defining the minimum number as represented by 00...0 and hence subracting the minimum from our value. + // (We add the minimum back after making the lookup table) + within { // Currently we always uncompute the lookup table garbage qubits, but we can think of making an option to remove the uncomputation (and keep the garbage qubits) + if minInFxP != 0.0 { + // Make a new fixed point register to store the minimum vlaue + use minRegister = Qubit[Length(registerIn)]; + let minInReg = FixedPoint(integerBitsIn, minRegister); // + within { + PrepareFxP(minInFxP, minInReg); // Store minimum value in prepared register (automatically creates closest FxP approximation) + } apply { + SubtractFxP(input, minInReg); // SubtractFxP(a, b) : a <- a - b + } + } + } apply { + SelectSwap(numSwapBits, outBits, input::Register, output::Register); + } + } + + /// # Summary + /// Basically applies the ApplyPauliFromBitString function but with the extra check that the length of bits is the same + /// as the number of qubits (so nothing can be implicitly ignored) + internal operation WriteBits(bits: Bool[], qubitArray: Qubit[]): Unit is Adj + Ctl { + EqualityFactI(Length(bits), Length(qubitArray), "Dimensions of bits and qubitArray should be the same"); + ApplyPauliFromBitString(PauliX, true, bits, qubitArray); + } + + /// # Summary + /// Helper function that creates an operator that takes in just 1 binary value input (i.e. a list + /// of booleans) and makes the circuit to apply paulis to create that binary value. We do this + /// so that we can use it as part of the Mapped function to be able to make a list of unitaries + /// given a list of binary numbers + internal function MakeWriteBitsUnitary(bits : Bool[]) : Qubit[] => Unit is Adj + Ctl { + return WriteBits(bits, _); + + } + + /// # Summary + /// This opration makes the lookup table by using the multiplex unitary operator - the operator that implements + /// different unitaries based on the value of the controlled bits. We just define each unitary as the set of + /// PauliX gates that will make the output qubit correspond to the data bits. + internal operation Select(data : Bool[][], addressRegister: Qubit[], outputRegister: Qubit[]) : Unit is Adj { + + let unitaries = Mapped(MakeWriteBitsUnitary, data); + MultiplexOperations(unitaries, LittleEndian(addressRegister), outputRegister); + } + + /// # Summary + /// This operation makes the swap circuit. The outputRegisters are 2^l qubit registers, each of size m + internal operation SwapDataOutputs(addressRegister: Qubit[], outputRegisters: Qubit[][]) : Unit is Adj { + let l = Length(addressRegister); + // For each input qubit we are using for swap qubits, we want to implement all the swaps + for i in 0.. Length(addressRegister)-1{ + // for the ith input qubit, we need to have to swap qubit registers that are 2^i places apart, and we need to do this for every qubit that is 2^(i+1) qubits apart, + // and we need to swap atotal of 2^l/2^(i+1) registers, where l is the number of output registers. E.g. + // i=0 => swaps between registers (0,1), (2,3), (4,5),..., (2^l - 2, 2^l - 1) + // i=1 => swaps between registers (0,2), (4,6), (8,10),..., (2^l - 4, 2^l - 2) + // i=2 => swaps between registers (0,2^i), (2^(i+1), 2^(i+1) + 2^i),..., (2^l - 2^(i+1), 2^l - 2^(i+1) + 2^i) + let innerStepSize = 2^i; + let outerStepSize = 2^(i+1); + let numSwaps = 2^l/2^(i+1); + use extraControls = Qubit[numSwaps-1]; + let fannedControls = [addressRegister[i]] + extraControls; + within { + ApplyToEachA(CNOT(addressRegister[i],_), extraControls); // Fanning out qubits to be able to do a fanned control + } apply { + for j in 0.. numSwaps-1{ + ApplyMultiTargetSwap(fannedControls[j], outputRegisters[j*outerStepSize], outputRegisters[j*outerStepSize+innerStepSize]); + } + } + } + } + + /// # Summary + /// Implements an efficient control swap (with 2 CNOTs and one CCNOT) + internal operation ApplyLowDepthCSWAP(control : Qubit, target1 : Qubit, target2 : Qubit) : Unit is Adj { + use helper = Qubit(); + + within { + CNOT(target2, target1); + ApplyLowDepthAnd(control, target1, helper); // this has T-depth 1, AND = CCNOT where target is in |0> + } apply { + CNOT(helper, target2); + } + } + + /// # Summary + /// Implements a control swap two registers controlled on a single qubits. To be able to parallelize it, it will + /// fan out the control register and perform all the swaps in parallel + internal operation ApplyMultiTargetSwap(control : Qubit, target1 : Qubit[], target2 : Qubit[]) : Unit is Adj { + EqualityFactI(Length(target1), Length(target2), "The two qubit registers are of different sizes"); + + use extraControls = Qubit[Length(target1) - 1]; + let fannedControls = [control] + extraControls; + + within { + ApplyToEachA(CNOT(control, _), extraControls); + } apply { + for i in 0..Length(target1)-1{ + ApplyLowDepthCSWAP(fannedControls[i], target1[i], target2[i]); + } + } + } + + /// # Summary + /// Creates the select-swap circuit. Uses the most significant bits of `addressRegister` to use for SWAP network. + /// Let n be `Length(addressRegister)`, the number of address bits, and let l be `numSwapBits`. Then the T-depth is + /// approximately O(2^{(n-l}) + l. If we want m output qubits, the number of additional ancilla qubits is m * 2^l: + /// These due additional ancilla qubits come from the swap + /// + /// # Input + /// ## numSwapBits + /// The number of bits of the input register that will be used in the SWAP section of the circuits. Another way of looking + /// at this is that in step in the SELECT section of the circuit in Fig 1c of arXiv:1812.00954, we will encode 2^numSawpBits + /// encoded. + /// ## data + /// The list of output values in bits in order, where the first value is the output for the value 00...0 and + /// the last value is the output for the value the largest integer value + /// ## addressRegister + /// Input register of qubits + /// ## outputRegister + /// Output register where the output values will be stored + internal operation SelectSwap(numSwapBits : Int, data : Bool[][], addressRegister: Qubit[], outputRegister: Qubit[]) : Unit is Adj{ + + let n = Length(addressRegister); + + // how many address bits do we need for `data`? We do this so that we optimize if Length(data) <= 2^(n-1) and don't have to use all the input qubits in the swap register + let nRequired = Ceiling(Lg(IntAsDouble(Length(data)))); + Fact(nRequired <= n, "Too few address bits"); + let addressRegisterFitted = addressRegister[...nRequired - 1]; + + // Probably numSwapBits == nRequired works, but has to be checked + Fact(numSwapBits < nRequired, "Too many bits for SWAP network"); + + if numSwapBits == 0 { // to not uncompute select if l=0 + Select(data, addressRegisterFitted, outputRegister); + } else { + let m = Length(outputRegister); + // number of SWAP bits + let l = numSwapBits; + // number of SELECT bits + let k = nRequired - numSwapBits; + + let addressRegisterParts = Partitioned([k, l], addressRegisterFitted); //creates two parts of the array - 1 for the select and 1 for the swaps + + use dataRegister = Qubit[m * 2^l]; //create one register with m*2^l qubits to have all the outputs stored + + // Now we want to create the data array for the select bit. This means that for the first array, we want all the outputs corresponding to the most sig bits = 00..00, then for the next array 00..01, then 00..10 etc. + let dataArray = CreatePaddedData(data, nRequired, m, k); + + // Now we split up the register in to chunks of m + let chunkedDataRegister = Chunks(m, dataRegister); //Chunks(nElements, array): splits array into chunks, where each chunk has nElements, e.g. Chunks(2, [1, 2, 3, 4, 5, 6]) -> [[1, 2], [3, 4], [5, 6]] + + // Perform select swap with the (1) dataArray for the select outputs and (2) chunkedDataRegister for the swap targets. We can think about improving the efficiency of these two steps by thinking of the fanout inner and outer controls more carefully. + within { + Select(dataArray, addressRegisterParts[0], dataRegister); // apply select using first part of address registers + SwapDataOutputs(addressRegisterParts[1], chunkedDataRegister); // apply swap using second part of address registers + } apply { + ApplyToEachA(CNOT, Zipped(chunkedDataRegister[0], outputRegister)); // apply CNOT from chunkedDataRegister[0] to outputRegister + } + } + } + + /// # Summary + /// Helper function that creates a list of binary numbers were each number is a concatination of all the possible outputs of each + /// select function (i.e. combining all the possible outputs into a single bitstring which will then be used in the swap bit of the + /// select-swap) + /// + /// # Input + /// ## data + /// The list of output values in bits in order, where the first value is the output for the value 00...0 and + /// the last value is the output for the value the largest integer value + /// ## nRequired + /// Minimum number of address bits required to ensure the largest data point can be stored + /// ## m + /// Size of final single output of lookup table + /// ## k + /// Number of bits from input that will be used in the select part + internal function CreatePaddedData(data : Bool[][], nRequired : Int, m : Int, k : Int) : Bool[][] { + let dataPadded = Padded(-2^nRequired, [false, size = m], data); // Padded so that we don't have problems for powers of 2 + mutable dataArray = [[], size = 2^k]; + for i in 0..2^k-1 { + let range = RangeAsIntArray(i..2^k..2^nRequired-1); // RangeAsIntArray(range) takes a Range and returns Int[], e.g., 1..3 -> [1, 2, 3], 1..3..9 -> [1, 4, 7]. In our case, for i=0 -> [0, 2^k, 2*2^k...] + set dataArray w/= i <- Flattened(Subarray(range, dataPadded)); // Subarray(indices, array) takes indices Int[] and returns subarray of array subject to indices + } + return dataArray; + } +} diff --git a/Numerics/tests/LookupTableTests.qs b/Numerics/tests/LookupTableTests.qs new file mode 100755 index 00000000000..fdfb535713a --- /dev/null +++ b/Numerics/tests/LookupTableTests.qs @@ -0,0 +1,96 @@ +namespace Microsoft.Quantum.Tests { + open Microsoft.Quantum.Arithmetic; + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Math; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Diagnostics; + open Microsoft.Quantum.Random; + + /// # Summary + /// Example of exponential operation with [0, 9.23] with input-eps 1e-3, output-eps 1e-3 + /// Input should require something like 5 integer bits and 10 fractional bits + /// Output should require something like 15 integer bits and 10 fractional bits + operation ExponentialExample(numSwapBits: Int, input : FixedPoint, output : FixedPoint) : Unit { + let func = ExpD; + let xMin = 0.0; + let xMax = 9.23; + let epsIn = 1e-3; + let epsOut = 1e-3; + + let lookup = ApplyFunctionWithLookupTable(ExpD, (xMin, xMax), epsIn, epsOut, numSwapBits); + // Check that input and output registers are the expected size + EqualityFactI(lookup::IntegerBitsIn + lookup::FractionalBitsIn, 15, "Number of input bits is incorrect"); + EqualityFactI(lookup::IntegerBitsOut + lookup::FractionalBitsOut, 25, "Number of output bits is incorrect"); + lookup::Apply(input, output); + } + + /// # Summary + /// Example to call Exponential with pre-computed number of input and + /// output qubits from ExponentialExample + operation EstimateExponentialInstance(numSwapBits : Int) : Unit { + use input = Qubit[15]; + use output = Qubit[25]; + let inputFxP = FixedPoint(5, input); + let outputFxP = FixedPoint(15, output); + + ExponentialExample(numSwapBits, inputFxP, outputFxP); + } + + //Tests for some examples + @Test("ToffoliSimulator") + operation TestExponentialExample() : Unit { + use input = Qubit[15]; + use output = Qubit[25]; + let inputFxP = FixedPoint(5, input); + let outputFxP = FixedPoint(15, output); + + for i in 0..9 { + let inputValue = DrawRandomDouble(9.23*IntAsDouble(i)/10.0, 9.23*IntAsDouble(i+1)/10.0); + + PrepareFxP(inputValue, inputFxP); + ExponentialExample(5, inputFxP, outputFxP); + + let inResult = MeasureFxP(inputFxP); + let outResult = MeasureFxP(outputFxP); + + let expected = ExpD(inResult); + + EqualityWithinToleranceFact(inResult, inputValue, 1e-3); + EqualityWithinToleranceFact(outResult, expected, 1e-3); + + } + } + + @Test("ToffoliSimulator") + operation TestFxPRegisterValues(): Unit { + let func = ExpD; + let xMin = -1.0; + let xMax = 8.125; + let epsIn = 0.125; + let epsOut = 0.25; + + let lookup = ApplyFunctionWithLookupTable(func, (xMin, xMax), epsIn, epsOut, 0); + + use inputRegister = Qubit[lookup::IntegerBitsIn+lookup::FractionalBitsIn]; + use outputRegister = Qubit[lookup::IntegerBitsOut+lookup::FractionalBitsOut]; + + let inputFxP = FixedPoint(lookup::IntegerBitsIn, inputRegister); + let outputFxP = FixedPoint(lookup::IntegerBitsOut, outputRegister); + + let samplePoints = 20; + + for i in 0..samplePoints { + let x = xMin + IntAsDouble(i) * (xMax - xMin) / IntAsDouble(samplePoints); + PrepareFxP(x, inputFxP); + lookup::Apply(inputFxP, outputFxP); + let inputResult = MeasureFxP(inputFxP); + let outputResult = MeasureFxP(outputFxP); + + EqualityWithinToleranceFact(inputResult, x, epsIn); + EqualityWithinToleranceFact(outputResult, func(inputResult), epsOut); + + } + } +} From 676894d5cb694683164a5a71b84401495747c4ab Mon Sep 17 00:00:00 2001 From: Cassandra Granade Date: Fri, 26 Aug 2022 14:23:50 -0700 Subject: [PATCH 50/66] Update magic. --- Chemistry/src/Jupyter/FermionHamiltonianMagic.cs | 2 +- Chemistry/src/Jupyter/WavefunctionMagic.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Chemistry/src/Jupyter/FermionHamiltonianMagic.cs b/Chemistry/src/Jupyter/FermionHamiltonianMagic.cs index a7aa229b094..e874cc0ba19 100644 --- a/Chemistry/src/Jupyter/FermionHamiltonianMagic.cs +++ b/Chemistry/src/Jupyter/FermionHamiltonianMagic.cs @@ -46,7 +46,7 @@ public class Arguments /// A Broombridge ProblemDescription to load the FermionHamiltonian from. /// [JsonProperty(PropertyName = "problem_description")] - public V0_2.ProblemDescription ProblemDescription { get; set; } + public V0_3.ProblemDescription ProblemDescription { get; set; } /// /// The IndexConvention to use to generate the Hamiltonian from the ProblemDescription. diff --git a/Chemistry/src/Jupyter/WavefunctionMagic.cs b/Chemistry/src/Jupyter/WavefunctionMagic.cs index 7586c9f096c..0b04b9c96f3 100644 --- a/Chemistry/src/Jupyter/WavefunctionMagic.cs +++ b/Chemistry/src/Jupyter/WavefunctionMagic.cs @@ -40,7 +40,7 @@ public class Arguments /// A Broombridge ProblemDescription to load the FermionHamiltonian from. /// [JsonProperty(PropertyName = "problem_description")] - public V0_2.ProblemDescription ProblemDescription { get; set; } + public V0_3.ProblemDescription ProblemDescription { get; set; } /// /// The IndexConvention to use to generate the Hamiltonian from the ProblemDescription. From 3d0aea9549f9dffc76a169b71187c6409037b800 Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Tue, 30 Aug 2022 20:36:00 +0200 Subject: [PATCH 51/66] Revise ApplyFunctionWithLookupTable (#617) --- Numerics/src/FixedPoint/LookupTable.qs | 173 ++----------------------- Numerics/tests/LookupTableTests.qs | 20 +-- 2 files changed, 17 insertions(+), 176 deletions(-) diff --git a/Numerics/src/FixedPoint/LookupTable.qs b/Numerics/src/FixedPoint/LookupTable.qs index 9a4024d1c3d..15675bb54e9 100755 --- a/Numerics/src/FixedPoint/LookupTable.qs +++ b/Numerics/src/FixedPoint/LookupTable.qs @@ -25,15 +25,13 @@ namespace Microsoft.Quantum.Arithmetic { ); /// # Summary - /// This function creates a select-swap lookup table operator for the function that you want to approximate, as well as - /// the parameters required to make the two FixedPoint registers that need to be used as inputs to the operator. - /// This is so that it is in similar to the other typical Q# arithmetic function (a larger discussion can be had - /// as to whether that can be changed). The circuit for the operator can be found in Fig. 1c in arXiv:1812.00954. + /// This function creates a lookup table operator for the function that you want to approximate, as well as + /// the parameters required to make the two `FixedPoint` registers that need to be used as inputs to the operator. /// /// # Remarks /// The operator guarantees that given an input value $x$ and a function $f(x)$, /// it will compute $\hat{f}(\hat{x})$ where $\hat{f}$ is an approximation of $f$ with a maximum error of epsOut and $\hat{x}$ is an - /// approximation of the input value $\hat{x}$ with a maximum error of epsIn. This is useful for most reasonably behaved + /// approximation of the input value $\hat{x}$ with a maximum error of `epsIn`. This is useful for most reasonably behaved /// functions, but note that it computes $\hat{f}(\hat{x})$ and not $\hat{f}(x)$ so if the domain function is very oscillatory and/or /// has funky derivatives then it may have high errors. /// @@ -46,13 +44,9 @@ namespace Microsoft.Quantum.Arithmetic { /// The maximum allowed error of the input value to the computation (i.e. |x'-x|) /// ## epsOut /// The maximum allowed error of the output without taking into account the error in input value (i.e. |f'(x')-f(x')|) - /// ## numSwapBits - /// The number of bits of the input register that will be used in the SWAP section of the circuits. Another way of looking - /// at this is that in step in the SELECT section of the circuit in Fig 1c of arXiv:1812.00954, we will encode 2^numSwapBits - /// encoded /// /// # Example - /// The following code creates a quantum operation based on `ExpD` in the (inclusive) range from `-5.0` to `5.0` with an input error of `1e-3` and an output error of `1e-4`. It uses `2` SWAP bits for the implementation. + /// The following code creates a quantum operation based on `ExpD` in the (inclusive) range from `-5.0` to `5.0` with an input error of `1e-3` and an output error of `1e-4`. /// /// ```qsharp /// // Create operation from lookup table @@ -60,7 +54,7 @@ namespace Microsoft.Quantum.Arithmetic { /// let epsIn = 1e-3; /// let epsOut = 1e-4; /// - /// let lookup = ApplyFunctionWithLookupTable(ExpD, domain, epsIn, epsOut, 2); + /// let lookup = ApplyFunctionWithLookupTable(ExpD, domain, epsIn, epsOut); /// /// // Allocate qubits /// use input = Qubit[lookup::IntegerBitsIn + lookup::FractionalBitsIn]; @@ -73,7 +67,7 @@ namespace Microsoft.Quantum.Arithmetic { /// // Apply operation /// lookup::Apply(inputFxP, outputFxP); /// ``` - function ApplyFunctionWithLookupTable(func: Double -> Double, domain: (Double, Double), epsIn: Double, epsOut: Double, numSwapBits: Int): FunctionWithLookupTable { + function ApplyFunctionWithLookupTable(func: Double -> Double, domain: (Double, Double), epsIn: Double, epsOut: Double): FunctionWithLookupTable { // First step is to find the number of integer bits (pIn) and fractional bits (qIn) required for the input based on the // domain and error tolerance (espIn). To find the value of pIn, we have to check both the @@ -137,7 +131,7 @@ namespace Microsoft.Quantum.Arithmetic { // Now we use the fixed point approximation of the minimum value of the input // and the list of output bit values to make the operation lookupOperation: (FixedPoint, FixedPoint) => Unit // More comments on how that's done in within the function - let lookupOperation = LookupOperationWrapper(minInFxP, outBits, numSwapBits, _, _); + let lookupOperation = LookupOperationWrapper(minInFxP, outBits, _, _); return FunctionWithLookupTable( @@ -159,15 +153,11 @@ namespace Microsoft.Quantum.Arithmetic { /// ## outBits /// The list of output values in bits in order, where the first value is the output for the smallest input value and /// the last value is the output for the largest input value - /// ## numSwapBits - /// The number of bits of the input register that will be used in the SWAP section of the circuits. Another way of looking - /// at this is that in step in the SELECT section of the circuit in Fig 1c of arXiv:1812.00954, we will encode 2^numSawpBits - /// encoded /// ## input /// Qubit FixedPoint register containing input values /// ## output /// Qubit FixedPoint register containing where output values will be stored - internal operation LookupOperationWrapper(minInFxP: Double, outBits: Bool[][], numSwapBits : Int, input: FixedPoint, output: FixedPoint) : Unit is Adj { + internal operation LookupOperationWrapper(minInFxP: Double, outBits: Bool[][], input: FixedPoint, output: FixedPoint) : Unit is Adj { let integerBitsIn = input::IntegerBits; let registerIn = input::Register; @@ -190,7 +180,11 @@ namespace Microsoft.Quantum.Arithmetic { } } } apply { - SelectSwap(numSwapBits, outBits, input::Register, output::Register); + let n = Length(input::Register); + let nRequired = Ceiling(Lg(IntAsDouble(Length(outBits)))); + Fact(nRequired <= n, "Too few address bits"); + let addressRegisterFitted = input::Register[...nRequired - 1]; + Select(outBits, input::Register[...nRequired - 1], output::Register); } } @@ -221,145 +215,4 @@ namespace Microsoft.Quantum.Arithmetic { let unitaries = Mapped(MakeWriteBitsUnitary, data); MultiplexOperations(unitaries, LittleEndian(addressRegister), outputRegister); } - - /// # Summary - /// This operation makes the swap circuit. The outputRegisters are 2^l qubit registers, each of size m - internal operation SwapDataOutputs(addressRegister: Qubit[], outputRegisters: Qubit[][]) : Unit is Adj { - let l = Length(addressRegister); - // For each input qubit we are using for swap qubits, we want to implement all the swaps - for i in 0.. Length(addressRegister)-1{ - // for the ith input qubit, we need to have to swap qubit registers that are 2^i places apart, and we need to do this for every qubit that is 2^(i+1) qubits apart, - // and we need to swap atotal of 2^l/2^(i+1) registers, where l is the number of output registers. E.g. - // i=0 => swaps between registers (0,1), (2,3), (4,5),..., (2^l - 2, 2^l - 1) - // i=1 => swaps between registers (0,2), (4,6), (8,10),..., (2^l - 4, 2^l - 2) - // i=2 => swaps between registers (0,2^i), (2^(i+1), 2^(i+1) + 2^i),..., (2^l - 2^(i+1), 2^l - 2^(i+1) + 2^i) - let innerStepSize = 2^i; - let outerStepSize = 2^(i+1); - let numSwaps = 2^l/2^(i+1); - use extraControls = Qubit[numSwaps-1]; - let fannedControls = [addressRegister[i]] + extraControls; - within { - ApplyToEachA(CNOT(addressRegister[i],_), extraControls); // Fanning out qubits to be able to do a fanned control - } apply { - for j in 0.. numSwaps-1{ - ApplyMultiTargetSwap(fannedControls[j], outputRegisters[j*outerStepSize], outputRegisters[j*outerStepSize+innerStepSize]); - } - } - } - } - - /// # Summary - /// Implements an efficient control swap (with 2 CNOTs and one CCNOT) - internal operation ApplyLowDepthCSWAP(control : Qubit, target1 : Qubit, target2 : Qubit) : Unit is Adj { - use helper = Qubit(); - - within { - CNOT(target2, target1); - ApplyLowDepthAnd(control, target1, helper); // this has T-depth 1, AND = CCNOT where target is in |0> - } apply { - CNOT(helper, target2); - } - } - - /// # Summary - /// Implements a control swap two registers controlled on a single qubits. To be able to parallelize it, it will - /// fan out the control register and perform all the swaps in parallel - internal operation ApplyMultiTargetSwap(control : Qubit, target1 : Qubit[], target2 : Qubit[]) : Unit is Adj { - EqualityFactI(Length(target1), Length(target2), "The two qubit registers are of different sizes"); - - use extraControls = Qubit[Length(target1) - 1]; - let fannedControls = [control] + extraControls; - - within { - ApplyToEachA(CNOT(control, _), extraControls); - } apply { - for i in 0..Length(target1)-1{ - ApplyLowDepthCSWAP(fannedControls[i], target1[i], target2[i]); - } - } - } - - /// # Summary - /// Creates the select-swap circuit. Uses the most significant bits of `addressRegister` to use for SWAP network. - /// Let n be `Length(addressRegister)`, the number of address bits, and let l be `numSwapBits`. Then the T-depth is - /// approximately O(2^{(n-l}) + l. If we want m output qubits, the number of additional ancilla qubits is m * 2^l: - /// These due additional ancilla qubits come from the swap - /// - /// # Input - /// ## numSwapBits - /// The number of bits of the input register that will be used in the SWAP section of the circuits. Another way of looking - /// at this is that in step in the SELECT section of the circuit in Fig 1c of arXiv:1812.00954, we will encode 2^numSawpBits - /// encoded. - /// ## data - /// The list of output values in bits in order, where the first value is the output for the value 00...0 and - /// the last value is the output for the value the largest integer value - /// ## addressRegister - /// Input register of qubits - /// ## outputRegister - /// Output register where the output values will be stored - internal operation SelectSwap(numSwapBits : Int, data : Bool[][], addressRegister: Qubit[], outputRegister: Qubit[]) : Unit is Adj{ - - let n = Length(addressRegister); - - // how many address bits do we need for `data`? We do this so that we optimize if Length(data) <= 2^(n-1) and don't have to use all the input qubits in the swap register - let nRequired = Ceiling(Lg(IntAsDouble(Length(data)))); - Fact(nRequired <= n, "Too few address bits"); - let addressRegisterFitted = addressRegister[...nRequired - 1]; - - // Probably numSwapBits == nRequired works, but has to be checked - Fact(numSwapBits < nRequired, "Too many bits for SWAP network"); - - if numSwapBits == 0 { // to not uncompute select if l=0 - Select(data, addressRegisterFitted, outputRegister); - } else { - let m = Length(outputRegister); - // number of SWAP bits - let l = numSwapBits; - // number of SELECT bits - let k = nRequired - numSwapBits; - - let addressRegisterParts = Partitioned([k, l], addressRegisterFitted); //creates two parts of the array - 1 for the select and 1 for the swaps - - use dataRegister = Qubit[m * 2^l]; //create one register with m*2^l qubits to have all the outputs stored - - // Now we want to create the data array for the select bit. This means that for the first array, we want all the outputs corresponding to the most sig bits = 00..00, then for the next array 00..01, then 00..10 etc. - let dataArray = CreatePaddedData(data, nRequired, m, k); - - // Now we split up the register in to chunks of m - let chunkedDataRegister = Chunks(m, dataRegister); //Chunks(nElements, array): splits array into chunks, where each chunk has nElements, e.g. Chunks(2, [1, 2, 3, 4, 5, 6]) -> [[1, 2], [3, 4], [5, 6]] - - // Perform select swap with the (1) dataArray for the select outputs and (2) chunkedDataRegister for the swap targets. We can think about improving the efficiency of these two steps by thinking of the fanout inner and outer controls more carefully. - within { - Select(dataArray, addressRegisterParts[0], dataRegister); // apply select using first part of address registers - SwapDataOutputs(addressRegisterParts[1], chunkedDataRegister); // apply swap using second part of address registers - } apply { - ApplyToEachA(CNOT, Zipped(chunkedDataRegister[0], outputRegister)); // apply CNOT from chunkedDataRegister[0] to outputRegister - } - } - } - - /// # Summary - /// Helper function that creates a list of binary numbers were each number is a concatination of all the possible outputs of each - /// select function (i.e. combining all the possible outputs into a single bitstring which will then be used in the swap bit of the - /// select-swap) - /// - /// # Input - /// ## data - /// The list of output values in bits in order, where the first value is the output for the value 00...0 and - /// the last value is the output for the value the largest integer value - /// ## nRequired - /// Minimum number of address bits required to ensure the largest data point can be stored - /// ## m - /// Size of final single output of lookup table - /// ## k - /// Number of bits from input that will be used in the select part - internal function CreatePaddedData(data : Bool[][], nRequired : Int, m : Int, k : Int) : Bool[][] { - let dataPadded = Padded(-2^nRequired, [false, size = m], data); // Padded so that we don't have problems for powers of 2 - mutable dataArray = [[], size = 2^k]; - for i in 0..2^k-1 { - let range = RangeAsIntArray(i..2^k..2^nRequired-1); // RangeAsIntArray(range) takes a Range and returns Int[], e.g., 1..3 -> [1, 2, 3], 1..3..9 -> [1, 4, 7]. In our case, for i=0 -> [0, 2^k, 2*2^k...] - set dataArray w/= i <- Flattened(Subarray(range, dataPadded)); // Subarray(indices, array) takes indices Int[] and returns subarray of array subject to indices - } - return dataArray; - } } diff --git a/Numerics/tests/LookupTableTests.qs b/Numerics/tests/LookupTableTests.qs index fdfb535713a..9c991b9d62a 100755 --- a/Numerics/tests/LookupTableTests.qs +++ b/Numerics/tests/LookupTableTests.qs @@ -12,31 +12,19 @@ namespace Microsoft.Quantum.Tests { /// Example of exponential operation with [0, 9.23] with input-eps 1e-3, output-eps 1e-3 /// Input should require something like 5 integer bits and 10 fractional bits /// Output should require something like 15 integer bits and 10 fractional bits - operation ExponentialExample(numSwapBits: Int, input : FixedPoint, output : FixedPoint) : Unit { + operation ExponentialExample(input : FixedPoint, output : FixedPoint) : Unit { let func = ExpD; let xMin = 0.0; let xMax = 9.23; let epsIn = 1e-3; let epsOut = 1e-3; - let lookup = ApplyFunctionWithLookupTable(ExpD, (xMin, xMax), epsIn, epsOut, numSwapBits); + let lookup = ApplyFunctionWithLookupTable(ExpD, (xMin, xMax), epsIn, epsOut); // Check that input and output registers are the expected size EqualityFactI(lookup::IntegerBitsIn + lookup::FractionalBitsIn, 15, "Number of input bits is incorrect"); EqualityFactI(lookup::IntegerBitsOut + lookup::FractionalBitsOut, 25, "Number of output bits is incorrect"); lookup::Apply(input, output); } - - /// # Summary - /// Example to call Exponential with pre-computed number of input and - /// output qubits from ExponentialExample - operation EstimateExponentialInstance(numSwapBits : Int) : Unit { - use input = Qubit[15]; - use output = Qubit[25]; - let inputFxP = FixedPoint(5, input); - let outputFxP = FixedPoint(15, output); - - ExponentialExample(numSwapBits, inputFxP, outputFxP); - } //Tests for some examples @Test("ToffoliSimulator") @@ -50,7 +38,7 @@ namespace Microsoft.Quantum.Tests { let inputValue = DrawRandomDouble(9.23*IntAsDouble(i)/10.0, 9.23*IntAsDouble(i+1)/10.0); PrepareFxP(inputValue, inputFxP); - ExponentialExample(5, inputFxP, outputFxP); + ExponentialExample(inputFxP, outputFxP); let inResult = MeasureFxP(inputFxP); let outResult = MeasureFxP(outputFxP); @@ -71,7 +59,7 @@ namespace Microsoft.Quantum.Tests { let epsIn = 0.125; let epsOut = 0.25; - let lookup = ApplyFunctionWithLookupTable(func, (xMin, xMax), epsIn, epsOut, 0); + let lookup = ApplyFunctionWithLookupTable(func, (xMin, xMax), epsIn, epsOut); use inputRegister = Qubit[lookup::IntegerBitsIn+lookup::FractionalBitsIn]; use outputRegister = Qubit[lookup::IntegerBitsOut+lookup::FractionalBitsOut]; From df7cc1fdc1069d2070da613510340ef166b4efb5 Mon Sep 17 00:00:00 2001 From: Cassandra Granade Date: Tue, 30 Aug 2022 20:54:05 +0000 Subject: [PATCH 52/66] Temporarily disable test not compatible with 0.3. --- .../SerializationTests/BroombridgeTests.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs index 6b793360b58..f6459a5f8d1 100644 --- a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs +++ b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs @@ -106,16 +106,17 @@ public void CheckNullUnitaryCoupledCluster() Assert.Contains("UCCSD nullOne", broombridge_internal.Wavefunctions.Keys); } - [Fact] - public void UpdateFrom_v0_1() - { - var filename = "Broombridge/broombridge_v0.1.yaml"; - var broombridge_v0_1 = Deserializers.Deserialize(filename); - var broombridge_v0_2 = DataStructures.Update(broombridge_v0_1); + // TODO: re-enable test before merging to main. + // [Fact] + // public void UpdateFrom_v0_1() + // { + // var filename = "Broombridge/broombridge_v0.1.yaml"; + // var broombridge_v0_1 = Deserializers.Deserialize(filename); + // var broombridge_v0_2 = DataStructures.Update(broombridge_v0_1); - Broombridge.Serializers.SerializeBroombridgev0_2(broombridge_v0_2, System.Console.Out); + // Broombridge.Serializers.SerializeBroombridgev0_2(broombridge_v0_2, System.Console.Out); - } + // } [Fact] public void JsonEncoding() From d43cb358bf5b190660b09f0a87dd6cda9daf5eb1 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Thu, 1 Sep 2022 00:42:08 -0700 Subject: [PATCH 53/66] Add exemption file for Central Feed Services onboarding (#621) --- .sscignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .sscignore diff --git a/.sscignore b/.sscignore new file mode 100644 index 00000000000..a2263606946 --- /dev/null +++ b/.sscignore @@ -0,0 +1,3 @@ +{ + "cfs": ["CFS0012", "CFS0013"] +} From c0b851735542117cf6d73f8946ab6eef8c84384d Mon Sep 17 00:00:00 2001 From: Adam Kania <48769688+remilvus@users.noreply.github.com> Date: Fri, 2 Sep 2022 05:35:00 -0700 Subject: [PATCH 54/66] Fix documentation (#615) * Fix documentation * Temporarily disable test not compatible with 0.3. Co-authored-by: Cassandra Granade Co-authored-by: Mathias Soeken --- .../SerializationTests/BroombridgeTests.cs | 17 +++++++++-------- .../src/Canon/Utils/ControlledOnBitString.qs | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs index 6b793360b58..f6459a5f8d1 100644 --- a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs +++ b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs @@ -106,16 +106,17 @@ public void CheckNullUnitaryCoupledCluster() Assert.Contains("UCCSD nullOne", broombridge_internal.Wavefunctions.Keys); } - [Fact] - public void UpdateFrom_v0_1() - { - var filename = "Broombridge/broombridge_v0.1.yaml"; - var broombridge_v0_1 = Deserializers.Deserialize(filename); - var broombridge_v0_2 = DataStructures.Update(broombridge_v0_1); + // TODO: re-enable test before merging to main. + // [Fact] + // public void UpdateFrom_v0_1() + // { + // var filename = "Broombridge/broombridge_v0.1.yaml"; + // var broombridge_v0_1 = Deserializers.Deserialize(filename); + // var broombridge_v0_2 = DataStructures.Update(broombridge_v0_1); - Broombridge.Serializers.SerializeBroombridgev0_2(broombridge_v0_2, System.Console.Out); + // Broombridge.Serializers.SerializeBroombridgev0_2(broombridge_v0_2, System.Console.Out); - } + // } [Fact] public void JsonEncoding() diff --git a/Standard/src/Canon/Utils/ControlledOnBitString.qs b/Standard/src/Canon/Utils/ControlledOnBitString.qs index 539387326d3..477f8bf8bfb 100644 --- a/Standard/src/Canon/Utils/ControlledOnBitString.qs +++ b/Standard/src/Canon/Utils/ControlledOnBitString.qs @@ -112,7 +112,7 @@ namespace Microsoft.Quantum.Canon { /// # Summary /// Applies a unitary operation on the target register if the control - /// register state corresponds to a specified positive integer. + /// register state corresponds to a specified nonnegative integer. /// /// # Input /// ## numberState @@ -140,11 +140,11 @@ namespace Microsoft.Quantum.Canon { /// # Summary /// Returns a unitary operator that applies an oracle on the target register - /// if the control register state corresponds to a specified positive integer. + /// if the control register state corresponds to a specified nonnegative integer. /// /// # Input /// ## numberState - /// Positive integer. + /// Nonnegative integer. /// ## oracle /// Unitary operator. /// From 9cbc6b16886e56f06c98715f6cd5a6eabc3094c5 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Fri, 2 Sep 2022 09:47:10 -0700 Subject: [PATCH 55/66] Add `$schema` to `cgmanifest.json` (#620) * Add `$schema` to `cgmanifest.json` * Temporarily disable test not compatible with 0.3. Co-authored-by: Jamie Magee Co-authored-by: Cassandra Granade Co-authored-by: Mathias Soeken --- Standard/src/Emulation/cgmanifest.json | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Standard/src/Emulation/cgmanifest.json b/Standard/src/Emulation/cgmanifest.json index ade0132fa50..40f174f139e 100644 --- a/Standard/src/Emulation/cgmanifest.json +++ b/Standard/src/Emulation/cgmanifest.json @@ -1,15 +1,16 @@ { - "Registrations": [ - { - "Component": { - "Type": "other", - "Other": { - "Name": "NumPy", - "Version": "4a2b6a7d8e389abe06d5d7f2fbfa6ebd03b9092a", - "DownloadUrl": "https://raw.githubusercontent.com/numpy/numpy/4a2b6a7d8e389abe06d5d7f2fbfa6ebd03b9092a/numpy/random/mtrand/distributions.c" - } - } + "$schema": "https://json.schemastore.org/component-detection-manifest.json", + "Registrations": [ + { + "Component": { + "Type": "other", + "Other": { + "Name": "NumPy", + "Version": "4a2b6a7d8e389abe06d5d7f2fbfa6ebd03b9092a", + "DownloadUrl": "https://raw.githubusercontent.com/numpy/numpy/4a2b6a7d8e389abe06d5d7f2fbfa6ebd03b9092a/numpy/random/mtrand/distributions.c" } - ], - "Version": 1 + } + } + ], + "Version": 1 } From 49a14a4689a4486ef47b3c73a6b0798ae637535f Mon Sep 17 00:00:00 2001 From: Cassandra Granade Date: Fri, 2 Sep 2022 13:43:43 -0700 Subject: [PATCH 56/66] Update test to bb 0.3, remove test made irrelevant by serialization refactor. --- .../SerializationTests/BroombridgeTests.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs index f6459a5f8d1..46bc61d8bf7 100644 --- a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs +++ b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs @@ -106,18 +106,6 @@ public void CheckNullUnitaryCoupledCluster() Assert.Contains("UCCSD nullOne", broombridge_internal.Wavefunctions.Keys); } - // TODO: re-enable test before merging to main. - // [Fact] - // public void UpdateFrom_v0_1() - // { - // var filename = "Broombridge/broombridge_v0.1.yaml"; - // var broombridge_v0_1 = Deserializers.Deserialize(filename); - // var broombridge_v0_2 = DataStructures.Update(broombridge_v0_1); - - // Broombridge.Serializers.SerializeBroombridgev0_2(broombridge_v0_2, System.Console.Out); - - // } - [Fact] public void JsonEncoding() { @@ -127,8 +115,10 @@ public void JsonEncoding() var json = JsonConvert.SerializeObject(original); File.WriteAllText("original.json", json); - var serialized = JsonConvert.DeserializeObject(json); - File.WriteAllText("serialized.json", JsonConvert.SerializeObject(serialized)); + // NB: Even though we loaded a 0.2 file, the export step above + // normalizes to 0.3. + var serialized = JsonConvert.DeserializeObject(json); + File.WriteAllText("serialized.json", JsonConvert.SerializeObject(serialized)); Assert.Equal(original.Format, serialized.Format); Assert.Equal(original.Bibliography.Count, serialized.Bibliography.Count); From 48541dab6690b22e917915ac97cbd347809d2201 Mon Sep 17 00:00:00 2001 From: Rufus Buschart Date: Wed, 7 Sep 2022 08:03:44 +0200 Subject: [PATCH 57/66] Fixes outdated example (#623) Fixes https://github.com/microsoft/QuantumLibraries/issues/622 --- Standard/src/Preparation/Arbitrary.qs | 1 - 1 file changed, 1 deletion(-) diff --git a/Standard/src/Preparation/Arbitrary.qs b/Standard/src/Preparation/Arbitrary.qs index 642bbe026e9..35ec4a3576a 100644 --- a/Standard/src/Preparation/Arbitrary.qs +++ b/Standard/src/Preparation/Arbitrary.qs @@ -98,7 +98,6 @@ namespace Microsoft.Quantum.Preparation { /// in the qubit register `qubitsLE`. /// ```qsharp /// let amplitudes = [Sqrt(0.125), 0.0, Sqrt(0.875), 0.0]; - /// let op = StatePreparationPositiveCoefficients(amplitudes); /// use qubits = Qubit[2]; /// let qubitsLE = LittleEndian(qubits); /// PrepareArbitraryStateD(amplitudes, qubitsLE); From eecc1b6c100af0ceffbe2c25eda3a9b5158febdf Mon Sep 17 00:00:00 2001 From: Cassandra Granade Date: Fri, 9 Sep 2022 08:49:54 -0700 Subject: [PATCH 58/66] Disable test for loading old version. --- .../JupyterTests/BroombridgeMagicTests.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Chemistry/tests/JupyterTests/BroombridgeMagicTests.cs b/Chemistry/tests/JupyterTests/BroombridgeMagicTests.cs index 79edefa1925..cb74a217c75 100644 --- a/Chemistry/tests/JupyterTests/BroombridgeMagicTests.cs +++ b/Chemistry/tests/JupyterTests/BroombridgeMagicTests.cs @@ -39,19 +39,19 @@ public async void LoadInvalidFile() } - [Fact] - public async void LoadBroombridgeFile() - { - var filename = "broombridge_v0.2.yaml"; - var magic = new BroombridgeMagic(); - var channel = new MockChannel(); - - var result = await magic.Run(filename, channel); - var broombridge = (V0_2.Data)result.Output; - Assert.Equal(ExecuteStatus.Ok, result.Status); - Assert.Equal("0.2", broombridge.Format.Version); - Assert.Equal(3, broombridge.Bibliography.Count); - Assert.Single(broombridge.ProblemDescriptions); - } + // [Fact] + // public async void LoadBroombridgeFile() + // { + // var filename = "broombridge_v0.2.yaml"; + // var magic = new BroombridgeMagic(); + // var channel = new MockChannel(); + + // var result = await magic.Run(filename, channel); + // var broombridge = (V0_2.Data)result.Output; + // Assert.Equal(ExecuteStatus.Ok, result.Status); + // Assert.Equal("0.2", broombridge.Format.Version); + // Assert.Equal(3, broombridge.Bibliography.Count); + // Assert.Single(broombridge.ProblemDescriptions); + // } } } \ No newline at end of file From f29e03e74ad08410fe07ab9c9ca06684310ca6fa Mon Sep 17 00:00:00 2001 From: DmitryVasilevsky <60718360+DmitryVasilevsky@users.noreply.github.com> Date: Fri, 9 Sep 2022 18:09:31 -0700 Subject: [PATCH 59/66] Updating QDK version to 0.25.228311 - August 2022 Release (#626) Co-authored-by: Dmitry Vasilevsky --- Build/props/tests.props | 2 +- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- Chemistry/tests/ChemistryTests/QSharpTests.csproj | 2 +- Chemistry/tests/SystemTests/SystemTests.csproj | 2 +- MachineLearning/src/MachineLearning.csproj | 2 +- MachineLearning/tests/MachineLearningTests.csproj | 2 +- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 2 +- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 2 +- Visualization/src/Visualization.csproj | 4 ++-- global.json | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Build/props/tests.props b/Build/props/tests.props index 0c1857d11f0..623981f02ee 100644 --- a/Build/props/tests.props +++ b/Build/props/tests.props @@ -7,7 +7,7 @@ - + diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index c96b57bd353..268051208f6 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index c894e694b5c..65a75e166e5 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index 28ee132073d..d6e3c0f01f4 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index 1328cd228b9..a96bc1de318 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index 9fb245ab0fd..935d0842b9d 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index 7834b95127c..361e8fd77d7 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index 677cb9a1d81..9daa12dfead 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index da274692ef2..32ee5624d3a 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index 5cc44825bd1..f6c7615a93b 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index bcac36a31ec..7c917b84563 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + diff --git a/global.json b/global.json index 172cc360c51..b2d8f34ce1d 100644 --- a/global.json +++ b/global.json @@ -4,6 +4,6 @@ "rollForward": "latestMinor" }, "msbuild-sdks": { - "Microsoft.Quantum.Sdk": "0.25.222597" + "Microsoft.Quantum.Sdk": "0.25.228311" } } From 76dd668d5a8b0e92e0b3140982398f16fd3a13a3 Mon Sep 17 00:00:00 2001 From: Rufus Buschart Date: Fri, 23 Sep 2022 21:23:11 +0200 Subject: [PATCH 60/66] Added example how to use PrepareArbitraryStateCP (#627) * Added example how to use PrepareArbitraryStateCP * Update Standard/src/Preparation/Arbitrary.qs Co-authored-by: Mathias Soeken Co-authored-by: Mathias Soeken --- Standard/src/Preparation/Arbitrary.qs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Standard/src/Preparation/Arbitrary.qs b/Standard/src/Preparation/Arbitrary.qs index 35ec4a3576a..8343a1c4e6b 100644 --- a/Standard/src/Preparation/Arbitrary.qs +++ b/Standard/src/Preparation/Arbitrary.qs @@ -51,6 +51,15 @@ namespace Microsoft.Quantum.Preparation { /// elements $(r_j, t_j) = (0.0, 0.0)$ if fewer than $2^n$ are /// specified. /// + /// # Example + /// The following snippet prepares the quantum state $\ket{\psi}=\sqrt{1/8}\ket{0}+\sqrt{7/8}\ket{2}$ + /// in the qubit register `qubitsLE`. + /// ```qsharp + /// use qubits = Qubit(); + /// let qubitsLE = LittleEndian([qubits]); + /// PrepareArbitraryStateCP([ComplexPolar(1.0/Sqrt(2.0),0.0),ComplexPolar(1.0/Sqrt(2.0),PI()/2.0)],qubitsLE); // = |i> + /// ``` + /// /// # References /// - Synthesis of Quantum Logic Circuits /// Vivek V. Shende, Stephen S. Bullock, Igor L. Markov From 2083e1a6d13b822e2ebcd8b95ca80a79c07ed42b Mon Sep 17 00:00:00 2001 From: Cassandra Granade Date: Fri, 30 Sep 2022 14:27:56 -0700 Subject: [PATCH 61/66] =?UTF-8?q?Use=20trivial=20symmetry=20for=20orbital?= =?UTF-8?q?=20=E2=86=92=20fermion=20transform.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrbitalIntegral/OrbitalIntegralExtensions.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs index 7ea73da05d0..cc48cf5324d 100644 --- a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs +++ b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs @@ -43,7 +43,10 @@ symmetry switch var nOrbitals = sourceHamiltonian.SystemIndices.Max() + 1; var hamiltonian = new FermionHamiltonian(); Func> conversion = - (orb, coeff) => new OrbitalIntegral(orb.OrbitalIndices, coeff).ToHermitianFermionTerms(nOrbitals, indexConvention) + // NB: We use a trivial symmetry here, as the symmetry is already resolved + // when constructing the orbital integral Hamiltonian initially. + // See https://github.com/microsoft/QuantumLibraries/blob/eecc1b6c100af0ceffbe2c25eda3a9b5158febdf/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs#L524. + (orb, coeff) => new OrbitalIntegral(orb.OrbitalIndices, coeff).ToHermitianFermionTerms(nOrbitals, OrbitalIntegral.PermutationSymmetry.Trivial, indexConvention) .Select(o => (o.Item1, o.Item2.ToDoubleCoeff())); foreach (var termType in sourceHamiltonian.Terms) @@ -69,8 +72,8 @@ symmetry switch public static IEnumerable<(HermitianFermionTerm, double)> ToHermitianFermionTerms( this OrbitalIntegral orbitalIntegral, int nOrbitals, - IndexConvention indexConvention = IndexConvention.UpDown, - OrbitalIntegral.PermutationSymmetry symmetry = OrbitalIntegral.PermutationSymmetry.Eightfold) + OrbitalIntegral.PermutationSymmetry symmetry, + IndexConvention indexConvention = IndexConvention.UpDown) { var termType = orbitalIntegral.TermType; if (termType == TermType.OrbitalIntegral.OneBody) From b80054e046713680d83bdecec375ec2bb54ee258 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Tue, 4 Oct 2022 20:36:04 -0700 Subject: [PATCH 62/66] Update license text for NetMQ (#632) --- NOTICE.txt | 551 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 463 insertions(+), 88 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index ac4b1dc0200..1a3683322de 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -6639,184 +6639,559 @@ SOFTWARE. --------------------------------------------------------- -AsyncIO 0.1.26 - MPL-2.0 +AsyncIO 0.1.69 - MPL-2.0 -(c) 2008 VeriSign, Inc. -Mozilla Public License Version 2.0 +Mozilla Public License, version 2.0 - 1. Definitions +1. Definitions - 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. +1.1. "Contributor" - 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. - 1.3. "Contribution" means Covered Software of a particular Contributor. +1.2. "Contributor Version" - 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. - 1.5. "Incompatible With Secondary Licenses" means +1.3. "Contribution" - (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or + means Covered Software of a particular Contributor. - (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. +1.4. "Covered Software" - 1.6. "Executable Form" means any form of the work other than Source Code Form. + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. - 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. +1.5. "Incompatible With Secondary Licenses" + means - 1.8. "License" means this document. + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or - 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. + b. that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the terms of + a Secondary License. - 1.10. "Modifications" means any of the following: +1.6. "Executable Form" - (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or + means any form of the work other than Source Code Form. - (b) any new file in Source Code Form that contains any Covered Software. +1.7. "Larger Work" - 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. + means a work that combines Covered Software with other material, in a + separate file or files, that is not Covered Software. - 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. +1.8. "License" - 1.13. "Source Code Form" means the form of the work preferred for making modifications. + means this document. - 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. +1.9. "Licensable" - 2. License Grants and Conditions + means having the right to grant, to the maximum extent possible, whether + at the time of the initial grant or subsequently, any and all of the + rights conveyed by this License. - 2.1. Grants +1.10. "Modifications" - Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: + means any of the following: - (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and + a. any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered Software; or - (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. + b. any new file in Source Code Form that contains any Covered Software. - 2.2. Effective Date +1.11. "Patent Claims" of a Contributor - The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the License, + by the making, using, selling, offering for sale, having made, import, + or transfer of either its Contributions or its Contributor Version. - 2.3. Limitations on Grant Scope +1.12. "Secondary License" - The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. - (a) for any code that a Contributor has removed from Covered Software; or +1.13. "Source Code Form" - (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or + means the form of the work preferred for making modifications. - (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. +1.14. "You" (or "Your") - This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, "control" means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. - 2.4. Subsequent Licenses - No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). +2. License Grants and Conditions - 2.5. Representation +2.1. Grants - Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: - 2.6. Fair Use + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and - This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. - 2.7. Conditions +2.2. Effective Date - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. + The licenses granted in Section 2.1 with respect to any Contribution + become effective for each Contribution on the date the Contributor first + distributes such Contribution. - 3. Responsibilities +2.3. Limitations on Grant Scope - 3.1. Distribution of Source Form + The licenses granted in this Section 2 are the only rights granted under + this License. No additional rights or licenses will be implied from the + distribution or licensing of Covered Software under this License. + Notwithstanding Section 2.1(b) above, no patent license is granted by a + Contributor: - All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. + a. for any code that a Contributor has removed from Covered Software; or - 3.2. Distribution of Executable Form + b. for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or - If You distribute Covered Software in Executable Form then: + c. under Patent Claims infringed by Covered Software in the absence of + its Contributions. - (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and + This License does not grant any rights in the trademarks, service marks, + or logos of any Contributor (except as may be necessary to comply with + the notice requirements in Section 3.4). - (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. +2.4. Subsequent Licenses - 3.3. Distribution of a Larger Work + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this + License (see Section 10.2) or under the terms of a Secondary License (if + permitted under the terms of Section 3.3). - You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). +2.5. Representation - 3.4. Notices + Each Contributor represents that the Contributor believes its + Contributions are its original creation(s) or it has sufficient rights to + grant the rights to its Contributions conveyed by this License. - You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. +2.6. Fair Use - 3.5. Application of Additional Terms + This License is not intended to limit any rights You have under + applicable copyright doctrines of fair use, fair dealing, or other + equivalents. - You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. +2.7. Conditions - 4. Inability to Comply Due to Statute or Regulation + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. - If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. - 5. Termination +3. Responsibilities - 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. +3.1. Distribution of Source Form - 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under + the terms of this License. You must inform recipients that the Source + Code Form of the Covered Software is governed by the terms of this + License, and how they can obtain a copy of this License. You may not + attempt to alter or restrict the recipients' rights in the Source Code + Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter the + recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for + the Covered Software. If the Larger Work is a combination of Covered + Software with a work governed by one or more Secondary Licenses, and the + Covered Software is not Incompatible With Secondary Licenses, this + License permits You to additionally distribute such Covered Software + under the terms of such Secondary License(s), so that the recipient of + the Larger Work may, at their option, further distribute the Covered + Software under the terms of either this License or such Secondary + License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices + (including copyright notices, patent notices, disclaimers of warranty, or + limitations of liability) contained within the Source Code Form of the + Covered Software, except that You may alter any license notices to the + extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on + behalf of any Contributor. You must make it absolutely clear that any + such warranty, support, indemnity, or liability obligation is offered by + You alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, + judicial order, or regulation then You must: (a) comply with the terms of + this License to the maximum extent possible; and (b) describe the + limitations and the code they affect. Such description must be placed in a + text file included with all distributions of the Covered Software under + this License. Except to the extent prohibited by statute or regulation, + such description must be sufficiently detailed for a recipient of ordinary + skill to be able to understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing + basis, if such Contributor fails to notify You of the non-compliance by + some reasonable means prior to 60 days after You have come back into + compliance. Moreover, Your grants from a particular Contributor are + reinstated on an ongoing basis if such Contributor notifies You of the + non-compliance by some reasonable means, this is the first time You have + received notice of non-compliance with this License from such + Contributor, and You become compliant prior to 30 days after Your receipt + of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, + counter-claims, and cross-claims) alleging that a Contributor Version + directly or indirectly infringes any patent, then the rights granted to + You by any and all Contributors for the Covered Software under Section + 2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, + without warranty of any kind, either expressed, implied, or statutory, + including, without limitation, warranties that the Covered Software is free + of defects, merchantable, fit for a particular purpose or non-infringing. + The entire risk as to the quality and performance of the Covered Software + is with You. Should any Covered Software prove defective in any respect, + You (not any Contributor) assume the cost of any necessary servicing, + repair, or correction. This disclaimer of warranty constitutes an essential + part of this License. No use of any Covered Software is authorized under + this License except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from + such party's negligence to the extent applicable law prohibits such + limitation. Some jurisdictions do not allow the exclusion or limitation of + incidental or consequential damages, so this exclusion and limitation may + not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts + of a jurisdiction where the defendant maintains its principal place of + business and such litigation shall be governed by laws of that + jurisdiction, without reference to its conflict-of-law provisions. Nothing + in this Section shall prevent a party's ability to bring cross-claims or + counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. Any law or regulation which provides that + the language of a contract shall be construed against the drafter shall not + be used to construe this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version + of the License under which You originally received the Covered Software, + or under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a + modified version of this License if you rename the license and remove + any references to the name of the license steward (except to note that + such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses If You choose to distribute Source Code Form that is + Incompatible With Secondary Licenses under the terms of this version of + the License, the notice described in Exhibit B of this License must be + attached. + +Exhibit A - Source Code Form License Notice + + This Source Code Form is subject to the + terms of the Mozilla Public License, v. + 2.0. If a copy of the MPL was not + distributed with this file, You can + obtain one at + http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, +then You may include the notice in a location (such as a LICENSE file in a +relevant directory) where a recipient would be likely to look for such a +notice. - 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. +You may add additional accurate notices of copyright ownership. - 6. Disclaimer of Warranty +Exhibit B - "Incompatible With Secondary Licenses" Notice - Covered Software is provided under this License on an "as is" basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer. + This Source Code Form is "Incompatible + With Secondary Licenses", as defined by + the Mozilla Public License, v. 2.0. - 7. Limitation of Liability +--------------------------------------------------------- - Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You. +--------------------------------------------------------- - 8. Litigation +NetMQ 4.0.1.9 - OTHER - Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. +http://www.zeromq.org/ - 9. Miscellaneous + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 - This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. - 10. Versions of the License - 10.1. New Versions + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. - Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. + 0. Additional Definitions. - 10.2. Effect of New Versions + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. - You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. - 10.3. Modified Versions + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. - If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". - 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. - If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. -This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + 1. Exception to Section 3 of the GNU GPL. -If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. -You may add additional accurate notices of copyright ownership. + 2. Conveying Modified Versions. -Exhibit B - "Incompatible With Secondary Licenses" Notice + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: -This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or ---------------------------------------------------------- + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. ---------------------------------------------------------- + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: -NetMQ 4.0.0.1 - OTHER + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + + + SPECIAL EXCEPTION GRANTED BY COPYRIGHT HOLDERS + +As a special exception, copyright holders give you permission to link this +library with independent modules to produce an executable, regardless of +the license terms of these independent modules, and to copy and distribute +the resulting executable under terms of your choice, provided that you also +meet, for each linked independent module, the terms and conditions of +the license of that module. An independent module is a module which is not +derived from or based on this library. If you modify this library, you must +extend this exception to your version of the library. -OTHER --------------------------------------------------------- From 05a50fdf1fd8b3708e7511dd623de96a11458a13 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Wed, 5 Oct 2022 23:58:16 -0700 Subject: [PATCH 63/66] Updating Notice.txt for all components (#633) --- NOTICE.txt | 570 +++++++++++++++++++++++++---------------------------- 1 file changed, 271 insertions(+), 299 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 1a3683322de..9227769ffc0 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -6643,371 +6643,343 @@ AsyncIO 0.1.69 - MPL-2.0 -Mozilla Public License, version 2.0 +Mozilla Public License Version 2.0 -1. Definitions + 1. Definitions -1.1. "Contributor" + 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. + 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. -1.2. "Contributor Version" + 1.3. "Contribution" means Covered Software of a particular Contributor. - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor's Contribution. + 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. -1.3. "Contribution" + 1.5. "Incompatible With Secondary Licenses" means - means Covered Software of a particular Contributor. + (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or -1.4. "Covered Software" + (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. + 1.6. "Executable Form" means any form of the work other than Source Code Form. -1.5. "Incompatible With Secondary Licenses" - means + 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or + 1.8. "License" means this document. - b. that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the terms of - a Secondary License. + 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. -1.6. "Executable Form" + 1.10. "Modifications" means any of the following: - means any form of the work other than Source Code Form. + (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or -1.7. "Larger Work" + (b) any new file in Source Code Form that contains any Covered Software. - means a work that combines Covered Software with other material, in a - separate file or files, that is not Covered Software. + 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. -1.8. "License" + 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. - means this document. + 1.13. "Source Code Form" means the form of the work preferred for making modifications. -1.9. "Licensable" + 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. - means having the right to grant, to the maximum extent possible, whether - at the time of the initial grant or subsequently, any and all of the - rights conveyed by this License. + 2. License Grants and Conditions -1.10. "Modifications" + 2.1. Grants - means any of the following: + Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: - a. any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered Software; or + (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and - b. any new file in Source Code Form that contains any Covered Software. + (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. -1.11. "Patent Claims" of a Contributor + 2.2. Effective Date - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the License, - by the making, using, selling, offering for sale, having made, import, - or transfer of either its Contributions or its Contributor Version. + The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. -1.12. "Secondary License" + 2.3. Limitations on Grant Scope - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. + The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: -1.13. "Source Code Form" + (a) for any code that a Contributor has removed from Covered Software; or - means the form of the work preferred for making modifications. + (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or -1.14. "You" (or "Your") + (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, "control" means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. + This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). + 2.4. Subsequent Licenses -2. License Grants and Conditions + No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). -2.1. Grants + 2.5. Representation - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: + Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and + 2.6. Fair Use - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. + This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. -2.2. Effective Date + 2.7. Conditions - The licenses granted in Section 2.1 with respect to any Contribution - become effective for each Contribution on the date the Contributor first - distributes such Contribution. + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. -2.3. Limitations on Grant Scope + 3. Responsibilities - The licenses granted in this Section 2 are the only rights granted under - this License. No additional rights or licenses will be implied from the - distribution or licensing of Covered Software under this License. - Notwithstanding Section 2.1(b) above, no patent license is granted by a - Contributor: + 3.1. Distribution of Source Form - a. for any code that a Contributor has removed from Covered Software; or + All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. - b. for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or + 3.2. Distribution of Executable Form - c. under Patent Claims infringed by Covered Software in the absence of - its Contributions. + If You distribute Covered Software in Executable Form then: - This License does not grant any rights in the trademarks, service marks, - or logos of any Contributor (except as may be necessary to comply with - the notice requirements in Section 3.4). + (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and -2.4. Subsequent Licenses + (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this - License (see Section 10.2) or under the terms of a Secondary License (if - permitted under the terms of Section 3.3). + 3.3. Distribution of a Larger Work -2.5. Representation + You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). - Each Contributor represents that the Contributor believes its - Contributions are its original creation(s) or it has sufficient rights to - grant the rights to its Contributions conveyed by this License. + 3.4. Notices -2.6. Fair Use + You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. - This License is not intended to limit any rights You have under - applicable copyright doctrines of fair use, fair dealing, or other - equivalents. + 3.5. Application of Additional Terms -2.7. Conditions + You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. + 4. Inability to Comply Due to Statute or Regulation + If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. -3. Responsibilities + 5. Termination -3.1. Distribution of Source Form + 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under - the terms of this License. You must inform recipients that the Source - Code Form of the Covered Software is governed by the terms of this - License, and how they can obtain a copy of this License. You may not - attempt to alter or restrict the recipients' rights in the Source Code - Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter the - recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for - the Covered Software. If the Larger Work is a combination of Covered - Software with a work governed by one or more Secondary Licenses, and the - Covered Software is not Incompatible With Secondary Licenses, this - License permits You to additionally distribute such Covered Software - under the terms of such Secondary License(s), so that the recipient of - the Larger Work may, at their option, further distribute the Covered - Software under the terms of either this License or such Secondary - License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices - (including copyright notices, patent notices, disclaimers of warranty, or - limitations of liability) contained within the Source Code Form of the - Covered Software, except that You may alter any license notices to the - extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on - behalf of any Contributor. You must make it absolutely clear that any - such warranty, support, indemnity, or liability obligation is offered by - You alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, - judicial order, or regulation then You must: (a) comply with the terms of - this License to the maximum extent possible; and (b) describe the - limitations and the code they affect. Such description must be placed in a - text file included with all distributions of the Covered Software under - this License. Except to the extent prohibited by statute or regulation, - such description must be sufficiently detailed for a recipient of ordinary - skill to be able to understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing - basis, if such Contributor fails to notify You of the non-compliance by - some reasonable means prior to 60 days after You have come back into - compliance. Moreover, Your grants from a particular Contributor are - reinstated on an ongoing basis if such Contributor notifies You of the - non-compliance by some reasonable means, this is the first time You have - received notice of non-compliance with this License from such - Contributor, and You become compliant prior to 30 days after Your receipt - of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, - counter-claims, and cross-claims) alleging that a Contributor Version - directly or indirectly infringes any patent, then the rights granted to - You by any and all Contributors for the Covered Software under Section - 2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an "as is" basis, - without warranty of any kind, either expressed, implied, or statutory, - including, without limitation, warranties that the Covered Software is free - of defects, merchantable, fit for a particular purpose or non-infringing. - The entire risk as to the quality and performance of the Covered Software - is with You. Should any Covered Software prove defective in any respect, - You (not any Contributor) assume the cost of any necessary servicing, - repair, or correction. This disclaimer of warranty constitutes an essential - part of this License. No use of any Covered Software is authorized under - this License except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from - such party's negligence to the extent applicable law prohibits such - limitation. Some jurisdictions do not allow the exclusion or limitation of - incidental or consequential damages, so this exclusion and limitation may - not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts - of a jurisdiction where the defendant maintains its principal place of - business and such litigation shall be governed by laws of that - jurisdiction, without reference to its conflict-of-law provisions. Nothing - in this Section shall prevent a party's ability to bring cross-claims or - counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. Any law or regulation which provides that - the language of a contract shall be construed against the drafter shall not - be used to construe this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version - of the License under which You originally received the Covered Software, - or under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a - modified version of this License if you rename the license and remove - any references to the name of the license steward (except to note that - such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary - Licenses If You choose to distribute Source Code Form that is - Incompatible With Secondary Licenses under the terms of this version of - the License, the notice described in Exhibit B of this License must be - attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, -then You may include the notice in a location (such as a LICENSE file in a -relevant directory) where a recipient would be likely to look for such a -notice. + 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. + + 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. + + 6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer. + + 7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You. + + 8. Litigation + + Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. + + 9. Miscellaneous + + This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. + + 10. Versions of the License + + 10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. + + 10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. + + 10.3. Modified Versions + + If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). + + 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses + + If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice + +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. You may add additional accurate notices of copyright ownership. Exhibit B - "Incompatible With Secondary Licenses" Notice - This Source Code Form is "Incompatible - With Secondary Licenses", as defined by - the Mozilla Public License, v. 2.0. +This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. + +--------------------------------------------------------- --------------------------------------------------------- +NaCl.Net 0.1.13 - MPL-2.0 + + + +Mozilla Public License Version 2.0 + + 1. Definitions + + 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. + + 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. + + 1.3. "Contribution" means Covered Software of a particular Contributor. + + 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. + + 1.5. "Incompatible With Secondary Licenses" means + + (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. + + 1.6. "Executable Form" means any form of the work other than Source Code Form. + + 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. + + 1.8. "License" means this document. + + 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. + + 1.10. "Modifications" means any of the following: + + (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or + + (b) any new file in Source Code Form that contains any Covered Software. + + 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. + + 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. + + 1.13. "Source Code Form" means the form of the work preferred for making modifications. + + 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. + + 2. License Grants and Conditions + + 2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and + + (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. + + 2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. + + 2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: + + (a) for any code that a Contributor has removed from Covered Software; or + + (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or + + (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. + + This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). + + 2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). + + 2.5. Representation + + Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. + + 2.6. Fair Use + + This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. + + 2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. + + 3. Responsibilities + + 3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. + + 3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and + + (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. + + 3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). + + 3.4. Notices + + You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. + + 3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. + + 4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. + + 5. Termination + + 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. + + 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. + + 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. + + 6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer. + + 7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You. + + 8. Litigation + + Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. + + 9. Miscellaneous + + This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. + + 10. Versions of the License + + 10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. + + 10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. + + 10.3. Modified Versions + + If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). + + 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses + + If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice + +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice + +This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. + +--------------------------------------------------------- --------------------------------------------------------- NetMQ 4.0.1.9 - OTHER From 60bc2f9376024912cce9cae5f8ade459dd5538e9 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Mon, 10 Oct 2022 13:42:48 -0700 Subject: [PATCH 64/66] Updating QDK version to 0.26.233415. (#634) --- Build/props/tests.props | 2 +- Chemistry/src/Runtime/Runtime.csproj | 4 ++-- Chemistry/tests/ChemistryTests/QSharpTests.csproj | 2 +- Chemistry/tests/SystemTests/SystemTests.csproj | 2 +- MachineLearning/src/MachineLearning.csproj | 2 +- MachineLearning/tests/MachineLearningTests.csproj | 2 +- Numerics/src/Numerics.csproj | 4 ++-- Numerics/tests/NumericsTests.csproj | 2 +- Standard/src/Standard.csproj | 6 +++--- Standard/tests/Standard.Tests.csproj | 2 +- Visualization/src/Visualization.csproj | 4 ++-- global.json | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Build/props/tests.props b/Build/props/tests.props index 623981f02ee..68caced6041 100644 --- a/Build/props/tests.props +++ b/Build/props/tests.props @@ -7,7 +7,7 @@ - + diff --git a/Chemistry/src/Runtime/Runtime.csproj b/Chemistry/src/Runtime/Runtime.csproj index 268051208f6..22e010c4e33 100644 --- a/Chemistry/src/Runtime/Runtime.csproj +++ b/Chemistry/src/Runtime/Runtime.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -40,7 +40,7 @@ - + diff --git a/Chemistry/tests/ChemistryTests/QSharpTests.csproj b/Chemistry/tests/ChemistryTests/QSharpTests.csproj index 65a75e166e5..90639d57a80 100644 --- a/Chemistry/tests/ChemistryTests/QSharpTests.csproj +++ b/Chemistry/tests/ChemistryTests/QSharpTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Chemistry/tests/SystemTests/SystemTests.csproj b/Chemistry/tests/SystemTests/SystemTests.csproj index d6e3c0f01f4..9c9dd7126fb 100644 --- a/Chemistry/tests/SystemTests/SystemTests.csproj +++ b/Chemistry/tests/SystemTests/SystemTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/MachineLearning/src/MachineLearning.csproj b/MachineLearning/src/MachineLearning.csproj index a96bc1de318..912e444310d 100644 --- a/MachineLearning/src/MachineLearning.csproj +++ b/MachineLearning/src/MachineLearning.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Microsoft.Quantum.MachineLearning diff --git a/MachineLearning/tests/MachineLearningTests.csproj b/MachineLearning/tests/MachineLearningTests.csproj index 935d0842b9d..7d5212774b9 100644 --- a/MachineLearning/tests/MachineLearningTests.csproj +++ b/MachineLearning/tests/MachineLearningTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Numerics/src/Numerics.csproj b/Numerics/src/Numerics.csproj index 361e8fd77d7..bd51e90e31f 100644 --- a/Numerics/src/Numerics.csproj +++ b/Numerics/src/Numerics.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -41,7 +41,7 @@ - + diff --git a/Numerics/tests/NumericsTests.csproj b/Numerics/tests/NumericsTests.csproj index 9daa12dfead..a4f39659b3a 100644 --- a/Numerics/tests/NumericsTests.csproj +++ b/Numerics/tests/NumericsTests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Standard/src/Standard.csproj b/Standard/src/Standard.csproj index 32ee5624d3a..37f020569da 100644 --- a/Standard/src/Standard.csproj +++ b/Standard/src/Standard.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -38,8 +38,8 @@ - - + + diff --git a/Standard/tests/Standard.Tests.csproj b/Standard/tests/Standard.Tests.csproj index f6c7615a93b..29464e24fed 100644 --- a/Standard/tests/Standard.Tests.csproj +++ b/Standard/tests/Standard.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/Visualization/src/Visualization.csproj b/Visualization/src/Visualization.csproj index 7c917b84563..9b01eb5bdf4 100644 --- a/Visualization/src/Visualization.csproj +++ b/Visualization/src/Visualization.csproj @@ -32,9 +32,9 @@ - + - + diff --git a/global.json b/global.json index b2d8f34ce1d..ffbdc6ad5a1 100644 --- a/global.json +++ b/global.json @@ -4,6 +4,6 @@ "rollForward": "latestMinor" }, "msbuild-sdks": { - "Microsoft.Quantum.Sdk": "0.25.228311" + "Microsoft.Quantum.Sdk": "0.26.233415" } } From 4558a7c8e6ee8d4c8871b1d4749c1085c1f92a8f Mon Sep 17 00:00:00 2001 From: Guang Hao Low Date: Thu, 20 Oct 2022 14:12:51 -0700 Subject: [PATCH 65/66] Gulow/broombridge 0.3 (#637) * Fix fourfold symmetry bugs * Add unit test * Update datamodel tests for v0.3 --- Chemistry.sln | 27 +++++--- .../OrbitalIntegral/OrbitalIntegral.cs | 62 ++++++++++--------- .../OrbitalIntegralExtensions.cs | 25 ++------ .../BroombridgeDataStructurev0.1.cs | 6 +- .../BroombridgeDataStructurev0.3.cs | 28 ++++++--- .../Serialization/LegacyFormats/FciDump.cs | 2 +- .../FermionHamiltonianTests.cs | 22 +++---- .../SerializationTests/LiQuiDTests.cs | 23 +++---- .../SamplesTests/DocsSecondQuantization.cs | 21 +++++++ 9 files changed, 123 insertions(+), 93 deletions(-) diff --git a/Chemistry.sln b/Chemistry.sln index 227549c7bb3..a4681332336 100644 --- a/Chemistry.sln +++ b/Chemistry.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28803.156 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentation", "{561759D2-4D2D-4EE3-9565-9AAEC4A7D64B}" ProjectSection(SolutionItems) = preProject @@ -24,23 +24,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Standard", "Standard\src\St EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BroombridgeExamples", "BroombridgeExamples", "{F25F3396-EDE5-4A9F-A428-643EB138F00F}" ProjectSection(SolutionItems) = preProject - Chemistry\tests\BroombridgeExamples\broombridge_v0.1.yaml = Chemistry\tests\BroombridgeExamples\broombridge_v0.1.yaml - Chemistry\tests\BroombridgeExamples\broombridge_v0.2.yaml = Chemistry\tests\BroombridgeExamples\broombridge_v0.2.yaml - Chemistry\tests\BroombridgeExamples\hydrogen_0.1.yaml = Chemistry\tests\BroombridgeExamples\hydrogen_0.1.yaml - Chemistry\tests\BroombridgeExamples\hydrogen_0.2.yaml = Chemistry\tests\BroombridgeExamples\hydrogen_0.2.yaml - Chemistry\tests\BroombridgeExamples\LiH_0.1.yaml = Chemistry\tests\BroombridgeExamples\LiH_0.1.yaml - Chemistry\tests\BroombridgeExamples\LiH_0.2.yaml = Chemistry\tests\BroombridgeExamples\LiH_0.2.yaml + Chemistry\tests\TestData\Broombridge\broombridge_v0.1.yaml = Chemistry\tests\TestData\Broombridge\broombridge_v0.1.yaml + Chemistry\tests\TestData\Broombridge\broombridge_v0.2.yaml = Chemistry\tests\TestData\Broombridge\broombridge_v0.2.yaml + Chemistry\tests\TestData\Broombridge\hydrogen_0.1.yaml = Chemistry\tests\TestData\Broombridge\hydrogen_0.1.yaml + Chemistry\tests\TestData\Broombridge\hydrogen_0.2.yaml = Chemistry\tests\TestData\Broombridge\hydrogen_0.2.yaml + Chemistry\tests\TestData\Broombridge\LiH_0.1.yaml = Chemistry\tests\TestData\Broombridge\LiH_0.1.yaml + Chemistry\tests\TestData\Broombridge\LiH_0.2.yaml = Chemistry\tests\TestData\Broombridge\LiH_0.2.yaml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamplesTests", "Chemistry\tests\SamplesTests\SamplesTests.csproj", "{2A0E61DB-7187-4359-B5C7-C30FCB1D6800}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metapackage", "Chemistry\src\Metapackage\Metapackage.csproj", "{E8268248-FC5B-4F4E-82FF-5C8CC40950BB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Metapackage", "Chemistry\src\Metapackage\Metapackage.csproj", "{E8268248-FC5B-4F4E-82FF-5C8CC40950BB}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chemistry", "Chemistry", "{43A9F607-5884-4CB9-A455-01E98F5532E2}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{812F2D11-792D-4305-8427-01B632A92299}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tools", "Chemistry\src\Tools\Tools.csproj", "{3EF5845F-B348-4DC9-A905-23A6FB9AB421}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools", "Chemistry\src\Tools\Tools.csproj", "{3EF5845F-B348-4DC9-A905-23A6FB9AB421}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataModelTests", "Chemistry\tests\DataModelTests\DataModelTests.csproj", "{B86DDA60-44F0-4C05-837E-CEA84DBCADF7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -80,6 +82,10 @@ Global {3EF5845F-B348-4DC9-A905-23A6FB9AB421}.Debug|Any CPU.Build.0 = Debug|Any CPU {3EF5845F-B348-4DC9-A905-23A6FB9AB421}.Release|Any CPU.ActiveCfg = Release|Any CPU {3EF5845F-B348-4DC9-A905-23A6FB9AB421}.Release|Any CPU.Build.0 = Release|Any CPU + {B86DDA60-44F0-4C05-837E-CEA84DBCADF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B86DDA60-44F0-4C05-837E-CEA84DBCADF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B86DDA60-44F0-4C05-837E-CEA84DBCADF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B86DDA60-44F0-4C05-837E-CEA84DBCADF7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -93,6 +99,7 @@ Global {E8268248-FC5B-4F4E-82FF-5C8CC40950BB} = {F561BE56-63D8-4C33-A3B3-CF2685BC7A5C} {812F2D11-792D-4305-8427-01B632A92299} = {43A9F607-5884-4CB9-A455-01E98F5532E2} {3EF5845F-B348-4DC9-A905-23A6FB9AB421} = {812F2D11-792D-4305-8427-01B632A92299} + {B86DDA60-44F0-4C05-837E-CEA84DBCADF7} = {595D5855-8820-48D7-B5E1-9C88215A866A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6869E5BF-551A-40F1-9B6B-D1B27A5676CB} diff --git a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs index 43fa2e39c0f..a6a15d1b6f5 100644 --- a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs +++ b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegral.cs @@ -45,6 +45,11 @@ public enum PermutationSymmetry /// public double Coefficient; + /// + /// Symmetry of the orbital overlap integral. + /// + public PermutationSymmetry Symmetry = PermutationSymmetry.Eightfold; + /// /// Parameterless constructors. Sets this as an empty OrbitalIntegral with coefficient 0.0 /// @@ -52,10 +57,10 @@ public OrbitalIntegral() : this(0.0) { } - public OrbitalIntegral(double coefficient) + /// coefficient of orbital integral. + /// Convention of symmetry of orbital indices. + public OrbitalIntegral(double coefficient, PermutationSymmetry symmetry = PermutationSymmetry.Eightfold) : this(new int[] { }, coefficient, symmetry) { - OrbitalIndices = new int[] { }; - Coefficient = coefficient; } /// @@ -63,10 +68,12 @@ public OrbitalIntegral(double coefficient) /// /// Array of orbital indices in Dirac notation. /// coefficient of orbital integral. - public OrbitalIntegral(IEnumerable orbitalIndices, double coefficient = 0.0) + /// Convention of symmetry of orbital indices. + public OrbitalIntegral(IEnumerable orbitalIndices, double coefficient = 0.0, PermutationSymmetry symmetry = PermutationSymmetry.Eightfold) { OrbitalIndices = orbitalIndices.ToArray(); Coefficient = coefficient; + Symmetry = symmetry; } /// @@ -75,10 +82,12 @@ public OrbitalIntegral(IEnumerable orbitalIndices, double coefficient = 0.0 /// Array of orbital indices. /// coefficient of orbital integral. /// Convention for ordering of orbital indices. - public OrbitalIntegral(IEnumerable orbitalIndices, double coefficient, Convention convention = Convention.Mulliken) + /// Convention of symmetry of orbital indices. + public OrbitalIntegral(IEnumerable orbitalIndices, double coefficient, PermutationSymmetry symmetry, Convention convention = Convention.Mulliken) { OrbitalIndices = ConvertIndices(orbitalIndices, convention, Convention.Dirac); Coefficient = coefficient; + Symmetry = symmetry; } public TermType.OrbitalIntegral TermType @@ -121,11 +130,13 @@ public void ResetSign() private static int[][] EnumerateTwoBodyPermutations(PermutationSymmetry symmetry, int i, int j, int k, int l) => symmetry switch { + // In Mulliken notation, // (ij|kl) = (ij|lk) = (ji|kl) = (ji|lk) = // (kl|ij) = (lk|ij) = (kl|ji) = (lk|ji) + // Orbital indices are in Dirac notation. PermutationSymmetry.Eightfold => new int[][] { - new int[] { i, j, k, l }, // 0123 + new int[] { i, j, k, l }, // 0123 new int[] { j, i, l, k }, // 1032 new int[] { k, l, i, j }, // 2301 new int[] { l, k, j, i }, // 3210 @@ -134,13 +145,15 @@ symmetry switch new int[] { j, l, i, k }, // 1302 new int[] { l, j, k, i } // 3120 }, + // In Mulliken notation, // (ij|kl) = (ji|lk) = (kl|ij) = (lk|ji) + // Orbital indices are in Dirac notation. PermutationSymmetry.Fourfold => new int[][] { - new int[] { i, j, k, l }, - new int[] { j, i, l, k }, - new int[] { k, l, i, j }, - new int[] { l, k, j, i } + new int[] { i, j, k, l }, // Identity + new int[] { l, k, j, i }, // Complex conjugation + new int[] { j, i, l, k }, // Change of variables + new int[] { k, l, i, j }, // Complex conjugation & Change of variables }, PermutationSymmetry.Trivial => new int[][] { @@ -149,11 +162,6 @@ symmetry switch _ => throw new Exception($"Permutation symmetry {symmetry} is not valid for two-body permutations.") }; - [Obsolete("Permutation symmetries must be specified explicitly as of Broombridge 0.3.", false)] - public OrbitalIntegral[] EnumerateOrbitalSymmetries() => - EnumerateOrbitalSymmetries(PermutationSymmetry.Eightfold); - - /// /// Enumerates over all orbital integrals with the same coefficient /// as this. @@ -162,7 +170,7 @@ symmetry switch /// - Orbitals are assumed to be real. /// /// Array of orbital integrals with the same coefficient. - public OrbitalIntegral[] EnumerateOrbitalSymmetries(PermutationSymmetry symmetry) + public OrbitalIntegral[] EnumerateOrbitalSymmetries() { var coefficient = Coefficient; if (OrbitalIndices.Length == 2) @@ -174,13 +182,13 @@ public OrbitalIntegral[] EnumerateOrbitalSymmetries(PermutationSymmetry symmetry new int[] {i, j}, new int[] {j, i} }; - return symmetries.Distinct(new ArrayEqualityComparer()).Select(o => new OrbitalIntegral(o, coefficient)).ToArray(); + return symmetries.Distinct(new ArrayEqualityComparer()).Select(o => new OrbitalIntegral(o, coefficient, Symmetry)).ToArray(); } else if (OrbitalIndices.Length == 4) { - return EnumerateTwoBodyPermutations(symmetry, OrbitalIndices[0], OrbitalIndices[1], OrbitalIndices[2], OrbitalIndices[3]) + return EnumerateTwoBodyPermutations(Symmetry, OrbitalIndices[0], OrbitalIndices[1], OrbitalIndices[2], OrbitalIndices[3]) .Distinct(new ArrayEqualityComparer()) - .Select(o => new OrbitalIntegral(o, coefficient)).ToArray(); + .Select(o => new OrbitalIntegral(o, coefficient, Symmetry)).ToArray(); } else { @@ -194,23 +202,19 @@ public OrbitalIntegral[] EnumerateOrbitalSymmetries(PermutationSymmetry symmetry public OrbitalIntegral Clone() { var newArray = OrbitalIndices.Clone(); - return new OrbitalIntegral(newArray, Coefficient); + return new OrbitalIntegral(newArray, Coefficient, Symmetry); } - [Obsolete("Permutation symmetries must be specified explicitly as of Broombridge 0.3.", false)] - public OrbitalIntegral ToCanonicalForm() => - ToCanonicalForm(PermutationSymmetry.Eightfold); - /// /// Returns orbital indices sorted in a canonical form that generates /// the same set of orbital integrals through . /// /// An in canonical form. - public OrbitalIntegral ToCanonicalForm(PermutationSymmetry symmetry) + public OrbitalIntegral ToCanonicalForm() { - var symmetries = EnumerateOrbitalSymmetries(symmetry).Select(o => o.OrbitalIndices).ToList(); + var symmetries = EnumerateOrbitalSymmetries().Select(o => o.OrbitalIndices).ToList(); symmetries.Sort(new ArrayLexicographicComparer()); - return new OrbitalIntegral(symmetries.First(), Coefficient); + return new OrbitalIntegral(symmetries.First(), Coefficient, Symmetry); } /// @@ -219,11 +223,11 @@ public OrbitalIntegral ToCanonicalForm(PermutationSymmetry symmetry) /// Returns if the orbital integral indices are canonically sorted /// and false otherwise. /// - public bool IsInCanonicalOrder(PermutationSymmetry symmetry) + public bool IsInCanonicalOrder() { if (Length == 2 || Length == 4) { - var canonicalOrder = ToCanonicalForm(symmetry); + var canonicalOrder = ToCanonicalForm(); return canonicalOrder.OrbitalIndices.SequenceEqual(OrbitalIndices); } else diff --git a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs index cc48cf5324d..0b00361a622 100644 --- a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs +++ b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs @@ -20,16 +20,6 @@ namespace Microsoft.Quantum.Chemistry.OrbitalIntegrals /// public static partial class Extensions { - internal static OrbitalIntegral.PermutationSymmetry FromBroombridgeV0_3(this Broombridge.V0_3.PermutationSymmetry symmetry) => - symmetry switch - { - Broombridge.V0_3.PermutationSymmetry.Eightfold => OrbitalIntegral.PermutationSymmetry.Eightfold, - Broombridge.V0_3.PermutationSymmetry.Fourfold => OrbitalIntegral.PermutationSymmetry.Fourfold, - Broombridge.V0_3.PermutationSymmetry.Trivial => OrbitalIntegral.PermutationSymmetry.Trivial, - _ => throw new Exception($"Broombridge v0.3 permutation symmetry kind {symmetry} is not supported.") - }; - - /// /// Method for constructing a fermion Hamiltonian from an orbital integral Hamiltonian. /// @@ -43,10 +33,7 @@ symmetry switch var nOrbitals = sourceHamiltonian.SystemIndices.Max() + 1; var hamiltonian = new FermionHamiltonian(); Func> conversion = - // NB: We use a trivial symmetry here, as the symmetry is already resolved - // when constructing the orbital integral Hamiltonian initially. - // See https://github.com/microsoft/QuantumLibraries/blob/eecc1b6c100af0ceffbe2c25eda3a9b5158febdf/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs#L524. - (orb, coeff) => new OrbitalIntegral(orb.OrbitalIndices, coeff).ToHermitianFermionTerms(nOrbitals, OrbitalIntegral.PermutationSymmetry.Trivial, indexConvention) + (orb, coeff) => new OrbitalIntegral(orb.OrbitalIndices, coeff, orb.Symmetry).ToHermitianFermionTerms(nOrbitals, indexConvention) .Select(o => (o.Item1, o.Item2.ToDoubleCoeff())); foreach (var termType in sourceHamiltonian.Terms) @@ -72,7 +59,6 @@ symmetry switch public static IEnumerable<(HermitianFermionTerm, double)> ToHermitianFermionTerms( this OrbitalIntegral orbitalIntegral, int nOrbitals, - OrbitalIntegral.PermutationSymmetry symmetry, IndexConvention indexConvention = IndexConvention.UpDown) { var termType = orbitalIntegral.TermType; @@ -82,7 +68,7 @@ symmetry switch } else if (termType == TermType.OrbitalIntegral.TwoBody) { - return orbitalIntegral.ToTwoBodySpinOrbitalTerms(nOrbitals, indexConvention, symmetry); + return orbitalIntegral.ToTwoBodySpinOrbitalTerms(nOrbitals, indexConvention); } else if(termType == TermType.OrbitalIntegral.Identity) { @@ -109,7 +95,7 @@ symmetry switch // One-electron orbital integral symmetries // ij = ji var pqSpinOrbitals = orbitalIntegral - .EnumerateOrbitalSymmetries(OrbitalIntegral.PermutationSymmetry.Eightfold) + .EnumerateOrbitalSymmetries() .EnumerateSpinOrbitals(); var coefficient = orbitalIntegral.Coefficient; @@ -139,12 +125,11 @@ symmetry switch private static IEnumerable<(HermitianFermionTerm, double)> ToTwoBodySpinOrbitalTerms( this OrbitalIntegral orbitalIntegral, int nOrbitals, - IndexConvention indexConvention, - OrbitalIntegral.PermutationSymmetry symmetry) + IndexConvention indexConvention) { // Two-electron orbital integral symmetries // ijkl = lkji = jilk = klij = ikjl = ljki = kilj = jlik. - var pqrsSpinOrbitals = orbitalIntegral.EnumerateOrbitalSymmetries(symmetry).EnumerateSpinOrbitals(); + var pqrsSpinOrbitals = orbitalIntegral.EnumerateOrbitalSymmetries().EnumerateSpinOrbitals(); var coefficient = orbitalIntegral.Coefficient; diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs index b3d68d045af..f4d08591a55 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.1.cs @@ -92,7 +92,7 @@ internal static class BroombridgeExtensionsV0_1 ConvertIndices( term .Key - .ToCanonicalForm(OrbitalIntegral.PermutationSymmetry.Eightfold) + .ToCanonicalForm() .OrbitalIndices, OrbitalIntegral.Convention.Dirac, OrbitalIntegral.Convention.Mulliken @@ -386,7 +386,7 @@ public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer) hamiltonian.Add (hamiltonianData.OneElectronIntegrals.Values .Select(o => new OrbitalIntegral(o.Item1 - .Select(k => (int)(k - 1)), o.Item2, OrbitalIntegral.Convention.Mulliken) + .Select(k => (int)(k - 1)), o.Item2, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Mulliken) .ToCanonicalForm()) .Distinct()); @@ -395,7 +395,7 @@ public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer) hamiltonian.Add (hamiltonianData.TwoElectronIntegrals.Values .Select(o => new OrbitalIntegral(o.Item1 - .Select(k => (int)(k - 1)), o.Item2, OrbitalIntegral.Convention.Mulliken) + .Select(k => (int)(k - 1)), o.Item2, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Mulliken) .ToCanonicalForm()) .Distinct()); diff --git a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs index 41a5c08d8ad..2857ad795c3 100644 --- a/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs +++ b/Chemistry/src/DataModel/Serialization/Broombridge/BroombridgeDataStructurev0.3.cs @@ -104,8 +104,8 @@ internal static V0_3.HamiltonianData ToBroombridgeV0_3(this OrbitalIntegralHamil .Terms[TermType.OrbitalIntegral.TwoBody] .ToBroombridgeV0_3(new V0_3.Symmetry { - // List terms explicitly with no compression. - Permutation = V0_3.PermutationSymmetry.Trivial + // Broombridge v0.2 and below assumes Eightfold symmetry. + Permutation = V0_3.PermutationSymmetry.Eightfold }); twoElectronIntegrals.IndexConvention = OrbitalIntegral.Convention.Mulliken; return new V0_3.HamiltonianData @@ -114,8 +114,9 @@ internal static V0_3.HamiltonianData ToBroombridgeV0_3(this OrbitalIntegralHamil .Terms[TermType.OrbitalIntegral.OneBody] .ToBroombridgeV0_3(new V0_3.Symmetry { - // List terms explicitly with no compression. - Permutation = V0_3.PermutationSymmetry.Trivial + // Broombridge v0.2 and below assumes Eightfold symmetry, + // which for one-body terms means h_{pq} = h_{qp}. + Permutation = V0_3.PermutationSymmetry.Eightfold }) .TransformKeys(idxs => (idxs[0], idxs[1])), TwoElectronIntegrals = twoElectronIntegrals @@ -136,7 +137,7 @@ V0_3.Symmetry symmetry var idxs = ConvertIndices( term .Key - .ToCanonicalForm(symmetry.Permutation.Value.FromBroombridgeV0_3()) + .ToCanonicalForm() .OrbitalIndices, OrbitalIntegral.Convention.Dirac, OrbitalIntegral.Convention.Mulliken @@ -477,6 +478,15 @@ public enum PermutationSymmetry Trivial } + internal static OrbitalIntegral.PermutationSymmetry ParseOrbitalIntegralSymmetry(PermutationSymmetry symmetry) => + symmetry switch + { + PermutationSymmetry.Eightfold => OrbitalIntegral.PermutationSymmetry.Eightfold, + PermutationSymmetry.Fourfold => OrbitalIntegral.PermutationSymmetry.Fourfold, + PermutationSymmetry.Trivial => OrbitalIntegral.PermutationSymmetry.Trivial, + _ => throw new Exception($"Broombridge v0.3 permutation symmetry kind {symmetry} is not supported.") + }; + public struct Symmetry { [YamlMember(Alias = "permutation")] @@ -506,9 +516,10 @@ internal static OrbitalIntegralHamiltonian ToOrbitalIntegralHamiltonian(ProblemD new OrbitalIntegral( o.Key.Select(k => (int)(k - 1)).ToArray(), o.Value, + OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Mulliken ) - .ToCanonicalForm(PermutationSymmetry.Eightfold.FromBroombridgeV0_3())) + .ToCanonicalForm()) .Distinct()); // This will convert from Broombridge 1-indexing to 0-indexing. @@ -519,9 +530,10 @@ internal static OrbitalIntegralHamiltonian ToOrbitalIntegralHamiltonian(ProblemD new OrbitalIntegral( o.Key.Select(k => (int)(k - 1)).ToArray(), o.Value, - OrbitalIntegral.Convention.Mulliken + ParseOrbitalIntegralSymmetry(hamiltonianData.TwoElectronIntegrals.Symmetry.Permutation.Value), + OrbitalIntegral.Convention.Mulliken ) - .ToCanonicalForm(hamiltonianData.TwoElectronIntegrals.Symmetry.Permutation.Value.FromBroombridgeV0_3())) + .ToCanonicalForm()) .Distinct()); hamiltonian.Add(new OrbitalIntegral(), identityterm); diff --git a/Chemistry/src/DataModel/Serialization/LegacyFormats/FciDump.cs b/Chemistry/src/DataModel/Serialization/LegacyFormats/FciDump.cs index 12f90f24d2c..c68a328c6d8 100644 --- a/Chemistry/src/DataModel/Serialization/LegacyFormats/FciDump.cs +++ b/Chemistry/src/DataModel/Serialization/LegacyFormats/FciDump.cs @@ -79,7 +79,7 @@ public static IEnumerable Deserialize(TextReader rea .SelectMaybe( row => row.Item2.Length % 2 == 0 ? new OrbitalIntegral( - row.Item2, row.Item1, OrbitalIntegral.Convention.Mulliken + row.Item2, row.Item1, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Mulliken ).ToCanonicalForm() : null ) diff --git a/Chemistry/tests/DataModelTests/FermionTermTests/FermionHamiltonianTests.cs b/Chemistry/tests/DataModelTests/FermionTermTests/FermionHamiltonianTests.cs index f95658a87be..1f8a0beda83 100644 --- a/Chemistry/tests/DataModelTests/FermionTermTests/FermionHamiltonianTests.cs +++ b/Chemistry/tests/DataModelTests/FermionTermTests/FermionHamiltonianTests.cs @@ -148,55 +148,55 @@ public void JsonEncoding() public static IEnumerable OrbitalsData => new List { - new object[] { new OrbitalIntegral(new[] {0,0 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PP, + new object[] { new OrbitalIntegral(new[] {0,0 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PP, new (int, int[], double)[] { (1, new[] { 0, 0 }, 1.0 ), (1, new[] { 1, 1 }, 1.0 )}}, - new object[] { new OrbitalIntegral(new[] {0,1 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQ, + new object[] { new OrbitalIntegral(new[] {0,1 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQ, new (int, int[], double)[] { (2, new[] { 0, 1 }, 2.0 ), (2, new[] { 2, 3 }, 2.0 )}}, - new object[] { new OrbitalIntegral(new[] {0,1,1,0 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQP, + new object[] { new OrbitalIntegral(new[] {0,1,1,0 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQP, new (int, int[], double)[] { (2, new[] { 0, 1, 1, 0 }, 1.0 ), (2, new[] { 2, 3, 3, 2 }, 1.0 ), (2, new[] { 0, 3, 3, 0 }, 1.0 ), (2, new[] { 1, 2, 2, 1 }, 1.0 )}}, - new object[] { new OrbitalIntegral(new[] {0,1,0,1 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQP, + new object[] { new OrbitalIntegral(new[] {0,1,0,1 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQP, new (int, int[], double)[] { (2, new[] { 0, 1, 1, 0 }, -1.0 ), (2, new[] { 2, 3, 3, 2 }, -1.0 ), } }, - new object[] { new OrbitalIntegral(new[] {0,1,0,1 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, + new object[] { new OrbitalIntegral(new[] {0,1,0,1 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, new (int, int[], double)[] { (2, new[] { 0, 3, 2, 1 }, 2.0 ), (2, new[] { 0, 2, 3, 1 }, 2.0 ) } }, - new object[] { new OrbitalIntegral(new[] {0,1,0,0 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQR, + new object[] { new OrbitalIntegral(new[] {0,1,0,0 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQR, new (int, int[], double)[] { (2, new[] { 0, 2, 2, 1 }, 2.0 ), (2, new[] { 0, 2, 3, 0 }, 2.0 ), } }, - new object[] {new OrbitalIntegral(new[] {0,0,1,2 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQR, + new object[] {new OrbitalIntegral(new[] {0,0,1,2 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQR, new (int, int[], double)[] { (3, new[] { 0, 1, 2, 0 }, -2.0 ), (3, new[] { 3, 4, 5, 3 }, -2.0 ), } }, - new object[] { new OrbitalIntegral(new[] {0,0,1,2 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, + new object[] { new OrbitalIntegral(new[] {0,0,1,2 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, new (int, int[], double)[] { (3, new[] { 0, 3, 4, 2 }, 2.0 ), (3, new[] { 0, 3, 5, 1 }, 2.0 ), (3, new[] { 0, 4, 3, 2 }, 2.0 ), (3, new[] { 0, 5, 3, 1 }, 2.0 ), } }, - new object[] { new OrbitalIntegral(new[] {0,1,2,0 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQR, + new object[] { new OrbitalIntegral(new[] {0,1,2,0 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQQR, new (int, int[], double)[] { (3, new[] { 0, 1, 2, 0 }, 2.0 ), (3, new[] { 1, 3, 3, 2 }, 2.0 ), (3, new[] { 0, 4, 5, 0 }, 2.0 ), (3, new[] { 3, 4, 5, 3 }, 2.0 ), } }, - new object[] { new OrbitalIntegral(new[] {0,1,2,3 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, + new object[] { new OrbitalIntegral(new[] {0,1,2,3 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, new (int, int[], double)[] { (4, new[] { 0, 5, 6, 3 }, 2.0 ), (4, new[] { 0, 6, 5, 3 }, 2.0 ), @@ -207,7 +207,7 @@ public void JsonEncoding() (4, new[] { 0, 2, 3, 1 }, -2.0 ), (4, new[] { 1, 7, 4, 2 }, 2.0 ), } }, - new object[] { new OrbitalIntegral(new[] {3,1,0,2 },1.0, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, + new object[] { new OrbitalIntegral(new[] {3,1,0,2 },1.0, OrbitalIntegral.PermutationSymmetry.Eightfold, OrbitalIntegral.Convention.Dirac), TermType.Fermion.PQRS, new (int, int[], double)[] { (4, new[] { 2, 4, 5, 3 }, 2.0 ), (4, new[] { 0, 6, 7, 1 }, 2.0 ), diff --git a/Chemistry/tests/DataModelTests/SerializationTests/LiQuiDTests.cs b/Chemistry/tests/DataModelTests/SerializationTests/LiQuiDTests.cs index 9a6ef795e53..81f166c3970 100644 --- a/Chemistry/tests/DataModelTests/SerializationTests/LiQuiDTests.cs +++ b/Chemistry/tests/DataModelTests/SerializationTests/LiQuiDTests.cs @@ -19,6 +19,7 @@ namespace Microsoft.Quantum.Chemistry.Tests { using static TermType.OrbitalIntegral; using static OrbitalIntegral.Convention; + using static OrbitalIntegral.PermutationSymmetry; public class LoadFromLiquidTests @@ -44,17 +45,17 @@ public void LoadFromLiquidTest(string line, TermType.OrbitalIntegral termType, O public static IEnumerable LiquidOrbitalsData => new List { - new object[] { "0,0=1.0", OneBody, new OrbitalIntegral(new[] {0,0},1.0, Dirac) }, - new object[] { "0,1=1.0", OneBody, new OrbitalIntegral(new[] {0,1},1.0, Dirac) }, - new object[] { "0,1,1,0=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,1,0},1.0, Dirac) }, - new object[] { "0,1,0,1=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,0,1},1.0, Dirac) }, - new object[] { "0,1,0,1=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,0,1},1.0, Dirac) }, - new object[] { "0,1,0,0=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,0,0},1.0, Dirac) }, - new object[] { "0,0,1,2=1.0", TwoBody, new OrbitalIntegral(new[] {0,0,1,2},1.0, Dirac) }, - new object[] { "0,0,1,2=1.0", TwoBody, new OrbitalIntegral(new[] {0,0,1,2},1.0, Dirac) }, - new object[] { "0,1,2,0=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,2,0},1.0, Dirac) }, - new object[] { "0,1,2,3=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,2,3},1.0, Dirac) }, - new object[] { "3,1,0,2=1.0", TwoBody, new OrbitalIntegral(new[] {3,1,0,2},1.0, Dirac) } + new object[] { "0,0=1.0", OneBody, new OrbitalIntegral(new[] {0,0},1.0, Eightfold, Dirac) }, + new object[] { "0,1=1.0", OneBody, new OrbitalIntegral(new[] {0,1},1.0, Eightfold, Dirac) }, + new object[] { "0,1,1,0=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,1,0},1.0, Eightfold, Dirac) }, + new object[] { "0,1,0,1=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,0,1},1.0, Eightfold, Dirac) }, + new object[] { "0,1,0,1=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,0,1},1.0, Eightfold, Dirac) }, + new object[] { "0,1,0,0=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,0,0},1.0, Eightfold, Dirac) }, + new object[] { "0,0,1,2=1.0", TwoBody, new OrbitalIntegral(new[] {0,0,1,2},1.0, Eightfold, Dirac) }, + new object[] { "0,0,1,2=1.0", TwoBody, new OrbitalIntegral(new[] {0,0,1,2},1.0, Eightfold, Dirac) }, + new object[] { "0,1,2,0=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,2,0},1.0, Eightfold, Dirac) }, + new object[] { "0,1,2,3=1.0", TwoBody, new OrbitalIntegral(new[] {0,1,2,3},1.0, Eightfold, Dirac) }, + new object[] { "3,1,0,2=1.0", TwoBody, new OrbitalIntegral(new[] {3,1,0,2},1.0, Eightfold, Dirac) } }; diff --git a/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs b/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs index 3c0e44bfc8c..12e86fac133 100644 --- a/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs +++ b/Chemistry/tests/SamplesTests/DocsSecondQuantization.cs @@ -297,6 +297,27 @@ static void MakeAnotherOrbitalIntegral() } + [Fact] + static void MakeOrbitalIntegralFourFoldSymmetry() + { + // We create a `OrbitalIntegral` object to store a two-electron molecular + // orbital integral data with four-fold symmetry. + var twoElectronIntegral = new OrbitalIntegral(new[] { 0, 1, 2, 3 }, 0.123,OrbitalIntegral.PermutationSymmetry.Fourfold); + + // This enumerates all two-electron integrals with the same coefficient -- + // an array of equivalent `OrbitalIntegral` instances is generated. In + // this case, there are 4 elements. + var twoElectronIntegrals = twoElectronIntegral.EnumerateOrbitalSymmetries(); + + Assert.Equal(4, twoElectronIntegrals.Count()); + + // These orbital indices should all be equivalent + foreach (OrbitalIntegral integral in twoElectronIntegrals) + { + Assert.Equal(integral.ToCanonicalForm().OrbitalIndices, twoElectronIntegral.ToCanonicalForm().OrbitalIndices); + } + } + [Fact] static void MakeHamiltonian() { From 0b82e62d162ceebd56ae0bc84a9a48dcad162e87 Mon Sep 17 00:00:00 2001 From: Guang Hao Low Date: Mon, 24 Oct 2022 18:32:31 -0700 Subject: [PATCH 66/66] Propgage symmetry when adding otbital integral terms to Hamiltonian. --- Chemistry.sln | 2 + .../OrbitalIntegralExtensions.cs | 1 - .../OrbitalIntegralHamiltonian.cs | 2 +- .../DataModelTests/DataModelTests.csproj | 8 +- .../OrbitalIntegralTests.cs | 38 + .../SerializationTests/BroombridgeTests.cs | 36 + .../Broombridge/H2O-6_fourfold_v0.3.yaml | 1006 +++++++++++++++++ .../Broombridge/H2O-6_trivial_v0.3.yaml | 1006 +++++++++++++++++ .../qsharp-chemistry-0.0.0.1.tar.gz | Bin 0 -> 5280 bytes .../qsharp_chemistry-0.0.0.1-py3-none-any.whl | Bin 0 -> 5491 bytes Python/qsharp/qsharp-0.0.0.1-py3-none-any.whl | Bin 0 -> 2145 bytes Python/qsharp/qsharp-0.0.0.1.tar.gz | Bin 0 -> 2671 bytes 12 files changed, 2096 insertions(+), 3 deletions(-) create mode 100644 Chemistry/tests/TestData/Broombridge/H2O-6_fourfold_v0.3.yaml create mode 100644 Chemistry/tests/TestData/Broombridge/H2O-6_trivial_v0.3.yaml create mode 100644 Python/qsharp-chemistry/qsharp-chemistry-0.0.0.1.tar.gz create mode 100644 Python/qsharp-chemistry/qsharp_chemistry-0.0.0.1-py3-none-any.whl create mode 100644 Python/qsharp/qsharp-0.0.0.1-py3-none-any.whl create mode 100644 Python/qsharp/qsharp-0.0.0.1.tar.gz diff --git a/Chemistry.sln b/Chemistry.sln index a4681332336..1f1ba8612d8 100644 --- a/Chemistry.sln +++ b/Chemistry.sln @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BroombridgeExamples", "Broo ProjectSection(SolutionItems) = preProject Chemistry\tests\TestData\Broombridge\broombridge_v0.1.yaml = Chemistry\tests\TestData\Broombridge\broombridge_v0.1.yaml Chemistry\tests\TestData\Broombridge\broombridge_v0.2.yaml = Chemistry\tests\TestData\Broombridge\broombridge_v0.2.yaml + Chemistry\tests\TestData\Broombridge\H2O-6_fourfold_v0.3.yaml = Chemistry\tests\TestData\Broombridge\H2O-6_fourfold_v0.3.yaml + Chemistry\tests\TestData\Broombridge\H2O-6_trivial_v0.3.yaml = Chemistry\tests\TestData\Broombridge\H2O-6_trivial_v0.3.yaml Chemistry\tests\TestData\Broombridge\hydrogen_0.1.yaml = Chemistry\tests\TestData\Broombridge\hydrogen_0.1.yaml Chemistry\tests\TestData\Broombridge\hydrogen_0.2.yaml = Chemistry\tests\TestData\Broombridge\hydrogen_0.2.yaml Chemistry\tests\TestData\Broombridge\LiH_0.1.yaml = Chemistry\tests\TestData\Broombridge\LiH_0.1.yaml diff --git a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs index 0b00361a622..0148a9e21c3 100644 --- a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs +++ b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralExtensions.cs @@ -48,7 +48,6 @@ public static partial class Extensions return hamiltonian; } - /// /// Creates all fermion terms generated by all symmetries of an orbital integral. /// diff --git a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralHamiltonian.cs b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralHamiltonian.cs index 2e746bb6da5..581db84a31a 100644 --- a/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralHamiltonian.cs +++ b/Chemistry/src/DataModel/OrbitalIntegral/OrbitalIntegralHamiltonian.cs @@ -32,7 +32,7 @@ public OrbitalIntegralHamiltonian(IEnumerable terms) : base() /// Orbital integral to add to Hamiltonian. public void Add(OrbitalIntegral orbitalIntegral) { - Add(new OrbitalIntegral(orbitalIntegral.OrbitalIndices), orbitalIntegral.Coefficient); + Add(new OrbitalIntegral(orbitalIntegral.OrbitalIndices, symmetry: orbitalIntegral.Symmetry), orbitalIntegral.Coefficient); } /// diff --git a/Chemistry/tests/DataModelTests/DataModelTests.csproj b/Chemistry/tests/DataModelTests/DataModelTests.csproj index 0853e952b36..1f86c83d434 100644 --- a/Chemistry/tests/DataModelTests/DataModelTests.csproj +++ b/Chemistry/tests/DataModelTests/DataModelTests.csproj @@ -42,7 +42,7 @@ - + PreserveNewest @@ -52,6 +52,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + diff --git a/Chemistry/tests/DataModelTests/OrbitalIntegralTests/OrbitalIntegralTests.cs b/Chemistry/tests/DataModelTests/OrbitalIntegralTests/OrbitalIntegralTests.cs index 1ab7e38ee29..193a8021f97 100644 --- a/Chemistry/tests/DataModelTests/OrbitalIntegralTests/OrbitalIntegralTests.cs +++ b/Chemistry/tests/DataModelTests/OrbitalIntegralTests/OrbitalIntegralTests.cs @@ -63,5 +63,43 @@ public void OrbitalIntegralIndexTest() Assert.True(orb0 == orb1); Assert.False(orb0 == orb2); } + + // Test fourfold symmetry + [Theory] + [InlineData(0, 0, 0, 0, 1)] + [InlineData(0, 0, 0, 1, 4)] + [InlineData(0, 0, 1, 0, 4)] + [InlineData(0, 1, 0, 0, 4)] + [InlineData(1, 0, 0, 0, 4)] + [InlineData(1, 1, 0, 0, 2)] + [InlineData(0, 1, 1, 0, 2)] + [InlineData(0, 0, 1, 2, 4)] + [InlineData(0, 1, 2, 0, 4)] + [InlineData(0, 1, 2, 3, 4)] + public void OrbitalIntegralEnumerateOrbitalSymmetriesFourfoldTest(int i, int j, int k, int l, int elements) + { + OrbitalIntegral orbitalIntegral = new OrbitalIntegral(new int[] { i, j, k, l }, 0.0, OrbitalIntegral.PermutationSymmetry.Fourfold); + var orbitalIntegrals = orbitalIntegral.EnumerateOrbitalSymmetries(); + Assert.Equal(elements, orbitalIntegrals.Length); + } + + // Test trivial symmetry + [Theory] + [InlineData(0, 0, 0, 0, 1)] + [InlineData(0, 0, 0, 1, 1)] + [InlineData(0, 0, 1, 0, 1)] + [InlineData(0, 1, 0, 0, 1)] + [InlineData(1, 0, 0, 0, 1)] + [InlineData(1, 1, 0, 0, 1)] + [InlineData(0, 1, 1, 0, 1)] + [InlineData(0, 0, 1, 2, 1)] + [InlineData(0, 1, 2, 0, 1)] + [InlineData(0, 1, 2, 3, 1)] + public void OrbitalIntegralEnumerateOrbitalSymmetriesTrivialTest(int i, int j, int k, int l, int elements) + { + OrbitalIntegral orbitalIntegral = new OrbitalIntegral(new int[] { i, j, k, l }, 0.0, OrbitalIntegral.PermutationSymmetry.Trivial); + var orbitalIntegrals = orbitalIntegral.EnumerateOrbitalSymmetries(); + Assert.Equal(elements, orbitalIntegrals.Length); + } } } \ No newline at end of file diff --git a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs index f81cb53cdf5..bda8201a88e 100644 --- a/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs +++ b/Chemistry/tests/DataModelTests/SerializationTests/BroombridgeTests.cs @@ -8,10 +8,13 @@ using System.Linq; using Microsoft.Quantum.Chemistry.Broombridge; +using Microsoft.Quantum.Chemistry.Fermion; +using Microsoft.Quantum.Chemistry.OrbitalIntegrals; using Newtonsoft.Json; using Xunit; +using YamlDotNet.Core.Tokens; namespace Microsoft.Quantum.Chemistry.Tests { @@ -139,4 +142,37 @@ public void JsonEncoding() Assert.Equal(original.Schema, serialized.Schema); } } + + + public class Broombridgev0_3Tests + { + public string Filename_trivial_symmetry = "Broombridge/H2O-6_trivial_v0.3.yaml"; + public string Filename_fourfold_symmetry = "Broombridge/H2O-6_fourfold_v0.3.yaml"; + + + // Check that fully expanded trivial and fourfold symmetries lead to the same Hamiltonian. + [Fact] + public void DeserializeVersionNumbers() + { + var broombridge_trivial = Deserializers.Deserialize(Filename_trivial_symmetry); + var broombridge_fourfold = Deserializers.Deserialize(Filename_fourfold_symmetry); + + var trivial_Hamiltonian = V0_3.ToOrbitalIntegralHamiltonian(broombridge_trivial.ProblemDescriptions.Single()); + var fourfold_Hamiltonian = V0_3.ToOrbitalIntegralHamiltonian(broombridge_fourfold.ProblemDescriptions.Single()); + + FermionHamiltonian x = trivial_Hamiltonian.ToFermionHamiltonian(); + FermionHamiltonian y = fourfold_Hamiltonian.ToFermionHamiltonian(); + foreach(var termType in y.Terms) + { + foreach (var term in termType.Value) + { + y.Terms[termType.Key][term.Key] = -term.Value; + } + } + + x.AddHamiltonian(y); + + Assert.Equal(x.Norm(), 0.0); + } + } } diff --git a/Chemistry/tests/TestData/Broombridge/H2O-6_fourfold_v0.3.yaml b/Chemistry/tests/TestData/Broombridge/H2O-6_fourfold_v0.3.yaml new file mode 100644 index 00000000000..8cf5b3b4234 --- /dev/null +++ b/Chemistry/tests/TestData/Broombridge/H2O-6_fourfold_v0.3.yaml @@ -0,0 +1,1006 @@ +"$schema": https://raw.githubusercontent.com/Microsoft/Quantum/master/Chemistry/Schema/broombridge-0.3.schema.json + +bibliography: +- {url: 'https://doi.org/10.48550/arXiv.2201.01257'} +format: {version: '0.3'} +problem_description: +- basis_set: {name: cc-pvdz, type: gaussian} + coulomb_repulsion: {units: hartree, value: 9.189534427591418} + energy_offset: {units: hartree, value: 0.0} + fci_energy: {lower: 0.0, units: hartree, upper: 0.0, value: 0.0} + geometry: + atoms: + - coords: [0.0, 0.0, 0.1173] + name: O + - coords: [0.0, 0.7572, -0.4692] + name: H + - coords: [0.0, -0.7572, -0.4692] + name: H + coordinate_system: cartesian + symmetry: C1 + units: angstrom + hamiltonian: + one_electron_integrals: + format: sparse + units: hartree + values: + - key: [1, 1] + value: -33.027197577299994 + - key: [1, 2] + value: -0.5819703916 + - key: [1, 4] + value: -0.18711222209999998 + - key: [1, 6] + value: 0.178897367 + - key: [2, 1] + value: -0.5819703916 + - key: [2, 2] + value: -7.8574375802 + - key: [2, 4] + value: -0.2416100102 + - key: [2, 6] + value: 0.8205910853 + - key: [3, 3] + value: -6.6802839478 + - key: [4, 1] + value: -0.18711222209999998 + - key: [4, 2] + value: -0.2416100102 + - key: [4, 4] + value: -6.9164495014 + - key: [4, 6] + value: -0.4325175718 + - key: [5, 5] + value: -7.0842606806 + - key: [6, 1] + value: 0.178897367 + - key: [6, 2] + value: 0.8205910853 + - key: [6, 4] + value: -0.4325175718 + - key: [6, 6] + value: -3.3633460066 + two_electron_integrals: + format: sparse + index_convention: mulliken + symmetry: {permutation: fourfold} + units: hartree + values: + - key: [1, 1, 1, 1] + value: 4.7389920091 + - key: [1, 1, 1, 2] + value: 0.4316471044 + - key: [1, 1, 1, 4] + value: 0.139835356 + - key: [1, 1, 1, 6] + value: -0.1446035916 + - key: [1, 1, 2, 1] + value: 0.4316471044 + - key: [1, 1, 2, 2] + value: 1.0467302187 + - key: [1, 1, 2, 4] + value: 0.0884260324 + - key: [1, 1, 2, 6] + value: -0.1672617384 + - key: [1, 1, 3, 3] + value: 0.8757027418 + - key: [1, 1, 4, 1] + value: 0.139835356 + - key: [1, 1, 4, 2] + value: 0.0884260324 + - key: [1, 1, 4, 4] + value: 0.9826139063 + - key: [1, 1, 4, 6] + value: 0.0769489618 + - key: [1, 1, 5, 5] + value: 1.0352624942 + - key: [1, 1, 6, 1] + value: -0.1446035916 + - key: [1, 1, 6, 2] + value: -0.1672617384 + - key: [1, 1, 6, 4] + value: 0.0769489618 + - key: [1, 1, 6, 6] + value: 0.4091524574 + - key: [1, 2, 1, 1] + value: 0.4316471044 + - key: [1, 2, 1, 2] + value: 0.0616039968 + - key: [1, 2, 1, 4] + value: 0.0170066336 + - key: [1, 2, 1, 6] + value: -0.0232123364 + - key: [1, 2, 2, 1] + value: 0.0638469782 + - key: [1, 2, 2, 2] + value: 0.0147095395 + - key: [1, 2, 2, 4] + value: 0.0078363372 + - key: [1, 2, 2, 6] + value: -0.002454583 + - key: [1, 2, 3, 3] + value: 0.0065772294 + - key: [1, 2, 4, 1] + value: 0.0167766846 + - key: [1, 2, 4, 2] + value: 0.0081165775 + - key: [1, 2, 4, 4] + value: 0.0128731668 + - key: [1, 2, 4, 6] + value: -0.0010592476 + - key: [1, 2, 5, 5] + value: 0.011493053 + - key: [1, 2, 6, 1] + value: -0.0246428629 + - key: [1, 2, 6, 2] + value: -0.0010864284 + - key: [1, 2, 6, 4] + value: -0.0013917344 + - key: [1, 2, 6, 6] + value: 0.0017680559 + - key: [1, 3, 1, 3] + value: 0.0166828154 + - key: [1, 3, 2, 3] + value: -0.0221783953 + - key: [1, 3, 3, 1] + value: 0.0196006449 + - key: [1, 3, 3, 2] + value: -0.0231197785 + - key: [1, 3, 3, 4] + value: -0.0030473194 + - key: [1, 3, 3, 6] + value: 0.0043572676 + - key: [1, 3, 4, 3] + value: -0.0026225249 + - key: [1, 3, 6, 3] + value: 0.0043617565 + - key: [1, 4, 1, 1] + value: 0.139835356 + - key: [1, 4, 1, 2] + value: 0.0170066336 + - key: [1, 4, 1, 4] + value: 0.0272140846 + - key: [1, 4, 1, 6] + value: 0.0008031441 + - key: [1, 4, 2, 1] + value: 0.0167766846 + - key: [1, 4, 2, 2] + value: 0.0146677206 + - key: [1, 4, 2, 4] + value: -0.0217417092 + - key: [1, 4, 2, 6] + value: -0.0090397453 + - key: [1, 4, 3, 3] + value: 0.007387959 + - key: [1, 4, 4, 1] + value: 0.0299840375 + - key: [1, 4, 4, 2] + value: -0.022508094 + - key: [1, 4, 4, 4] + value: -0.0086662352 + - key: [1, 4, 4, 6] + value: 0.0033567718 + - key: [1, 4, 5, 5] + value: 0.0045801578 + - key: [1, 4, 6, 1] + value: 0.001377367 + - key: [1, 4, 6, 2] + value: -0.0091739517 + - key: [1, 4, 6, 4] + value: 0.0028886004 + - key: [1, 4, 6, 6] + value: 0.0066603239 + - key: [1, 5, 1, 5] + value: 0.0271884177 + - key: [1, 5, 2, 5] + value: -0.0288516874 + - key: [1, 5, 4, 5] + value: -0.0090235212 + - key: [1, 5, 5, 1] + value: 0.0299152685 + - key: [1, 5, 5, 2] + value: -0.0293007731 + - key: [1, 5, 5, 4] + value: -0.0093711715 + - key: [1, 5, 5, 6] + value: 0.0076193471 + - key: [1, 5, 6, 5] + value: 0.0070498091 + - key: [1, 6, 1, 1] + value: -0.1446035916 + - key: [1, 6, 1, 2] + value: -0.0232123364 + - key: [1, 6, 1, 4] + value: 0.0008031441 + - key: [1, 6, 1, 6] + value: 0.0104990496 + - key: [1, 6, 2, 1] + value: -0.0246428629 + - key: [1, 6, 2, 2] + value: -0.0010929887 + - key: [1, 6, 2, 4] + value: -0.0092159495 + - key: [1, 6, 2, 6] + value: -0.0019197882 + - key: [1, 6, 3, 3] + value: -0.0004761759 + - key: [1, 6, 4, 1] + value: 0.001377367 + - key: [1, 6, 4, 2] + value: -0.0095546897 + - key: [1, 6, 4, 4] + value: -0.0073492828 + - key: [1, 6, 4, 6] + value: 0.0018798592 + - key: [1, 6, 5, 5] + value: -0.0025744419 + - key: [1, 6, 6, 1] + value: 0.0100582331 + - key: [1, 6, 6, 2] + value: -0.001148843 + - key: [1, 6, 6, 4] + value: 0.0012367661 + - key: [1, 6, 6, 6] + value: 0.0010071293 + - key: [2, 1, 1, 1] + value: 0.4316471044 + - key: [2, 1, 1, 2] + value: 0.0638469782 + - key: [2, 1, 1, 4] + value: 0.0167766846 + - key: [2, 1, 1, 6] + value: -0.0246428629 + - key: [2, 1, 2, 1] + value: 0.0616039968 + - key: [2, 1, 2, 2] + value: 0.0147095395 + - key: [2, 1, 2, 4] + value: 0.0081165775 + - key: [2, 1, 2, 6] + value: -0.0010864284 + - key: [2, 1, 3, 3] + value: 0.0065772294 + - key: [2, 1, 4, 1] + value: 0.0170066336 + - key: [2, 1, 4, 2] + value: 0.0078363372 + - key: [2, 1, 4, 4] + value: 0.0128731668 + - key: [2, 1, 4, 6] + value: -0.0013917344 + - key: [2, 1, 5, 5] + value: 0.011493053 + - key: [2, 1, 6, 1] + value: -0.0232123364 + - key: [2, 1, 6, 2] + value: -0.002454583 + - key: [2, 1, 6, 4] + value: -0.0010592476 + - key: [2, 1, 6, 6] + value: 0.0017680559 + - key: [2, 2, 1, 1] + value: 1.0467302187 + - key: [2, 2, 1, 2] + value: 0.0147095395 + - key: [2, 2, 1, 4] + value: 0.0146677206 + - key: [2, 2, 1, 6] + value: -0.0010929887 + - key: [2, 2, 2, 1] + value: 0.0147095395 + - key: [2, 2, 2, 2] + value: 0.7459919427 + - key: [2, 2, 2, 4] + value: -0.0168158772 + - key: [2, 2, 2, 6] + value: -0.0962292596 + - key: [2, 2, 3, 3] + value: 0.6722147818 + - key: [2, 2, 4, 1] + value: 0.0146677206 + - key: [2, 2, 4, 2] + value: -0.0168158772 + - key: [2, 2, 4, 4] + value: 0.674550755 + - key: [2, 2, 4, 6] + value: 0.0488525301 + - key: [2, 2, 5, 5] + value: 0.70774557 + - key: [2, 2, 6, 1] + value: -0.0010929887 + - key: [2, 2, 6, 2] + value: -0.0962292596 + - key: [2, 2, 6, 4] + value: 0.0488525301 + - key: [2, 2, 6, 6] + value: 0.3677403255 + - key: [2, 3, 1, 3] + value: -0.0221783953 + - key: [2, 3, 2, 3] + value: 0.1439192313 + - key: [2, 3, 3, 1] + value: -0.0231197785 + - key: [2, 3, 3, 2] + value: 0.1487607073 + - key: [2, 3, 3, 4] + value: -0.0154338337 + - key: [2, 3, 3, 6] + value: -0.0027892125 + - key: [2, 3, 4, 3] + value: -0.0164191585 + - key: [2, 3, 6, 3] + value: -0.0018370861 + - key: [2, 4, 1, 1] + value: 0.0884260324 + - key: [2, 4, 1, 2] + value: 0.0078363372 + - key: [2, 4, 1, 4] + value: -0.0217417092 + - key: [2, 4, 1, 6] + value: -0.0092159495 + - key: [2, 4, 2, 1] + value: 0.0081165775 + - key: [2, 4, 2, 2] + value: -0.0168158772 + - key: [2, 4, 2, 4] + value: 0.1176240209 + - key: [2, 4, 2, 6] + value: 0.0175061567 + - key: [2, 4, 3, 3] + value: -0.0123799239 + - key: [2, 4, 4, 1] + value: -0.022508094 + - key: [2, 4, 4, 2] + value: 0.1224416506 + - key: [2, 4, 4, 4] + value: 0.0690613663 + - key: [2, 4, 4, 6] + value: 0.0006158001 + - key: [2, 4, 5, 5] + value: 0.0367349258 + - key: [2, 4, 6, 1] + value: -0.0095546897 + - key: [2, 4, 6, 2] + value: 0.0179834246 + - key: [2, 4, 6, 4] + value: 0.0009394053 + - key: [2, 4, 6, 6] + value: -0.0302865102 + - key: [2, 5, 1, 5] + value: -0.0288516874 + - key: [2, 5, 2, 5] + value: 0.1210151285 + - key: [2, 5, 4, 5] + value: 0.0297249972 + - key: [2, 5, 5, 1] + value: -0.0293007731 + - key: [2, 5, 5, 2] + value: 0.1251534778 + - key: [2, 5, 5, 4] + value: 0.0300346914 + - key: [2, 5, 5, 6] + value: -0.0234680664 + - key: [2, 5, 6, 5] + value: -0.0216941823 + - key: [2, 6, 1, 1] + value: -0.1672617384 + - key: [2, 6, 1, 2] + value: -0.002454583 + - key: [2, 6, 1, 4] + value: -0.0090397453 + - key: [2, 6, 1, 6] + value: -0.0019197882 + - key: [2, 6, 2, 1] + value: -0.0010864284 + - key: [2, 6, 2, 2] + value: -0.0962292596 + - key: [2, 6, 2, 4] + value: 0.0175061567 + - key: [2, 6, 2, 6] + value: 0.0394645048 + - key: [2, 6, 3, 3] + value: -0.0697594153 + - key: [2, 6, 4, 1] + value: -0.0091739517 + - key: [2, 6, 4, 2] + value: 0.0179834246 + - key: [2, 6, 4, 4] + value: -0.0645496877 + - key: [2, 6, 4, 6] + value: -0.0219155062 + - key: [2, 6, 5, 5] + value: -0.0870774079 + - key: [2, 6, 6, 1] + value: -0.001148843 + - key: [2, 6, 6, 2] + value: 0.032432543 + - key: [2, 6, 6, 4] + value: -0.0177919004 + - key: [2, 6, 6, 6] + value: -0.0171335527 + - key: [3, 1, 1, 3] + value: 0.0196006449 + - key: [3, 1, 2, 3] + value: -0.0231197785 + - key: [3, 1, 3, 1] + value: 0.0166828154 + - key: [3, 1, 3, 2] + value: -0.0221783953 + - key: [3, 1, 3, 4] + value: -0.0026225249 + - key: [3, 1, 3, 6] + value: 0.0043617565 + - key: [3, 1, 4, 3] + value: -0.0030473194 + - key: [3, 1, 6, 3] + value: 0.0043572676 + - key: [3, 2, 1, 3] + value: -0.0231197785 + - key: [3, 2, 2, 3] + value: 0.1487607073 + - key: [3, 2, 3, 1] + value: -0.0221783953 + - key: [3, 2, 3, 2] + value: 0.1439192313 + - key: [3, 2, 3, 4] + value: -0.0164191585 + - key: [3, 2, 3, 6] + value: -0.0018370861 + - key: [3, 2, 4, 3] + value: -0.0154338337 + - key: [3, 2, 6, 3] + value: -0.0027892125 + - key: [3, 3, 1, 1] + value: 0.8757027418 + - key: [3, 3, 1, 2] + value: 0.0065772294 + - key: [3, 3, 1, 4] + value: 0.007387959 + - key: [3, 3, 1, 6] + value: -0.0004761759 + - key: [3, 3, 2, 1] + value: 0.0065772294 + - key: [3, 3, 2, 2] + value: 0.6722147818 + - key: [3, 3, 2, 4] + value: -0.0123799239 + - key: [3, 3, 2, 6] + value: -0.0697594153 + - key: [3, 3, 3, 3] + value: 0.6438382812 + - key: [3, 3, 4, 1] + value: 0.007387959 + - key: [3, 3, 4, 2] + value: -0.0123799239 + - key: [3, 3, 4, 4] + value: 0.5959262868 + - key: [3, 3, 4, 6] + value: 0.0325101489 + - key: [3, 3, 5, 5] + value: 0.613223063 + - key: [3, 3, 6, 1] + value: -0.0004761759 + - key: [3, 3, 6, 2] + value: -0.0697594153 + - key: [3, 3, 6, 4] + value: 0.0325101489 + - key: [3, 3, 6, 6] + value: 0.3586509025 + - key: [3, 4, 1, 3] + value: -0.0030473194 + - key: [3, 4, 2, 3] + value: -0.0154338337 + - key: [3, 4, 3, 1] + value: -0.0026225249 + - key: [3, 4, 3, 2] + value: -0.0164191585 + - key: [3, 4, 3, 4] + value: 0.032130949 + - key: [3, 4, 3, 6] + value: -0.0041871063 + - key: [3, 4, 4, 3] + value: 0.0376204313 + - key: [3, 4, 6, 3] + value: -0.0027502214 + - key: [3, 5, 3, 5] + value: 0.0237503555 + - key: [3, 5, 5, 3] + value: 0.0289508433 + - key: [3, 6, 1, 3] + value: 0.0043572676 + - key: [3, 6, 2, 3] + value: -0.0027892125 + - key: [3, 6, 3, 1] + value: 0.0043617565 + - key: [3, 6, 3, 2] + value: -0.0018370861 + - key: [3, 6, 3, 4] + value: -0.0041871063 + - key: [3, 6, 3, 6] + value: 0.0245522836 + - key: [3, 6, 4, 3] + value: -0.0027502214 + - key: [3, 6, 6, 3] + value: 0.0200647031 + - key: [4, 1, 1, 1] + value: 0.139835356 + - key: [4, 1, 1, 2] + value: 0.0167766846 + - key: [4, 1, 1, 4] + value: 0.0299840375 + - key: [4, 1, 1, 6] + value: 0.001377367 + - key: [4, 1, 2, 1] + value: 0.0170066336 + - key: [4, 1, 2, 2] + value: 0.0146677206 + - key: [4, 1, 2, 4] + value: -0.022508094 + - key: [4, 1, 2, 6] + value: -0.0091739517 + - key: [4, 1, 3, 3] + value: 0.007387959 + - key: [4, 1, 4, 1] + value: 0.0272140846 + - key: [4, 1, 4, 2] + value: -0.0217417092 + - key: [4, 1, 4, 4] + value: -0.0086662352 + - key: [4, 1, 4, 6] + value: 0.0028886004 + - key: [4, 1, 5, 5] + value: 0.0045801578 + - key: [4, 1, 6, 1] + value: 0.0008031441 + - key: [4, 1, 6, 2] + value: -0.0090397453 + - key: [4, 1, 6, 4] + value: 0.0033567718 + - key: [4, 1, 6, 6] + value: 0.0066603239 + - key: [4, 2, 1, 1] + value: 0.0884260324 + - key: [4, 2, 1, 2] + value: 0.0081165775 + - key: [4, 2, 1, 4] + value: -0.022508094 + - key: [4, 2, 1, 6] + value: -0.0095546897 + - key: [4, 2, 2, 1] + value: 0.0078363372 + - key: [4, 2, 2, 2] + value: -0.0168158772 + - key: [4, 2, 2, 4] + value: 0.1224416506 + - key: [4, 2, 2, 6] + value: 0.0179834246 + - key: [4, 2, 3, 3] + value: -0.0123799239 + - key: [4, 2, 4, 1] + value: -0.0217417092 + - key: [4, 2, 4, 2] + value: 0.1176240209 + - key: [4, 2, 4, 4] + value: 0.0690613663 + - key: [4, 2, 4, 6] + value: 0.0009394053 + - key: [4, 2, 5, 5] + value: 0.0367349258 + - key: [4, 2, 6, 1] + value: -0.0092159495 + - key: [4, 2, 6, 2] + value: 0.0175061567 + - key: [4, 2, 6, 4] + value: 0.0006158001 + - key: [4, 2, 6, 6] + value: -0.0302865102 + - key: [4, 3, 1, 3] + value: -0.0026225249 + - key: [4, 3, 2, 3] + value: -0.0164191585 + - key: [4, 3, 3, 1] + value: -0.0030473194 + - key: [4, 3, 3, 2] + value: -0.0154338337 + - key: [4, 3, 3, 4] + value: 0.0376204313 + - key: [4, 3, 3, 6] + value: -0.0027502214 + - key: [4, 3, 4, 3] + value: 0.032130949 + - key: [4, 3, 6, 3] + value: -0.0041871063 + - key: [4, 4, 1, 1] + value: 0.9826139063 + - key: [4, 4, 1, 2] + value: 0.0128731668 + - key: [4, 4, 1, 4] + value: -0.0086662352 + - key: [4, 4, 1, 6] + value: -0.0073492828 + - key: [4, 4, 2, 1] + value: 0.0128731668 + - key: [4, 4, 2, 2] + value: 0.674550755 + - key: [4, 4, 2, 4] + value: 0.0690613663 + - key: [4, 4, 2, 6] + value: -0.0645496877 + - key: [4, 4, 3, 3] + value: 0.5959262868 + - key: [4, 4, 4, 1] + value: -0.0086662352 + - key: [4, 4, 4, 2] + value: 0.0690613663 + - key: [4, 4, 4, 4] + value: 0.7102351206 + - key: [4, 4, 4, 6] + value: 0.04867595 + - key: [4, 4, 5, 5] + value: 0.654436878 + - key: [4, 4, 6, 1] + value: -0.0073492828 + - key: [4, 4, 6, 2] + value: -0.0645496877 + - key: [4, 4, 6, 4] + value: 0.04867595 + - key: [4, 4, 6, 6] + value: 0.3413097466 + - key: [4, 5, 1, 5] + value: -0.0090235212 + - key: [4, 5, 2, 5] + value: 0.0297249972 + - key: [4, 5, 4, 5] + value: 0.0363022632 + - key: [4, 5, 5, 1] + value: -0.0093711715 + - key: [4, 5, 5, 2] + value: 0.0300346914 + - key: [4, 5, 5, 4] + value: 0.0411648761 + - key: [4, 5, 5, 6] + value: 0.0011172499 + - key: [4, 5, 6, 5] + value: 0.00135636 + - key: [4, 6, 1, 1] + value: 0.0769489618 + - key: [4, 6, 1, 2] + value: -0.0010592476 + - key: [4, 6, 1, 4] + value: 0.0033567718 + - key: [4, 6, 1, 6] + value: 0.0018798592 + - key: [4, 6, 2, 1] + value: -0.0013917344 + - key: [4, 6, 2, 2] + value: 0.0488525301 + - key: [4, 6, 2, 4] + value: 0.0006158001 + - key: [4, 6, 2, 6] + value: -0.0219155062 + - key: [4, 6, 3, 3] + value: 0.0325101489 + - key: [4, 6, 4, 1] + value: 0.0028886004 + - key: [4, 6, 4, 2] + value: 0.0009394053 + - key: [4, 6, 4, 4] + value: 0.04867595 + - key: [4, 6, 4, 6] + value: 0.0205293025 + - key: [4, 6, 5, 5] + value: 0.0434854311 + - key: [4, 6, 6, 1] + value: 0.0012367661 + - key: [4, 6, 6, 2] + value: -0.0177919004 + - key: [4, 6, 6, 4] + value: 0.0187224135 + - key: [4, 6, 6, 6] + value: 0.0010454473 + - key: [5, 1, 1, 5] + value: 0.0299152685 + - key: [5, 1, 2, 5] + value: -0.0293007731 + - key: [5, 1, 4, 5] + value: -0.0093711715 + - key: [5, 1, 5, 1] + value: 0.0271884177 + - key: [5, 1, 5, 2] + value: -0.0288516874 + - key: [5, 1, 5, 4] + value: -0.0090235212 + - key: [5, 1, 5, 6] + value: 0.0070498091 + - key: [5, 1, 6, 5] + value: 0.0076193471 + - key: [5, 2, 1, 5] + value: -0.0293007731 + - key: [5, 2, 2, 5] + value: 0.1251534778 + - key: [5, 2, 4, 5] + value: 0.0300346914 + - key: [5, 2, 5, 1] + value: -0.0288516874 + - key: [5, 2, 5, 2] + value: 0.1210151285 + - key: [5, 2, 5, 4] + value: 0.0297249972 + - key: [5, 2, 5, 6] + value: -0.0216941823 + - key: [5, 2, 6, 5] + value: -0.0234680664 + - key: [5, 3, 3, 5] + value: 0.0289508433 + - key: [5, 3, 5, 3] + value: 0.0237503555 + - key: [5, 4, 1, 5] + value: -0.0093711715 + - key: [5, 4, 2, 5] + value: 0.0300346914 + - key: [5, 4, 4, 5] + value: 0.0411648761 + - key: [5, 4, 5, 1] + value: -0.0090235212 + - key: [5, 4, 5, 2] + value: 0.0297249972 + - key: [5, 4, 5, 4] + value: 0.0363022632 + - key: [5, 4, 5, 6] + value: 0.00135636 + - key: [5, 4, 6, 5] + value: 0.0011172499 + - key: [5, 5, 1, 1] + value: 1.0352624942 + - key: [5, 5, 1, 2] + value: 0.011493053 + - key: [5, 5, 1, 4] + value: 0.0045801578 + - key: [5, 5, 1, 6] + value: -0.0025744419 + - key: [5, 5, 2, 1] + value: 0.011493053 + - key: [5, 5, 2, 2] + value: 0.70774557 + - key: [5, 5, 2, 4] + value: 0.0367349258 + - key: [5, 5, 2, 6] + value: -0.0870774079 + - key: [5, 5, 3, 3] + value: 0.613223063 + - key: [5, 5, 4, 1] + value: 0.0045801578 + - key: [5, 5, 4, 2] + value: 0.0367349258 + - key: [5, 5, 4, 4] + value: 0.654436878 + - key: [5, 5, 4, 6] + value: 0.0434854311 + - key: [5, 5, 5, 5] + value: 0.7411502377 + - key: [5, 5, 6, 1] + value: -0.0025744419 + - key: [5, 5, 6, 2] + value: -0.0870774079 + - key: [5, 5, 6, 4] + value: 0.0434854311 + - key: [5, 5, 6, 6] + value: 0.3480021806 + - key: [5, 6, 1, 5] + value: 0.0076193471 + - key: [5, 6, 2, 5] + value: -0.0234680664 + - key: [5, 6, 4, 5] + value: 0.0011172499 + - key: [5, 6, 5, 1] + value: 0.0070498091 + - key: [5, 6, 5, 2] + value: -0.0216941823 + - key: [5, 6, 5, 4] + value: 0.00135636 + - key: [5, 6, 5, 6] + value: 0.0156117396 + - key: [5, 6, 6, 5] + value: 0.0116811584 + - key: [6, 1, 1, 1] + value: -0.1446035916 + - key: [6, 1, 1, 2] + value: -0.0246428629 + - key: [6, 1, 1, 4] + value: 0.001377367 + - key: [6, 1, 1, 6] + value: 0.0100582331 + - key: [6, 1, 2, 1] + value: -0.0232123364 + - key: [6, 1, 2, 2] + value: -0.0010929887 + - key: [6, 1, 2, 4] + value: -0.0095546897 + - key: [6, 1, 2, 6] + value: -0.001148843 + - key: [6, 1, 3, 3] + value: -0.0004761759 + - key: [6, 1, 4, 1] + value: 0.0008031441 + - key: [6, 1, 4, 2] + value: -0.0092159495 + - key: [6, 1, 4, 4] + value: -0.0073492828 + - key: [6, 1, 4, 6] + value: 0.0012367661 + - key: [6, 1, 5, 5] + value: -0.0025744419 + - key: [6, 1, 6, 1] + value: 0.0104990496 + - key: [6, 1, 6, 2] + value: -0.0019197882 + - key: [6, 1, 6, 4] + value: 0.0018798592 + - key: [6, 1, 6, 6] + value: 0.0010071293 + - key: [6, 2, 1, 1] + value: -0.1672617384 + - key: [6, 2, 1, 2] + value: -0.0010864284 + - key: [6, 2, 1, 4] + value: -0.0091739517 + - key: [6, 2, 1, 6] + value: -0.001148843 + - key: [6, 2, 2, 1] + value: -0.002454583 + - key: [6, 2, 2, 2] + value: -0.0962292596 + - key: [6, 2, 2, 4] + value: 0.0179834246 + - key: [6, 2, 2, 6] + value: 0.032432543 + - key: [6, 2, 3, 3] + value: -0.0697594153 + - key: [6, 2, 4, 1] + value: -0.0090397453 + - key: [6, 2, 4, 2] + value: 0.0175061567 + - key: [6, 2, 4, 4] + value: -0.0645496877 + - key: [6, 2, 4, 6] + value: -0.0177919004 + - key: [6, 2, 5, 5] + value: -0.0870774079 + - key: [6, 2, 6, 1] + value: -0.0019197882 + - key: [6, 2, 6, 2] + value: 0.0394645048 + - key: [6, 2, 6, 4] + value: -0.0219155062 + - key: [6, 2, 6, 6] + value: -0.0171335527 + - key: [6, 3, 1, 3] + value: 0.0043617565 + - key: [6, 3, 2, 3] + value: -0.0018370861 + - key: [6, 3, 3, 1] + value: 0.0043572676 + - key: [6, 3, 3, 2] + value: -0.0027892125 + - key: [6, 3, 3, 4] + value: -0.0027502214 + - key: [6, 3, 3, 6] + value: 0.0200647031 + - key: [6, 3, 4, 3] + value: -0.0041871063 + - key: [6, 3, 6, 3] + value: 0.0245522836 + - key: [6, 4, 1, 1] + value: 0.0769489618 + - key: [6, 4, 1, 2] + value: -0.0013917344 + - key: [6, 4, 1, 4] + value: 0.0028886004 + - key: [6, 4, 1, 6] + value: 0.0012367661 + - key: [6, 4, 2, 1] + value: -0.0010592476 + - key: [6, 4, 2, 2] + value: 0.0488525301 + - key: [6, 4, 2, 4] + value: 0.0009394053 + - key: [6, 4, 2, 6] + value: -0.0177919004 + - key: [6, 4, 3, 3] + value: 0.0325101489 + - key: [6, 4, 4, 1] + value: 0.0033567718 + - key: [6, 4, 4, 2] + value: 0.0006158001 + - key: [6, 4, 4, 4] + value: 0.04867595 + - key: [6, 4, 4, 6] + value: 0.0187224135 + - key: [6, 4, 5, 5] + value: 0.0434854311 + - key: [6, 4, 6, 1] + value: 0.0018798592 + - key: [6, 4, 6, 2] + value: -0.0219155062 + - key: [6, 4, 6, 4] + value: 0.0205293025 + - key: [6, 4, 6, 6] + value: 0.0010454473 + - key: [6, 5, 1, 5] + value: 0.0070498091 + - key: [6, 5, 2, 5] + value: -0.0216941823 + - key: [6, 5, 4, 5] + value: 0.00135636 + - key: [6, 5, 5, 1] + value: 0.0076193471 + - key: [6, 5, 5, 2] + value: -0.0234680664 + - key: [6, 5, 5, 4] + value: 0.0011172499 + - key: [6, 5, 5, 6] + value: 0.0116811584 + - key: [6, 5, 6, 5] + value: 0.0156117396 + - key: [6, 6, 1, 1] + value: 0.4091524574 + - key: [6, 6, 1, 2] + value: 0.0017680559 + - key: [6, 6, 1, 4] + value: 0.0066603239 + - key: [6, 6, 1, 6] + value: 0.0010071293 + - key: [6, 6, 2, 1] + value: 0.0017680559 + - key: [6, 6, 2, 2] + value: 0.3677403255 + - key: [6, 6, 2, 4] + value: -0.0302865102 + - key: [6, 6, 2, 6] + value: -0.0171335527 + - key: [6, 6, 3, 3] + value: 0.3586509025 + - key: [6, 6, 4, 1] + value: 0.0066603239 + - key: [6, 6, 4, 2] + value: -0.0302865102 + - key: [6, 6, 4, 4] + value: 0.3413097466 + - key: [6, 6, 4, 6] + value: 0.0010454473 + - key: [6, 6, 5, 5] + value: 0.3480021806 + - key: [6, 6, 6, 1] + value: 0.0010071293 + - key: [6, 6, 6, 2] + value: -0.0171335527 + - key: [6, 6, 6, 4] + value: 0.0010454473 + - key: [6, 6, 6, 6] + value: 0.3009843355 + initial_state_suggestions: + - energy: + units: hartree + value: 0.0 + label: '|G>' + method: sparse_multi_configurational + superposition: + - - 1.0 + - (1a)+ + - (2a)+ + - (3a)+ + - (4a)+ + - (5a)+ + - (1b)+ + - (2b)+ + - (3b)+ + - (4b)+ + - (5b)+ + - '|vacuum>' + metadata: {molecule_name: unknown, note: Full CCSD energy = -76.240099478499133} + n_electrons: 10 + n_orbitals: 6 + scf_energy: {units: hartree, value: -76.0267720564472} + scf_energy_offset: {units: hartree, value: 0.0} + + diff --git a/Chemistry/tests/TestData/Broombridge/H2O-6_trivial_v0.3.yaml b/Chemistry/tests/TestData/Broombridge/H2O-6_trivial_v0.3.yaml new file mode 100644 index 00000000000..0100ab0dfb8 --- /dev/null +++ b/Chemistry/tests/TestData/Broombridge/H2O-6_trivial_v0.3.yaml @@ -0,0 +1,1006 @@ +"$schema": https://raw.githubusercontent.com/Microsoft/Quantum/master/Chemistry/Schema/broombridge-0.3.schema.json + +bibliography: +- {url: 'https://doi.org/10.48550/arXiv.2201.01257'} +format: {version: '0.3'} +problem_description: +- basis_set: {name: cc-pvdz, type: gaussian} + coulomb_repulsion: {units: hartree, value: 9.189534427591418} + energy_offset: {units: hartree, value: 0.0} + fci_energy: {lower: 0.0, units: hartree, upper: 0.0, value: 0.0} + geometry: + atoms: + - coords: [0.0, 0.0, 0.1173] + name: O + - coords: [0.0, 0.7572, -0.4692] + name: H + - coords: [0.0, -0.7572, -0.4692] + name: H + coordinate_system: cartesian + symmetry: C1 + units: angstrom + hamiltonian: + one_electron_integrals: + format: sparse + units: hartree + values: + - key: [1, 1] + value: -33.027197577299994 + - key: [1, 2] + value: -0.5819703916 + - key: [1, 4] + value: -0.18711222209999998 + - key: [1, 6] + value: 0.178897367 + - key: [2, 1] + value: -0.5819703916 + - key: [2, 2] + value: -7.8574375802 + - key: [2, 4] + value: -0.2416100102 + - key: [2, 6] + value: 0.8205910853 + - key: [3, 3] + value: -6.6802839478 + - key: [4, 1] + value: -0.18711222209999998 + - key: [4, 2] + value: -0.2416100102 + - key: [4, 4] + value: -6.9164495014 + - key: [4, 6] + value: -0.4325175718 + - key: [5, 5] + value: -7.0842606806 + - key: [6, 1] + value: 0.178897367 + - key: [6, 2] + value: 0.8205910853 + - key: [6, 4] + value: -0.4325175718 + - key: [6, 6] + value: -3.3633460066 + two_electron_integrals: + format: sparse + index_convention: mulliken + symmetry: {permutation: trivial} + units: hartree + values: + - key: [1, 1, 1, 1] + value: 4.7389920091 + - key: [1, 1, 1, 2] + value: 0.4316471044 + - key: [1, 1, 1, 4] + value: 0.139835356 + - key: [1, 1, 1, 6] + value: -0.1446035916 + - key: [1, 1, 2, 1] + value: 0.4316471044 + - key: [1, 1, 2, 2] + value: 1.0467302187 + - key: [1, 1, 2, 4] + value: 0.0884260324 + - key: [1, 1, 2, 6] + value: -0.1672617384 + - key: [1, 1, 3, 3] + value: 0.8757027418 + - key: [1, 1, 4, 1] + value: 0.139835356 + - key: [1, 1, 4, 2] + value: 0.0884260324 + - key: [1, 1, 4, 4] + value: 0.9826139063 + - key: [1, 1, 4, 6] + value: 0.0769489618 + - key: [1, 1, 5, 5] + value: 1.0352624942 + - key: [1, 1, 6, 1] + value: -0.1446035916 + - key: [1, 1, 6, 2] + value: -0.1672617384 + - key: [1, 1, 6, 4] + value: 0.0769489618 + - key: [1, 1, 6, 6] + value: 0.4091524574 + - key: [1, 2, 1, 1] + value: 0.4316471044 + - key: [1, 2, 1, 2] + value: 0.0616039968 + - key: [1, 2, 1, 4] + value: 0.0170066336 + - key: [1, 2, 1, 6] + value: -0.0232123364 + - key: [1, 2, 2, 1] + value: 0.0638469782 + - key: [1, 2, 2, 2] + value: 0.0147095395 + - key: [1, 2, 2, 4] + value: 0.0078363372 + - key: [1, 2, 2, 6] + value: -0.002454583 + - key: [1, 2, 3, 3] + value: 0.0065772294 + - key: [1, 2, 4, 1] + value: 0.0167766846 + - key: [1, 2, 4, 2] + value: 0.0081165775 + - key: [1, 2, 4, 4] + value: 0.0128731668 + - key: [1, 2, 4, 6] + value: -0.0010592476 + - key: [1, 2, 5, 5] + value: 0.011493053 + - key: [1, 2, 6, 1] + value: -0.0246428629 + - key: [1, 2, 6, 2] + value: -0.0010864284 + - key: [1, 2, 6, 4] + value: -0.0013917344 + - key: [1, 2, 6, 6] + value: 0.0017680559 + - key: [1, 3, 1, 3] + value: 0.0166828154 + - key: [1, 3, 2, 3] + value: -0.0221783953 + - key: [1, 3, 3, 1] + value: 0.0196006449 + - key: [1, 3, 3, 2] + value: -0.0231197785 + - key: [1, 3, 3, 4] + value: -0.0030473194 + - key: [1, 3, 3, 6] + value: 0.0043572676 + - key: [1, 3, 4, 3] + value: -0.0026225249 + - key: [1, 3, 6, 3] + value: 0.0043617565 + - key: [1, 4, 1, 1] + value: 0.139835356 + - key: [1, 4, 1, 2] + value: 0.0170066336 + - key: [1, 4, 1, 4] + value: 0.0272140846 + - key: [1, 4, 1, 6] + value: 0.0008031441 + - key: [1, 4, 2, 1] + value: 0.0167766846 + - key: [1, 4, 2, 2] + value: 0.0146677206 + - key: [1, 4, 2, 4] + value: -0.0217417092 + - key: [1, 4, 2, 6] + value: -0.0090397453 + - key: [1, 4, 3, 3] + value: 0.007387959 + - key: [1, 4, 4, 1] + value: 0.0299840375 + - key: [1, 4, 4, 2] + value: -0.022508094 + - key: [1, 4, 4, 4] + value: -0.0086662352 + - key: [1, 4, 4, 6] + value: 0.0033567718 + - key: [1, 4, 5, 5] + value: 0.0045801578 + - key: [1, 4, 6, 1] + value: 0.001377367 + - key: [1, 4, 6, 2] + value: -0.0091739517 + - key: [1, 4, 6, 4] + value: 0.0028886004 + - key: [1, 4, 6, 6] + value: 0.0066603239 + - key: [1, 5, 1, 5] + value: 0.0271884177 + - key: [1, 5, 2, 5] + value: -0.0288516874 + - key: [1, 5, 4, 5] + value: -0.0090235212 + - key: [1, 5, 5, 1] + value: 0.0299152685 + - key: [1, 5, 5, 2] + value: -0.0293007731 + - key: [1, 5, 5, 4] + value: -0.0093711715 + - key: [1, 5, 5, 6] + value: 0.0076193471 + - key: [1, 5, 6, 5] + value: 0.0070498091 + - key: [1, 6, 1, 1] + value: -0.1446035916 + - key: [1, 6, 1, 2] + value: -0.0232123364 + - key: [1, 6, 1, 4] + value: 0.0008031441 + - key: [1, 6, 1, 6] + value: 0.0104990496 + - key: [1, 6, 2, 1] + value: -0.0246428629 + - key: [1, 6, 2, 2] + value: -0.0010929887 + - key: [1, 6, 2, 4] + value: -0.0092159495 + - key: [1, 6, 2, 6] + value: -0.0019197882 + - key: [1, 6, 3, 3] + value: -0.0004761759 + - key: [1, 6, 4, 1] + value: 0.001377367 + - key: [1, 6, 4, 2] + value: -0.0095546897 + - key: [1, 6, 4, 4] + value: -0.0073492828 + - key: [1, 6, 4, 6] + value: 0.0018798592 + - key: [1, 6, 5, 5] + value: -0.0025744419 + - key: [1, 6, 6, 1] + value: 0.0100582331 + - key: [1, 6, 6, 2] + value: -0.001148843 + - key: [1, 6, 6, 4] + value: 0.0012367661 + - key: [1, 6, 6, 6] + value: 0.0010071293 + - key: [2, 1, 1, 1] + value: 0.4316471044 + - key: [2, 1, 1, 2] + value: 0.0638469782 + - key: [2, 1, 1, 4] + value: 0.0167766846 + - key: [2, 1, 1, 6] + value: -0.0246428629 + - key: [2, 1, 2, 1] + value: 0.0616039968 + - key: [2, 1, 2, 2] + value: 0.0147095395 + - key: [2, 1, 2, 4] + value: 0.0081165775 + - key: [2, 1, 2, 6] + value: -0.0010864284 + - key: [2, 1, 3, 3] + value: 0.0065772294 + - key: [2, 1, 4, 1] + value: 0.0170066336 + - key: [2, 1, 4, 2] + value: 0.0078363372 + - key: [2, 1, 4, 4] + value: 0.0128731668 + - key: [2, 1, 4, 6] + value: -0.0013917344 + - key: [2, 1, 5, 5] + value: 0.011493053 + - key: [2, 1, 6, 1] + value: -0.0232123364 + - key: [2, 1, 6, 2] + value: -0.002454583 + - key: [2, 1, 6, 4] + value: -0.0010592476 + - key: [2, 1, 6, 6] + value: 0.0017680559 + - key: [2, 2, 1, 1] + value: 1.0467302187 + - key: [2, 2, 1, 2] + value: 0.0147095395 + - key: [2, 2, 1, 4] + value: 0.0146677206 + - key: [2, 2, 1, 6] + value: -0.0010929887 + - key: [2, 2, 2, 1] + value: 0.0147095395 + - key: [2, 2, 2, 2] + value: 0.7459919427 + - key: [2, 2, 2, 4] + value: -0.0168158772 + - key: [2, 2, 2, 6] + value: -0.0962292596 + - key: [2, 2, 3, 3] + value: 0.6722147818 + - key: [2, 2, 4, 1] + value: 0.0146677206 + - key: [2, 2, 4, 2] + value: -0.0168158772 + - key: [2, 2, 4, 4] + value: 0.674550755 + - key: [2, 2, 4, 6] + value: 0.0488525301 + - key: [2, 2, 5, 5] + value: 0.70774557 + - key: [2, 2, 6, 1] + value: -0.0010929887 + - key: [2, 2, 6, 2] + value: -0.0962292596 + - key: [2, 2, 6, 4] + value: 0.0488525301 + - key: [2, 2, 6, 6] + value: 0.3677403255 + - key: [2, 3, 1, 3] + value: -0.0221783953 + - key: [2, 3, 2, 3] + value: 0.1439192313 + - key: [2, 3, 3, 1] + value: -0.0231197785 + - key: [2, 3, 3, 2] + value: 0.1487607073 + - key: [2, 3, 3, 4] + value: -0.0154338337 + - key: [2, 3, 3, 6] + value: -0.0027892125 + - key: [2, 3, 4, 3] + value: -0.0164191585 + - key: [2, 3, 6, 3] + value: -0.0018370861 + - key: [2, 4, 1, 1] + value: 0.0884260324 + - key: [2, 4, 1, 2] + value: 0.0078363372 + - key: [2, 4, 1, 4] + value: -0.0217417092 + - key: [2, 4, 1, 6] + value: -0.0092159495 + - key: [2, 4, 2, 1] + value: 0.0081165775 + - key: [2, 4, 2, 2] + value: -0.0168158772 + - key: [2, 4, 2, 4] + value: 0.1176240209 + - key: [2, 4, 2, 6] + value: 0.0175061567 + - key: [2, 4, 3, 3] + value: -0.0123799239 + - key: [2, 4, 4, 1] + value: -0.022508094 + - key: [2, 4, 4, 2] + value: 0.1224416506 + - key: [2, 4, 4, 4] + value: 0.0690613663 + - key: [2, 4, 4, 6] + value: 0.0006158001 + - key: [2, 4, 5, 5] + value: 0.0367349258 + - key: [2, 4, 6, 1] + value: -0.0095546897 + - key: [2, 4, 6, 2] + value: 0.0179834246 + - key: [2, 4, 6, 4] + value: 0.0009394053 + - key: [2, 4, 6, 6] + value: -0.0302865102 + - key: [2, 5, 1, 5] + value: -0.0288516874 + - key: [2, 5, 2, 5] + value: 0.1210151285 + - key: [2, 5, 4, 5] + value: 0.0297249972 + - key: [2, 5, 5, 1] + value: -0.0293007731 + - key: [2, 5, 5, 2] + value: 0.1251534778 + - key: [2, 5, 5, 4] + value: 0.0300346914 + - key: [2, 5, 5, 6] + value: -0.0234680664 + - key: [2, 5, 6, 5] + value: -0.0216941823 + - key: [2, 6, 1, 1] + value: -0.1672617384 + - key: [2, 6, 1, 2] + value: -0.002454583 + - key: [2, 6, 1, 4] + value: -0.0090397453 + - key: [2, 6, 1, 6] + value: -0.0019197882 + - key: [2, 6, 2, 1] + value: -0.0010864284 + - key: [2, 6, 2, 2] + value: -0.0962292596 + - key: [2, 6, 2, 4] + value: 0.0175061567 + - key: [2, 6, 2, 6] + value: 0.0394645048 + - key: [2, 6, 3, 3] + value: -0.0697594153 + - key: [2, 6, 4, 1] + value: -0.0091739517 + - key: [2, 6, 4, 2] + value: 0.0179834246 + - key: [2, 6, 4, 4] + value: -0.0645496877 + - key: [2, 6, 4, 6] + value: -0.0219155062 + - key: [2, 6, 5, 5] + value: -0.0870774079 + - key: [2, 6, 6, 1] + value: -0.001148843 + - key: [2, 6, 6, 2] + value: 0.032432543 + - key: [2, 6, 6, 4] + value: -0.0177919004 + - key: [2, 6, 6, 6] + value: -0.0171335527 + - key: [3, 1, 1, 3] + value: 0.0196006449 + - key: [3, 1, 2, 3] + value: -0.0231197785 + - key: [3, 1, 3, 1] + value: 0.0166828154 + - key: [3, 1, 3, 2] + value: -0.0221783953 + - key: [3, 1, 3, 4] + value: -0.0026225249 + - key: [3, 1, 3, 6] + value: 0.0043617565 + - key: [3, 1, 4, 3] + value: -0.0030473194 + - key: [3, 1, 6, 3] + value: 0.0043572676 + - key: [3, 2, 1, 3] + value: -0.0231197785 + - key: [3, 2, 2, 3] + value: 0.1487607073 + - key: [3, 2, 3, 1] + value: -0.0221783953 + - key: [3, 2, 3, 2] + value: 0.1439192313 + - key: [3, 2, 3, 4] + value: -0.0164191585 + - key: [3, 2, 3, 6] + value: -0.0018370861 + - key: [3, 2, 4, 3] + value: -0.0154338337 + - key: [3, 2, 6, 3] + value: -0.0027892125 + - key: [3, 3, 1, 1] + value: 0.8757027418 + - key: [3, 3, 1, 2] + value: 0.0065772294 + - key: [3, 3, 1, 4] + value: 0.007387959 + - key: [3, 3, 1, 6] + value: -0.0004761759 + - key: [3, 3, 2, 1] + value: 0.0065772294 + - key: [3, 3, 2, 2] + value: 0.6722147818 + - key: [3, 3, 2, 4] + value: -0.0123799239 + - key: [3, 3, 2, 6] + value: -0.0697594153 + - key: [3, 3, 3, 3] + value: 0.6438382812 + - key: [3, 3, 4, 1] + value: 0.007387959 + - key: [3, 3, 4, 2] + value: -0.0123799239 + - key: [3, 3, 4, 4] + value: 0.5959262868 + - key: [3, 3, 4, 6] + value: 0.0325101489 + - key: [3, 3, 5, 5] + value: 0.613223063 + - key: [3, 3, 6, 1] + value: -0.0004761759 + - key: [3, 3, 6, 2] + value: -0.0697594153 + - key: [3, 3, 6, 4] + value: 0.0325101489 + - key: [3, 3, 6, 6] + value: 0.3586509025 + - key: [3, 4, 1, 3] + value: -0.0030473194 + - key: [3, 4, 2, 3] + value: -0.0154338337 + - key: [3, 4, 3, 1] + value: -0.0026225249 + - key: [3, 4, 3, 2] + value: -0.0164191585 + - key: [3, 4, 3, 4] + value: 0.032130949 + - key: [3, 4, 3, 6] + value: -0.0041871063 + - key: [3, 4, 4, 3] + value: 0.0376204313 + - key: [3, 4, 6, 3] + value: -0.0027502214 + - key: [3, 5, 3, 5] + value: 0.0237503555 + - key: [3, 5, 5, 3] + value: 0.0289508433 + - key: [3, 6, 1, 3] + value: 0.0043572676 + - key: [3, 6, 2, 3] + value: -0.0027892125 + - key: [3, 6, 3, 1] + value: 0.0043617565 + - key: [3, 6, 3, 2] + value: -0.0018370861 + - key: [3, 6, 3, 4] + value: -0.0041871063 + - key: [3, 6, 3, 6] + value: 0.0245522836 + - key: [3, 6, 4, 3] + value: -0.0027502214 + - key: [3, 6, 6, 3] + value: 0.0200647031 + - key: [4, 1, 1, 1] + value: 0.139835356 + - key: [4, 1, 1, 2] + value: 0.0167766846 + - key: [4, 1, 1, 4] + value: 0.0299840375 + - key: [4, 1, 1, 6] + value: 0.001377367 + - key: [4, 1, 2, 1] + value: 0.0170066336 + - key: [4, 1, 2, 2] + value: 0.0146677206 + - key: [4, 1, 2, 4] + value: -0.022508094 + - key: [4, 1, 2, 6] + value: -0.0091739517 + - key: [4, 1, 3, 3] + value: 0.007387959 + - key: [4, 1, 4, 1] + value: 0.0272140846 + - key: [4, 1, 4, 2] + value: -0.0217417092 + - key: [4, 1, 4, 4] + value: -0.0086662352 + - key: [4, 1, 4, 6] + value: 0.0028886004 + - key: [4, 1, 5, 5] + value: 0.0045801578 + - key: [4, 1, 6, 1] + value: 0.0008031441 + - key: [4, 1, 6, 2] + value: -0.0090397453 + - key: [4, 1, 6, 4] + value: 0.0033567718 + - key: [4, 1, 6, 6] + value: 0.0066603239 + - key: [4, 2, 1, 1] + value: 0.0884260324 + - key: [4, 2, 1, 2] + value: 0.0081165775 + - key: [4, 2, 1, 4] + value: -0.022508094 + - key: [4, 2, 1, 6] + value: -0.0095546897 + - key: [4, 2, 2, 1] + value: 0.0078363372 + - key: [4, 2, 2, 2] + value: -0.0168158772 + - key: [4, 2, 2, 4] + value: 0.1224416506 + - key: [4, 2, 2, 6] + value: 0.0179834246 + - key: [4, 2, 3, 3] + value: -0.0123799239 + - key: [4, 2, 4, 1] + value: -0.0217417092 + - key: [4, 2, 4, 2] + value: 0.1176240209 + - key: [4, 2, 4, 4] + value: 0.0690613663 + - key: [4, 2, 4, 6] + value: 0.0009394053 + - key: [4, 2, 5, 5] + value: 0.0367349258 + - key: [4, 2, 6, 1] + value: -0.0092159495 + - key: [4, 2, 6, 2] + value: 0.0175061567 + - key: [4, 2, 6, 4] + value: 0.0006158001 + - key: [4, 2, 6, 6] + value: -0.0302865102 + - key: [4, 3, 1, 3] + value: -0.0026225249 + - key: [4, 3, 2, 3] + value: -0.0164191585 + - key: [4, 3, 3, 1] + value: -0.0030473194 + - key: [4, 3, 3, 2] + value: -0.0154338337 + - key: [4, 3, 3, 4] + value: 0.0376204313 + - key: [4, 3, 3, 6] + value: -0.0027502214 + - key: [4, 3, 4, 3] + value: 0.032130949 + - key: [4, 3, 6, 3] + value: -0.0041871063 + - key: [4, 4, 1, 1] + value: 0.9826139063 + - key: [4, 4, 1, 2] + value: 0.0128731668 + - key: [4, 4, 1, 4] + value: -0.0086662352 + - key: [4, 4, 1, 6] + value: -0.0073492828 + - key: [4, 4, 2, 1] + value: 0.0128731668 + - key: [4, 4, 2, 2] + value: 0.674550755 + - key: [4, 4, 2, 4] + value: 0.0690613663 + - key: [4, 4, 2, 6] + value: -0.0645496877 + - key: [4, 4, 3, 3] + value: 0.5959262868 + - key: [4, 4, 4, 1] + value: -0.0086662352 + - key: [4, 4, 4, 2] + value: 0.0690613663 + - key: [4, 4, 4, 4] + value: 0.7102351206 + - key: [4, 4, 4, 6] + value: 0.04867595 + - key: [4, 4, 5, 5] + value: 0.654436878 + - key: [4, 4, 6, 1] + value: -0.0073492828 + - key: [4, 4, 6, 2] + value: -0.0645496877 + - key: [4, 4, 6, 4] + value: 0.04867595 + - key: [4, 4, 6, 6] + value: 0.3413097466 + - key: [4, 5, 1, 5] + value: -0.0090235212 + - key: [4, 5, 2, 5] + value: 0.0297249972 + - key: [4, 5, 4, 5] + value: 0.0363022632 + - key: [4, 5, 5, 1] + value: -0.0093711715 + - key: [4, 5, 5, 2] + value: 0.0300346914 + - key: [4, 5, 5, 4] + value: 0.0411648761 + - key: [4, 5, 5, 6] + value: 0.0011172499 + - key: [4, 5, 6, 5] + value: 0.00135636 + - key: [4, 6, 1, 1] + value: 0.0769489618 + - key: [4, 6, 1, 2] + value: -0.0010592476 + - key: [4, 6, 1, 4] + value: 0.0033567718 + - key: [4, 6, 1, 6] + value: 0.0018798592 + - key: [4, 6, 2, 1] + value: -0.0013917344 + - key: [4, 6, 2, 2] + value: 0.0488525301 + - key: [4, 6, 2, 4] + value: 0.0006158001 + - key: [4, 6, 2, 6] + value: -0.0219155062 + - key: [4, 6, 3, 3] + value: 0.0325101489 + - key: [4, 6, 4, 1] + value: 0.0028886004 + - key: [4, 6, 4, 2] + value: 0.0009394053 + - key: [4, 6, 4, 4] + value: 0.04867595 + - key: [4, 6, 4, 6] + value: 0.0205293025 + - key: [4, 6, 5, 5] + value: 0.0434854311 + - key: [4, 6, 6, 1] + value: 0.0012367661 + - key: [4, 6, 6, 2] + value: -0.0177919004 + - key: [4, 6, 6, 4] + value: 0.0187224135 + - key: [4, 6, 6, 6] + value: 0.0010454473 + - key: [5, 1, 1, 5] + value: 0.0299152685 + - key: [5, 1, 2, 5] + value: -0.0293007731 + - key: [5, 1, 4, 5] + value: -0.0093711715 + - key: [5, 1, 5, 1] + value: 0.0271884177 + - key: [5, 1, 5, 2] + value: -0.0288516874 + - key: [5, 1, 5, 4] + value: -0.0090235212 + - key: [5, 1, 5, 6] + value: 0.0070498091 + - key: [5, 1, 6, 5] + value: 0.0076193471 + - key: [5, 2, 1, 5] + value: -0.0293007731 + - key: [5, 2, 2, 5] + value: 0.1251534778 + - key: [5, 2, 4, 5] + value: 0.0300346914 + - key: [5, 2, 5, 1] + value: -0.0288516874 + - key: [5, 2, 5, 2] + value: 0.1210151285 + - key: [5, 2, 5, 4] + value: 0.0297249972 + - key: [5, 2, 5, 6] + value: -0.0216941823 + - key: [5, 2, 6, 5] + value: -0.0234680664 + - key: [5, 3, 3, 5] + value: 0.0289508433 + - key: [5, 3, 5, 3] + value: 0.0237503555 + - key: [5, 4, 1, 5] + value: -0.0093711715 + - key: [5, 4, 2, 5] + value: 0.0300346914 + - key: [5, 4, 4, 5] + value: 0.0411648761 + - key: [5, 4, 5, 1] + value: -0.0090235212 + - key: [5, 4, 5, 2] + value: 0.0297249972 + - key: [5, 4, 5, 4] + value: 0.0363022632 + - key: [5, 4, 5, 6] + value: 0.00135636 + - key: [5, 4, 6, 5] + value: 0.0011172499 + - key: [5, 5, 1, 1] + value: 1.0352624942 + - key: [5, 5, 1, 2] + value: 0.011493053 + - key: [5, 5, 1, 4] + value: 0.0045801578 + - key: [5, 5, 1, 6] + value: -0.0025744419 + - key: [5, 5, 2, 1] + value: 0.011493053 + - key: [5, 5, 2, 2] + value: 0.70774557 + - key: [5, 5, 2, 4] + value: 0.0367349258 + - key: [5, 5, 2, 6] + value: -0.0870774079 + - key: [5, 5, 3, 3] + value: 0.613223063 + - key: [5, 5, 4, 1] + value: 0.0045801578 + - key: [5, 5, 4, 2] + value: 0.0367349258 + - key: [5, 5, 4, 4] + value: 0.654436878 + - key: [5, 5, 4, 6] + value: 0.0434854311 + - key: [5, 5, 5, 5] + value: 0.7411502377 + - key: [5, 5, 6, 1] + value: -0.0025744419 + - key: [5, 5, 6, 2] + value: -0.0870774079 + - key: [5, 5, 6, 4] + value: 0.0434854311 + - key: [5, 5, 6, 6] + value: 0.3480021806 + - key: [5, 6, 1, 5] + value: 0.0076193471 + - key: [5, 6, 2, 5] + value: -0.0234680664 + - key: [5, 6, 4, 5] + value: 0.0011172499 + - key: [5, 6, 5, 1] + value: 0.0070498091 + - key: [5, 6, 5, 2] + value: -0.0216941823 + - key: [5, 6, 5, 4] + value: 0.00135636 + - key: [5, 6, 5, 6] + value: 0.0156117396 + - key: [5, 6, 6, 5] + value: 0.0116811584 + - key: [6, 1, 1, 1] + value: -0.1446035916 + - key: [6, 1, 1, 2] + value: -0.0246428629 + - key: [6, 1, 1, 4] + value: 0.001377367 + - key: [6, 1, 1, 6] + value: 0.0100582331 + - key: [6, 1, 2, 1] + value: -0.0232123364 + - key: [6, 1, 2, 2] + value: -0.0010929887 + - key: [6, 1, 2, 4] + value: -0.0095546897 + - key: [6, 1, 2, 6] + value: -0.001148843 + - key: [6, 1, 3, 3] + value: -0.0004761759 + - key: [6, 1, 4, 1] + value: 0.0008031441 + - key: [6, 1, 4, 2] + value: -0.0092159495 + - key: [6, 1, 4, 4] + value: -0.0073492828 + - key: [6, 1, 4, 6] + value: 0.0012367661 + - key: [6, 1, 5, 5] + value: -0.0025744419 + - key: [6, 1, 6, 1] + value: 0.0104990496 + - key: [6, 1, 6, 2] + value: -0.0019197882 + - key: [6, 1, 6, 4] + value: 0.0018798592 + - key: [6, 1, 6, 6] + value: 0.0010071293 + - key: [6, 2, 1, 1] + value: -0.1672617384 + - key: [6, 2, 1, 2] + value: -0.0010864284 + - key: [6, 2, 1, 4] + value: -0.0091739517 + - key: [6, 2, 1, 6] + value: -0.001148843 + - key: [6, 2, 2, 1] + value: -0.002454583 + - key: [6, 2, 2, 2] + value: -0.0962292596 + - key: [6, 2, 2, 4] + value: 0.0179834246 + - key: [6, 2, 2, 6] + value: 0.032432543 + - key: [6, 2, 3, 3] + value: -0.0697594153 + - key: [6, 2, 4, 1] + value: -0.0090397453 + - key: [6, 2, 4, 2] + value: 0.0175061567 + - key: [6, 2, 4, 4] + value: -0.0645496877 + - key: [6, 2, 4, 6] + value: -0.0177919004 + - key: [6, 2, 5, 5] + value: -0.0870774079 + - key: [6, 2, 6, 1] + value: -0.0019197882 + - key: [6, 2, 6, 2] + value: 0.0394645048 + - key: [6, 2, 6, 4] + value: -0.0219155062 + - key: [6, 2, 6, 6] + value: -0.0171335527 + - key: [6, 3, 1, 3] + value: 0.0043617565 + - key: [6, 3, 2, 3] + value: -0.0018370861 + - key: [6, 3, 3, 1] + value: 0.0043572676 + - key: [6, 3, 3, 2] + value: -0.0027892125 + - key: [6, 3, 3, 4] + value: -0.0027502214 + - key: [6, 3, 3, 6] + value: 0.0200647031 + - key: [6, 3, 4, 3] + value: -0.0041871063 + - key: [6, 3, 6, 3] + value: 0.0245522836 + - key: [6, 4, 1, 1] + value: 0.0769489618 + - key: [6, 4, 1, 2] + value: -0.0013917344 + - key: [6, 4, 1, 4] + value: 0.0028886004 + - key: [6, 4, 1, 6] + value: 0.0012367661 + - key: [6, 4, 2, 1] + value: -0.0010592476 + - key: [6, 4, 2, 2] + value: 0.0488525301 + - key: [6, 4, 2, 4] + value: 0.0009394053 + - key: [6, 4, 2, 6] + value: -0.0177919004 + - key: [6, 4, 3, 3] + value: 0.0325101489 + - key: [6, 4, 4, 1] + value: 0.0033567718 + - key: [6, 4, 4, 2] + value: 0.0006158001 + - key: [6, 4, 4, 4] + value: 0.04867595 + - key: [6, 4, 4, 6] + value: 0.0187224135 + - key: [6, 4, 5, 5] + value: 0.0434854311 + - key: [6, 4, 6, 1] + value: 0.0018798592 + - key: [6, 4, 6, 2] + value: -0.0219155062 + - key: [6, 4, 6, 4] + value: 0.0205293025 + - key: [6, 4, 6, 6] + value: 0.0010454473 + - key: [6, 5, 1, 5] + value: 0.0070498091 + - key: [6, 5, 2, 5] + value: -0.0216941823 + - key: [6, 5, 4, 5] + value: 0.00135636 + - key: [6, 5, 5, 1] + value: 0.0076193471 + - key: [6, 5, 5, 2] + value: -0.0234680664 + - key: [6, 5, 5, 4] + value: 0.0011172499 + - key: [6, 5, 5, 6] + value: 0.0116811584 + - key: [6, 5, 6, 5] + value: 0.0156117396 + - key: [6, 6, 1, 1] + value: 0.4091524574 + - key: [6, 6, 1, 2] + value: 0.0017680559 + - key: [6, 6, 1, 4] + value: 0.0066603239 + - key: [6, 6, 1, 6] + value: 0.0010071293 + - key: [6, 6, 2, 1] + value: 0.0017680559 + - key: [6, 6, 2, 2] + value: 0.3677403255 + - key: [6, 6, 2, 4] + value: -0.0302865102 + - key: [6, 6, 2, 6] + value: -0.0171335527 + - key: [6, 6, 3, 3] + value: 0.3586509025 + - key: [6, 6, 4, 1] + value: 0.0066603239 + - key: [6, 6, 4, 2] + value: -0.0302865102 + - key: [6, 6, 4, 4] + value: 0.3413097466 + - key: [6, 6, 4, 6] + value: 0.0010454473 + - key: [6, 6, 5, 5] + value: 0.3480021806 + - key: [6, 6, 6, 1] + value: 0.0010071293 + - key: [6, 6, 6, 2] + value: -0.0171335527 + - key: [6, 6, 6, 4] + value: 0.0010454473 + - key: [6, 6, 6, 6] + value: 0.3009843355 + initial_state_suggestions: + - energy: + units: hartree + value: 0.0 + label: '|G>' + method: sparse_multi_configurational + superposition: + - - 1.0 + - (1a)+ + - (2a)+ + - (3a)+ + - (4a)+ + - (5a)+ + - (1b)+ + - (2b)+ + - (3b)+ + - (4b)+ + - (5b)+ + - '|vacuum>' + metadata: {molecule_name: unknown, note: Full CCSD energy = -76.240099478499133} + n_electrons: 10 + n_orbitals: 6 + scf_energy: {units: hartree, value: -76.0267720564472} + scf_energy_offset: {units: hartree, value: 0.0} + + diff --git a/Python/qsharp-chemistry/qsharp-chemistry-0.0.0.1.tar.gz b/Python/qsharp-chemistry/qsharp-chemistry-0.0.0.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..431705ce4b4064b591455782791c5eba94968f53 GIT binary patch literal 5280 zcma);=QG@o_xAM`OOzl4iKvOPdhbzI5QGS#_uj2&OSG)sOZ4bOqL)|}5nc2si+`}6(%1^1kpGuK@6nsYt59vt>~GO}`216u;X+t_nt|_gF)_>H)*g4?QAVjWU;b>uZkuUpYjHaf|*mF)M zjr7ABEH#GuI{P3PFYsg9=F=pZE)s(W@tjFe#ruKDU}p7oPo9fW7Igsz1&m-h->42O zZ(LUrlXz`59#D%-2zlQcL#vS=1HNmjG+C1E-)tQvsS87*cQ0#_Afff@!qeFYP^f(7SdJ+X+D`7Ho~0@5ul=Bbk{SQXQ7k$x*>K$k_W<$rL1E9RlI z3l=!qWL=;Aoc|kUYi);F6?A5)OPr?hUlin{7*yx0EAO`}^<(Z71UYtY*bP*6YfO*y zH)uQoxih3Tu%}r{CMHg^pzSZib&HSrww0SvPTFn?i5fAxouGLMRmHPG#Hp*cJX@z{ zI-7)6uSTqcg~y+dVO|d3O!v|k4~I6L)lpnMTSY;ZtmQ$Yp|5l z#rlMgjIS&~o#+>B^LlxCN)*Yf_m@_q5ap|!Bq_rlaZm5|#w7KguBETfs5UYZl>oUW zf!L!H{`Yd|Eh(!fn^OI|{C~$X6NgJ28^U{GY-=}ZY7S1MkDM&fqz7vbST_c|XZfLj zK*e{No0h>W<%!eWDLDs~v)Rpg>*(dWG*t8G~bpeH>+JBD^bb;(ru!!Mb{k z(kVKW#XZG^#5r@CYhVicB&Mg2yrf{`?VPJ=66s8M$SQ6Thkp)sW5X{ZanGqt*3+X9 z*1_P$^;yCx1aA2Il4*EG(p^q`30(+dy&2KjsqYr^@i5}W=Wsbk3Z>V{}s>1%-=J#2cwWyvDtBW=25G=VghDTB+!23v# zs_|Xz=ut_T3S?#K>f%qRC0t_V3*oC@-P#F5l`>O*ER%T{2&ORO^MsII=oNqOApg#F zlW?EH>Pn76?`?(~#fsFU^oNs#A3w?ClLtBmx3*W&$nJ+b#${Abv>ZxB4J<<=`nhNG zmFZ^S0wnYSnx7ZB>zx@j5C{a3jkctg4|q<#I*asEq8 zDD|=)wGgzIO#JzWU)GNMTHj1Rqi^A9HqE-X7146WfgMOMr z6lWLr?6Bw&u@+Q0;Y^Qv$Fo8m!_fU$v`4dqoESnO5KVs_%JcmT;g}T%SGl(#Q>}cb zVw-N`5u)|IT2e%X?I7}(oL1CzsK1#Mg8r1GGM&7Mxd=CXaFEW-5gI z%6)cXz-ariA*ZIzg&)yV=(zJpRGlm}2zNKLb-w)p&I0Q*-eR}GR<2mS19o>Vi(0+_ z%}tj@7Ql8v7}8ekayr=pcn_<;K3j?SV~P&NR-%mefx|aV^ZOp_x34PEGy97Byg_qH z-dWhs?SLR?}{h!;DD*`O9nA zzv9!kw=m=lQkQWZ>34^I-2lkoj;Wh~(Z9g0Vp|^TA$~KK+NV}!zZvNA=&U|Ot^zZ6 z^BCCoJEkj`RI_{@b*wr#covI%;~Cs(xd5P!{5yjHPXP=}QCz)s-fGp6Bim3or5%UR z)n;e>1ci(ZUa}%0M-y+rnPm5)%=_ftRVK`etbNP7cZwG6h!bM;Ni0hbRm_RLvKxWS zEswZU9AT{2Vtq>C2hvnDnH;o@AESL}^{xQ|-%Us4z$RXiPomE)y-R!|p%9W|YMLajp{#7T91NYPurO6V=sUoyIxa)cn=nFI2|gUxe|+$dJ3OooW;#kN zhxO4LBrCk;oFDJy();|GhPxkmWY9mItI)U88?DJ|5-?~Pa0PpsjPxFhL;-bxx?ue zqnnL)r-j5-RP8;wa1O=c7Ey{z0SRvS=~wl!hx23(A)Hv7-p&Cpr-&R1n%-?P)8F}_ zS}d4$Z z$F@q-g#PG+d$OgHjvi^4cZ1pxY;&?AJGE_SP+T@Gw1#A zyGs1|oVA5N)npyIi6-kZ$);e6H;$D`+gQd%MnZ3jsZnSwL7Ii)LCvr9t~9=pK$kMH zm$RaWpO$D?2=r)3RavQi_2oRM*%%wJO45lA^4$S#eQk_0lYH6SFY>x=tYTSh+>7wR z9-TFCRAt%OxA#qXRKzgs?O~djrPwL7RNl8(mrTUwFO{ELT%zlPwuZQeoP(f7i2#0^ ze?M5d@*Z{cv0h&yDaU6QOCIJ!VM<+ntg14~)*!}}9-Y=x0X*6jJ38{A6wf6w5Q;YV zwv9~V_q9Du;wa}*C5Lt0ngdi#W`CsMK6gB+*rrsOmaNnxaW$8~fvdn{%q z+#UsUgn8^t()cRbMGz@$=b3xjCUO@IZc^Xb)NuhjGnI5J>v&3-WBdwr&ALL{JPv&3!Gx5<^UF(j*zk2xV7HNZU3DaVSQVl} zPU>*p`};I3%lq=hI>XDHK3PrJX5s2!7~jINSmIlmXx@?KxM8C1t#8J>o;m7e=Y)LO zWSgpX;tzfg=BnQv!+?oKct3P9s#BK@=k)Wfu=x!)amR7l+8>IR5RQ~*2D)VwahxyY zC5_$+u8Uc!O+V}uKH?-Ujjp&S_sXOll4Nm^=34RS3Abl4(Zp#=d%~;G`0yD5aZ>9D zzL!gVwmZz&GD&`zqPzmfumwJy@DzkWiBptP38u}=wey9(bg%s^TiffbYV)*OAT#fM z*5UWJ?MsNnn@;CQpU$UEpA#`Jb zfbk-OAD0H<{q)*yv=aX zCe+9v&?1a0MIG+nB)9a#Qo3?5m*nRswtnp#&bB=tHsj$6O>Tt)ZgvFqFLmcwl*FQFZR_S;EF*m;}qqt0KsF}c=R#s z5@U|V3b_N~Knr$$le8YV0l-B!=Q&r%d1uB07>j&(E3nTydKT~X<7J4OC;EEes%&p9 z_A|*aogBS`>yv_!q0qeNMKYNJ1Qk!mJ?Z8>5^&W5{SLFUG4^##x)EzcC5PSyI;6S^ zs+nJi)aL{mGu=WcA}kgfEIyi{ibT$}LYYrK!Rs{Kn&n*F7uEf{m#n^?2n}JIo7}_R}5bv#*6W&kj%RUS;seABvBL{zy zNko{m8eO!Vh36kmSdAI(De&wsX7c5H>SBQSe*ME$dAAXlwT3c@_SE=`D)<3SfALx| zfd3)4uuW8~FeW*qw5VR+wR&fZu>FX;(U(s?S*TX++;LeW@Nh?=FK@8x&Kd?>aQ*u> z57Xg?vzDL98hew&wpk`lDIbfh4m&Yfng1h1fTq1#k8L+%TaLr&GCR`Fb?OBZ6bBt- z_d;Ynp4;gsO@-q9f5%C7p!)A3>@8pC#1kbXH69zzpM%IrD%PmdqUTiv9!Mwj~P;q7Tq)#th+ zkRh|Kq~x5w{eLKVa0KkbJ|t-pS&V4+GK=YeMo!o17h4?!@5kz{Hjr?BMnunXKV zdmFCF54hegYJ*`pKRz{<}{;HnjeLz%`Y0A@u%-K(={p7*=yhzp3tEvHauTDHRQ%c70)|Lkqp z{$)|+cU0z#^BaBnHz5r+`cxa$ax)@NbnBI0WYPe_5MK_B*fqREN(D>&1Ma z`iN)*cl#)Pg8f>MFu%Yce*>LJVE6o(6k?Bw7m;DX~~~C#qIYr@;T83pGBnA?7{@) zVeaM{y+d-4+fIj}!?>=L)@UYd%oecC+`My#yW)v54r;u@|W8&ny zXs5tOEZaXrq2`V!R7{uO3;zVJkNYvEB9Z!HVQWmN;Pr#(fsxBP|hSQ<#=HY68JiS>hoBg)_$NE$4tO>c(ET89aS3 zXKjD)h7n{>u@asTUOH#9j$JR!4*tQ&PKEA{%KBDC*C243$){|uXl2o2^F`)@VzBe8 z+mjR9OZ;yQ-k^}4bmr%omEK9y#{QQW9Ui_=0b^p8){z{y43TL34oFABc=#JLtw9U6 z{3E2I-0&{LR)@4gl`8IqyK#9{JoWOhD!b^oS^*^K1LfW0fHH*W0mzpGl42(wk7$Vc z05-^vbLtaQj=UQxH3`PN620f>v z?fLX(RyLTlJPo9DLgd6%a`KGnJ{Pd%he}DyDue}7wC=X8W5>kYGejDh{#MGw89ZV! z6V!TbQt-I?t&ARQ&iq;0KIx`m)rc>3497m3OqcM!LUobie0K;&k|51NO^Y&4(xWPt zAlBqeRjwsOuW&T&)oqe$_?-osUDNd0DV#)FE7^U5wz5I}BmPzWmn3q hsE`KzY4pa78l$=2)c@!DC%6gV^(t^KUM&)MgF-@R28ajsDU004YISP4|CcaHS_b36dx zf&l3WMSfH&tql*x3zR~c6`BOWMpY)>1<@gZU15kwrw{pNOsB0vTg4K?qVjV znSS5wd%YZru9Y7xdQyrd`EH0D&L1xypB3vNiEL=a*sGM?;pmPls8$}y!CfW|kztNH zT5*#|&3b!_8A|6PbHcVr^pNJIr}gziZ?wOBTlk=y>guy?9ezIwQFFee(Qpnfn%0-R z*gf3>*@T1vBRh2v5{_gAze@@ZK6kTtQXrd(Y-6;I;N(yg-cG2jI(v)-V?s@|41Zie zrzN4bJTfb^N0FWZ*S?Fjhbkg{jyL|@3Z)@bId9&PbdTma2Vq`xMjlXzDQdG-IFP!32t^-{@9?}uHh5)&xM6Kq`dfb_NLcdP10oD z`G+-=EaJb%(ZJZed?&N}gNoB6(ik5i&?%u)ee~wsLn{ss_)^roEILn3x}M0j+N*Mk z9FMw*6F*4`yj>(VgTej-H_j~5vP2J)9oEJAyM9k$lFg z#PaH{u5j7R%|gBy;SkJgIxT7P&T~WUX1n8b7JZs2`;g5r>|SJ#A(N6)bXj`1dIn{= z{(ACBa~JH0dzMCr@y_|jIv>fAMT5wrPjNk|%;Hximv4cx$YYFVl!$&!!Mb?Ti3VY5 z*Ml^Jk+HXuVroqk#d8Q=B|ge&Eh)B0+K^Hb_^_XpM#mIr5)Q5)nbd}&xB(ryTWO`o-W4bB%Xby zOym&sX~?RLW{iB5`s}GCom@bNVvJ+$66SM_YSeKmD_E+}Ge_Y$(0!VhcKpFhE8y9f z<_X8bDKT3qWM zckkAr=J!iC4A3M63B2mEdAw`z2pNu6_8ZctF>(Pp>0IgF{2R?>s<9^}kua^)3ab`M zl417jnB1jf8R~MjufrYHF*zvx)&_?KI}V|0y5WIdcny~@{57BS2;{r*38M9s9ya0Q z%c)oUeMUPW?1Zx&LG7885iS!hlL&yxR09LPaOfov@04MYq9V0;K24Wvred6<6B_xQ zCIZyFKGV_LF#FIpOmqz~`JqU3qL9heyJRG45C>M4K$$ih&7#EAOh%0~oKE$l7t;|= z!K!Op$y5dn>$V`OHni5oJ`B|#$(oCq;!x_2%fW{c zW65#jHCMQ> zBT_%w-Q$R$8S;_L>ga8F&gvnNt5SFU!)=L2%?Ej;X@1+KSq0c)hd%8icp^a%OyW5l6m6!0}7dH?d6@(AL}Lsmt|JYfo$2%b1clbQL|S@e`}l zq>$b$GR`^TRkx}r?cNT`BAj{ho*jumve@MQ3z}~Qg|+bMoBESTX>>imC?=9_5<;J5 z(t^e~crEo~0zWBCL#*zI=miTdPY6&f^In=rzK~{6JGy=&p`)kHxB_oI!Sc?<`B_?# z+*hDxOHO}l6?gc9&6Wnj#Y$-N3{hU)&0L~xf6e@8&{%_ZI>SO6je~=r6q1)VQH-3@D3o`1S1|GXbGQPYORy?utlD?au&t+pkp$CsMbIae%_AX35R`mil zoh}lwIBGwu+-`Q7Jv_Oo7B6aTGN$5pE1_xEVDEftvkl4*_x73Sd2@Dc=qOVEZn2g) z8aIlCt6?0GqNKf$L`>6T5$2WLDq=`FeUnLM3T z0cE?_VfNd}uT5bwmy>B z?SMa8$&7R@lsvfh$vimkzF%$x)s=C5D-zTd9`i}7coI4!$#1&+KuGCcT`KtpNa(72 zmX3@hIgV_l>)x1vivt@M=tKXWXd^%FRwALzyC9ski9L0^;ukb{r%R?Hcg}VeJWo|l z@ab^=3f6`5BJhX?@x=3m?WXl?YDuV1~cer;&fD4484=bKL=NrH9(D@vO&nlOmf zn3U*x`TbX{_ut$#WEB0ZtjOjqwouLS1ie|=%Q~z`(TOm}B(IPfYAfiGaSqn>b!Ki# z)AF~z&W@!UypOHJPQ971uCgtm(wVs%?72#+0X7JDf@FheBRVpb@*NSh?#Ut9Y6bC} zX8og#Jm>O(wTlXJxWJkc1;=|;M%4vY40OGqe%UvB!qR0@h<9p&tra_|(J zcAUz{ibVi=h>`z|l!jX<-BSTUdKBNAM&>AAZ%MM_AULwy4X4tWdIF!|H5A(P4hLsJ zp0BIA$)4<;sBLMd7rC=x3kgsbd>~{_Y^B)K`@~HlTMJYYt}YO=9G@v3(2iXc*=ov6 zROHy7XFA%K_CSg_TWH9CAy$YI=C}A+Djg@F15cS!75&M1yz7L}fHpQN9-kh{wV~0q z5(9IP4ZdD}cKTJ%U1Cpgs8{eH9rjpZRlq-wfGZuEd6Dm3m84F?J?vT!6+2VJ^Oq&} ze#Tl?=vu$LvWwPp_W8;*Co0yPY*k7KR9?}w97Q#TZ->U)R`MYI3&Z3Z;m(O8d(p45X=WGr1MlfmXj6*Y`>c6q zCs#9=X5CzhZjSbIRHAyMWF^n->dk?DR&RvJS)PVtJI3X5gjbc4elfthe4l*FZhviA zJoD4TVxJF*g6`75)Uz{Hs0euy3F&(3yk74%y+>8#A4^MFdVy&Qg&WMdgLNclZs#6l znR~ktv*V6cIrw@rxkZXJPM1YaRdxe(Rl(jkKYt7QD=Dxpcg`Td1ptJJ007`$)BER~ z<^ps7IC#0AT}4+eOFMG}4^&oDQbtl!@~yTWVp@>Wd$L%_x3q!)WNkZ3O!?G9FG4Uu z5Ehg{%c+}T+d|2)7b|mia3-%%<^&5O!NLw>9X#P)Vf+>+s?Fc|o#)Hb^zoF`!BqJ3 zf_W$O6bZkrp{@I!0)7L*trIx)MJha@(K2yu*?G7oLR-L&jRO@(*UVK|p04s5c4!C@ zLrl>lAp;ezhLqOxg5JXU&Kd$4eCTiSK=BtjDG2c!SY;GZpUsuux1zk+R!Atw!4C(4 zg^c+r=PuzC8RoZS+v8dW&x_O|-+CtGLSivH*4!@B zzSq6TwnDt{%~9~}=yW+=LQ4Xe;Avn=&I7k+O#CLdd|}MIYoQ7v#mFZaDO5IEwo5PDD9`3`W>au=}zk5LayONXs*i zmJ&t%*_UPGTo8K^VMgS5vaiMncxf{xxxg&c#~N+q@qH$Nhh7;dxi zZad>R05>-5vtk>URdq&&cBzPyp2J|MXp`63N?tZS`ACO>ar!_9itpK)^L<{dz)XhP zSC&)~?{>2~WH8_79?{0jff~Y8jN1^yt*n(R7V@)vq`EKL-$<7t>oNmfBvtXtzw@=x zgCFAyN;Z{D+fy*ATF#ui54}qLyz*&Pr`5ea`#sG}JN85OY_$q`Fzz+`GC&;YhBvQR zFlCmKT4>OeRbPM4+E8k`N4Sor?$%3D>s?pP^bNZB;Mzz7$5jpJC7FaGg@0hMKRDB% zSc+{Hm@Ms%v-w0K@v=R_7%NbXHjbT1<48YcVgx1JWJ-3=OIkV0II_4d*X$cd;O+RW zcKr<=*4in1?)PeM0Rnj0&JebU9ym$c>_Q`7*^;J0$;KH zK5iRfyc_jX(&F33E5N$#%(WeD@I=wo2(4h;ldspl&^)CVPiVBQa9HC!J9)+^#NgWB z3W*@WIVlxg#(2@=v>j2zo#!I*8z6wy5!VATs)G$bln|Dtv*S(#~ zq+N-Pc02b1%;%HHg4PD;@p#1$a>V!}?o?J3ye&{laf(%jq6I6(l_4j#gZ_)!5)*@? z-d%2n5Sqxs$$D;AiHAN8apv_N8_Wvnvl#6}@VdWeSr7zs>tkZr(V2G~Q0!HgLG{U@ zT$`1MI0hOSWnz2?`FBNKv!M6Yzf#g4mHqb=RYzV{R*7g(9@;-lqR7QL&^P!|9X!TA z=cv-J$fW@4<|$K`SLg(o?XAH;NR<^Gs51;2JQ;C;dXX+ z27(6UL7a2HVmXpbnNU}WGUF;Oar_=uT~=B}T_$3nH!|Z9rSH6#1Q9z6WxFXgi<{=P zQZ+%DB=xOHKe<%z+Sd-Xo_s`3u?otZCl{lK-PzVC1OewLv)d7zHb*P8)qeO(NR&h% z&L{Q_3>4whYYWN@D~WN$t;Vw6FX{2i)P;SxE5o!d6wT^R@0)OF$2Vs`R3Hhso|fjm#dXlfR{rtZA^@nE>Qj{vWPlsuF9=&~+m3EpnWm#Y{=MCT#5 z_By3T&fot_{i5r1$3Bj2JR{zLysAXSAmk6vb%+KORKXoxIcc5R@*0hHDf$*ughhb= z*fvtgr@s7Vm^Nke4&cJ%6DU^q<&B1532nZ@q65c#_Y9E7*UXqICh8m#H&Q`ucx zWr~zp;|KV8+TnUJWQot+^&uumIZe>ct6Oi9&%_&O$}$Q0@146#1QnM*Go)fdCC20R z-WWG?+vEB>=|3$${^S4v zmB{p~U9*3XelAA-4*E}-{wFB@YHt6xg#Rn$*M$F*(*G;vA9?@ptp60JezFR#)(?O7 z=(obvui#%*N~REqW+sM{7U~-5dM!|j&<~V^grc6RT1}U TTKw2t#Rr63Y0DV-kGuZ?))yJiQy_;~5wLM{0c!l$Q6+pkVmTJ7j+Z&dd>GigCpJ;_T-? zW&YECg9oO2g2^9sdCFf9tcjZ(_t|24pGx(r8kT@6)pg{oLsLGjTFhEe-jFpC0Wl#9 z7tbmgo(;)x&+SQLpKG#}?~0e*;<6L)t?|WEpeZuvR}b#)XM+wQtk4vE{sFJj;v`sO z6hqRqd_P(!^Pys{+lhO@oIwpWpRbcfpT5)SKNHwkwH)cn5H6F!$}sgDzPt(%n*^fI zkk7>c)+C03Is4v;SbE}uu%5=xpGr4Aw1_9!Q$;Dp@97*R*>!~0K_|UIejaw|sgb^4 zd=MquQn8_~x*m^Rkv9YpfvGZi1BL?oJ0G(mMHvV!f9HU)X6CeKAA?&vHNR7)kq^Hz z&whd98q@^KI=A=AESG#@%eD9PGbPznhyJu-atqP=a#+NM@Ir)JVR&(5FY%$w%$m(V zjB-;7o`4wcT`RT0+y3N}j@!N+7R~JVv^MNgnK6r!^(+njUcbPb{a*029a6ukbVA!2 zsA?0dX$Ai1R#XMFV||lTOnU@A<33X5*cU=*++4Qy>o$?p;5OuVV_*U_a2ighErx_p- zl=xc#?`CPsF05a>+h}c|S+2^!>D=b*up6co?Tboq(U%qlCdE|3P6opYOth!}DeZ=Gxr4EH>(a)O2EDsHytoaXNz}4et#lDfzf3BZk@c4e$`5*v93MY+)P6*&V~t5w@B)tl`~B% zZdSRejSAh?((c}Tg|}^bd;-fONtmvQ&1eOg9)#JV4f3zNPJ+?*LJo2b)=6)oL9=Sv zR+zj~L|7sIOygAdNQA)9ucW-C`?lwODT~###LFme0~4Zkx)0mKNO5_%CB<}e20scm zu;k=R$hVm_0PNrztQWL%{U9Yvx_0wR*N5(eIkZDUPflXxv?MmzMoru?A+a&B;5tYv z!T1yfGax;(ylYiSACFgo#&9 z)Z@KqQe_@lSQL~U5C7KMg-Rc|A$0;0-K!j4+J=p*{&2>j+J%28v*`gj&}el&DsI9? zMN+|?KjHkoq|%r6a?~DratU=oYU$uN&bz46#Sn|YKTLggb0e_%56YgF;2RWVr_c~_sCdJXS^mGww#RRgromCIhaecY+gd|3~pt}kKK_D(v_ zPH~et&9JpB6M&({Z4*&4_R_ykxa-}Fo{n!u>()P9EwOw3Tcda=y#&bNDal}!slt?E2;Xnd*r}LtXDozfRga|7e}-^J|K8Sqx=}{f9rbyPi5%5(D;GIEj1?;Z*ZD2==_*5?XuzKngh5pSO9{Wq~x?U^2<$H!YI91k?rO$l|Sec%=aU zyCEL_$6up4=KJ!0+v8E(QS1B-0|1(1paRF>{xZ^0*3oqTm(_I~>xbkYWggA_f0#`? c{DQ~m``Zb4Yk|W{0094C7#x~M6!?AjZ#?05(f|Me literal 0 HcmV?d00001 diff --git a/Python/qsharp/qsharp-0.0.0.1.tar.gz b/Python/qsharp/qsharp-0.0.0.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..80243bf31bd15c3965f80126b8aa198b11f2f834 GIT binary patch literal 2671 zcmV-#3Xt_5iwFp*LsDY`|8a9@VRCRSFfK4IFfK7JbYXG;?Ob_p+d2}@-v<00xCwTX z6u!?kfPt5nrftwBcH^{*hoZ1)iMEMIqC!$hw2S@jJ0v9^IeP3S-o@)ofySc9;c#X+ zBaQiUrCO=}HlVlf81Ckr_*UR+nsi|QfoJwjb^8?h4iPVD>bJwF4rpNU%mQl`@h@mKED6qbG_AUv|6ot zr(HMuA0ogOY2*HXcB)|f$M}!&ALGA^|AY5$%O_`V`cJ<9!Mh&Y|LuDFZv3w|;5Mn@ z{(p8lWt#d_)ADB~6&KL~X;kXP!Wj+O0ddYzEG+J2Zc;1^lQ5(*Js=-<$Ok@=RC1=s zR7k=j&7_FQ4cBurNcCJqm15zY2w6F%GhjN`I#vhO>I^z0lZq$8YREk)l$h%3$Am^Y z2^TDjg~J3`$OCek_sN^eETlXDArn^iM5L*w)o%+Bme`ZKfEeO0&=nCMS{4Vg~<3u*TO+d6LH()LuS<)j?zVB8_1wn%(Lu zDF4zIH&L-rEbJH~oH(@u;|UMAPOU96sdr4Ti#a1>XV5W;sds5sw$jPS&3!N;zst#5 zQp51fIOH|EW`T%9kcqtKn$XB!>9j+FOmQU=(o3^U=)U5Un$DI<11DKl;#h8`v z%Uh)%fNF=LXIZae~1TzOgIkv;gSN`R`mGlph5RZZk zff7W^l!!!MPlhBry%Q=>=dxSW<=(n_eRAh(RJynSLnnC>w(N_I=0(h$r; z+xx7xq;z)!vnfZ0v0N0 zq}ncO0?HHtIJsTwj`2OK1tXyq<}jilg-^+j^}LfQNkJb87-4Y-EP2W!ZZArNFB#~E z-1LSA0ilT&A-IbNJyRIs1&Pl+jRyhaz|1%vk3kvpV!=(8u_t9OUwD~CGafM} z&6IhRgHiVvWLER2&m*uBj)WmJPl zmCPOqX=;=Uikc>Y;gt(+g-}ii*fDb^jWr_I{-DNSs+Cy>S*wXKw`6aS4o-}pUI^mD zjudvEf>A*ZXJun93K!gQ89O%Bd=j5a=4l~Q=Qc8l$XGF*#FaQ5FPA*d#2*8%Sz^?2 z$2dM&V_Yn_ZA5Zj`TAE)^SklidybMXaAy(fzN2rWWQaN@aDazMKU;tnB2eQp$OnPJ z>C()lG-#d8Ql~Swg(w6TmrBZf8Mw*KoUx!}bz&s6T!{$HaMksJB{$MK&L0==`e&oh$LGV7{@IwY=$cCr*{yL637$e|0hgZ|UZ64? zVIOqv&54yo*t>bW1zU#;8GuQcM8+wB2WV27 z+)KVdUh*zUA9Okm#LY4*DAO*oW}Ax^3$JQAn=!w7_18vo--Yt%p>*R|AK!WqJZ39- zE)#E&CMtF=mi7DAT;{@XPECSa8p68Nix*crFJ4$97V%vY>pzdze;S?p^`9oze>PJ8 zX)NnM?ar&0oldh-!`=F;)_=~A4_}`iS3-Y-^`BOwRk!t@M!nW0#|ERrs)#&2Z`}N-c-DQQ%X7FG# z71bx(|37#BuUYHj`9G}xqWw2o|8?=dgY{pG|9Sj>lJkH+cmB`pfB4(Q`tK$P&;Q~1 zKP=&62_H-NSi;8=K9=yYgpVbBJpYIFAFTgi{Rionum24DpU#hthZTLRpRN8=YqYv| z>p$HN;y*V+ivyp9{IRR>SPii74d=LbZ}Co+j^I7&Qa#v7va1B%B_6)1MLY`3S7GAISf!Z)nf< z{$Fd~egAK_x=qag8??VCBvkNCg;UH-@4f5!a3%>V97U~f8m>iz%i_y5M--+%5l@caLb&=+{r z8<|JFuf>9F#qHG|DXN+AAkQ3^M7^-?8*24H}ZcoKmWJ# z`+uDV{{G)aXy-5036H8Qx+V@}V(^6J7iHoJ1G70GiJq2Unid1aFgJ4-ImlsBDhJ!l zh0+TYA6=jjKkiiWu}30KC7;bT+4J_7kWOfqv2a+x3ONh{Vmm1!nPSo*&31AurB9N` zw+JY<3bD-QaQLm$LI3<>n8AT~Xwf4}fX|{ysBAz6P$A}+{KQgt zOew=hIdIh)xaDDNix!0D@EEH+Egg7?YQmMpk-(}=PX|Lh9*|b6=5SR?kQ;-+nls6@ z8?p|xF%01*v%NvQn9j`en(YY_yRBW##(>3)ip-b`aTo9v2#*GCov=V{fI~MzURt4Y zNR6T)TV15#l&@2jK-66e#j^;c72FV^25053;Baz*jPCOV^}rUDjCp0o^xp2ec6Uo; zH)FWFpBe4-@$l&UWUyi^1N;gE=+|GOXGxeLoJmZT@g4(0UATfVLXx${B6iSJSgqk^ zU~(kRVX_udmBH&OFjKNv^Nd9X$Lipvt20m13^|lBv>IF-xFu5qEwbvru}G>MZuge! zcgX~NKNeO;)-y!RqP^|P@&{VCOJrMa?;G__=Lf|C0WxbJtxC{?dlds*NcUvS}OMAp5q#U*u8D%P1_~cmf5YB{mojb1!niQ7aMzf?Z(I= zwt>~7i0!=p${KpxKLjz)N8VLI?{32*{YIVxS&wuY!)n(+);aG)g77~DU(ZKoexrIT zDxUJlALTdp_OqVe0w=C|UtE)+?H>T9=abp~KZZ+R8}fZvdfxqO_BX?4j`C9is}fIl z*S=c*XXYvY+ATfQXZcO@vST(^v9OOXpGZhZNJvOXNJvOXNJvOXNJvOXNJvOXNJvOX dNJvOXNJvOXNJvOXNJvPQ{tbJg6rBK|0009_NRI#j literal 0 HcmV?d00001