This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
Initial version of quantum machine learning library / QCC classifier #176
Merged
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
7f62673
Merged PR 2339: Initial development on QML library.
cfb2ba4
Merge branch 'master' into feature/qml
6d23ce3
Unit tests for new operations and functions in M.Q.Standard used to s…
20529cf
Merge branch 'master' into feature/qml
3e0517d
Merge branch 'master' into feature/qml
3201cde
Merge branch 'master' into feature/qml
cgranade 929478b
Add repeated operation (#153) (#180)
7e4440a
Merge branch 'feature/qml' of github.com:Microsoft/QuantumLibraries i…
cgranade 22a3dd5
Fix merge conflict.
cgranade 1423aca
Simplify classification API. (#179)
cae0050
Bounded univariate minimization (#183)
0e3b5f9
Add placeholder for QML unit tests. (#185)
c10eea4
Consolidate exact and approximate multiplexing logic. (#184)
f7be904
Update QML feature branch with latest master. (#191)
38120f2
Use new UDTs to consolidate and simplify training / validation API. (…
67cd369
Update QML feature to master. (#198)
3e1e461
Simplify gradient estimation and classifier structure generation (#200)
a35aa5f
Final prep for QML review (#205)
0ba2327
Merge branch 'master' into cgranade/master→qml
cgranade 680c52e
Merge pull request #208 from microsoft/cgranade/master→qml
d8c4371
Fix path to pubkey for QML signing.
cgranade 99ddbae
Merge pull request #213 from microsoft/cgranade/fix-qml-key
27cae56
Update QML signing for new pipeline. (#217)
f1e9ade
Merge branch 'master' into final-qml-api
cgranade a8a2a95
Update project files to newest QDK release.
cgranade bf09e3e
One more project file update.
cgranade caee3d6
Added model structure to SequentialModel.
cgranade b0da363
Combined GateSpan and ControlledRotation.
cgranade 5590c97
Types.qs ☑
cgranade c3889e3
Classification.qs ☑
cgranade a158b39
GradientEstimation.qs ☑
cgranade a1771fb
InputEncoding.qs ☑
cgranade 8a3188a
Structure.qs ☑
cgranade d9fccf2
Training.qs ☑
cgranade 4bebaec
Validation.qs ☑
cgranade fa31ab5
Merge branch 'feature/qml' into final-qml-api
c66bd7d
Fix build properties to use latest QDK version.
cgranade e61441a
Update MachineLearning/src/Types.qs
cgranade 89511e0
Addressing feedback from @bettinaheim.
cgranade 063948a
Merge branch 'final-qml-api' of https://github.com/cgranade/QuantumLi…
cgranade 482e25f
Merge pull request #220 from cgranade/final-qml-api
7997c9a
Began adding more tests.
cgranade 2076e8c
New test for applysequentialclassifier.
cgranade cfb10d3
Reduce warning count.
cgranade 1c85c75
More tests of structure functions.
cgranade fd0b40a
Fixed test and eliminated some warnings.
cgranade 748d129
Further warning elimination.
cgranade a387017
Tests for InferredLabel and InferredLabels.
cgranade 1039a0d
Undo printf-style debugging.
cgranade d9ff816
Update MachineLearning/tests/ClassificationTests.qs
cgranade daec81b
Improve QML test coverage. (#224)
d2de0e0
Merge branch 'master' into master→qml
cgranade 73a3686
Merge pull request #227 from cgranade/master→qml
3982206
Merge branch 'master' into feature/qml
bettinaheim 86712bd
Addressing feedback from @bettinaheim. (#233)
22e61d7
Added new verbosemessage training option.
cgranade 61d5e4f
Cache state preparation using BoundCA.
cgranade 1feae2d
Merge branch 'feature/qml' into cgranade/use-udt-perf
01dc4e1
Addressing @bettinaheim's feedback.
cgranade bdc04ba
Fix type of Ignore.
cgranade df27b30
Add verbose option to TrainingOptions UDT, cache state preparation (#…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| | ||
| 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", "{D067C787-94C3-4DB8-9012-1F22AE784BEF}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearningTests", "MachineLearning\tests\MachineLearningTests.csproj", "{94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachineLearning", "MachineLearning\src\MachineLearning.csproj", "{B045BF35-6BE6-4982-9618-8725C70D3F91}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Debug|x64 = Debug|x64 | ||
| Debug|x86 = Debug|x86 | ||
| Release|Any CPU = Release|Any CPU | ||
| Release|x64 = Release|x64 | ||
| Release|x86 = Release|x86 | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {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 | ||
| {94EBDF5F-0A9D-4CE5-9D16-3FF323B8792C} = {D067C787-94C3-4DB8-9012-1F22AE784BEF} | ||
| {B045BF35-6BE6-4982-9618-8725C70D3F91} = {D067C787-94C3-4DB8-9012-1F22AE784BEF} | ||
| EndGlobalSection | ||
| EndGlobal | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using System.Reflection; | ||
|
|
||
| // Attributes for delay-signing | ||
| #if SIGNED | ||
| [assembly:AssemblyKeyFile("..\\..\\Build\\267DevDivSNKey2048.snk")] | ||
| [assembly:AssemblyDelaySign(true)] | ||
| #endif | ||
|
|
||
| internal static class SigningConstants | ||
| { | ||
| #if SIGNED | ||
| public const string PUBLIC_KEY = ", PublicKey=" + | ||
| "002400000c800000140100000602000000240000525341310008000001000100613399aff18ef1" + | ||
| "a2c2514a273a42d9042b72321f1757102df9ebada69923e2738406c21e5b801552ab8d200a65a2" + | ||
| "35e001ac9adc25f2d811eb09496a4c6a59d4619589c69f5baf0c4179a47311d92555cd006acc8b" + | ||
| "5959f2bd6e10e360c34537a1d266da8085856583c85d81da7f3ec01ed9564c58d93d713cd0172c" + | ||
| "8e23a10f0239b80c96b07736f5d8b022542a4e74251a5f432824318b3539a5a087f8e53d2f135f" + | ||
| "9ca47f3bb2e10aff0af0849504fb7cea3ff192dc8de0edad64c68efde34c56d302ad55fd6e80f3" + | ||
| "02d5efcdeae953658d3452561b5f36c542efdbdd9f888538d374cef106acf7d93a4445c3c73cd9" + | ||
| "11f0571aaf3d54da12b11ddec375b3"; | ||
| #else | ||
| public const string PUBLIC_KEY = ""; | ||
| #endif | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| namespace Microsoft.Quantum.MachineLearning { | ||
| open Microsoft.Quantum.Math; | ||
| open Microsoft.Quantum.Characterization; | ||
| open Microsoft.Quantum.Arithmetic; | ||
| open Microsoft.Quantum.Arrays; | ||
| open Microsoft.Quantum.Intrinsic; | ||
| open Microsoft.Quantum.Canon; | ||
| open Microsoft.Quantum.Convert; | ||
|
|
||
|
|
||
| operation _PrepareClassification( | ||
| encoder : (LittleEndian => Unit is Adj + Ctl), | ||
| model : SequentialModel, | ||
| target : Qubit[] | ||
| ) | ||
| : Unit is Adj { | ||
| encoder(LittleEndian(target)); | ||
| ApplySequentialClassifier(model, target); | ||
| } | ||
|
|
||
| /// # Summary | ||
| /// Given a sample and a sequential classifier, estimates the | ||
| /// classification probability for that sample by repeatedly measuring | ||
| /// the output of the classifier on the given sample. | ||
| /// | ||
| /// # Input | ||
| /// ## tolerance | ||
| /// The tolerance to allow in encoding the sample into a state preparation | ||
| /// operation. | ||
| /// ## model | ||
| /// The sequential model to be used to estimate the classification | ||
| /// probability for the given sample. | ||
| /// ## sample | ||
| /// The feature vector for the sample to be classified. | ||
| /// ## nMeasurements | ||
| /// The number of measusrements to use in estimating the classification | ||
| /// probability. | ||
| /// # Output | ||
| /// An estimate of the classification probability for the given sample. | ||
| operation EstimateClassificationProbability( | ||
| tolerance : Double, | ||
| model : SequentialModel, | ||
| sample : Double[], | ||
| nMeasurements: Int | ||
| ) | ||
| : Double { | ||
| let encodedSample = ApproximateInputEncoder(tolerance / IntAsDouble(Length(model::Structure)), sample); | ||
| return 1.0 - EstimateFrequencyA( | ||
| _PrepareClassification(encodedSample::Prepare, model, _), | ||
| _TailMeasurement(encodedSample::NQubits), | ||
| encodedSample::NQubits, | ||
| nMeasurements | ||
| ); | ||
| } | ||
|
|
||
| /// # Summary | ||
| /// Given a set of samples and a sequential classifier, estimates the | ||
| /// classification probability for those samples by repeatedly measuring | ||
| /// the output of the classifier on each sample. | ||
| /// | ||
| /// # Input | ||
| /// ## tolerance | ||
| /// The tolerance to allow in encoding the sample into a state preparation | ||
| /// operation. | ||
| /// ## model | ||
| /// The sequential model to be used to estimate the classification | ||
| /// probabilities for the given samples. | ||
| /// ## samples | ||
| /// An array of feature vectors for each sample to be classified. | ||
| /// ## nMeasurements | ||
| /// The number of measusrements to use in estimating the classification | ||
| /// probability. | ||
| /// # Output | ||
| /// An array of estimates of the classification probability for each given | ||
| /// sample. | ||
| operation EstimateClassificationProbabilities( | ||
| tolerance : Double, | ||
| model : SequentialModel, | ||
| samples : Double[][], | ||
| nMeasurements : Int | ||
| ) | ||
| : Double[] { | ||
| let effectiveTolerance = tolerance / IntAsDouble(Length(model::Structure)); | ||
| return ForEach( | ||
| EstimateClassificationProbability( | ||
| effectiveTolerance, model, _, nMeasurements | ||
| ), | ||
| samples | ||
| ); | ||
| } | ||
|
|
||
| /// # Summary | ||
| /// Given a of classification probability and a bias, returns the | ||
| /// label inferred from that probability. | ||
| /// | ||
| /// # Input | ||
| /// ## bias | ||
| /// The bias between two classes, typically the result of training a | ||
| /// classifier. | ||
| /// ## probability | ||
| /// A classification probabilities for a particular sample, typicaly | ||
| /// resulting from estimating its classification frequency. | ||
| /// | ||
| /// # Output | ||
| /// The label inferred from the given classification probability. | ||
| function InferredLabel(bias : Double, probability : Double) : Int { | ||
| return probability + bias > 0.5 ? 1 | 0; | ||
| } | ||
|
|
||
| /// # Summary | ||
| /// Given an array of classification probabilities and a bias, returns the | ||
| /// label inferred from each probability. | ||
| /// | ||
| /// # Input | ||
| /// ## bias | ||
| /// The bias between two classes, typically the result of training a | ||
| /// classifier. | ||
| /// ## probabilities | ||
| /// An array of classification probabilities for a set of samples, typicaly | ||
| /// resulting from estimating classification frequencies. | ||
| /// | ||
| /// # Output | ||
| /// The label inferred from each classification probability. | ||
| function InferredLabels(bias : Double, probabilities : Double[]): Int[] { | ||
| return Mapped(InferredLabel(bias, _), probabilities); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be overwritten if it's opened with VS19 I believe. It might still be worth it quickly doing that, since we no longer support VS17.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I generated this with
dotnet new sln, didn't realize that it used an older version of the sln format.