Measuring and Input#

Measuring#

So far you’ve implemented a number of simulators which take a quantum state as input and output a quantum state. This is how a quanutm computer works except you don’t ever actually get to look at the output state in the real world. Instead, at the end of a computation, you are forced to measure your state. This measurement gives us a single bit string (integer) from your state; if you’re state is \(\sum_i \alpha_i |i\rangle\) you end up seeing state \(|i\rangle\) with probability \(|\alpha_i|^2\). Notice that this is a stochastic result - every time you run, you end up (potentially) getting a different measurement.

Modify your simulator(s) so that if the final line of the text description is a MEASURE - i.e. something like

2
H 0
CNOT 0 1
MEASURE

your simulator(s) output a single bit-string with the correct probabilities. You can check this by running without measure and then running with measure and showing that your probability distribution corresponds to the amplitude squared.

Grading

Get your simulators to perform measurement. Run your circuit 1000 times and show that the probability distribution that you get out of the measurement corresponds to the correct one on the following circuit:

Input#

By default we will assume that the input to your quantum circuit is the state \(|00..0\rangle\). Often (especially for testing purposes) you’ll want to be able to put in another input though. To do this, we will use a line like

INITSTATE FILE myInputState.txt

where myInputState.txt will be a file with \(2^n\) complex numbers in it like such:

0.0 -0.0
0.0 -0.0
0.0 -0.0
0.0 -0.7071
0.0 -0.0
0.0 -0.0
0.7071 0.0
0.0 -0.0

for the state \(\frac{1}{\sqrt{2}} \left( -i |3\rangle + |6 \rangle\right)\)

In addition to getting input to work this way, you should be able to read input like

INITSTATE BASIS |001>

which starts your input in the basis \(|1\rangle\).

Grading

Get your simulator(s) to perform these two different types of input. To test this, go ahead and run the following circuits

Tests: