Dear Pennylane team,
This post is related to my previous post where I tried to create a Hamiltonian for a large molecule. Back then Pennylane took long time to create a Hamiltonian and then crashed the system. The solution was offered but it crashed the Jupter lab (not the entire system). So I moved to other frameworks that handled this situation.
Today, I tried to get past the stage of Hamiltonian creation and get the circuit for the Hamiltonian. Unfortunattely, it seems Pennylane still can’t deal with relatively large molecules as it produces an error during the circuit creation.
Here is the code:
molecule == "C2HF3"
symbols = ["C", "C", "F", "F", "F", "H"]
coordinates = (
np.array(
[
0.0,
0.430631,
0.000000,
-0.704353,
-0.686847,
0.0,
1.314791,
0.500587,
0.0,
-0.554822,
1.630861,
0.0,
-0.092517,
-1.882156,
0.0,
-1.780948,
-0.706341,
0.0,
]
) / 0.529177210903
hamiltonian, num_qubits = qchem.molecular_hamiltonian(
symbols, coordinates, method="pyscf"
)
print(f"Number of qubits: {num_qubits}")
# print(hamiltonian)
# Init device
wires = range(num_qubits)
num_wires = num_qubits
dev = qml.device("default.qubit", wires=wires)
# Build a circuit
evolution_time = 0.5
trotter_steps = 1
coeffs_and_time = [*hamiltonian.coeffs, evolution_time]
@qml.qnode(dev)
def circuit(evolution_time):
ApproxTimeEvolution.compute_decomposition(
*coeffs_and_time, wires=wires, n=trotter_steps, hamiltonian=hamiltonian
)
return [qml.expval(qml.PauliZ(wires=i)) for i in wires]
specs_func = qml.specs(circuit, expansion_strategy="device")
print(specs_func(evolution_time))
The output:
Traceback (most recent call last):
File "/home/user1/x/x-x/circuit_compilation/qchem/chem_circuits_sk.py", line 80, in <module>
dev = qml.device("default.qubit", wires=wires)
File "/home/user1/x/x-x/circuit_compilation/qalgs_env/lib/python3.10/site-packages/pennylane/__init__.py", line 337, in device
dev = plugin_device_class(*args, **options)
File "/home/user1/x/x-x/circuit_compilation/qalgs_env/lib/python3.10/site-packages/pennylane/devices/default_qubit.py", line 205, in __init__
self._state = self._create_basis_state(0)
File "/home/user1/x/x-x/circuit_compilation/qalgs_env/lib/python3.10/site-packages/pennylane/devices/default_qubit.py", line 705, in _create_basis_state
state = np.zeros(2**self.num_wires, dtype=np.complex128)
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 64.0 PiB for an array with shape (4503599627370496,) and data type complex128
(qalgs_env) user1@linuxpc:~/x/x-Research/circuit_compilation/qchem$
Version:
Name: PennyLane
Version: 0.31.0
Platform info: Linux-5.19.0-46-generic-x86_64-with-glibc2.35
Python version: 3.10.6
Numpy version: 1.23.5
Scipy version: 1.10.0