cirq.sub_state_vector
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: 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
.
Args |
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.
|
Returns |
The state vector expressed over the desired subset of qubits.
|
Raises |
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.
|
IndexError
|
If any indexes are out of range.
|
EntangledStateError
|
If the result of factoring is not a pure state and
default is not provided.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-15 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-04-15 UTC."],[],[]]