Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Pylint and code license headers pass
Browse files Browse the repository at this point in the history
  • Loading branch information
brilee committed Oct 1, 2018
1 parent 085c94f commit 37f8bc1
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 32 deletions.
13 changes: 0 additions & 13 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,17 @@ extension-pkg-whitelist=
# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=
# cloud_logging.py,
# coords.py,
dual_net.py,
# evaluation.py,
example_buffer.py,
features.py,
fsdb.py,
go.py,
gtp_cmd_handlers.py,
gtp_engine.py,
# gtp.py,
inference_worker.py,
local_rl_loop.py,
main.py,
mcts.py,
preprocessing.py,
rl_loop.py,
rl_runner.py,
# selfplay.py,
sgf_wrapper.py,
# shipname.py,
strategies.py,
symmetries.py,
# utils.py,

# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
Expand Down
30 changes: 25 additions & 5 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Bootstrap network weights.
Usage:
BOARD_SIZE=19 python bootstrap.py \
--work_dir=/tmp/estimator_working_dir \
--export_path=/tmp/published_models_dir
"""

import os

from absl import app, flags
Expand All @@ -11,14 +32,13 @@

FLAGS = flags.FLAGS

def bootstrap(export_path):
dual_net.bootstrap()
dual_net.export_model(export_path)

def main(unused_argv):
"""Bootstrap random weights."""
utils.ensure_dir_exists(os.path.dirname(FLAGS.export_path))
bootstrap(FLAGS.export_path)
dual_net.bootstrap()
dual_net.export_model(FLAGS.export_path)

if __name__ == '__main__':
flags.mark_flags_as_required(['work_dir', 'export_path'])
app.run(main)
app.run(main)
15 changes: 14 additions & 1 deletion rl_loop/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import subprocess

from absl import app, flags
import fsdb
Expand Down
2 changes: 1 addition & 1 deletion rl_loop/local_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

sys.path.insert(0, '.')

from absl import app, flags
from absl import app
from tensorflow import gfile

import example_buffer as eb
Expand Down
19 changes: 16 additions & 3 deletions rl_loop/prep_flags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

'''Filters flagfile to only pass in flags that are defined.
Having one big flagfile is great for seeing all the configuration at a glance.
Expand Down Expand Up @@ -67,9 +81,8 @@ def valid_argv(argv):
flagname_match = FLAG_RE.match(argv)
if not flagname_match:
return True
else:
flagname = flagname_match.group()
return flagname in valid_flags
flagname = flagname_match.group()
return flagname in valid_flags
filtered_flags = list(filter(valid_argv, parsed_flags))
return [subprocess_cmd[0]] + filtered_flags

Expand Down
8 changes: 5 additions & 3 deletions rl_loop/selfplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
# From rl_loop/fsdb.py
flags.declare_key_flag('bucket_name')

flags.DEFINE_enum('mode', ['cc', 'tpu'],
flags.DEFINE_enum('mode', None, ['cc', 'tpu'],
'Which setup to use: cc on GPU or cc/py on TPU.')

FLAGS = flags.FLAGS

def run_cc():
_, model_name = fsdb.get_latest_model()
num_games_finished = len(fsdb.get_games(model_name))
Expand Down Expand Up @@ -62,9 +64,9 @@ def run_tpu():

def main(unused_argv):
flags.mark_flags_as_required(['bucket_name', 'mode'])
if mode == 'cc':
if FLAGS.mode == 'cc':
run_cc()
elif mode == 'tpu':
elif FLAGS.mode == 'tpu':
run_tpu()

if __name__ == '__main__':
Expand Down
15 changes: 9 additions & 6 deletions rl_loop/train_and_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

import itertools
import os
import subprocess
import sys
import time

sys.path.insert(0, '.')

from absl import app, flags
from tensorflow import gfile
import fsdb
import prep_flags
import shipname
import utils

flags.DEFINE_string('pro_dataset', None,
Expand All @@ -37,6 +38,8 @@
flags.declare_key_flag('base_dir')
flags.declare_key_flag('bucket_name')

FLAGS = flags.FLAGS

try:
TPU_NAME = os.environ['TPU_NAME']
except KeyError:
Expand Down Expand Up @@ -70,16 +73,16 @@ def validate_holdout_selfplay():
holdout_dirs = (os.path.join(fsdb.holdout_dir(), d)
for d in reversed(gfile.ListDirectory(fsdb.holdout_dir()))
if gfile.IsDirectory(os.path.join(fsdb.holdout_dir(), d))
for f in gfile.ListDirectory(os.path.join(fsdb.holdout_dir(), d)))
for f in gfile.ListDirectory(os.path.join(fsdb.holdout_dir(), d)))

# This is a roundabout way of computing how many hourly directories we need
# to read in order to encompass 20,000 holdout games.
holdout_dirs = set(itertools.islice(holdout_dirs), 20000)
cmd = ['python', 'validate.py'] + list(holdout_dirs) + [
'--use_tpu',
'--tpu_name={}'.format(TPU_NAME),
'--flagfile=rl_loop/distributed_flags',
'--expand_validation_dirs']
'--use_tpu',
'--tpu_name={}'.format(TPU_NAME),
'--flagfile=rl_loop/distributed_flags',
'--expand_validation_dirs']
prep_flags.run(cmd)

def validate_pro():
Expand Down
14 changes: 14 additions & 0 deletions train.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Train a network.
Usage:
Expand Down
14 changes: 14 additions & 0 deletions validate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Validate a network.
Usage:
Expand Down

0 comments on commit 37f8bc1

Please sign in to comment.