# Quantum Volume¶

Quantum Volume (QV) is a single-number metric that can be measured using a concrete protocol on near-term quantum computers of modest size. The QV method quantifies the largest random circuit of equal width and depth that the computer successfully implements. Quantum computing systems with high-fidelity operations, high connectivity, large calibrated gate sets, and circuit rewriting toolchains are expected to have higher quantum volumes. See Qiskit Textbook for an explanation on the QV method, which is described in Ref. [1, 2].

The Quantum Volume is determined by the largest successful circuit depth
\(d_{max}\), and equals to \(2^{d_{max}}\). In the QV experiment
we generate QV
circuits
on \(d\) qubits, which contain \(d\) layers, where each layer
consists of random 2-qubit unitary gates from \(SU(4)\), followed by
a random permutation on the \(d\) qubit. Then these circuits run on
the quantum backend and on an ideal simulator (either `AerSimulator`

or `qiskit.quantum_info.Statevector`

).

A depth \(d\) QV circuit is successful if it has ‘mean heavy-output probability’ > 2/3 with confidence level > 0.977 (corresponding to z_value = 2), and at least 100 trials have been ran.

```
from qiskit_experiments.framework import BatchExperiment
from qiskit_experiments.library import QuantumVolume
from qiskit import Aer
from qiskit.providers.aer import AerSimulator
# For simulation
from qiskit.providers.fake_provider import FakeSydney
backend = AerSimulator.from_backend(FakeSydney())
```

## QV experiment¶

To run the QV experiment we need need to provide the following QV parameters, in order to generate the QV circuits and run them on a backend and on an ideal simulator:

`qubits`

: The number of qubits or list of physical qubits for the experiment.`trials`

: The number of trials to run the quantum volume circuit (the default is 100).`seed`

: Seed or generator object for random number generation. If`None`

then`default_rng`

will be used.`simulation_backend`

: The simulator backend to use to generate the expected results. the simulator must have a`save_probabilities`

method. If None`AerSimulator`

simulator will be used (in case`AerSimulator`

is not installed`qiskit.quantum_info.Statevector`

will be used).

**Note:** In some cases, 100 trials are not enough to obtain a QV
greater than 1 for the specified number of qubits. In this case, adding
more trials may reduce the error bars to allow passing the threshold.

The analysis results of the QV Experiment are:

The mean heavy output probabilities (HOP) and standard deviation

The calculated quantum volume, which will be None if the experiment does not pass the threshold

Extra data included in the analysis results includes

The heavy HOPs for each trial

Confidence level (should be greater than 0.977)

The number of trials and depth of the QV circuits

Whether the QV circuit was successful

```
qubits = tuple(range(4)) # Can use specific qubits. for example [2, 4, 7, 10]
qv_exp = QuantumVolume(qubits, seed=42)
# Transpile options like optimization_level affect only the real device run and not the simulation run
# Run options affect both simulation and real device runs
qv_exp.set_transpile_options(optimization_level=3)
# Run experiment
expdata = qv_exp.run(backend).block_for_results()
```

```
# View result data
display(expdata.figure(0))
for result in expdata.analysis_results():
print(result)
```

```
AnalysisResult
- name: mean_HOP
- value: 0.75+/-0.04
- quality: bad
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3']
- verified: False
AnalysisResult
- name: quantum_volume
- value: 1
- quality: bad
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3']
- verified: False
```

```
# Print extra data
for result in expdata.analysis_results():
print(f"\n{result.name} extra:")
for key, val in result.extra.items():
print(f"- {key}: {val}")
```

```
mean_HOP extra:
- HOPs: [0.830078125, 0.7958984375, 0.7548828125, 0.7021484375, 0.8642578125, 0.6240234375, 0.73828125, 0.84765625, 0.794921875, 0.767578125, 0.7021484375, 0.8369140625, 0.689453125, 0.6943359375, 0.71875, 0.802734375, 0.8212890625, 0.7138671875, 0.6572265625, 0.6328125, 0.7177734375, 0.7138671875, 0.6455078125, 0.708984375, 0.755859375, 0.763671875, 0.888671875, 0.734375, 0.71484375, 0.75, 0.662109375, 0.779296875, 0.861328125, 0.77734375, 0.6748046875, 0.6796875, 0.7978515625, 0.7646484375, 0.6728515625, 0.73046875, 0.8642578125, 0.7138671875, 0.7431640625, 0.697265625, 0.8271484375, 0.6279296875, 0.7890625, 0.708984375, 0.755859375, 0.9228515625, 0.681640625, 0.7236328125, 0.6650390625, 0.7001953125, 0.693359375, 0.7763671875, 0.7041015625, 0.8271484375, 0.673828125, 0.80859375, 0.765625, 0.7763671875, 0.78125, 0.8447265625, 0.724609375, 0.7314453125, 0.7978515625, 0.74609375, 0.7587890625, 0.7587890625, 0.7587890625, 0.7783203125, 0.8017578125, 0.705078125, 0.6611328125, 0.7578125, 0.708984375, 0.62890625, 0.7568359375, 0.77734375, 0.7294921875, 0.7431640625, 0.783203125, 0.6435546875, 0.6953125, 0.763671875, 0.701171875, 0.6767578125, 0.7294921875, 0.697265625, 0.7919921875, 0.7099609375, 0.693359375, 0.810546875, 0.7705078125, 0.8232421875, 0.7724609375, 0.6982421875, 0.75390625, 0.814453125]
- two_sigma: 0.08716126178544155
- depth: 4
- trials: 100
quantum_volume extra:
- success: False
- confidence: 0.9640440466296999
- depth: 4
- trials: 100
```

## Adding trials¶

Adding more trials may reduce the error bars to allow passing the threshold (beside the error bars - QV experiment must have at least 100 trials to be considered successful). In case you want to add less than 100 additional trials, you can modify the amount of trials added before re-running the experiment.

```
qv_exp.set_experiment_options(trials=60)
expdata2 = qv_exp.run(backend, analysis=None).block_for_results()
expdata2.add_data(expdata.data())
qv_exp.analysis.run(expdata2).block_for_results()
# View result data
display(expdata2.figure(0))
for result in expdata2.analysis_results():
print(result)
```

```
AnalysisResult
- name: mean_HOP
- value: 0.746+/-0.034
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3']
- verified: False
AnalysisResult
- name: quantum_volume
- value: 16
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3']
- verified: False
```

## Calculating Quantum Volume using a batch experiment¶

Run the QV experiment with an increasing number of qubits to check what is the maximum Quantum Volume for the specific device. To reach the real system’s Quantum Volume, one must run more trials and additional enhancements might be required (See Ref. [2] for details).

```
exps = [QuantumVolume(tuple(range(i)), trials=200) for i in range(3, 6)]
batch_exp = BatchExperiment(exps)
batch_exp.set_transpile_options(optimization_level=3)
# Run
batch_expdata = batch_exp.run(backend).block_for_results()
```

Extracting the maximum Quantum Volume.

```
qv_values = [
batch_expdata.child_data(i).analysis_results("quantum_volume").value
for i in range(batch_exp.num_experiments)
]
print(f"Max quantum volume is: {max(qv_values)}")
```

```
Max quantum volume is: 32
```

```
for i in range(batch_exp.num_experiments):
print(f"\nComponent experiment {i}")
sub_data = batch_expdata.child_data(i)
display(sub_data.figure(0))
for result in sub_data.analysis_results():
print(result)
```

```
Component experiment 0
```

```
AnalysisResult
- name: mean_HOP
- value: 0.788+/-0.029
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2']
- verified: False
AnalysisResult
- name: quantum_volume
- value: 8
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2']
- verified: False
Component experiment 1
```

```
AnalysisResult
- name: mean_HOP
- value: 0.744+/-0.031
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3']
- verified: False
AnalysisResult
- name: quantum_volume
- value: 16
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3']
- verified: False
Component experiment 2
```

```
AnalysisResult
- name: mean_HOP
- value: 0.732+/-0.031
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3', 'Q4']
- verified: False
AnalysisResult
- name: quantum_volume
- value: 32
- quality: good
- extra: <4 items>
- device_components: ['Q0', 'Q1', 'Q2', 'Q3', 'Q4']
- verified: False
```

## 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

```
import qiskit.tools.jupyter
%qiskit_copyright
```

### This code is a part of Qiskit

© Copyright IBM 2017, 2022.

This code is licensed under the Apache License, Version 2.0. You may

obtain a copy of this license in the LICENSE.txt file in the root directory

of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this

copyright notice, and modified files need to carry a notice indicating

that they have been altered from the originals.