tencent-quantum-lab / tensorcircuit

Tensor network based quantum software framework for the NISQ era
https://tensorcircuit.readthedocs.io
Apache License 2.0
265 stars 78 forks source link

c.to_qiskit()失败 #225

Open yulianhui opened 8 hours ago

yulianhui commented 8 hours ago

你好!我在使用tensorcircuit进行mnist分类过程中,想将量子线路转化为qiskit线路,并且进行真机模拟。但是遇到以下错误: File "/home/cpu_user_cpu/ylh_temporary/QUEST_IBMQ/mnist_2_qibm.py", line 67, in train_circuit quantum_model.train(x_train, y_train) File "/home/cpu_user_cpu/ylh_temporary/QUEST_IBMQ/model_file/model.py", line 163, in train self.model.fit(x_train, y_train_one_hot, batch_size=self.batch_size, epochs=self.epochs, validation_split=0.2) File "/home/cpu_user_cpu/condaenvstc/lib/python3.9/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler raise e.with_traceback(filtered_tb) from None File "/home/cpu_user_cpu/condaenvstc/lib/python3.9/site-packages/tensorcircuit/keras.py", line 122, in call result = tf.vectorized_map( File "/home/cpu_user_cpu/condaenvstc/lib/python3.9/site-packages/tensorcircuit/keras.py", line 123, in lambda vec: self.f(vec, *self.pqc_weights, *kwargs), File "/home/cpu_user_cpu/ylh_temporary/QUEST_IBMQ/model_file/model.py", line 89, in _qml qc = c.to_qiskit() File "/home/cpu_user_cpu/condaenvstc/lib/python3.9/site-packages/tensorcircuit/abstractcircuit.py", line 770, in to_qiskit return qir2qiskit( File "/home/cpu_user_cpu/condaenvstc/lib/python3.9/site-packages/tensorcircuit/translation.py", line 295, in qir2qiskit getattr(qiskit_circ, gate_name)(_get_float(parameters, "theta"), index) File "/home/cpu_user_cpu/condaenvstc/lib/python3.9/site-packages/tensorcircuit/translation.py", line 71, in _get_float return np.real(backend.numpy(gates.array_to_tensor(parameters.get(key, default)))).item() # type: ignore File "/home/cpu_user_cpu/condaenvstc/lib/python3.9/site-packages/tensorcircuit/backends/tensorflow_backend.py", line 475, in numpy return a.numpy() # only valid in eager mode AttributeError: Exception encountered when calling QuantumLayer.call().

Could not automatically infer the output shape / dtype of 'quantum_layer' (of type QuantumLayer). Either the QuantumLayer.call() method is incorrect, or you need to implement the QuantumLayer.compute_output_spec() / compute_output_shape() method. Error encountered:

'SymbolicTensor' object has no attribute 'numpy'

Arguments received by QuantumLayer.call(): • args=('<KerasTensor shape=(64, 10), dtype=float32, sparse=False, name=keras_tensor>',) • kwargs={'mask': 'None'}

Process finished with exit code 1

我猜测问题可能出现在张量图转化失败,但是不知道应该怎么解决。在这里请求您的帮助!

yulianhui commented 8 hours ago

我不是很明白,您能帮我解释一下吗