cocoademon / rl-glue-ext

Exported from code.google.com/p/rl-glue-ext
http://glue.rl-community.org/
0 stars 0 forks source link

Figure out how to run Python agent, env, and experiment all from one python script. #63

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
We have it for Matlab (single-threaded) and Java (multi-threaded) now, I'm
sure we can do it for Python.

C/C++ is a little harder because we'd need to distribute
librl{agent,env,exp} that don't have a main, and we'd be using function
pointers.

I'm not sure about Lisp.

Original issue reported on code.google.com by brian.ta...@gmail.com on 7 Feb 2009 at 11:18

GoogleCodeExporter commented 8 years ago
Brian,

just in case it might help. The way I am doing this in python (launching 
experiment,
environment and agent from within a single script) is the following (please 
bare with
me this is a sample script, and many parts are missing, but you get the idea). 
You
need to invoke the python interpreter three times though (it doesn't launch
everything at once; I leave that as another exercise I haven't done yet).

class MySampleAgent(): pass
class MySampleExperiment(): pass
class MySampleEnvironment(): pass

def start_agent(agent):
    AgentLoader.loadAgent(agent)

def start_environment(environment):
    EnvironmentLoader.loadEnvironment(environment)

def start_experiment(experiment):
    experiment.init()
    experiment.start()
    experiment.run()
    experiment.cleanup()

if __name__=="__main__":
    import sys
    def usage():
        print "%s [agent|environment|experiment]" % sys.argv[0]

    if len(sys.argv) < 2: 
        usage()
        exit(0)

    role = sys.argv[1]
    if role == 'agent':
        start_agent(MySampleAgent())
    elif role == 'environment':
        start_environment(MySampleEnvironment())
    elif role == 'experiment':
        start_experiment(MySampleExperiment())
    else:
        usage()
        exit(0)

Original comment by ricardok...@gmail.com on 21 May 2009 at 2:36