This video belongs to the openHPI course Quantum Optimization (with IBM Quantum). Do you want to see more?
An error occurred while loading the video player, or it takes a long time to initialize. You can try clearing your browser cache. Please try again later and contact the helpdesk if the problem persists.
Scroll to current position
- 00:00Welcome to this bonus episode of the quantum optimization course.
- 00:04In the previous lecture, you have learned about the variation of quantum Eigensolver or VQE and how we can use it to solve
- 00:10optimization problems.
- 00:12In this short video,
- 00:14we'll have a look at how you can concretely solve a MaxCut problem with the open source software package Qiskit.
- 00:20As an example, we here have a five node MaxCut graph and we want to find the maximum cut.
- 00:27We have the five nodes labeled from 0-4 and between some of the nodes we have edges with certain weights.
- 00:36In the lecture
- 00:37before the previous lecture, you've learned how you can translate that into an Ising Hamiltonian.
- 00:41So the first step is to set up the MaxCut objective C and then convert the binary variables Xi to spin variables and then
- 00:50finally promote the spin variables Z to polyZ operators.
- 00:54If you do all the math, then you can come up with the Hamiltonian that you can see on the right of the screen.
- 00:59So let's see how we can solve that with Qiskit.
- 01:03The first step is to construct a graph. Here we can use network X and use the add weighted edge from method.
- 01:11Once the graph is set up, you can use Qiskit optimizations MaxCut application to define the MaxCut problem.
- 01:19You simply have to give the graph into the MaxCut object.
- 01:22And then you can call to quadratic program on it which will construct a quadratic program object.
- 01:27Now, if we want to inspect the Hamiltonian, we can call to Ising on the program and that gives us the Ising Hamiltonian.
- 01:35Now you can convince yourself that this is the same one that we came up with
- 01:38by hand. If you have a large problem now in the future, you don't have to do all the math by hand.
- 01:42But you can just ask Qiskit to do it for you.
- 01:47Now that we have the Hamiltonian, we can choose an Ansatz. Here which is a predefined
- 01:52Ansatz from caskets Qiskit library called the RealAmplitudes.
- 01:55And this is somewhere between a arbitrary guess and a circuit with an intrinsic motivation.
- 02:04It is an Ansatz that is hardware efficient.
- 02:06That means we can efficiently map it onto our current devices because it only requires a linear connectivity.
- 02:12But there's also some motivation behind it because this Ansatz can only map real amplitudes to our quantum states.
- 02:18And optimization
- 02:19we generally don't need the complex amplitudes.
- 02:23If you draw the circuit, then you can see that it consists of layers of Ry gates, these are parameterized.
- 02:28And here we can tune the angles followed by an entanglement layer of blue C not gates.
- 02:36with the Ansatz at hand
- 02:37And Hamiltonian that we want to solve, we can now set up the VQE. The VQE takes a few ingredients.
- 02:43The first argument is the estimator.
- 02:46This is a subroutine that computes expectation values.
- 02:49The second argument is the Ansatz which is defined above.
- 02:53And the last argument is the optimizer.
- 02:55This is a classical subroutine.
- 02:57And here we choose to use COBYLA that's also implemented in Qiskit.
- 03:02Finally, we can run the VQE by calling the computer minimum eigenvalue method on it and giving it the Hamiltonian.
- 03:09Once we have the result, we want to inspect which bit string is the best bit string, which is the solution to our MaxCut problem.
- 03:16For that, we can use this sampler and plug in the optimal parameter values into our Ansatz.
- 03:20And then we measure all the cubits and run the sampler.
- 03:26If we now plot the histogram using Qiskit visualization, we can see that one bit string clearly stands out.
- 03:32This is the bit string, 10100, and keeping the reverse ordering of Qiskit in mind, we can now map these two nodes and we can
- 03:41see that nodes two and four are in the same group and the other nodes zero, one and three are in a separate group.
- 03:49And if you look at the graph, then we can see that indeed this is the grouping that provides the maximum cut.
- 03:55This is how you can implement the MaxCut problem in Qiskit.
- 03:58And if you want to check out more applications, have a look at the documentation.
To enable the transcript, please select a language in the video player settings menu.