This is Part 1 of a 3-part series on quantum software. Part 1 covers how quantum computers calculate, Part 2 covers testing and debugging, and Part 3 covers which problems quantum software suits.
Let’s say you write a simple computer program in Python that adds two numbers. You run the same two numbers 1,000 times. You get the same answer 1,000 times. Now you write a small quantum program and run it 1,000 times. The answers vary. The program is working correctly. Varying answers are how quantum computers report results. The program sets the odds for each possible answer, and a well-built program gives the correct answer the highest odds. You run it many times and keep the answer that shows up most often. The rest of this post shows how that works.
A regular computer stores information as bits. Each bit is a 0 or a 1, and the computer follows your instructions one step at a time. The same input gives the same output every time. A quantum computer stores information in qubits. A qubit can hold both possibilities, 0 and 1, until you measure it. The measurement forces one answer. Because of this, a quantum program sets the odds for each possible answer. The program is a list of operations called a circuit. Chapter 4 of my book, Quantum from the Ground Up, covers qubits in more depth.
Each run gives you one answer, so you run the circuit many times. Each run is called a shot. The pattern across all the shots is your result. If a circuit should give answer A 70 percent of the time, you need enough shots to see that 70 percent. One tutorial uses 8,192 shots to estimate a single value. On real machines, shots cost time and money, so you plan how many to use.
Here is how the calculation itself differs. A regular computer holds one pattern of bits at a time. Three bits hold one pattern, such as 101, and each operation turns it into one new pattern. Testing all 8 possible patterns takes 8 runs. Three qubits are described by 8 numbers called amplitudes, one for each pattern from 000 to 111.
Each amplitude can be positive or negative (or more generally, a complex number with a phase), and one operation updates all 8 together. The count doubles with each added qubit. Ten qubits need 1,024 amplitudes. Fifty qubits need about 1.1 quadrillion, which takes roughly 9 petabytes to store on a classical computer.
When you measure, the chance of reading each pattern equals its amplitude squared, and you read one pattern per shot. Amplitudes that lead to the same pattern add together, and a positive amplitude cancels a negative one. This is called interference. A quantum algorithm arranges its operations so the amplitudes for wrong answers cancel and the amplitudes for right answers add up. The right answer then shows up in most shots.
Varying answers still lead to one correct answer, because the odds are designed. Take Grover's search over 8 items, where one item is correct. Before the algorithm runs, each item has a 12.5 percent chance. After one round of its steps, the correct item has a 78 percent chance and each wrong item about 3 percent. In a 100-shot simulator run, the correct item appeared 76 times and the most common wrong item appeared 7 times, so the winner was clear. A second round raises the correct item to 94.5 percent. A third round drops it to 33 percent, so the algorithm needs the right number of rounds, which is 2 for 8 items. Noise lowers the correct item's share and raises the others. The correct answer still wins while it remains the most frequent result, and more shots widen the margin. Quadrupling the shots roughly halves the statistical error. For simulations of molecules and materials, the answer is the average across thousands of shots, and the spread becomes the error bar.
Let's go back to that Python program. Run it 1,000 times and you get one answer 1,000 times. Run the quantum program 1,000 times and you get a spread, and the program was built so the correct answer leads it. You read the pattern across shots, and the pattern is the result.
This is Part 1 of 3. Part 2 covers testing and debugging quantum software. Part 3 covers which problems quantum computers help with.
My free book updated quarterly, Quantum from the Ground Up, is in this shared folder.

.png)
.jpg)




