def test_init_array(self):
        """Test initialization from array."""
        vec = self.rand_vec(3)
        statevec = Statevector(vec)
        self.assertAllClose(statevec.data, vec)
        self.assertEqual(statevec.dim, 3)
        self.assertEqual(statevec.dims(), (3,))

        vec = self.rand_vec(2 * 3 * 4)
        state = Statevector(vec, dims=[2, 3, 4])
        self.assertAllClose(state.data, vec)
        self.assertEqual(state.dim, 2 * 3 * 4)
        self.assertEqual(state.dims(), (2, 3, 4))
    def test_init_array(self):
        """Test initialization from array."""
        vec = self.rand_vec(3)
        state = Statevector(vec)
        assert_allclose(state.data, vec)
        self.assertEqual(state.dim, 3)
        self.assertEqual(state.dims(), (3, ))
        self.assertIsNone(state.num_qubits)

        vec = self.rand_vec(2 * 3 * 4)
        state = Statevector(vec, dims=[2, 3, 4])
        assert_allclose(state.data, vec)
        self.assertEqual(state.dim, 2 * 3 * 4)
        self.assertEqual(state.dims(), (2, 3, 4))
        self.assertIsNone(state.num_qubits)
 def test_init_array_qubit(self):
     """Test subsystem initialization from N-qubit array."""
     # Test automatic inference of qubit subsystems
     vec = self.rand_vec(8)
     for dims in [None, 8]:
         state = Statevector(vec, dims=dims)
         self.assertAllClose(state.data, vec)
         self.assertEqual(state.dim, 8)
         self.assertEqual(state.dims(), (2, 2, 2))
 def test_tensor(self):
     """Test tensor method."""
     for _ in range(10):
         vec0 = self.rand_vec(2)
         vec1 = self.rand_vec(3)
         target = np.kron(vec0, vec1)
         state = Statevector(vec0).tensor(Statevector(vec1))
         self.assertEqual(state.dim, 6)
         self.assertEqual(state.dims(), (3, 2))
         assert_allclose(state.data, target)
 def test_expand(self):
     """Test expand method."""
     for _ in range(10):
         vec0 = self.rand_vec(2)
         vec1 = self.rand_vec(3)
         target = np.kron(vec1, vec0)
         state = Statevector(vec0).expand(Statevector(vec1))
         self.assertEqual(state.dim, 6)
         self.assertEqual(state.dims(), (2, 3))
         assert_allclose(state.data, target)
    def test_init_circuit(self):
        """Test initialization from circuit."""
        circuit = QuantumCircuit(3)
        circuit.x(0)
        state = Statevector(circuit)

        self.assertEqual(state.dim, 8)
        self.assertEqual(state.dims(), (2, 2, 2))
        self.assertTrue(all(state.data == np.array([0, 1, 0, 0, 0, 0, 0, 0], dtype=complex)))
        self.assertEqual(state.num_qubits, 3)