I have two questions regarding @qml.qjit.
-
I am using @qml.qjit with the UCCSD ansatz, and it’s giving the following error.
ValueError: Operation Sum is not written in terms of a single parameter
Here is my code:
dev = qml.device("lightning.qubit", wires=qubits)
s_wires, d_wires = qchem.excitations_to_wires(singles, doubles)
@qml.qnode(dev)
def circuit(params):
qml.UCCSD(params,range(qubits),s_wires,d_wires,hf_state)
return qml.expval(H)
opt = qml.QNGOptimizerQJIT(stepsize=0.1, approx='block-diag')
def update_step_qjit(i, args):
params, state = args
return opt.step(circuit, params, state)
@qml.qjit
def optimization_qjit(params, iters):
state = opt.init(params)
args = (params, state)
params, state = qml.for_loop(iters)(update_step_qjit)(args)
return params
params = jnp.zeros(num_params)
iters = 5
start = time.time()
optimization_qjit(params=params,iters=iters)
print(time.time() - start)
Any idea how to resolve this? I am running the code on an A100 GPU on Google Colab.
- When I run the code without @qml.qjit. The code is running ok. However, it’s taking more time than regular Pennylane numpy and QNGOptimizer. After reading this blog, PennyLane v0.43 and Catalyst v0.13 released | PennyLane Blog, I thought this would speed up (or atleast perform the same) the simulation. Could you suggest an alternative method to accelerate the VQE?
For reference: Pennylane Numpy + QNGOptimizer: 35 secs per iteration on CPU.
Here is qml.about()
!pip install pennylane==0.43
!pip install pennylane-catalyst==0.13
!pip install -U "jax[cuda12]==0.6.2"
import pennylane as qml
qml.about()
Name: pennylane
Version: 0.43.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:
Author:
Author-email:
License:
Location: /usr/local/lib/python3.12/dist-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing_extensions
Required-by: pennylane_catalyst, pennylane_lightning
Platform info: Linux-6.6.105+-x86_64-with-glibc2.35
Python version: 3.12.12
Numpy version: 2.0.2
Scipy version: 1.16.3
JAX version: 0.6.2
Installed devices:
- default.clifford (pennylane-0.43.0)
- default.gaussian (pennylane-0.43.0)
- default.mixed (pennylane-0.43.0)
- default.qubit (pennylane-0.43.0)
- default.qutrit (pennylane-0.43.0)
- default.qutrit.mixed (pennylane-0.43.0)
- default.tensor (pennylane-0.43.0)
- null.qubit (pennylane-0.43.0)
- reference.qubit (pennylane-0.43.0)
- nvidia.custatevec (pennylane_catalyst-0.13.0)
- nvidia.cutensornet (pennylane_catalyst-0.13.0)
- oqc.cloud (pennylane_catalyst-0.13.0)
- softwareq.qpp (pennylane_catalyst-0.13.0)
- lightning.qubit (pennylane_lightning-0.43.0)