def test_copy(self): state1 = qudot.QuState({"00": .5, "10": .5, "01": .5, "11": -.5}) state2 = qudot.QuState({ "00": 1 / math.sqrt(2), "11": 1 / math.sqrt(2) }) state1_copy = state1.copy() state2_copy = state2.copy() self.assertEqual(state1, state1_copy) self.assertEqual(state2, state2_copy)
def test_apply_gate(self): test_input = qudot.QuState.init_zeros(2) output = qudot.QuState({"00": .5, "10": .5, "01": .5, "11": -.5}) test_input.apply_gate(qudot.H, [1]) test_input.apply_gate(qudot.CNOT) test_input.apply_gate(qudot.H, [1]) self.assertEqual(test_input, output) test_input = qudot.QuState.init_zeros(2) output = qudot.QuState({ "00": 1 / math.sqrt(2), "11": 1 / math.sqrt(2) }) test_input.apply_gate(qudot.H, [1]) test_input.apply_gate(qudot.CNOT) self.assertEqual(test_input, output)
def test_init_from_map(self): self.assertRaises(qudot_errors.InvalidQuStateError, lambda: qudot.QuState(None)) self.assertRaises(qudot_errors.InvalidQuBitError, lambda: qudot.QuState({"}": 1})) # make map with even states in 4D Hilbert space qubit_map = {} for i in range(0, 8): if not i % 2: if i == 6: qubit_map[qudot_utils.int_to_bit_str(i, 4)] = 0.5j else: qubit_map[qudot_utils.int_to_bit_str(i, 4)] = 0.5 qu_state = qudot.QuState(qubit_map) column_vector = get_column_vector(self.base_vector) row_vector = get_row_vector(self.adj_vector) vectors_equal(column_vector, qu_state.ket) vectors_equal(row_vector, qu_state.bra) self.assertTrue(qu_state.num_qubits == 4) self.assertTrue(qu_state.hilbert_dimension == 2**4)
def test_init_from_list(self): self.assertRaises(qudot_errors.InvalidQuStateError, lambda: qudot.QuState([])) self.assertRaises(qudot_errors.InvalidQuBitError, lambda: qudot.QuState.init_from_state_list(["{"])) qu_state_lst = ["0000", "0010", "0100", "0110"] qu_state = qudot.QuState.init_from_state_list(qu_state_lst) column_vector = get_column_vector(self.base_vector_real) row_vector = get_row_vector(self.base_vector_real) vectors_equal(column_vector, qu_state.ket) vectors_equal(row_vector, qu_state.bra) self.assertTrue(qu_state.num_qubits == 4) self.assertTrue(qu_state.hilbert_dimension == 2**4)
def setUp(self): amplitude = 1 / math.sqrt(5) self.qubit_map = { "1000": amplitude, "0010": amplitude, "0011": amplitude, "1010": amplitude, "1011": amplitude } self.test_state = qudot.QuState(self.qubit_map) self.test_amplitude = amplitude # |0000>, |0010>, |0100>, |0110> self.base_vector = [ .5, 0, .5, 0, .5, 0, .5j, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.base_vector_real = [ .5, 0, .5, 0, .5, 0, .5, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.adj_vector = [ .5, 0, .5, 0, .5, 0, -.5j, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]