Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5k stars 2.32k forks source link

FakeRueschlikon has wrong backend properties #5456

Closed VicentePerezSoloviev closed 1 year ago

VicentePerezSoloviev commented 3 years ago

Information

What is the current behavior?

When using FakeRueschlikon fake simulator, exploring the simulator properties cannot find any type of noise. I have looked for the decoherence time, the cx, u1, u2, u3 error and nothing was found. I have done the same for other fake simulators, and I have found the errors.

Steps to reproduce the problem

I have designed a function to print the information. The following:

import numpy as np
import pandas as pd
from qiskit.visualization import plot_circuit_layout
from qiskit import QuantumCircuit, transpile
from qiskit.test.mock import FakeMelbourne, FakeRueschlikon, FakeTokyo, FakePoughkeepsie, FakeAlmaden, FakeSingapore, FakeBoeblingen, FakeJohannesburg

def describe_backend(backend):
    conf = backend.configuration()
    prop = backend.properties()

    print('Name:', conf.backend_name, 
          '\nGates:', conf.basis_gates, 
          '\nN. qubits:', conf.n_qubits)

    zeros_array = np.zeros((conf.n_qubits, conf.n_qubits))

    for i in range(conf.n_qubits):
        for j in range(conf.n_qubits):
            try:
                zeros_array[i,j] = round(prop.gate_error('cx', [i, j]), 3)
            except:
                pass

    print('\ncx noise')
    qubits = ['q' + str(i) for i in range(conf.n_qubits)]
    df = pd.DataFrame(data=zeros_array, index=qubits, columns=qubits)
    df.update(df.select_dtypes(include=np.number).applymap('{:,g}'.format))
    display(df)

    for j in range(2,4):
        try:
            dt = pd.DataFrame(columns=qubits)
            dt.loc[0] = [round(prop.gate_error('u'+str(j), i), 3) for i in range(conf.n_qubits)]
            print('\nNoise u'+str(j))
            display(dt)
        except:
            pass

    print('\nreadout error')
    dt = pd.DataFrame(columns=qubits)
    dt.loc[0] = [prop.readout_error(i) for i in range(conf.n_qubits)]
    display(dt)

    print('\nDecoherence times')
    dt = pd.DataFrame(columns=qubits)
    dt.loc['T1'] = [prop.t1(i) for i in range(conf.n_qubits)]
    dt.loc['T2'] = [prop.t2(i) for i in range(conf.n_qubits)]
    display(dt)

    circ = QuantumCircuit(conf.n_qubits)
    circ.measure_all()
    new_circ_lv0 = transpile(circ, backend=backend, optimization_level=0)
    display(plot_circuit_layout(new_circ_lv0, backend))

What is the expected behavior?

The function prints the information abount the simulator. If this type of simulator has no noise, what is the difference between this simulator and the state_vector one from Aer. The unique difference with the state_simulator, is the coupling_map. The state_vector one does not have coupling map.

Suggested solutions

The problem might be that the backend properties are not the real ones. The backend properties of other simulators are different.

jwoehr commented 2 years ago

Made a diff and created a bogus props_rueschlikon.json and it seems to work. I don't have access to ibmq_rueschlikon to make a better props file.

diff --git a/qiskit/test/mock/backends/rueschlikon/fake_rueschlikon.py b/qiskit/test/mock/backends/rueschlikon/fake_rueschlikon.py
index 306de8311..5ac0da332 100644
--- a/qiskit/test/mock/backends/rueschlikon/fake_rueschlikon.py
+++ b/qiskit/test/mock/backends/rueschlikon/fake_rueschlikon.py
@@ -13,8 +13,10 @@
 """
 Fake Reuschlikon device (16 qubit).
 """
+import os
+import json

-from qiskit.providers.models import GateConfig, QasmBackendConfiguration
+from qiskit.providers.models import GateConfig, QasmBackendConfiguration, BackendProperties
 from qiskit.test.mock.fake_backend import FakeBackend, FakeLegacyBackend

@@ -70,6 +72,14 @@ class FakeRueschlikon(FakeBackend):

         super().__init__(configuration)

+    def properties(self):
+        """Returns a snapshot of device properties"""
+        dirname = os.path.dirname(__file__)
+        filename = "props_rueschlikon.json"
+        with open(os.path.join(dirname, filename)) as f_prop:
+            props = json.load(f_prop)
+        return BackendProperties.from_dict(props)
+

 class FakeLegacyRueschlikon(FakeLegacyBackend):
     """A fake 16 qubit backend."""
@@ -122,3 +132,11 @@ class FakeLegacyRueschlikon(FakeLegacyBackend):
         )

         super().__init__(configuration)
+
+    def properties(self):
+        """Returns a snapshot of device properties"""
+        dirname = os.path.dirname(__file__)
+        filename = "props_melbourne.json"
+        with open(os.path.join(dirname, filename)) as f_prop:
+            props = json.load(f_prop)
+        return BackendProperties.from_dict(props)
1ucian0 commented 2 years ago

If this type of simulator has no noise, what is the difference between this simulator and the state_vector one from Aer.

Fakebackends and simulators are not the same thing. Simulators can take a noise model from a backend, if there is one. Fakebackends do not perform simulations per se.

@VicentePerezSoloviev , would it help if you get a warning when a fake backend dont have a props_*.json? Something like "Warning: FakeRueschlikon does not provide noise information"

VicentePerezSoloviev commented 2 years ago

HIi @1ucian0 and @jwoehr. When I realised this, was when I was executing a quantum-inspired approach in different Fakebackends. Others, were able to emulate noise and different behaviour were obtained when changing the Fakebackend. However, when I executed the approach with FakeRueschlikon, the behaviour was the same as for the state-vector simulator. When I entered in the code, I realised that the noise was equal to 0. Then, the doubt is if Rueschlikon really have no noise, which would be a very strange case. Anycase, if the noise is not updated, it could be a good idea to raise a Warning such as you propose so other people do not expend time with this issues. I can implement it if needed

1ucian0 commented 2 years ago

I wont say no to somebody offering code :) that's my weakness :P

PRs are welcomed! Thanks Vicente!

VicentePerezSoloviev commented 2 years ago

It is done now. The intantiation of the class will raise a Warning remembering the user that this backend has no noise properties, as proposed by @1ucian0

VicentePerezSoloviev commented 2 years ago

It fails in the pull request for the Coverage report. What could be happening?

jakelishman commented 2 years ago

Sorry, I didn't see this before: I don't think it's an appropriate solution to raise a warning when a user simply instantiates a fake backend. If we're not actually supplying the full information for Rueschlikon, then the solution is more like "don't call it Rueschlikon" than to warn - there's nothing the user did wrong, so there shouldn't be a warning. If we can't supply enough information to make it a proper fake backend, I don't think we should have it.

jakelishman commented 1 year ago

Given our current position that fake backends are just for testing the provider interfaces, and that Rüschlikon was retired in 2018, I'm going to close this as stale now.