Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quantum Generative Eigensolver for Molecular Energy Estimation (Q-GESolver)

This project implements a Quantum Generative Eigensolver (GQE) using PennyLane and PyTorch. The model aims to estimate molecular energies by applying a Transformer-based neural network to quantum chemical systems. The project combines quantum mechanics, variational principles, and machine learning to optimize and predict molecular energies efficiently.

Inspiration: This project was inspired by the PennyLane GQE training demo.

Project Overview

The core of this project is a GPT-like Transformer model that generates sequences of quantum operators (excitations) and evaluates their impact on molecular systems. It leverages a Quantum Generative Eigensolver (GQE) to minimize the difference between predicted and true molecular energies, providing an efficient method for simulating quantum systems such as molecules.

Key Concepts

  1. Quantum Generative Eigensolver (GQE): The GQE framework is inspired by classical eigensolvers, but it employs a quantum neural network to generate the operator sequences that simulate the evolution of a quantum state. The aim is to find the ground-state energy of a molecule by minimizing the loss function, which is defined based on the cumulative energy of operator sequences.

  2. UCC Operator Pool: The project uses Unitary Coupled Cluster (UCC) operators to describe the excitations in molecular systems, forming a pool of operators applied to generate quantum states.

  3. Hamiltonian and Expectation Values: The energy of a quantum system is described by the expectation value of its Hamiltonian:

    $E(\theta) = \left\langle \psi(\theta) \middle| H \middle| \psi(\theta) \right\rangle$

    where $\lvert \psi(\theta)\rangle$ is the parameterized quantum state generated by the model, and $H$ is the Hamiltonian of the system.

  4. Subsequence Energy Calculation: The model generates sequences of quantum operators and applies them to an initial quantum state. The energy for each subsequence of operators is computed using:

    $E_{\text{subsequence}} = \left\langle \psi_{\text{init}} \middle| U^\dagger H U \middle| \psi_{\text{init}} \right\rangle$

Physics Background

The quantum mechanical Hamiltonian of a molecular system describes the energy of electrons and nuclei. For a molecule like $\text{H}_2$, the Hamiltonian can be expressed as:

$$ H = -\sum_i \frac{\nabla_i^2}{2} - \sum_{i,j} \frac{Z_j}{r_{ij}} + \sum_{i < j} \frac{1}{r_{ij}} $$

where $\nabla_i^2$ is the kinetic energy of the electrons, $Z_j$ is the charge of the nucleus, and $r_{ij}$ is the distance between electron $i$ and nucleus $j$.

Mathematics in the Model

The core mathematical concept is minimizing the loss function, which is defined by the mean-squared error (MSE) between predicted cumulative energies and the true molecular energy:

$$ \mathcal{L}(\theta) = \frac{1}{N} \sum_{i=1}^{N} \left( E_{\text{predicted}}(\theta) - E_{\text{true}} \right)^2 $$

This is optimized using stochastic gradient descent (AdamW optimizer).


Features

  • Quantum Operator Pool: Generates and applies UCC (Unitary Coupled Cluster) and Lie Algebra-based operators to quantum states.
  • Transformer-based Architecture: Uses a GPT-like neural network to predict energy sequences.
  • Quantum Simulation: Calculates molecular energies using PennyLane and a qubit-based quantum simulator.
  • Custom Loss Function: Minimizes the difference between predicted energy sequences and true molecular energies using variational methods.

Installation

To set up the project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/JakeKitchen/Q-GESolver
    cd Q-GESolver
  2. Install the dependencies:

    pip install -r requirements.txt
  3. (Optional) Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # For Windows: venv\Scripts\activate

Usage

Once you have set up the environment, you can train the Quantum Generative Eigensolver as follows:

  1. Run the training script:
    python main.py

This will begin training the model, generating sequences of quantum operators and optimizing their energies to match the ground-state energy of a molecule (like $\text{H}_2$).


Example

An example of the energy prediction and loss calculation is shown below:

from models.gpt import GPTQE, GPTConfig

gptqe = GPTQE(GPTConfig(
    vocab_size=1000,  # Depends on operator pool size
    block_size=6,
    n_layer=12,
    n_head=12,
    n_embd=768,
    dropout=0.1
)).to("cuda")

# Example input: tokens and energy
tokens = torch.from_numpy(train_token_seq).to("cuda")
energies = torch.from_numpy(train_sub_seq_en).to("cuda")

# Forward pass
logits = gptqe(tokens)
loss = gptqe.calculate_loss(tokens, energies)
print(f"Loss: {loss.item()}")

Results

The GQE model predicts molecular energies with high accuracy, as shown by the following metrics:

  • Mean Absolute Error (MAE): Measures how close the predictions are to the true energy values.
  • Root Mean Squared Error (RMSE): Provides an average measure of the magnitude of the prediction error.
  • Mean Absolute Percentage Error (MAPE): Quantifies the error as a percentage of the true energy.

The results demonstrate that the model converges towards the ground-state energy of the molecule with minimal error.


Contributing

We welcome contributions to improve this project. Feel free to submit issues, create pull requests, or propose new features.


License

This project is licensed under the MIT License. See the LICENSE file for more details.


References

About

Quantum Generative Eigensolver for Molecular Energy Estimation

Resources

Stars

6 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages