Example #1
0
    def dirac_notation(self, decimals: int = 2) -> str:
        """Returns the state vector as a string in Dirac notation.

        Args:
            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."""
        return qis.dirac_notation(self.state_vector(), decimals, qid_shape=self._qid_shape)
 def __str__(self) -> str:
     samples = super().__str__()
     ret = f'measurements: {samples}'
     for substate in self._get_substates():
         final = substate.target_tensor
         shape = final.shape
         size = np.prod(shape, dtype=np.int64)
         final = final.reshape(size)
         if len([1 for e in final if abs(e) > 0.001]) < 16:
             state_vector = qis.dirac_notation(final, 3)
         else:
             state_vector = str(final)
         label = f'qubits: {substate.qubits}' if substate.qubits else 'phase:'
         ret += f'\n\n{label}\noutput vector: {state_vector}'
     return ret
def dirac_notation(*args, **kwargs):
    return qis.dirac_notation(*args, **kwargs)