Path: blob/main/notebooks/quantum-hardware/measuring-quantum-volume.ipynb
3855 views
Measuring Quantum Volume

Why quantum volume?
Comparing different quantum computers is not an easy task. There are many different factors that affect the performance of a quantum computer and it’s not always clear which factors will have the biggest effect when doing useful quantum computations.
Say you were designing your quantum computer: Would you trade higher fidelity gates (with less errors) for reduced qubit connectivity (requiring longer circuits)? Maybe you have a great transpiler that can organise the swaps so reduced connectivity isn’t as much of an issue. Or maybe the readout errors are so high that any improvement in gate fidelity is negligible anyway? We can add each of these statistics to our quantum computer scorecard, but the exact importance of each element is up for debate. Even if we manage to score highly at each individual metric, there could still be other unforeseen problems that arise when running quantum circuits.
One thing is certain, to achieve a quantum advantage, we need many qubits, and the ability to manipulate them precisely . If we don't have enough qubits, we can't do any useful computations, and if these qubits are not precise or reliable enough, then our measurements will be meaningless.
What affects computing power?
Qubit count
Number of qubits (more is better)
The number of qubits in our quantum computer sets an upper limit on the power of the computations it can do. To gain advantage over classical computers, we want to be able to entangle as many qubits as possible.

Readout errors
Gate and readout errors (less is better)
As mentioned above, the errors in our quantum computer also set an upper limit on the power of our quantum computer. If we can’t reliably manipulate our quantum states, then we’re not going to get meaningful results from our quantum computer.

Connectivity
Qubit-Qubit connectivity (more is better)
If two qubits cannot communicate directly, we need to add extra ‘swap’ gates to move them to the right place, increasing the length of our computation. Quantum volume circuits assume full connectivity, so if you need to insert extra swap gates, that’s on you!

Gate set
Gate set (larger / more powerful is better)
Quantum volume asks for random two-qubit gates, but working out how to implement them is also on you. If your hardware supports more gates, you’re more likely to get decent results.

Software stack
Compilers and software stack (more intelligent is better)
Some other problems (inserting extra swap gates, creating the specified gates from your available gate set, and dealing with noise) can be mitigated using intelligent classical software such as the transpiler.

This is where quantum volume comes in. Quantum volume is a holistic benchmark. Instead of looking at the details, we simply measure how good the quantum computer is at doing the thing we want it to do: running quantum circuits. The quantum volume test creates randomized circuits to a specification, and the ‘score’ of the quantum computer increases with the size of the circuit it can reliably run.
In this chapter, we will learn:
What quantum volume is.
How to create a random square circuit.
How to see if a device can achieve a certain quantum volume.
How to use Qiskit’s tools to make this easier for us.
Visual demo
The Quantum Volume Protocol
Overview
To perform the quantum volume benchmark, we first create a bunch of circuits of size . We then simulate the circuits and record the most likely outputs for each. We run these same circuits on the device we’re testing and see how regularly the outputs match those we simulated. If the device produces good enough results, we increase d and start over. The quantum volume of the device is 2 to the power of the largest circuit size our device can produce acceptable results for.
1.

Create a set of random circuits of width and depth .
2.

Simulate the circuits and record which outputs are most likely.
3.

Run the circuits on the device we’re testing and record the results.
4.

If the device results are statically close enough to the simulation results, increase and go to step one. Repeat until failure.
5.

The quantum volume is , where is the width and depth of the largest circuit our device can successfully run.
Square circuits
A square circuit is a circuit of equal width and depth. This roughly approximates the kind of circuits we will want to run on a general-purpose quantum computer, and since the depth and width are equal, they can be defined by a single number.
We know we can build our quantum algorithms with quantum circuits using a polynomial number of two-qubit unitary gates. The model we choose has layers of random permutations of the qubit labels, followed by randomly specified two-qubits gates. When we have an odd number of qubits, one of the qubits is idle in each layer.
These random circuits more closely approximate the circuits found in near term quantum algorithms than the circuits found in some more traditional algorithms.
Square circuit demo
Layers and Unitaries
Click on any of the layers to see examples of gates inside of each layer. Each layer affects each qubit exactly once, and all the unitary gates in a layer can be run in parallel (assuming the device has full qubit connectivity).
Creating a square circuit
To start, let’s have a go at creating our own random, square circuit. The first thing we need to do is decide which qubits our circuit is going to act on. When measuring quantum volume, we can choose whichever qubits on our device we think will give us the best results. Here I’m choosing the first five qubits of an imaginary device. This means our circuit’s depth and width will both be five.
Next, we need a way to create our random 2-qubit gates. Qiskit provides a tool, random_unitary that creates a random unitary operator for us. This function could generate any unitary, two-qubit operation possible.
We can use this to create a single layer of our random, square circuit:
Now we can create a layer from a list of qubits, all we need to do is randomly change the order of the qubits and repeat. Python has a built-in function to shuffle lists (note that this works ‘in place’, so the data qubit_lists refers to will change).
Exercise
Create a function, random_square_circuit(n) that takes an integer n, and returns a random QuantumCircuit with width and depth n, that could be used in a quantum volume experiment. You may use the code shown above in your solution.
Qiskit also provides a circuit class, QuantumVolume (imported here as QuantumVolumeCircuit), that creates these circuits for us. We just need to specify the number of qubits we want to use. In the cell below, we create a quantum volume circuit with four qubits, which tests for a quantum volume of 16.
Running the circuit
So how do we know if the quantum circuit is being run correctly? The quantum volume protocol is run on a perfect simulator as well as the quantum device we’re testing. We can then compare the simulated results (what the quantum computer should do) to the experimental results (what the quantum computer actually does).

What would an ideal quantum computer do?
Each circuit has an ideal output distribution. This distribution is what we’d see if we ran the circuit on a perfect quantum computer, as the number of shots approaches infinity. We can calculate this ideal distribution for small circuits using Qiskit's Statevector class. Let’s try this on the four-qubit circuit we created above:
The heavy outputs of a circuit are the outputs with probability of occurring greater than the median probability. For any circuit, half the possible outputs are heavy outputs.
Below is a function, get_heavy_outputs, that extracts the heavy outputs from an experiment’s counts:
We run each circuit on our device and record the number of outputs that are heavy outputs. To pass the heavy output test, we want the probability of measuring a heavy output to be greater than two-thirds. I.e. over a large enough number of circuits we have:
ParseError: KaTeX parse error: Undefined control sequence: \class at position 7: \frac{\̲c̲l̲a̲s̲s̲{qv_nh}{n_h}}{\…Where is the number of heavy outputs measured, is the number of circuits we created, and is the number of times we run each circuit (shots). But how do we decide what a “large enough” number of experiments is? Firstly, quantum volume requires at least 100 circuits are run, otherwise the test is invalid. Secondly, an adjusted threshold is used to ensure approximately 97% confidence:
ParseError: KaTeX parse error: Undefined control sequence: \class at position 7: \frac{\̲c̲l̲a̲s̲s̲{qv_nh}{n_h} -\…Adding the new term (enclosed in the square root) requires a greater heavy output probability to satisfy the inequality, or a greater number of runs. Since the new term grows more slowly than the other terms, for lots of runs this inequality resembles the simpler one shown above. If a quantum volume test satisfies the above inequality, there is at least a 97% chance the heavy output probability is greater than 2/3.
Below is a function (check_threshold) that evaluates this inequality:
Exercise
We now have everything we need to check if a quantum device can achieve a specific quantum volume. Below are the steps of an algorithm that checks if a device can achieve a specific quantum volume, try to order them correctly.
Algorithm to test if algorithm passes a quantum volume test. Inputs: d, nc > 100, ns
Here is the algorithm as Qiskit code:
And an example of using this to see if a simulated Santiago device can achieve quantum volume 16:
Exercise
What is the maximum quantum volume you can achieve using a simulated Athens device? What affect does changing the list of qubits have? What affect does changing the optimization level have? Can you do anything to improve the score?
Using Qiskit’s quantum volume tools
The qiskit-experiments package also includes tools to measure quantum volume. First, we'll set up a fake device (Boeblingen) to demonstrate this on.
Next, we create a QuantumVolume experiment using this device and a subset of its qubits.
Finally, we run this experiment and view the results. The method .analysis_results() returns a list of different result objects, so we'll iterate through them and print each one.
We can see the device achieved a quantum volume of 8. The result also generates a figure we can access using the code below:
Try increasing the number of qubits in the experiment above; how does Boeblingen perform?
It’s easy to imagine that, with a smart selection of qubits and lots of circuits, we could also achieve a quantum volume of 16 on the mock Boeblingen device as IBM has achieved on the real Boeblingen device. To provide another example, below is an image taken from IBM’s demonstration of QV64 on the Montreal device [2].

You can read more about how this was achieved in the paper here.
References
[1] Andrew W. Cross, Lev S. Bishop, Sarah Sheldon, Paul D. Nation, and Jay M. Gambetta, Validating quantum computers using randomized model circuits, Phys. Rev. A 100, 032328 (2019). https://arxiv.org/pdf/1811.12926
[2] Petar Jurcevic et. al. Demonstration of quantum volume 64 on a superconducting quantum computing system https://arxiv.org/pdf/2008.08571.pdf