kengz / SLM-Lab

Modular Deep Reinforcement Learning framework in PyTorch. Companion library of the book "Foundations of Deep Reinforcement Learning".
https://slm-lab.gitbook.io/slm-lab/
MIT License
1.23k stars 263 forks source link

Problem Parsing Input Spec for Enjoy Mode Demo #469

Open fundmntlTheorem opened 3 years ago

fundmntlTheorem commented 3 years ago

I'm going through the demo with Ubuntu OS, and, things are working so far, and I get to the part about the enjoy mode. https://slm-lab.gitbook.io/slm-lab/using-slm-lab/resume-and-enjoy-reinforce-cartpole

This command is run, after having done a successful training run python run_lab.py slm_lab/spec/benchmark/reinforce/reinforce_cartpole.json reinforce_cartpole enjoy@data/reinforce_cartpole_2020_11_30_185405/reinforce_cartpole_t0_s0_spec.json

But it crashes with an error about parsing the input files

[2020-11-30 21:04:00,306 PID:4659 INFO run_lab.py read_spec_and_run] Running lab spec_file:slm_lab/spec/benchmark/reinforce/reinforce_cartpole.json spec_name:reinforce_cartpole in mode:enjoy@data/reinforce_cartpole_2020_11_30_185405/reinforce_cartpole_t0_s0_spec.json
Traceback (most recent call last):
  File "run_lab.py", line 80, in <module>
    main()
  File "run_lab.py", line 72, in main
    read_spec_and_run(*args)
  File "run_lab.py", line 53, in read_spec_and_run
    spec = spec_util.get_eval_spec(spec_file, prename)
  File "/home/philip/Documents/MachineLearning/SLM-Lab/slm_lab/spec/spec_util.py", line 166, in get_eval_spec
    predir, _, _, _, _, _ = util.prepath_split(spec_file)
  File "/home/philip/Documents/MachineLearning/SLM-Lab/slm_lab/lib/util.py", line 339, in prepath_split
    experiment_ts = RE_FILE_TS.findall(prefolder)[0]
IndexError: list index out of range

I could get the demo to run by modifying a few files. It may be a hack though because I don't know what all different inputs you may be expecting. Here's the change in the run_lab.py file...the case in the #eval mode has been modified

def read_spec_and_run(spec_file, spec_name, lab_mode):
    '''Read a spec and run it in lab mode'''
    logger.info(f'Running lab spec_file:{spec_file} spec_name:{spec_name} in mode:{lab_mode}')
    if lab_mode in TRAIN_MODES:
        spec = spec_util.get(spec_file, spec_name)
    else:  # eval mode
        lab_mode, base_path = lab_mode.split('@')
        # ex prename = reinforce_cartpole_t0_s0_spec.json
        _, _, prename, _, _, _ = util.prepath_split(base_path)
        # remove the _spec.json from the name
        prename = re.search('([\w\a\d\_]+)_spec\.json', prename).group(1)
        spec = spec_util.get_eval_spec(base_path, prename)