PaddlePaddle / Quantum

Other
567 stars 176 forks source link

Input object type error or incompatible array data type. tensor.set() supports array with bool, float16, float32, float64, int8, int16, int32, int64, uint8 or uint16, please check your input or input array data type. (at /paddle/paddle/fluid/pybind/tensor_py.h:411) #44

Open BoltzmannEntropy opened 1 year ago

BoltzmannEntropy commented 1 year ago

Hello, Has something changed in the API? This worked before.

image

! python -m pip install paddlepaddle paddle-quantum

LeiZhang-116-4 commented 1 year ago

Hi, can you please provide the package version for paddlepaddle and paddle-quantum?

BoltzmannEntropy commented 1 year ago
print (pq.__version__,paddle.__version__)
> 2.2.2 2.3.0

Before you ask me to upgrade to 2.4.xx .... please note:
I am on a no-avx machine, e.g an Ubunto docker running inside OSX with the M1 chip.

This is the installation command:

RUN python3.8 -m pip download paddlepaddle==2.3.0 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/noavx/stable.html --no-index --no-deps
RUN python3.8 -m pip install paddlepaddle-2.3.0-cp38-cp38-linux_x86_64.whl paddle-quantum==2.2.2 
LeiZhang-116-4 commented 1 year ago

The Gibbs State Preparation tutorial should work well for paddlepaddle==2.3.0 and paddlequantum==2.2.2, and the function state_fidelity was not changed since v2.2.2 (released in last December).

Can you specify more error information by expanding those "3 frames" in the screenshot?

BoltzmannEntropy commented 1 year ago
ValueError                                Traceback (most recent call last)
Cell In[7], line 27
     25             print (type(rho_B), type(rho_G))
     26             # Convert to Numpy array to calculate the fidelity of the quantum state F(rho_B, rho_G)
---> 27             fid = state_fidelity(rho_B, rho_G)
     29             # Print training results
     30 #             if itr % 10 == 0:
     31 #                 print('iter:', itr, 'loss:', '%.4f' % loss.numpy(), 'fid:', '%.4f' % fid.numpy())
     32             if itr == ITR:                
     33 #                 print(single_cir)

File ~/.local/lib/python3.8/site-packages/paddle_quantum/qinfo.py:155, in state_fidelity(rho, sigma)
    153 if type_rho == "numpy" and type_sigma == "numpy":
    154     return fidelity
--> 155 return paddle.to_tensor(fidelity)

File /opt/conda/lib/python3.8/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
    230 if not kwsyntax:
    231     args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File ~/.local/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py:25, in wrap_decorator.<locals>.__impl__(func, *args, **kwargs)
     22 @decorator.decorator
     23 def __impl__(func, *args, **kwargs):
     24     wrapped_func = decorator_func(func)
---> 25     return wrapped_func(*args, **kwargs)

File ~/.local/lib/python3.8/site-packages/paddle/fluid/framework.py:434, in _dygraph_only_.<locals>.__impl__(*args, **kwargs)
    431 def __impl__(*args, **kwargs):
    432     assert _non_static_mode(
    433     ), "We only support '%s()' in dynamic graph mode, please call 'paddle.disable_static()' to enter dynamic graph mode." % func.__name__
--> 434     return func(*args, **kwargs)

File ~/.local/lib/python3.8/site-packages/paddle/tensor/creation.py:184, in to_tensor(data, dtype, place, stop_gradient)
    176     return core.eager.Tensor(
    177         value=data,
    178         place=place,
   (...)
    181         name=None,
    182         stop_gradient=stop_gradient)
    183 else:
--> 184     return paddle.Tensor(
    185         value=data,
    186         place=place,
    187         persistable=False,
    188         zero_copy=False,
    189         stop_gradient=stop_gradient)

ValueError: (InvalidArgument) Input object type error or incompatible array data type. tensor.set() supports array with bool, float16, float32, float64, int8, int16, int32, int64, uint8 or uint16, please check your input or input array data type. (at /paddle/paddle/fluid/pybind/tensor_py.h:529)
LeiZhang-116-4 commented 1 year ago

Since state_fidelity mainly deals with numpy, one suggestion is to verify the data type of the variable fidelity between lines 154 and 155 in the file paddle_quantum.qinfo.py. If the data type is

It is kind of strange for paddle.to_tensor to report an error, especially in the function state_fidelity computed by numpy. If this tutorial in your machine went well in January or later, then it should work now because there was nothing changed for state_fidelity.

BoltzmannEntropy commented 1 year ago

Thank you so much for the response. Indeed, I amended the docker file, and now persisted it here for the record: https://github.com/BoltzmannEntropy/QMLDocker/blob/main/Dockerfile

Again, many thanks.