Skip to content
fsmosca edited this page Oct 7, 2021 · 8 revisions
python tuner.py -h

usage: Optuna Game Parameter Tuner v5.0.0 [-h] --engine ENGINE [--draw-movenumber DRAW_MOVENUMBER]
                                          [--draw-movecount DRAW_MOVECOUNT] [--draw-score DRAW_SCORE]
                                          [--resign-movecount RESIGN_MOVECOUNT] [--resign-score RESIGN_SCORE]
                                          [--trials TRIALS] [--concurrency CONCURRENCY]
                                          [--games-per-trial GAMES_PER_TRIAL] [--study-name STUDY_NAME]
                                          [--base-time-sec BASE_TIME_SEC] [--inc-time-sec INC_TIME_SEC]
                                          [--depth DEPTH] [--nodes NODES] --opening-file OPENING_FILE
                                          [--opening-format OPENING_FORMAT] [--opening-posperfile OPENING_POSPERFILE]
                                          [--variant VARIANT] [--pgn-output PGN_OUTPUT] [--plot] [--elo-objective]
                                          [--noisy-result] [--save-plots-every-trial SAVE_PLOTS_EVERY_TRIAL]
                                          [--match-manager MATCH_MANAGER] [--protocol PROTOCOL]
                                          [--sampler [name= [option_name= ...]]]
                                          [--threshold-pruner [result= [games= ...]]] --input-param INPUT_PARAM [-v]
                                          [--common-param COMMON_PARAM]

Optimize parameter values of a game agent using optuna framework.

optional arguments:
  -h, --help            show this help message and exit
  --engine ENGINE       Engine filename or engine path and filename.
  --draw-movenumber DRAW_MOVENUMBER
                        Number of moves reached before applying the draw adjudication.
                        If not specified then draw adjudication will be disabled.
                        This should be used together with --draw-movecount and --draw-score. Example:
                        --draw-movenumber 40 --draw-movecount 6 --draw-score 0.
  --draw-movecount DRAW_MOVECOUNT
                        Number of move count reached before applying the draw adjudication, default=6.
                        This should be used together with --draw-movenumber and --draw-score. Example:
                        --draw-movenumber 40 --draw-movecount 6 --draw-score 0.
  --draw-score DRAW_SCORE
                        Score is in cp, default=0.
                        This should be used together with --draw-movenumber and --draw-movecount. Example:
                        --draw-movenumber 40 --draw-movecount 6 --draw-score 0.
  --resign-movecount RESIGN_MOVECOUNT
                        Number of move counts before the game is adjudicated as a loss.
                        This should be used together with --resign-score option. Example:
                        --resign-movecount 10 --resign-score 700
                        Will terminate the game when there are 10 successive -700 or worse score.
  --resign-score RESIGN_SCORE
                        Score is centipawn where the game is considered resignable.
                        This should be used together with --resign-movecount option.
  --trials TRIALS       Trials to try, default=1000.
  --concurrency CONCURRENCY
                        Number of game matches to run concurrently, default=1.
  --games-per-trial GAMES_PER_TRIAL
                        Number of games per trial, default=32.
                        This should be even number.
  --study-name STUDY_NAME
                        The name of study. This can be used to resume
                        study sessions, default=default_study_name.
  --base-time-sec BASE_TIME_SEC
                        Base time in sec for time control, default=5.
  --inc-time-sec INC_TIME_SEC
                        Increment time in sec for time control, default=0.05.
  --depth DEPTH         The maximum depth that the engine is allowed to search.
  --nodes NODES         The maximum nodes that the engine is allowed to search.
                        This is only applicable to cutechess match manager.
  --opening-file OPENING_FILE
                        Start opening filename in pgn, fen or epd format.
                        If match manager is cutechess, you can use pgn, fen
                        or epd format. The format is hard-coded currently.
                        You have to modify the code.
  --opening-format OPENING_FORMAT
                        Can be pgn, or epd for cutechess match manager,default is pgn, for duel.py no need as it will use epd or fen.
  --opening-posperfile OPENING_POSPERFILE
                        number of positions per startpos file for duel.py match manager only.
                        If not specified then all positions will be considered.
  --variant VARIANT     Game variant, default=normal.
  --pgn-output PGN_OUTPUT
                        Output pgn filename, default=optuna_games.pgn.
  --plot                A flag to output plots in png.
  --elo-objective       A flag to enable the elo as objective value instead of the default score rate.
  --noisy-result        A flag to replay engine vs engine match when sampler repeats suggesting same parameter values.
                        When you play an engine vs engine match at fixed depth, generally the result is not noisy.
                        When the sampler suggests a param that was already suggested before we just return the result from
                        the previous trial. However if you play an engine vs engine match with TC, the result is noisy
                        specially when number of games is low. If this flag is enabled, we replay an engine match even if
                        the param was already suggested before.
  --save-plots-every-trial SAVE_PLOTS_EVERY_TRIAL
                        Save plots every n trials, default=10.
  --match-manager MATCH_MANAGER
                        The application that handles the engine match, default=cutechess.
  --protocol PROTOCOL   The protocol that the engine supports, can be uci or cecp, default=uci.
  --sampler [name= [option_name= ...]]
                        The sampler to be used in the study, default name=tpe.
                        name can be tpe or cmaes or skopt, examples:
                        --sampler name=tpe n_ei_candidates=50 multivariate=true group=true seed=100 constant_liar=true n_startup_trials=6 ...
                          default values: n_ei_candidates=24, multivariate=false, group=false, seed=None, constant_liar=false, n_startup_trials=10
                          TPE ref: https://optuna.readthedocs.io/en/stable/reference/generated/optuna.samplers.TPESampler.html
                        --sampler name=cmaes sigma0=20 n_startup_trials=6 seed=100 ...
                          default values: sigma0 or initial std deviation is None, n_startup_trials=1, seed=None.
                          This tells cmaes that optimal parameter values
                          lies within init_value +/- 3 * sigma0. By default this value is the parameter minimum_range/6.
                          ref: https://optuna.readthedocs.io/en/stable/reference/generated/optuna.integration.PyCmaSampler.html
                        --sampler name=skopt acquisition_function=LCB random_state=100 acq_optimizer=lbfgs n_startup_trials=6 ...
                          default values: acquisition_function=gp_hedge, random_state is None, acq_optimizer=auto, can be sampling and lbfgs, n_startup_trials=1
                          acquisition_function can be LCB or EI or PI or gp_hedge
                          Example to explore, with LCB and kappa, high kappa would explore, low would exploit:
                          --sampler name=skopt acquisition_function=LCB kappa=10000
                          Example to exploit, with EI or PI and xi, high xi would explore, low would exploit:
                          --sampler name=skopt acquisition_function=EI xi=0.0001
                          Note: negative xi does not work with PI, but will work with EI.
                          Ref.: https://scikit-optimize.github.io/stable/auto_examples/exploration-vs-exploitation.html#sphx-glr-auto-examples-exploration-vs-exploitation-py
                          skopt has base_estimator options namely: GP, RF, ET and GBRT, default is GP.
                          GP=Gaussian Process, RF=Random Forest, ET=Extra Tree, GBRT=Gradient Boosted Regressor Tree.
                          Example:
                          --sampler name=skopt base_estimator=GBRT acquisition_function=EI ...
                          skopt has also a consider_pruned_trials parameter which is true by default. To not consider pruned trials use:
                          --sampler name=skopt consider_pruned_trials=false ...
                          consider_pruned_trials means that during sampling or finding the next best param values, the parameters
                          that failed or pruned will be taken into account.
                        --sampler name=botorch
                          A sampler based on BoTorch or Bayesian Optimization in PyTorch.
                          Ref.: https://github.com/pytorch/botorch
  --threshold-pruner [result= [games= ...]]
                        A trial pruner used to prune or stop unpromising trials. Example:
                        tuner.py --games-per-trial 100 --threshold-pruner result=0.45 games=50 interval=1 ...
                        After 50 partial games, check the score of the match, if this is below 0.45, then prune
                        the trial or stop the engine match, get new param from optimizer and start a new trial.
                        Default values: result=0.25, games=games_per_trial/2, interval=1
                        If --elo-objective flag is enabled, the result is in Elo, example:
                        tuner.py --games-per-trial 100 --elo-objective --threshold-pruner result=-10 ...
                        That would mean after 50 partial games, when result is below -10 Elo
                        then the trial is pruned, the other 50 games will not be played.
  --input-param INPUT_PARAM
                        The parameters that will be optimized.
                        Example 1 with 1 parameter:
                        --input-param "{'pawn': {'default': 92, 'min': 90, 'max': 120, 'step': 2}}"
                        Example 2 with 2 parameters:
                        --input-param "{'pawn': {'default': 92, 'min': 90, 'max': 120, 'step': 2}, 'knight': {'default': 300, 'min': 250, 'max': 350, 'step': 2}}"
                        Example 3 with 1 parameter but float value:
                        --input-param "{'CPuct': {'default': 0.5, 'min': 0.1, 'max': 3.0, 'step': 0.05, 'type': 'float'}}"
  -v, --version         show program's version number and exit
  --common-param COMMON_PARAM
                        The parameters that will be sent to both test and base engines.
                        Make sure that this param is not included in the input-param.
                        Example:
                        --common-param "{'RookOpenFile': 92, 'KnightOutpost': 300}"

Optuna Game Parameter Tuner v5.0.0