# cirq.linalg.sub_state_vector

Attempts to factor a state vector into two parts and return one of them.

The input state_vector must have shape (2,) * n or (2 ** n) where state_vector is expressed over n qubits. The returned array will retain the same type of shape as the input state vector, either (2 ** k) or (2,) * k where k is the number of qubits kept.

If a state vector $|\psi\rangle$ defined on n qubits is an outer product of kets like $|\psi\rangle$ = $|x\rangle \otimes |y\rangle$, and $|x\rangle$ is defined over the subset keep_indices of k qubits, then this method will factor $|\psi\rangle$ into $|x\rangle$ and $|y\rangle$ and return $|x\rangle$. Note that $|x\rangle$ is not unique, because scalar multiplication may be absorbed by any factor of a tensor product, $e^{i \theta} |y\rangle \otimes |x\rangle = |y\rangle \otimes e^{i \theta} |x\rangle$

This method randomizes the global phase of $|x\rangle$ in order to avoid accidental reliance on the global phase being some specific value.

If the provided state_vector cannot be factored into a pure state over keep_indices, the method will fall back to return default. If default is not provided, the method will fail and raise ValueError.

state_vector The target state_vector.
keep_indices Which indices to attempt to get the separable part of the state_vector on.
default Determines the fallback behavior when state_vector doesn't have a pure state factorization. If the factored state is not pure and default is not set, a ValueError is raised. If default is set to a value, that value is returned.
atol The minimum tolerance for comparing the output state's coherence measure to 1.

The state vector expressed over the desired subset of qubits.

ValueError if the state_vector is not of the correct shape or the indices are not a valid subset of the input state_vector's indices, or the result of factoring is not a pure state.