q.js icon indicating copy to clipboard operation
q.js copied to clipboard

Added possibility to set start values via GUI

Open manzanillo opened this issue 4 years ago • 2 comments

Hi, this PR allows to set start values by clicking the 0 or 1 at the beginning of a lane. This feature was intended in the source code, but hasn't been completed yet. I tried to be minimally invasive and added an additional attribute to circuit elements. Love to hear your feedback. Let me know, if we need to apply any changes.

Best, Stefan

manzanillo avatar Dec 07 '20 18:12 manzanillo

Thank you so much for taking this initiative!

I notice that in Circuit you’re adding a new Array called startValues to store 0s and 1s. But this is redundant because there’s already an array called qubits that’s storing each qubit starting valule. (And that’s what we should be using to evaluate the circuit in the evaluate$ routine.) Check it out: this.qubits = new Array( bandwidth ).fill( Q.Qubit.HORIZONTAL )

What I think we should do is stick to the qubits variable and instead of the user interactions flipping a 0 to 1 (or more accurately as you have it: ++i % 2) it ought to flip a Horizontal qubit to a Vertical qubit by applying a Pauli X gate. (And at some point further down the road this could really manipulated to hold any qubit value 😉

Do you think you can give that a try instead? (And thank you again for looking into this!)

stewdio avatar Dec 07 '20 22:12 stewdio

Hi Stewart, great suggestion. I updated the PR.

While preparing the commit, I was wondering, why Q.Circuit.applyGate is not working in place. If we consider qubits as being singular, it would probably be more natural to have it in place. Nevertheless, this is not important for this PR.

If you have any other suggestions, e.g. regarding naming of variables, let me know.

Best, Stefan

manzanillo avatar Dec 08 '20 08:12 manzanillo