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.

[question] How to Use --env-kwargs correctly?

See original GitHub issue

How do you use --env-kwargs correctly?

I have this code in a custom environment.

custom_env = gym.make('forex-v0',
               df = FOREX_EURUSD_1H_ASK,
               window_size = 10,
               frame_bound = (10, 300),
               unit_side = 'right')

let us say I want to use the df = FOREX_EURUSD_1H_ASK

–env-kwargs df = FOREX_EURUSD_1H_ASK post an error.


Traceback (most recent call last):
  File "train.py", line 79, in <module>
    args = parser.parse_args()
  File "C:\anaconda\envs\zootesting\lib\argparse.py", line 1755, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "C:\anaconda\envs\zootesting\lib\argparse.py", line 1787, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "C:\anaconda\envs\zootesting\lib\argparse.py", line 1993, in _parse_known_args
    start_index = consume_optional(start_index)
  File "C:\anaconda\envs\zootesting\lib\argparse.py", line 1933, in consume_optional
    take_action(action, args, option_string)
  File "C:\anaconda\envs\zootesting\lib\argparse.py", line 1861, in take_action
    action(self, namespace, argument_values, option_string)
  File "E:\ML\reinforcementlearning\zoo\rl-baselines-zoo\utils\utils.py", line 394, in __call__
    arg_dict[key] = eval(value)
  File "<string>", line 0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
caburucommented, Jun 26, 2020

@toksis I believe the problem is yet with the equal sign.

The other command line parameters has only one value. For example: for --algo, in a terminal, you could use --algo=acktr or --algo acktr, and both it would work. But for --env-kwargs you need to pass more than one value, so you can’t use the equal sign.

If you were using a terminal you would only need to replace the equal sign by space character. But this will not work with Visual Studio Code because when there is a space inside the arg, VS code put quotes around the arg. So I believe the solution is to separate the args.

Replace this line:

                     "--sampler=tpe","--pruner=median","--env-kwargs=df:'FOREX_EURUSD_1H_ASK' frame_bound:'(50, 100)' window_size:'10' "]

by this:

                     "--sampler=tpe","--pruner=median","--env-kwargs", "df:'FOREX_EURUSD_1H_ASK'", "frame_bound:'(50, 100)'", "window_size:'10'"]

And tell us if it works.

0reactions
toksiscommented, Jun 26, 2020

Thank you for your help @araffin and @caburu cabu. Sorry for the delay, but I did this directly after waking up hehe.

To this: image

From this: image

The way I put the argument in Launch.json is the culprit. It works now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use *args and **kwargs in Python 3 - DigitalOcean
In this tutorial, we will cover the syntax of working with *args and **kwargs as parameters within functions to pass a variable number...
Read more >
Proper way to use **kwargs in Python - Stack Overflow
I like to use positional arguments only for required arguments, and kwargs for arguments that may or may not be specified, but it...
Read more >
Working of kwargs in Python with Examples - eduCBA
In Python, we use kwargs that are keyword argument is used to when you provide a name to a variable as we pass...
Read more >
*args and **kwargs in python explained - Yasoob Khalid
This is just the basics of **kwargs and you can see how useful it is. Now lets talk about how you can use...
Read more >
Python args and kwargs: Demystified
To recap, the correct order for your parameters is: Standard arguments; *args arguments; **kwargs arguments. For example, this function definition is correct:.
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