From eae6322736724bf743d7c2e92720be3f93883bd6 Mon Sep 17 00:00:00 2001 From: cnheider Date: Sat, 6 Feb 2021 23:18:12 +0100 Subject: [PATCH] move reqs --- .github/workflows/publish-to-test-pypi.yml | 10 +- .pre-commit-config.yaml | 11 +- .travis.yml | 10 +- __init__.py | 6 +- docs/source/conf.py | 247 +------- neodroid/__init__.py | 6 +- .../entry_points/action_space_sampling.py | 4 +- neodroid/entry_points/cli.py | 30 +- .../image_batch_observation_plot.py | 21 +- .../entry_points/keyboard/qweasd_input.py | 64 +- .../deprecated/batched_unity_environments.py | 41 +- .../deprecated/single_unity_environment.py | 110 ++-- .../droid_environment/unity_environment.py | 155 +++-- .../vector_unity_environment.py | 80 ++- neodroid/environments/environment.py | 97 ++- .../gym_environment/action_encoding.py | 10 +- .../gym_environment/gym_wrapper.py | 38 +- .../gym_environment/vector_gym_environment.py | 35 +- .../environments/networking_environment.py | 36 +- .../non_neodroidian_environments/blackjack.py | 70 +-- .../constant_environment.py | 62 +- .../contextual_bandit_environment.py | 26 +- .../fixed_sequence_environment.py | 26 +- .../non_neodroidian_environments/inventory.py | 9 +- .../mnist_environment.py | 34 +- .../python_environment/python_environment.py | 20 +- neodroid/factories/configuration_reactions.py | 39 +- neodroid/factories/motion_reactions.py | 58 +- .../single/single_reaction_factory.py | 95 ++- neodroid/messaging/fbs/fbs_state_utilties.py | 584 +++++++++--------- neodroid/messaging/message_client.py | 30 +- neodroid/utilities/exceptions/exceptions.py | 15 +- .../download_environment.py | 55 +- .../launcher/environment_launcher.py | 35 +- .../snapshot_extraction/camera_extraction.py | 38 +- .../vector_environment_snapshot.py | 6 +- neodroid/utilities/spaces/action_space.py | 40 +- .../utilities/spaces/observation_space.py | 6 +- neodroid/utilities/spaces/range.py | 151 +++-- neodroid/utilities/spaces/signal_space.py | 20 +- neodroid/utilities/spaces/space.py | 84 +-- .../spaces/vector/vector_action_space.py | 10 +- .../transformations/action_transformations.py | 28 +- .../utilities/transformations/encodings.py | 147 +++-- .../utilities/transformations/quaternion.py | 62 +- .../transformations/terminal_masking.py | 10 +- .../utilities/unity_specifications/actor.py | 32 +- .../unity_specifications/actuator.py | 16 +- .../unity_specifications/configurable.py | 28 +- .../unity_specifications/configuration.py | 22 +- .../unity_specifications/displayable.py | 22 +- .../environment_description.py | 100 ++- .../environment_snapshot.py | 134 ++-- .../utilities/unity_specifications/motion.py | 35 +- .../unity_specifications/reaction.py | 65 +- .../reaction_parameters.py | 52 +- .../utilities/unity_specifications/sensor.py | 28 +- .../simulator_configuration.py | 29 +- .../unity_specifications/unobservables.py | 28 +- pytest.ini | 5 + .../requirements_dev.txt | 0 .../requirements_docs.txt | 2 +- .../requirements_gui.txt | 0 requirements/requirements_setup.txt | 0 .../requirements_tests.txt | 0 .../requirements_webapp.txt | 0 .../requirements_wrappers.txt | 0 samples/experimental/deprecated/__init__.py | 6 +- .../multienv_action_space_sampling.py | 1 + samples/external_agents/berkley_agent.py | 22 +- .../generation/dataset/tf_record_generator.py | 15 +- samples/generation/web_app/app.py | 9 +- samples/generation/web_app/config.py | 4 +- samples/gui_client/gui.py | 9 +- samples/gui_client/main.py | 8 +- scripts/deprecated/clean_generated_files.bat | 9 + scripts/deprecated/clean_generated_files.sh | 7 + scripts/dev_install.sh | 3 + scripts/upload.bat | 9 + scripts/upload.sh | 4 + setup.py | 86 ++- tests/test_sanity.py | 33 +- 82 files changed, 1639 insertions(+), 1955 deletions(-) create mode 100644 pytest.ini rename requirements_dev.txt => requirements/requirements_dev.txt (100%) rename requirements_docs.txt => requirements/requirements_docs.txt (87%) rename requirements_gui.txt => requirements/requirements_gui.txt (100%) create mode 100644 requirements/requirements_setup.txt rename requirements_tests.txt => requirements/requirements_tests.txt (100%) rename requirements_webapp.txt => requirements/requirements_webapp.txt (100%) rename requirements_wrappers.txt => requirements/requirements_wrappers.txt (100%) create mode 100644 scripts/deprecated/clean_generated_files.bat create mode 100644 scripts/deprecated/clean_generated_files.sh create mode 100644 scripts/dev_install.sh create mode 100644 scripts/upload.bat create mode 100644 scripts/upload.sh diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml index eea4ee59..46c9f3c7 100644 --- a/.github/workflows/publish-to-test-pypi.yml +++ b/.github/workflows/publish-to-test-pypi.yml @@ -31,13 +31,17 @@ jobs: --out-dir dist/ . - name: Publish distribution 📦 to Test PyPI - if: endsWith(github.ref, 'master') + env: + test_pypi_password: ${{ secrets.test_pypi_password }} + if: env.test_pypi_password != null && endsWith(github.ref, 'master') uses: pypa/gh-action-pypi-publish@master with: - password: ${{ secrets.test_pypi_password }} + password: env.test_pypi_password repository_url: https://test.pypi.org/legacy/ - name: Publish distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags') + env: + pypi_password: ${{ secrets.pypi_password }} + if: env.pypi_password != null && startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@master with: password: ${{ secrets.pypi_password }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd8101a9..bb933678 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,15 @@ +fail_fast: true repos: - repo: https://github.com/ambv/black rev: stable hooks: - id: black - language_version: python3.7 \ No newline at end of file + language_version: python3.7 + - repo: local + hooks: + - id: pytest-check + name: pytest-check + entry: pytest + language: system + pass_filenames: false + always_run: true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 6e519d82..c52128b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ dist: xenial language: python python: - - '3.6' -# - '3.7' -# - '3.8' + - '3.7' + - '3.8' install: - pip install -r requirements.txt - - pip install -r requirements_dev.txt + - pip install -r requirements/requirements_dev.txt - pip install -e . script: - - pytest --cov=neodroid + - pytest --cov=yeet - coveralls + - black --check yeet diff --git a/__init__.py b/__init__.py index 25b20a6b..54e45b33 100644 --- a/__init__.py +++ b/__init__.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -__author__ = 'Christian Heider Nielsen' -__doc__ = r''' +__author__ = "Christian Heider Nielsen" +__doc__ = r""" Created on 30-09-2020 - ''' + """ diff --git a/docs/source/conf.py b/docs/source/conf.py index 1cac2867..ac957d27 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,244 +1,3 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Neo documentation build configuration file, created by -# sphinx-quickstart on Tue Jul 25 10:23:12 2017. -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -# -# needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.napoleon", - "sphinx.ext.doctest", - "sphinx.ext.intersphinx", - "sphinx.ext.todo", - "sphinx.ext.coverage", - "sphinx.ext.mathjax", - "sphinx.ext.viewcode", - "sphinx.ext.githubpages", -] - -napoleon_use_ivar = True - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# -# source_suffix = ['.rst', '.md'] -source_suffix = ".rst" - -# The master toctree document. -master_doc = "index" - -# General information about the project. -project = "Neo" -author = "Christian Heider Nielsen" -copyright = f"2017, {author}" - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# version = 'master (' + neodroid.__version__ + ' )' -release = "master" - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set 'language' from the command line for these cases. -language = None - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This patterns also effect to html_static_path and html_extra_path -exclude_patterns = [] - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = False - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# -# html_theme_options = {} - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named 'default.css' will overwrite the builtin 'default.css'. -html_static_path = ["_static"] - -# -- Options for HTMLHelp output ------------------------------------------ - -# Output file base name for HTML help builder. -htmlhelp_basename = "Neodoc" - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - (master_doc, "Neo.tex", "Neo Documentation", "Christian Heider Nielsen", "manual") -] - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [(master_doc, "neo", "Neo Documentation", [author], 1)] - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - master_doc, - "Neo", - "Neo Documentation", - author, - "Neo", - "One line description of project.", - "Miscellaneous", - ) -] - -# -- Options for Epub output ---------------------------------------------- - -# Bibliographic Dublin Core info. -epub_title = project -epub_author = author -epub_publisher = author -epub_copyright = copyright - -# The unique identifier of the text. This can be a ISBN number -# or the project homepage. -# -# epub_identifier = '' - -# A unique identification for the text. -# -# epub_uid = '' - -# A list of files that should not be packed into the epub file. -epub_exclude_files = ["search.html"] - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("https://docs.python.org/", None), - "numpy": ("http://docs.scipy.org/doc/numpy/", None), -} - -# -- A patch that prevents Sphinx from cross-referencing ivar tags ------- -# See http://stackoverflow.com/a/41184353/3343043 - -from docutils import nodes -from sphinx import addnodes -from sphinx.util.docfields import TypedField - - -def patched_make_field(self, types, domain, items, **kw): - # `kw` catches `env=None` needed for newer sphinx while maintaining - # backwards compatibility when passed along further down! - - # type: (List, unicode, Tuple) -> nodes.field - def handle_item(fieldarg, content): - par = nodes.paragraph() - par += addnodes.literal_strong("", fieldarg) # Patch: this line added - # par.extend(self.make_xrefs(self.rolename, domain, fieldarg, - # addnodes.literal_strong)) - if fieldarg in types: - par += nodes.Text(" (") - # NOTE: using .pop() here to prevent a single type node to be - # inserted twice into the doctree, which leads to - # inconsistencies later when references are resolved - fieldtype = types.pop(fieldarg) - if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text): - typename = "".join(n.astext() for n in fieldtype) - typename = typename.replace("int", "python:int") - typename = typename.replace("long", "python:long") - typename = typename.replace("float", "python:float") - typename = typename.replace("type", "python:type") - par.extend( - self.make_xrefs( - self.typerolename, - domain, - typename, - addnodes.literal_emphasis, - **kw, - ) - ) - else: - par += fieldtype - par += nodes.Text(")") - par += nodes.Text(" -- ") - par += content - return par - - field_name = nodes.field_name("", self.label) - if len(items) == 1 and self.can_collapse: - field_arg, content = items[0] - body_node = handle_item(field_arg, content) - else: - body_node = self.list_type() - for field_arg, content in items: - body_node += nodes.list_item("", handle_item(field_arg, content)) - field_body = nodes.field_body("", body_node) - return nodes.field("", field_name, field_body) - - -TypedField.make_field = patched_make_field +version https://git-lfs.github.com/spec/v1 +oid sha256:3fd5c2e27ccdca0ccf687fdeddae95a4b4b6ff7181c318b47755531bcec0f6dd +size 8490 diff --git a/neodroid/__init__.py b/neodroid/__init__.py index 770f2517..85ab2685 100644 --- a/neodroid/__init__.py +++ b/neodroid/__init__.py @@ -34,8 +34,7 @@ def dist_is_editable(dist: Any) -> bool: """ -Return True if given Distribution is an editable install. -""" + Return True if given Distribution is an editable install.""" for path_item in sys.path: egg_link = Path(path_item) / f"{dist.project_name}.egg-link" if egg_link.is_file(): @@ -47,7 +46,8 @@ def dist_is_editable(dist: Any) -> bool: PROJECT_VERSION = __version__ PROJECT_AUTHOR = __author__.lower().strip().replace(" ", "_") PROJECT_APP_PATH = AppPath(app_name=PROJECT_NAME, app_author=PROJECT_AUTHOR) - +PACKAGE_DATA_PATH = Path(pkg_resources.resource_filename(PROJECT_NAME, "data")) +INCLUDE_PROJECT_READMES = False DEFAULT_ENVIRONMENTS_PATH = (PROJECT_APP_PATH.user_cache / "environments").absolute() distributions = {v.key: v for v in pkg_resources.working_set} diff --git a/neodroid/entry_points/action_space_sampling.py b/neodroid/entry_points/action_space_sampling.py index 9d19909e..916c2feb 100644 --- a/neodroid/entry_points/action_space_sampling.py +++ b/neodroid/entry_points/action_space_sampling.py @@ -13,9 +13,7 @@ def main(): - """ - - """ + """""" parser = argparse.ArgumentParser(description="Neodroid Action Space Sampling") parser.add_argument( "--IP", "-ip", type=str, default="localhost", metavar="IP", help="IP Address" diff --git a/neodroid/entry_points/cli.py b/neodroid/entry_points/cli.py index 1ecb0e81..2aa27fb7 100644 --- a/neodroid/entry_points/cli.py +++ b/neodroid/entry_points/cli.py @@ -26,8 +26,7 @@ class NeodroidCLI(object): def run(self, env_name: str) -> None: """ -Run an environment -""" + Run an environment""" fail = False if os.path.exists(DEFAULT_ENVIRONMENTS_PATH): exe_path = f'{DEFAULT_ENVIRONMENTS_PATH}/{env_name}/{env_name.split("_")[0]}.x86_64' @@ -63,8 +62,7 @@ def run(self, env_name: str) -> None: @staticmethod def fetch(env_name: str) -> Path: """ -Fetches a remotely stored environment with the specified name to local storage -""" + Fetches a remotely stored environment with the specified name to local storage""" exe_path = download_environment( env_name, path_to_executables_directory=DEFAULT_ENVIRONMENTS_PATH ) @@ -73,15 +71,13 @@ def fetch(env_name: str) -> Path: def install(self, env_name: str) -> Path: """ -Fetches a remotely stored environment with the specified name to local storage -""" + Fetches a remotely stored environment with the specified name to local storage""" return self.fetch(env_name) @staticmethod def remove(env_name: str) -> None: """ -Removes locally stored environment with the specified name -""" + Removes locally stored environment with the specified name""" exe_path = f"{DEFAULT_ENVIRONMENTS_PATH}/{env_name}" shutil.rmtree(exe_path, ignore_errors=True) # os.remove(exe_path) @@ -89,8 +85,7 @@ def remove(env_name: str) -> None: def update(self, env_name: str) -> None: """ -Updates, fetches environment with the specified name again and replaces the previous version if present -""" + Updates, fetches environment with the specified name again and replaces the previous version if present""" if os.path.exists(DEFAULT_ENVIRONMENTS_PATH): self.remove(env_name) exe_path = self.fetch(env_name) @@ -99,16 +94,14 @@ def update(self, env_name: str) -> None: @staticmethod def clean() -> None: """ -Removes all locally stored environments -""" + Removes all locally stored environments""" if os.path.exists(DEFAULT_ENVIRONMENTS_PATH): shutil.rmtree(DEFAULT_ENVIRONMENTS_PATH, ignore_errors=True) print(f"{indent}cleaned, removed {DEFAULT_ENVIRONMENTS_PATH}") def ls_local(self) -> None: """ -Which environments are available locally -""" + Which environments are available locally""" envs = [] if os.path.exists(DEFAULT_ENVIRONMENTS_PATH): envs = os.listdir(DEFAULT_ENVIRONMENTS_PATH) @@ -122,23 +115,20 @@ def ls_local(self) -> None: @staticmethod def ls_remote() -> None: """ -Which environments are available on remote servers -""" + Which environments are available on remote servers""" envs = available_environments() for k, v in envs.items(): print(f"{indent}- {k}") def ls(self) -> None: """ -Same as ls_local result -""" + Same as ls_local result""" self.ls_local() @staticmethod def version() -> None: """ -Prints the version of this Neodroid installation. -""" + Prints the version of this Neodroid installation.""" draw_cli_header() print(f"Version: {get_version()}") diff --git a/neodroid/entry_points/image_batch_observation_plot.py b/neodroid/entry_points/image_batch_observation_plot.py index ccf2be64..5f4d1912 100644 --- a/neodroid/entry_points/image_batch_observation_plot.py +++ b/neodroid/entry_points/image_batch_observation_plot.py @@ -1,18 +1,27 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from draugr import batch_generator, horizontal_imshow -from draugr.torch_utilities import float_chw_to_hwc_uint_tensor, to_tensor, uint_hwc_to_chw_float_tensor +from draugr.torch_utilities import ( + float_chw_to_hwc_uint_tensor, + to_tensor, + uint_hwc_to_chw_float_tensor, +) from matplotlib import pyplot -from draugr.python_utilities.torch_channel_transform import reverse_torch_vision_normalize_batch_nchw, rgb_drop_alpha_batch_nhwc, torch_vision_normalize_batch_nchw +from draugr.python_utilities.torch_channel_transform import ( + reverse_torch_vision_normalize_batch_nchw, + rgb_drop_alpha_batch_nhwc, + torch_vision_normalize_batch_nchw, +) from neodroid.wrappers.observation_wrapper.mixed_observation_wrapper import ( MixedObservationWrapper, ) __author__ = "Christian Heider Nielsen" -__doc__ = r''' -''' +__doc__ = r""" +""" + def main(): env = MixedObservationWrapper() @@ -27,7 +36,9 @@ def main(): ) ) - inputs = float_chw_to_hwc_uint_tensor(reverse_torch_vision_normalize_batch_nchw(inputs)) + inputs = float_chw_to_hwc_uint_tensor( + reverse_torch_vision_normalize_batch_nchw(inputs) + ) horizontal_imshow(inputs, true_label, num_columns=5) pyplot.show() diff --git a/neodroid/entry_points/keyboard/qweasd_input.py b/neodroid/entry_points/keyboard/qweasd_input.py index cf33b0b5..c8a0da4f 100644 --- a/neodroid/entry_points/keyboard/qweasd_input.py +++ b/neodroid/entry_points/keyboard/qweasd_input.py @@ -11,9 +11,9 @@ def up() -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if "ActorY_" in ENVIRONMENT.description.actuators: return {"ActorY_": ENVIRONMENT.description.actuator("ActorY_").motion_space.max} raise KeyError(f"Could not find actuator ActorY_") @@ -22,9 +22,9 @@ def up() -> dict: def down() -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if "ActorY_" in ENVIRONMENT.description.actuators: return {"ActorY_": ENVIRONMENT.description.actuator("ActorY_").motion_space.min} raise KeyError(f"Could not find actuator ActorY_") @@ -33,9 +33,9 @@ def down() -> dict: def left() -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if "ActorX_" in ENVIRONMENT.description.actuators: return {"ActorX_": ENVIRONMENT.description.actuator("ActorX_").motion_space.min} raise KeyError(f"Could not find actuator ActorX_") @@ -44,9 +44,9 @@ def left() -> dict: def right() -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if "ActorX_" in ENVIRONMENT.description.actuators: return {"ActorX_": ENVIRONMENT.description.actuator("ActorX_").motion_space.max} raise KeyError(f"Could not find actuator ActorX_") @@ -55,9 +55,9 @@ def right() -> dict: def backward() -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if "ActorZ_" in ENVIRONMENT.description.actuators: return {"ActorZ_": ENVIRONMENT.description.actuator("ActorZ_").motion_space.min} raise KeyError(f"Could not find actuator ActorZ_") @@ -66,9 +66,9 @@ def backward() -> dict: def forward() -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if "ActorZ_" in ENVIRONMENT.description.actuators: return {"ActorZ_": ENVIRONMENT.description.actuator("ActorZ_").motion_space.max} raise KeyError(f"Could not find actuator ActorZ_") @@ -77,9 +77,9 @@ def forward() -> dict: def reset() -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return "reset" @@ -105,9 +105,9 @@ def reset() -> str: def listen_for_combinations(): """ - @return: - @rtype: - """ + @return: + @rtype: + """ print(f"\n\nPress any of:\n{COMBINATIONS}\n\n") print("") return keyboard.Listener(on_press=on_press, on_release=on_release) @@ -116,9 +116,9 @@ def listen_for_combinations(): def on_press(key): """ - @param key: - @type key: - """ + @param key: + @type key: + """ global STEP_I if any([key in COMBINATIONS]): if key not in CURRENT_COMBINATIONS: @@ -146,18 +146,16 @@ def on_press(key): def on_release(key): """ - @param key: - @type key: - """ + @param key: + @type key: + """ if any([key in COMBINATIONS]): if key in CURRENT_COMBINATIONS: CURRENT_COMBINATIONS.remove(key) def main(): - """ - - """ + """""" with listen_for_combinations() as listener: listener.join() diff --git a/neodroid/environments/droid_environment/deprecated/batched_unity_environments.py b/neodroid/environments/droid_environment/deprecated/batched_unity_environments.py index a8c512ef..0fefbb7e 100644 --- a/neodroid/environments/droid_environment/deprecated/batched_unity_environments.py +++ b/neodroid/environments/droid_environment/deprecated/batched_unity_environments.py @@ -11,9 +11,7 @@ class BatchedUnityEnvironment(UnityEnvironment): - """ - - """ + """""" def __init__(self, **kwargs): super().__init__(**kwargs) @@ -89,23 +87,19 @@ def _react(self, reactions=None, **kwargs): class VectorWrapper: - """ - - """ + """""" def __init__(self, env: UnityEnvironment): """ -:param env: -""" + :param env:""" self._env = env @property def observation_space(self) -> ObservationSpace: """ -:return: -""" + :return:""" _input_shape = None if len(next(iter(self._env._observation_space.values())).shape) >= 1: @@ -127,8 +121,7 @@ def observation_space(self) -> ObservationSpace: def action_space(self) -> ActionSpace: """ -:return: -""" + :return:""" _output_shape = None if len(next(iter(self._env.action_space.values())).shape) >= 1: @@ -150,15 +143,15 @@ def action_space(self) -> ActionSpace: def react(self, a, *args, **kwargs): """ - @param a: - @type a: - @param args: - @type args: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param a: + @type a: + @param args: + @type args: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ if isinstance(a, numpy.ndarray): a = a.tolist() @@ -171,9 +164,9 @@ def react(self, a, *args, **kwargs): def reset(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ info = self._env.reset() info = next(iter(info.values())) diff --git a/neodroid/environments/droid_environment/deprecated/single_unity_environment.py b/neodroid/environments/droid_environment/deprecated/single_unity_environment.py index aaac8597..b4cce7be 100644 --- a/neodroid/environments/droid_environment/deprecated/single_unity_environment.py +++ b/neodroid/environments/droid_environment/deprecated/single_unity_environment.py @@ -27,9 +27,9 @@ class SingleUnityEnvironment(UnityEnvironment): def description(self) -> EnvironmentDescription: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._description: self.describe() return next(iter(self._description.values())) @@ -38,9 +38,9 @@ def description(self) -> EnvironmentDescription: def observation_space(self) -> ObservationSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._observation_space: self.describe() return next(iter(self._observation_space.values())) @@ -49,9 +49,9 @@ def observation_space(self) -> ObservationSpace: def action_space(self) -> ActionSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._action_space: self.describe() return next(iter(self._action_space.values())) @@ -60,9 +60,9 @@ def action_space(self) -> ActionSpace: def signal_space(self) -> SignalSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._signal_space: self.describe() return next(iter(self._signal_space.values())) @@ -77,17 +77,17 @@ def react( ) -> EnvironmentSnapshot: """ - @param input_reaction: - @type input_reaction: - @param parameters: - @type parameters: - @param normalise: - @type normalise: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param input_reaction: + @type input_reaction: + @param parameters: + @type parameters: + @param normalise: + @type normalise: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ if not isinstance(input_reaction, Reaction): input_reaction = verify_motion_reaction( reaction_input=input_reaction, @@ -112,15 +112,15 @@ def reset( ) -> EnvironmentSnapshot: """ - @param input_reaction: - @type input_reaction: - @param state: - @type state: - @param on_reset_callback: - @type on_reset_callback: - @return: - @rtype: - """ + @param input_reaction: + @type input_reaction: + @param state: + @type state: + @param on_reset_callback: + @type on_reset_callback: + @return: + @rtype: + """ input_reaction = verify_configuration_reaction( input_reaction=input_reaction, environment_description=self.description ) @@ -136,25 +136,25 @@ def reset( def configure(self, *args, **kwargs) -> EnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ return self.reset(*args, **kwargs) def describe(self, *args, **kwargs) -> EnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ new_states = super().describe(*args, **kwargs) message = list(new_states.values())[0] return message @@ -162,15 +162,15 @@ def describe(self, *args, **kwargs) -> EnvironmentSnapshot: def sensor(self, name, *args, **kwargs) -> Sensor: """ - @param name: - @type name: - @param args: - @type args: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param name: + @type name: + @param args: + @type args: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ state_env_0 = list(self._last_snapshots.values())[0] sens = state_env_0.sensor(name) if not sens: diff --git a/neodroid/environments/droid_environment/unity_environment.py b/neodroid/environments/droid_environment/unity_environment.py index fef40b4d..ea51559d 100644 --- a/neodroid/environments/droid_environment/unity_environment.py +++ b/neodroid/environments/droid_environment/unity_environment.py @@ -30,9 +30,7 @@ class UnityEnvironment(NetworkingEnvironment): - """ - - """ + """""" def __init__( self, @@ -81,9 +79,9 @@ def __init__( def description(self) -> Mapping[str, EnvironmentDescription]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._description: self.describe() return self._description @@ -92,9 +90,9 @@ def description(self) -> Mapping[str, EnvironmentDescription]: def observation_space(self) -> Mapping[str, ObservationSpace]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._observation_space: self.describe() return self._observation_space @@ -103,9 +101,9 @@ def observation_space(self) -> Mapping[str, ObservationSpace]: def action_space(self) -> Mapping[str, ActionSpace]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._action_space: self.describe() return self._action_space @@ -114,9 +112,9 @@ def action_space(self) -> Mapping[str, ActionSpace]: def signal_space(self) -> Mapping[str, SignalSpace]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._signal_space: self.describe() return self._signal_space @@ -125,9 +123,9 @@ def signal_space(self) -> Mapping[str, SignalSpace]: def simulator_configuration(self) -> SimulatorConfiguration: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._simulator_configuration: self.describe() return self._simulator_configuration @@ -136,19 +134,19 @@ def simulator_configuration(self) -> SimulatorConfiguration: def neodroid_api_version(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return __version__ def sensor(self, name: str): """ - @param name: - @type name: - @return: - @rtype: - """ + @param name: + @type name: + @return: + @rtype: + """ envs = list(self._last_snapshots.values()) observer = [] @@ -181,13 +179,13 @@ def _setup_connection(self, auto_describe=True): def configure(self, *args, **kwargs) -> Mapping[str, EnvironmentSnapshot]: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ return self.reset(*args, **kwargs) def react( @@ -202,19 +200,18 @@ def react( ) -> Mapping[str, EnvironmentSnapshot]: """ -:param input_reactions: -:type input_reactions: -:param parameters: -:type parameters: -:param normalise: -:type normalise: -:param on_reaction_sent_callback: -:type on_reaction_sent_callback: -:param on_step_done_callback: -:type on_step_done_callback: -:return: -:rtype: -""" + :param input_reactions: + :type input_reactions: + :param parameters: + :type parameters: + :param normalise: + :type normalise: + :param on_reaction_sent_callback: + :type on_reaction_sent_callback: + :param on_step_done_callback: + :type on_step_done_callback: + :return: + :rtype:""" logging.info("Reacting in environment") if ( @@ -243,11 +240,11 @@ def react( def send(self, input_reactions): """ - @param input_reactions: - @type input_reactions: - @return: - @rtype: - """ + @param input_reactions: + @type input_reactions: + @return: + @rtype: + """ (new_snapshots, simulator_configuration) = self._message_server.send_receive( input_reactions ) @@ -265,11 +262,11 @@ def send(self, input_reactions): def display(self, displayables) -> Mapping[str, EnvironmentSnapshot]: """ - @param displayables: - @type displayables: - @return: - @rtype: - """ + @param displayables: + @type displayables: + @return: + @rtype: + """ conf_reaction = Reaction(displayables=displayables) message = self.reset(conf_reaction) if message: @@ -280,15 +277,15 @@ def reset( ) -> Mapping[str, EnvironmentSnapshot]: """ - @param input_reactions: - @type input_reactions: - @param state: - @type state: - @param on_reset_callback: - @type on_reset_callback: - @return: - @rtype: - """ + @param input_reactions: + @type input_reactions: + @param state: + @type state: + @param on_reset_callback: + @type on_reset_callback: + @return: + @rtype: + """ logging.info("Resetting environment") if input_reactions is None: @@ -302,11 +299,10 @@ def reset( def _close(self, callback=None): """ -:param callback: -:type callback: -:return: -:rtype: -""" + :param callback: + :type callback: + :return: + :rtype:""" logging.info("Closing") # if self._message_server: # self._message_server.__del__() @@ -319,11 +315,10 @@ def _close(self, callback=None): def describe(self) -> Mapping[str, EnvironmentSnapshot]: """ -:param parameters: -:type parameters: -:return: -:rtype: -""" + :param parameters: + :type parameters: + :return: + :rtype:""" reaction = Reaction( parameters=ReactionParameters( terminable=False, describe=True, episode_count=False @@ -335,11 +330,11 @@ def describe(self) -> Mapping[str, EnvironmentSnapshot]: def update_interface_attributes(self, new_states, new_simulator_configuration): """ - @param new_states: - @type new_states: - @param new_simulator_configuration: - @type new_simulator_configuration: - """ + @param new_states: + @type new_states: + @param new_simulator_configuration: + @type new_simulator_configuration: + """ if not self._description: self._description = {} if not self._action_space: diff --git a/neodroid/environments/droid_environment/vector_unity_environment.py b/neodroid/environments/droid_environment/vector_unity_environment.py index b9b3c265..b3a20829 100644 --- a/neodroid/environments/droid_environment/vector_unity_environment.py +++ b/neodroid/environments/droid_environment/vector_unity_environment.py @@ -23,9 +23,7 @@ class VectorUnityEnvironment(UnityEnvironment): - """ - - """ + """""" def __next__(self) -> Union[VectorEnvironmentSnapshot, None]: if not self._is_connected_to_server: @@ -38,13 +36,13 @@ def react( ) -> VectorEnvironmentSnapshot: """ - @param input_reactions: - @type input_reactions: - @param parameters: - @type parameters: - @return: - @rtype: - """ + @param input_reactions: + @type input_reactions: + @param parameters: + @type parameters: + @return: + @rtype: + """ if not isinstance(input_reactions, Reaction): input_reactions = verify_motion_reactions( input_reactions=input_reactions, @@ -62,15 +60,15 @@ def reset( ) -> VectorEnvironmentSnapshot: """ - @param input_reactions: - @type input_reactions: - @param state: - @type state: - @param on_reset_callback: - @type on_reset_callback: - @return: - @rtype: - """ + @param input_reactions: + @type input_reactions: + @param state: + @type state: + @param on_reset_callback: + @type on_reset_callback: + @return: + @rtype: + """ input_reactions = verify_configuration_reactions( input_reactions=input_reactions, environment_descriptions=self._description ) @@ -80,30 +78,30 @@ def reset( def configure(self, *args, **kwargs) -> VectorEnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ return self.reset(*args, **kwargs) def describe(self) -> VectorEnvironmentSnapshot: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return VectorEnvironmentSnapshot(super().describe()) @property def action_space(self) -> VectorActionSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._action_space: self.describe() return VectorActionSpace( @@ -114,9 +112,9 @@ def action_space(self) -> VectorActionSpace: def description(self) -> EnvironmentDescription: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._description: self.describe() return next(iter(self._description.values())) @@ -125,9 +123,9 @@ def description(self) -> EnvironmentDescription: def observation_space(self) -> ObservationSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._observation_space: self.describe() return next(iter(self._observation_space.values())) @@ -136,9 +134,9 @@ def observation_space(self) -> ObservationSpace: def signal_space(self) -> SignalSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ while not self._signal_space: self.describe() return next(iter(self._signal_space.values())) diff --git a/neodroid/environments/environment.py b/neodroid/environments/environment.py index b430f3c2..affac59f 100644 --- a/neodroid/environments/environment.py +++ b/neodroid/environments/environment.py @@ -24,12 +24,11 @@ class Environment(ABC): """ -Environment base class, this class is responsible for defining the interface of interaction. It is -designed with the idea for constructing/connecting, configuring, resetting and reacting with an -Environment as a Markov Decision Process(MDP). However can easily used as a stateless interface for -collecting data, eg. from a real world camera, synthetic (Maybe domain randomised images) data or -sampling consecutive data points (Maybe a time series of sensor values). -""" + Environment base class, this class is responsible for defining the interface of interaction. It is + designed with the idea for constructing/connecting, configuring, resetting and reacting with an + Environment as a Markov Decision Process(MDP). However can easily used as a stateless interface for + collecting data, eg. from a real world camera, synthetic (Maybe domain randomised images) data or + sampling consecutive data points (Maybe a time series of sensor values).""" @drop_unused_kws def __init__( @@ -61,96 +60,88 @@ def __init__( def environment_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._environment_name @abstractmethod def configure(self, *args, **kwargs) -> EnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + """ raise NotImplementedError @abstractmethod def reset(self, *args, **kwargs) -> EnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + """ raise NotImplementedError @abstractmethod def react(self, *args, **kwargs) -> EnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + """ raise NotImplementedError @abstractmethod def display(self, *args, **kwargs) -> EnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + """ raise NotImplementedError @abstractmethod def describe(self, *args, **kwargs) -> EnvironmentSnapshot: """ - @param args: - @type args: - @param kwargs: - @type kwargs: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + """ raise NotImplementedError @property @abstractmethod def description(self) -> EnvironmentDescription: - """ - - """ + """""" raise NotImplementedError @property @abstractmethod def observation_space(self) -> ObservationSpace: - """ - - """ + """""" raise NotImplementedError @property @abstractmethod def action_space(self) -> ActionSpace: - """ - - """ + """""" raise NotImplementedError @property @abstractmethod def signal_space(self) -> SignalSpace: - """ - - """ + """""" raise NotImplementedError def __next__(self): @@ -179,22 +170,18 @@ def __str__(self): @coroutine def coroutine_generator(self): """ -:return: -:rtype: -""" + :return: + :rtype:""" return self def render(self): - """ - - """ + """""" pass @staticmethod def seed(seed): """ -:param seed: -:type seed: -""" + :param seed: + :type seed:""" numpy.random.seed(seed) diff --git a/neodroid/environments/gym_environment/action_encoding.py b/neodroid/environments/gym_environment/action_encoding.py index 7a02e4eb..17852d03 100644 --- a/neodroid/environments/gym_environment/action_encoding.py +++ b/neodroid/environments/gym_environment/action_encoding.py @@ -10,9 +10,7 @@ class ToIntWrapper: - """ - - """ + """""" def __init__(self, action_space: ActionSpace): self.action_space = action_space @@ -20,9 +18,9 @@ def __init__(self, action_space: ActionSpace): def sample(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return [round(a) for a in self.action_space.sample()] def __getattr__(self, item): diff --git a/neodroid/environments/gym_environment/gym_wrapper.py b/neodroid/environments/gym_environment/gym_wrapper.py index 1ea5c472..f3057641 100644 --- a/neodroid/environments/gym_environment/gym_wrapper.py +++ b/neodroid/environments/gym_environment/gym_wrapper.py @@ -20,9 +20,7 @@ class NeodroidGymEnvironment(object): - """ - - """ + """""" @drop_unused_kws def __init__( @@ -30,8 +28,7 @@ def __init__( ): """ -:param environment: -""" + :param environment:""" if isinstance(environment, str): self._env = gym.make(environment) else: @@ -43,8 +40,7 @@ def __init__( def signal_space(self) -> SignalSpace: """ -:return: -""" + :return:""" space = SignalSpace( [ @@ -62,8 +58,7 @@ def signal_space(self) -> SignalSpace: def observation_space(self) -> ObservationSpace: """ -:return: -""" + :return:""" if len(self._env.observation_space.shape) >= 1: aspc = self._env.observation_space @@ -92,8 +87,7 @@ def observation_space(self) -> ObservationSpace: def action_space(self) -> ActionSpace: """ -:return: -""" + :return:""" if len(self._env.action_space.shape) >= 1: aspc = self._env.action_space @@ -123,20 +117,20 @@ def action_space(self) -> ActionSpace: def environment_name(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._environment_name @drop_unused_kws def react(self, a: Iterable) -> VectorEnvironmentSnapshot: """ - @param a: - @type a: - @return: - @rtype: - """ + @param a: + @type a: + @return: + @rtype: + """ a = a[0] e = EnvironmentSnapshot.from_gym(self.environment_name, *self._env.step(a)) return VectorEnvironmentSnapshot({self.environment_name: e}) @@ -144,9 +138,9 @@ def react(self, a: Iterable) -> VectorEnvironmentSnapshot: def reset(self) -> VectorEnvironmentSnapshot: """ - @return: - @rtype: - """ + @return: + @rtype: + """ observables = self._env.reset() e = EnvironmentSnapshot.from_gym( self.environment_name, observables, 0, False, None diff --git a/neodroid/environments/gym_environment/vector_gym_environment.py b/neodroid/environments/gym_environment/vector_gym_environment.py index 3c6b43d1..019920b0 100644 --- a/neodroid/environments/gym_environment/vector_gym_environment.py +++ b/neodroid/environments/gym_environment/vector_gym_environment.py @@ -20,9 +20,7 @@ class NeodroidVectorGymEnvironment(object): - """ - - """ + """""" @drop_unused_kws def __init__( @@ -43,8 +41,7 @@ def __init__( def signal_space(self) -> SignalSpace: """ -:return: -""" + :return:""" space = SignalSpace( [ @@ -62,8 +59,7 @@ def signal_space(self) -> SignalSpace: def observation_space(self) -> ObservationSpace: """ -:return: -""" + :return:""" if len(self._env.observation_space.shape) >= 1: aspc = self._env.observation_space @@ -92,8 +88,7 @@ def observation_space(self) -> ObservationSpace: def action_space(self) -> ActionSpace: """ -:return: -""" + :return:""" if len(self._env.action_space.shape) >= 1: aspc = self._env.action_space @@ -123,20 +118,20 @@ def action_space(self) -> ActionSpace: def environment_name(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._environment_name @drop_unused_kws def react(self, a: Sequence) -> VectorEnvironmentSnapshot: """ - @param a: - @type a: - @return: - @rtype: - """ + @param a: + @type a: + @return: + @rtype: + """ a = self.action_space.reproject(a) if self.action_space.is_discrete: a = numpy.squeeze(a, -1) @@ -157,9 +152,9 @@ def react(self, a: Sequence) -> VectorEnvironmentSnapshot: def reset(self) -> VectorEnvironmentSnapshot: """ - @return: - @rtype: - """ + @return: + @rtype: + """ res = self._env.reset() e = { f"{self.environment_name}{i}": EnvironmentSnapshot.from_gym( diff --git a/neodroid/environments/networking_environment.py b/neodroid/environments/networking_environment.py index f4fd93b5..53a5f5f3 100644 --- a/neodroid/environments/networking_environment.py +++ b/neodroid/environments/networking_environment.py @@ -19,9 +19,7 @@ class NetworkingEnvironment(Environment, ABC): - """ - - """ + """""" def __init__( self, @@ -83,26 +81,20 @@ def _setup_connection(self, auto_describe: bool = True): @message_client_event(event=ClientEvents.CONNECTED) def __on_connected_callback__(self): - """ - -""" + """""" if self._external_on_connected_callback: self._external_on_connected_callback() @message_client_event(event=ClientEvents.DISCONNECTED) def __on_disconnected_callback__(self): - """ - -""" + """""" self._is_connected_to_server = False if self._external_on_disconnected_callback: self._external_on_disconnected_callback() @message_client_event(event=ClientEvents.TIMEOUT) def __on_timeout_callback__(self): - """ - -""" + """""" if self._external_on_timeout_callback: self._external_on_timeout_callback() @@ -110,9 +102,9 @@ def __on_timeout_callback__(self): def is_connected(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._is_connected_to_server @abstractmethod @@ -129,13 +121,13 @@ def __exit__(self, exc_type, exc_val, exc_tb): def close(self, *args, **kwargs): """ - @param args: - @type args: - @param kwargs: - @type kwargs: - @return: - @rtype: - """ + @param args: + @type args: + @param kwargs: + @type kwargs: + @return: + @rtype: + """ self._message_server.teardown() return self._close(*args, **kwargs) diff --git a/neodroid/environments/python_environment/non_neodroidian_environments/blackjack.py b/neodroid/environments/python_environment/non_neodroidian_environments/blackjack.py index 7fff1cb2..4060accb 100644 --- a/neodroid/environments/python_environment/non_neodroidian_environments/blackjack.py +++ b/neodroid/environments/python_environment/non_neodroidian_environments/blackjack.py @@ -37,9 +37,7 @@ class BlackjackEnvironment: - """ - - """ + """""" def __init__(self): # Starts are parametrized efficiently with (s_player, s_dealer) where: @@ -52,9 +50,9 @@ def __init__(self): def reset(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ # Create a fresh deck of 52 cards (we will randomly sample this deck with replacement) SUITS = ["diamond", "club", "heart", "spade"] RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] @@ -74,20 +72,20 @@ def reset(self): def step(self, action): """ - @param action: - @type action: - @return: - @rtype: - """ + @param action: + @type action: + @return: + @rtype: + """ def deal_card(DECK): """ - @param DECK: - @type DECK: - @return: - @rtype: - """ + @param DECK: + @type DECK: + @return: + @rtype: + """ card = random.choice(DECK) # deal card with replacement if card["rank"] in ["A"]: return 1 # non-usable ace @@ -140,9 +138,7 @@ def deal_card(DECK): class Agent: - """ - - """ + """""" def __init__(self, state_dim, action_dim): self.state_dim = state_dim # state dimension @@ -151,16 +147,12 @@ def __init__(self, state_dim, action_dim): self.reset_learning_memory() def reset_episodic_memory(self): - """ - - """ + """""" # Reset episodic memories self.memories = list() def reset_learning_memory(self): - """ - - """ + """""" # Reset Q[s,a], r_visits[s,a], n_visits[s,a] to zero self.Q = numpy.zeros( self.state_dim + self.action_dim, dtype=float @@ -175,13 +167,13 @@ def reset_learning_memory(self): def get_action(self, state, force_random=False): """ - @param state: - @type state: - @param force_random: - @type force_random: - @return: - @rtype: - """ + @param state: + @type state: + @param force_random: + @type force_random: + @return: + @rtype: + """ if random.uniform(0, 1) < self.epsilon or force_random: # explore action = numpy.random.randint(self.action_dim[0]) @@ -191,9 +183,7 @@ def get_action(self, state, force_random=False): return action def train(self): - """ - - """ + """""" # List all uniquely visited (state, action) pairs from episodic memory. # Also compute the total reward collected from the episode. # Returns after first-occurence of (s,a) @@ -220,15 +210,13 @@ def train(self): def memorize(self, memory): """ - @param memory: - @type memory: - """ + @param memory: + @type memory: + """ self.memories.append(memory) def display_greedy_policy(self): - """ - - """ + """""" # Display greedy policy: # - rows are s_player # - columns are s_dealer diff --git a/neodroid/environments/python_environment/non_neodroidian_environments/constant_environment.py b/neodroid/environments/python_environment/non_neodroidian_environments/constant_environment.py index 6fa7a21e..2be3590d 100644 --- a/neodroid/environments/python_environment/non_neodroidian_environments/constant_environment.py +++ b/neodroid/environments/python_environment/non_neodroidian_environments/constant_environment.py @@ -8,16 +8,14 @@ class NoRenderEnv(Env): def render(self, mode="human"): """ - @param mode: - @type mode: - """ + @param mode: + @type mode: + """ pass class ConstantEnvironment(NoRenderEnv): - """ - - """ + """""" def __init__(self, n_obs=1, n_actions=1): @@ -39,20 +37,20 @@ def __init__(self, n_obs=1, n_actions=1): def reset(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ self.obs = self.observation_space.sample() return self.obs def step(self, actions): """ - @param actions: - @type actions: - @return: - @rtype: - """ + @param actions: + @type actions: + @return: + @rtype: + """ if actions > 0: return self.obs, 0, True, {} @@ -61,21 +59,21 @@ def step(self, actions): def act(self, a): """ - @param a: - @type a: - @return: - @rtype: - """ + @param a: + @type a: + @return: + @rtype: + """ return self.step(a) def react(self, a): """ - @param a: - @type a: - @return: - @rtype: - """ + @param a: + @type a: + @return: + @rtype: + """ return self.act(a) @@ -83,20 +81,20 @@ class StatefulEnvironment(ConstantEnvironment): def reset(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ self.obs = self.observation_space.sample() return [self.obs] def step(self, actions): """ - @param actions: - @type actions: - @return: - @rtype: - """ + @param actions: + @type actions: + @return: + @rtype: + """ terminated = numpy.array_equal(self.obs, [actions]) if isinstance(terminated, numpy.ndarray): terminated = terminated.all() diff --git a/neodroid/environments/python_environment/non_neodroidian_environments/contextual_bandit_environment.py b/neodroid/environments/python_environment/non_neodroidian_environments/contextual_bandit_environment.py index b875915d..c84ca5c8 100644 --- a/neodroid/environments/python_environment/non_neodroidian_environments/contextual_bandit_environment.py +++ b/neodroid/environments/python_environment/non_neodroidian_environments/contextual_bandit_environment.py @@ -6,9 +6,7 @@ class ContextualBanditEnvironment(object): - """ - - """ + """""" def __init__(self, seed=0): @@ -24,28 +22,28 @@ def __init__(self, seed=0): def update_state(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ self.state = self.np_random.randint(0, len(self.bandits)) return self.state def reset(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self.update_state() def act(self, action): """ - @param action: - @type action: - @return: - @rtype: - """ + @param action: + @type action: + @return: + @rtype: + """ threshold = self.bandits[self.state, action] result = self.np_random.random_sample() if result > threshold: diff --git a/neodroid/environments/python_environment/non_neodroidian_environments/fixed_sequence_environment.py b/neodroid/environments/python_environment/non_neodroidian_environments/fixed_sequence_environment.py index 34d4f50c..09196c67 100644 --- a/neodroid/environments/python_environment/non_neodroidian_environments/fixed_sequence_environment.py +++ b/neodroid/environments/python_environment/non_neodroidian_environments/fixed_sequence_environment.py @@ -7,9 +7,7 @@ class FixedSequenceEnvironment(NoRenderEnv): - """ - - """ + """""" def __init__(self, n_actions=10, seed=0, episode_length=100): self._episode_len = episode_length @@ -28,20 +26,20 @@ def __init__(self, n_actions=10, seed=0, episode_length=100): def reset(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ self._time = 0 return 0 def step(self, actions): """ - @param actions: - @type actions: - @return: - @rtype: - """ + @param actions: + @type actions: + @return: + @rtype: + """ signal = self._get_signal(actions) self._to_next_state() if self._episode_len and self.time >= self._episode_len: @@ -53,9 +51,9 @@ def step(self, actions): def time(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._time def _to_next_state(self): diff --git a/neodroid/environments/python_environment/non_neodroidian_environments/inventory.py b/neodroid/environments/python_environment/non_neodroidian_environments/inventory.py index 495f5ab1..af75a88d 100644 --- a/neodroid/environments/python_environment/non_neodroidian_environments/inventory.py +++ b/neodroid/environments/python_environment/non_neodroidian_environments/inventory.py @@ -20,11 +20,10 @@ class InventoryEnv(gym.Env, utils.EzPickle): """Inventory control with lost sales environment -This environment corresponds to the version of the inventory control -with lost sales problem described in Example 1.1 in Algorithms for -Reinforcement Learning by Csaba Szepesvari (2010). -https://sites.ualberta.ca/~szepesva/RLBook.html -""" + This environment corresponds to the version of the inventory control + with lost sales problem described in Example 1.1 in Algorithms for + Reinforcement Learning by Csaba Szepesvari (2010). + https://sites.ualberta.ca/~szepesva/RLBook.html""" def step(self, action): return self._step(action) diff --git a/neodroid/environments/python_environment/non_neodroidian_environments/mnist_environment.py b/neodroid/environments/python_environment/non_neodroidian_environments/mnist_environment.py index ac4ebf17..27610029 100644 --- a/neodroid/environments/python_environment/non_neodroidian_environments/mnist_environment.py +++ b/neodroid/environments/python_environment/non_neodroidian_environments/mnist_environment.py @@ -9,16 +9,14 @@ class MnistEnv(Env): - """ - - """ + """""" def render(self, mode="human"): """ - @param mode: - @type mode: - """ + @param mode: + @type mode: + """ pyplot.imshow(self.state[0]) pyplot.title(self.state[1]) pyplot.show() @@ -49,9 +47,9 @@ def __init__(self, seed=0, episode_len=None, no_images=None): def reset(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ self._choose_next_state() self.time = 0 @@ -60,11 +58,11 @@ def reset(self): def step(self, actions): """ - @param actions: - @type actions: - @return: - @rtype: - """ + @param actions: + @type actions: + @return: + @rtype: + """ signal = self._get_reward(actions) self._choose_next_state() terminal = False @@ -75,15 +73,11 @@ def step(self, actions): return self.state[0], signal, terminal, {} def train_mode(self): - """ - - """ + """""" self.dataset = self.mnist.train_ssd def test_mode(self): - """ - - """ + """""" self.dataset = self.mnist.test def _choose_next_state(self): diff --git a/neodroid/environments/python_environment/python_environment.py b/neodroid/environments/python_environment/python_environment.py index 36547e97..9f9e3bce 100644 --- a/neodroid/environments/python_environment/python_environment.py +++ b/neodroid/environments/python_environment/python_environment.py @@ -11,9 +11,7 @@ class PythonEnvironment(Environment, ABC): - """ - - """ + """""" def __init__( self, @@ -42,9 +40,9 @@ def __next__(self): def describe(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self.react( parameters=M.ReactionParameters( terminable=False, describe=True, episode_count=False @@ -54,11 +52,11 @@ def describe(self): def update_interface_statics(self, new_states, new_simulator_configuration): """ - @param new_states: - @type new_states: - @param new_simulator_configuration: - @type new_simulator_configuration: - """ + @param new_states: + @type new_states: + @param new_simulator_configuration: + @type new_simulator_configuration: + """ self._last_message = new_states self._simulator_configuration = new_simulator_configuration diff --git a/neodroid/factories/configuration_reactions.py b/neodroid/factories/configuration_reactions.py index f3befada..1e32c048 100644 --- a/neodroid/factories/configuration_reactions.py +++ b/neodroid/factories/configuration_reactions.py @@ -26,10 +26,9 @@ def verify_configuration_reactions( ): """ -:param input_reactions: -:param environment_descriptions: -:return: -""" + :param input_reactions: + :param environment_descriptions: + :return:""" """ if environment_descriptions: @@ -153,15 +152,15 @@ def construct_configuration_reaction_from_list( ): """ - @param configuration_list: - @type configuration_list: - @param configurables: - @type configurables: - @param env_name: - @type env_name: - @return: - @rtype: - """ + @param configuration_list: + @type configuration_list: + @param configurables: + @type configurables: + @param env_name: + @type env_name: + @return: + @rtype: + """ configurations = construct_configurations_from_known_observables( configuration_list, configurables ) @@ -184,13 +183,13 @@ def construct_configuration_reaction_from_list( def construct_configurations_from_known_observables(input_list, configurables): """ - @param input_list: - @type input_list: - @param configurables: - @type configurables: - @return: - @rtype: - """ + @param input_list: + @type input_list: + @param configurables: + @type configurables: + @return: + @rtype: + """ new_configurations = [ Configuration(configurable.configurable_name, list_val) for (list_val, configurable) in zip(input_list, configurables) diff --git a/neodroid/factories/motion_reactions.py b/neodroid/factories/motion_reactions.py index fd326d64..23368336 100644 --- a/neodroid/factories/motion_reactions.py +++ b/neodroid/factories/motion_reactions.py @@ -24,17 +24,17 @@ def verify_motion_reactions( ): """ - @param input_reactions: - @type input_reactions: - @param environment_descriptions: - @type environment_descriptions: - @param environment_snapshots: - @type environment_snapshots: - @param _auto_reset: - @type _auto_reset: - @return: - @rtype: - """ + @param input_reactions: + @type input_reactions: + @param environment_descriptions: + @type environment_descriptions: + @param environment_snapshots: + @type environment_snapshots: + @param _auto_reset: + @type _auto_reset: + @return: + @rtype: + """ outs = [] if ( input_reactions is not None @@ -123,17 +123,17 @@ def construct_individual_reactions_from_list( ): """ - @param motion_list: - @type motion_list: - @param actors: - @type actors: - @param env_name: - @type env_name: - @param reset: - @type reset: - @return: - @rtype: - """ + @param motion_list: + @type motion_list: + @param actors: + @type actors: + @param env_name: + @type env_name: + @param reset: + @type reset: + @return: + @rtype: + """ motions = construct_motions_from_list(motion_list, actors) parameters = ReactionParameters( terminable=True, @@ -149,13 +149,13 @@ def construct_individual_reactions_from_list( def construct_motions_from_list(input_list, actors): """ - @param input_list: - @type input_list: - @param actors: - @type actors: - @return: - @rtype: - """ + @param input_list: + @type input_list: + @param actors: + @type actors: + @return: + @rtype: + """ actor_motor_tuples = [ (actor.actor_name, motor.actuator_name, motor.motion_space) for actor in actors diff --git a/neodroid/factories/single/single_reaction_factory.py b/neodroid/factories/single/single_reaction_factory.py index a12ea8c6..ea676b86 100644 --- a/neodroid/factories/single/single_reaction_factory.py +++ b/neodroid/factories/single/single_reaction_factory.py @@ -28,11 +28,10 @@ def verify_motion_reaction( ): """ -:param action_space: -:param environment_description: -:param normalise: -:type reaction_input: object -""" + :param action_space: + :param environment_description: + :param normalise: + :type reaction_input: object""" if reaction_input is None: logging.info( "Received empty reaction, Constructing empty counting terminal step reaction" @@ -109,17 +108,17 @@ def verify_motion_reaction( def construct_reaction_from_list(motion_list, actors, normalise, space): """ - @param motion_list: - @type motion_list: - @param actors: - @type actors: - @param normalise: - @type normalise: - @param space: - @type space: - @return: - @rtype: - """ + @param motion_list: + @type motion_list: + @param actors: + @type actors: + @param normalise: + @type normalise: + @param space: + @type space: + @return: + @rtype: + """ if not isinstance(motion_list, list): motion_list = [motion_list] motions = construct_motions_from_list(motion_list, actors, normalise, space) @@ -132,17 +131,17 @@ def construct_motions_from_list( ): """ - @param input_list: - @type input_list: - @param actors: - @type actors: - @param normalise: - @type normalise: - @param space: - @type space: - @return: - @rtype: - """ + @param input_list: + @type input_list: + @param actors: + @type actors: + @param normalise: + @type normalise: + @param space: + @type space: + @return: + @rtype: + """ actor_actuator_tuples = [ (actor.actor_name, actuator.actuator_name, actuator.motion_space) for actor in actors @@ -180,13 +179,13 @@ def verify_configuration_reaction( ): """ - @param input_reaction: - @type input_reaction: - @param environment_description: - @type environment_description: - @return: - @rtype: - """ + @param input_reaction: + @type input_reaction: + @param environment_description: + @type environment_description: + @return: + @rtype: + """ if environment_description: parameters = ReactionParameters(reset=True, configure=True, describe=True) configurables = environment_description.configurables.values() @@ -236,13 +235,13 @@ def verify_configuration_reaction( def construct_configuration_reaction_from_list(configuration_list, configurables): """ - @param configuration_list: - @type configuration_list: - @param configurables: - @type configurables: - @return: - @rtype: - """ + @param configuration_list: + @type configuration_list: + @param configurables: + @type configurables: + @return: + @rtype: + """ configurations = construct_configurations_from_known_observables( configuration_list, configurables ) @@ -253,13 +252,13 @@ def construct_configuration_reaction_from_list(configuration_list, configurables def construct_configurations_from_known_observables(input_list, configurables): """ - @param input_list: - @type input_list: - @param configurables: - @type configurables: - @return: - @rtype: - """ + @param input_list: + @type input_list: + @param configurables: + @type configurables: + @return: + @rtype: + """ new_configurations = [ Configuration(configurable.configurable_name, list_val) for (list_val, configurable) in zip(input_list, configurables) diff --git a/neodroid/messaging/fbs/fbs_state_utilties.py b/neodroid/messaging/fbs/fbs_state_utilties.py index d5a88f6a..80ef991b 100644 --- a/neodroid/messaging/fbs/fbs_state_utilties.py +++ b/neodroid/messaging/fbs/fbs_state_utilties.py @@ -7,7 +7,16 @@ from PIL.Image import Image from flatbuffers import Table -from neodroid.messaging.fbs import FActor, FArray, FBSModels as F, FByteArray, FObservation, FQTObs, FRange, FValues +from neodroid.messaging.fbs import ( + FActor, + FArray, + FBSModels as F, + FByteArray, + FObservation, + FQTObs, + FRange, + FValues, +) from neodroid.utilities import unity_specifications as US from neodroid.utilities.spaces.range import Range @@ -36,376 +45,375 @@ "deserialise_rigidbody", "deserialise_triple", "deserialise_unobservables", - ] +] def deserialise_states(flat_states) -> Tuple[Dict[str, Any], Any]: - states = {} + states = {} - for i in range(flat_states.StatesLength()): - state = US.EnvironmentSnapshot(flat_states.States(i)) - states[state.environment_name] = state + for i in range(flat_states.StatesLength()): + state = US.EnvironmentSnapshot(flat_states.States(i)) + states[state.environment_name] = state - out_states = {} - for key in sorted( - states.keys() - ): # Sort states by key, ensures the same order every time - out_states[key] = states[key] + out_states = {} + for key in sorted( + states.keys() + ): # Sort states by key, ensures the same order every time + out_states[key] = states[key] - simulator_configuration = US.SimulatorConfiguration( - flat_states.SimulatorConfiguration(), flat_states.ApiVersion() - ) + simulator_configuration = US.SimulatorConfiguration( + flat_states.SimulatorConfiguration(), flat_states.ApiVersion() + ) - return out_states, simulator_configuration + return out_states, simulator_configuration def deserialise_configurables(flat_environment_description) -> Dict[str, Any]: - configurables = {} - if flat_environment_description: - for i in range(flat_environment_description.ConfigurablesLength()): - f_conf = flat_environment_description.Configurables(i) - obs_type = f_conf.ConfigurableValueType() - obs_value = f_conf.ConfigurableValue() - observation_value, observation_space, _ = deserialise_sensor( - obs_type, obs_value - ) - - configurable = US.Configurable( - f_conf.ConfigurableName().decode(), observation_value, observation_space - ) - configurables[configurable.configurable_name] = configurable - return configurables + configurables = {} + if flat_environment_description: + for i in range(flat_environment_description.ConfigurablesLength()): + f_conf = flat_environment_description.Configurables(i) + obs_type = f_conf.ConfigurableValueType() + obs_value = f_conf.ConfigurableValue() + observation_value, observation_space, _ = deserialise_sensor( + obs_type, obs_value + ) + + configurable = US.Configurable( + f_conf.ConfigurableName().decode(), observation_value, observation_space + ) + configurables[configurable.configurable_name] = configurable + return configurables def deserialise_sensors(flat_description) -> Dict[str, Any]: - out_sensors = {} + out_sensors = {} - for i in range(flat_description.SensorsLength()): - f_obs = flat_description.Sensors(i) - obs_type = f_obs.SensorValueType() - obs_value = f_obs.SensorValue() - sensor_value, sensor_space, is_image = deserialise_sensor(obs_type, obs_value) + for i in range(flat_description.SensorsLength()): + f_obs = flat_description.Sensors(i) + obs_type = f_obs.SensorValueType() + obs_value = f_obs.SensorValue() + sensor_value, sensor_space, is_image = deserialise_sensor(obs_type, obs_value) - name = f_obs.SensorName().decode() - out_sensors[name] = US.Sensor(name, sensor_space, sensor_value, is_image) - return out_sensors + name = f_obs.SensorName().decode() + out_sensors[name] = US.Sensor(name, sensor_space, sensor_value, is_image) + return out_sensors def deserialise_sensor(obs_type, obs_value) -> Tuple[Any, List, bool]: - value = None - value_range = None - only_direct_access = False - if obs_type is F.FObservation.FSingle: - value, value_range = deserialise_single(obs_value) - elif obs_type is F.FObservation.FDouble: - value, value_range = deserialise_double(obs_value) - elif obs_type is F.FObservation.FTriple: - value, value_range = deserialise_triple(obs_value) - elif obs_type is F.FObservation.FQuadruple: - value, value_range = deserialise_quadruple(obs_value) - elif obs_type is F.FObservation.FArray: - value, value_range = deserialise_array(obs_value) - elif obs_type is F.FObservation.FETObs: - value, value_range = deserialise_euler_transform(obs_value) - elif obs_type is F.FObservation.FRBObs: - value, value_range = deserialise_body(obs_value) - elif obs_type is F.FObservation.FQTObs: - value, value_range = deserialise_quaternion_transform(obs_value) - elif obs_type is F.FObservation.FByteArray: - value, value_range = deserialise_byte_array(obs_value) - only_direct_access = True - elif obs_type is F.FObservation.FString: - value, value_range = deserialise_string(obs_value) - - return value, value_range, only_direct_access + value = None + value_range = None + only_direct_access = False + if obs_type is F.FObservation.FSingle: + value, value_range = deserialise_single(obs_value) + elif obs_type is F.FObservation.FDouble: + value, value_range = deserialise_double(obs_value) + elif obs_type is F.FObservation.FTriple: + value, value_range = deserialise_triple(obs_value) + elif obs_type is F.FObservation.FQuadruple: + value, value_range = deserialise_quadruple(obs_value) + elif obs_type is F.FObservation.FArray: + value, value_range = deserialise_array(obs_value) + elif obs_type is F.FObservation.FETObs: + value, value_range = deserialise_euler_transform(obs_value) + elif obs_type is F.FObservation.FRBObs: + value, value_range = deserialise_body(obs_value) + elif obs_type is F.FObservation.FQTObs: + value, value_range = deserialise_quaternion_transform(obs_value) + elif obs_type is F.FObservation.FByteArray: + value, value_range = deserialise_byte_array(obs_value) + only_direct_access = True + elif obs_type is F.FObservation.FString: + value, value_range = deserialise_string(obs_value) + + return value, value_range, only_direct_access def deserialise_observables(state) -> List[float]: - return [state.Observables(i) for i in range(state.ObservablesLength())] + return [state.Observables(i) for i in range(state.ObservablesLength())] def deserialise_unobservables(state) -> Any: - return US.Unobservables(state.Unobservables()) + return US.Unobservables(state.Unobservables()) def deserialise_actors(flat_environment_description) -> Dict[str, Any]: - actors = {} - if flat_environment_description: - for i in range(flat_environment_description.ActorsLength()): - flat_actor = flat_environment_description.Actors(i) - actor = US.Actor(flat_actor) - actors[actor.actor_name] = actor - - out_actors = ( - {} - ) # All dictionaries in python3.6+ are insertion ordered, actors are sorted by key and - # inserted so that the order of actor key-value pairs are always the same for all instances the same - # environment. This is - # useful when descriptions are used for inference what value (motion strength) in a numeric vector - # corresponds to what actor. - for key in sorted(actors.keys()): - out_actors[key] = actors[key] - - return out_actors + actors = {} + if flat_environment_description: + for i in range(flat_environment_description.ActorsLength()): + flat_actor = flat_environment_description.Actors(i) + actor = US.Actor(flat_actor) + actors[actor.actor_name] = actor + + out_actors = ( + {} + ) # All dictionaries in python3.6+ are insertion ordered, actors are sorted by key and + # inserted so that the order of actor key-value pairs are always the same for all instances the same + # environment. This is + # useful when descriptions are used for inference what value (motion strength) in a numeric vector + # corresponds to what actor. + for key in sorted(actors.keys()): + out_actors[key] = actors[key] + + return out_actors def deserialise_description(flat_description) -> Any: - return US.EnvironmentDescription(flat_description) + return US.EnvironmentDescription(flat_description) def deserialise_poses(unobservables) -> numpy.ndarray: - pl = unobservables.PosesLength() - poses = numpy.zeros((pl, 7)) - for i in range(pl): - pose = unobservables.Poses(i) - pos = pose.Position(F.FVector3()) - rot = pose.Rotation(F.FQuaternion()) - poses[i] = [pos.X(), pos.Y(), pos.Z(), rot.X(), rot.Y(), rot.Z(), rot.W()] - return poses + pl = unobservables.PosesLength() + poses = numpy.zeros((pl, 7)) + for i in range(pl): + pose = unobservables.Poses(i) + pos = pose.Position(F.FVector3()) + rot = pose.Rotation(F.FQuaternion()) + poses[i] = [pos.X(), pos.Y(), pos.Z(), rot.X(), rot.Y(), rot.Z(), rot.W()] + return poses def deserialise_bodies(unobservables) -> numpy.ndarray: - bl = unobservables.BodiesLength() - bodies = numpy.zeros((bl, 6)) - for i in range(bl): - body = unobservables.Bodies(i) - vel = body.Velocity(F.FVector3()) - ang = body.AngularVelocity(F.FVector3()) - bodies[i] = [vel.X(), vel.Y(), vel.Z(), ang.X(), ang.Y(), ang.Z()] - return bodies + bl = unobservables.BodiesLength() + bodies = numpy.zeros((bl, 6)) + for i in range(bl): + body = unobservables.Bodies(i) + vel = body.Velocity(F.FVector3()) + ang = body.AngularVelocity(F.FVector3()) + bodies[i] = [vel.X(), vel.Y(), vel.Z(), ang.X(), ang.Y(), ang.Z()] + return bodies def deserialise_euler_transform(f_obs: Table) -> Tuple[List, List]: - transform = F.FETObs() - transform.Init(f_obs.Bytes, f_obs.Pos) - t = transform.Transform() - position = t.Position(F.FVector3()) - rotation = t.Rotation(F.FVector3()) - direction = t.Direction(F.FVector3()) - # ranges = [q.XRange(),q.YRange(), q.ZRange()] - - return ( - [ - [position.X(), position.Y(), position.Z()], - [direction.X(), direction.Y(), direction.Z()], - [rotation.X(), rotation.Y(), rotation.Z()], - ], - [Range(decimal_granularity=10) for _ in range(9)], - ) + transform = F.FETObs() + transform.Init(f_obs.Bytes, f_obs.Pos) + t = transform.Transform() + position = t.Position(F.FVector3()) + rotation = t.Rotation(F.FVector3()) + direction = t.Direction(F.FVector3()) + # ranges = [q.XRange(),q.YRange(), q.ZRange()] + + return ( + [ + [position.X(), position.Y(), position.Z()], + [direction.X(), direction.Y(), direction.Z()], + [rotation.X(), rotation.Y(), rotation.Z()], + ], + [Range(decimal_granularity=10) for _ in range(9)], + ) def deserialise_body(f_obs: Table) -> Tuple[List, List]: - body = F.FRBObs() - body.Init(f_obs.Bytes, f_obs.Pos) - b = body.Body() - velocity = b.Velocity(F.FVector3()) - angular_velocity = b.AngularVelocity(F.FVector3()) + body = F.FRBObs() + body.Init(f_obs.Bytes, f_obs.Pos) + b = body.Body() + velocity = b.Velocity(F.FVector3()) + angular_velocity = b.AngularVelocity(F.FVector3()) - # ranges = [q.XRange(),q.YRange(), q.ZRange()] + # ranges = [q.XRange(),q.YRange(), q.ZRange()] - return ( - [ - [velocity.X(), velocity.Y(), velocity.Z()], - [angular_velocity.X(), angular_velocity.Y(), angular_velocity.Z()], - ], - [Range(decimal_granularity=10, normalised=True) for _ in range(6)], - ) + return ( + [ + [velocity.X(), velocity.Y(), velocity.Z()], + [angular_velocity.X(), angular_velocity.Y(), angular_velocity.Z()], + ], + [Range(decimal_granularity=10, normalised=True) for _ in range(6)], + ) def deserialise_quadruple(f_obs: Table) -> Tuple[List, List]: - q = F.FQuadruple() - q.Init(f_obs.Bytes, f_obs.Pos) - quad = q.Quat() - data = [quad.X(), quad.Y(), quad.Z(), quad.W()] - # ranges = [q.XRange(),q.YRange(), q.ZRange(), q.WRange()] - return data, [Range(decimal_granularity=10, normalised=True) for _ in range(4)] + q = F.FQuadruple() + q.Init(f_obs.Bytes, f_obs.Pos) + quad = q.Quat() + data = [quad.X(), quad.Y(), quad.Z(), quad.W()] + # ranges = [q.XRange(),q.YRange(), q.ZRange(), q.WRange()] + return data, [Range(decimal_granularity=10, normalised=True) for _ in range(4)] def deserialise_triple(f_obs: Table) -> Tuple[List, List]: - pos = F.FTriple() - pos.Init(f_obs.Bytes, f_obs.Pos) - position = pos.Vec3() - value = [position.X(), position.Y(), position.Z()] - value_range = [ - deserialise_range(pos.XRange()), - deserialise_range(pos.YRange()), - deserialise_range(pos.ZRange()), - ] - return value, value_range + pos = F.FTriple() + pos.Init(f_obs.Bytes, f_obs.Pos) + position = pos.Vec3() + value = [position.X(), position.Y(), position.Z()] + value_range = [ + deserialise_range(pos.XRange()), + deserialise_range(pos.YRange()), + deserialise_range(pos.ZRange()), + ] + return value, value_range def deserialise_double(f_obs: Table) -> Tuple[List, List]: - pos = F.FDouble() - pos.Init(f_obs.Bytes, f_obs.Pos) - position = pos.Vec2() - value = [position.X(), position.Y()] - value_range = [deserialise_range(pos.XRange()), deserialise_range(pos.YRange())] - return value, value_range + pos = F.FDouble() + pos.Init(f_obs.Bytes, f_obs.Pos) + position = pos.Vec2() + value = [position.X(), position.Y()] + value_range = [deserialise_range(pos.XRange()), deserialise_range(pos.YRange())] + return value, value_range def deserialise_single(f_obs: Table) -> Tuple[float, List]: - val = F.FSingle() - val.Init(f_obs.Bytes, f_obs.Pos) - value, value_range = val.Value(), val.Range() - return value, [deserialise_range(value_range)] + val = F.FSingle() + val.Init(f_obs.Bytes, f_obs.Pos) + value, value_range = val.Value(), val.Range() + return value, [deserialise_range(value_range)] def deserialise_string(f_obs: Table) -> Tuple[str, List]: - val = F.FString() - val.Init(f_obs.Bytes, f_obs.Pos) - value = val.Str() - return value, [None] + val = F.FString() + val.Init(f_obs.Bytes, f_obs.Pos) + value = val.Str() + return value, [None] def deserialise_rigidbody(f_obs: Table) -> Tuple[List, List]: - qt = F.FRBObs() - qt.Init(f_obs.Bytes, f_obs.Pos) - position = qt.Body().Position(F.FVector3()) - rotation = qt.Body().Rotation(F.FVector3()) - data = [ - position.X(), - position.Y(), - position.Z(), - rotation.X(), - rotation.Y(), - rotation.Z(), - ] - return ( - data, - [deserialise_range(qt.VelRange()) for _ in range(3)] - + [deserialise_range(qt.AngRange()) for _ in range(3)], - ) + qt = F.FRBObs() + qt.Init(f_obs.Bytes, f_obs.Pos) + position = qt.Body().Position(F.FVector3()) + rotation = qt.Body().Rotation(F.FVector3()) + data = [ + position.X(), + position.Y(), + position.Z(), + rotation.X(), + rotation.Y(), + rotation.Z(), + ] + return ( + data, + [deserialise_range(qt.VelRange()) for _ in range(3)] + + [deserialise_range(qt.AngRange()) for _ in range(3)], + ) def deserialise_quaternion_transform(f_obs: Table) -> Tuple[List, List]: - qt = F.FQTObs() - qt.Init(f_obs.Bytes, f_obs.Pos) - position = qt.Transform().Position(F.FVector3()) - rotation = qt.Transform().Rotation(F.FQuaternion()) - data = [ - position.X(), - position.Y(), - position.Z(), - rotation.X(), - rotation.Y(), - rotation.Z(), - rotation.W(), - ] - return ( - data, - [deserialise_range(qt.PosRange()) for _ in range(3)] - + [deserialise_range(qt.RotRange()) for _ in range(4)], - ) + qt = F.FQTObs() + qt.Init(f_obs.Bytes, f_obs.Pos) + position = qt.Transform().Position(F.FVector3()) + rotation = qt.Transform().Rotation(F.FQuaternion()) + data = [ + position.X(), + position.Y(), + position.Z(), + rotation.X(), + rotation.Y(), + rotation.Z(), + rotation.W(), + ] + return ( + data, + [deserialise_range(qt.PosRange()) for _ in range(3)] + + [deserialise_range(qt.RotRange()) for _ in range(4)], + ) def deserialise_byte_array(f_obs: Table) -> Tuple[Any, List]: - byte_array = F.FByteArray() - byte_array.Init(f_obs.Bytes, f_obs.Pos) - data: numpy.ndarray = byte_array.BytesAsNumpy() # Deserialise as numpy array for performance reasons, implementation is faster - t = byte_array.Type() - if t == F.FByteDataType.UINT8: - out = numpy.frombuffer(data, dtype=numpy.uint8) - out = out.reshape(*byte_array.ShapeAsNumpy()) - out = numpy.flipud(out) - # out = out[...,::-1] - elif t == F.FByteDataType.FLOAT16: - out = numpy.frombuffer(data, dtype=numpy.float16) - out = out.reshape(*byte_array.ShapeAsNumpy()) - out = numpy.flipud(out) - # out = out[...,::-1] - elif t == F.FByteDataType.FLOAT32: - out = numpy.frombuffer(data, dtype=numpy.float32) - out = out.reshape(*byte_array.ShapeAsNumpy()) - out = numpy.flipud(out) - # out = out[...,::-1] - elif t == F.FByteDataType.PNG: - ''' - - out = imageio.get_reader(data.tobytes() - , - # "png" - format="PNG-PIL" - ) - ''' - out = PIL.Image.open(io.BytesIO(data.tobytes())) - elif t == F.FByteDataType.JPEG: - ''' - out = imageio.get_reader(data.tobytes() + byte_array = F.FByteArray() + byte_array.Init(f_obs.Bytes, f_obs.Pos) + data: numpy.ndarray = ( + byte_array.BytesAsNumpy() + ) # Deserialise as numpy array for performance reasons, implementation is faster + t = byte_array.Type() + if t == F.FByteDataType.UINT8: + out = numpy.frombuffer(data, dtype=numpy.uint8) + out = out.reshape(*byte_array.ShapeAsNumpy()) + out = numpy.flipud(out) + # out = out[...,::-1] + elif t == F.FByteDataType.FLOAT16: + out = numpy.frombuffer(data, dtype=numpy.float16) + out = out.reshape(*byte_array.ShapeAsNumpy()) + out = numpy.flipud(out) + # out = out[...,::-1] + elif t == F.FByteDataType.FLOAT32: + out = numpy.frombuffer(data, dtype=numpy.float32) + out = out.reshape(*byte_array.ShapeAsNumpy()) + out = numpy.flipud(out) + # out = out[...,::-1] + elif t == F.FByteDataType.PNG: + """ + + out = imageio.get_reader(data.tobytes() , - # "jpeg" - format="JPEG-PIL" + # "png" + format="PNG-PIL" ) - ''' - - out = PIL.Image.open(io.BytesIO(data.tobytes())) - else: - out = data - return out, [None] + """ + out = PIL.Image.open(io.BytesIO(data.tobytes())) + elif t == F.FByteDataType.JPEG: + """ + out = imageio.get_reader(data.tobytes() + , + # "jpeg" + format="JPEG-PIL" + ) + """ + + out = PIL.Image.open(io.BytesIO(data.tobytes())) + else: + out = data + return out, [None] def deserialise_array(flat_obs: Table) -> Tuple[numpy.ndarray, List]: - array = F.FArray() - array.Init(flat_obs.Bytes, flat_obs.Pos) - # data = numpy.array([array.Array(i) for i in range(array.ArrayLength())]) - data = array.ArrayAsNumpy() - return ( - data, - [ - Range(decimal_granularity=10, normalised=False) - for _ in range(array.ArrayLength()) - ], - ) + array = F.FArray() + array.Init(flat_obs.Bytes, flat_obs.Pos) + # data = numpy.array([array.Array(i) for i in range(array.ArrayLength())]) + data = array.ArrayAsNumpy() + return ( + data, + [ + Range(decimal_granularity=10, normalised=False) + for _ in range(array.ArrayLength()) + ], + ) def deserialise_actuators(flat_actor: FActor) -> Dict[str, Any]: - """ - -# All dictionaries in python3.6+ are insertion ordered, actuators are sorted by key and -# inserted so that the order of actuator key-value pairs are always the same for all instances the same -# environment. This is -# useful when descriptions are used for inference what value (motion strength) in a numeric vector -# corresponds to what actuator. - -:param flat_actor: -:return: -""" - actuators = {} - for i in range(flat_actor.ActuatorsLength()): - flat_actuator = flat_actor.Actuators(i) - input_actuator = US.Actuator( - flat_actuator.ActuatorName().decode(), flat_actuator.ActuatorRange() + """ + + # All dictionaries in python3.6+ are insertion ordered, actuators are sorted by key and + # inserted so that the order of actuator key-value pairs are always the same for all instances the same + # environment. This is + # useful when descriptions are used for inference what value (motion strength) in a numeric vector + # corresponds to what actuator. + + :param flat_actor: + :return:""" + actuators = {} + for i in range(flat_actor.ActuatorsLength()): + flat_actuator = flat_actor.Actuators(i) + input_actuator = US.Actuator( + flat_actuator.ActuatorName().decode(), flat_actuator.ActuatorRange() ) - actuators[input_actuator.actuator_name] = input_actuator + actuators[input_actuator.actuator_name] = input_actuator - out_actuators = {} - for key in sorted(actuators.keys()): - out_actuators[key] = actuators[key] + out_actuators = {} + for key in sorted(actuators.keys()): + out_actuators[key] = actuators[key] - return actuators + return actuators def deserialise_range(flat_range: FRange) -> Range: - """ + """ -@param flat_range: -@return: -""" - return Range( - decimal_granularity=flat_range.DecimalGranularity(), - min_value=flat_range.MinValue(), - max_value=flat_range.MaxValue(), - normalised=flat_range.Normalised(), - ) + @param flat_range: + @return:""" + return Range( + decimal_granularity=flat_range.DecimalGranularity(), + min_value=flat_range.MinValue(), + max_value=flat_range.MaxValue(), + normalised=flat_range.Normalised(), + ) def deserialise_space(flat_space: List[FRange]) -> List[Range]: - """ - -@param flat_space: -@return: -""" - ret = [] - for space in flat_space: - if space is not None: - ret.append(deserialise_range(space)) - return ret + """ + + @param flat_space: + @return:""" + ret = [] + for space in flat_space: + if space is not None: + ret.append(deserialise_range(space)) + return ret diff --git a/neodroid/messaging/message_client.py b/neodroid/messaging/message_client.py index 4c818abf..3005fd98 100644 --- a/neodroid/messaging/message_client.py +++ b/neodroid/messaging/message_client.py @@ -12,9 +12,7 @@ # @singleton class MessageClient(object): - """ - -""" + """""" def __init__( self, @@ -55,9 +53,7 @@ def __init__( self.LAST_RECEIVED_FRAME_NUMBER = 0 def open_connection(self): - """ - -""" + """""" self._request_socket = self._context.socket(self._socket_type) if not self._request_socket: @@ -83,9 +79,7 @@ def open_connection(self): self._poller.register(self._request_socket, zmq.POLLIN) def close_connection(self): - """ - -""" + """""" with suppress(zmq.error.ZMQError): # if not self._request_socket.closed: self._request_socket.setsockopt(zmq.LINGER, 0) @@ -94,18 +88,15 @@ def close_connection(self): # self._poller.close() def teardown(self): - """ - -""" + """""" self.close_connection() self._context.term() def build(self, single_threaded=False): """ -@param single_threaded: -@type single_threaded: -""" + @param single_threaded: + @type single_threaded:""" if single_threaded: self._context = zmq.Context.instance() @@ -119,11 +110,10 @@ def build(self, single_threaded=False): def send_receive(self, reactions): """ -@param reactions: -@type reactions: -@return: -@rtype: -""" + @param reactions: + @type reactions: + @return: + @rtype:""" if self._request_socket is None: self.build() diff --git a/neodroid/utilities/exceptions/exceptions.py b/neodroid/utilities/exceptions/exceptions.py index 86b43269..0a95308c 100644 --- a/neodroid/utilities/exceptions/exceptions.py +++ b/neodroid/utilities/exceptions/exceptions.py @@ -8,35 +8,28 @@ class InvalidReactionException(Exception): """ -Raised when a supplied reaction is invalid. -""" + Raised when a supplied reaction is invalid.""" def __init__(self, msg="The supplied reaction is invalid."): Exception.__init__(self, msg) class NoEnvironment(Exception): - """ - -""" + """""" def __init__(self, msg="No environment available."): Exception.__init__(self, msg) class NoUnobservablesException(Exception): - """ - - """ + """""" def __init__(self, msg="Unoberservables not available."): Exception.__init__(self, msg) class SensorNotAvailableException(Exception): - """ - - """ + """""" def __init__(self, msg="Sensor not available."): Exception.__init__(self, msg) diff --git a/neodroid/utilities/launcher/download_utilities/download_environment.py b/neodroid/utilities/launcher/download_utilities/download_environment.py index 6c350116..f079655a 100644 --- a/neodroid/utilities/launcher/download_utilities/download_environment.py +++ b/neodroid/utilities/launcher/download_utilities/download_environment.py @@ -1,5 +1,5 @@ import os -import pathlib +from pathlib import Path import stat import struct @@ -7,9 +7,7 @@ class DownloadProgress(tqdm): - """ - - """ + """""" last_block = 0 @@ -23,13 +21,13 @@ def __init__( def hook(self, block_num=1, block_size=1, total_size=None): """ - @param block_num: - @type block_num: - @param block_size: - @type block_size: - @param total_size: - @type total_size: - """ + @param block_num: + @type block_num: + @param block_size: + @type block_size: + @param total_size: + @type total_size: + """ self.total = total_size self.update((block_num - self.last_block) * block_size) self.last_block = block_num @@ -37,13 +35,12 @@ def hook(self, block_num=1, block_size=1, total_size=None): def download_environment( name: str = "mab_win", path_to_executables_directory: str = "/tmp/neodroid" -) -> pathlib.Path: +) -> Path: """ -:param path_to_executables_directory: -:return: -:type name: object -""" + :param path_to_executables_directory: + :return: + :type name: object""" from urllib.request import urlretrieve import zipfile @@ -54,9 +51,7 @@ def download_environment( print(f"\nFetching {name} environment\n") # download_format = 'https://drive.google.com/uc?export=download&confirm=NezD&id={FILE_ID}' - formatted = ( - f"https://drive.google.com/uc?export=download&confirm=-oy0&id={hash_id}" - ) # +'.tmp') + formatted = f"https://drive.google.com/uc?export=download&confirm=-oy0&id={hash_id}" # +'.tmp') if not os.path.exists(path_to_executables_directory): os.makedirs(path_to_executables_directory) @@ -64,14 +59,14 @@ def download_environment( with DownloadProgress(desc=name) as progress_bar: zip_file_name, headers = urlretrieve( formatted, - str(pathlib.Path(path_to_executables_directory) / f"{name}.zip"), + str(Path(path_to_executables_directory) / f"{name}.zip"), reporthook=progress_bar.hook, ) with zipfile.ZipFile(zip_file_name, "r") as zip_ref: zip_ref.extractall(path_to_executables_directory) - zip_file_name = str(pathlib.Path(path_to_executables_directory) / zip_file_name) + zip_file_name = str(Path(path_to_executables_directory) / zip_file_name) # shutil.rmtree(file, ignore_errors=True) os.remove(zip_file_name) @@ -81,13 +76,11 @@ def download_environment( if system_arch == 32: path_to_executable = str( - pathlib.Path(path_to_executables_directory) - / name - / f"{executable_file_name}.x86" + Path(path_to_executables_directory) / name / f"{executable_file_name}.x86" ) else: path_to_executable = str( - pathlib.Path(path_to_executables_directory) + Path(path_to_executables_directory) / name / f"{executable_file_name}.x86_64" ) @@ -95,17 +88,17 @@ def download_environment( st = os.stat(path_to_executable) os.chmod(path_to_executable, st.st_mode | stat.S_IEXEC) - return pathlib.Path(path_to_executables_directory) / name + return Path(path_to_executables_directory) / name def available_environments(repository="http://environments.neodroid.ml/ls"): """ - @param repository: - @type repository: - @return: - @rtype: - """ + @param repository: + @type repository: + @return: + @rtype: + """ from urllib.request import Request, urlopen import csv diff --git a/neodroid/utilities/launcher/environment_launcher.py b/neodroid/utilities/launcher/environment_launcher.py index e5272d51..a99b1012 100644 --- a/neodroid/utilities/launcher/environment_launcher.py +++ b/neodroid/utilities/launcher/environment_launcher.py @@ -16,15 +16,14 @@ def launch_environment( """ -:param environment_name: -:param path_to_executables_directory: -:param ip: -:param port: -:param headless: -:return: -""" + :param environment_name: + :param path_to_executables_directory: + :param ip: + :param port: + :param headless: + :return:""" import logging - import pathlib + from pathlib import Path from neodroid.utilities.launcher.download_utilities.download_environment import ( download_environment, @@ -36,9 +35,9 @@ def launch_environment( import sys import stat - environment_name = pathlib.Path(environment_name) + environment_name = Path(environment_name) - if pathlib.Path.exists(environment_name): + if Path.exists(environment_name): path_to_executable = environment_name else: system_arch = struct.calcsize("P") * 8 @@ -56,7 +55,7 @@ def launch_environment( else: variation_name = f"{variation_name}_linux" - base_name = pathlib.Path(path_to_executables_directory) / environment_name + base_name = Path(path_to_executables_directory) / environment_name path = base_name / variation_name if not base_name.exists(): @@ -85,9 +84,9 @@ def launch_environment( true_filename = os.path.basename(os.path.normpath(file_name)) launch_string = None if platform == 'linux' or platform == 'linux2': -candidates = glob.glob(pathlib.Path.joinpath(cwd, file_name) + '.x86_64') +candidates = glob.glob(Path.joinpath(cwd, file_name) + '.x86_64') if len(candidates) == 0: -candidates = glob.glob(pathlib.Path.joinpath(cwd, file_name) + '.x86') +candidates = glob.glob(Path.joinpath(cwd, file_name) + '.x86') if len(candidates) == 0: candidates = glob.glob(file_name + '.x86_64') if len(candidates) == 0: @@ -96,19 +95,19 @@ def launch_environment( launch_string = candidates[0] elif platform == 'darwin': -candidates = glob.glob(pathlib.Path.joinpath(cwd, file_name + '.app', 'Contents', 'MacOS', +candidates = glob.glob(Path.joinpath(cwd, file_name + '.app', 'Contents', 'MacOS', true_filename)) if len(candidates) == 0: -candidates = glob.glob(pathlib.Path.joinpath(file_name + '.app', 'Contents', 'MacOS', +candidates = glob.glob(Path.joinpath(file_name + '.app', 'Contents', 'MacOS', true_filename)) if len(candidates) == 0: -candidates = glob.glob(pathlib.Path.joinpath(cwd, file_name + '.app', 'Contents', 'MacOS', '*')) +candidates = glob.glob(Path.joinpath(cwd, file_name + '.app', 'Contents', 'MacOS', '*')) if len(candidates) == 0: -candidates = glob.glob(pathlib.Path.joinpath(file_name + '.app', 'Contents', 'MacOS', '*')) +candidates = glob.glob(Path.joinpath(file_name + '.app', 'Contents', 'MacOS', '*')) if len(candidates) > 0: launch_string = candidates[0] elif platform == 'win32': -candidates = glob.glob(pathlib.Path.joinpath(cwd, file_name + '.exe')) +candidates = glob.glob(Path.joinpath(cwd, file_name + '.exe')) if len(candidates) == 0: candidates = glob.glob(file_name + '.exe') if len(candidates) > 0: diff --git a/neodroid/utilities/snapshot_extraction/camera_extraction.py b/neodroid/utilities/snapshot_extraction/camera_extraction.py index 66803008..21a925c1 100644 --- a/neodroid/utilities/snapshot_extraction/camera_extraction.py +++ b/neodroid/utilities/snapshot_extraction/camera_extraction.py @@ -36,13 +36,13 @@ def extract_from_cameras(state, cameras=default_camera_observer_names): """ - @param state: - @type state: - @param cameras: - @type cameras: - @return: - @rtype: - """ + @param state: + @type state: + @param cameras: + @type cameras: + @return: + @rtype: + """ out = dict() for camera in cameras: @@ -56,11 +56,11 @@ def extract_from_cameras(state, cameras=default_camera_observer_names): def extract_all_cameras(state): """ - @param state: - @type state: - @return: - @rtype: - """ + @param state: + @type state: + @return: + @rtype: + """ out = dict() for camera in state.sensors.keys(): @@ -74,13 +74,13 @@ def extract_all_cameras(state): def extract_camera_observation(state, key): """ - @param state: - @type state: - @param key: - @type key: - @return: - @rtype: - """ + @param state: + @type state: + @param key: + @type key: + @return: + @rtype: + """ sensor = state.sensor(key) if sensor and sensor.is_image: img = sensor.value diff --git a/neodroid/utilities/snapshot_extraction/vector_environment_snapshot.py b/neodroid/utilities/snapshot_extraction/vector_environment_snapshot.py index 322f25af..455c39fb 100644 --- a/neodroid/utilities/snapshot_extraction/vector_environment_snapshot.py +++ b/neodroid/utilities/snapshot_extraction/vector_environment_snapshot.py @@ -24,8 +24,7 @@ class VectorPoints(IterDictValuesMixin, OrdinalIndexingDictMixin): def __len__(self): """ -@return: -""" + @return:""" return len(self.terminated) @@ -39,8 +38,7 @@ class NumpyVectorPoints(IterDictValuesMixin, OrdinalIndexingDictMixin): def __len__(self): """ -@return: -""" + @return:""" return len(self.terminated) diff --git a/neodroid/utilities/spaces/action_space.py b/neodroid/utilities/spaces/action_space.py index b14a07c7..3e72d1d7 100644 --- a/neodroid/utilities/spaces/action_space.py +++ b/neodroid/utilities/spaces/action_space.py @@ -16,9 +16,9 @@ class ActionSpace(Space): def sample(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ actions = [] for valid_input in self._ranges: sample = numpy.random.uniform( @@ -30,11 +30,11 @@ def sample(self): def validate(self, actions): """ - @param actions: - @type actions: - @return: - @rtype: - """ + @param actions: + @type actions: + @return: + @rtype: + """ for i in range(len(actions)): clipped = numpy.clip( actions[i], self._ranges[i].min_unnorm, self._ranges[i].max_unnorm @@ -45,9 +45,9 @@ def validate(self, actions): def discrete_one_hot_sample(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ idx = numpy.random.randint(0, self.num_actuators) zeros = numpy.zeros(self.num_actuators) if len(self._ranges) > 0: @@ -60,18 +60,18 @@ def discrete_one_hot_sample(self): def discrete_sample(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ idx = numpy.random.randint(0, self.discrete_steps) return idx def one_hot_sample(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ idx = numpy.random.randint(0, self.num_actuators) zeros = numpy.zeros(self.num_actuators) if len(self._ranges) > 0: @@ -82,9 +82,9 @@ def one_hot_sample(self): def num_actuators(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self.n diff --git a/neodroid/utilities/spaces/observation_space.py b/neodroid/utilities/spaces/observation_space.py index 95bd3af5..e7b062d6 100644 --- a/neodroid/utilities/spaces/observation_space.py +++ b/neodroid/utilities/spaces/observation_space.py @@ -15,9 +15,9 @@ class ObservationSpace(Space): def space(self) -> Sequence: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self.continuous_shape diff --git a/neodroid/utilities/spaces/range.py b/neodroid/utilities/spaces/range.py index 5b5c756c..9214d4f1 100644 --- a/neodroid/utilities/spaces/range.py +++ b/neodroid/utilities/spaces/range.py @@ -14,20 +14,17 @@ class Range: - """ - -""" + """""" def __init__( self, *, min_value=0, max_value=1, decimal_granularity=0, normalised=True ): """ -:param min_value: -:param max_value: -:param decimal_granularity: -:param normalised: -""" + :param min_value: + :param max_value: + :param decimal_granularity: + :param normalised:""" assert max_value >= min_value # assert decimal_granularity >= 0 @@ -40,45 +37,44 @@ def __init__( @property def normalised(self) -> bool: """ -Indicates whether the action space span is zero-one normalised -:return: -""" + Indicates whether the action space span is zero-one normalised + :return:""" return self._normalised @property def decimal_granularity(self) -> int: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._decimal_granularity @property def min_unnorm(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._min_value @property def max_unnorm(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._max_value @cached_property def min(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self.normalised: return 0 return self.min_unnorm @@ -87,9 +83,9 @@ def min(self) -> float: def max(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self.normalised: return 1 return self.max_unnorm @@ -98,9 +94,9 @@ def max(self) -> float: def discrete_step_size(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self.decimal_granularity >= 0: return 1 / numpy.power(10, self.decimal_granularity) return sys.float_info.epsilon # numpy.inf @@ -109,18 +105,18 @@ def discrete_step_size(self) -> float: def span_unnorm(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self.max_unnorm - self.min_unnorm @cached_property def span(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self.normalised: return 1 return self.span_unnorm @@ -129,18 +125,17 @@ def span(self) -> float: def discrete_steps(self) -> int: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return math.floor(self.span_unnorm / self.discrete_step_size) + 1 @functools.lru_cache() def to_dict(self) -> dict: """ -type(dict) -:return: -""" + type(dict) + :return:""" return { "decimal_granularity": self._decimal_granularity, "min_value": self._min_value, @@ -150,31 +145,31 @@ def to_dict(self) -> dict: def normalise(self, value): """ - @param value: - @type value: - @return: - @rtype: - """ + @param value: + @type value: + @return: + @rtype: + """ return (self.min_unnorm + value + 1) / (self.max_unnorm + 1) def denormalise(self, value): """ - @param value: - @type value: - @return: - @rtype: - """ + @param value: + @type value: + @return: + @rtype: + """ return (value * self.max_unnorm) - self.min_unnorm def clip(self, value): """ - @param value: - @type value: - @return: - @rtype: - """ + @param value: + @type value: + @return: + @rtype: + """ if self.span > 0: return numpy.clip(value, self._min_value, self._max_value) return value @@ -182,11 +177,11 @@ def clip(self, value): def round(self, value): """ - @param value: - @type value: - @return: - @rtype: - """ + @param value: + @type value: + @return: + @rtype: + """ if self.decimal_granularity >= 0: return numpy.round(value, self.decimal_granularity) return value @@ -194,11 +189,11 @@ def round(self, value): def clip_normalise_round(self, value): """ - @param value: - @type value: - @return: - @rtype: - """ + @param value: + @type value: + @return: + @rtype: + """ return self.round(self.normalise(self.clip(value))) @functools.lru_cache() @@ -221,9 +216,9 @@ def __unicode__(self) -> str: def sample(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self.decimal_granularity == 0: return self.cheapest_sample() @@ -233,9 +228,9 @@ def sample(self) -> float: def cheapest_sample(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ val = numpy.random.randint(self.min, self.max + 1) if isinstance(val, numpy.ndarray): @@ -246,9 +241,9 @@ def cheapest_sample(self) -> float: def cheaper_sample(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ val = self.round(numpy.random.random() * self.span) if isinstance(val, numpy.ndarray): @@ -259,9 +254,9 @@ def cheaper_sample(self) -> float: def expensive_sample(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ val = numpy.random.choice( numpy.linspace(self.min, self.max, num=self.discrete_steps) ) diff --git a/neodroid/utilities/spaces/signal_space.py b/neodroid/utilities/spaces/signal_space.py index c9a7e868..7ed09744 100644 --- a/neodroid/utilities/spaces/signal_space.py +++ b/neodroid/utilities/spaces/signal_space.py @@ -16,9 +16,7 @@ class SignalSpace(Space): - """ - - """ + """""" def __init__(self, ranges: Sequence[Range], solved_threshold=math.inf): super().__init__(ranges) @@ -28,20 +26,20 @@ def __init__(self, ranges: Sequence[Range], solved_threshold=math.inf): def is_solved(self, value) -> bool: """ - @param value: - @type value: - @return: - @rtype: - """ + @param value: + @type value: + @return: + @rtype: + """ return value > self.solved_threshold @cached_property def is_sparse(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return numpy.array([a.decimal_granularity == 0 for a in self._ranges]).all() diff --git a/neodroid/utilities/spaces/space.py b/neodroid/utilities/spaces/space.py index 93d0e2f8..1df16e72 100644 --- a/neodroid/utilities/spaces/space.py +++ b/neodroid/utilities/spaces/space.py @@ -15,16 +15,13 @@ class Space(object): - """ - -""" + """""" def __init__(self, ranges: Sequence[Range], names: Sequence[str] = ()): """ -:param ranges: -:param names: -""" + :param ranges: + :param names:""" assert isinstance(ranges, Sequence) self._ranges = ranges self._names = names @@ -32,9 +29,8 @@ def __init__(self, ranges: Sequence[Range], names: Sequence[str] = ()): def project(self, a: Sequence[float]) -> Sequence[float]: """ -@param a: -@return: -""" + @param a: + @return:""" if self.is_discrete: return a # if self.is_01normalised: @@ -45,9 +41,8 @@ def project(self, a: Sequence[float]) -> Sequence[float]: def reproject(self, a: Sequence[float]) -> Sequence[float]: """ -@param a: -@return: -""" + @param a: + @return:""" if self.is_discrete: return a # if self.is_01normalised: @@ -58,65 +53,57 @@ def reproject(self, a: Sequence[float]) -> Sequence[float]: def clip(self, values: Sequence) -> numpy.ndarray: """ -@param values: -@return: -""" + @param values: + @return:""" assert len(self.ranges) == len(values) return numpy.array([a.clip(v) for a, v in zip(self._ranges, values)]) def sample(self) -> Sequence[float]: """ -@return: -""" + @return:""" return [r.sample() for r in self._ranges] @property def max(self) -> numpy.ndarray: """ -@return: -""" + @return:""" return self.high @property def min(self) -> numpy.ndarray: """ -@return: -""" + @return:""" return self.low @cached_property def ranges(self) -> Sequence[Range]: """ -@return: -""" + @return:""" return self._ranges @cached_property def low(self) -> numpy.ndarray: """ -@return: -""" + @return:""" return numpy.array([motion_space.min_unnorm for motion_space in self._ranges]) @cached_property def high(self) -> numpy.ndarray: """ -@return: -""" + @return:""" return numpy.array([motion_space.max_unnorm for motion_space in self._ranges]) @cached_property def span(self) -> numpy.ndarray: """ -@return: -""" + @return:""" res = self.high - self.low assert (res > 0).all() return res @@ -125,32 +112,28 @@ def span(self) -> numpy.ndarray: def decimal_granularity(self) -> List[int]: """ -@return: -""" + @return:""" return [motion_space.decimal_granularity for motion_space in self._ranges] @cached_property def is_singular(self) -> bool: """ -@return: -""" + @return:""" return len(self._ranges) == 1 @cached_property def is_discrete(self) -> bool: """ -@return: -""" + @return:""" return numpy.array([a.decimal_granularity == 0 for a in self._ranges]).all() @cached_property def is_mixed(self) -> bool: """ -@return: -""" + @return:""" return ( numpy.array([a.decimal_granularity != 0 for a in self._ranges]).any() and not self.is_continuous @@ -160,16 +143,14 @@ def is_mixed(self) -> bool: def is_continuous(self) -> bool: """ -@return: -""" + @return:""" return numpy.array([a.decimal_granularity != 0 for a in self._ranges]).all() @cached_property def shape(self) -> Tuple[int, ...]: """ -@return: -""" + @return:""" if self.is_discrete: return self.discrete_steps_shape @@ -179,32 +160,28 @@ def shape(self) -> Tuple[int, ...]: def discrete_steps(self) -> int: """ -@return: -""" + @return:""" return sum(self.discrete_steps_shape) @cached_property def discrete_steps_shape(self) -> Tuple[int, ...]: """ -@return: -""" + @return:""" return (*[r.discrete_steps for r in self._ranges],) @cached_property def continuous_shape(self) -> Tuple[int, ...]: """ -@return: -""" + @return:""" return (len(self._ranges),) @cached_property def is_01normalised(self) -> numpy.ndarray: """ -@return: -""" + @return:""" return numpy.array( [a.normalised for a in self._ranges if hasattr(a, "normalised")] ).all() @@ -213,8 +190,7 @@ def is_01normalised(self) -> numpy.ndarray: def __repr__(self) -> str: """ -@return: -""" + @return:""" names_str = "".join([str(r.__repr__()) for r in self._names]) ranges_str = "".join([str(r.__repr__()) for r in self._ranges]) @@ -229,16 +205,14 @@ def __repr__(self) -> str: def n(self) -> int: """ -@return: -""" + @return:""" return len(self._ranges) @functools.lru_cache() def __len__(self) -> int: """ -@return: -""" + @return:""" return self.n diff --git a/neodroid/utilities/spaces/vector/vector_action_space.py b/neodroid/utilities/spaces/vector/vector_action_space.py index 1604cc40..994324a8 100644 --- a/neodroid/utilities/spaces/vector/vector_action_space.py +++ b/neodroid/utilities/spaces/vector/vector_action_space.py @@ -11,9 +11,7 @@ class VectorActionSpace: - """ - - """ + """""" def __init__(self, action_space: ActionSpace, num_env: int): self.action_space = action_space @@ -22,9 +20,9 @@ def __init__(self, action_space: ActionSpace, num_env: int): def sample(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return [self.action_space.sample() for _ in range(self.num_env)] def __getattr__(self, item): diff --git a/neodroid/utilities/transformations/action_transformations.py b/neodroid/utilities/transformations/action_transformations.py index 2c9bc6d0..cb9b51b8 100644 --- a/neodroid/utilities/transformations/action_transformations.py +++ b/neodroid/utilities/transformations/action_transformations.py @@ -8,13 +8,13 @@ def reverse_normalise_action(self, action): """ - @param self: - @type self: - @param action: - @type action: - @return: - @rtype: - """ + @param self: + @type self: + @param action: + @type action: + @return: + @rtype: + """ act_k_inv = 2.0 / (self.action_space.high - self.action_space.low) act_b = (self.action_space.high + self.action_space.low) / 2.0 return act_k_inv * (action - act_b) @@ -23,13 +23,13 @@ def reverse_normalise_action(self, action): def normalise_action(action, motion_space): """ - @param action: - @type action: - @param motion_space: - @type motion_space: - @return: - @rtype: - """ + @param action: + @type action: + @param motion_space: + @type motion_space: + @return: + @rtype: + """ act_k = (motion_space.max_unnorm - motion_space.min_unnorm) / 2.0 act_b = (motion_space.max_unnorm + motion_space.min_unnorm) / 2.0 return act_k * action + act_b diff --git a/neodroid/utilities/transformations/encodings.py b/neodroid/utilities/transformations/encodings.py index 62cbc491..dd4bc393 100644 --- a/neodroid/utilities/transformations/encodings.py +++ b/neodroid/utilities/transformations/encodings.py @@ -13,89 +13,86 @@ def signed_ternary_encoding(*, size: int, index: int): - """ - -@param size: -@type size: -@param index: -@type index: -@return: -@rtype: -""" - # assert isinstance(size,(int,numpy.int64)), f'size was {type(size)}' - # assert isinstance(index,(int,numpy.int64)), f'index was {type(index)}' - # assert size*2 > index, f'signed size was {size*2}, index was {index}' - - if not isinstance(index, Iterable): - index = [index] - acs = [] - for i in index: - a = numpy.zeros(size) - if i < 0: - return a - elif 0 <= i < size: - a[i] = 1 - elif size <= i < size * 2: - a[i - size] = -1 - acs.append(a) - return acs - - -def to_one_hot(dims:Sequence[int], index:Union[int,Sized]): - """ - -@param dims: -@type dims: -@param index: -@type index: -@return: -@rtype: -""" - if not isinstance(index, Sized): - index = [index] - - acs = [] - for i in index: - if isinstance(i, numpy.int) or isinstance(i, int): - one_hot = numpy.zeros(dims) - one_hot[i] = 1.0 - else: - one_hot = numpy.zeros((len(i), *dims)) - one_hot[numpy.arange(len(i)), i] = 1.0 - acs.append(one_hot) - - return acs + """ + + @param size: + @type size: + @param index: + @type index: + @return: + @rtype:""" + # assert isinstance(size,(int,numpy.int64)), f'size was {type(size)}' + # assert isinstance(index,(int,numpy.int64)), f'index was {type(index)}' + # assert size*2 > index, f'signed size was {size*2}, index was {index}' + + if not isinstance(index, Iterable): + index = [index] + acs = [] + for i in index: + a = numpy.zeros(size) + if i < 0: + return a + elif 0 <= i < size: + a[i] = 1 + elif size <= i < size * 2: + a[i - size] = -1 + acs.append(a) + return acs + + +def to_one_hot(dims: Sequence[int], index: Union[int, Sized]): + """ + + @param dims: + @type dims: + @param index: + @type index: + @return: + @rtype:""" + if not isinstance(index, Sized): + index = [index] + + acs = [] + for i in index: + if isinstance(i, numpy.int) or isinstance(i, int): + one_hot = numpy.zeros(dims) + one_hot[i] = 1.0 + else: + one_hot = numpy.zeros((len(i), *dims)) + one_hot[numpy.arange(len(i)), i] = 1.0 + acs.append(one_hot) + + return acs def agg_double_list(l): - """ + """ -@param l: -@type l: -@return: -@rtype: -""" - # l: [ [...], [...], [...] ] - # l_i: result of each step in the i-th episode - s = [numpy.sum(numpy.array(l_i), 0) for l_i in l] - s_mu = numpy.mean(numpy.array(s), 0) - s_std = numpy.std(numpy.array(s), 0) - return s_mu, s_std + @param l: + @type l: + @return: + @rtype:""" + # l: [ [...], [...], [...] ] + # l_i: result of each step in the i-th episode + s = [numpy.sum(numpy.array(l_i), 0) for l_i in l] + s_mu = numpy.mean(numpy.array(s), 0) + s_std = numpy.std(numpy.array(s), 0) + return s_mu, s_std if __name__ == "__main__": - def aasdsd(): - a_size = 2 - a_index = 0 - print(signed_ternary_encoding(size=a_size, index=a_index)) + def aasdsd(): + a_size = 2 + a_index = 0 + print(signed_ternary_encoding(size=a_size, index=a_index)) - def asadaasdsd(): - print(to_one_hot(dims=(3,), index=0)) - print(to_one_hot(dims=(3,),index=(0,))) - print(to_one_hot(dims=(3,),index=(0,1,0,2))) - print(to_one_hot(dims=(3,),index=([0],[1],[0],[2]))) + def asadaasdsd(): + print(to_one_hot(dims=(3,), index=0)) + print(to_one_hot(dims=(3,), index=(0,))) + print(to_one_hot(dims=(3,), index=(0, 1, 0, 2))) + print(to_one_hot(dims=(3,), index=([0], [1], [0], [2]))) - #aasdsd() + # aasdsd() - asadaasdsd() + asadaasdsd() diff --git a/neodroid/utilities/transformations/quaternion.py b/neodroid/utilities/transformations/quaternion.py index 3f8c6bf0..c9f7a341 100644 --- a/neodroid/utilities/transformations/quaternion.py +++ b/neodroid/utilities/transformations/quaternion.py @@ -18,13 +18,13 @@ def normalise_vector(vector: Iterable, tolerance=0.00001) -> numpy.ndarray: """ - @param vector: - @type vector: - @param tolerance: - @type tolerance: - @return: - @rtype: - """ + @param vector: + @type vector: + @param tolerance: + @type tolerance: + @return: + @rtype: + """ mag2 = sum(n * n for n in vector) if abs(mag2 - 1.0) > tolerance: mag = sqrt(mag2) @@ -37,13 +37,13 @@ class Quaternion: def from_axisangle(theta, vector): """ - @param theta: - @type theta: - @param vector: - @type vector: - @return: - @rtype: - """ + @param theta: + @type theta: + @param vector: + @type vector: + @return: + @rtype: + """ vector = normalise_vector(vector) new_quaternion = Quaternion() @@ -54,11 +54,11 @@ def from_axisangle(theta, vector): def from_value(value): """ - @param value: - @type value: - @return: - @rtype: - """ + @param value: + @type value: + @return: + @rtype: + """ new_quaternion = Quaternion() new_quaternion.components = value return new_quaternion @@ -104,9 +104,9 @@ def _multiply_with_vector(self, vector: Iterable): def get_conjugate(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ w, x, y, z = self.components result = Quaternion.from_value(numpy.array((w, -x, -y, -z))) return result @@ -118,9 +118,9 @@ def __repr__(self): def get_axisangle(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ w, axis = self.components[0], self.components[1:] theta = acos(w) * 2.0 @@ -129,17 +129,17 @@ def get_axisangle(self): def tolist(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self.components.tolist() def vector_norm(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ w, v = self.get_axisangle() return numpy.linalg.norm(v) diff --git a/neodroid/utilities/transformations/terminal_masking.py b/neodroid/utilities/transformations/terminal_masking.py index 370b5f40..20a67fd4 100644 --- a/neodroid/utilities/transformations/terminal_masking.py +++ b/neodroid/utilities/transformations/terminal_masking.py @@ -19,9 +19,8 @@ def non_terminal_mask(terminal: Any) -> Any: """ -@param terminal: -@return: -""" + @param terminal: + @return:""" if isinstance(terminal, bool): return not terminal if isinstance(terminal, (numpy.ndarray, Sequence)): @@ -36,9 +35,8 @@ def non_terminal_mask(terminal: Any) -> Any: def non_terminal_numerical_mask(terminal: Any) -> Any: """ -@param terminal: -@return: -""" + @param terminal: + @return:""" if isinstance(terminal, bool): return 0 if terminal else 1 if isinstance(terminal, tuple): diff --git a/neodroid/utilities/unity_specifications/actor.py b/neodroid/utilities/unity_specifications/actor.py index cde0f267..30ae8348 100644 --- a/neodroid/utilities/unity_specifications/actor.py +++ b/neodroid/utilities/unity_specifications/actor.py @@ -11,9 +11,7 @@ class Actor(object): - """ - - """ + """""" def __init__(self, flat_actor): self._flat_actor = flat_actor @@ -22,28 +20,28 @@ def __init__(self, flat_actor): def actor_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._flat_actor.ActorName().decode() @cached_property def is_alive(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._flat_actor.Alive() def actuator(self, key) -> Union[None, Any]: """ - @param key: - @type key: - @return: - @rtype: - """ + @param key: + @type key: + @return: + @rtype: + """ if key in deserialise_actuators(self._flat_actor): return deserialise_actuators(self._flat_actor)[key] @@ -51,9 +49,9 @@ def actuator(self, key) -> Union[None, Any]: def actuators(self) -> Dict[str, Any]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return deserialise_actuators(self._flat_actor) @functools.lru_cache() diff --git a/neodroid/utilities/unity_specifications/actuator.py b/neodroid/utilities/unity_specifications/actuator.py index 052ab28c..785b7679 100644 --- a/neodroid/utilities/unity_specifications/actuator.py +++ b/neodroid/utilities/unity_specifications/actuator.py @@ -11,9 +11,7 @@ class Actuator(object): - """ - - """ + """""" def __init__(self, actuator_name, motion_space): self._actuator_name = actuator_name @@ -23,18 +21,18 @@ def __init__(self, actuator_name, motion_space): def actuator_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._actuator_name @cached_property def motion_space(self) -> Range: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return deserialise_range(self._range) @functools.lru_cache() diff --git a/neodroid/utilities/unity_specifications/configurable.py b/neodroid/utilities/unity_specifications/configurable.py index d6d4e7a5..73a00b51 100644 --- a/neodroid/utilities/unity_specifications/configurable.py +++ b/neodroid/utilities/unity_specifications/configurable.py @@ -13,9 +13,7 @@ class Configurable(object): - """ - - """ + """""" def __init__( self, @@ -31,27 +29,27 @@ def __init__( def configurable_name(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._configurable_name @cached_property def configurable_value(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._configurable_value @cached_property def configurable_space(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self._configurable_space: # space = deserialise_space(self._configurable_space) #Already done space = self._configurable_space @@ -61,9 +59,9 @@ def configurable_space(self): def to_dict(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return { "configurable_name": self.configurable_name, "configurable_value": self.configurable_value, diff --git a/neodroid/utilities/unity_specifications/configuration.py b/neodroid/utilities/unity_specifications/configuration.py index b17644f3..fcb05f54 100644 --- a/neodroid/utilities/unity_specifications/configuration.py +++ b/neodroid/utilities/unity_specifications/configuration.py @@ -8,9 +8,7 @@ class Configuration(object): - """ - - """ + """""" def __init__(self, configurable_name, configurable_value): self._configurable_name = configurable_name @@ -20,27 +18,27 @@ def __init__(self, configurable_name, configurable_value): def configurable_name(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._configurable_name @cached_property def configurable_value(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._configurable_value @functools.lru_cache() def to_dict(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return { "_configurable_name": self._configurable_name, "_configurable_value": self._configurable_value, diff --git a/neodroid/utilities/unity_specifications/displayable.py b/neodroid/utilities/unity_specifications/displayable.py index 68acefdf..532dc6e0 100644 --- a/neodroid/utilities/unity_specifications/displayable.py +++ b/neodroid/utilities/unity_specifications/displayable.py @@ -7,9 +7,7 @@ class Displayable(object): - """ - - """ + """""" def __init__(self, displayable_name, displayable_value): self._displayable_name = displayable_name @@ -19,26 +17,26 @@ def __init__(self, displayable_name, displayable_value): def displayable_name(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._displayable_name @cached_property def displayable_value(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._displayable_value def to_dict(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return { "_displayable_name": self._displayable_name, "_displayable_value": self._displayable_value, diff --git a/neodroid/utilities/unity_specifications/environment_description.py b/neodroid/utilities/unity_specifications/environment_description.py index c1cc5bdc..404df0a5 100644 --- a/neodroid/utilities/unity_specifications/environment_description.py +++ b/neodroid/utilities/unity_specifications/environment_description.py @@ -18,9 +18,7 @@ class EnvironmentDescription(object): - """ - - """ + """""" def __init__(self, fbs_description: FEnvironmentDescription): self._fbs_description = fbs_description @@ -29,37 +27,37 @@ def __init__(self, fbs_description: FEnvironmentDescription): def objective_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._fbs_description.Objective().ObjectiveName() @cached_property def max_episode_length(self) -> int: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._fbs_description.Objective().MaxEpisodeLength() @cached_property def actors(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return deserialise_actors(self._fbs_description) def actor(self, key): """ - @param key: - @type key: - @return: - @rtype: - """ + @param key: + @type key: + @return: + @rtype: + """ actors = self.actors if key in actors: return actors[key] @@ -68,9 +66,9 @@ def actor(self, key): def actuators(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ actuators_out = [] for a in deserialise_actors(self._fbs_description).values(): actuators_out.append(a.actuators) @@ -79,11 +77,11 @@ def actuators(self): def actuator(self, key): """ - @param key: - @type key: - @return: - @rtype: - """ + @param key: + @type key: + @return: + @rtype: + """ actuators = self.actuators if key in actuators: return actuators[key] @@ -92,19 +90,19 @@ def actuator(self, key): def sensors(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return deserialise_sensors(self._fbs_description) def sensor(self, key) -> Sensor: """ - @param key: - @type key: - @return: - @rtype: - """ + @param key: + @type key: + @return: + @rtype: + """ if key in self.sensors: return self.sensors[key] @@ -112,19 +110,19 @@ def sensor(self, key) -> Sensor: def configurables(self) -> Dict[str, Configurable]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return deserialise_configurables(self._fbs_description) def configurable(self, key: str) -> Configurable: """ - @param key: - @type key: - @return: - @rtype: - """ + @param key: + @type key: + @return: + @rtype: + """ configurables = self.configurables if key in configurables: return configurables[key] @@ -160,9 +158,9 @@ def __unicode__(self) -> str: def observation_space(self) -> ObservationSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ sensor_names = self.sensors.keys() observation_spaces = [] observers = self.sensors.values() @@ -175,9 +173,9 @@ def observation_space(self) -> ObservationSpace: def action_space(self) -> ActionSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ motion_names = self.actors.keys() motion_spaces = [] for actor in self.actors.values(): @@ -187,12 +185,12 @@ def action_space(self) -> ActionSpace: return ActionSpace(motion_spaces, motion_names) @cached_property - def signal_space(environment_description) -> SignalSpace: + def signal_space(self) -> SignalSpace: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return SignalSpace((Range(min_value=-1, max_value=1, decimal_granularity=3),)) diff --git a/neodroid/utilities/unity_specifications/environment_snapshot.py b/neodroid/utilities/unity_specifications/environment_snapshot.py index 8cc00c27..eda36a94 100644 --- a/neodroid/utilities/unity_specifications/environment_snapshot.py +++ b/neodroid/utilities/unity_specifications/environment_snapshot.py @@ -24,9 +24,7 @@ class EnvironmentSnapshot(object): - """ - - """ + """""" def __init__(self, fbs_state: FState = None): self._fbs_state = fbs_state @@ -39,9 +37,9 @@ def _environment_name(self) -> str: def environment_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._environment_name, Callable): self._environment_name = self._environment_name() return self._environment_name @@ -54,9 +52,9 @@ def _signal(self) -> float: def signal(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._signal, Callable): self._signal = self._signal() return self._signal @@ -69,9 +67,9 @@ def _observables(self) -> List[float]: def observables(self) -> List[float]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._observables, Callable): self._observables = self._observables() return self._observables @@ -84,9 +82,9 @@ def _unobservables(self) -> List[float]: def unobservables(self) -> List[float]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._unobservables, Callable): self._unobservables = self._unobservables() return self._unobservables @@ -99,9 +97,9 @@ def _frame_number(self) -> int: def frame_number(self) -> int: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._frame_number, Callable): self._frame_number = self._frame_number() return self._frame_number @@ -114,9 +112,9 @@ def _terminated(self) -> bool: def terminated(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._terminated, Callable): self._terminated = self._terminated() return self._terminated @@ -129,9 +127,9 @@ def _termination_reason(self) -> str: def termination_reason(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._termination_reason, Callable): self._termination_reason = self._termination_reason() return self._termination_reason @@ -144,9 +142,9 @@ def _extra_serialised_message(self) -> str: def extra_serialised_message(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if isinstance(self._extra_serialised_message, Callable): self._extra_serialised_message = self._extra_serialised_message() return self._extra_serialised_message @@ -155,9 +153,9 @@ def extra_serialised_message(self) -> str: def description(self) -> EnvironmentDescription: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self._fbs_state: if self._fbs_state.EnvironmentDescription(): return deserialise_description(self._fbs_state.EnvironmentDescription()) @@ -166,20 +164,20 @@ def description(self) -> EnvironmentDescription: def sensors(self) -> Mapping[str, Sensor]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self.description: return self.description.sensors def sensor(self, key) -> Sensor: """ - @param key: - @type key: - @return: - @rtype: - """ + @param key: + @type key: + @return: + @rtype: + """ if self.description: return self.description.sensor(key) @@ -187,29 +185,29 @@ def sensor(self, key) -> Sensor: def configurables(self) -> Mapping[str, Configurable]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self.description: return self.description.configurables def configurable(self, key) -> Configurable: """ - @param key: - @type key: - @return: - @rtype: - """ + @param key: + @type key: + @return: + @rtype: + """ if self.description: return self.description.configurable(key) def to_gym_like_output(self) -> tuple: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self.observables, self.signal, self.terminated, self @staticmethod @@ -218,19 +216,19 @@ def from_gym( ) -> EnvironmentSnapshotType: """ - @param environment_name: - @type environment_name: - @param observables: - @type observables: - @param signal: - @type signal: - @param terminated: - @type terminated: - @param info: - @type info: - @return: - @rtype: - """ + @param environment_name: + @type environment_name: + @param observables: + @type observables: + @param signal: + @type signal: + @param terminated: + @type terminated: + @param info: + @type info: + @return: + @rtype: + """ snapshot = EnvironmentSnapshot(None) snapshot._environment_name = environment_name snapshot._environment_name = "" @@ -246,18 +244,18 @@ def from_gym( def to_dict(self) -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ # inspect.getmembers(a) return dict(vars(self)) def to_json(self) -> object: """ - @return: - @rtype: - """ + @return: + @rtype: + """ import json encoder = json.JSONEncoder() diff --git a/neodroid/utilities/unity_specifications/motion.py b/neodroid/utilities/unity_specifications/motion.py index e5f139d0..568d2860 100644 --- a/neodroid/utilities/unity_specifications/motion.py +++ b/neodroid/utilities/unity_specifications/motion.py @@ -6,17 +6,14 @@ class Motion(object): - """ - - """ + """""" def __init__(self, actor_name: str, actuator_name: str, strength: float): """ -:param actor_name: -:param actuator_name: -:param strength: Strength has a possible direction given by the sign of the float -""" + :param actor_name: + :param actuator_name: + :param strength: Strength has a possible direction given by the sign of the float""" self._actor_name = actor_name self._actuator_name = actuator_name self._strength = strength @@ -25,35 +22,35 @@ def __init__(self, actor_name: str, actuator_name: str, strength: float): def actor_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._actor_name @property def actuator_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._actuator_name @property def strength(self) -> float: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._strength def to_dict(self) -> Dict[str, Any]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return { "_actor_name": self._actor_name, "_motor_name": self._actuator_name, diff --git a/neodroid/utilities/unity_specifications/reaction.py b/neodroid/utilities/unity_specifications/reaction.py index 83ea5a9a..d274b1cb 100644 --- a/neodroid/utilities/unity_specifications/reaction.py +++ b/neodroid/utilities/unity_specifications/reaction.py @@ -12,9 +12,7 @@ class Reaction(object): - """ - - """ + """""" def __init__( self, @@ -29,10 +27,9 @@ def __init__( ): """ -The environment_name argument lets you specify which environments to react in, 'all' means all environment -receives the same reaction. - -""" + The environment_name argument lets you specify which environments to react in, 'all' means all environment + receives the same reaction. + """ self._serialised_message = serialised_message self._environment_name = environment_name @@ -48,18 +45,18 @@ def __init__( def environment_name(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._environment_name @property def parameters(self) -> ReactionParameters: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._parameters @parameters.setter @@ -70,9 +67,9 @@ def parameters(self, parameters: ReactionParameters) -> None: def motions(self) -> Sequence: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._motions @motions.setter @@ -83,9 +80,9 @@ def motions(self, motions: Sequence) -> None: def configurations(self) -> Sequence: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._configurations @configurations.setter @@ -96,9 +93,9 @@ def configurations(self, configurations: Sequence) -> None: def displayables(self) -> Sequence: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._displayables @displayables.setter @@ -109,9 +106,9 @@ def displayables(self, displayables: Sequence) -> None: def unobservables(self) -> Optional[Unobservables]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._unobservables @unobservables.setter @@ -122,9 +119,9 @@ def unobservables(self, unobservables: Optional[Unobservables]): def string_serialised_message(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._serialised_message @string_serialised_message.setter @@ -134,9 +131,9 @@ def string_serialised_message(self, message: str) -> None: def to_dict(self) -> Dict[str, List]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return { "_configurations": [ configuration.to_dict() for configuration in self._configurations @@ -147,9 +144,9 @@ def to_dict(self) -> Dict[str, List]: def to_json(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return json.dumps(self.to_dict()) def __repr__(self) -> str: diff --git a/neodroid/utilities/unity_specifications/reaction_parameters.py b/neodroid/utilities/unity_specifications/reaction_parameters.py index 7da1c06f..6784382f 100644 --- a/neodroid/utilities/unity_specifications/reaction_parameters.py +++ b/neodroid/utilities/unity_specifications/reaction_parameters.py @@ -8,9 +8,7 @@ class ReactionParameters(object): - """ - - """ + """""" def __init__( self, @@ -35,54 +33,54 @@ def __init__( def reset(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._reset @property def configure(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._configure @property def describe(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._describe @property def step(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._step @property def episode_count(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._episode_count @property def terminable(self) -> bool: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._terminable @reset.setter @@ -92,17 +90,17 @@ def reset(self, value: bool) -> None: def to_dict(self) -> dict: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return {"_reset": self._reset} def to_json(self) -> str: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return json.dumps(self.to_dict()) def __repr__(self): diff --git a/neodroid/utilities/unity_specifications/sensor.py b/neodroid/utilities/unity_specifications/sensor.py index 84f3655d..bb590908 100644 --- a/neodroid/utilities/unity_specifications/sensor.py +++ b/neodroid/utilities/unity_specifications/sensor.py @@ -8,9 +8,7 @@ class Sensor(object): - r""" - -""" + r"""""" def __init__(self, sensor_name, sensor_range, sensor_value, is_image): self._range = sensor_range @@ -22,36 +20,36 @@ def __init__(self, sensor_name, sensor_range, sensor_value, is_image): def name(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._sensor_name @property def is_image(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._is_image @property def space(self) -> List[Range]: """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._range @property def value(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._value def __repr__(self): diff --git a/neodroid/utilities/unity_specifications/simulator_configuration.py b/neodroid/utilities/unity_specifications/simulator_configuration.py index 7b2095ce..8f065358 100644 --- a/neodroid/utilities/unity_specifications/simulator_configuration.py +++ b/neodroid/utilities/unity_specifications/simulator_configuration.py @@ -6,9 +6,7 @@ class SimulatorConfiguration(object): - """ - - """ + """""" def __init__( self, @@ -18,10 +16,9 @@ def __init__( ): """ -:param fbs_configuration: -:param api_version: -:param simulator_info: -""" + :param fbs_configuration: + :param api_version: + :param simulator_info:""" self._fbs_configuration = fbs_configuration self._api_version = api_version self._simulator_info = simulator_info @@ -30,27 +27,27 @@ def __init__( def simulator_configuration(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._fbs_configuration @cached_property def api_version(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._api_version.decode() @property def simulator_info(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ # if not isinstance(self._simulator_info, str): # return self._simulator_info.decode() return self._simulator_info diff --git a/neodroid/utilities/unity_specifications/unobservables.py b/neodroid/utilities/unity_specifications/unobservables.py index 8a49325d..7e16e96b 100644 --- a/neodroid/utilities/unity_specifications/unobservables.py +++ b/neodroid/utilities/unity_specifications/unobservables.py @@ -15,9 +15,7 @@ class Unobservables(object): - """ - - """ + """""" def __init__(self, unobservables): self._unobservables = unobservables @@ -26,18 +24,18 @@ def __init__(self, unobservables): def unobservables(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return self._unobservables @cached_property def poses_numpy(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self._unobservables: return deserialise_poses(self._unobservables) @@ -45,9 +43,9 @@ def poses_numpy(self): def bodies_numpy(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ if self._unobservables: return deserialise_bodies(self._unobservables) @@ -55,9 +53,9 @@ def bodies_numpy(self): def state_configuration(self): """ - @return: - @rtype: - """ + @return: + @rtype: + """ return numpy.array( [self.poses_numpy.flatten(), self.bodies_numpy.flatten()] ).flatten() diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..77718237 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +addopts = --ignore=exclude --ignore-glob=*exclude* + +#[pycodestyle] +#ignore = not_me_* ALL \ No newline at end of file diff --git a/requirements_dev.txt b/requirements/requirements_dev.txt similarity index 100% rename from requirements_dev.txt rename to requirements/requirements_dev.txt diff --git a/requirements_docs.txt b/requirements/requirements_docs.txt similarity index 87% rename from requirements_docs.txt rename to requirements/requirements_docs.txt index 0cdff193..9feba0bc 100644 --- a/requirements_docs.txt +++ b/requirements/requirements_docs.txt @@ -1,3 +1,3 @@ sphinx -m2r +m2r2 sphinxcontrib-programoutput diff --git a/requirements_gui.txt b/requirements/requirements_gui.txt similarity index 100% rename from requirements_gui.txt rename to requirements/requirements_gui.txt diff --git a/requirements/requirements_setup.txt b/requirements/requirements_setup.txt new file mode 100644 index 00000000..e69de29b diff --git a/requirements_tests.txt b/requirements/requirements_tests.txt similarity index 100% rename from requirements_tests.txt rename to requirements/requirements_tests.txt diff --git a/requirements_webapp.txt b/requirements/requirements_webapp.txt similarity index 100% rename from requirements_webapp.txt rename to requirements/requirements_webapp.txt diff --git a/requirements_wrappers.txt b/requirements/requirements_wrappers.txt similarity index 100% rename from requirements_wrappers.txt rename to requirements/requirements_wrappers.txt diff --git a/samples/experimental/deprecated/__init__.py b/samples/experimental/deprecated/__init__.py index 691f402c..96434968 100644 --- a/samples/experimental/deprecated/__init__.py +++ b/samples/experimental/deprecated/__init__.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -__author__ = 'Christian Heider Nielsen' -__doc__ = r''' +__author__ = "Christian Heider Nielsen" +__doc__ = r""" Created on 01-10-2020 - ''' + """ diff --git a/samples/experimental/deprecated/multienv_action_space_sampling.py b/samples/experimental/deprecated/multienv_action_space_sampling.py index 1a48935e..77cd2348 100644 --- a/samples/experimental/deprecated/multienv_action_space_sampling.py +++ b/samples/experimental/deprecated/multienv_action_space_sampling.py @@ -6,6 +6,7 @@ import neodroid.wrappers.formal_wrapper as neo + def construct_reactions(env): parameters = ReactionParameters( terminable=True, diff --git a/samples/external_agents/berkley_agent.py b/samples/external_agents/berkley_agent.py index e9e57093..12b4aa35 100644 --- a/samples/external_agents/berkley_agent.py +++ b/samples/external_agents/berkley_agent.py @@ -30,12 +30,11 @@ def run_ddpg(snapshot_config, *_): """Set up environment and algorithm and run the task. -Args: - snapshot_config (garage.experiment.SnapshotConfig): The snapshot - configuration used by LocalRunner to create the snapshotter. - If None, it will create one with default settings. - _ : Unused parameters -""" + Args: + snapshot_config (garage.experiment.SnapshotConfig): The snapshot + configuration used by LocalRunner to create the snapshotter. + If None, it will create one with default settings. + _ : Unused parameters""" runner = LocalRunner(snapshot_config) env = GarageEnv(normalize(gym.make(ENV))) @@ -79,12 +78,11 @@ def run_ddpg(snapshot_config, *_): def run_ppo(snapshot_config, *_): """Set up environment and algorithm and run the task. -Args: - snapshot_config (garage.experiment.SnapshotConfig): The snapshot - configuration used by LocalRunner to create the snapshotter. - If None, it will create one with default settings. - _ : Unused parameters -""" + Args: + snapshot_config (garage.experiment.SnapshotConfig): The snapshot + configuration used by LocalRunner to create the snapshotter. + If None, it will create one with default settings. + _ : Unused parameters""" env = TfEnv(env_name=ENV) runner = LocalRunner(snapshot_config) diff --git a/samples/generation/dataset/tf_record_generator.py b/samples/generation/dataset/tf_record_generator.py index 1b181643..3c8b1469 100644 --- a/samples/generation/dataset/tf_record_generator.py +++ b/samples/generation/dataset/tf_record_generator.py @@ -48,12 +48,11 @@ def int64(value): def neodroid_tf_example(image_string, label, image_shape, bounding_box): """ -:param bounding_box: -:param image_shape: -:param image_string: -:param label: -:return: -""" + :param bounding_box: + :param image_shape: + :param image_string: + :param label: + :return:""" feature = { "height": TFF.int64([image_shape[0]]), @@ -71,9 +70,7 @@ def neodroid_tf_example(image_string, label, image_shape, bounding_box): def write_tf_record_file(data_tuples, file_name="neodroid_bb_images.tfr"): - """ - -""" + """""" with tf.python_io.TFRecordWriter(file_name) as writer: for data_tuple in data_tuples: diff --git a/samples/generation/web_app/app.py b/samples/generation/web_app/app.py index 093a75a4..31ed0354 100644 --- a/samples/generation/web_app/app.py +++ b/samples/generation/web_app/app.py @@ -54,12 +54,11 @@ def server_error(e): def allowed_file(filename): """ -check if an extension is valid and that uploads the file and redirects the user to the URL for the -uploaded file + check if an extension is valid and that uploads the file and redirects the user to the URL for the + uploaded file -:param filename: -:return: -""" + :param filename: + :return:""" return "." in filename and filename.rsplit(".", 1)[1] in ALLOWED_EXTENSIONS @app.route("/assessment") diff --git a/samples/generation/web_app/config.py b/samples/generation/web_app/config.py index 72da4044..82bf2e53 100644 --- a/samples/generation/web_app/config.py +++ b/samples/generation/web_app/config.py @@ -2,9 +2,9 @@ PROJECT = "DemoWebApp" CONFIG_NAME = __name__ -import pathlib +from pathlib import Path -CONFIG_FILE_PATH = pathlib.Path(__file__) +CONFIG_FILE_PATH = Path(__file__) VERBOSE = False USE_LOGGING = True diff --git a/samples/gui_client/gui.py b/samples/gui_client/gui.py index fead8967..faf3c3ce 100644 --- a/samples/gui_client/gui.py +++ b/samples/gui_client/gui.py @@ -3,15 +3,16 @@ from gui_components import EnvironmentStateBox, ReactionBox, StatusBar, XMLBox __author__ = "Christian Heider Nielsen" -__doc__ = r''' -''' +__doc__ = r""" +""" from kivy.app import App from kivy.core.window import Window from kivy.uix.boxlayout import BoxLayout -__all__ = ['NeoGUI'] +__all__ = ["NeoGUI"] + class NeoGUI(App): def __init__( @@ -21,7 +22,7 @@ def __init__( self._on_step_callback = on_step_callback self._on_reset_callback = on_reset_callback self._on_connect_callback = on_connect_callback - #Window.clearcolor = (1, 1, 1, 1) + # Window.clearcolor = (1, 1, 1, 1) self.parent_rows = BoxLayout(orientation="vertical") self.columns = BoxLayout(orientation="horizontal") diff --git a/samples/gui_client/main.py b/samples/gui_client/main.py index f2945e44..219cb1e2 100644 --- a/samples/gui_client/main.py +++ b/samples/gui_client/main.py @@ -10,8 +10,8 @@ __author__ = "Christian Heider Nielsen" -__doc__ = r''' -''' +__doc__ = r""" +""" from gui import NeoGUI @@ -60,7 +60,9 @@ def on_step_callback(actor_name, slider_values): describe=False, episode_count=True, ) - new_state = NEODROID_ENVIRONMENT.react(Reaction(motions=motions, parameters=parameters)) + new_state = NEODROID_ENVIRONMENT.react( + Reaction(motions=motions, parameters=parameters) + ) update_callback(new_state) diff --git a/scripts/deprecated/clean_generated_files.bat b/scripts/deprecated/clean_generated_files.bat new file mode 100644 index 00000000..23ccf1f4 --- /dev/null +++ b/scripts/deprecated/clean_generated_files.bat @@ -0,0 +1,9 @@ +@echo off +cls +del /q "logs\*" +del /q "models\*" +mkdir models +mkdir logs +type nul >> models/.trackfolder +type nul >> logs/.trackfolder +pause \ No newline at end of file diff --git a/scripts/deprecated/clean_generated_files.sh b/scripts/deprecated/clean_generated_files.sh new file mode 100644 index 00000000..22ff602d --- /dev/null +++ b/scripts/deprecated/clean_generated_files.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +rm logs/ -r +rm models/ -r +mkdir logs +mkdir models +touch models/.trackfolder +touch logs/.trackfolder diff --git a/scripts/dev_install.sh b/scripts/dev_install.sh new file mode 100644 index 00000000..02ad15b6 --- /dev/null +++ b/scripts/dev_install.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +#conda activate Development +python3 setup.py develop diff --git a/scripts/upload.bat b/scripts/upload.bat new file mode 100644 index 00000000..9902f78e --- /dev/null +++ b/scripts/upload.bat @@ -0,0 +1,9 @@ +@ECHO OFF + +pushd %~dp0 + +git push --all +git push --all pything +git push --tags pything + +popd diff --git a/scripts/upload.sh b/scripts/upload.sh new file mode 100644 index 00000000..bd15fd5d --- /dev/null +++ b/scripts/upload.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +git push --all +git push --all pything +git push --tags pything diff --git a/setup.py b/setup.py index 8af69af9..ace87368 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from typing import List, Union +from pathlib import Path +from typing import List, Sequence, Union -def python_version_check(major=3, minor=6): +def python_version_check(major: int = 3, minor: int = 7): import sys assert sys.version_info.major == major and sys.version_info.minor >= minor, ( @@ -15,13 +16,60 @@ def python_version_check(major=3, minor=6): python_version_check() import os -import pathlib + + +def read_reqs(file: str, path: Path) -> List[str]: + """""" + + def readlines_ignore_comments(f): + """""" + return [a_ for a_ in f.readlines() if "#" not in a_ and a_] + + def recursive_flatten_ignore_str(seq: Sequence) -> Sequence: + """""" + if not seq: # is empty Sequence + return seq + if isinstance(seq[0], str): + return seq + if isinstance(seq[0], Sequence): + return ( + *recursive_flatten_ignore_str(seq[0]), + *recursive_flatten_ignore_str(seq[1:]), + ) + return (*seq[:1], *recursive_flatten_ignore_str(seq[1:])) + + def unroll_nested_reqs(req_str: str, base_path: Path): + """""" + if req_str.startswith("-r"): + with open(base_path / req_str.strip("-r").strip()) as f: + return [ + unroll_nested_reqs(req.strip(), base_path) + for req in readlines_ignore_comments(f) + ] + else: + return (req_str,) + + requirements_group = [] + with open(str(path / file)) as f: + requirements = readlines_ignore_comments(f) + for requirement in requirements: + requirements_group.extend( + recursive_flatten_ignore_str( + unroll_nested_reqs(requirement.strip(), path) + ) + ) + + req_set = set(requirements_group) + req_set.discard("") + return list(req_set) + + import re from setuptools import find_packages with open( - pathlib.Path(os.path.dirname(__file__)) / "neodroid" / "__init__.py", "r" + Path(os.path.dirname(__file__)) / "neodroid" / "__init__.py", "r" ) as project_init_file: str_reg_exp = "['\"]([^'\"]*)['\"]" content = project_init_file.read() # get strings from module @@ -30,16 +78,21 @@ def python_version_check(major=3, minor=6): author = re.search(rf"__author__ = {str_reg_exp}", content, re.M).group(1) __author__ = author -__all__ = ['NeodroidPackage'] +__all__ = ["NeodroidPackage"] + class NeodroidPackageMeta(type): @property def test_dependencies(self) -> list: - return ["pytest", "mock"] + return read_reqs( + "requirements_tests.txt", Path(__file__).parent / "requirements" + ) @property def setup_dependencies(self) -> list: - return ["pytest-runner"] + return read_reqs( + "requirements_setup.txt", Path(__file__).parent / "requirements" + ) @property def package_name(self) -> str: @@ -84,7 +137,7 @@ def maintainer_email(self) -> str: @property def package_data(self) -> dict: # data = glob.glob('environments/mab/**', recursive=True) - emds = [str(p) for p in pathlib.Path(__file__).parent.rglob('.md')] + emds = [str(p) for p in Path(__file__).parent.rglob(".md")] return { "neodroid": [ @@ -121,33 +174,24 @@ def extras(self) -> dict: # 'neodroid-win-mab platform_system == "Windows"'] } - path: pathlib.Path = pathlib.Path(__file__).parent + path: Path = Path(__file__).parent / "requirements" for file in path.iterdir(): if file.name.startswith("requirements_"): - - requirements_group = [] - with open(str(file.absolute())) as f: - requirements = f.readlines() - - for requirement in requirements: - requirements_group.append(requirement.strip()) - group_name_ = "_".join(file.name.strip(".txt").split("_")[1:]) - - these_extras[group_name_] = requirements_group + these_extras[group_name_] = read_reqs(file.name, path) all_dependencies = [] for group_name in these_extras: all_dependencies += these_extras[group_name] - these_extras["all"] = all_dependencies + these_extras["all"] = list(set(all_dependencies)) return these_extras @property def requirements(self) -> list: - path = pathlib.Path(__file__).parent + path = Path(__file__).parent requirements_out = [] with open(path / "requirements.txt") as f: requirements = f.readlines() diff --git a/tests/test_sanity.py b/tests/test_sanity.py index 2a50f572..2813bb32 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -9,30 +9,31 @@ Created on 01/08/2020 """ + def test_answer(): - def inc(x): - return x + 1 + def inc(x): + return x + 1 - assert inc(4) == 5 + assert inc(4) == 5 def test_sanity(): - assert True - assert False is not True - answer_to_everything = str(42) - assert str(42) == answer_to_everything + assert True + assert False is not True + answer_to_everything = str(42) + assert str(42) == answer_to_everything def test_print(capsys): - """Correct my_name argument prints""" - text = "hello" - err = "world" - print(text) - sys.stderr.write("world") - captured = capsys.readouterr() - assert text in captured.out - assert err in captured.err + """Correct my_name argument prints""" + text = "hello" + err = "world" + print(text) + sys.stderr.write("world") + captured = capsys.readouterr() + assert text in captured.out + assert err in captured.err if __name__ == "__main__": - test_sanity() + test_sanity()