[go: nahoru, domu]

Skip to content

Commit

Permalink
Formats python for the entire tf_agents code base.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 550068074
Change-Id: Ia57ffa5e7a76a71d87880b37148d146ffdd413f6
  • Loading branch information
TF-Agents Team authored and Copybara-Service committed Jul 21, 2023
1 parent 3ae2b39 commit da4be6a
Show file tree
Hide file tree
Showing 500 changed files with 31,554 additions and 20,283 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/colab_kernel_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def SetDisplayFromWebTest():
assert res

# If we find "/tmp/.X11-unix/X1", then we will set DISPLAY to be ":1".
display = ":" + res[0][len(pattern)-1:]
display = ":" + res[0][len(pattern) - 1 :]
os.environ["DISPLAY"] = display
logging.info("Set DISPLAY=%s", display)

Expand Down
30 changes: 17 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ def main(_):
# issue when we import multiprocessing.pool.dummy down the line because
# the PYTHONPATH has changed.
for module in [
'multiprocessing', 'multiprocessing.pool', 'multiprocessing.dummy',
'multiprocessing.pool.dummy'
'multiprocessing',
'multiprocessing.pool',
'multiprocessing.dummy',
'multiprocessing.pool.dummy',
]:
if module in sys.modules:
del sys.modules[module]
Expand All @@ -113,7 +115,8 @@ def main(_):
gpus = tf.config.experimental.list_physical_devices('GPU')
for gpu in gpus:
tf.config.set_logical_device_configuration(
gpu, [tf.config.LogicalDeviceConfiguration(memory_limit=1024)])
gpu, [tf.config.LogicalDeviceConfiguration(memory_limit=1024)]
)

run_separately = load_test_list('test_individually.txt')
broken_tests = load_test_list(FLAGS.broken_tests)
Expand All @@ -138,13 +141,11 @@ def main(_):
for failure in external_test_failures:
stderr.writeln(str(failure))

final_output = (
'Tests run: {} grouped and {} external. '.format(
result.testsRun, len(run_separately)) +
'Errors: {} Failures: {} External failures: {}.'.format(
len(result.errors),
len(result.failures),
len(external_test_failures)))
final_output = 'Tests run: {} grouped and {} external. '.format(
result.testsRun, len(run_separately)
) + 'Errors: {} Failures: {} External failures: {}.'.format(
len(result.errors), len(result.failures), len(external_test_failures)
)

header = '=' * len(final_output)
stderr.writeln(header)
Expand All @@ -158,6 +159,7 @@ def main(_):

# Run inside absl.app.run to ensure flags parsing is done.
from tf_agents.system import system_multiprocessing as multiprocessing # pylint: disable=g-import-not-at-top

return multiprocessing.handle_test_main(lambda: app.run(main))


Expand Down Expand Up @@ -210,7 +212,7 @@ def get_test_packages():
'opencv-python >= 3.4.1.15',
'pybullet',
'scipy >= 1.1.0',
'tensorflow_datasets'
'tensorflow_datasets',
]
return test_packages

Expand Down Expand Up @@ -322,7 +324,8 @@ def run_setup():
parser.add_argument(
'--release',
action='store_true',
help='Pass as true to do a release build')
help='Pass as true to do a release build',
)
parser.add_argument(
'--tf-version',
type=str,
Expand Down Expand Up @@ -350,7 +353,8 @@ def run_setup():
'--broken_tests',
type=str,
default='broken_tests.txt',
help='Broken tests file to use.')
help='Broken tests file to use.',
)
FLAGS, unparsed = parser.parse_known_args()
# Go forward with only non-custom flags.
sys.argv.clear()
Expand Down
24 changes: 14 additions & 10 deletions tf_agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ def _ensure_tf_install(): # pylint: disable=g-statement-before-imports
import tensorflow as tf
except (ImportError, ModuleNotFoundError):
# Print more informative error message, then reraise.
print("\n\nFailed to import TensorFlow. Please note that TensorFlow is not "
"installed by default when you install TF Agents. This is so that "
"users can decide whether to install the GPU-enabled TensorFlow "
"package. To use TF Agents, please install the most recent version "
"of TensorFlow, by following instructions at "
"https://tensorflow.org/install.\n\n")
print(
"\n\nFailed to import TensorFlow. Please note that TensorFlow is not "
"installed by default when you install TF Agents. This is so that "
"users can decide whether to install the GPU-enabled TensorFlow "
"package. To use TF Agents, please install the most recent version "
"of TensorFlow, by following instructions at "
"https://tensorflow.org/install.\n\n"
)
raise

import distutils.version
Expand All @@ -53,14 +55,16 @@ def _ensure_tf_install(): # pylint: disable=g-statement-before-imports
required_tensorflow_version = "2.2.0"

tf_version = tf.version.VERSION
if (distutils.version.LooseVersion(tf_version) <
distutils.version.LooseVersion(required_tensorflow_version)):
if distutils.version.LooseVersion(
tf_version
) < distutils.version.LooseVersion(required_tensorflow_version):
raise ImportError(
"This version of TF Agents requires TensorFlow "
"version >= {required}; Detected an installation of version {present}. "
"Please upgrade TensorFlow to proceed.".format(
required=required_tensorflow_version,
present=tf_version))
required=required_tensorflow_version, present=tf_version
)
)


_ensure_tf_install()
Expand Down
1 change: 0 additions & 1 deletion tf_agents/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from tf_agents.agents import sac
from tf_agents.agents import td3
from tf_agents.agents import tf_agent

from tf_agents.agents.behavioral_cloning.behavioral_cloning_agent import BehavioralCloningAgent
from tf_agents.agents.categorical_dqn.categorical_dqn_agent import CategoricalDqnAgent
from tf_agents.agents.cql.cql_sac_agent import CqlSacAgent
Expand Down
Loading

0 comments on commit da4be6a

Please sign in to comment.