# cirq.to_valid_state_vector¶

cirq.to_valid_state_vector(state_rep: cirq.STATE_VECTOR_LIKE, num_qubits: Optional[int] = None, *, qid_shape: Optional[Sequence[int]] = None, dtype: Type[numpy.number] = <class 'numpy.complex64'>, atol: float = 1e-07) → numpy.ndarray[source]

Verifies the state_rep is valid and converts it to ndarray form.

This method is used to support passing in an integer representing a
computational basis state or a full wave function as a representation of
a state.
Parameters
• state_rep – If an int, the state returned is the state corresponding to a computational basis state. If an numpy array this is the full wave function. Both of these are validated for the given number of qubits, and the state must be properly normalized and of the appropriate dtype.

• num_qubits – The number of qubits for the state. The state_rep must be valid for this number of qubits.

• qid_shape – The expected qid shape of the state vector. Specify this argument when using qudits.

• dtype – The numpy dtype of the state, will be used when creating the state for a computational basis state, or validated against if state_rep is a numpy array.

• atol – Numerical tolerance for verifying that the norm of the state is close to 1.

Returns

A numpy ndarray corresponding to the state on the given number of qubits.

Raises

ValueError if the state is not valid or num_qubits != len(qid_shape)