Path: blob/main/notebooks/ch-labs/Lab09_QuantumSimulationSearchAlgorithm.ipynb
3855 views
Lab 9 Quantum Simulation as a Search Algorithm
Prerequisites:
Other relevant materials:
[Ch 6.2 in QCQI] Michael A. Nielsen and Isaac L. Chuang. Quantum Computation and Quantum Information, p255
Part 1: Hamiltonian Simulation
Goal
In this lab, we consider changes to a quantum state veiwed as an evolution process generated by a given Hamiltonian. For a specified Hamiltonian, there is a corresponding unitary operator that determines the final state for any given initial state.
For an initial state, and a time independent Hamiltonian , the final state is . Therefore, by constructing an appropriate gate for the unitary operator , we can build a quantum circuit that simulates the evolution of the quantum state .
1. Build a quantum circuit for a given Hamiltonian.
When the hamiltonian and the initial state of the system, , are given by
.
Build the circuit with two qubits to evolve the state, , by for a time , where the state of the system is encoded on the 0th qubit and the 1st qubit is an auxiliary. Then, the final state is .
📓Step A. Show that the gate H1 from the following circuit performs the operation on the 0th qubit when the state of the system is encoded on the 0th qubit and the 1st qubit, auxiliary, is set to the state.
Your Solution:
📓Step B. Construct the gate H2 by completing the following code for the circuit `h2` to performs the operation on the 0th qubit when the state of the system is encoded on the 0th qubit and the 1st qubit, auxiliary, is set to the state.
2. Execute the cell below to generate the state of the 0th qubit after every iteration.
The circuit performs on the 0th qubit. The state of the 0th qubit after each H1H2 operation is stored in the list variable 'myst'.
The following Bloch sphere picture shows the evolution of the 0th qubit state. As it shows, the state starts from the state rotate toward to and passes the state. Therefore, with appropriate the angle of the H1 and H2 operations, state evolves to state by applying proper number of times.

If you have installed kaleidoscope or run this lab on IQX, you can excute the cell below to visualize the state evolution through the interactive bloch sphere.
Part 2: Quantum Search as a Quantum Simulation
Goal
In this part of the lab, we solve a search problem through quantum simulation.
In Part1, we showed that the Hamiltonian, , transforms the state, , to when its structure depends on both states as with a proper time duration.
Considering a search problem with a unique solution, we should be able to find the solution with the form of the Hamiltonian, when all possible items are encoded in a superposition state and given as the initial state, same as in Grover's algorithm, while represents the unknown solution.
Applying the unitary operator, on the initial state, , right number of times with the properly chosen , should evolve the state into the solution or close enough to it. The following code constructs the oracle gate for the search problem. Execute the cell below.
The following circuit encodes the phase on the solution state and zero on the other items through phase kickback with the 5th qubit as an auxiliary. Therefore, the output state of the circuit is , which can be confirmed visually using a qsphere plot where the color indicates the phase of each basis state. Run the following two cells.
1. Construct a circuit to approximate the Hamiltonian, , when all possible items are encoded in a superposition state and given as the initial state while represents the unique unknown solution.
As we did in the Part1, we build the circuit for the simulation with the Hamiltonian, but with more qubits to examine all the items in the question. Regard the search problem having one solution out of 32 items.
📓Step A. Construct the gate H1 performing the operation by completing the following code.
📓Step B. Construct the gate H2 performing the operation by completing the following code.
📓Step C. Create the circuit, 'sim_h', to compute which evolves the state under the Hamiltonian approximately over the time duration .
The state represents the superposition state of all possible items.
Utilize the gates H1 and H2.
2. Show that the search problem can be solved through quantum simulation with by verifying the two operations, Grover's algorithm and with , are equivalent.
Step A. The following circuit, `grover`, runs the Grover's algorithm for the problem to find a solution for the oracle that we built above. Run the cell below.
Step B. Upon executing the cells below, the result shows that the circuits, 'grover' and 'sim_h' are identical up to a global phase.
📓Step C. Find the number of the Grover iterations, R, needed to find the solutions of the Oracle that we built.
Step D. Find the solution to the search problem, for the Oracle that we built, through Grover's algorithm and the simulation computing where R is the number of iterations.
📓 Complete the code to build the circuit, qc_sim, to solve the search problem through the simulation.
Run the following cell to simulate both circuits, qc_grover and qc_sim and compare their solutions.