cirq.dirac_notation(state: Sequence, decimals: int = 2) → 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⟩
  • 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.

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