Skip to content

[BUG] Creation of Qnode with a Azure device via Qiskit #8657

@Willem-de-kok

Description

@Willem-de-kok

Expected behavior

I would expect that via 'qiskit.remote', I could actually create a qml.QNode where I use as a device an azure.quantum device. I expect that, because the azure.quantum.qiskit package is set up via Qiskit. And the docs on remote devices https://docs.pennylane.ai/projects/qiskit/en/latest/devices/remote.html state:

The 'qiskit.remote' device is a generic adapter to use any Qiskit backend as interface for a PennyLane device.

Actual behavior

'num_qubits' property of the azure backend is not identified, and hence the Qnode can not be created.

Additional information

I recently discussed with some of the Pennylane colleagues the 'way-to-go' when wanting to run Pennylane circuits on Azure devices. They suggested to go from a QuantumTape through OpenQasm to a qiskit.QuantumCircuit representation, to then eventually run the qiskit.QuantumCircuit on an Azure-device.

I think that is a valid way and probably most stable under new updates of Pennylane, Qiskit or Azure.quantum SDKs. Nevertheless, it would be great if this was also a possibility.

If there is some clear reason why this won't work, I am also very happy to learn why that is the case.

Source code

from azure.quantum.qiskit import AzureQuantumProvider
from azure.quantum import Workspace
import pennylane as qml

workspace = Workspace.from_connection_string("<key>")
provider = AzureQuantumProvider(workspace)

azure_backend = provider.get_backend("quantinuum.sim.h2-1sc")
device = qml.device('qiskit.remote', wires=2, backend=azure_backend, shots=10)

def circuit():
    qml.Hadamard(0)
    qml.CNOT([0, 1])
    return qml.probs([0, 1])

qnode = qml.QNode(circuit, device)
print(qnode())

Tracebacks

PennyLaneDeprecationWarning: Setting shots on device is deprecated. Please use the `set_shots` transform on the respective QNode instead.
  warnings.warn(
Traceback (most recent call last):
  File "C:\pennylane_qiskit_converter\azure_connect_via_pennylane.py", line 57, in <module>
    device = qml.device('qiskit.remote', wires=2, backend=azure_backend, shots=10)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\pennylane-qiskit-converter\venv\Lib\site-packages\pennylane\devices\device_constructor.py", line 264, in device
    dev = plugin_device_class(*args, **options)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\pennylane-qiskit-converter\venv\Lib\site-packages\pennylane_qiskit\remote.py", line 146, in __init__
    super().__init__(wires, backend=backend, shots=shots, **kwargs)
  File "C:\pennylane_qiskit\qiskit_device.py", line 358, in __init__
    if len(self.wires) > int(self.backend.num_qubits):
                             ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'QuantinuumSyntaxCheckerQirBackend' object has no attribute 'num_qubits'

System information

Name: pennylane
Version: 0.43.1
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: 
Author: 
Author-email: 
License-Expression: Apache-2.0
Location: C:\pennylane-qiskit-converter\venv\Lib\site-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing_extensions
Required-by: PennyLane-qiskit, pennylane_lightning, tno.quantum.plugins.pennylane_qiskit_converter

Platform info:           Windows-10-10.0.26100-SP0
Python version:          3.11.10
Numpy version:           2.3.4
Scipy version:           1.16.3
JAX version:             None
Installed devices:
- default.clifford (pennylane-0.43.1)
- default.gaussian (pennylane-0.43.1)
- default.mixed (pennylane-0.43.1)
- default.qubit (pennylane-0.43.1)
- default.qutrit (pennylane-0.43.1)
- default.qutrit.mixed (pennylane-0.43.1)
- default.tensor (pennylane-0.43.1)
- null.qubit (pennylane-0.43.1)
- reference.qubit (pennylane-0.43.1)
- lightning.qubit (pennylane_lightning-0.43.0)
- qiskit.aer (PennyLane-qiskit-0.43.0)
- qiskit.basicaer (PennyLane-qiskit-0.43.0)
- qiskit.basicsim (PennyLane-qiskit-0.43.0)
- qiskit.remote (PennyLane-qiskit-0.43.0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions