ai4co / rl4co

A PyTorch library for all things Reinforcement Learning (RL) for Combinatorial Optimization (CO)

Home Page:https://rl4.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG]When I use the PTRNET model to run a TSP experiment, an error is reported:AttributeError("'PointerNetwork' object has no attribute 'env'")

lihaoya5 opened this issue · comments

Describe the bug

Change experiment:
Train model with chosen experiment configuration from configs/experiment/ (e.g. tsp/am, and environment with 42 cities)

I used python run.py experiment=archive/op/am to successfully run the experiment of finding the OP problem in the am model,but when I try to run a TSP experiment with the PTRNET model, I get an error.

Here's the command I used and the error message:
(rl4co) E:\rl4co-main>python run.py experiment=archive/tsp/ptrnet
[2024-03-11 11:02:58,330][rl4co.tasks.train][INFO] - Instantiating environment <rl4co.envs.TSPEnv>
[2024-03-11 11:02:58,911][rl4co.envs.common.base][WARNING] - Unused keyword arguments: name. Please check the documentation for the correct keyword arguments
[2024-03-11 11:02:58,911][rl4co.tasks.train][INFO] - Instantiating model <rl4co.models.PointerNetwork>
[2024-03-11 11:03:00,816][rl4co.utils.utils][ERROR] -
Traceback (most recent call last):
File "C:\Users\qian.conda\envs\rl6co\Lib\site-packages\hydra_internal\instantiate_instantiate2.py", line 92, in _call_target
return target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\rl4co-main\rl4co\models\zoo\ptrnet\model.py", line 33, in init
PointerNetworkPolicy(self.env, **policy_kwargs) if policy is None else policy
^^^^^^^^
File "C:\Users\qian.conda\envs\rl6co\Lib\site-packages\torch\nn\modules\module.py", line 1688, in getattr
raise AttributeError(f"'{type(self).name}' object has no attribute '{name}'")
AttributeError: 'PointerNetwork' object has no attribute 'env'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "E:\rl4co-main\rl4co\utils\utils.py", line 36, in wrap
metric_dict, object_dict = task_func(cfg=cfg)
^^^^^^^^^^^^^^^^^^
File "E:\rl4co-main\rl4co\tasks\train.py", line 44, in run
model: LightningModule = hydra.utils.instantiate(cfg.model, env)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\qian.conda\envs\rl6co\Lib\site-packages\hydra_internal\instantiate_instantiate2.py", line 226, in instantiate
return instantiate_node(
^^^^^^^^^^^^^^^^^
File "C:\Users\qian.conda\envs\rl6co\Lib\site-packages\hydra_internal\instantiate_instantiate2.py", line 347, in instantiate_node
return _call_target(target, partial, args, kwargs, full_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\qian.conda\envs\rl6co\Lib\site-packages\hydra_internal\instantiate_instantiate2.py", line 97, in _call_target
raise InstantiationException(msg) from e
hydra.errors.InstantiationException: Error in call to target 'rl4co.models.zoo.ptrnet.model.PointerNetwork':
AttributeError("'PointerNetwork' object has no attribute 'env'")
full_key: model
[2024-03-11 11:03:00,816][rl4co.utils.utils][INFO] - Output dir: E:\rl4co-main\logs\train\runs\tsp50\ptrnet-tsp50\2024-03-11_11-02-58
[2024-03-11 11:03:00,816][rl4co.utils.utils][INFO] - Closing loggers...
Error executing job with overrides: ['experiment=archive/tsp/ptrnet']
Error in call to target 'rl4co.models.zoo.ptrnet.model.PointerNetwork':
AttributeError("'PointerNetwork' object has no attribute 'env'")
full_key: model

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

suggestion:What I see in your documentation are examples of change experiments in the configs/experiment/ folder, can you provide more documentation for change experiments, such as /configs/experiment/archive
Experiment under the folder how to run up commands.

Hi @lihaoya5 , thanks for reporting the bug, now it should be fixed! Could you try again with a local installation?

I was able to run after redownloading, thank you very much.