print("脚本执行完成。查看 'output.log' 获取打印输出,查看当前目录获取保存的图表。")
上述代码报错To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
Traceback (most recent call last):
File "C:\代码备份库\importance-sampling-master-yuanweihua-QNN-pennylane\examples\yuanweihua_renew_usesoftmax_NQNN.py", line 355, in
history = wrapped_model.fit(
File "C:\代码备份库\importance-sampling-master-yuanweihua-QNN-pennylane\importance_sampling\training.py", line 132, in fit
return self.fit_dataset(
File "C:\代码备份库\importance-sampling-master-yuanweihua-QNN-pennylane\importance_sampling\training.py", line 273, in fit_dataset
loss_value, metrics_results, scores = self.train_batch(x_batch, y_batch, w)
File "C:\代码备份库\importance-sampling-master-yuanweihua-QNN-pennylane\importance_sampling\training.py", line 336, in train_batch
y_pred = self.model.model(x, training=True)
File "C:\Users\liuwenjing.conda\envs\pennylane3\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\代码备份库\importance-sampling-master-yuanweihua-QNN-pennylane\examples\yuanweihua_renew_usesoftmax_NQNN.py", line 295, in call
q_output = self.quantum_layer(inputs)
File "C:\代码备份库\importance-sampling-master-yuanweihua-QNN-pennylane\examples\yuanweihua_renew_usesoftmax_NQNN.py", line 270, in call
q_output = tf.map_fn(
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filejpvnma68.py", line 6, in
tf__lam = lambda x: ag_.with_function_scope(lambda lscope: ag__.converted_call(quantum_neural_network, (x, self.weights_qnn), None, lscope), 'lscope', ag__.STD)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filejpvnma68.py", line 6, in
tf__lam = lambda x: ag_.with_function_scope(lambda lscope: ag__.converted_call(quantum_neural_network, (x, self.weights_qnn), None, lscope), 'lscope', ag__.STD)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filexf5nwm7n.py", line 384, in tf____call_
ag__.if_stmt(ag__.converted_call(ag__.ld(qml).active_return, (), None, fscope), if_body_20, else_body_20, get_state_20, set_state_20, ('do_return', 'retval_', 'self.device', "self.execute_kwargs['grad_on_execution']", 'self.gradient_fn', 'self.gradient_kwargs', 'self.interface'), 7)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filexf5nwm7n.py", line 88, in if_body_20
res = ag_.converted_call(ag__.ld(qml).execute, ([ag__.ld(self).tape],), dict(device=ag__.ld(self).device, gradient_fn=ag__.ld(self).gradient_fn, interface=ag__.ld(self).interface, gradient_kwargs=ag__.ld(self).gradient_kwargs, override_shots=ag__.ld(override_shots), **ag__.ld(self).execute_kwargs), fscope)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_fileaxbgx7mu.py", line 505, in tf__execute
ag_.if_stmt(ag__.not_(ag__.converted_call(ag__.ld(qml).active_return, (), None, fscope)), if_body_17, else_body_17, get_state_19, set_state_19, ('do_return', 'retval_', 'execute', 'cache', 'expand_fn', 'gradient_fn', 'gradient_kwargs', 'interface', 'tapes'), 2)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_fileaxbgx7mu.py", line 490, in else_body_17
ag.if_stmt(ag__.ld(gradient_fn) is None, if_body_16, else_body_16, get_state_18, set_state_18, ('do_return', 'retval_', 'execute', 'gradient_fn', 'tapes'), 2)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_fileaxbgx7mu.py", line 480, in else_body_16
ag.if_stmt(ag__.or_(lambda : ag__.ld(gradient_fn) == 'backprop', lambda : ag__.ld(interface) is None), if_body_15, else_body_15, get_state_17, set_state_17, ('do_return', 'retval_', 'execute', 'gradient_fn', 'tapes'), 2)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_fileaxbgx7mu.py", line 286, in if_body_15
retval = ag_.converted_call(ag__.ld(batch_fn), (ag__.converted_call(ag__.converted_call(ag__.ld(qml).interfaces.cache_execute, (ag__.ld(batch_execute), ag__.ld(cache)), dict(return_tuple=False, expand_fn=ag__.ld(expand_fn)), fscope), (ag__.ld(tapes),), None, fscope),), None, fscope)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_file9rxxqk87.py", line 373, in wrapper
ag_.if_stmt(ag__.or_(lambda : ag__.ld(cache) is None, lambda : ag__.and_(lambda : ag__.converted_call(ag__.ld(isinstance), (ag__.ld(cache), ag__.ld(bool)), None, fscope_2), lambda : ag__.not_(ag__.ld(cache)))), if_body_14, else_body_14, get_state_16, set_state_16, ('do_return_2', 'retval__2', 'res'), 2)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_file9rxxqk87.py", line 291, in else_body_14
ag_.if_stmt(ag__.not_(ag__.ld(execution_tapes)), if_body_10, else_body_10, get_state_11, set_state_11, ('do_return_2', 'res', 'retval__2'), 3)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_file9rxxqk87.py", line 289, in else_body_10
res = ag_.converted_call(ag__.ld(fn), (ag__.converted_call(ag__.ld(execution_tapes).values, (), None, fscope_2),), dict(**ag__.ld(kwargs)), fscope_2)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_file9rxxqk87.py", line 66, in fn
retval__1 = ag_.converted_call(ag__.ld(original_fn), (ag__.ld(tapes),), dict(**ag__.ld(kwargs)), fscope_1)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_fileprk7vcs8.py", line 20, in inner
retval__1 = ag_.converted_call(ag__.ld(func), tuple(ag__.ld(args)), dict(**ag__.ld(kwds)), fscope_1)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_fileooplhnce.py", line 82, in tf__batch_execute
ag_.if_stmt(ag__.not_(ag__.converted_call(ag__.ld(qml).active_return, (), None, fscope)), if_body_1, else_body_1, get_state_2, set_state_2, ('do_return', 'retval_'), 2)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_fileooplhnce.py", line 58, in else_body_1
ag_.for_stmt(ag__.ld(circuits), None, loop_body, get_state, set_state, (), {'iterate_names': 'circuit'})
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_fileooplhnce.py", line 54, in loop_body
res = ag_.converted_call(ag__.ld(self).execute, (ag__.ld(circuit),), None, fscope)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filefwao4ysq.py", line 111, in tf__execute
ag_.if_stmt(ag__.not_(ag__.converted_call(ag__.ld(qml).active_return, (), None, fscope)), if_body_3, else_body_3, get_state_3, set_state_3, ('do_return', 'retval_', 'self.num_executions', 'self.samples'), 4)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_filefwao4ysq.py", line 54, in else_body_3
ag.converted_call(ag_.ld(self).apply, (ag__.ld(circuit).operations,), dict(rotations=ag__.converted_call(ag__.ld(self).get_diagonalizing_gates, (ag_.ld(circuit),), None, fscope), **ag__.ld(kwargs)), fscope)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filexhfeixtr.py", line 108, in tf__apply
ag_.for_stmt(ag__.converted_call(ag__.ld(enumerate), (ag__.ld(operations),), None, fscope), None, loop_body, get_state_7, set_state_7, ('self.state',), {'iterate_names': '(i, operation)'})
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_filexhfeixtr.py", line 104, in loop_body
ag.if_stmt(ag__.converted_call(ag__.ld(isinstance), (ag__.ld(operation), ag__.ld(QubitStateVector)), None, fscope), if_body_6, else_body_6, get_state_6, set_state_6, ('self.debugger.snapshots[operation.tag]', 'self.state'), 2)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_filexhfeixtr.py", line 103, in else_body_6
ag.if_stmt(ag_.converted_call(ag__.ld(isinstance), (ag__.ld(operation), ag__.ld(BasisState)), None, fscope), if_body_5, else_body_5, get_state_5, set_state_5, ('self.debugger.snapshots[operation.tag]', 'self.state'), 2)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_filexhfeixtr.py", line 102, in else_body_5
ag.if_stmt(ag_.converted_call(ag__.ld(isinstance), (ag__.ld(operation), ag__.ld(Snapshot)), None, fscope), if_body_4, else_body_4, get_state_4, set_state_4, ('self.debugger.snapshots[operation.tag]', 'self.state'), 2)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_filexhfeixtr.py", line 101, in else_body_4
ag.if_stmt(ag_.converted_call(ag__.ld(isinstance), (ag__.ld(operation), ag__.ld(ParametrizedEvolution)), None, fscope), if_body_3, else_body_3, get_state_3, set_state_3, ('self.state',), 1)
File "C:\Users\LIUWEN~1\AppData\Local\Temp_autograph_generated_filexhfeixtr.py", line 100, in else_body_3
ag.ld(self).state = ag_.converted_call(ag__.ld(self).apply_operation, (ag_.ld(self).state, ag_.ld(operation)), None, fscope)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filex76y30qg.py", line 115, in tf___apply_operation
ag_.if_stmt(ag__.ld(operation).class.name == 'Identity', if_body_3, else_body_3, get_state_3, set_state_3, ('do_return', 'retval_'), 2)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filex76y30qg.py", line 110, in else_body_3
ag_.if_stmt(ag__.ld(operation).class.name in ag__.ld(self).apply_ops, if_body_2, else_body_2, get_state_2, set_state_2, ('do_return', 'retval'), 2)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filex76y30qg.py", line 106, in else_body_2
ag_.if_stmt(ag__.ld(operation) in ag__.ld(diagonal_in_z_basis), if_body_1, else_body_1, get_state_1, set_state_1, ('do_return', 'retval_'), 2)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filex76y30qg.py", line 105, in else_body_1
ag_.if_stmt(ag__.converted_call(ag__.ld(len), (ag__.ld(wires),), None, fscope) <= 2, if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filex76y30qg.py", line 92, in if_body
retval = ag__.converted_call(ag__.ld(self).apply_unitary_einsum, (ag_.ld(state), ag__.ld(matrix), ag__.ld(wires)), None, fscope)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filed3wsrzix.py", line 25, in tf___apply_unitary_einsum
batch_size = ag_.converted_call(ag__.ld(self).get_batch_size, (ag_.ld(mat), (ag__.ld(dim), ag__.ld(dim)), ag__.ld(dim) ** 2), None, fscope)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filewgt0wgg4.py", line 50, in tf___get_batch_size
ag_.if_stmt(ag__.not_(ag__.converted_call(ag__.ld(qml).math.is_abstract, (ag__.ld(tensor),), None, fscope)), if_body_1, else_body_1, get_state_1, set_state_1, (), 0)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filewgt0wgg4.py", line 46, in if_body_1
raise ag_.ld(err)
File "C:\Users\LIUWEN1\AppData\Local\Temp_autograph_generated_filewgt0wgg4.py", line 36, in tf___get_batch_size
ag_.if_stmt(ag__.or_(lambda : ag__.ld(ndim) > ag__.converted_call(ag__.ld(len), (ag__.ld(expected_shape),), None, fscope), lambda : ag__.ld(size) > ag__.ld(expected_size)), if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
ValueError: Exception encountered when calling layer "quantum_neural_network_layer" " f"(type QuantumNeuralNetworkLayer).