1. Homepage
  2. Programming
  3. CS 401: Quantum Computing - Coding Assignment 2: Quantum Teleportation algorithm

CS 401: Quantum Computing - Coding Assignment 2: Quantum Teleportation algorithm

Engage in a Conversation
CS 401Quantum ComputingQuantum Teleportation algorithmPython

Coding Assignment 2
CS 401: Quantum Computing 

CourseNana.COM

Instructions  CourseNana.COM

To complete the assignment, please fill in all coding cells as instructed below, and then submit the file on Notebowl once completed. Before you turn in your submission, make sure everything runs as expected. First, restart the kernel (in the menubar, select Kernel → Restart) and then run all cells (in the menubar, select Cell → Run All). Make sure you fill in any place that says YOUR CODE GOES HERE. CourseNana.COM

Constraints on references and collaborations CourseNana.COM

You may: Reference any chapter from the course textbook, references, and relevant Wikipedia pages. You are permitted to collaborate with others in the class in groups of 2-3, but these collaborations should be solely conceptual (i.e., clarifying the problem, brainstorming algorithms, etc.). CourseNana.COM

You may not: CourseNana.COM

  • You may not share code or work with others when writing your code. 
    CourseNana.COM

  • Reference the Qiskit Quantum Teleportion guide (This is Chapter 3.11 in the Qiskit online textbook.) CourseNana.COM

Finally: Be sure to use proper coding style for all your solutions! For example, you should write docstrings for all functions, include useful in-line comments explaining how your code works, write clean code with readable variable names, etc.. You will lose points if you write sloppy code with poor style (e.g., not writing docstrings for any of your functions). CourseNana.COM

Best of luck! CourseNana.COM

In [ ]:
# Specify your name below
NAME = "Your Name"
In [1]:
# Qiskit and NumPy imports
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, assemble, Aer
from qiskit.quantum_info import Statevector
from qiskit.visualization import array_to_latex
from qiskit.visualization import state_visualization
from qiskit.visualization import plot_state_city, plot_bloch_multivector
import qis401, random, math, cmath 

Part 1 [20 points]

In this first part, you will implement the Quantum Teleportation algorithm using Qiskit. You must structure your solution by implementing the following API: CourseNana.COM

  • random_qubit(): returns a two-element list containing the amplitudes of a randomly selected qubit (i.e., the first value is the amplitude for |0 and the second value is the amplitude for |1). To produce the random qubit, you must generate the parameters θ and φ in the Bloch sphere equation (Equation 1.4 on page 15 in NC) uniformly at random and then use these parameters to calculate each amplitude. 
    CourseNana.COM

  • initialize_circuit(teleport_amps): Takes in a two-element list teleport_amps and returns the six tuple (circ, teleport, alice, bob, t_measure, a_measure), where teleport, alice,, and bob are the QuantumRegister objects that will be used in the algorithm; t_result and a_result are the ClassicalRegister objects that will be use to store Alice's measurement of the teleport and aliceregisters; and circ is the overall QuantumCircuit object itself. Furthermore, the state of teleport should be initialized to be the values in teleport_amps (which will be created by previously calling random_qubit()). Use the QuantumCircuit method initialize() to perform this initialization of the teleportation qubit. Also at the end of the function, call the barrier() method to block off this initial phase of the algorithm.

    CourseNana.COM

  • make_epr(circ, alice, bob): takes in the QT circuit and quantum registers for Alice and Bob and puts them in an EPR pair. At the end of the function, again use the barrier() method to block off this segment of the algorithm. 
    CourseNana.COM

  • alice_computation(circ, teleport, alice, t_measure, a_measure): Takes in the QT circuit along with the registers needed to perform Alice's part of the algorithm. Use the barrier() method twice to create two blocks, one for her quantum operations and one for her measurements. 
    CourseNana.COM

  • bob_computation(circ, bob, t_measure, a_measure): Takes in the QT circuit along with the registers needed to perform Bob's part of the algorithm CourseNana.COM

Implement the above functions in a single cell. To generate your output, create three additional cells that do the following: CourseNana.COM

  • Your first cell should simply create teleport_amps by calling random_qubit(). You should then pass teleport_amps into the Qiskit function plot_bloch_multivector() to visualize the qubit as a Bloch sphere. The output of the cell should look something like:
  • Your second cell should then construct the circuit by calling the functions from the API, and then use the draw() method to display the circuit. The output of the cell should look similar to the final circuit in the Quantum Teleportation slides from class (along with the initialization block at the beginning that generates the random qubit). 
    CourseNana.COM

  • Your third cell should then simulate the circuit by calling qis401.simulate_circuit(). You should then use the returned result object to get the final state vector, and then pass this into plot_bloch_multivector() to visualize the final state of teleport, alice, and bob. The output should look something like: CourseNana.COM

In particular, the first and second spheres (corresponding to the teleport and Alice qubits) should be pointing either straight up or down (since they've been measured). The third sphere corresponding to Bob's qubit should be pointing in the same direction as the original sphere for the teleportation qubit. CourseNana.COM

Part 2 [30 points]

In this part, you will now implement the Quantum Teleportation algorithm using NumPy vectors and matrices. You will implement the same API as in Part 1. The differences between the functions parameters and return values are specified as follows: CourseNana.COM

  • random_qubit(): Reuse the implementation from Part 1. 
    CourseNana.COM

  • initialize_circuit(teleport_amps): Again takes in a two element list teleport_amps, but now returns an 8-dimensional NumPy vector that has initialized the amplitudes of the teleportation qubit according to teleport_amps. Note that in order to store complex values in the NumPy array state vector, you need to initialize the state vector using zeros(8, dtype=numpy.complex_). 
    CourseNana.COM

  • make_epr(state): Takes in the current state vector and returns the resulting vector after applying the unitary matrices that put Alice and Bob's qubits in an EPR pair. (Like we saw in class, you should use the numpy.kron() function to create the unitary matrices corresponding to each gate). 
    CourseNana.COM

  • alice_computation(state): Takes the current state vector and returns a two-tuple (output_state, measure), where output_state is the resulting state after first applying the unitary matrices corresponding to Alice's quantum computations and then measuring the teleport and Alice qubits; measure should then be one of four strings "00", "01", "10", or "11" that indicates Alice's measurement result. Note you will have to manually simulate the process of measurement, i.e., you will need to randomly select the measurement outcome and then renormalize the quantum state according to the outcome. 
    CourseNana.COM

  • bob_computation(state, measure): Takes the current state vector and Alice's measurement result, and returns the resulting state vector after applying the unitary matrices corresponding to Bob's computations. CourseNana.COM

Again, implement the functions in the above API in a single cell. (Note to avoid having to repeatedly construct the single qubit matrices for the H, Z, X, and CX gates in each function, it's fine to declare these matrices as global variables at the top). CourseNana.COM

To generate your output, again write a single cell that creates the random teleportation qubit and displays its state as a Bloch sphere. Then, create a second cell that uses the functions in your API to apply the QT algorithm to the intial state vector. At the end of the cell, you should display the state of Bob's qubit as a single Bloch sphere, which should match the original Bloch sphere of the teleportation qubit. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
CS 401代写,Quantum Computing代写,Quantum Teleportation algorithm代写,Python代写,CS 401代编,Quantum Computing代编,Quantum Teleportation algorithm代编,Python代编,CS 401代考,Quantum Computing代考,Quantum Teleportation algorithm代考,Python代考,CS 401help,Quantum Computinghelp,Quantum Teleportation algorithmhelp,Pythonhelp,CS 401作业代写,Quantum Computing作业代写,Quantum Teleportation algorithm作业代写,Python作业代写,CS 401编程代写,Quantum Computing编程代写,Quantum Teleportation algorithm编程代写,Python编程代写,CS 401programming help,Quantum Computingprogramming help,Quantum Teleportation algorithmprogramming help,Pythonprogramming help,CS 401assignment help,Quantum Computingassignment help,Quantum Teleportation algorithmassignment help,Pythonassignment help,CS 401solution,Quantum Computingsolution,Quantum Teleportation algorithmsolution,Pythonsolution,