def test_pauli_gate(self): """Test pauli x, y, z gate.""" rand = np.random.rand(3) qubit1 = qubit(*rand) # test x gate new_bit = Pauli_X(qubit1) assert_allclose(new_bit.state[::-1], qubit1.state) # test y gate new_bit = Pauli_Y(qubit1) assert_allclose(new_bit.state[::-1] * np.array([-1j, 1j]), qubit1.state) # test z gate new_bit = Pauli_Z(qubit1) assert_allclose(new_bit.state * np.array([1, -1]), qubit1.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)