Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
161 stars 157 forks source link

How to run Fake Providers locally with QiskitRuntime #1753

Closed ACE07-Sev closed 5 months ago

ACE07-Sev commented 5 months ago

Greetings,

Hope you are well. I am trying to get fake providers running for my wrapper, but have been having issues with defining the QiskitRuntime instance which is needed for the latest caliberations.

I have prepared a minimal example.

from qiskit import QuantumCircuit
from qiskit import transpile
from qiskit.visualization import plot_histogram
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_aer import AerSimulator

# get a real backend from the runtime service
service = QiskitRuntimeService()
backend = service.get_backend('ibmq_manila')

# generate a simulator that mimics the real quantum system with the latest calibration results
backend_sim = AerSimulator.from_backend(backend)

# Create a simple circuit
circuit = QuantumCircuit(3)
circuit.h(0)
circuit.cx(0,1)
circuit.cx(0,2)
circuit.measure_all()
circuit.draw('mpl', style="iqp")

# Transpile the ideal circuit to a circuit that can be directly executed by the backend
transpiled_circuit = transpile(circuit, backend_sim)
transpiled_circuit.draw('mpl', style="iqp")

# Run the transpiled circuit using the simulated fake backend
job = backend_sim.run(transpiled_circuit)
counts = job.result().get_counts()
plot_histogram(counts)

And here is the error I am getting.

---------------------------------------------------------------------------
AccountNotFoundError                      Traceback (most recent call last)
Cell In[1], [line 9](vscode-notebook-cell:?execution_count=1&line=9)
      [5](vscode-notebook-cell:?execution_count=1&line=5) from qiskit_aer import AerSimulator
      [8](vscode-notebook-cell:?execution_count=1&line=8) # get a real backend from the runtime service
----> [9](vscode-notebook-cell:?execution_count=1&line=9) service = QiskitRuntimeService()
     [10](vscode-notebook-cell:?execution_count=1&line=10) backend = service.get_backend('ibmq_manila')
     [12](vscode-notebook-cell:?execution_count=1&line=12) # generate a simulator that mimics the real quantum system with the latest calibration results

File /mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:125, in QiskitRuntimeService.__init__(self, channel, token, url, filename, name, instance, proxies, verify, channel_strategy)
     [82](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:82) """QiskitRuntimeService constructor
     [83](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:83) 
     [84](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:84) An account is selected in the following order:
   (...)
    [121](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:121)     IBMInputValueError: If an input is invalid.
    [122](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:122) """
    [123](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:123) super().__init__()
--> [125](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:125) self._account = self._discover_account(
    [126](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:126)     token=token,
    [127](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:127)     url=url,
    [128](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:128)     instance=instance,
    [129](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:129)     channel=channel,
    [130](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:130)     filename=filename,
    [131](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:131)     name=name,
    [132](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py:132)     proxies=ProxyConfiguration(**proxies) if proxies else None,
...
    [192](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/accounts/management.py:192)     if account_name in all_config:
    [193](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/accounts/management.py:193)         return Account.from_saved_format(all_config[account_name])
--> [195](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/A.C.EA/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_ibm_runtime/accounts/management.py:195) raise AccountNotFoundError("Unable to find account.")

AccountNotFoundError: 'Unable to find account.'

I understand it's asking for an IBM Cloud account, but if I recall correctly the fake providers were supposed to be runnable locally without IBM Cloud account?

I am using Python 3.11.9, qiskit 1.1.0 (downloaded from the stable branch), qiskit_ibm_runtime 0.23.2, and qiskit_aer 0.14.2.

arujjval commented 5 months ago

@ACE07-Sev to use QiskitRuntime, you need to initialize your account. Please refer to this page https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/runtime_service#account-initialization

ACE07-Sev commented 5 months ago

I see, thank you very much! May I ask how I can access all of the fake providers? I apparently can only access Kyoto, Osaka, Sherbrooke, and Brisbane.

arujjval commented 5 months ago

@ACE07-Sev I am not getting this issue. Screenshot from 2024-06-09 18-16-49

I guess you should try again configuring your work environment. Refer to this video https://www.youtube.com/watch?v=dZWz4Gs_BuI&list=PLOFEBzvs-VvrgHZt3exM_NNiNKtZlHvZi&index=3&ab_channel=Qiskit

ACE07-Sev commented 5 months ago

No, I use QiskitRuntime to get the latest caliberations for the fake providers. You're apparently just importing the provider backends directly.

1ucian0 commented 5 months ago

The fake backend from IBM Qiskit Runtime are in https://github.com/Qiskit/qiskit-ibm-runtime

So... moving it there.

kt474 commented 5 months ago

Hi @ACE07-Sev, if you want to access latest calibration info of a backend, it will required an IBM Quantum/Cloud account. Otherwise, you can use the fake backends as mentioned in this comment