Slow building adaptive circuits in Pennylane

Hi,

I have been trying o build adaptive circuits based on Adapt VQE for some larger molecules (where the number of qubits ranged from 14-24). I was simulating circuits like CH4 and was trying to build circuits with larger number of qubits. I wanted to use the generated rpoigrams as a benchmarking scheme.
However basing my code on https://pennylane.ai/qml/demos/tutorial_adaptive_circuits.html. However mon trying some larger molecules were the number of active electrons was placed higher and the number of qubits went to 24 for example, then the following peices of code took an incredibly long time

> dev = qml.device("default.qubit", wires=qubits)
cost_fn = qml.ExpvalCost(circuit_1, H, dev, optimize=True)
circuit_gradient = qml.grad(cost_fn, argnum=0)
params = [0.0] * len(doubles)
grads = circuit_gradient(params, excitations=doubles)
for i in range(len(doubles)):
        print(f"Excitation : {doubles[i]}, Gradient: {grads[i]}")

I realized the costy function creation using the ExpvalCost was extremely slow. Same with the circuit_gradients() method as well. Is there any way I can speed up the process of creation if the cost function for different (and larger) hamiltonians? Or is the scaling for these operations extremely bad and I don’t have much wiggle room.

Hi @Rquant, could you please share the full code you’re using? This way we can do tests on your code and see if we can find any possible improvements. You shouyld be able to upload your code here as a .py file or you can copy and paste it here too.