Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path = os.path.dirname(__file__)
if args.agent_config:
# Use absolute path
agent_config = json.load(path + args.agent_config)
else:
raise TensorForceError("No agent configuration provided.")
if not args.network_spec:
raise TensorForceError("No network configuration provided.")
else:
network_spec = json.load(path + args.network_config)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO) # configurable!!!
agent = Agent.from_spec(
spec=agent_config,
kwargs=dict(
states=environment.states,
actions=environment.actions,
network=network_spec
)
)
if args.load:
load_dir = os.path.dirname(args.load)
if not os.path.isdir(load_dir):
raise OSError("Could not load agent from {}: No such directory.".format(load_dir))
agent.restore_model(args.load)
if args.debug:
logger.info("-" * 16)
logger.info("Configuration:")
distributed_spec=dict(
cluster_spec=cluster_spec,
task_index=args.task_index,
parameter_server=args.parameter_server,
device=('/job:{}/task:{}'.format('ps' if args.parameter_server else 'worker', args.task_index)), # '/cpu:0'
)
)
if args.network_spec:
with open(args.network_spec, 'r') as fp:
network_spec = json.load(fp=fp)
else:
network_spec = None
logger.info("No network configuration provided.")
agent = Agent.from_spec(
spec=args.agent,
kwargs=dict(
states_spec=environment.states,
actions_spec=environment.actions,
network_spec=network_spec,
config=config
)
)
logger.info("Starting distributed agent for OpenAI Gym '{gym_id}'".format(gym_id=args.gym_id))
logger.info("Config:")
logger.info(config)
runner = Runner(
agent=agent,
environment=environment,
if args.network_spec is not None:
with open(args.network_spec, 'r') as fp:
network_spec = json.load(fp=fp)
else:
network_spec = None
logger.info("No network configuration provided.")
agent_config['states_preprocessing'] = [{'type': 'flatten'}]
logger.info("Start training")
environment = OpenSim(env_id=1,visualize=True)
agent = Agent.from_spec(
spec=agent_config,
kwargs=dict(
states=environment.states,
actions=environment.actions,
network=network_spec,
)
)
runner = Runner(
agent=agent,
environment=environment,
repeat_actions=1
)
def episode_finished(r):
if r.episode % 100 == 0:
environment = MazeExplorer(mode_id=args.mode, visible=not args.hide)
if args.agent_config is not None:
with open(args.agent_config, 'r') as fp:
agent_config = json.load(fp=fp)
else:
raise TensorForceError("No agent configuration provided.")
if args.network_spec is not None:
with open(args.network_spec, 'r') as fp:
network = json.load(fp=fp)
else:
network = None
logger.info("No network configuration provided.")
agent = Agent.from_spec(
spec=agent_config,
kwargs=dict(
states=environment.states,
actions=environment.actions,
network=network
)
)
if args.load:
load_dir = os.path.dirname(args.load)
if not os.path.isdir(load_dir):
raise OSError("Could not load agent from {}: No such directory.".format(load_dir))
agent.restore_model(args.load)
if args.debug:
logger.info("-" * 16)