In the context of a project on variational quantum circuit and Xanadu, I wanted to simulate the CH4 molecule using PennyLane. After going through most of the tutorials, I came up with this code : GitHub - Mohamed-MEGUEBEL/CH4-Simulation-PennyLane: QML project
I add that computing the molecular Hamiltonian as it is (considering all the orbitals) didn’t work, so I add to make some simplifications based on a prior study of the molecular structure of CH4 :
So in the end, I’ve namely considered an initial spin multiplicity of one (no single electron) and 5 active MOs (the 2s-s, 2p-p and 2p-s) with 8 active electrons. Using a direct computation of the eigenvalues sparsing out the Hamiltonian gives a rather close result to the one I found using VQE.
My questions were :
how does PennyLane know that I’m considering the aforementionned orbitals and not say the low energy non-bounding 2s- or the 3 highest energy MOs ? same question for the electrons.
when PennyLane is computing the gradient, is it doing so with parameter-shift rules or with finite differences ?
I’ve tried computing the gradient using QNG instead of vanilla gradient descent, but without any noticable speed-up. Isn’t QNG supposed to be better for optimization than vanilla gradient descent is ?
I realize this is a lot of fairly technical questions, many thanks in advance for answering them!!
I’m not sure that I understand your first question. PennyLane will find the configuration that gives the lowest energy. So it’s normal that it won’t consider molecular orbitals that result in higher energies.
When PennyLane is computing the gradient the default differentiation method will depend on the device and the interface. If not specified, the default differentiation method is
diff_method="best". PennyLane will attempt to determine the best differentiation method given the device and interface. Typically, PennyLane will prioritize device-provided gradients, backpropagation, parameter-shift rule, and finally finite differences, in that order. You can also specify the differentiation method that you want when you create the qnode.
QNG isn’t always better. It really depends on what you want to optimize so it’s not the secret sauce that will always work best.
Please let me know if this answers your questions!
First, thanks (again) for your answers!
What I meant for the first question is that : for CH4, you have C : 1s^22p^22p^2 and H : 1s^1.
This means that you technically have 1 (1s of C) + 1 (2s of C) + 3 (p_x,p_y,p_z) + 4 (1s of the four H).
After studying the geometry (see diagram), you end up with MOs : 1s (deepest energy for C, core orbital) + 8 MOs (see diagram), meaning 9 MOs hence 18 qubits.
I want to take out of the computation in PennyLane the MOs 1s and the three sigma^* (see diagram).
However, PennyLane only lets you indicate how many orbitals are active, but not which one are.
Who’s to say that when I indicated “active_orbitals = 5” it didn’t take into account the 5 lowest energy MOs ?
Hope it’s clearer this way.
And I’ve taken notes on what you’ve said for the two other questions.
Many thanks for your time!
Hi @Mohamed_SO. In PennyLane, the active molecular orbitals are selected according to their energy level as described in this demo (more specifically this figure). For instance, when you select 8 electrons and 5 molecular orbitals to construct your active space, the 4 highest energy occupied molecular orbitals and the lowest energy unoccupied molecular orbital (LUMO) are used to construct the active space. Please let me know if you have any other questions.
Well if I understood correctly, this is good thing but I don’t understand why wouldn’t PennyLane take the 1s orbital coming from C into account. I mean that’s a good thing that it doesn’t but I’m not sure I’m seeing how it can.
Hi @Mohamed_SO. If I understand correctly, you want to keep all of the electrons in the active space but exclude some of the molecular orbitals. If my understanding is correct, then all you can do is to exclude some of the highest energy unoccupied orbitals. Based on what you mentioned above:
I want to take out of the computation in PennyLane the MOs 1s and the three sigma^*
You cannot exclude the occupied molecular orbitals and still keep all of the electrons in your active space. If you exclude the lowest energy occupied orbital in the diagram you showed, then the core electrons have to be excluded as well. If you please provide me with more information about what you want to do (I guess you want to reduce the number of qubits to make the simulation more affordable?) then I can give you more details. Thanks!