Skip to content

Commit

Permalink
Add better support for multiprocessing of usage: optuna [--version] […
Browse files Browse the repository at this point in the history
…-v | -q] [--log-file LOG_FILE] [-h] [--debug]

              [--config CONFIG] [--storage STORAGE]

optional arguments:
  --version            show program's version number and exit
  -v, --verbose        Increase verbosity of output. Can be repeated.
  -q, --quiet          Suppress output except warnings and errors.
  --log-file LOG_FILE  Specify a file to log output. Disabled by default.
  -h, --help           Show help message and exit.
  --debug              Show tracebacks on errors.
  --config CONFIG      Config file path. (default=$HOME/.optuna.yml)
  --storage STORAGE    DB URL. (e.g. sqlite:///example.db)

Commands:
  complete       print bash completion command (cliff)
  create-study
  dashboard
  help           print detailed help for another command (cliff)
  storage upgrade
  studies        Command base class for providing a list of data as output.
  study optimize
  study set-user-attr   optimizing.
  • Loading branch information
notadamking committed Jul 4, 2019
1 parent d81b2f9 commit 36d3717
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
9 changes: 3 additions & 6 deletions lib/RLTrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,11 @@ def optimize_params(self, trial, n_prune_evals_per_trial: int = 2, n_tests_per_e

del test_provider

n_envs = min(self.n_envs, 4)
n_minibatches = self.n_minibatches if n_envs % self.n_minibatches == 0 else n_envs

train_env = SubprocVecEnv([make_env(train_provider, i) for i in range(n_envs)])
validation_env = SubprocVecEnv([make_env(validation_provider, i) for i in range(n_envs)])
train_env = SubprocVecEnv([make_env(train_provider, i) for i in range(1)])
validation_env = SubprocVecEnv([make_env(validation_provider, i) for i in range(1)])

model_params = self.optimize_agent_params(trial)
model = self.Model(self.Policy, train_env, verbose=self.model_verbose, nminibatches=n_minibatches,
model = self.Model(self.Policy, train_env, verbose=self.model_verbose, nminibatches=1,
tensorboard_log=self.tensorboard_path, **model_params)

last_reward = -np.finfo(np.float16).max
Expand Down
25 changes: 22 additions & 3 deletions optimize.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import numpy as np

import multiprocessing
from lib.RLTrader import RLTrader

np.warnings.filterwarnings('ignore')

if __name__ == '__main__':
trader = RLTrader()

def optimize_code(params):
trader = RLTrader(**params)

trader.optimize()


if __name__ == '__main__':
n_process = multiprocessing.cpu_count()
params = {}

process = []
for i in range(n_process):
process.append(multiprocessing.Process(target=optimize_code, args=(params,)))

for p in process:
p.start()

for p in process:
p.join()

trader = RLTrader(**params)

trader.train(test_trained_model=True, render_trained_model=True)

0 comments on commit 36d3717

Please sign in to comment.