Bravyi_kitaev vs jordan_wigner - molecular Hamiltonian

Mapping bravyi_kitaev vs jordan_wigner - molecular Hamiltonian

I run the code from the following tutorial:

without any changes, except for setting the mapping explicitly to bravyi_kitaev instead of the default one which I assume is jordan_wigner.

After this minor change I get at the end of the VQE result that is numerically not accurate.

The same happens (change to bravyi_kitaev does not allow to reproduce correct numerical results) when I run the code from the Usage Details section from this link:

Is it an internal pennylane issue or is it just that bravyi kitaev for some reason performs worse for chemistry VQE than jordan wigner?

Hi @mbaczyk, welcome to the forum and thank you for posting this question here!

I’m not being able to reproduce your problem. I ran the Adaptive circuits for quantum chemistry — PennyLane demo with mapping='bravyi_kitaev' in the computation of the molecular hamiltonian and I get the same result (E = -7.88223735) as when I specify mapping="jordan_wigner" or when I don’t specify any mapping.

Could you please post the output of qml.about()? import pennylane as qml; qml.about()

If you’re already using the latest PennyLane version then I would recommend that you post the exact line(s) of code that you changed because the problem may be there.

Hi @CatalinaAlbornoz, thank you for your prompt response and warm welcome!

I was working with the Pennylane version 0.22.2 and with that version for the Adaptive circuits tutorial I was getting an error that “output seems to be independent of input” while calculating gradients of circuits. The update to the latest version has solved the issue.

However, I think some problem still exists. Right now I am running bravyi_kitaev transformation in the openfermion library and then I am importing the observable to pennylane. In that case I am still getting an error that output seems to be independent of the input. The following lines are the details how I create my Hamiltonian, then I run the code from Adaptive circuits tutorial for the optimization.

system = '
basis = 'sto-3g'
multiplicity = 1
charge = 0
active_indices = [1, 2, 3, 4, 5]
occupied_indices = [0]
active_orbitals = 2 * len(active_indices)
active_electrons = 2

geometry = openfermion.chem.geometry_from_file('')

molecule = MolecularData(geometry=geometry,

fermionic_H = get_fermion_operator(

Hamiltonian = bravyi_kitaev(fermionic_H)

Hamiltonian = qchem.import_operator(Hamiltonian, format="openfermion")

Hi @mbaczyk, could you please share your full code, including your system? It will make it easier to reproduce your error.

Also, if you want to use an xyz file you can use our read_structure function, without needing to do so many things using openfermion. This may help you prevent errors. Here’s an example on how to use this function:

symbols, coordinates = qml.qchem.read_structure('')
print(symbols, coordinates)

Hi @mbaczyk, I’m adding your code here for completeness. (16.3 KB)

Hi @mbaczyk,

Thank you for your question.

I have looked into your code and I have the following comments.

First, I don’t see any problem in the way you are building the Hamiltonian. Perhaps you can save few lines of code by using the molecular_hamiltonian function available in PennyLane. In your example, this can be done as follows:

bohr_angs = 0.529177210903
symb = ["Li", "H"]
coords = np.array([0.0, 0.0, -0.39870062, 0.0, 0.0, 1.19046204])/bohr_angs

H, qubits = qml.qchem.molecular_hamiltonian(symb,

My second observation is probably more important. You have to be consistent with the chosen basis to encode the molecular wave function. If you use the occupation number basis, where the states of the qubits encode the occupation number of the spin molecular orbitals, you have to use the Jordan-Wigner transformation to map the fermionic to the qubit operator. Similarly, if you build your Hamiltonian using the Bravyi-Kitaev (BK) transformation you have to encode the molecular state using the BK basis. In the example code you provided these two representations are mixed as the defined quantum circuits rely on the occupation number basis encoding. In short, if you want to work with the BK Hamiltonian you would need to re-define the circuits to prepare the trial states in the BK basis. The transformations that can help you to do this can be found in this paper (e.g. Eq. (24):

The Bravyi-Kitaev transformation for quantum computation of electronic structure

I hope this helps. If you have further questions, do not hesitate to get back to us.

Thank you.