From 01fe8d4c9d97ca54a4ded90b86b155c1789a6c2d Mon Sep 17 00:00:00 2001 From: abbycross Date: Thu, 13 Jun 2024 11:51:47 -0400 Subject: [PATCH] Tutorial housecleaning: VQE (#1379) Related to #1286 --------- Co-authored-by: Rebecca Dimock <66339736+beckykd@users.noreply.github.com> --- .../variational-quantum-eigensolver/vqe.ipynb | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/tutorials/variational-quantum-eigensolver/vqe.ipynb b/tutorials/variational-quantum-eigensolver/vqe.ipynb index ce8de7d7c4c..8ce0aaaf579 100644 --- a/tutorials/variational-quantum-eigensolver/vqe.ipynb +++ b/tutorials/variational-quantum-eigensolver/vqe.ipynb @@ -6,18 +6,20 @@ "id": "a6f69b77", "metadata": {}, "source": [ + "*Usage estimate: 73 minutes on ibm_kyiv or 28 minutes on ibm_manila. (NOTE: This is an estimate only. Your runtime may vary.)*\n", + "\n", "## Background\n", "\n", - "[Variational quantum algorithms](https://arxiv.org/abs/2012.09265) are promising candidate hybrid-algorithms for observing the utility of quantum computation on noisy near-term devices. Variational algorithms are characterized by the use of a classical optimization algorithm to iteratively update a parameterized trial solution, or \"ansatz\". Chief among these methods is the Variational Quantum Eigensolver (VQE) that aims to solve for the ground state of a given Hamiltonian represented as a linear combination of Pauli terms, with an ansatz circuit where the number of parameters to optimize over is polynomial in the number of qubits. Given that size of the full solution vector is exponential in the number of qubits, successful minimization using VQE requires, in general, additional problem specific information to define the structure of the ansatz circuit.\n", + "[Variational quantum algorithms](https://arxiv.org/abs/2012.09265) are promising candidate hybrid-algorithms for observing quantum computation utility on noisy near-term devices. Variational algorithms are characterized by the use of a classical optimization algorithm to iteratively update a parameterized trial solution, or \"ansatz\". Chief among these methods is the Variational Quantum Eigensolver (VQE) that aims to solve for the ground state of a given Hamiltonian represented as a linear combination of Pauli terms, with an ansatz circuit where the number of parameters to optimize over is polynomial in the number of qubits. Given that the size of the full solution vector is exponential in the number of qubits, successful minimization using VQE requires, in general, additional problem-specific information to define the structure of the ansatz circuit.\n", "\n", "\n", - "Executing a VQE algorithm requires the following 3 components:\n", + "Executing a VQE algorithm requires the following components:\n", "\n", " 1. Hamiltonian and ansatz (problem specification)\n", " 2. Qiskit Runtime estimator\n", " 3. Classical optimizer\n", "\n", - "Although the Hamiltonian and ansatz require domain specific knowledge to construct, these details are immaterial to the Runtime, and we can execute a wide class of VQE problems in the same manner." + "Although the Hamiltonian and ansatz require domain-specific knowledge to construct, these details are immaterial to the Runtime, and we can execute a wide class of VQE problems in the same manner." ] }, { @@ -68,21 +70,10 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "bc380c46", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'ibm_algiers'" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# runtime imports\n", "from qiskit_ibm_runtime import QiskitRuntimeService, Session\n", @@ -90,8 +81,7 @@ "\n", "# To run on hardware, select the backend with the fewest number of jobs in the queue\n", "service = QiskitRuntimeService(channel=\"ibm_quantum\")\n", - "backend = service.least_busy(operational=True, simulator=False)\n", - "backend.name" + "backend = service.least_busy(operational=True, simulator=False)" ] }, { @@ -102,9 +92,9 @@ "source": [ "## Step 1: Map classical inputs to a quantum problem\n", "\n", - "Here we define the problem instance for our VQE algorithm. Although the problem in question can come from a variety of domains, the form for execution through Qiskit Runtime is the same. Qiskit provides a convenience class for expressing Hamiltonians in Pauli form, and a collection of widely used ansatz circuits in the [`qiskit.circuit.library`](https://docs.quantum-computing.ibm.com/api/qiskit/circuit_library).\n", + "Although the problem instance in question for the VQE algorithm can come from a variety of domains, the form for execution through Qiskit Runtime is the same. Qiskit provides a convenience class for expressing Hamiltonians in Pauli form, and a collection of widely used ansatz circuits in the [`qiskit.circuit.library`](https://docs.quantum-computing.ibm.com/api/qiskit/circuit_library).\n", "\n", - "Here, our example Hamiltonian is derived from a quantum chemistry problem" + "This example Hamiltonian is derived from a quantum chemistry problem." ] }, { @@ -187,7 +177,7 @@ "id": "ac6f36e3", "metadata": {}, "source": [ - "## Step 2: Optimize problem for quantum execution." + "## Step 2: Optimize problem for quantum execution" ] }, { @@ -195,7 +185,7 @@ "id": "ed01c675-6506-4779-bf71-74f0de9212fb", "metadata": {}, "source": [ - "To reduce the total job execution time, Qiskit Runtime V2 primitives only accept circuits (ansatz) and observables (Hamiltonian) that conforms to the instructions and connectivity supported by the target system (referred to as instruction set architecture (ISA) circuits and observables, respectively)." + "To reduce the total job execution time, Qiskit primitives only accept circuits (ansatz) and observables (Hamiltonian) that conform to the instructions and connectivity supported by the target system (referred to as instruction set architecture (ISA) circuits and observables)." ] }, { @@ -203,7 +193,7 @@ "id": "3390069d-572c-472c-abb5-9cde12fd82a2", "metadata": {}, "source": [ - "### ISA Circuit" + "### ISA circuit" ] }, { @@ -211,9 +201,9 @@ "id": "ad6ddd99-b680-4ac4-b2d8-c0ac6266e6e8", "metadata": {}, "source": [ - "We can schedule a series of [`qiskit.transpiler`](https://docs.quantum-computing.ibm.com/api/qiskit/transpiler) passes to optimize our circuit for a selected backend and make it compatible with the instruction set architecture (ISA) of the backend. This can be easily done using a preset pass manager from `qiskit.transpiler` and its `optimization_level` parameter.\n", + "Schedule a series of [`qiskit.transpiler`](https://docs.quantum-computing.ibm.com/api/qiskit/transpiler) passes to optimize the circuit for a selected backend and make it compatible with the backend's ISA. This can be easily done with a preset pass manager from `qiskit.transpiler` and its `optimization_level` parameter.\n", "\n", - "- [`optimization_level`](https://docs.quantum-computing.ibm.com/api/qiskit/transpiler_preset#preset-pass-manager-generation): The lowest optimization level just does the bare minimum needed to get the circuit running on the device; it maps the circuit qubits to the device qubits and adds swap gates to allow all 2-qubit operations. The highest optimization level is much smarter and uses lots of tricks to reduce the overall gate count. Since multi-qubit gates have high error rates and qubits decohere over time, the shorter circuits should give better results." + "The lowest optimization level does the minimum needed to get the circuit running on the device; it maps the circuit qubits to the device qubits and adds swap gates to allow all two-qubit operations. The highest optimization level is much smarter and uses lots of tricks to reduce the overall gate count. Since multi-qubit gates have high error rates and qubits decohere over time, the shorter circuits should give better results." ] }, { @@ -258,7 +248,7 @@ "id": "aab9e309-d643-496f-ad4b-c90173102ad6", "metadata": {}, "source": [ - "### ISA Observable" + "### ISA observable" ] }, { @@ -266,7 +256,7 @@ "id": "6c9e5dcd", "metadata": {}, "source": [ - "Similarly, we need to transform the Hamiltonian to make it backend compatible before running jobs with [`Runtime Estimator V2`](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.EstimatorV2#run). We can perform the transformation using the `apply_layout` the method of `SparsePauliOp` object." + "Transform the Hamiltonian to make it backend-compatible before running jobs with [`Runtime Estimator V2`](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.EstimatorV2#run). Perform the transformation by using the `apply_layout` method of `SparsePauliOp` object." ] }, { @@ -285,7 +275,7 @@ "id": "b4d480b3", "metadata": {}, "source": [ - "## Step 3: Execute using Qiskit Primitives.\n", + "## Step 3: Execute using Qiskit Primitives\n", "\n", "Like many classical optimization problems, the solution to a VQE problem can be formulated as minimization of a scalar cost function. By definition, VQE looks to find the ground state solution to a Hamiltonian by optimizing the ansatz circuit parameters to minimize the expectation value (energy) of the Hamiltonian. With the Qiskit Runtime [`Estimator`](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.EstimatorV2) directly taking a Hamiltonian and parameterized ansatz, and returning the necessary energy, the cost function for a VQE instance is quite simple.\n", "\n", @@ -611,7 +601,7 @@ "id": "50b94af2", "metadata": {}, "source": [ - "## Step 4: Post-process, return result in classical format." + "## Step 4: Post-process, return result in classical format" ] }, {