4 ms·
Wow—I didn’t even recognize my own code there with all the whitespace changed and semicolons inserted ;) And yes—not having any dependencies or anything to ins
by stewdio 6y ago
Wow—I didn’t even recognize my own code there with all the whitespace changed and semicolons inserted ;)
And yes—not having any dependencies or anything to install was one of my goals to help anyone get up and running with minimal fuss. I have more to say about that here:
https://quantumjavascript.app/contributing.html#JavaScript_style https://quantumjavascript.app/contributing.html#JavaScript_s...
You’re asking a really good question—I should probably write page on this to make it more clear; it definitely was NOT clear to me at first either! The short answer is “no.” What you’re seeing there is the Q.Circuit.prototype.try$ function which forces a circuit to choose one of its probable outcomes. I mostly added this in so users could write a simple coin-flip demo and get an actual heads or tails result—you know; feel good about making their first superposition and then collapsing it to a conclusion:
Q`H`.try$() ? 'tails' : 'heads'
But it’s the management and redistribution of probabilities during the course of a circuit’s operation that is the real quantum magic—not choosing a series of random outcomes. In fact if you search the entire repo for “Math.random” you’ll see that this try$ function is the only “semi-meaningful” use of randomness. (The other calls to Math.random are either part of some included THREE.js bits for the Bloch Sphere visualizer, or for randomly tilting the click-and-draggable gate tiles in circuit palettes, or for choosing random color + animal names. Yes... Random color + animal names!)
Q.getRandomName$()
The way we manage probabilities in a simulator is by representing qubits as a pair of numbers. This should give you a better idea of how that works—and what “superposition” means in this context:
https://quantumjavascript.app/Q-Qubit.html https://quantumjavascript.app/Q-Qubit.html
But the weirdest part for me to wrap my head around was that there is no answer until you’ve computed the ENTIRE answer. In a regular computer you can ask what the value of a particular bit is at anytime and that doesn’t effect any other piece of the circuit. But with quantum simulation like this you are mixing all of the ingredients together and it is impossible to pull one out, point to it and say “this particular qubit has this particular value!” Instead you can only know the total state of the system.
You’ve given me a lot to think about in terms of adding more content to Q :)
I need another coffee now...