def test_bell_state(self): for i in range(4): bell_st = bell_state(i) proj_st = BellBasis(bell_st, [0, 1]) j = i // 2 k = i % 2 assert proj_st.state[j][k] == 1 back_st = BellBasis(proj_st, [0, 1]) np.allclose(back_st.state, bell_st.state)
def test_quantum_teleportation(self): """Test quantum teleportation algorithm.""" bell_st = bell_state(0) # generater a random state a = np.random.rand(3) alice = qubit(*a) phi = alice @ bell_st phi = CNOT(phi, [0, 1]) phi = H(phi, [0]) bits, result_state = Measure(phi, [0, 1]) bit1, bit2 = bits if bit2: result_state = Pauli_X(result_state) if bit1: result_state = Pauli_Z(result_state) assert_allclose(result_state.state, alice.state)
def test_quantum_teleportation_bell_basis_permute(self): """Test quantum teleportation algorithm with bell basis and permutation.""" bell_st = bell_state(0) # generate a random state a = np.random.rand(3) alice = qubit(*a) phi = bell_st @ alice phi = BellBasis(phi, [1, 2]) bits, result_state = Measure(phi, [1, 2]) if bits == (0, 1): result_state = Pauli_X(result_state) elif bits == (1, 0): result_state = Pauli_X(Pauli_Z((result_state))) elif bits == (1, 1): result_state = Pauli_Z(result_state) assert_allclose(result_state.state, alice.state)
def test_quantum_teleportation_permute(self): """Test quantum teleportation algorithm with permutation.""" bell_st = bell_state(0) # generater a random state a = np.random.rand(3) alice = qubit(*a) phi = bell_st @ alice phi = CNOT(phi, [2, 1]) phi = H(phi, [2]) # assert False bits, result_state = Measure(phi, [2, 1]) bit1, bit2 = bits if bit2: result_state = Pauli_X(result_state) if bit1: result_state = Pauli_Z(result_state) assert_allclose(result_state.state, alice.state)