tequilahub / tequila

A High-Level Abstraction Framework for Quantum Algorithms
MIT License
369 stars 103 forks source link

Why the expect value of Hamiltonian is different from qiskit? #299

Closed YangD5014 closed 1 year ago

YangD5014 commented 1 year ago

When I have a tequila circuit transformed from openqasm, I do try the circuit(no uncertain parameters) as ansatz,and I get the expectation value of Hamiltonian,but get far different value compared to qiskit. Please correct me if I do misuse the tequila API.

kottmanj commented 1 year ago

Hi, can you post a small example on what exactly you're doing, that might help.

YangD5014 commented 1 year ago

https://github.com/YangD5014/Tequlia_issue/blob/main/tequila_issue.ipynb Really thank you for instantly reply!

kottmanj commented 1 year ago

thanks for the example. Next reply will take a bit longer ;-)

kottmanj commented 1 year ago

I think I found the problem: it is not the qasm import, this works fine.

Qiskit is using the following oder in the second quantized Hamiltonian: first N/2 qubits are the spin-up orbitals, second N/2 qubits are the spin-down orbitals. So for the H2 we have: qubit 0: orbital0 spin-up qubit 1: orbital1 spin-up qubit 2: orbital0 spin-down quits 3: orbital1 spin-down

Tequila is using the same ordering as openfermion: Even qubits are spin-up, odd qubits are spin-down. So for the H2 we have: qubit 0: orbital0 spin-up qubit 1: orbital0 spin-down qubit 2: orbital1 spin-up quits 3: orbital1 spin-down

Good news is: You can use the ordering that qiskit uses also in Tequila

mol = tq.Molecule(geometry=..., basis_set=..., transformation="ReorderedJordanWigner")

same goes with "ReorderedBravyiKitaev" etc (the upper-cases are just for readability)

YangD5014 commented 1 year ago

It is so clear! And it is indeed working,thank you!