View source on GitHub |
Attempts to factor a state vector into two parts and return one of them.
cirq.sub_state_vector(
state_vector: np.ndarray,
keep_indices: List[int],
*,
default: np.ndarray = RaiseValueErrorIfNotProvided,
atol: Union[int, float] = 1e-06
) -> np.ndarray
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
.
Returns | |
---|---|
The state vector expressed over the desired subset of qubits. |