Skip to content

Instantly share code, notes, and snippets.

@shoyer
Created November 19, 2014 03:47
Show Gist options
  • Save shoyer/92f8beb8bf9b0a66da69 to your computer and use it in GitHub Desktop.
Save shoyer/92f8beb8bf9b0a66da69 to your computer and use it in GitHub Desktop.
def transform_state_vector(rho, U):
N = len(U)
if rho.shape[-1] == N:
# rho is in Hilbert space
pass
elif rho.shape[-1] == N ** 2:
# rho is in Liouville space
U = np.kron(U, U)
else:
raise ValueError('basis transformation incompatible with '
'operator dimensions')
return np.einsum('ij,...j->...i', U.T.conj(), rho)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment