Skip to content

QuantumApplicationLab/wntr-quantum

Repository files navigation

Platform Python License Code style: Black Tests Coverage Status

wntr_quantum

wntr_quantum builds on the python package WNTR to leverage quantum computing for the simulation and optimization of water networks. The main capablities of the software are:

1. Quantum Enhanced Newton-Raphson Algorithm

The QuantumEpanetSimulator of wntr_quantum use quantum solvers to solve the linear systems required as part of the Newon-Raphson GGA algorithm. Several quantum linear solvers are available:

  • Harrow–Hassidim–Lloyd (HHL) : Gate based quantum solution. See example for Net0
  • Variational Quantum Linear Solver (VQLS) : hybrid quantum-classical gate based solution. See example for Net0 and on Net2loops
  • QUBO Linear Solver (QUBOLS) : Quantum Annealing solution. See example for Net0 and on Net2loops

2. Quantum Hydraulics Simulations

The FullQuboPolynomialSimulator recast the hydraulics equation as a Quadratic Unconstrained Binary Optimization (QUBO) problem, that can be solved using quantum annealers. An example of use on Net0can be found here

3. Quantum Optimization of Water Networks

The QUBODesignPipeDiameter recast the hydraulics equation and the pipe-diameter optimization as a Quadratic Unconstrained Binary Optimization problem, that can be solved using quantum annealers. An example of use on Net0can be found here

Installation

To install wntr_quantum from GitHub repository, do:

git clone [email protected]:QuantumApplicationLab/wntr-quantum.git
cd wntr-quantum
python -m pip install .

Installation of EPANET Quantum

WNTR Quantum can use a dedicated EPANET solver that allows to offload calculation to quantum linear solvers. This custom EPANET code can be found at : https://github.com/QuantumApplicationLab/EPANET. To install this sover follow the instructions below:

# clone EPANET
git clone https://github.com/QuantumApplicationLab/EPANET

# build EPANET
cd EPANET
mkdir build
cd build 
cmake .. 
cmake --build . --config Release

# copy the shared lib
cp lib/libepanet2.so <path to wntr-quantum>/wntr-quantum/wntr_quantum/epanet/Linux/libepanet22_amd64.so

# export environment variable
export EPANET_TMP=<path to tmp dir>/.epanet_quantum 
export EPANET_QUANTUM = <path to EPANET_QUANTUM>

Example

The example below shows how to use the Variational Quantum Linear Solver to solve the linear systems required in the Newton-Raphson-GGA algorithm.

import wntr
import wntr_quantum
from qiskit.circuit.library import RealAmplitudes
from qiskit.primitives import Estimator
from qiskit_algorithms import optimizers as opt
from quantum_newton_raphson.vqls_solver import VQLS_SOLVER

# define the water network 
inp_file = 'Net2Loops.inp'
wn = wntr.network.WaterNetworkModel(inp_file)

# define the vqls ansatz
n_qubits = 3
qc = RealAmplitudes(n_qubits, reps=3, entanglement="full")
estimator = Estimator()

# define the VQLS solver
linear_solver = VQLS_SOLVER(
    estimator=estimator,
    ansatz=qc,
    optimizer=[opt.COBYLA(maxiter=1000, disp=True), opt.CG(maxiter=500, disp=True)],
    matrix_decomposition="symmetric",
    verbose=True,
    preconditioner="diagonal_scaling",
    reorder=True,
)

# use wntr-quantum to solve the network
sim = wntr_quantum.sim.QuantumEpanetSimulator(wn, linear_solver=linear_solver)
results_vqls = sim.run_sim(linear_solver=linear_solver)

Contributing

If you want to contribute to the development of wntr_quantum, have a look at the contribution guidelines.

Credits

This package was created with Cookiecutter and the NLeSC/python-template.

About

A quantum enabled water network tool

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •