Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stored configuration in another script #143

Closed
jdubkim opened this issue Jul 12, 2021 · 4 comments
Closed

Use stored configuration in another script #143

jdubkim opened this issue Jul 12, 2021 · 4 comments

Comments

@jdubkim
Copy link

jdubkim commented Jul 12, 2021

Hi, is it possible to store some of the configurations into a file and load them into another file?
For example, I have 'train.py' and a configuration file for this script.

@gin.configurable  
def train(agent, environment):  
    ...  

gin:

train.agent = @DQN
train.environment = @Gym
... # some other arguments not needed in eval.py

I have another script called 'eval.py', and I need to reload an agent and an environment.

@gin.configurable. 
def eval(agent, environment):  
    ...      

However, two functions have different names, I could not use the configuration file.

I tried to use '@gin.configurable('main')' to both functions, but since train takes additional arguments that is not needed in eval function, it did not work.

I also tried to create a function such as get_agent and get_environment which simply takes an argument and returns it, but this does not seem to be a good design choice.

Do you have any suggestion to resolve this issue?
Thank you.

@sguada
Copy link
Collaborator

sguada commented Jul 12, 2021

Yeah you can define a macro/constant for the agent and the environment and the use them as needed.

Ex:

AGENT = @DQN
ENV = @Gym

train.agent = %AGENT
train.environment = %ENV
... # some other arguments for train.py

eval.agent = %AGENT
eval.environment = %ENV
... # some other arguments for eval.py

@jdubkim
Copy link
Author

jdubkim commented Jul 12, 2021

Thank you for the reply. But if I run train.py with this configuration setup, it does not recognise eval function which results in an error. If I import eval function in train.py, it solves the issue, but I think this is not an ideal solution to this problem. Can you give an advice to this? That would be so helpful. Thank you.

@sguada
Copy link
Collaborator

sguada commented Jul 12, 2021

You should split the gin configuration in different files, one with the common parts, ex.. agent and env and then include it in the train.gin and the eval.gin files.

# common.gin
AGENT = @DQN
ENV = @Gym

# train.gin
include common.gin

train.agent = %AGENT
train.environment = %ENV
... # some other arguments for train.py

# eval.gin
include common.gin
eval.agent = %AGENT
eval.environment = %ENV
... # some other arguments for eval.py

@jdubkim
Copy link
Author

jdubkim commented Jul 13, 2021

Thank you so much, this was very helpful :)

@sguada sguada closed this as completed Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants