⟨QonFusion⟩ Quantum Circuits for Gaussian Random Variables: A Dual-Application Framework for Stable Diffusion and Diffusion Monte Carlo.

JHU


"Quantum Gaussian Number Generation"

Quantum Gaussian Generator.

An illustrative depiction of our proposed pipeline.

1 Utilizing N qubits, an initial non-parametric quantum circuit, founded on Hadamard transformations, engenders a uniform distribution across 2^N discrete values through sampled measurement outcomes, rather than expectation values. These outcomes are subsequently transmuted into equidistant angles, which are then channeled into a static quantum circuit that neither adapts nor learns, with the purpose of inducing stochastic rotations. 2 This static assembly, encompassing M>N qubits, functions as follows: a Hadamard gate is applied to each qubit, thus creating a superposition of states. Upon activation of the \texttt{useRot} flag, the circuit administers a rotation to every qubit, utilizing the \textbf{previously generated angles as the parameters for these rotations}. The output 3 from this circuit is then employed in the 4 Marsaglia polar method to transmute the uniform distribution into a zero-mean Gaussian 5. This transformation is achieved through the equation \(\mathbf{Z = \sqrt{-2\log U}\cos(2\pi V)}\), where U and V are two uniform random numbers, and by substituting our quantumly-generated uniform random bits for $U$ and $V$, we synthesize a source of quantum Gaussian random variables. 6 The Marsaglia polar method serves as a paradigmatic example of how quantum random bits can seamlessly supplant classical pseudo-random numbers in a Stable Diffusion (SD) model pipeline, specifically in the forward diffusion phase .

Abstract

In this investigation, we introduce a method based on non-parametric quantum circuits for generating Gaussian Random Variables (GRVs). This quantum-based methodology serves as an analogue to classical pseudorandom number generators (PRNGs), such as those implemented in PyTorch's \textbf{torch.rand}. Importantly, our quantum Gaussian generator holds dual functionality: it offers a new avenue for simulating Stable Diffusion (SD) as well as Diffusion Monte Carlo (DMC) techniques. Our approach stands in contrast to existing methods that employ parametric quantum circuits, often in conjunction with variational quantum eigensolvers. These prevalent methods, while effective for approximating the ground states of complex systems or learning intricate probability distributions, necessitate a cumbersome and computationally demanding parameter optimization phase. Our non-parametric approach eliminates this requirement. To facilitate the integration of our methodology into existing computational frameworks, we unveil a Python library, QonFusion.
Quantum Gaussian Generator.


This library is designed for seamless compatibility with both PyTorch and PennyLane, serving as a nexus between classical and quantum computing paradigms. We validate the efficacy of QonFusion through a comprehensive suite of statistical tests, including Kolmogorov-Smirnov, Kullback-Leibler, Maximum Mean Discrepancy, and statistical permutation tests. These assessments affirm that the Gaussian samples generated via our quantum approach are statistically indistinguishable from their classical counterparts within established significance thresholds.

Generating uniform and Gaussian distributions.

Initially, we employ \( N \) qubits in a non-parametric quantum circuit to produce a uniform distribution over \( 2^N \) discrete outcomes: PennyLane quantum circuit
The following animation illustrates the process. Each qubit randomly generates an angle, no entanglement is involved: PennyLane quantum circuit
The resultant uniform PDF output is transformed into quantum rotations: PennyLane quantum circuit
These are fed into the next quantum circuit:
PennyLane quantum circuit
The mathematical representation of this 3-qubit quantum system undergoing a Hadamard transformation followed by rotations can be formulated as follows:

  1. Initial State: The initial state of the three qubits is prepared by another quantum circuit consisting solely of Hadamard gates. Mathematically, this is represented as:
    \[ |\psi_{\text{initial}}\rangle = (H \otimes H \otimes H) |0\rangle^{\otimes 3}. \]
  2. Total Operation: The total unitary operation acting on the initial state consists of Hadamard gates followed by general rotations on each qubit. This is given by:
    \[ U_{\text{total}} = (U(\theta_1, \phi_1, \lambda_1) \otimes U(\theta_2, \phi_2, \lambda_2) \otimes U(\theta_3, \phi_3, \lambda_3)) \cdot (H \otimes H \otimes H) \cdot (H \otimes H \otimes H). \]
  3. Final State: The final state of the system is then:
    \[ |\psi_{\text{final}}\rangle = U_{\text{total}} |\psi_{\text{initial}}\rangle. \]

Let's consider a numerical example for the system. We'll use the following rotation angles for each qubit:

  • \( \theta_1 = \frac{\pi}{4} \), \( \phi_1 = \frac{\pi}{2} \), \( \lambda_1 = \pi \)
  • \( \theta_2 = \frac{\pi}{3} \), \( \phi_2 = \frac{\pi}{4} \), \( \lambda_2 = \frac{\pi}{2} \)
  • \( \theta_3 = \frac{\pi}{6} \), \( \phi_3 = \frac{\pi}{3} \), \( \lambda_3 = \frac{\pi}{4} \)

The Hadamard gate \( H \) is represented as:

\[ H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \]

And a general rotation \( U(\theta, \phi, \lambda) \) is given by:

\[ U(\theta, \phi, \lambda) = \begin{pmatrix} \cos(\frac{\theta}{2}) & -e^{i \lambda} \sin(\frac{\theta}{2}) \\ e^{i \phi} \sin(\frac{\theta}{2}) & e^{i (\phi + \lambda)} \cos(\frac{\theta}{2}) \end{pmatrix} \]

First, we'll find the initial state \( |\psi_{\text{initial}}\rangle \) after applying the Hadamard gates:

\[ |\psi_{\text{initial}}\rangle = (H \otimes H \otimes H) |0\rangle^{\otimes 3} = \frac{1}{\sqrt{8}}(|000\rangle + |001\rangle + |010\rangle + |011\rangle + |100\rangle + |101\rangle + |110\rangle + |111\rangle) \]

Next, we'll find the unitary operation \( U_{\text{total}} \) for the Hadamard and rotation gates:

\[ U_{\text{total}} = (U(\theta_1, \phi_1, \lambda_1) \otimes U(\theta_2, \phi_2, \lambda_2) \otimes U(\theta_3, \phi_3, \lambda_3)) \cdot (H \otimes H \otimes H) \]

Finally, we'll find the final state \( |\psi_{\text{final}}\rangle \):

\[ |\psi_{\text{final}}\rangle = U_{\text{total}} |\psi_{\text{initial}}\rangle \]

Calculating \( |\psi_{\text{final}}\rangle \) would involve the PannyLane library.

Here we provide the respective code snippet for the second circuit:
def Q_PQC_UNIFORM_DIST_ANZATS(weights, useRot=True): for i in range(n_qubits): qml.Hadamard(wires=i) if useRot: qml.Rot(weights[0], weights[1], weights[2], wires=0) qml.Rot(weights[3], weights[4], weights[5], wires=1) qml.Rot(weights[6], weights[7], weights[8], wires=2) _expectations = [qml.sample(qml.PauliZ(i)) for i in range(n_qubits)] return _expectations

Our focus is on sampling techniques. The key difference between the expressions \texttt{[qml.sample(qml.PauliZ(i)) for i in range(n\_qubits)]} and \texttt{[qml.expval(qml.PauliZ(i)) for i in range(n\_qubits)]} lies in the type of result they produce. The former yields a sampled measurement outcome, whereas the latter returns the expectation value. Specifically, \texttt{qml.sample()} performs a measurement on the qubit in the Pauli-Z basis, leading to the collapse of the wavefunction and randomly returning either 0 or 1, based on the inherent probabilities of the qubit state. Conversely, \texttt{qml.expval()} calculates the expectation value \( \langle Z \rangle \) of the Pauli-Z operator on the qubit, providing the average value one would expect to measure, without causing the wavefunction to collapse. In summary, \texttt{qml.sample()} gives a random measurement sample (0 or 1), while \texttt{qml.expval()} delivers the expected average value of a measurement (a value between 0 and 1). Sampling leads to the collapse of the quantum state, whereas expectation values allow for continued quantum operations.

See: QonFusion source code.

Statistical tests

The quality of the quantum Gaussian distribution is validated using statistical tests [1], [2], [3] such as the Kolmogorov-Smirnov test as depicted in the table below.

The quantum random Gaussian generator was scrutinized via an array of statistical tests, comparing the quantum generated samples to classical Gaussian samples. The results of the Kolmogorov-Smirnov (KS) test revealed a statistic of \( S = 0.052 \) and a \( p \)-value of \( p = 0.124 \). The null hypothesis, proposing that the quantum and classical samples originated from the same continuous distribution, could not be dismissed given the \( p \)-value surpassing the conventional threshold of \( 0.05 \). This implies that the quantum samples exhibit no significant deviation from the classical Gaussian samples. The Maximum Mean Discrepancy (MMD), a metric quantifying the difference between the mean embeddings of two distributions in a Reproducing Kernel Hilbert Space (RKHS), registered a value of \( MMD = 0.001 \). This low MMD value suggests a negligible difference between the quantum and classical Gaussian distributions' mean embeddings in the RKHS, thereby indicating a close match between the two distributions. The Kullback-Leibler (KL) divergence, assessing the quantum distribution's divergence from the classical Gaussian distribution, yielded a value of \( D_{KL} = 0.030 \). This relatively small KL divergence value signifies that the quantum distribution does not significantly diverge from the classical Gaussian distribution. These findings are in line with the results from the KS test and MMD, further underscoring the similarity between the quantum and classical Gaussian distributions.
Test Value
KS Statistic 0.052
KS P-Value 0.124
MMD 0.001
KL Divergence 0.030


Quantum Gaussian Generator.
Moreover, presented herein is a depiction of the application of our Quantum Gaussian generator in simulating Brownian motion. This serves as a quality assessment of our Quantum Random Number Generator (QRNG). In typical Brownian motion, if the mean of the Gaussian distribution deviates from zero, the resultant motion ceases to resemble true Brownian behavior. In contrast, our QRNG successfully captures the essence of Brownian motion.

Quantum Gaussian Generator.

BibTeX

@misc{sk2023qdiffusion,
    title={Quantum Circuits for Gaussian Random Number Generation:
                            A Non-parametric Approach to the Stable Diffusion Noise Corrupter.},
    author={Shlomo Kashani},
    year={2023},
    eprint={},
    archivePrefix={arXiv},
    primaryClass={}
}