QuantumVariationalEigensolverGradFree¶
-
class
zyglrox.models.qve.
QuantumVariationalEigensolverGradFree
(hamiltonian: zyglrox.core.hamiltonians.Hamiltonian, qc: zyglrox.core.circuit.QuantumCircuit, exact=False, optimizer: str = None, **params)¶ Quantum Variational Eigensolver according to Peruzzo et al. (2014) using only gradient free optimizers.
We take a quantum circuit with parameters \(\theta\) which implements some unitary transformation \(\mathcal{U}(\theta)\). This unitary brings our initial state \(|0\rangle\) to a state \(|\psi(\theta)\rangle\).
\[\mathcal{U}(\theta)|0\rangle = |\psi(\theta)\rangle\]Then, we realize that any Hamiltonian \(H\) can be written as a polynomial of single qubit interactions.
\[H = \sum_{i\alpha} h_\alpha^i \sigma_i^\alpha + \sum_{ij\alpha\beta} w_{\alpha\beta}^{ij} \sigma_{i}^{\alpha}\sigma_{j}^{\beta} + \ldots\]where \(i,j,\ldots=1,\ldots,N\) indicate the qubit and \(\alpha,\beta,\ldots=x,y,z\) indicates the Pauli operator. By measuring the expectation values of the quantum circuit, we obtain a variational energy which is a lower bound on the true energy \(\langle H \rangle = \langle \psi| H |\psi \rangle\).
\[\langle H \rangle \approx \langle H \rangle_{\theta^t} = \sum_{i\alpha} h_\alpha^i \langle\sigma_i^\alpha\rangle + \sum_{ij\alpha\beta} w_{\alpha\beta}^{ij} \langle \sigma_{i}^{\alpha} \sigma_{j}^{\beta}\rangle + \ldots\]By minimizing this variational energy, we hope to learn a quantum circuit which best represents the groundstate of \(H\). If this minimization is successful, we can easily sample the ground state.
In the derivative-free method, we need only function evaluations at a point \(\theta^t\). In the case of the QVE this function is simply the expected energy under the variational circuit ansatz:
\[f(\theta^t) = \langle H \rangle_{\theta^t} = \langle 0 | \mathcal{U}^\dagger(\theta^t) H \mathcal{U}(\theta^t)|0\rangle\]- Args:
- hamiltonian (list):
List of numpy arrays containing the operators and their locations. See
verify_hamiltonian()
for the required format.- qc (QuantumCircuit):
QuantumCircuit
object containing a quantum circuit architecture.- exact (bool):
Boolean indicating whether we want to calculate the exact ground state and eigenvectors of the Hamiltonian. Will throw an error if the number of qubits is larger than 18.
- device (string):
Device of choice for running tensorflow.
- optimizer (str):
Desired scipy optimizer, choose from ‘Nelder-Mead’, ‘Powell’, ‘COBYLA’, ‘SLSQP’, ‘trust-constr’ or ‘trust-exact’.
-
scipy_fn
(theta: numpy.ndarray)¶ Evaluate the energy for a given set of parameters \(\theta^t\).
- Args:
- theta (array):
Array of size \(M\) containing the parameters of the quantum circuit.
- Returns (float):
Returns the energy \(\langle H \rangle_{\theta^t}\) of the variational circuit.
-
train
(maxiter: int = 1000)¶ Train the quantum variational eigensolver. We minimize the energy \(\langle H \rangle_\theta\) as defined above using a gradient free method.
- Args:
- maxiter (int):
The maximum number of iterations for the gradient free optimzer.
- Returns (inplace):
None
-
get_convergence
(plot=True) → Optional[float]¶ Plot the energy at each epoch. If the argument exact=True was passed to the``QuantumVariationalEigensolverGradFree`` constructor we also calculates the residual energy \(\epsilon_{\text{res}} = |\text{min}(E_{qc} - E_{gs_wavefunction})|\). Otherwise returns None
- Args:
- plot (bool):
Wheter to plot the training schedule.
- Returns (float):
Residual energy.
-
get_statistics
(plot=True)¶ Compare the ground state statistics of the
QuantumCircuit
with the exact ground state statistics.\[\begin{split}\text{MSE}_{h} = \frac{1}{M} \sum_i^M (\langle \sigma_i \rangle - \langle \hat{\sigma}_i \rangle)^2 \\ \text{MSE}_{w} = \frac{1}{M} \sum_{i,j}^M (\langle \sigma_i \sigma_j \rangle - \langle \hat{\sigma}_i \hat{\sigma}_j\rangle)^2\end{split}\]- Args:
- plot (bool):
Whether to plot the training schedule.
- Returns (dict):
Dict with entries ‘field’ and ‘coupling’ with the respective MSE between the circuit and true statistics.
-
get_wavefunction
(plot=False)¶ Compare the exact ground state wave function with the quantum circuit wave function by calculating the overlap
\[R = |\langle \psi(\theta)| \psi_0\rangle|^2\]- Args:
- plot (bool):
Whether to plot the training schedule.
- Returns (float):
The overlap \(R\)