You are expected to complete this assignment individually. If you need help, you are invited to come to office hours and/or ask questions on Canvas. Clarification questions about the assignments may be asked publicly. Once you have specific bugs related to your code, make the posts private.
In this homework, you'll add to the qubit we created.
You should submit several files for this assignment ( Qubit.java, TestQubit.java, tests.txt Makefile). You will submit your work in a zip file to Gradescope. More detailed submission instructions will come later.
Error handling capabilities vary by language, and what you want to do in an error varies by the situation. When an error occurs in a function, the question becomes, what should you do, and how do you notify the caller that an error occurred?
In Java, there is a construct for this. We'll use this when calling methods that use it but, right now, we won't implement them ourselves. This is an exercise because if you write a method, and it's used in a variety of different circumstances, it is bad programming practice to determine within the function what will be done. For example, one program might want to exit, whereas another might want to notify the user that there was bad input and to try again.
In this course, we will print the error message in a special way (see below). If there is an opportunity, we will designate a specific return value for an error condition. If there is no available return value, then we will exit from within the function.
System.out.println("error: too many widgets for the number of grommets"); System.out.println("error: need ten boondoggles, but only have + num_bds");
Sometimes, these lines will be followed by System.exit(1); This immediately exits the program and returns a code. If you were writing a large program, you might assign a different code to each type of error that would result in an exit.
public float surface_area_cylinder(float height, float radius) { Console.WriteLine("surface_area_cylinder not yet implemented"); return 0.0; }
public static void Main(string[] args) { float fval; fval = test_surface_area_cylinder(3.5, 7.9); }
First get this compiling and running. It won't do anything useful, but this will mean that your code will compile and execute with our infrastructure. This must work in order to get any points in this course. Do this first, not last.
You are adding three pieces of functionality: Superposition, measurement, phase, and multiple qubit operations.
Superposition: This means that the value can be not only 0 or 1, but somewhere in between. You need to store the state such that a) you can perform accurate measurements on it and b) it can be used for single and multiple qubit operations. I am not specifying how you store the state - however, it will need to store all the pertinent information. Assume that when someone enters a float, it is the probability, between 0 and 1, inclusive, of measuring a 1. They can also enter a negative number, which would indicate a negative phase.
Measurement: You implement a simple measurement method that measures whether it is 0 or 1, and the measurement outcomes (over time) need to match the desired probability (within the constraints of the random number generators in classical computers).
Phase: You need to store whether the phase is positive or negative. This does not affect the measurement, but it affects operations.
New Gates: You need to implement the H gate, swap gate, and C-NOT gates. You only need to handle limited superposition, as specified below.
Adjust and add methods as specified below: