Skip to main content

A quantum-based approach to the distribution unfolding problem

Project description

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).

:warning: 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:

:warning: 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qunfold-0.3.5.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

QUnfold-0.3.5-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file qunfold-0.3.5.tar.gz.

File metadata

  • Download URL: qunfold-0.3.5.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for qunfold-0.3.5.tar.gz
Algorithm Hash digest
SHA256 19cf8d06b861a55dca0851fff1aa3d13859a43ba875e3a440d8f71a759128df1
MD5 477d5a20b27bb8f8f3b258e4083a22e7
BLAKE2b-256 55922c78bf3f8218336fa7b7974105007519c692d869f5ffa6ec4f1710e701ce

See more details on using hashes here.

File details

Details for the file QUnfold-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: QUnfold-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for QUnfold-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 25c7d07b283eda5a0b7f3ea82ec96ee59e21e1c3d8ba641a7124b21d69be7486
MD5 5702cbe89cbd3ecc765469e9ffb8530f
BLAKE2b-256 69ccd9ba6429a24014dd7d6a6b45d952d04c3578018be55bd7d61d7a6c2411b0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page