I'd like to form some tensor products of sparse matrices, but this does not 
seem to work:

from sympy import diag
from sympy.physics.quantum import TensorProduct
from sympy.matrices import SparseMatrix

spm = SparseMatrix(diag(1,0))

tp = TensorProduct(spm,spm)


Here's the failure:

Traceback (most recent call last):
  File 
"/Users/ddahl/anaconda3/envs/qiskit/lib/python3.8/site-packages/IPython/core/interactiveshell.py",
 
line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-88417d1a4157>", line 1, in <module>
    tp = TensorProduct(spm,spm)
  File 
"/Users/ddahl/anaconda3/envs/qiskit/lib/python3.8/site-packages/sympy/physics/quantum/tensorproduct.py",
 
line 123, in __new__
    c_part, new_args = cls.flatten(sympify(args))
  File 
"/Users/ddahl/anaconda3/envs/qiskit/lib/python3.8/site-packages/sympy/physics/quantum/tensorproduct.py",
 
line 139, in flatten
    cp, ncp = arg.args_cnc()
  File 
"/Users/ddahl/anaconda3/envs/qiskit/lib/python3.8/site-packages/sympy/matrices/matrices.py",
 
line 2339, in __getattr__
    raise AttributeError(
AttributeError: ImmutableSparseMatrix has no attribute args_cnc.


When I look in sympy/physics/quantum/tensorproduct.py it looks to me like 
there is an attempted test to determine
whether the first argument to the TensorProduct(...) function is a sparse 
SciPy matrix:

def __new__(cls, *args):
    if isinstance(args[0], (Matrix, numpy_ndarray, scipy_sparse_matrix)):
        return matrix_tensor_product(*args)
    c_part, new_args = cls.flatten(sympify(args))
    c_part = Mul(*c_part)
    if len(new_args) == 0:
        return c_part
    elif len(new_args) == 1:
        return c_part * new_args[0]
    else:
        tp = Expr.__new__(cls, *new_args)
        return c_part * tp


But according to my debugger, the isinstance(...) call in the above code 
block returns false.
Looks to me like that sparse matrix should be of type scipy_sparse_matrix.

My environment is a freshly built Anaconda from two weeks ago and I'm 
running on macOS.

What am I missing?

Thanks,
-Denny


-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/478ff24e-d488-442d-927a-1865b2565850%40googlegroups.com.

Reply via email to