Skip to content

Commit

Permalink
refactor: auto format comments (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickstaa authored Jun 23, 2023
1 parent f0dfdbe commit b5d43dc
Show file tree
Hide file tree
Showing 52 changed files with 567 additions and 524 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
# Maintain dependencies for GitHub Actions
# Maintain dependencies for GitHub Actions.
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand All @@ -14,15 +14,15 @@ updates:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]

# Maintain dependencies for npm
# Maintain dependencies for npm.
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
# Maintain dependencies for npm
# Maintain dependencies for npm.
- package-ecosystem: "pip"
directory: "/"
schedule:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/stable_learning_control.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
tags-ignore:
- v*.*.*
jobs:
markdown-lint: # Lints the markdown code
markdown-lint: # Lints the markdown code.
name: runner / remark-lint
runs-on: ubuntu-latest
steps:
Expand All @@ -18,7 +18,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: warning
black: # Check python code format
black: # Check python code format.
name: runner / black
runs-on: ubuntu-latest
steps:
Expand All @@ -28,7 +28,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: warning
flake8: # Lints python code
flake8: # Lints python code.
name: runner / flake8
runs-on: ubuntu-latest
steps:
Expand All @@ -54,9 +54,9 @@ jobs:
name: python-tests (Testing)
runs-on: ubuntu-latest
strategy:
fail-fast: false # Run all matrix jobs
fail-fast: false # Run all matrix jobs.
matrix:
python-version: [3.8, 3.9, "3.10"] # Supported python versions
python-version: [3.8, 3.9, "3.10"] # Supported python versions.
steps:
- name: Checkout stable-learning-control repository
uses: actions/checkout@v3
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
level: warning
exclude: |
./CHANGELOG.md
alex: # Checks docs for inconsiderate writing
alex: # Checks docs for inconsiderate writing.
name: runner / alex
runs-on: ubuntu-latest
steps:
Expand All @@ -25,7 +25,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: warning
markdown-lint: # Lints the markdown code
markdown-lint: # Lints the markdown code.
name: runner / remark-lint
runs-on: ubuntu-latest
steps:
Expand All @@ -36,7 +36,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: warning
black: # Check python code format
black: # Check python code format.
name: runner / black
runs-on: ubuntu-latest
steps:
Expand All @@ -46,7 +46,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: warning
flake8: # Lints python code
flake8: # Lints python code.
name: runner / flake8
runs-on: ubuntu-latest
steps:
Expand All @@ -72,9 +72,9 @@ jobs:
name: python-tests (Testing)
runs-on: ubuntu-latest
strategy:
fail-fast: false # Run all matrix jobs
fail-fast: false # Run all matrix jobs.
matrix:
python-version: [3.8, 3.9, "3.10"] # Supported python versions
python-version: [3.8, 3.9, "3.10"] # Supported python versions.
steps:
- name: Checkout stable-learning-control repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for Stable Learning Control Sphinx documentation

# You can set these variables from the command line.
# You can set these variables from the command line
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = Stable Learning Control
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def __getattr__(cls, name):
"myst_parser",
]

# Extension settings
# Extension settings.
autosummary_generate = True
autosummary_generate_overwrite = True
autodoc_member_order = "bysource"

# imgmath settings
# imgmath settings.
imgmath_image_format = "svg"
imgmath_font_size = 14

Expand Down Expand Up @@ -110,7 +110,7 @@ def __getattr__(cls, name):

# 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
# This patterns also effect to html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "TODO.*", "README.*"]

# The name of the Pygments (syntax highlighting) style to use.
Expand Down
36 changes: 18 additions & 18 deletions docs/source/control/eval_robustness.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ under several Impulse disturbances.
if __name__ == "__main__":
# Parse input arguments
# Parse input arguments.
parser = argparse.ArgumentParser()
parser.add_argument("fpath", type=str, help="The path where the policy is stored")
args = parser.parse_args()
# Retrieve dataframe
# Retrieve dataframe.
robustness_eval_df = pd.read_csv(Path(args.fpath).absolute())
# Retrieve observation and reference data from the dataframe
# Retrieve observation and reference data from the dataframe.
o_disturbances_df = robustness_eval_df.query("variable == 'observation'").dropna(
axis=1, how="all"
)
ref_disturbance_df = robustness_eval_df.query("variable == 'reference'").dropna(
axis=1, how="all"
)
# Merge observations and references into one dataframe
# Merge observations and references into one dataframe.
obs_df_tmp = o_disturbances_df.query("observation == 3")
obs_df_tmp["signal"] = "obs_" + (obs_df_tmp["observation"] + 1).astype(str)
obs_df_tmp.insert(len(obs_df_tmp.columns), "type", "observation")
Expand Down Expand Up @@ -190,14 +190,14 @@ class to add all the required methods and attributes to make it compatible with
import numpy as np
from stable_learning_control.simzoo.simzoo.common.disturber import Disturber
# Disturber config used to overwrite the default config
# Disturber config used to overwrite the default config.
DISTURBER_CFG = {
# Disturbance applied to environment variables
# Disturbance applied to environment variables.
"env": {
"description": "Pole length disturbance",
# The env variable which you want to disturb
# The env variable which you want to disturb.
"variable": "length",
# The range of values you want to use for each disturbance iteration
# The range of values you want to use for each disturbance iteration.
"variable_range": np.linspace(0.5, 2.0, num=5, dtype=np.float32),
# Label used in robustness plots.
"label": "r: %s",
Expand Down Expand Up @@ -271,10 +271,10 @@ When editing the ``DISTURBANCE_CFG`` config in the :class:`~stable_learning_cont
:linenos:
:emphasize-lines: 5
# A random noise that is applied at every timestep
# A random noise that is applied at every timestep.
"noise": {
"description": "Random noise disturbance",
# The means and standards deviations of the random noise disturbance
# The means and standards deviations of the random noise disturbance.
"noise_range": {
"mean": np.linspace(80, 155, num=3, dtype=np.int16),
"std": np.linspace(1.0, 5.0, num=3, dtype=np.int16),
Expand All @@ -292,14 +292,14 @@ When editing the ``DISTURBANCE_CFG`` config in the :class:`~stable_learning_cont
# Disturbance applied to the *OUTPUT* of the environment step function
"output": {
# The disturbance variant used when no variant is given
# The disturbance variant used when no variant is given.
"default_variant": "impulse",
# A random noise that is applied at every timestep
# A random noise that is applied at every timestep.
"noise": {
"description": "Random noise disturbance",
# The means and standards deviations of the random noise disturbance
# The means and standards deviations of the random noise disturbance.
"noise_range": {
# "mean": np.linspace(80, 155, num=3, dtype=np.int16), # All obs
# "mean": np.linspace(80, 155, num=3, dtype=np.int16), # All obs.
"mean": np.vstack(
(
np.linspace(80, 155, num=3, dtype=np.int16), # Obs 1
Expand All @@ -308,7 +308,7 @@ When editing the ``DISTURBANCE_CFG`` config in the :class:`~stable_learning_cont
np.linspace(80, 155, num=3, dtype=np.int16), # Obs 4
)
).T,
# "std": np.linspace(1.0, 5.0, num=3, dtype=np.int16), # All Obs
# "std": np.linspace(1.0, 5.0, num=3, dtype=np.int16), # All Obs.
"std": np.vstack(
(
np.linspace(1.0, 5.0, num=3, dtype=np.int16), # Obs 1
Expand All @@ -332,20 +332,20 @@ When editing the ``DISTURBANCE_CFG`` config in the :class:`~stable_learning_cont
:linenos:
:emphasize-lines: 4, 12
# Input and output noise disturbance
# Input and output noise disturbance.
"noise": {
"description": "Random input and output noise disturbance",
"input_noise": {
# The means and standards deviations of the random input noise
# disturbance
# disturbance.
"noise_range": {
"mean": np.linspace(80, 155, num=3, dtype=np.int16),
"std": np.linspace(1.0, 5.0, num=3, dtype=np.int16),
},
},
"output_noise": {
# The means and standards deviations of the random output noise
# disturbance
# disturbance.
"noise_range": {
"mean": np.linspace(80, 155, num=3, dtype=np.int16),
"std": np.linspace(1.0, 5.0, num=3, dtype=np.int16),
Expand Down
16 changes: 8 additions & 8 deletions docs/source/control/saving_and_loading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,23 @@ the :torch:`PyTorch documentation <tutorials/beginner/saving_loading_models.html
MODEL_LOAD_FOLDER = "./data/lac/oscillator-v1/runs/run_1614680001"
MODEL_PATH = osp.join(MODEL_LOAD_FOLDER, "torch_save/model_state.pt")
# Restore the model
# Restore the model.
config = EpochLogger.load_config(
MODEL_LOAD_FOLDER
) # Retrieve the experiment configuration
) # Retrieve the experiment configuration.
env = EpochLogger.load_env(MODEL_LOAD_FOLDER)
model = LAC(env=env, ac_kwargs=config["ac_kwargs"])
restored_model_state_dict = torch.load(MODEL_PATH, map_location="cpu")
model.load_state_dict(
restored_model_state_dict,
)
# Create dummy observations and retrieve the best action
# Create dummy observations and retrieve the best action.
obs = torch.rand(env.observation_space.shape)
a = model.get_action(obs)
L_value = model.ac.L(obs, torch.from_numpy(a))
# Print results
# Print results.
print(f"The LAC agent thinks it is a good idea to take action {a}.")
print(f"It assigns a Lyapunov Value of {L_value} to this action.")
Expand Down Expand Up @@ -237,23 +237,23 @@ Load Tensorflow Policy
MODEL_LOAD_FOLDER = "./data/lac/oscillator-v1/runs/run_1614673367"
MODEL_PATH = osp.join(MODEL_LOAD_FOLDER, "tf2_save")
# Restore the model
# Restore the model.
config = EpochLogger.load_config(
MODEL_LOAD_FOLDER
) # Retrieve the experiment configuration
) # Retrieve the experiment configuration.
env = EpochLogger.load_env(MODEL_LOAD_FOLDER)
model = LAC(env=env, ac_kwargs=config["ac_kwargs"])
weights_checkpoint = tf.train.latest_checkpoint(MODEL_PATH)
model.load_weights(
weights_checkpoint,
)
# Create dummy observations and retrieve the best action
# Create dummy observations and retrieve the best action.
obs = tf.random.uniform((1, env.observation_space.shape[0]))
a = model.get_action(obs)
L_value = model.ac.L([obs, tf.expand_dims(a, axis=0)])
# Print results
# Print results.
print(f"The LAC agent thinks it is a good idea to take action {a}.")
print(f"It assigns a Lyapunov Value of {L_value} to this action.")
Expand Down
4 changes: 2 additions & 2 deletions docs/source/hardware/hardware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ then be loaded onto the hardware using the :obj:`tf.saved_model.load` method.
model_path = "./data/lac/oscillator-v1/runs/run_1614673367/tf2_save"
# Load model and environment
# Load model and environment.
loaded_model = tf.saved_model.load(model_path)
loaded_env = EpochLogger.load_env(os.path.dirname(model_path))
# Get action for dummy observation
# Get action for dummy observation.
obs = tf.random.uniform((1, loaded_env.observation_space.shape[0]))
a = loaded_model.get_action(obs)
print(f"\nThe model thinks it is a good idea to take action: {a.numpy()}")
Expand Down
2 changes: 1 addition & 1 deletion docs/source/simzoo/simzoo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ being printed to the console.
print("Taking 1000 steps in the Oscillator-v1 environment...")
for ii in range(1000):
env.render() # Does not work with the Oscillator-v1 environment.
obs, cost, done, info_doc = env.step(env.action_space.sample()) # take a random action
obs, cost, done, info_doc = env.step(env.action_space.sample()) # take a random action.
if ii % 100 == 0:
print(f"Randoms step {ii}: {obs}")
env.close()
Expand Down
Loading

0 comments on commit b5d43dc

Please sign in to comment.