Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Create new kata: Bounded Knapsack #457

Merged
merged 115 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
7ac5bd6
Create new Kata: BoundedKnapsack
louiswmarquis Aug 11, 2020
b63f05c
Add files via upload
louiswmarquis Aug 11, 2020
f1e9507
Delete bk
louiswmarquis Aug 11, 2020
f1075c5
Update ReferenceImplementation.qs
louiswmarquis Aug 11, 2020
8538186
Update ReferenceImplementation.qs
louiswmarquis Aug 11, 2020
fc6f258
Delete Tasks.qs
louiswmarquis Aug 11, 2020
f7aab3b
Add files via upload
louiswmarquis Aug 11, 2020
be8d973
Delete Tasks.qs
louiswmarquis Aug 11, 2020
3c4e1b1
Add files via upload
louiswmarquis Aug 11, 2020
5b73f12
Update Tasks.qs
louiswmarquis Aug 11, 2020
3104fce
Merge branch 'master' into emax-wenjun-knapsack
msoeken Aug 11, 2020
564f5ae
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
d97fa05
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
bf010e9
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
93f0144
Update BoundedKnapsack/ReferenceImplementation.qs
louiswmarquis Aug 12, 2020
657c484
Update BoundedKnapsack/ReferenceImplementation.qs
louiswmarquis Aug 12, 2020
8b69fa1
Update BoundedKnapsack.csproj
louiswmarquis Aug 12, 2020
2516521
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
a8436b0
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
de82114
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
be041ef
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
334d622
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
78d4fcb
Update BoundedKnapsack/Hints.qs
louiswmarquis Aug 12, 2020
dc66123
Update BoundedKnapsack/ReferenceImplementation.qs
louiswmarquis Aug 12, 2020
e17f08f
Apply suggestions from code review
louiswmarquis Aug 12, 2020
8445eb5
Update ReferenceImplementation.qs
louiswmarquis Aug 12, 2020
532cf51
Update ReferenceImplementation.qs
louiswmarquis Aug 12, 2020
9588a4c
Update Tasks.qs
louiswmarquis Aug 12, 2020
65319d6
Update Hints.qs
louiswmarquis Aug 12, 2020
3775371
Update Hints.qs
louiswmarquis Aug 12, 2020
4d9fee8
Update ReferenceImplementation.qs
louiswmarquis Aug 12, 2020
c1be683
Update Tests.qs
louiswmarquis Aug 12, 2020
4f0aea9
Update ReferenceImplementation.qs
louiswmarquis Aug 12, 2020
d3034e7
Apply suggestions from code review
louiswmarquis Aug 15, 2020
76a8d02
Apply suggestions from code review
louiswmarquis Aug 15, 2020
6e562cb
Apply suggestions from code review
louiswmarquis Aug 15, 2020
03ccc97
Update Tests.qs
louiswmarquis Aug 15, 2020
23dafb3
Apply suggestions from code review
louiswmarquis Aug 15, 2020
41ddc97
Update BoundedKnapsack/ReferenceImplementation.qs
louiswmarquis Aug 15, 2020
1aefc98
Apply suggestions from code review
louiswmarquis Aug 15, 2020
c207387
Create Hints.md
louiswmarquis Aug 15, 2020
309ee07
Update Hints.md
louiswmarquis Aug 15, 2020
cb1458f
Delete Hints.qs
louiswmarquis Aug 15, 2020
d95464b
Update BoundedKnapsack/ReferenceImplementation.qs
louiswmarquis Aug 15, 2020
80834b1
Update Tasks.qs
louiswmarquis Aug 15, 2020
11619e7
Merge branch 'master' into emax-wenjun-knapsack
louiswmarquis Aug 15, 2020
b37c902
Update ReferenceImplementation.qs
louiswmarquis Aug 15, 2020
272d808
Update Tests.qs
louiswmarquis Aug 15, 2020
c6b83ad
Update ReferenceImplementation.qs
louiswmarquis Aug 15, 2020
3d7fe66
Create README.md
louiswmarquis Aug 16, 2020
9c5fe0e
Update README.md
louiswmarquis Aug 16, 2020
3b9af49
Update README.md
louiswmarquis Aug 17, 2020
09cdf16
Merge branch 'master' into emax-wenjun-knapsack
louiswmarquis Aug 19, 2020
54bb61f
Merge branch 'master' into emax-wenjun-knapsack
louiswmarquis Aug 24, 2020
55c7024
Apply suggestions from code review
louiswmarquis Aug 25, 2020
0fde84d
Update TestSuiteRunner.cs
louiswmarquis Aug 25, 2020
d3b1864
Update Tests.qs
louiswmarquis Aug 25, 2020
0ca2d99
Update Tasks.qs
louiswmarquis Aug 25, 2020
65a375d
Update ReferenceImplementation.qs
louiswmarquis Aug 25, 2020
62930dc
Update Hints.md
louiswmarquis Aug 25, 2020
4d8bea7
Update Hints.md
louiswmarquis Aug 25, 2020
2b2bd26
Update TestSuiteRunner.cs
louiswmarquis Aug 25, 2020
f4b0c8e
Update Tests.qs
louiswmarquis Aug 25, 2020
163b398
Update BoundedKnapsack/BoundedKnapsack.csproj
louiswmarquis Aug 25, 2020
c3bd934
Update Tests.qs
louiswmarquis Aug 25, 2020
27a149a
Update Tests.qs
louiswmarquis Aug 25, 2020
2cd1648
Update Hints.md
louiswmarquis Aug 25, 2020
8c1d065
Update Tasks.qs
louiswmarquis Aug 25, 2020
52d0357
Update ReferenceImplementation.qs
louiswmarquis Aug 25, 2020
baa7459
Update ReferenceImplementation.qs
louiswmarquis Aug 25, 2020
fefac5e
Update Tests.qs
louiswmarquis Aug 25, 2020
0d06225
Update Tests.qs
louiswmarquis Aug 25, 2020
4711a5d
Update Tests.qs
louiswmarquis Aug 25, 2020
02a7f66
Update BoundedKnapsack.csproj
louiswmarquis Aug 25, 2020
4b172b2
Update ReferenceImplementation.qs
louiswmarquis Aug 25, 2020
248679f
Update Tests.qs
louiswmarquis Aug 25, 2020
3f82aff
Update BoundedKnapsack.csproj
louiswmarquis Aug 25, 2020
baacfd7
Merge branch 'master' into emax-wenjun-knapsack
louiswmarquis Aug 27, 2020
8e666ac
Merge branch 'master' into emax-wenjun-knapsack
louiswmarquis Sep 1, 2020
57796cc
Update ReferenceImplementation.qs
louiswmarquis Sep 1, 2020
f5258b3
Update Tasks.qs
louiswmarquis Sep 1, 2020
8b2960e
Update TestSuiteRunner.cs
louiswmarquis Sep 1, 2020
bb70523
Update Tests.qs
louiswmarquis Sep 1, 2020
1fdcbc8
Update BoundedKnapsack.csproj
louiswmarquis Sep 2, 2020
4a2bb4d
Update BoundedKnapsack.csproj
louiswmarquis Sep 2, 2020
b37aef6
Update BoundedKnapsack.csproj
louiswmarquis Sep 3, 2020
d173039
Merge branch 'master' into emax-wenjun-knapsack
louiswmarquis Sep 3, 2020
f6a7244
Update BoundedKnapsack.csproj
louiswmarquis Sep 3, 2020
fac3f53
Merge branch 'master' into emax-wenjun-knapsack
louiswmarquis Sep 8, 2020
e4f71a8
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Sep 9, 2020
35e6130
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Sep 11, 2020
397d23b
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Sep 12, 2020
6c6d733
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Sep 19, 2020
d35fd95
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Oct 17, 2020
acb20df
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Oct 21, 2020
1d3fea9
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Oct 26, 2020
29a0174
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Oct 28, 2020
b91f73f
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Nov 11, 2020
9e5ddd6
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Nov 15, 2020
2cc0b86
Merge branch 'main' into emax-wenjun-knapsack
louiswmarquis Nov 20, 2020
82d7be0
Update to 0.15 (except tests) and latest kata structure
tcNickolas Feb 25, 2021
506ea9f
Continue update, polish tasks 1.1-1.2
tcNickolas Feb 26, 2021
4f16e07
Clean up task 1.3
tcNickolas Feb 26, 2021
aecb8a3
Clean up tasks 1.4-5, unify tests
tcNickolas Mar 9, 2021
f33b69d
Clean up tasks 1.6-8, unify tests
tcNickolas Mar 11, 2021
b380fcf
Clean up task 2.1
tcNickolas Jul 13, 2021
2cfabfe
Rewrite task 2.2 to use type parameterization
tcNickolas Jul 13, 2021
0134534
Clean up task 2.3, rename bounds -> limits
tcNickolas Jul 13, 2021
a67c016
Clean up tasks 2.4 and 2.5
tcNickolas Jul 14, 2021
3d4fc05
Clean up task 2.6
tcNickolas Jul 14, 2021
738e7bb
Clean up tasks 2.7 and 2.8
tcNickolas Jul 15, 2021
578192f
Clean up task 2.9
tcNickolas Jul 15, 2021
6a62035
Refactor parts I and II to use unified variable names and test struct…
tcNickolas Jul 15, 2021
9347a20
Remove part III tasks for now
tcNickolas Jul 15, 2021
32f1b3c
Merge branch 'main' into emax-wenjun-knapsack
tcNickolas Jul 15, 2021
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
18 changes: 18 additions & 0 deletions BoundedKnapsack/BoundedKnapsack.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
louiswmarquis marked this conversation as resolved.
Show resolved Hide resolved
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<IsPackable>false</IsPackable>
<RootNamespace>Quantum.Kata.BoundedKnapsack</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Standard" Version="0.12.20072031" />
<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.12.20072031" />
<PackageReference Include="Microsoft.Quantum.Xunit" Version="0.12.20072031" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions BoundedKnapsack/BoundedKnapsack.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.705
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BoundedKnapsack", "BoundedKnapsack.csproj", "{A924553C-0AF5-4802-8A3A-E5E074DC34AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A924553C-0AF5-4802-8A3A-E5E074DC34AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A924553C-0AF5-4802-8A3A-E5E074DC34AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A924553C-0AF5-4802-8A3A-E5E074DC34AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A924553C-0AF5-4802-8A3A-E5E074DC34AB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DCD43C51-6BFB-465B-808F-52F685E3257E}
EndGlobalSection
EndGlobal
96 changes: 96 additions & 0 deletions BoundedKnapsack/Hints.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//////////////////////////////////////////////////////////////////////
louiswmarquis marked this conversation as resolved.
Show resolved Hide resolved
// This file contains hints to all tasks.
// The tasks themselves can be found in Tasks.qs file.
// We recommend that you try to solve the tasks yourself first,
// but feel free to look up these hints, and ultimately
// the solutions if you get stuck.
//////////////////////////////////////////////////////////////////////

// Hints have been provided to clarify and guide your work through some of
// the harder or more complicated katas. The hints within each task gradually reveal
// more and more of the solution. You might consider reading hints for a task
// up to a point of understanding, and then try finishing the task yourself.




// Task 1.2. Calculate Total Weight or Profit
//
// 1) The IncrementByInteger operation may be of use: https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.arithmetic.incrementbyinteger
//
// 2) How does the state of a qubit in the register affect whether its corresponding value is added into the total?




// Task 1.3. Compare Qubit Array with Integer (>)
//
// 1) Given two classical bitstrings, what would be the most straightforward way to compare them?
//
// 2) Are the more significant bits or the less significants bits more important in the comparison of two integers?
//
// 3) If we begin at the most significant bits and iterate downwards, at what point can we conclude whether a or b is larger?
//
// 4) Answer to previous question: We can conclude which one is larger upon arriving at the highest bit that has different value
// in a and b. Example: If a = 10101101₂ (173) and b = 10100011₂ (163), the highest 4 digits are the same in a and b. The digit with
// little-endian index 3 (5th from the left) is the highest bit that has different values in a and b. Since it is 1 in a and 0 in b,
// we conclude a > b.
//
// 5) After passing through one of a's qubits in iteration, how can we temporarily change its state so that it can be used to determine whether
// a later, less significant bit is the first bit with different values in a and b?




// Task 1.4. Compare Qubit Array with Integer (≤)
//
// 1) Is it necessary to go through all of the logic like we did in Task 1.3, or is there an easier way to conserve code?




// Task 2.2. Convert Qubit Register into Jagged Qubit Array
//
// 1) For each i, xᵢ can have values from 0 to bᵢ. How many distinct values are thus possible for xᵢ? What's the minimum number of qubits
// to hold this many distinct values?
//
// 2) Additional information on jagged arrays: https://docs.microsoft.com/quantum/user-guide/language/types#array-types




// Task 2.4. Increment Qubit Array by Product of an Integer and a different Qubit Array
//
// 1) Given two classical unsigned integers and their bitstrings, how would you calculate their product? Could you split this product into
// partial products?
//
// 2) Additional information on multiplication: https://en.wikipedia.org/wiki/Binary_multiplier#Binary_numbers




// Task 2.5. Calculation of Total Weight
//
// 1) How do the weight of an item and the number of instances of that item affect how much weight that item type contributes to the total?




// Task 3.1. Using Grover Search with Knapsack Oracle to solve (a slightly modified version of the) Knapsack Decision Problem
//
// 1) How many total qubits are necessary for the register? You may want to revisit Hint #1 for Task 2.2.
//
// 2) If you know how to implement the quantum counting algorithm in Q#, feel free to do so. Otherwise, you might consider
// using the iteration method in the GraphColoring kata, or classicaly calculating the ideal number of iterations.




// Task 3.2. Solving the Bounded Knapsack Optimization Problem
//
// 1) The key in this task is choosing an efficient method to adjust the value P over several calls to Grover's Algorithm, to ultimately
// identify the maximum achievable profit value. The method should minimize the number of calls to Grover's Algorithm and the total number of oracle
// oracle calls.
//
// 2) There are numerous methods of performing the task as previously described. One such method is exponential search. See
// https://en.wikipedia.org/wiki/Exponential_search for more information.
Loading