% Simple examples for Quack! % by Peter Rohde quack % Prepare a Bell state and look at the reduced density matrix for one of the qubits disp('*** Example 1 ***') disp(' ') init_state(2) prepare_bell_00(1,2) disp('Density matrix of an EPR pair:') print_dm disp(' ') disp('Reduced density matrix for the first qubit (should be a completely mixed state):') print_rdm(1) disp(' ') input('Press <> to go to the next example'); disp(' ') % Prepare a Bell state using a product state and a CNOT gate disp('*** Example 2 ***') disp(' ') disp('Prepare the state |+>|0>:') init_state(2) prepare_plus(1) print_dm; disp(' ') disp('Apply a CNOT gate (we should get an EPR pair):') cnot(1,2) print_dm disp(' ') disp('Reduced density matrix of first qubit:') print_rdm(1) input('Press <> to go to the next example'); disp(' ') % Bit-flip channel disp('*** Example 3 ***') disp(' ') disp('Prepare the |0> state and apply a p=0.5 bit-flip channel (should get a completely mixed state):') init_state(1) X_ch(0.5,1) print_hist print_dm disp('Now prepare the |+> state and apply a p=0.5 bit-flip channel (state shouldn''t change):') init_state(1) prepare_plus(1) X_ch(0.5,1) print_hist print_dm input('Press <> to go to the next example'); disp(' ') % Circuit history disp('*** Example 4 ***') disp(' ') disp('Construct a circuit containing state preparation, simple gates and measurment, and show the circuit history:') init_state(5) prepare_one(1) prepare_plus(2) prepare_minus(3) prepare_bell_00(4,5) cnot(1,2) Y(3) H(4) Rz(pi,5) swap(1,5) cz(2,3) Z_measure(1); Z_measure(2); bell_measure(3,4); T(5) Z_measure(5); print_hist