Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turn numpy to jax numpy in reshape.py #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/qutip_jax/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from . import JaxArray
import qutip
from functools import partial
import numpy as np

__all__ = [
"reshape_jaxarray",
Expand Down Expand Up @@ -64,14 +63,14 @@ def split_columns_jaxarray(matrix, copy=None):


def _parse_ptrace_inputs(dims, sel, shape):
dims = np.atleast_1d(dims).ravel()
sel = np.atleast_1d(sel)
dims = jnp.atleast_1d(dims).ravel()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since jnp is not defined in the header nothing will happen, maybe you should change jnp to JaxArray or import jax.numpy as jnp

sel = jnp.atleast_1d(sel)
sel.sort()

if shape[0] != shape[1]:
raise ValueError("ptrace is only defined for square density matrices")

if shape[0] != np.prod(dims, dtype=int):
if shape[0] != jnp.prod(dims, dtype=int):
raise ValueError(
f"the input matrix shape, {shape} and the"
f" dimension argument, {dims}, are not compatible."
Expand Down Expand Up @@ -110,11 +109,11 @@ def ptrace_jaxarray(matrix, dims, sel):
nd = dims.shape[0]
dims2 = tuple(list(dims) * 2)
sel = list(sel)
qtrace = list(set(np.arange(nd)) - set(sel))
qtrace = list(set(jnp.arange(nd)) - set(sel))


dkeep = np.prod([dims[x] for x in sel], dtype=int)
dtrace = np.prod([dims[x] for x in qtrace], dtype=int)
dkeep = jnp.prod([dims[x] for x in sel], dtype=int)
dtrace = jnp.prod([dims[x] for x in qtrace], dtype=int)

transpose_idx = tuple(
qtrace + [nd + q for q in qtrace]
Expand Down
Loading