Generating Approximate Ground States of Molecules Using Quantum Machine Learning

Hello all! I’m trying to replicate the results from this paper:, and its GitHub is linked here: GitHub - XanaduAI/generative_qml_qchem: Repository for the generative QML for quantum chemistry project.

I noticed the code came out a year or 2 ago, and since Pennylane is fast paced, would any Pennylane expert know if it is possible to get this code working? For example, I noticed that this code uses qml.qchem.sparse_hamiltonian in file, but I noticed Pennylane doesn’t have this anymore? Will the function be anywhere in Pennylane’s other libraries, and in general, how would I go about adapting this code to use with Pennylane’s current function?


Hey @ImranNasrullah!

qml.qchem.sparse_hamiltonian was deprecated in v0.29, and you should use a Hamiltonian’s sparse_matrix method: qml.Hamiltonian — PennyLane 0.35.1 documentation.

If you run into any other features that are deprecated in that code, check out our deprecation page: Deprecations — PennyLane 0.35.1 documentation

Hope this helps!

A quick question. Some of the code seems a bit incomplete (but I know it can’t be because they ran the code. For example in their file, they call an n_params attribute of “model.obj”, but in the ModelObject class, that isn’t even a defined class attribute.

Would you mind taking a look at the code for me to see what I’m talking about and if I’m missing something?

Hi @ImranNasrullah ,

I mentioned this to one of the authors to see if they can help you understand the code. We’ll be back with more info in the next couple of days.

Hi @ImranNasrullah,

Unfortunately the code is quite old and the authors are busy at the moment so there isn’t much help they can provide at the moment.

You may need to dig deep into the code and rewrite parts of it to make it work. I’m sorry there’s no easy solution here.

Thank you that would be amazing. I think I get most of it, there’s just some actual inconsistencies in their code.

For example, they have a class called Molecule(), and for example, they’ll call Molecule.nelectrons multiple times in the code, but if you look at the class definition, their won’t be an attribute called .nelectrons. So not that specifically, but that’s just the type of errors I’m seeing, I could be wrong

Hi @ImranNasrullah, in the case of Molecule() I think they may be using the qml.qchem.Molecule class from PennyLane. This one indeed has an n_electrons attribute and here in the repo they have some classes for certain molecules where they specify that too.

Please remember that PennyLane has evolved a lot since the time when that code was written so it’s possible that the Molecule class is now different from how it was before.