Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c.to_qiskit()失败 #225

Open
UESTC-YLH opened this issue Sep 19, 2024 · 2 comments
Open

c.to_qiskit()失败 #225

UESTC-YLH opened this issue Sep 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@UESTC-YLH
Copy link

你好!我在使用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

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

@UESTC-YLH UESTC-YLH added the bug Something isn't working label Sep 19, 2024
@UESTC-YLH
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
@UESTC-YLH and others