Issue qml.qchem.basis_rotation

Hello! I’m trying to obtain a double factorized Hamiltonian in the LCU form using the qml.qchem.basis_rotation function. The problem is that the 1-norm of the Hamiltonian obtained through this function differs from the expected value and differs from the one calculated using qml.resource.DoubleFactorization which appears to return the correct result.

Here the snippet that shows this:

import pennylane as qml

molname = "H2"
bond =2.1

SystemData = qml.data.load(
        "qchem",
        molname=molname,
        bondlength=bond,
        basis="STO-3G",
        force = False,
        attributes = ["molecule", "hamiltonian"])[0]


mol = SystemData.molecule

nuc_core, one_body, two_body = qml.qchem.electron_integrals(mol)()

coeffs, ops, unitaries = qml.qchem.basis_rotation(one_body, two_body, tol_factor=1.0e-5)

one_norm_JW = sum(sum(abs(c)) for c in coeffs)

from pennylane.resource import DoubleFactorization as DF
norm_df = DF(one_body,two_body).lamb

print(f"One norm before JW {norm_df} one norm after JW {one_norm_JW}")

I’m reaching out to check if there is some error in the implementation of basis_rotation.

Thank you very much for your support.

Output of qml.about():
Name: PennyLane
Version: 0.40.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Author:
Author-email:
License: Apache License 2.0
Location: /home/ubmachine/Master_thesis/Bench_QTE/venv/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing-extensions
Required-by: PennyLane_Lightning

Platform info: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 2.0.2
Scipy version: 1.15.2
Installed devices:

  • default.clifford (PennyLane-0.40.0)
  • default.gaussian (PennyLane-0.40.0)
  • default.mixed (PennyLane-0.40.0)
  • default.qubit (PennyLane-0.40.0)
  • default.qutrit (PennyLane-0.40.0)
  • default.qutrit.mixed (PennyLane-0.40.0)
  • default.tensor (PennyLane-0.40.0)
  • null.qubit (PennyLane-0.40.0)
  • reference.qubit (PennyLane-0.40.0)
  • lightning.qubit (PennyLane_Lightning-0.40.0)

Hi @Francesco and thank you for using PennyLane!

Could you please look at the theory describing the computation of the 1-norm in qml.resource.DoubleFactorization and check if your manual computation of the 1-norm matches the definition there?

Please let me know if you still see inconsistency.

Thanks!

Hi, thanks for your answer.

I would expect the two definitions to coincide. Do you expect a different result?

Thanks

Hi @Francesco,

I am not sure the sum of coefficients, sum(sum(abs(c)) for c in coeffs), gives you the norm computed according to the definition provided in norm().

The norm computed by qml.resource.DoubleFactorization is different than summing over coefficients, as far as I can tell.

Please let me know if you have different thoughts.

Thanks.

Hi. Thanks for your support.

According to the documentation, the 1-norm provided by norm() is the "1-norm of a double-factorized molecular Hamiltonian ", and qml.qchem.basis_rotation returns the double-factorized Hamiltonian. So, if I compute the 1-norm of the double-factorized Hamiltonian (from qml.qchem.basis_rotation), I would expect the two to coincide.

Thank you very much for your patience.

Hi @Francesco,

It looks like the norm calculated by norm() is not the same as the norm calculated by doing sum(sum(abs(c)) for c in coeffs). This is because the mathematical definition for the norm in norm() is different. There’s nothing inherently wrong with that, they’re just two different norms, so you’ll have to check which one is best suited for your specific problem.

I hope this helps!