Skip to content

Quantum Annealing for distribution unfolding in experimental High-Energy Physics

License

Notifications You must be signed in to change notification settings

Quantum4HEP/QUnfold

Repository files navigation

logo

DOI docs
version license python

Table of contents

Introduction

This package provides a quantum-based approach to the statistical unfolding problem in High-Energy Physics (HEP). The technique is based on the reformulation of this task as a Quadratic Unconstrained Binary Optimization (QUBO) problem to be solved by Quantum Annealing (QA) on D-Wave quantum devices.

The code is written in Python and relies on numpy arrays as basic data structures. However, the package also includes simple tools to convert ROOT data to numpy, allowing HEP scientists to run the algorithms for their specific use-cases with a minimal effort. The software is designed leveraging the powerful D-Wave Ocean SDK, which provides several tools to define the QUBO model and run widely-used heuristics for classical computers (e.g. Simulated Annealing) as well as hybrid/quantum solvers running on real QA D-Wave Systems.

The idea for this project was inspired by the work done by K. Cormier, R. Di Sipio, and P. Wittek in 2019 (see here for the links to an oral presentation and the published paper).

⚠️ For a comprehensive introduction to the classical problem, see Chapter 11 of the book Statistical Data Analysis by G. Cowan.

Documentation

(work in progress...)

Read the Docs: API documentation for all the available features of the package.

Installation

User-mode

To install the QUnfold latest version released on PyPI in user-mode you can do:

pip install QUnfold

If you also want to enable the classical Gurobi solver both for the integer optimization problem and the QUBO problem, you need to install QUnfold including this additional requirement:

pip install QUnfold[gurobi]

Dev-mode

To create a dedicated conda environment and install QUnfold in developer-mode you can do:

conda create --name qunfold-dev python==3.10.14
conda activate qunfold-dev
git clone https://github.com/Quantum4HEP/QUnfold.git
cd QUnfold
pip install --upgrade -r requirements-dev.txt
pip install -e .[gurobi]

Docker container

Two different Docker images are ready to be downloaded from DockerHub to start playing with a containerized version of QUnfold:

  • qunfold: minimal working version for testing basic functionalities
  • qunfold-dev: full version based on the conda distribution for Python, including the installation of ROOT framework and RooUnfold library for expert users in High-Energy Physics

Both the containerized solutions offer the possibility to use QUnfold running a JupyterLab web-based environment on your favourite browser. First, run the Docker container with the porting option as follows:

docker run -itp 8888:8888 qunfold

Secondly, once the container has started, launch jupyter-lab with the following command:

jupyter-lab --ip=0.0.0.0

Usage example

Here is a minimal example showing how to use QUnfold. The code snippet shows how to create an instance of the unfolder class, initialize the QUBO model, and run the simulated annealing algorithm to solve the problem.

from qunfold import QUnfolder

# Define your input response matrix and measured histogram as numpy arrays
response = ...
measured = ...
binning = ...

# Create the QUnfolder object and initialize the QUBO model
unfolder = QUnfolder(response, measured, binning, lam=0.1)
unfolder.initialize_qubo_model()

# Run one of the available solvers to get the unfolding result
sol, cov = unfolder.solve_simulated_annealing(num_reads=100)

The figures show a specific example of a given response matrix as well as the correponding histograms for the case of a gamma distribution with Gaussian smearing.

If you are working in High-Energy Physics, your response matrix might be a RooUnfoldResponse object and your measured histogram is probably stored in a ROOT.TH1. The qunfold.root2numpy module provides some simple functions to convert these objects to standard numpy arrays:

from qunfold.root2numpy import TH1_to_numpy, TH2_to_numpy

# Convert ROOT.TH1 measured histogram to numpy array
measured = TH1_to_numpy(measured)

# Convert RooUnfoldResponse object to numpy array
response = TH2_to_numpy(response.Hresponse())

For a complete example on how to run the QUnfold solvers and plot the final results, you can take a look at the examples directory in the repository.

Unfolding studies

This section contains instructions to solve the unfolding problem by classical methods (widely used in HEP data analysis) as well as the QUnfold quantum-based method. It also provides several tools and examples to compare the results of the two different approaches.

HEP dependencies

To run the classical unfolding algorithms you need to install the ROOT framework developed by CERN (see documentation here) and the specialized RooUnfold library (see documentation here). On Linux or Mac OS this can be done automatically by running the following script in the root directory of the repository:

./install_roounfold.sh

This step can be ignored if you are using the qunfold-dev Docker container since the corresponding Docker image already includes the required HEP software.

Performance analysis

The code available in the studies directory can be used to generate syntetic data samples according to common HEP probability density functions (normal, gamma, exponential, Breit-Wigner, double-peaked) and apply a smearing to roughly simulate the distortion effects due to limited efficiency, acceptance, and space/time resolution of a given detector.

Then, unfolding is performed by several classical, hybrid, and quantum techniques and the results are studied to compare the performance of the different methods. In particular, the algorithms currently available are the following:

  • RooUnfold framework:
    • Matrix Inversion unfolding (MI)
    • Bin-by-Bin unfolding (B2B)
    • Iterative Bayesian Unfolding (IBU)
    • Tikhonov regularized unfolding (SVD)
  • QUnfold library:

⚠️ The HYB and QA solvers require access to a real D-Wave quantum annealer (1 min/month available for free via the D-Wave Leap cloud platform) while the Gurobi solvers (Python API) require a software license (freely available for 18 months).


Main developers


Gianluca Bianco

Simone Gasperini

Other contributors


Marco Lorusso