Improving sources of sustainable energy is a worldwide problem with environmental and economic security implications. Ying-Yi Hong, distinguished professor of Power Systems and Energy at Chung Yuan Christian University in Taiwan, researches hybrid quantum-classical methods. These approaches leverage quantum computing to solve challenging problems in power systems and sustainable energy.

Solar irradiance prediction is a key focus of Professor Hong’s research group. The goal is to use geographical and historical data to forecast the power generation of photovoltaic farms, enabling power utilities to optimally schedule traditional fossil fuel-based power generation.

Professor Hong and his student, Dylan Lopez have used the NVIDIA CUDA-Q platform to predict solar irradiance through calculations run by hybrid quantum neural networks (HQNNs). This work was recently published in the paper, Solar Irradiance Forecasting Using a Hybrid Quantum Neural Network: A Comparison on GPU-Based Workflow Development Platforms.

This work on HQNN made use of CUDA-Q interoperability with the NVIDIA cuDNN library to achieve a 2.7x model training speedup and a 3.4x reduction in test set error compared to other leading quantum simulators.

## What is a hybrid quantum neural network?

Classical neural networks (NNs) are trainable machine learning (ML) models built from layers of mathematical operations that resemble the connectivity of neurons in the brain. Each layer is made up of neurons which are connected to neurons in adjacent layers through trainable weights. A standard NN consists of an input layer to receive the raw data, hidden layers that apply various transformations, and an output layer that produces a final prediction.

An NN is an ML model trained with a data set to find the optimal parameters that minimize a cost function. The trained model can then make predictions based on new data in a process known as inference. NNs have proved remarkably capable when modeling complex systems.

An HQNN shares the same objective, but instead replaces one or more layers of the traditional NN with a parameterized *quantum* circuit within a so-called “quantum layer.” A quantum layer consists of a few important sublayers (Figure 1).

First, the input data is encoded into the quantum circuit with an encoding layer. Then, a set of parameterized single qubit gates act on each qubit. The structure of these gates is generally called an ansatz. Next, an entangling layer is applied with a cascade of controlled NOT (CNOT) gates. Finally, a quantum circuit is measured and the measurement results are either used to compute a cost function or are fed forward as inputs to another layer.

HQNNs are a promising approach because the unique properties of quantum entanglement allow the opportunity for a more expressive model that can capture complex patterns with fewer trainable parameters. However, many challenges remain, particularly regarding the best way to encode classical data into a quantum circuit.

## A CUDA-Q HQNN for solar irradiance

HQNNs require CPUs, GPUs, and QPUs all working in concert (Figure 2). Data preprocessing takes place on a traditional CPU, GPUs run the classical layers of the HQNN, and the QPU runs the circuits that compose the quantum layers. Professor Hong and Dylan used the CUDA-Q development platform to construct and train an HQNN with data from the National Solar Radiation Database including a multitude of weather related features from across Taiwan.

Figure 2 shows a typical HQNN workflow. Most of the workflow is accelerated with CUDA and additional acceleration is realized using the cuDNN and cuQuantum libraries.

A classical NN was implemented in PyTorch, with the NN layers designed using Bayesian optimization as described in the Methodology section of the paper. The resulting architecture served as the classical component of an HQNN, where a final dense layer was replaced with a quantum layer (Figure 3).

Working together, NVIDIA CUDA-Q, CUDA, and cuDNN tools were able to accelerate the whole workflow in this HQNN. CUDA-Q ensures acceleration of both the quantum and classical layers in the network, enabling quantum and classical resources to work together seamlessly. The PyTorch training is automatically accelerated with CUDA.

Two NVIDIA libraries provide even further acceleration for specific tasks. cuDNN ensures highly efficient NN operations like convolution, while in cases where the quantum layers are simulated (rather than running on actual quantum hardware), cuQuantum accelerates all quantum circuit simulations.

## CUDA-Q improves HQNN speed and accuracy

Professor Hong and Dylan trained their HQNN model to predict solar irradiance for all four seasons of the year using two NVIDIA RTX 3070 GPUs. They compared their results to a classical baseline and benchmarked the impact of different simulators and methods of accelerating the classical NN part of the hybrid workflow. The data suggests the importance of using GPU acceleration *and* CUDA-Q to realize the greatest performance gains.

The utility of the GPU is made clear for simulating both the quantum and the classical parts of an HQNN. Regardless of the simulator, GPU-accelerated quantum circuit simulations lowered the epoch latency (time for each training step) by at least 3x. The classical NN steps could also be accelerated with CUDA or CUDA plus cuDNN (Figure 4, left).

CUDA-Q is uniquely optimized to take advantage of the GPU better than any other simulator. Compared to other leading GPU simulators, when CUDA and cuDNN accelerated the classical NN steps, CUDA-Q was 2.7x faster (Figure 4, left) and trained a model that was 3.4x more accurate (Figure 4, right) in terms of the test set RMSE.

Professor Hong and Dylan were able to successfully predict the seasonal solar irradiance in Taiwan with competitive accuracy to classical approaches. Professor Hong noted that the outcomes of this study indicate that “CUDA-Q provides a great means to stage hybrid quantum operations for energy research during the NISQ-era and beyond. Accelerating both the classical and quantum tasks allows us to explore best-case and worst-case solutions for integrating HPCs and quantum computers in solution pipelines.”

## Get started with CUDA-Q

CUDA-Q is a platform for hybrid quantum-classical computing, not just a quantum simulator. CUDA-Q orchestrates all aspects of a hybrid CPU, GPU, and QPU workflow enabling acceleration of the quantum and classical components of the HQNN presented in this work. Code developed on the CUDA-Q platform has longevity and is designed to seamlessly scale as accelerated quantum computers scale to solve practical problems.

To get started with CUDA-Q, check out the following resources:

- Quickly set up your environment with the CUDA-Q Quick Start guide.
- Write your first CUDA-Q application using CUDA-Q Basics.
- Learn more with the CUDA-Q HQNN Tutorial.
- Get inspiration for your own quantum application development with CUDA-Q By Example and CUDA-Q Tutorials.
- Visit the NVIDIA/cuda-quantum GitHub repo to provide feedback and suggestions.