Skip to content
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
467 changes: 467 additions & 0 deletions algorithms/qaoa/knapsack/qaoa_knapsack.ipynb

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions algorithms/qaoa/knapsack/qaoa_knapsack.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"friendly_name": "Constrained QAOA: Knapsack",
"description": "Optimizing the Knapsack problem using the QAOA Algorithm",
"problem_domain_tags": ["optimization"],
"qmod_type": ["algorithms"],
"level": ["demos"]
}
26 changes: 26 additions & 0 deletions algorithms/qaoa/knapsack/qaoa_knapsack.qmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
qstruct KnapsackVars {
a: qnum<3>;
b: qnum<2>;
}

qfunc apply_cost(gamma: real, v: KnapsackVars) {
aux: qbit;
within {
aux = ((v.a * 2) + (v.b * 3)) <= 12;
} apply {
control (aux) {
phase (-((v.a * 3) + (v.b * 5)), gamma);
}
}
}

qfunc main(params: real[6], output v: KnapsackVars) {
allocate(v.size, v);
hadamard_transform(v);
repeat (i: 3) {
apply_cost(params[2 * i], v);
apply_to_all(lambda(q) {
RX(params[(2 * i) + 1], q);
}, v);
}
}
44 changes: 44 additions & 0 deletions algorithms/qaoa/knapsack/qaoa_knapsack.synthesis_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"constraints": {
"max_gate_count": {},
"optimization_parameter": "no_opt"
},
"preferences": {
"machine_precision": 8,
"custom_hardware_settings": {
"basis_gates": [
"id",
"cy",
"sx",
"z",
"cx",
"u",
"rx",
"y",
"r",
"t",
"u1",
"tdg",
"rz",
"cz",
"x",
"s",
"sxdg",
"h",
"u2",
"sdg",
"ry",
"p"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"synthesize_all_separately": false,
"optimization_level": 3,
"output_format": ["qasm"],
"pretty_qasm": true,
"transpilation_option": "auto optimize",
"timeout_seconds": 300,
"random_seed": 695440439
}
}
Loading
Loading