%% Configure Options for A3C Training
% To train an agent using the asynchronous advantage actor-critic (A3C) method, you must set the agent and parallel training options appropriately.
%
% When creating the AC agent, set  the NumStepsToLookAhead value to be greater than 1. Common values are 64 and 128.

agentOpts = rlACAgentOptions('NumStepsToLookAhead',64);

% Use agentOpts when creating your agent.
% Configure the training algorithm to use asynchronous parallel training.

trainOpts = rlTrainingOptions('UseParallel',true);
trainOpts.ParallelizationOptions.Mode = "async";

% Configure the workers to return gradient data to the host. Also, set the number of steps before the workers send data back to the host to match the number of steps to look ahead.

trainOpts.ParallelizationOptions.DataToSendFromWorkers = "gradients";
trainOpts.ParallelizationOptions.StepsUntilDataIsSent = agentOpts.NumStepsToLookAhead;

% Use trainOpts when training your agent.
% Copyright 2019 The MathWorks, Inc.