Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial housecleaning: VQE #1379

Merged
merged 14 commits into from
Jun 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions tutorials/variational-quantum-eigensolver/vqe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"[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",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"\n",
"Executing a VQE algorithm requires the following 3 components:\n",
"Executing a VQE algorithm requires the following three components:\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"\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."
]
},
{
Expand Down Expand Up @@ -104,7 +104,7 @@
"\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",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"Here, our example Hamiltonian is derived from a quantum chemistry problem"
"Here, our example Hamiltonian is derived from a quantum chemistry problem."
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand Down Expand Up @@ -192,23 +192,23 @@
"id": "ac6f36e3",
"metadata": {},
"source": [
"## Step 2: Optimize problem for quantum execution."
"## Step 2: Optimize problem for quantum execution"
]
},
{
"cell_type": "markdown",
"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 Runtime V2 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)."
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "markdown",
"id": "3390069d-572c-472c-abb5-9cde12fd82a2",
"metadata": {},
"source": [
"### ISA Circuit"
"### ISA circuit"
]
},
{
Expand All @@ -218,7 +218,7 @@
"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",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"\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."
"- [`optimization_level`](https://docs.quantum-computing.ibm.com/api/qiskit/transpiler_preset#preset-pass-manager-generation): The lowest optimization level 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 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."
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand Down Expand Up @@ -268,15 +268,15 @@
"id": "aab9e309-d643-496f-ad4b-c90173102ad6",
"metadata": {},
"source": [
"### ISA Observable"
"### ISA observable"
]
},
{
"cell_type": "markdown",
"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."
"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` method of `SparsePauliOp` object."
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand All @@ -295,7 +295,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",
Expand Down Expand Up @@ -351,7 +351,7 @@
"source": [
"### Creating a callback function\n",
"\n",
"Callback functions are a standard way for users to obtain additional information about the status of an iterative algorithm. The standard SciPy callback routine allows for returning only the interim vector at each iteration. However, it is possible to do much more than this. Here, we show how to use a mutable object, such as a dictionary, to store the current vector at each iteration, for example in case we need to restart the routine due to failure, and also return the current iteration number and average time per iteration."
"Callback functions are a standard way for users to obtain additional information about the status of an iterative algorithm. The standard SciPy callback routine allows for returning only the interim vector at each iteration. However, it is possible to do much more than this. Here, we show how to use a mutable object, such as a dictionary, to store the current vector at each iteration (this is useful in case we need to restart the routine due to failure), and also return the current iteration number and average time per iteration."
]
},
{
Expand Down Expand Up @@ -542,7 +542,7 @@
"id": "50b94af2",
"metadata": {},
"source": [
"## Step 4: Post-process, return result in classical format."
"## Step 4: Post-process, return result in classical format"
]
},
{
Expand Down
Loading