logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Rakesh RastogiManagement
(5/5)

925 Answers

Hire Me
expert
Kathleen HaslamResume writing
(4/5)

627 Answers

Hire Me
expert
Milton BlahaEconomics
(5/5)

939 Answers

Hire Me
expert
Steven HughesEducation
(5/5)

777 Answers

Hire Me
Others
(5/5)

contains a constructor that: i. accepts an operator matrix and creates an instance variable

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

1. Create a file called main.py that runs a function called main(). Your main() function should:

a. Read in a file called qubits.txt that contains the state of the qubits and sequences of operators that will be applied to the qubit. Each line in the input file will contain a floating point value for alpha, a floating point value for beta, and a number of operators that will be applied to the qubit (only the X and H gates are valid operators) i. Ex: 0.8 0.6 H X (alpha = 0.8, beta = 0.6, apply 1 H gate then 1 X gate)

b. Contains a loop that processes each qubit in the input file (applies the list of operators) using the Qubit and Operator classes.

c. Calls the experiment method in the Qubit class 100 times for each qubit in the input file and outputs the results as a percentage of 0’s and 1’s resulting from the experiment.

d. Prints the initial state of the qubit at the beginning of the process and the final state of the qubit once all operators have been applied.

2. Next, create a Qubit class inside of a module named qubit.py. Your class should:

a. Keep track of the state of the qubit which will be the 0 basis state |0>, the 1 basis state|1>, or an arbitrarily weighted superposition of the two basis states. The constructor should also call validate_amplitudes (defined in ‘c’ below) to ensure the coefficients alpha and beta are valid (the sum of their squares = 1).

b. Contains a method named prob_amplitudes that returns a tuple containing the probability of receiving a |0> and the probability of receiving a |1> from a measurement. That is, the square of alpha and the square of beta.

c. Contains a method called validate_amplitudes that raises an InvalidProbabilityAmplitude exception that prints “Invalid probability amplitude(s).” if illegal values for alpha and/or beta (the sum of their squares is not equal to one.

d. Contains a method called experiment that uses a properly weighted binomial distribution to demonstrate that a measurement of a qubit yields a 0 (|0>) with probability alpha2 and yields a 1 (|1>) with probability beta2 .

e. Contains a __str__ method that provides a string representation of a qubit object: i. “X|0> + Y|1>”, where X and Y are the coefficients of the basis vectors

3. Next, build a SingleQubitOperator class inside of a module named operator.py that:

a. Will be used to derive 2 specific single-qubit operator subclasses

b. Contains a constructor that: i. accepts an operator matrix and creates an instance variable from it ii. raises an InvalidOperator exception that prints “Invalid operator.” if an operator other than X or H are provided in the input file

4. Finally, build 2 classes: PauliX in a module named paulix.py and Hadamard in a module named hadamard.py, both of which are child classes of SingleQubitOperator. Each class should:

a. Be a child class of the SingleQubitOperator class created in Step #2

b. Call the parent class’ constructor and pass in the appropriate matrix (operator)

c. Implement a method called operate that accepts a qubit, applies the class’ operator to the qubit, and returns a new Qubit object containing the updated state

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme