QuantumVariationalEigensolver

class zyglrox.models.qve.QuantumVariationalEigensolver(hamiltonian: zyglrox.core.hamiltonians.Hamiltonian, qc: zyglrox.core.circuit.QuantumCircuit, exact=False, optimizer=None, **kwargs)

Quantum Variational Eigensolver according to Peruzzo et al. (2014) with gradient based optimization.

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} = \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.

For the Gradient-based QVE, we calculate the gradient for each parametrized unitary in the quantum circuit as follows:

\[\frac{\partial \mathcal{U}(\theta) }{\partial \theta_j} = \left(\prod_{i=1}^{j-1} \mathcal{U}_i(\theta_i)\right) \frac{\partial \mathcal{U}_j(\theta_j) }{\partial \theta_j} \left(\prod_{i=j+1}^{M} \mathcal{U}_i(\theta_i)\right)\]
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.

optimizer (tf.optimizers.Optimizer):

Desired optimizer to perform the QVE algorithm.

Returns (inplace):

None

train(max_iter: int = 1000, tol: float = 1e-08, fetch_from_graph={}, sc_method: str = 'single') → numpy.ndarray

Train the quantum variational eigensolver. We minimize the energy \(\langle H \rangle_\theta\) as defined above.

Args:
max_iter (int):

Number of max iterations for the training algorithm.

tol (float):

Tolerance on the energy. If the absolute difference between iterations is smaller than this value, training stops.

fetch_from_graph (dict):

Tolerance on the energy. If the absolute difference between iterations is smaller than this value, training stops.

sc_method (str):

Method for stopping criterion.

Returns expvals (np.ndarray):

Expectation values after training is complete.

get_convergence(plot=False) → 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\)