Hey! I think I posted this before but I’m having trouble again with this.

I’m simulating a 20 qubit system on Google Collab, using the `lightning.gpu`

backend. On Google-collab, I’m using the A100 runtime as well.

Here is a self-contained version of the code:

```
# Test circuit:
# Imports relevant packages:
!pip install pennylane custatevec-cu12 pennylane-lightning-gpu
!pip install pyscf
# imports and relevant defines:
import pennylane as qml
from pennylane import qchem
from pennylane import numpy as np
import time
# Simulation starting parameters:
symbols = ["O", "H", "H", "O", "H", "H"]
# geometry array for water-dimer
x = np.array([ 0. , 0. , 0. , 1.563923 , 0.98312309,
-0.60365174, -0.78395943, 1.43700227, 1.04747968, 4.26606551,
0.56799183, 1.68673518, 4.63354675, 1.15239926, 3.50338239,
6.10594353, 0.1835633 , 1.19292837], requires_grad=True)
active_electrons = 16
active_orbitals = 10
# define the hamiltonian needed to compute cost-function
def H(x):
return qml.qchem.molecular_hamiltonian(symbols, x, charge=0, active_electrons = active_electrons, active_orbitals = active_orbitals, method = "pyscf")[0]
# Define Hartree-Fock State
hf = qml.qchem.hf_state(electrons=active_electrons, orbitals=active_orbitals*2)
print(hf)
# other parameters
qubits = active_orbitals*2
singles_select = np.load('singles_select_1610.npy').tolist()
doubles_select = np.load('doubles_select_1610.npy').tolist()
hf_state = hf
num_wires = qubits
# Define Quantum Circuit to take expectation value:
dev = qml.device("lightning.gpu", wires=num_wires, batch_obs=True)
@qml.qnode(dev, interface="autograd", diff_method="adjoint")
def circuit(params, obs, wires):
# prepares Hartee-fock state:
qml.BasisState(hf_state, wires=wires)
# apply all single excitations
for i, singles in enumerate(singles_select):
qml.SingleExcitation(params[i], wires=singles)
# apply all double excitations
for j, doubles in enumerate(doubles_select):
qml.DoubleExcitation(params[j + len(singles_select)], wires=doubles)
# returns expectation value of the ansatz prepared from this quantum circuit:
return qml.expval(obs)
########### Define the Objective Function: ###########
def cost(params, x):
hamiltonian = H(x)
return circuit(params, obs=hamiltonian, wires=range(num_wires))
# Define circuit parameters:
theta = np.array([0.0] * (len(doubles_select) + len(singles_select)), requires_grad=True)
# Define Optimizer:
opt_theta = qml.GradientDescentOptimizer(stepsize=0.2)
# Perform a single update of theta:
theta.requires_grad = True
x.requires_grad = False
theta, _ = opt_theta.step(cost, theta, x)
print("Done with theta optimization!")
```

I’ve tried implementing the `adjoint`

diffrentiation method as you can see for the QNode parameter. If anyone as any other methods to reduce memory, such as maybe some form of parallelization or an alternate differentiation, that would be *much* appreciated! I know it should it be possible to run this because I’ve seen posts of people simulating >25 qubits before!

By the way, I’ve also attached a file of the selected gates I used (‘singles_select_1610.npy’ and ‘doubles_select_1610.npy’) If you’re running this, if you could just simply put the files in the same directory as the code, that’s all that’s needed to run!

Thanks so much!