PaddlePaddle / Quantum

Other
558 stars 177 forks source link

(NotFound) There are no kernels which are registered in the einsum operator. #37

Closed SSSSSCV closed 1 year ago

SSSSSCV commented 1 year ago

运行官网上的QGAN的例子时出现这个错误,运行失败。 image image image

buzzgamesnews commented 1 year ago

also encountered this bug Traceback (most recent call last): File "main.py", line 79, in <module> main() File "main.py", line 65, in main cut_bitstring, _ = find_cut(G, p, ITR, LR, print_loss=True, plot=True) File "c:\dropbox\python\quantum\quantum\paddle_quantum\QAOA\maxcut.py", line 87, in find_cut loss = -loss_func(state) File "C:\Users\user\anaconda3\envs\qnet_env\lib\site-packages\paddle\fluid\dygraph\layers.py", line 930, in __call__ return self._dygraph_call_func(*inputs, **kwargs) File "C:\Users\user\anaconda3\envs\qnet_env\lib\site-packages\paddle\fluid\dygraph\layers.py", line 915, in _dygraph_call_func outputs = self.forward(*inputs, **kwargs) File "c:\dropbox\python\quantum\quantum\paddle_quantum\loss\measure.py", line 117, in forward output_state = paddle.einsum('ia, ab->ib', matrix, _state_data).reshape([2 ** num_qubits]) File "C:\Users\user\anaconda3\envs\qnet_env\lib\site-packages\paddle\tensor\einsum.py", line 993, in einsum return einsum_v2(equation, *operands) File "C:\Users\user\anaconda3\envs\qnet_env\lib\site-packages\paddle\tensor\einsum.py", line 776, in einsum_v2 return gen_einsum_op(lhs + '->' + rhs, *operands) File "C:\Users\user\anaconda3\envs\qnet_env\lib\site-packages\paddle\tensor\einsum.py", line 805, in gen_einsum_op return _C_ops.einsum(operands, RuntimeError: (NotFound) There are no kernels which are registered in the einsum operator. [Hint: Expected kernels_iter != all_op_kernels.end(), but received kernels_iter == all_op_kernels.end().] (at C:\home\workspace\Paddle_release\paddle\fluid\imperative\prepared_operator.cc:341) [operator < einsum > error]

this exsample: cd paddle_quantum/QAOA/example python main.py

and TSP problem error in loss_func

Define the loss function

def loss_func(cir: Circuit, H: Hamiltonian) -> paddle.Tensor: state = cir() loss = paddle_quantum.loss.ExpecVal(H) return loss(state) <-- HERE

LeiZhang-116-4 commented 1 year ago

The function paddle.einsum in PaddlePaddle 2.3.1 does not work properly for complex tensors. Thus the problem should be solved by downgrading your PaddlePaddle version to 2.3.0.

buzzgamesnews commented 1 year ago

on default installed 2.3.2 when I try install PaddlePaddle 2.3.0 python -m pip install PaddlePaddle 2.3.0 got error: Collecting PaddlePaddle Using cached paddlepaddle-2.3.2-cp39-cp39-win_amd64.whl (64.3 MB) ERROR: Could not find a version that satisfies the requirement 2.3.0 (from versions: none) ERROR: No matching distribution found for 2.3.0

How install 2.3.0 ?

buzzgamesnews commented 1 year ago

Install it with - python -m pip install PaddlePaddle 2.3.0 fork fine! thx

buzzgamesnews commented 1 year ago

but. how to connect to real quantum computer for comparision performance for TSP example ? I try set backend: paddle_quantum.set_backend('quleaf')

and got error : Traceback (most recent call last): File "C:\Dropbox\Python\Quantum\tsp.py", line 98, in loss = loss_func(cir, H_C) File "C:\Dropbox\Python\Quantum\tsp.py", line 61, in loss_func return loss(state) File "C:\Program Files\Python39\lib\site-packages\paddle\fluid\dygraph\layers.py", line 930, in call return self._dygraph_call_func(*inputs, *kwargs) File "C:\Program Files\Python39\lib\site-packages\paddle\fluid\dygraph\layers.py", line 915, in _dygraph_call_func outputs = self.forward(inputs, **kwargs) File "C:\Program Files\Python39\lib\site-packages\paddle_quantum\loss\measure.py", line 94, in forward paddle.concat(state.param_list), File "C:\Program Files\Python39\lib\site-packages\paddle\tensor\manipulation.py", line 331, in concat return paddle.fluid.layers.concat(input=x, axis=axis, name=name) File "C:\Program Files\Python39\lib\site-packages\paddle\fluid\layers\tensor.py", line 343, in concat _C_ops.concat(input, out, 'axis', axis) ValueError: (InvalidArgument) concat(): argument 'X' (position 0) must be list of Tensors, but got empty list (at C:\home\workspace\Paddle_release\paddle\fluid\pybind\op_function_common.cc:768)

wangzihe1996 commented 1 year ago

This is a bug. Briefly, it will occur when your circuit has no trainable parameters.

buzzgamesnews commented 1 year ago

without backend bug not appears. but the backend set leads to failure TSP example: paddle_quantum.set_backend('quleaf')

wangzihe1996 commented 1 year ago

It only occurs when the backend is quleaf.

buzzgamesnews commented 1 year ago

please advise correct backend ?

wangzihe1996 commented 1 year ago

If you want to use the simulator, you can choose the 'state_vector' or 'density_matirx'. If you want to use the real quantum computer, you can just choose the 'quleaf' backend.

buzzgamesnews commented 1 year ago

hm. I do that, but not work. tutorials not work with real quleaf backend ? only simulations ?

LeiZhang-116-4 commented 1 year ago

This bug has been fixed by the latest version of PaddleQuantum. Note that token is required to access QPU. See here for more details.