qiskit-community / qiskit-experiments

Qiskit Experiments
https://qiskit-community.github.io/qiskit-experiments/
Apache License 2.0
160 stars 126 forks source link

Randomized benchmarking fails to analyze the results from IBM Eagle, due to the lack of 2Q gate decomposition value for ECR gate #1419

Closed jungmin-cho-eng closed 6 months ago

jungmin-cho-eng commented 8 months ago

Informations

What is the current behavior?

When I run Randomized benchmarking on IBM Eagle machine by following Randomized benchmarking reference, qiskit-experiment fails to analyze the results. Specifically, Python interpreter prints TypeError: unsupported operand type(s) for *: 'NoneType' and 'float' from qiskit_experiments/library/randomized_benchmarking/rb_analysis.py", line 370, in _calculate_epg

Steps to reproduce the problem

Run a two-qubit RB experiment on any IBM Eagle backend. Following code is from Randomized benchmarking reference

import numpy as np
from qiskit_experiments.library import StandardRB, InterleavedRB
from qiskit_experiments.framework import ParallelExperiment, BatchExperiment
import qiskit.circuit.library as circuits

service = QiskitRuntimeService(channel='ibm_quantum', token=*** Your token ***)
backend = service.backend('ibm_kyoto')  # Instead of ibm_kyoto, you can use ibm_brisbane, ibm_osaka, ibm_nazca, or ibm_cusco

lengths_2_qubit = np.arange(1, 200, 30)
lengths_1_qubit = np.arange(1, 800, 200)
num_samples = 10
seed = 1010
qubits = (1, 2)

# Run a 1-qubit RB experiment on qubits 1, 2 to determine the error-per-gate of 1-qubit gates
single_exps = BatchExperiment(
    [
        StandardRB((qubit,), lengths_1_qubit, num_samples=num_samples, seed=seed)
        for qubit in qubits
    ],
    flatten_results=True,
)
expdata_1q = single_exps.run(backend).block_for_results()

# Run an RB experiment on qubits 1, 2
exp_2q = StandardRB(qubits, lengths_2_qubit, num_samples=num_samples, seed=seed)

# Use the EPG data of the 1-qubit runs to ensure correct 2-qubit EPG computation
exp_2q.analysis.set_options(epg_1_qubit=expdata_1q.analysis_results())

# Run the 2-qubit experiment
expdata_2q = exp_2q.run(backend).block_for_results()

# View result data
print("Gate error ratio: %s" % expdata_2q.experiment.analysis.options.gate_error_ratio)
display(expdata_2q.figure(0))
for result in expdata_2q.analysis_results():
    print(result)

What is the expected behavior?

Randomized benchmarking should analyze the results from IBM backend and print the result without any error.

Suggested solutions

The cause of the error is that rb_analysis.py lacks the Clifford decomposition ratio for ECR gate. IBM Eagle machines use ECR gate as a basis two-qubit gate. Therefore, when rb_analysis.py calculates EPC from EPG_ecr, it tries to find the Clifford decomposition ratio for ECR gate from a dictionary standard_2q_ratio. However, there is no such key in the dictionary, so it gets None as a return. Then, it multiplies the retuned None with a float, so a TypeError occurs.

From line 317 to 335 in qiskit_experiments/library/randomized_benchmarking/rb_analysis.py", line 370, in _calculate_epg, I added a key and a value "ecr": 1.0, at the end of the dictionary standard_2q_ratio. ECR gate is also a Clifford gate (Reference), so the value 1.0 makes sense.

    # Gate count in (CX, CSX)-based decomposition, 1q gate contribution is ignored.
    # Amplitude or duration modulated pulse implementation is not considered.
    standard_2q_ratio = {
        "swap": 3.0,
        "rxx": 2.0,
        "rzz": 2.0,
        "cx": 1.0,
        "cy": 1.0,
        "cz": 1.0,
        "ch": 1.0,
        "crx": 2.0,
        "cry": 2.0,
        "crz": 2.0,
        "csx": 1.0,
        "cu1": 2.0,
        "cp": 2.0,
        "cu": 2.0,
        "cu3": 2.0,
        "ecr": 1.0,  # -> I added this line
    }

With the modified rb_analysis.py as the upper code block, I verified that Randomized benchmarking works without an error for ibm_kyoto.