question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature request] Parsing train's arguments from a list of strings

See original GitHub issue

Now that rl-baselines3-zoo is a package and the train function can be imported, I’d like to introduce the following feature

Current workflow

The learning is performed by calling a standalone python process such as:

python train.py <arguments>

Desired workflow

In an interactive programming environment such as jupyter notebooks I’d like it to behave as:

from rl_zoo3.train import train

argument_list: List[str] = [...]

train(argument_list)

This is possible because ArgumentParser’s method parse_args accepts a list of strings as input for parsing.

Changes to be introduced

A simple change on the behaviour of the train function should be enough, that is:

Option A:

rl_zoo3/train.py

import sys

def train(arguments_list: List[str] = sys.argv[1:]):
    ...
    args = parser.parse_args(arguments_list)

Option B:

rl_zoo3/train.py:

def train(arguments_list: List[str]):
    ...
    args = parser.parse_args(arguments_list)

train.py:

import sys
from rl_zoo3.train import train

if __name__ == "__main__":  # noqa: C901
    train(sys.argv[1:])

I’m more inclined to option B because it is much cleaner and straightforward to interpret what the program is doing.

Change purpose

When using jupyter notebook and the program raises an exception, the magic line %debug is used to inspect the stack frame, executing python train.py <args> forces us to use another method to live debug.

Final comments

All comments on why/why not the change should be done are always welcome. Also comments on how to improve my current workflow are welcome. Let me know if I can proceed with the PR.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
araffincommented, Oct 12, 2022

Hello, you have actually a simple (slightly hacky solution), which allows you to do what you want:

import sys
from rl_zoo3.train import train

sys.argv = ["python", "--algo", "ppo", "--env", "Pendulum-v1"]

train()
0reactions
araffincommented, Oct 12, 2022

so, different things: the zoo is not meant to be used from an interactive session (or only when debugging), if you need a more pythonic interface, you have the experiment manager and other utils available, or even SB3 api. Making the rl zoo a package was mainly to give access to the wrappers/callbacks/utils, and to be able to call the train/enjoy scripts from anywhere. I agree it’s not pretty but that’s only for debugging.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Three ways to parse arguments in your Python code
First, we initialize the parser and, then, we can add the arguments we want to access. This is an example to run the...
Read more >
Simple, Elegant, Typed Argument Parsing with argparse
Using dataclasses, simple-parsing makes it easier to share and reuse command-line arguments - no more copy pasting! Supports inheritance, nesting, easy ...
Read more >
Parsing a string as a Python argument list - Stack Overflow
I would like to parse a string that represents a Python argument list into a form that I can forward to a function...
Read more >
Additional documentation - yargs - JS.ORG
If key is an array, demand each element. If a msg string is given, it will be printed when the argument is missing,...
Read more >
Pipelines - Hugging Face
This will work whenever the pipeline uses its streaming ability (so when passing lists or Dataset or generator ). Copied. from transformers import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found