Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Build/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Pack-One() {
-c $Env:BUILD_CONFIGURATION `
-v $Env:BUILD_VERBOSITY `
-o $Env:NUGET_OUTDIR `
/property:PackageVersion=$Env:NUGET_VERSION
/property:PackageVersion=$Env:NUGET_VERSION

if ($LastExitCode -ne 0) {
Write-Host "##vso[task.logissue type=error;]Failed to pack $project."
Expand All @@ -29,7 +29,7 @@ Write-Host "##[info]Pack Chemistry library"
Pack-One '../Chemistry/src/DataModel/DataModel.csproj'

Write-Host "##[info]Pack QML library"
Pack-One '../MachineLearning/src/DataModel/DataModel.csproj'
Pack-One '../MachineLearning/src/MachineLearning.csproj'

Write-Host "##[info]Pack Numerics library"
Pack-One '../Numerics/src/Numerics.csproj'
Expand Down
76 changes: 29 additions & 47 deletions MachineLearning.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MachineLearning", "MachineLearning", "{A16B06ED-70E8-4494-B040-D446F0F74588}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MachineLearning", "MachineLearning", "{D067C787-94C3-4DB8-9012-1F22AE784BEF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E540364C-047F-446E-B8C1-CD41224E2282}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearningTests", "MachineLearning\tests\MachineLearningTests.csproj", "{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runtime", "MachineLearning\src\Runtime\Runtime.csproj", "{4C399D64-0435-47E0-99D3-AA898E640717}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModel", "MachineLearning\src\DataModel\DataModel.csproj", "{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearningTests", "MachineLearning\tests\MachineLearningTests.csproj", "{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearning", "MachineLearning\src\MachineLearning.csproj", "{B045BF35-6BE6-4982-9618-8725C70D3F91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -26,47 +22,33 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4C399D64-0435-47E0-99D3-AA898E640717}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x64.ActiveCfg = Debug|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x64.Build.0 = Debug|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x86.ActiveCfg = Debug|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Debug|x86.Build.0 = Debug|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Release|Any CPU.Build.0 = Release|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Release|x64.ActiveCfg = Release|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Release|x64.Build.0 = Release|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Release|x86.ActiveCfg = Release|Any CPU
{4C399D64-0435-47E0-99D3-AA898E640717}.Release|x86.Build.0 = Release|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x64.ActiveCfg = Debug|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x64.Build.0 = Debug|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x86.ActiveCfg = Debug|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Debug|x86.Build.0 = Debug|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|Any CPU.Build.0 = Release|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x64.ActiveCfg = Release|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x64.Build.0 = Release|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x86.ActiveCfg = Release|Any CPU
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B}.Release|x86.Build.0 = Release|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x64.ActiveCfg = Debug|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x64.Build.0 = Debug|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x86.ActiveCfg = Debug|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Debug|x86.Build.0 = Debug|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|Any CPU.Build.0 = Release|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x64.ActiveCfg = Release|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x64.Build.0 = Release|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x86.ActiveCfg = Release|Any CPU
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B}.Release|x86.Build.0 = Release|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x64.ActiveCfg = Debug|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x64.Build.0 = Debug|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x86.ActiveCfg = Debug|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Debug|x86.Build.0 = Debug|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|Any CPU.Build.0 = Release|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x64.ActiveCfg = Release|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x64.Build.0 = Release|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x86.ActiveCfg = Release|Any CPU
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}.Release|x86.Build.0 = Release|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x64.ActiveCfg = Debug|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x64.Build.0 = Debug|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x86.ActiveCfg = Debug|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Debug|x86.Build.0 = Debug|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|Any CPU.Build.0 = Release|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x64.ActiveCfg = Release|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x64.Build.0 = Release|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x86.ActiveCfg = Release|Any CPU
{B045BF35-6BE6-4982-9618-8725C70D3F91}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E540364C-047F-446E-B8C1-CD41224E2282} = {A16B06ED-70E8-4494-B040-D446F0F74588}
{4C399D64-0435-47E0-99D3-AA898E640717} = {E540364C-047F-446E-B8C1-CD41224E2282}
{E4A725A7-3525-4FC5-9794-4317B5DB9C9B} = {E540364C-047F-446E-B8C1-CD41224E2282}
{0F1A243B-5263-4F97-ACAE-A7A6BAB8163B} = {A16B06ED-70E8-4494-B040-D446F0F74588}
{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C} = {D067C787-94C3-4DB8-9012-1F22AE784BEF}
{B045BF35-6BE6-4982-9618-8725C70D3F91} = {D067C787-94C3-4DB8-9012-1F22AE784BEF}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Quantum.MachineLearning {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;


operation _PrepareClassification(
encoder : (LittleEndian => Unit is Adj + Ctl),
parameters : Double[],
Expand All @@ -28,7 +28,7 @@ namespace Microsoft.Quantum.MachineLearning {
)
: Double {
let nQubits = FeatureRegisterSize(sample);
let circEnc = NoisyInputEncoder(tolerance / IntAsDouble(Length(gates!)), sample);
let circEnc = ApproximateInputEncoder(tolerance / IntAsDouble(Length(gates!)), sample);
let encodedSample = StateGenerator(nQubits, circEnc);
return 1.0 - EstimateFrequencyA(
_PrepareClassification(encodedSample::Apply, parameters, gates, _),
Expand Down
66 changes: 66 additions & 0 deletions MachineLearning/src/Convert.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.MachineLearning {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Math;

function unFlattenSchedule(sc : Int[][]) : SamplingSchedule
{
mutable ret = new Range[0];
for (flattenedRange in sc) {
set ret += [flattenedRange[0]..flattenedRange[1]..flattenedRange[2]];
}
return SamplingSchedule(ret);
}

function unFlattenLabeledSamples(dat:Double[][], labs:Int[]) : LabeledSample[] {
mutable cnt = MinI(Length(dat), Length(labs));
mutable ret = new LabeledSample[cnt];
for (j in 0..(cnt - 1)) {
set ret w/= j <- LabeledSample(dat[j], labs[j]);
}
return ret;
}

/// Debugging prop
operation unFlattenPauli(p:Int): Pauli
{
if (p==1)
{
return PauliX;
}
if (p==2)
{
return PauliY;
}
if (p==3)
{
return PauliZ;
}
return PauliI;
}

/// Debugging prop
/// upcasting controlled rotation in flat representation (paramIx,pauliIx,gateSpan)
operation unFlattenControlledRotation(cod:Int[]): ControlledRotation {
return ControlledRotation(
GateSpan(
cod[2], cod[3...]
),
unFlattenPauli(cod[1]),
cod[0]
);
}

/// Debugging prop
operation unFlattenGateSequence(seq: Int[][]) : GateSequence {
mutable tmp = new ControlledRotation[Length(seq)];
for (icr in 0..(Length(seq) - 1)) {
set tmp w/= icr <- unFlattenControlledRotation(seq[icr]);
}
return GateSequence(tmp);
}

}
Loading