Hi there,
It has been a while since my last touch with Pennylane and Catalyst, and now I want to use Catalyst as a way to speed up QAOA optimization but I am running into some issues that I hope to get help with…
My pennylane version:
Name: PennyLane
Version: 0.36.0
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: /work/acslab/users/baobach/anaconda3/envs/pennylane_catalyst/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-Catalyst, PennyLane_Lightning
Platform info: Linux-3.10.0-957.27.2.el7.x86_64-x86_64-with-glibc2.17
Python version: 3.11.7
Numpy version: 1.26.4
Scipy version: 1.12.0
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.36.0)
- default.clifford (PennyLane-0.36.0)
- default.gaussian (PennyLane-0.36.0)
- default.mixed (PennyLane-0.36.0)
- default.qubit (PennyLane-0.36.0)
- default.qubit.autograd (PennyLane-0.36.0)
- default.qubit.jax (PennyLane-0.36.0)
- default.qubit.legacy (PennyLane-0.36.0)
- default.qubit.tf (PennyLane-0.36.0)
- default.qubit.torch (PennyLane-0.36.0)
- default.qutrit (PennyLane-0.36.0)
- default.qutrit.mixed (PennyLane-0.36.0)
- null.qubit (PennyLane-0.36.0)
- nvidia.custatevec (PennyLane-Catalyst-0.6.0)
- nvidia.cutensornet (PennyLane-Catalyst-0.6.0)
- oqc.cloud (PennyLane-Catalyst-0.6.0)
- softwareq.qpp (PennyLane-Catalyst-0.6.0)
The implementation is as follows:
dev = qml.device("lightning.qubit", wires=n_wires, shots=1)
# unitary operator U_B with parameter beta
def U_B(beta):
for wire in range(n_wires):
qml.RX(2*beta, wires=wire)
# unitary operator U_C with parameter gamma
def U_C(gamma):
edges_set = list(G.edges)
for edge in range(len(edges_set)):
wire1 = edges_set[edge][0]
wire2 = edges_set[edge][1]
qml.CNOT(wires=[wire1, wire2])
qml.RZ(gamma, wires=wire2)
qml.CNOT(wires=[wire1, wire2])
# QAOA circuit
@qml.qnode(dev)
def circuit(gammas, betas, edge):
qml.broadcast(qml.Hadamard, range(n_wires), pattern="single")
for i in range(num_layers):
U_C(gammas[i])
U_B(betas[i])
H = qml.PauliZ(edge[0]) @ qml.PauliZ(edge[1])
return qml.expval(H)
# minimize the negative of the objective function
@qml.qjit
def objective(params):
gammas = params[0]
betas = params[1]
neg_obj = 0
for edge in G.edges():
# objective for the MaxCut problem
neg_obj -= 0.5 * (1 - circuit(gammas, betas, edge=edge))
return neg_obj
When I try to execute the following code,
gammas = jnp.array(np.random.uniform(0, 1, size = (num_layers,)))
betas = jnp.array(np.random.uniform(0, 1, size = (num_layers,)))
init_params = jnp.array([betas, gammas])
objective(init_params)
There is an error as follows:
The error is kinda weird and hope someone can help me with this.
Thanks a lot.