# Quantum Bayesian Networks

## June 15, 2018

### Quantum Edward, models with complex-valued layers

Filed under: Uncategorized — rrtucci @ 4:31 am

The Quantum Edward Python lib (its github repo here), in its first version, comes with 2 models called NbTrolsModel and NoNbTrolsModel. However, the lib is written with enough generality so that you can also run it with other models of your own devising. A model describes a quantum circuit for a QNN (Quantum Neural Network) which is split into layers.

Below is an excerpt from the docstring for the QEdward class called NbTrolsModel. The excerpt gives the quantum circuit for the NbTrolsModel


...
Below we represent them in Qubiter ASCII
picture notation in ZL convention, for nb=3 and na=4
[--nb---]   [----na-----]
NbTrols (nb Controls) model:
|0> |0> |0> |0> |0> |0> |0>
NOTA P(x) next
|---|---|---|---|---|---Ry
|---|---|---|---|---Ry--%
|---|---|---|---Ry--%---%
|---|---|---Ry--%---%---%
NOTA P(y|x) next
|---|---Ry--%---%---%---%
|---Ry--%---%---%---%---%
Ry--%---%---%---%---%---%
M   M   M

A gate |---|---Ry--%---%---%---% is called an MP_Y Multiplexor,
or plexor for short. In Ref.1 (Qubiter repo at github), see Rosetta Stone


If you look up the definition of a multiplexor in the Qubiter repo and references therein, you will notice that a multiplexor is a real-valued gate. Hence this model, since it only uses multiplexor gates, does not parametrize the full family of complex-valued amplitudes that are allowed in quantum mechanics. The NbTrolsModel does parametrize the whole family of possible (real-valued) probability distributions P(y|x) and P(x), where $x = (q3, q2, q1, q0)$ and $y = (q6, q5, q4)$, where $qi$ is an element of 0, 1 for i=0,1,2,…6

So how can we generalize the model NbTrolsModel so that it parametrizes all possible complex-valued amplitudes too. One possibility is as follows. (call it the C_NbTrolsModel)


|0> |0> |0> |0> |0> |0> |0>
NOTA A(x) next
|---|---|---|---|---|---Ry
|---|---|---|---|---|---%
|---|---|---|---|---Ry--%
|---|---|---|---|---%---%
|---|---|---|---Ry--%---%
|---|---|---|---%---%---%
|---|---|---Ry--%---%---%
|---|---|---%---%---%---%
NOTA A(y|x) next
|---|---Ry--%---%---%---%
|---|---%---%---%---%---%
|---Ry--%---%---%---%---%
|---%---%---%---%---%---%
Ry--%---%---%---%---%---%
%---%---%---%---%---%---%
M   M   M


This new model contains twice as many layers as the old one. Each multiplexor gate from the old model has been followed by a “diagonal unitary” gate consisting of only % or | symbols, for instance,

|---|---|---%---%---%---%
 

. You can look up the definition of such a gate in the Qubiter repo, in the same places where you found the def of a multiplexor. In this example, D =

 %---%---%---%

represents a 2^4=16 dimensional diagonal unitary matrix and $I_8$ =

 |---|---|

represents the 2^3=8 dimensional unit matrix. The whole gate is $I_8 \otimes D$, which is a 2^7=128 diagonal unitary matrix.

To motivate what is going on in this C_NbTrolsModel model, let me claim without proof that the first two lines of the circuit parametrize a complex amplitude $A(q0)$, the next two lines $A(q1|q0)$, the next two $A(q2|q1, q0)$ and so forth.

If $x = (q3, q2, q1, q0)$ and $y = (q6, q5, q4)$, then

$A(x) = A(q3|q2, q1, q0)A(q2|q1, q0)A(q1|q0)A(q0)$

$A(y|x) = A(q6|q5, q4)A(q5|q4)A(q4)$

$A(y, x) = A(y| x) A(x)$.

This is just a generalization of the chain rule for probabilities which for 3 random variables is

$P(c, b, a) = P(c|b, a) P(b | a) P(a)$

To go from the chain rule for probabilities to the chain rule for amplitudes, we just take the square root of all the probabilities and add a bunch of relative phase factors, leading to

$A(c, b, a) = A(c|b, a) A(b | a) A(a)$

Warning: Note that the expansion of a multiplexor (and of a diagonal unitary) into elementary gates (cnots and single qubit rotations) contains a huge number of gates (exp in the number of controls). However, such expansions can be shortened by approximating the multiplexor (or the diagonal unitary) using, for instance, the technique of Ref.2: Oracular Approximation of Quantum Multiplexors and Diagonal Unitary Matrices, by Robert R. Tucci, https://arxiv.org/abs/0901.3851 Another possible source of simplification: just like

$P(c, b, a) = P(c|b, a) P(b | a) P(a)$

represents a fully connected graph which simplifies to

$P(c, b, a) = P(c| a) P(b | a) P(a)$

if c is independent of b, in the same way, the chain rule in these QdEdward models might simplify due to certain conditional independences in the data.

Added July 11, 2018: Of course, this can all be generalized by making q0 a qudit with d0 states, q1 a qudit with d1 states, etc. Qudit q0 can be represented by n0 qubits, where n0 is the smallest int such that d0 ≤ 2^n0, same for qudit q1, q2, etc.

In Qubiter, the Quantum CSD Compiler decomposes an arbitrary unitary matrix into a product of multiplexors and diagonal unitaries. Qubiter also allows you to decompose multiplexors and diagonal unitaries into elementary ops (CNOTs and single qubit rotations). For example, Qubiter's CSD compiler will expand an arbitrary 3 qubit unitary matrix into the following:


%---%---%
%---%---Ry
%---%---%
%---Ry--%
%---%---%
%---%---Ry
%---%---%
Ry--%---%
%---%---%
%---%---Ry
%---%---%
%---Ry--%
%---%---%
%---%---Ry
%---%---%


Hence, a QNN is like a portion of the expansion of an arbitrary unitary matrix.

When one uses complex-valued layers, the definition of ELBO must be in terms of density matrices, not classical prob distributions.