Failing to create a circuit for a large molecule

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 = (
    ) / 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]

def circuit(evolution_time):
        *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")

The output:

Traceback (most recent call last):
  File "/home/user1/x/x-x/circuit_compilation/qchem/", 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/", 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/", 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/", 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$ 


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

Hey @Einar_Gabbassov!

Unfortunately, reaching this high of a qubit count is not possible right now. But, we’re adding some high-performance devices in the coming few months that should help you reach these qubit counts!

We’ve tagged this forum post in the internal pipeline we have for creating new features in PennyLane :slight_smile:. Be on the lookout for a reply from us when the high-performance devices become available! :smiley:

Hey @Einar_Gabbassov!

We’re curious about what other framework(s) you’ve been using that does allow you to simulate something this large :thinking:. Let us know if you can :slightly_smiling_face:

hi @isaacdevlugt
There are two parts to it:

  1. Getting a description of a quantum circuit which could be a python object (like Qiskit Circuit) or a QASM file. This is where Pennylane fails me so far. The key point is that the description may not require numpy array allocations.
  2. Getting the object or QASM file into a simulator or a compiler.

For the first part, I use Tangelo which is developed by my ex-1Qbit colleagues. For the second part, I can’t comment on it.

Hope this was anyhow useful.

1 Like

Thank you! This is useful information for us. Will get back to you here when we have a solution for you in PennyLane! :smile:

Do you mean that this is this confidential, or that you aren’t able to do it? :thinking: