CQCL / pytket-qiskit

pytket-qiskit, extensions for pytket quantum SDK
Apache License 2.0
16 stars 13 forks source link

QiskitBackendNotFoundError: 'More than one backend matches the criteria' #352

Closed ACE07-Sev closed 4 months ago

ACE07-Sev commented 4 months ago

Greetings there,

Hope all are well. I am having some trouble with the AerBackend from pytket-qiskit extension. When I try to initialize the backend

from pytket.extensions.qiskit import AerBackend

backend = AerBackend()

I get the following error

QiskitBackendNotFoundError: 'More than one backend matches the criteria'

Version

qiskit = 1.1.0 qiskit_aer = 0.14.2 pytket = 1.27.0 pytket-qiskit = 0.53.0

cqc-alec commented 4 months ago

Hi, I am not able to reproduce this (I've tried with exactly those versions). Can you provide a full stack trace?

ACE07-Sev commented 4 months ago

Of course. Here.

--> [592](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/qickit/circuit/tketcircuit.py:592)     base_backend = AerBackend()
    [593](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/qickit/circuit/tketcircuit.py:593)     # Run the circuit
    [594](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/qickit/circuit/tketcircuit.py:594)     result = base_backend.run_circuit(circuit.circuit, n_shots=num_shots, seed=0)

File ~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:505, in AerBackend.__init__(self, noise_model, simulation_method, crosstalk_params, n_qubits)
    [497](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:497) def __init__(
    [498](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:498)     self,
    [499](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:499)     noise_model: Optional[NoiseModel] = None,
   (...)
    [502](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:502)     n_qubits: int = 40,
    [503](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:503) ):
    [504](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:504)     super().__init__()
--> [505](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:505)     self._qiskit_backend: "QiskitAerBackend" = Aer.get_backend(
    [506](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:506)         self._qiskit_backend_name
    [507](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:507)     )
    [508](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:508)     self._qiskit_backend.set_options(method=simulation_method)
    [509](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:509)     gate_set = _tket_gate_set_from_qiskit_backend(self._qiskit_backend).union(
    [510](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:510)         self._allowed_special_gates
    [511](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/pytket/extensions/qiskit/backends/aer.py:511)     )

File ~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_aer/aerprovider.py:67, in AerProvider.get_backend(self, name, **kwargs)
     [66](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_aer/aerprovider.py:66) def get_backend(self, name=None, **kwargs):
---> [67](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit_aer/aerprovider.py:67)     return super().get_backend(name=name, **kwargs)

File ~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/utils/deprecation.py:96, in deprecate_func.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
     [93](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/utils/deprecation.py:93) @functools.wraps(func)
     [94](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/utils/deprecation.py:94) def wrapper(*args, **kwargs):
     [95](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/utils/deprecation.py:95)     warnings.warn(msg, category=category, stacklevel=2)
---> [96](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/utils/deprecation.py:96)     return func(*args, **kwargs)

File ~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/providers/provider.py:69, in ProviderV1.get_backend(self, name, **kwargs)
     [67](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/providers/provider.py:67) backends = self.backends(name, **kwargs)
     [68](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/providers/provider.py:68) if len(backends) > 1:
---> [69](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/providers/provider.py:69)     raise QiskitBackendNotFoundError("More than one backend matches the criteria")
     [70](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/providers/provider.py:70) if not backends:
     [71](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/notebooks/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/qiskit/providers/provider.py:71)     raise QiskitBackendNotFoundError("No backend matches the criteria")

QiskitBackendNotFoundError: 'More than one backend matches the criteria'
ACE07-Sev commented 4 months ago

I have to mention I am on WSL : Ubuntu 22.0.4 if that makes a difference.

ACE07-Sev commented 4 months ago

Could it be that I'm using the updated branch of qiskit? Qiskit had an issue with the .depth() method which is merged with their 1.1.0 branch but not updated on their 1.1.0 pypi release. I am installing it like so

pip install git+https://github.com/Qiskit/qiskit.git@stable/1.1

Here's my full requirements.txt:

cirq == 1.3.0
cuda-quantum == 0.7.0
cuquantum == 24.3.0
numpy == 1.26.4
pennylane == 0.34.0
pennylane-lightning == 0.36.0
pytket == 1.27.0
pytket-qiskit == 0.53.0
qiskit @ git+https://github.com/Qiskit/qiskit.git@stable/1.1
qiskit_aer == 0.14.2
qiskit-aer-gpu == 0.14.2
qiskit_ibm_runtime == 0.23.0
qiskit-transpiler-service == 0.4.3
cqc-alec commented 4 months ago

OK, I think this is because you have qiskit-aer-gpu installed. I did not have it installed, but if I install it I see the same error. You can reproduce the error (independent of pytket) by running:

from qiskit_aer import Aer
b = Aer.get_backend("aer_simulator")

I guess this is because there is a GPU and a non-GPU variant. Indeed Aer.get_backends() lists two with this name.

This seems like an issue that should be addressed in qiskit-aer-gpu. Most of the GPU variants have distinguished names, e.g. "'aer_simulator_statevector_gpu" to distinguish from "'aer_simulator_statevector".

But we should find a workaround in pytket-qiskit.

ACE07-Sev commented 4 months ago

Awesome. May I ask when this will be merged so that I can install it in my environment as well?

cqc-alec commented 4 months ago

It's now merged to main so you can install directly from there, or wait for a pytket-qiskit release which should be in the next day or so.