qdevpsi3 / qrl-dqn-gym

PennyLane/PyTorch implementation of Quantum agents in the Gym: a variational quantum algorithm for deep Q-learning (Skolik et al., 2021)
GNU General Public License v3.0
37 stars 10 forks source link

code error #2

Open DylanCZW opened 2 weeks ago

DylanCZW commented 2 weeks ago

when I run your code, I got this error: E:\anaconda\envs\qrl\lib\site-packages\gym\envs\registration.py:593: UserWarning: WARN: The environment CartPole-v0 is out of date. You should consider upgrading to version v1. logger.warn( E:\anaconda\envs\qrl\lib\site-packages\gym\core.py:317: DeprecationWarning: WARN: Initializing wrapper in old step API which returns one bool instead of two. It is recommended to set new_step_api=True to use new step API. This will be the default behaviour in future. deprecation( E:\anaconda\envs\qrl\lib\site-packages\gym\wrappers\step_api_compatibility.py:39: DeprecationWarning: WARN: Initializing environment in old step API which returns one bool instead of two. It is recommended to set new_step_api=True to use new step API. This will be the default behaviour in future. deprecation( E:\anaconda\envs\qrl\lib\site-packages\gym\core.py:256: DeprecationWarning: WARN: Function env.seed(seed) is marked as deprecated and will be removed in the future. Please use env.reset(seed=seed) instead. deprecation( E:\anaconda\envs\qrl\lib\site-packages\gym\utils\passive_envchecker.py:241: DeprecationWarning: np.bool8 is a deprecated alias for `np.bool`. (Deprecated NumPy 1.24) if not isinstance(terminated, (bool, np.bool8)): DQN: 0%| | 0/5000 [21:09<?, ?episode/s] Traceback (most recent call last): File "F:/bishe/code/qrl-dqn-gym/cart_pole/train.py", line 168, in main() File "F:/bishe/code/qrl-dqn-gym/cart_pole/train.py", line 160, in main trainer.learn(args.total_episodes, File "F:\bishe\code\qrl-dqn-gym\common\trainer.py", line 238, in learn train_stats = self.train_step() File "F:\bishe\code\qrl-dqn-gym\common\trainer.py", line 180, in train_step loss = self.update_net() File "F:\bishe\code\qrl-dqn-gym\common\trainer.py", line 135, in update_net state_action_values = self.net(states) File "E:\anaconda\envs\qrl\lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "E:\anaconda\envs\qrl\lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl return forward_call(*args, *kwargs) File "F:/bishe/code/qrl-dqn-gym/cart_pole/train.py", line 115, in forward outputs = self.q_layers(inputs) File "E:\anaconda\envs\qrl\lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl return self._call_impl(args, kwargs) File "E:\anaconda\envs\qrl\lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl return forward_call(args, kwargs) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\qnn\torch.py", line 404, in forward results = self._evaluate_qnode(inputs) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\qnn\torch.py", line 430, in _evaluate_qnode res = self.qnode(kwargs) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\workflow\qnode.py", line 1164, in call return self._impl_call(args, kwargs) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\workflow\qnode.py", line 1144, in _impl_call self.construct(args, kwargs) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\logging\decorators.py", line 61, in wrapper_entry return func(*args, *kwargs) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\workflow\qnode.py", line 966, in construct self._qfunc_output = self.func(args, kwargs) File "F:/bishe/code/qrl-dqn-gym/cart_pole/train.py", line 83, in circuit layer(n_qubits, y_weights[layer_idx], z_weights[layer_idx]) KeyboardInterrupt

Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)

How can I deal with it?

DylanCZW commented 2 weeks ago

File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\qnn\torch.py", line 404, in forward results = self._evaluate_qnode(inputs) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\qnn\torch.py", line 445, in _evaluate_qnode return _combine_dimensions(res) File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\qnn\torch.py", line 437, in _combine_dimensions _res = [torch.reshape(r, (x.shape[0], -1)) for r in _res] File "E:\anaconda\envs\qrl\lib\site-packages\pennylane\qnn\torch.py", line 437, in _res = [torch.reshape(r, (x.shape[0], -1)) for r in _res] RuntimeError: shape '[16, -1]' is invalid for input of size 4

Process finished with exit code 1 I think the batch size and qbit is confused.