cirq.dirac_notation¶

cirq.dirac_notation(state: Sequence, decimals: int = 2, qid_shape: Optional[Tuple[int, …]] = None) → str[source]

Returns the wavefunction as a string in Dirac notation.

For example:

state = np.array([1/np.sqrt(2), 1/np.sqrt(2)], dtype=np.complex64)
print(dirac_notation(state)) -> 0.71|0⟩ + 0.71|1⟩

Parameters
• state – A sequence representing a wave function in which the ordering mapping to qubits follows the standard Kronecker convention of numpy.kron.

• decimals – How many decimals to include in the pretty print.

Returns

A pretty string consisting of a sum of computational basis kets and non-zero floats of the specified accuracy.