# I am optimising a variational quantum circuit to learn a distribution $p(x)$, but it doesn't converge over a training set $\mathcal{X}$?

I am training a variational quantum circuit to learn distributions: given data $$s(\vec{\lambda})$$, what is the probability distribution for the parameterisation $$\vec{\lambda}$$, i.e. the posterior distribution $$p(\vec{\lambda}|s)$$? I attempt to do this by discretising the parameters into $$2^N$$ bins to give it a qubit representation. For example, if a parameter ranges from 0 to 3, then we use the mapping $$|00\rangle\to0,|01\rangle\to1,|10\rangle\to2,|11\rangle\to3$$. A state $$\frac{1}{\sqrt{2}}(|00\rangle+e^{i\phi}|01\rangle)$$ would be $$0.5$$ (with uncertainty spread).

I then feed a training set $$\mathcal{X}=\{\lambda^i,s^i\}$$ to the circuit. I know that if I feed $$s^i$$ into the circuit, I should find $$|\lambda^i\rangle$$, so I aim to maximise $$|\langle\lambda^i|\psi_s\rangle|^2$$, where $$|\psi_s\rangle$$ is the quantum state that the variational quantum circuit outputs. I let the system optimise over the entire training set, so I minimise $$-\sum_{i\in\mathcal{X}}|\langle\lambda^i|\psi_s\rangle|^2$$.

However, it never optimises fully. The data is slightly noise which means we will find some spread in our final results. But I find that the optimiser never comes remotely close to finding the true minimum, and therefore inference over new data always gives nonsense. Is my qubit mapping wrong perhaps, where the discretisation I employ is an awkward mapping? Is the loss function bad? Thoughts would be appreciated.

• I don't understand your problem setup - could you give an example of what $s(\lambda)$ and $p(\lambda|s)$ and some training data would look like for your problem? Jan 5, 2023 at 20:15
• Sure! A simple example would be to look at linear regression. Suppose your training data consists of parameters $a'$: the inferred slopes of linear data, with corresponding $s(x) = ax + n(x)$, where $n(x)$ is some noise realisation that is stationary and Gaussian, with a constant standard deviation. Because of the noise, the slope of $s(x)$ is not necessarily found to be $a$, but deviates slightly. The posterior distribution then tells you how likely it is to find a certain slope. In the case of $n(x)=0$, the posterior is a sharp $\delta$ peak. In the case of $n(x)\neq 0$, there is spread.
– JoJo
Jan 5, 2023 at 21:53
• That's not a good mapping, it's not even linear... One of the main points of quantum computers is that you get $2^N$ possible bitstrings for $N$ qubits, so why would you map 0.5 to a weird state like that? Map every data point to a single bitstring. I don't really understand your problem setup either, what we mean by explaining your problem setup is what do you mean by "I feed in $s_i$"? Give an example of what state is inputted into the computer and what do you expect to come out? Your response above just explains what linear regression is which is irrelevant here. Jan 5, 2023 at 23:40
• That's because my discretisation example was weak. In practice you wouldn't have 4 bins, but something more akin to 100s, having a more coarse-grained representation of the parameterisation. What I mean by 'feeding in $s$' is injecting the data into the quantum circuit. Every unique data $s$ should give rise to a unique circuit $U(\theta|s)$ and a unique posterior $p(\lambda|s)$. There's plenty of ways to do this such as phase encoding, but eventually I'm looking to employ this algorithm for classical data, so the input problem might become an issue. Linear regression is just a toy example.
– JoJo
Jan 6, 2023 at 10:28
• To answer your last question, let us cut back to the very rough discretisation of 2 qubits. If I were to generate fake training data for $s(x) = x + n(x)$, I would expect that the slope is 1, so the output should be $|\lambda\rangle=|01\rangle$ for $s=1$. For $s(x) = 2x + n(x)$, we'd expect $|\lambda\rangle=|10\rangle$ for $s=2$. The loss function reflects this. Again, this seems trivial, but for more complex systems that are parameterised by multiple parameters, this becomes non-trivial. (Also, the way to encode $s$ into the circuit becomes non-trivial, still don't know how to fix this.)
– JoJo
Jan 6, 2023 at 10:35