-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgraded knapsack notebook, moved to algorithms
- Loading branch information
1 parent
2bba551
commit 937b7b7
Showing
9 changed files
with
574 additions
and
1,163 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,7 @@ | ||
{ | ||
"friendly_name": "Constrained QAOA: Knapsack", | ||
"description": "Optimizing the Knapsack problem using the QAOA Algorithm", | ||
"problem_domain_tags": ["optimization"], | ||
"qmod_type": ["algorithms"], | ||
"level": ["demos"] | ||
} |
This file contains 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,32 @@ | ||
qstruct KnapsackVars { | ||
a: qnum<3>; | ||
b: qnum<2>; | ||
} | ||
|
||
|
||
|
||
qfunc eval_constraint(v: KnapsackVars, output aux: qbit) { | ||
aux = ((v.a * 2) + (v.b * 3)) <= 12; | ||
} | ||
|
||
qfunc apply_cost(gamma: real, v: KnapsackVars) { | ||
aux: qbit; | ||
within { | ||
eval_constraint(v, aux); | ||
} 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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
algorithms/qaoa/knapsack/qaoa_knapsack.synthesis_options.json
This file contains 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,43 @@ | ||
{ | ||
"constraints": { | ||
"max_gate_count": {}, | ||
"optimization_parameter": "no_opt" | ||
}, | ||
"preferences": { | ||
"machine_precision": 8, | ||
"custom_hardware_settings": { | ||
"basis_gates": [ | ||
"x", | ||
"p", | ||
"tdg", | ||
"sx", | ||
"rz", | ||
"sxdg", | ||
"sdg", | ||
"ry", | ||
"cy", | ||
"t", | ||
"y", | ||
"s", | ||
"u1", | ||
"cz", | ||
"z", | ||
"rx", | ||
"u2", | ||
"h", | ||
"u", | ||
"r", | ||
"id", | ||
"cx" | ||
], | ||
"is_symmetric_connectivity": true | ||
}, | ||
"debug_mode": true, | ||
"synthesize_all_separately": false, | ||
"output_format": ["qasm"], | ||
"pretty_qasm": true, | ||
"transpilation_option": "auto optimize", | ||
"timeout_seconds": 300, | ||
"random_seed": 3016072189 | ||
} | ||
} |
Oops, something went wrong.