Product/matanvax2/cls 5625 beautify qmods#1440
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
| state_loading(state[1:state.len], state[0]); | ||
| allocate(phase); | ||
| qpe(lambda() { | ||
| my_grover_operator(state); |
There was a problem hiding this comment.
why not changing to the regular grover_operator?
There was a problem hiding this comment.
I guess the reason is the intent of this example, to demonstrate the QCM algorithm in full. I would ask the same question about the notebook first..
| // eigenvalues of a given matrix by applying an exactly exponentiated unitary | ||
| // operator. | ||
|
|
||
| unitary_for_HM: real[][] = [ // the unitary matrix obtained by exp(i·2π·HM) |
There was a problem hiding this comment.
what is HM? it is not defined
| // operator. | ||
|
|
||
| unitary_for_HM: real[][] = [ // the unitary matrix obtained by exp(i·2π·HM) | ||
| [ |
There was a problem hiding this comment.
you can write each row of the matrix in a single row
There was a problem hiding this comment.
I'm not sure it's better - it yields lines with 170 characters, which requires right-scrolling and is typically not recommended.
| // of the 3-SAT problem, showing how quantum amplitude amplification can be | ||
| // used to find a satisfying assignment. | ||
|
|
||
| qperm sat3_oracle(const x: qbit[], res: qbit) { |
There was a problem hiding this comment.
Identifiers that start with numeric characters are illegal in Qmod (and in all programming languages I know).
| allocate(x); | ||
| hadamard_transform(x); | ||
| power (r) { | ||
| grover_operator(lambda(vars) { |
There was a problem hiding this comment.
I would define 3sat_oracle directly as a phase oracle using controlled phase(pi), then provide it grover_operator
There was a problem hiding this comment.
I would love to, here and in the notebook too! But at the moment it yields 2X in depth (because uncomp-recomp). This degradation will be removed with the migration to the new arithmetic, hopefully soon. Do you (and your boss) approve this temporary degradation?
| @@ -0,0 +1,33 @@ | |||
| // Solving 3-SAT Problem using Grover's Algorithm | |||
There was a problem hiding this comment.
rename to 3_sat_grover (without the large)
| qfunc main(params: real[6], output v: KnapsackVars) { | ||
| allocate(v); | ||
| hadamard_transform(v); | ||
| repeat (i: 3) { |
There was a problem hiding this comment.
change to num_layers
There was a problem hiding this comment.
See reply to the next comment..
| } | ||
| } | ||
|
|
||
| qfunc main(params: real[6], output v: KnapsackVars) { |
There was a problem hiding this comment.
change 6 to 2*num_layers
There was a problem hiding this comment.
I would love to, but alas -
https://classiq.atlassian.net/browse/CLS-5663
| // This function outputs the segment label of a given x value | ||
| qperm map_label(num_segs: int, const v: qbit[], output label: qbit[]) { | ||
| allocate(num_segs, label); | ||
| repeat (i: num_segs) { // duplicate MSBs of v |
There was a problem hiding this comment.
map_label can use |= between QArrays instead of the repeat
| @@ -15,7 +18,7 @@ qfunc compute_piecewise_linear(As: real[], Bs: real[], x: qnum, y: qnum) { | |||
|
|
|||
| repeat (i: As.len) { | |||
| control (label==i) { | |||
There was a problem hiding this comment.
instead of copying the label, now you can control operation with constant x based on x value, so you can save the auxilliary qubits
f81878a to
41f03a9
Compare
41f03a9 to
18c60f6
Compare
|
💪 Great job, @matanvax2! You've merged your 8th PR! 🎊 Your contributions to classiq-library are making a real difference. Keep up the fantastic work! 💪 |
PR Description
Beautify qmods - my part