def test_evolve_global_phase(self): """Test evolve circuit with global phase.""" state_i = Statevector([1, 0]) qr = QuantumRegister(2) phase = np.pi / 4 circ = QuantumCircuit(qr, global_phase=phase) circ.x(0) state_f = state_i.evolve(circ, qargs=[0]) target = Statevector([0, 1]) * np.exp(1j * phase) self.assertEqual(state_f, target)
def test_evolve_subsystem(self): """Test subsystem _evolve method.""" # Test evolving single-qubit of 3-qubit system for _ in range(5): vec = self.rand_vec(8) state = Statevector(vec) op0 = random_unitary(2) op1 = random_unitary(2) op2 = random_unitary(2) # Test evolve on 1-qubit op = op0 op_full = Operator(np.eye(4)).tensor(op) target = Statevector(np.dot(op_full.data, vec)) self.assertEqual(state.evolve(op, qargs=[0]), target) # Evolve on qubit 1 op_full = Operator(np.eye(2)).tensor(op).tensor(np.eye(2)) target = Statevector(np.dot(op_full.data, vec)) self.assertEqual(state.evolve(op, qargs=[1]), target) # Evolve on qubit 2 op_full = op.tensor(np.eye(4)) target = Statevector(np.dot(op_full.data, vec)) self.assertEqual(state.evolve(op, qargs=[2]), target) # Test evolve on 2-qubits op = op1.tensor(op0) # Evolve on qubits [0, 2] op_full = op1.tensor(np.eye(2)).tensor(op0) target = Statevector(np.dot(op_full.data, vec)) self.assertEqual(state.evolve(op, qargs=[0, 2]), target) # Evolve on qubits [2, 0] op_full = op0.tensor(np.eye(2)).tensor(op1) target = Statevector(np.dot(op_full.data, vec)) self.assertEqual(state.evolve(op, qargs=[2, 0]), target) # Test evolve on 3-qubits op = op2.tensor(op1).tensor(op0) # Evolve on qubits [0, 1, 2] op_full = op target = Statevector(np.dot(op_full.data, vec)) self.assertEqual(state.evolve(op, qargs=[0, 1, 2]), target) # Evolve on qubits [2, 1, 0] op_full = op0.tensor(op1).tensor(op2) target = Statevector(np.dot(op_full.data, vec)) self.assertEqual(state.evolve(op, qargs=[2, 1, 0]), target)