{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Improving Variational Quantum Optimization using CVaR" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\n", "\n", "This notebook shows how to use the Conditional Value at Risk (CVaR) objective function introduced in  within the variational quantum optimization algorithms provided by Qiskit. Particularly, it is shown how to setup the MinimumEigenOptimizer using VQE accordingly. \n", "For a given set of shots with corresponding objective values of the considered optimization problem, the CVaR with confidence level $\\alpha \\in [0, 1]$ is defined as the average of the $\\alpha$ best shots.\n", "Thus, $\\alpha = 1$ corresponds to the standard expected value, while $\\alpha=0$ corresponds to the minimum of the given shots, and $\\alpha \\in (0, 1)$ is a tradeoff between focusing on better shots, but still applying some averaging to smoothen the optimization landscape.\n", "\n", "## References\n", "\n", " [P. Barkoutsos et al., *Improving Variational Quantum Optimization using CVaR,* Quantum 4, 256 (2020).](https://quantum-journal.org/papers/q-2020-04-20-256/)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from qiskit.circuit.library import RealAmplitudes\n", "from qiskit.algorithms.optimizers import COBYLA\n", "from qiskit.algorithms import NumPyMinimumEigensolver, VQE\n", "from qiskit.opflow import PauliExpectation, CVaRExpectation\n", "from qiskit_optimization import QuadraticProgram\n", "from qiskit_optimization.converters import LinearEqualityToPenalty\n", "from qiskit_optimization.algorithms import MinimumEigenOptimizer\n", "from qiskit_optimization.translators import from_docplex_mp\n", "from qiskit import execute, Aer\n", "from qiskit.utils import algorithm_globals\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from docplex.mp.model import Model" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "algorithm_globals.random_seed = 123456" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Portfolio Optimization\n", "In the following we define a problem instance for portfolio optimization as introduced in .