Skip to content

Demo: X-ray Absorption Spectroscopy #1390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 101 commits into
base: master
Choose a base branch
from
Open

Demo: X-ray Absorption Spectroscopy #1390

wants to merge 101 commits into from

Conversation

colinjdale
Copy link
Collaborator

@colinjdale colinjdale commented May 30, 2025

Title:

X-ray absorption spectroscopy simulation in the time domain

Summary:

This demo shows how to implement a time-domain XAS simulation algorithm for a small instance of an $H_2$ molecule. The algorithm is based on Fomichev et al. 2025, omitting some of the optimizations in that paper. XAS is introduced as well as why simulating XAS could be a promising use for early fault-tolerant quantum computers. The algorithm is described, and then implemented in PennyLane, with the time-domain and spectrum output plotted. Additional optimizations are discussed at the end.

Relevant references:

"Fast simulations of X-ray absorption spectroscopy for battery materials on a quantum computer" by Stepan Fomichev, Pablo A. M. Casares, Jay Soni, Utkarsh Azad, Alexander Kunitsa, Arne-Christian Voigt, Jonathan E. Mueller, Juan Miguel Arrazola, (2025) https://arxiv.org/abs/2506.15784

"Simulating X-ray absorption spectroscopy of battery materials on a quantum computer", by Stepan Fomichev, Kasra Hejazi, Ignacio Loaiza, Modjtaba Shokrian Zini, Alain Delgado, Arne-Christian Voigt, Jonathan E. Mueller, Juan Miguel Arrazola (2024) https://arxiv.org/abs/2405.11015

Possible Drawbacks:

Large knowledge overhead
The demo makes extensive reference to previous quantum chemistry demos: Using PennyLane with PySCF and OpenFermion, Initial state preparation for quantum chemistry, and How to build compressed double-factorized Hamiltonians. This increases the overhead for the reader to understand the demo (IMO).

Example too simple/not relevant
$H_2$ is not a battery material, but calculating the ground state for some small cluster of a relevant material would take a long time, and is infeasible for a demo. I tried to use an $N_2$ molecule, but factorize seemed to produce different results on my local computer and on the website, so I changed back to $H_2$.

PennyLane factorization requires fine-tuned parameters
qml.qchem.factorize does not seem to reliably produce a factorized Hamiltonian that works well in the algorithm unless the number of factors and number of steps of optimization are set very specifically. This was particularly an issue for an $N_2$ active space, where I had to scan a large parameter space to find the number of factors that worked. The implementation in Stepan and Pablo's xas_simulation repo works much better than the PennyLane implementation. I'm not sure why the PennyLane factorization is so reliant on a very specific number of factors. It seems to be reliable for $H_2$, which is why I switched back to it.

Molecular orbital coefficient sign flip-flop/inconsistency between implementations
The molecular orbital coefficients (MO coeffs) that are calculated in PySCF, PennyLane and OpenFermion end up slightly different from each other. Because CASCI methods are used to find the ground state in the active space, I had to overwrite the PySCF MO coeffs with the PennyLane calculated MO coeffs to match the ones used in the Hamiltonian and the dipole operator. I believe the MO coeffs have to be the same in all calculations for the result to be correct. However, qml.qchem.scf does not consistently produce the same MO coeffs, and I believe the same is true for PySCF. But, the beyond Hartree-Fock calculation methods in PySCF pull from the initial Hartree Fock instance, so the MO coefficients remain the same. However in PennyLane, the MO coeffs are recalculated when dipole_moment and electron_integrals are called, so I'm not sure if they will always give the same values. When trying an $N_2$ active space, I ended up changing the bond length to 1.0 Angstrom from 1.077 because that seemed to produce more stable results.

Related GitHub Issues:


If you are writing a demonstration, please answer these questions to facilitate the marketing process.

  • GOALS — Why are we working on this now?

To show off a recent Xanadu paper. This paper is of interest because it describes a quantum algorithm that could have near-term industrial utility (battery material simulation). The implementation of this algorithm in PennyLane is relatively simple, due to the functions in the quantum chemistry module of PennyLane. Showing off the utility of these functions is a main focus of the demo.

  • AUDIENCE — Who is this for?

Chemistry researchers, anyone interested in Hamiltonian simulation algorithms.

  • KEYWORDS — What words should be included in the marketing post?

X-ray absorption spectroscopy, Hamiltonian simulation, battery research, compressed double-factorized Hamiltonians, time-domain simulation, optimization, product formulas, commercial application

  • Which of the following types of documentation is most similar to your file?
    (more details here)
  • Tutorial
  • Demo
  • How-to

@colinjdale colinjdale self-assigned this May 30, 2025
Copy link

github-actions bot commented Jun 2, 2025

Thank you for opening this pull request.

You can find the built site at this link.

Deployment Info:

  • Pull Request ID: 1390
  • Deployment SHA: e10e2d1968258d55b25235abb605576007e54bbb
    (The Deployment SHA refers to the latest commit hash the docs were built from)

Note: It may take several minutes for updates to this pull request to be reflected on the deployed site.

Copy link
Collaborator

@alvaro-at-xanadu alvaro-at-xanadu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to read this in more detail so suggest more story-telling improvements, but I think it's already in excellent shape. I don't think we need to add any more stuff, the $H_2$ implementation is more than enough. I feel that a more complex example would make the demo too long and unnecessarily complex.

######################################################################
# .. figure:: ../_static/demonstration_assets/xas/fingerprinting.gif
# :alt: alt text
#
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this so much 😍

return qml.state()

return qml.QNode(circuit, dev)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice pieces of code 🚀

colinjdale and others added 12 commits July 14, 2025 09:21
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Implemented minor comments.

Co-authored-by: Alvaro Ballon <91897656+alvaro-at-xanadu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants