IBMBackendValueError: number of circuits exceeds the maximum for this backend, 300

Hi, I am trying to run the QAOA on the IBMQ device. The QAOA circuit consists of 6 qubits, two layers. The number of total trainable parameters for the QAOA circuit is 14. The toy code is as below:

dev = qml.device('qiskit.ibmq', wires=args.dataset.n_node, backend='ibm_kyoto', ibmqx_token=token)
circuit = QAOA(dev)
opt_b = qml.AdamOptimizer(args.lr_qaoa)
param_b, loss = opt_b.step_and_cost(lambda param_b: circuit(param_b, circuit.param_c), circuit.param_b)

After running the code, it successfully run on the IBMQ backend in the beginning by checking the IBMQ dashboard of my account. However, it soon raised the error qiskit_ibm_provider.exceptions.IBMBackendValueError: Number of circuits, 418 exceeds the maximum for this backend, 300).
The detailed pennylane version information is listed in the following:

Name: PennyLane
Version: 0.35.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: https://github.com/PennyLaneAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /home/yqia7342/qml/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-qiskit, PennyLane_Lightning

Platform info:           Linux-5.15.0-58-generic-x86_64-with-glibc2.35
Python version:          3.10.12
Numpy version:           1.26.4
Scipy version:           1.12.0
Installed devices:
- default.clifford (PennyLane-0.35.1)
- default.gaussian (PennyLane-0.35.1)
- default.mixed (PennyLane-0.35.1)
- default.qubit (PennyLane-0.35.1)
- default.qubit.autograd (PennyLane-0.35.1)
- default.qubit.jax (PennyLane-0.35.1)
- default.qubit.legacy (PennyLane-0.35.1)
- default.qubit.tf (PennyLane-0.35.1)
- default.qubit.torch (PennyLane-0.35.1)
- default.qutrit (PennyLane-0.35.1)
- null.qubit (PennyLane-0.35.1)
- lightning.qubit (PennyLane_Lightning-0.35.1)
- qiskit.aer (PennyLane-qiskit-0.35.1)
- qiskit.basicaer (PennyLane-qiskit-0.35.1)
- qiskit.ibmq (PennyLane-qiskit-0.35.1)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.35.1)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.35.1)
- qiskit.remote (PennyLane-qiskit-0.35.1)

Could you please provide some advice to solve this issue? Thanks !

Hey @Yang,

Based on the error you’re getting, tt seems like you’re asking too much from the backend. Are you able to accomplish what you want to accomplish with a less demanding calculation?

Hi @isaacdevlugt ,

Thank you for the advice. I cannot recognize which part of the code requires a larger number of circuits and how to control the demanding resource. Could you please explain it?

Can you attach the code that you’re running? It’s hard to tell why this is happening without it :sweat_smile:

Thanks for your reply. The following is the simplified version of my code.

def encode_layer(nr_qubits):
    for i in range(nr_qubits):
        qml.Hadamard(wires=i)

def U_C(gamma, weights=None, edges=None):
    for i, edge in enumerate(edges):
        qml.CNOT(wires=[int(edge[0]), int(edge[1])])
        qml.RZ(gamma*weights[i], wires=int(edge[1]))
        qml.CNOT(wires=[int(edge[0]), int(edge[1])])

def U_B(beta, n_qubits=None):
    for i in range(n_qubits):
        qml.RX(beta[i], wires=i)

def circuit(param_b, param_c, edges, weights, n_qubits, n_layer):
    encode_layer(n_qubits)
    for j in range(n_layers):
        U_C(param_c[j], weights, edges)
        U_B(param_b[j], n_qubits)
    return qml.expval(A)

n_node = 6
n_layer =2
degree = 3
edges = nx.random_regular_graph(degree, n_node)
edges = list(edges..edges().keys())
weights = np.random.uniform(0, 1, len(edges)).tolist()
dev = qml.device('qiskit.ibmq', wires=n_node, backend='ibm_kyoto')
circuit_dev = qml.qnode(dev)(circuit)

lr = 0.15
opt_b = qml.AdamOptimizer(lr)
param_b = np.random.uniform(0, np.pi * 2, (n_layer, n_node))
param_c = np.random.uniform(0, np.pi * 2, (n_layer))
param_b, loss = opt_b.step_and_cost(lambda param: circuit_dev(param, param_c, edges, weights, n_node, n_layer), param_b)

Interesting… I wasn’t able to replicate the behaviour with this code:

import pennylane as qml
import pennylane.numpy as np
import networkx as nx

n_node = 6
n_layer =2
degree = 3
edges = nx.random_regular_graph(degree, n_node)
edges = list(edges.edges().keys())
weights = np.random.uniform(0, 1, len(edges)).tolist()

def encode_layer(nr_qubits):
    for i in range(nr_qubits):
        qml.Hadamard(wires=i)

def U_C(gamma, weights=None, edges=None):
    for i, edge in enumerate(edges):
        qml.CNOT(wires=[int(edge[0]), int(edge[1])])
        qml.RZ(gamma*weights[i], wires=int(edge[1]))
        qml.CNOT(wires=[int(edge[0]), int(edge[1])])

def U_B(beta, n_qubits=None):
    for i in range(n_qubits):
        qml.RX(beta[i], wires=i)

def circuit(param_b, param_c, edges, weights, n_qubits, n_layer):
    encode_layer(n_qubits)
    for j in range(n_layer):
        U_C(param_c[j], weights, edges)
        U_B(param_b[j], n_qubits)
    return qml.expval(qml.Z(0))

dev = qml.device('qiskit.ibmq', wires=n_node, backend='ibm_kyoto', ibmqx_token="~~~~")
circuit_dev = qml.qnode(dev)(circuit)

with qml.Tracker(dev) as tracker:

    print(circuit_dev.get_best_method(dev, interface="numpy"))
    lr = 0.15
    opt_b = qml.AdamOptimizer(lr)
    param_b = np.random.uniform(0, np.pi * 2, (n_layer, n_node))
    param_c = np.random.uniform(0, np.pi * 2, (n_layer))
    param_b, loss = opt_b.step_and_cost(lambda param: circuit_dev(param, param_c, edges, weights, n_node, n_layer), param_b)

print(tracker.latest)
(<transform: param_shift>, {}, <IBMQDevice device (wires=6, shots=1024) at 0x3109f6290>)
...
{'job_time': {'queued': 0.886248, 'running': 35.419}}

I tried using our tracker (qml.Tracker — PennyLane 0.35.1 documentation) to see what was going on, but everything seems fine! Let me know if you’re able to replicate this. For reference:

Name: PennyLane
Version: 0.35.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: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Users/isaac/.virtualenvs/pennylane-qiskit/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-qiskit, PennyLane_Lightning

Platform info:           macOS-14.4.1-arm64-arm-64bit
Python version:          3.11.8
Numpy version:           1.26.4
Scipy version:           1.12.0
Installed devices:
- default.clifford (PennyLane-0.35.1)
- default.gaussian (PennyLane-0.35.1)
- default.mixed (PennyLane-0.35.1)
- default.qubit (PennyLane-0.35.1)
- default.qubit.autograd (PennyLane-0.35.1)
- default.qubit.jax (PennyLane-0.35.1)
- default.qubit.legacy (PennyLane-0.35.1)
- default.qubit.tf (PennyLane-0.35.1)
- default.qubit.torch (PennyLane-0.35.1)
- default.qutrit (PennyLane-0.35.1)
- null.qubit (PennyLane-0.35.1)
- lightning.qubit (PennyLane_Lightning-0.35.1)
- qiskit.aer (PennyLane-qiskit-0.35.1)
- qiskit.basicaer (PennyLane-qiskit-0.35.1)
- qiskit.ibmq (PennyLane-qiskit-0.35.1)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.35.1)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.35.1)
- qiskit.remote (PennyLane-qiskit-0.35.1)