You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using MPSs with cupy as backend and, since v1.9, I get a bug when using the measure method. I believe it is due to the changes in isel, because of the new "r" value for selectors as cupy apparently cannot compare cupy.array and string.
I think that changing the order of the tests in isel to have this case in the else part could do the trick.
Also worth noting that afaik this only happens with cupy, with other backends such as jax, torch, numpy all goes well.
What did you expect to happen?
I was trying to measure an MPS and this uses isel. I expected it to keep working as before.
Minimal Complete Verifiable Example
importquimb.tensorasqtnimportnumpyasnpimportcupyimportautorayfromfunctoolsimportpartialto_cupy=lambdax: cupy.array(x, dtype=cupy.complex64)
defcupy_choice(a, p=None):
returnpartial(cupy.random.choice, size=1)(a, p=p)[0]
autoray.register_function(
backend="cupy",
name="random.choice",
fn=cupy_choice
)
defgen_gates(N=40, x=0.1, depth=10, seed=42):
"""Generate a long range circuit that only slowly builds up entanglement. Parameters ---------- N : int, optional The number of qubits. x : float, optional The average angle magnitude of U3 rotations. depth : int, optional The number of fully entangling gate layers. seed : int, optional A random seed. Yields ------ qtn.Gate """rng=np.random.default_rng(seed)
qubits=list(range(N))
for_inrange(depth):
# random small single qubit rotationsforqinqubits:
yieldqtn.Gate("U3", params=rng.normal(scale=x, size=3), qubits=[q])
# random CZs between arbitrary qubit pairsrng.shuffle(qubits)
foriinrange(0, N, 2):
qa=qubits[i]
qb=qubits[i+1]
yieldqtn.Gate("CZ", params=(), qubits=[qa, qb])
circ=qtn.CircuitMPS(N=16, to_backend=to_cupy)
forgateingen_gates(N=circ.N):
circ.apply_gate(gate)
psi=circ.psim, psi=psi.measure(site=8)
Relevant log output
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
CellIn[15], line5855circ.apply_gate(gate)
57psi=circ.psi--->58m, psi=psi.measure(site=8)
File/home/qit/gpu_env/lib/python3.12/site-packages/quimb/tensor/tensor_1d.py:379, inconvert_cur_orthog.<locals>.wrapped(self, cur_orthog, info, *args, **kwargs)
376 @functools.wraps(fn)
377defwrapped(self, *args, cur_orthog=None, info=None, **kwargs):
378info=parse_cur_orthog(cur_orthog, info)
-->379returnfn(self, *args, info=info, **kwargs)
File/home/qit/gpu_env/lib/python3.12/site-packages/quimb/tensor/tensor_1d.py:3569, inMatrixProductState.measure(self, site, remove, outcome, renorm, info, get, inplace)
3566returnoutcome3568# project the outcome and renormalize->3569t.isel_({ind: outcome})
3571ifrenorm:
3572t.modify(data=t.data/p[outcome] **0.5)
File/home/qit/gpu_env/lib/python3.12/site-packages/quimb/tensor/tensor_core.py:1667, inTensor.isel(self, selectors, inplace)
1665new_inds.append(ix)
1666data_loc.append(sel)
->1667elifsel=="r":
1668# eagerly remove any 'random' selections1669T.rand_reduce_(ix)
1670else:
1671# index will be removed by selecting a specific indexFilecupy/_core/core.pyx:1217, incupy._core.core._ndarray_base.__richcmp__()
TypeError: operandtype(s) allreturnedNotImplementedfrom__array_ufunc__(<ufunc'equal'>, '__call__', array(0), 'r'): 'ndarray', 'str'
Anything else we need to know?
No response
Environment
I came across it on v1.10.0 but according to the changelog it dates back to v1.9.0
The text was updated successfully, but these errors were encountered:
What happened?
I've been using MPSs with cupy as backend and, since v1.9, I get a bug when using the
measure
method. I believe it is due to the changes inisel
, because of the new "r" value for selectors as cupy apparently cannot comparecupy.array
andstring
.I think that changing the order of the tests in
isel
to have this case in the else part could do the trick.Also worth noting that afaik this only happens with cupy, with other backends such as jax, torch, numpy all goes well.
What did you expect to happen?
I was trying to measure an MPS and this uses
isel
. I expected it to keep working as before.Minimal Complete Verifiable Example
Relevant log output
Anything else we need to know?
No response
Environment
I came across it on v1.10.0 but according to the changelog it dates back to v1.9.0
The text was updated successfully, but these errors were encountered: