Why doesn't execution in lightning.gpu work?

Hello! When I try to use lightning.gpu simulator instead of default.qubit simulator or lightning.qubit simulator, the execution results are strange. What could be the cause?

I am using Google Colab.

The code is below.

I referred to this site.
https://docs.pennylane.ai/en/stable/code/qml_qaoa.html

pip install pennylane

pip install cuquantum-python

pip install pennylane-lightning[gpu]
import pennylane as qml
from pennylane import qaoa
from networkx import Graph

# Defines the wires and the graph on which MaxCut is being performed
wires = range(3)
graph = Graph([(0, 1), (1, 2), (2, 0)])
# Defines the QAOA cost and mixer Hamiltonians
cost_h, mixer_h = qaoa.maxcut(graph)
# Defines a layer of the QAOA ansatz from the cost and mixer Hamiltonians
def qaoa_layer(gamma, alpha):
    qaoa.cost_layer(gamma, cost_h)
    qaoa.mixer_layer(alpha, mixer_h)
# Repeatedly applies layers of the QAOA ansatz
def circuit(params, **kwargs):

    for w in wires:
        qml.Hadamard(wires=w)

    qml.layer(qaoa_layer, 2, params[0], params[1])
# Defines the device and the QAOA cost function
dev = qml.device('lightning.gpu', wires=len(wires))
cost_function = qml.ExpvalCost(circuit, cost_h, dev)
print(cost_function([[1, 1], [1, 1]]))

In case of ‘default.qubit’
-1.8260274380964303

In case of ‘lightning.qubit’
-1.8260274380964303

In case of ‘lightning.gpu’
image

Hello Shuto.M!

Thank you for your question. This is likely an issue with cuQuantum and not with PennyLane, but I will consult our software team and get back to you when we figure out where the issue is.

2 Likes

Hi @Shuto.M,

Do you have access to an NVIDIA GPU through Google Colab? My guess is that you don’t have access to supported GPUs and thus the program is going through some trouble. What result do you get if you use lightning.qubit instead of lightning.gpu? And what is your output for qml.about()?

1 Like

Hello Ballon!

Thanks for your reply.
I would appreciate it if you could let me know what you find out.
Best regards.

Hi @CatalinaAlbornoz

In the case of lightning.qubit, the image is shown below.

Hi @Shuto.M, I can see that you’re using ExpvalCost which is deprecated. I see that this is a mistake in our documentation. I will look for an alternate solution using qml.expval and let you know if I can find one.

1 Like