def create(
        cls,
        *,
        initial_state: np.ndarray | cirq.STATE_VECTOR_LIKE = 0,
        qid_shape: tuple[int, ...] | None = None,
        dtype: type[np.complexfloating] | None = None,
        buffer: list[np.ndarray] | None = None,
    ):
        """Creates a buffered density matrix with the requested state.

        Args:
            initial_state: The initial state for the simulation in the computational basis.
            qid_shape: The shape of the density matrix, if the initial state is provided as an int.
            dtype: The desired dtype of the density matrix.
            buffer: Optional, must be length 3 and same shape as the density matrix. If not
                provided, a buffer will be created automatically.
        Raises:
            ValueError: If initial state is provided as integer, but qid_shape is not provided.
        """
        if not isinstance(initial_state, np.ndarray):
            if qid_shape is None:
                raise ValueError('qid_shape must be provided if initial_state is not ndarray')
            density_matrix = qis.to_valid_density_matrix(
                initial_state, len(qid_shape), qid_shape=qid_shape, dtype=dtype
            ).reshape(qid_shape * 2)
        else:
            if qid_shape is not None:
                if dtype and initial_state.dtype != dtype:
                    initial_state = initial_state.astype(dtype)
                density_matrix = qis.to_valid_density_matrix(
                    initial_state, len(qid_shape), qid_shape=qid_shape, dtype=dtype
                ).reshape(qid_shape * 2)
            else:
                density_matrix = initial_state  # pragma: no cover
            if np.may_share_memory(density_matrix, initial_state):
                density_matrix = density_matrix.copy()
        density_matrix = density_matrix.astype(dtype, copy=False)
        return cls(density_matrix, buffer)
Creates a buffered density matrix with the requested state.

        Args:
            initial_state: The initial state for the simulation in the computational basis.
            qid_shape: The shape of the density matrix, if the initial state is provided as an int.
            dtype: The desired dtype of the density matrix.
            buffer: Optional, must be length 3 and same shape as the density matrix. If not
                provided, a buffer will be created automatically.
        Raises:
            ValueError: If initial state is provided as integer, but qid_shape is not provided.
        
cirq-core/cirq/sim/density_matrix_simulation_state.py