unitaryfund / mitiq

Mitiq is an open source toolkit for implementing error mitigation techniques on most current intermediate-scale quantum computers.
https://mitiq.readthedocs.io
GNU General Public License v3.0
346 stars 145 forks source link

Support `observable=None` in Quantum Subspace Expansion (QSE) #1813

Open andreamari opened 1 year ago

andreamari commented 1 year ago

This is an optional improvement to QSE:

This is useful to apply QSE when the executor defined by the user returns an expectation value as float instead of bitstrings (MeasurementResult).

This is a sub-issue of #818

Useful links: Mitiq documentation: https://mitiq.readthedocs.io/en/stable/guide/qse.html Quantum Subspace Expansion paper: https://arxiv.org/pdf/1903.05786.pdf

FarLab commented 2 months ago

Regarding the adding observable=None in the QSE, I thought the approach would be as follows.

In this case, the executor returns a float (so it already returns some expectation value). In QSE, you solve a minimization problem for a projector $P_c = \sum_i c_i M_i$ where $M_i$ are check operators and $c_i$ are real numbers subject to some constraints. The QSE mitigated value is then $Tr(P_c \rho P_c^ O)$ where $O$ is some observable. Since the executor already returns the expectation value of $O$ given a state $\rho$, we have to modify the state (when observable is not None, you change the observable argument in the executor to $P_c^ O P_c$ as is done right now).

Write $\rho = \ket{\psi}\bra{\psi}$. Given the $c_i$ and $M_i$, we just compute the state $M_i\ket{\psi}$ and pass it to the executor that returns, say, $E_i$. We do this for each $i$ and the QSE mitigated value in this case would be $\sum_i c_i E_i$.

Does this make sense? @natestemen

FarLab commented 2 months ago

The above approach looks to be incorrect, because $Tr(P_c\rho Pc^\dagger O) = \sum{ij}c_ic_j^* Tr(M_i\rho M_j^\dagger O)$. So we need to compute for each $i,j$ the value $Tr(M_i\rho M_j^\dagger O)$.

FarLab commented 2 months ago

Hi @bubakazouba, I know you have worked on implementing QSE in Mitiq and so I am curious about what you think about the above approach and if it makes sense at all. As QSE is implemented right now, you compute the expectation value $\langle P_cOP_c\rangle$ by passing it to the executor. However, if the executor doesn't accept an observable (because it already computes one) you need to pass a modified state to it, namely $P_c\rho P_c^*$. Since we want to pass a quantum circuit to the executor, one has to write this as a sum of pure states: $P_c\rho P_c^\dagger = \sum_ip_i\ket{\psi_i}\bra{\psi_i}$. Once we have this expression, we pass the quantum circuits associated to $\ket{\psi_i}$ to the executor that returns the expectation value $Tr(\ket{\psi_i}\bra{\psi_i}O)$. The QSE mitigated value is then $\sum_i p_iTr(\ket{\psi_i}\bra{\psi_i}O)$.

I guess the hard part is obtaining the RHS of this expression $P_c\rho P_c^\dagger = \sum_ip_i\ket{\psi_i}\bra{\psi_i}$ in terms of the check operators $M_i$, $c_i$ and $\ket{\psi}$. Hope this makes sense.

bubakazouba commented 2 months ago

hi @FarLab, sorry for the late reply. I haven't worked on this in a while so I can't remember all details of the implementation. But the general idea you wrote here makes sense. I'm not sure how you would obtain the projected state in terms of the $M_i$ operators.

Death0004 commented 3 weeks ago

Based on this information, it seems like GSE resolves this issue and thus it might be easier to merge this feature request with the implementation of GSE...

Assuming that we want to compute the expectation value of some observable A, given by $Tr(P_c A P_c \rho) = Tr(A P_c \rho P_c)$, in the "power subspace" method of GSE we simply define the powers of a noisy state $\rho$ which eliminates the ambiguities surrounding what quantum state to pass. In GSE, the bases of the subspace are first restricted to powers of noisy quantum states $\rho^{(m)}$, and A is set to the identity matrix $I$.

According to the GSE paper, the most general subspace can then be implemented as

Screenshot 2024-06-15 at 00 46 04

where $β^{(i)}_k∈C$, and $U^{(i)}_k$, $V^{(i)}_k$ are general operators, and $\sigma_i$ is a basis element which spans the generalized subspace.

A basis element which spans the noisy subspace can then be constructed using these general operators, which can be used to construct the generalized subspace. The Ansatz for an error mitigated state is given in the form $\rho_{EM}$ by this equation:

Screenshot 2024-06-15 at 00 57 37

where $P=∑_i​α_i​σ_i$. To determine the coefficients $α_i$ we simply solve the generalized eigenvalue problem (just like in the current QSE implementation) and then compute the error-mitigated expectation value of any observable $O$ as:

$$⟨O⟩=∑_{ij}α^*_iα_jTr[σ^†_iAσ_jO]$$

Note how A is set to identity since the basis elements are powers of the noisy quantum state $\sigma_i = \rho^i$. This helps in exponentially suppressing stochastic errors and mitigating coherent errors, see paper for reference: https://arxiv.org/pdf/2107.02611

jordandsullivan commented 2 weeks ago

And for reference, we already have an issue opened for Generalized Subspace Expansion: https://github.com/unitaryfund/mitiq/issues/2377.

FarLab commented 1 week ago

Thanks @Death0004 for your comment. I need to read and and think in more detail about your approach, but I already have a few basic questions. 1) You mention that you set $A$ to the identity matrix in the expression $$\langle O \rangle = \sum_{ij}\alpha_i^\alpha_j Tr(\sigma_i^\dagger A\sigma_j O).$$ What does the matrix $A$ represent actually? 2) Assume $\rho = \ket{\psi}\bra{\psi}$ a pure state, then $\rho^i = \rho$ for any $i\geq 1$. If I understand correctly, assuming you know the constants $\alpha_i$ and setting $A=I$, we have $Tr(\sigma_i^\dagger A\sigmaj O) = Tr(\rho^{i \dagger} \rho^j O) = Tr(\rho O)$. This we can evaluate using an executor that returns a float/expectation value of $O$ given a pure state. But then the error-mitigated value is $\langle O \rangle = Tr(\rho O)\sum{ij}\alpha_i^\alpha_j$. Is this correct from your understanding of GSE?