diff --git a/.gitignore b/.gitignore index e56f28cbf..523bce730 100644 --- a/.gitignore +++ b/.gitignore @@ -21,9 +21,8 @@ dist/ # node related node_modules/ -# Files to ignore -.coverage -*.pyc +# IDE files to ignore +.vscode *.code-workspace # Other diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 1e064a3c3..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - }, - { - "name": "Python: Current File (mlc)", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "python": "/home/ricks/miniconda3/envs/mlc/bin/python" - }, - { - "name": "Python: Current File (lac_translate)", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "python": "/home/ricks/miniconda3/envs/lac_translate/bin/python" - }, - { - "name": "Python: Module run (mlc)", - "type": "python", - "python": "/home/ricks/miniconda3/envs/mlc/bin/python", - "request": "launch", - "module": "machine_learning_control.run", - "args": [ - "lac_tf", - "--exp_name", - "Oscillator-v1_test", - "--env", - "Oscillator-v1", - "--seed", - "0", - "23", - "455", - "--epochs", - "3", - ] - }, - { - "name": "Python: Module plot (mlc)", - "type": "python", - "python": "/home/ricks/miniconda3/envs/mlc/bin/python", - "request": "launch", - "module": "machine_learning_control.run", - "args": [ - "plot", - "data/", - ] - }, - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index a0fcec04d..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "workbench.colorCustomizations": { - "activityBar.activeBackground": "#8ee1fe", - "activityBar.activeBorder": "#fd41cd", - "activityBar.background": "#8ee1fe", - "activityBar.foreground": "#15202b", - "activityBar.inactiveForeground": "#15202b99", - "activityBarBadge.background": "#fd41cd", - "activityBarBadge.foreground": "#15202b", - "tab.activeBorder": "#8ee1fe", - "titleBar.activeBackground": "#5cd3fd", - "titleBar.activeForeground": "#15202b", - "titleBar.inactiveBackground": "#5cd3fd99", - "titleBar.inactiveForeground": "#15202b99" - }, - "peacock.color": "#5cd3fd", - "python.pythonPath": "/home/ricks/miniconda3/envs/mlc/bin/python", - "todo-tree.tree.scanMode": "workspace only", - "editor.formatOnSave": true, - "cSpell.words": [ - "serializable" - ] -} \ No newline at end of file diff --git a/machine_learning_control/control/algos/pytorch/lac/lac.py b/machine_learning_control/control/algos/pytorch/lac/lac.py index 69db6ce14..62b3a4415 100644 --- a/machine_learning_control/control/algos/pytorch/lac/lac.py +++ b/machine_learning_control/control/algos/pytorch/lac/lac.py @@ -411,8 +411,7 @@ def update(self, data): q2_pi_targ = self.ac_targ.Q2(o_, a2) if self._opt_type.lower() == "minimize": q_pi_targ = torch.max( - q1_pi_targ, - q2_pi_targ, + q1_pi_targ, q2_pi_targ, ) # Use max clipping to prevent overestimation bias. else: q_pi_targ = torch.min( @@ -656,9 +655,7 @@ def load_state_dict(self, state_dict, restore_lagrance_multipliers=True): try: super().load_state_dict(state_dict) except AttributeError as e: - raise type(e)( - "The 'state_dict' could not be loaded successfully.", - ) from e + raise type(e)("The 'state_dict' could not be loaded successfully.",) from e def _update_targets(self): """Updates the target networks based on a Exponential moving average @@ -721,7 +718,7 @@ def bound_lr( if lr_alpha_final is not None: if self._log_alpha_optimizer.param_groups[0]["lr"] < lr_a_final: self._log_alpha_optimizer.param_groups[0]["lr"] = lr_a_final - if lr_labda_final is not None: + if lr_labda_final is not None and self._use_lyapunov: if self._log_labda_optimizer.param_groups[0]["lr"] < lr_labda_final: self._log_labda_optimizer.param_groups[0]["lr"] = lr_labda_final @@ -736,8 +733,7 @@ def alpha(self): def alpha(self, set_val): """Property used to make sure alpha and log_alpha are related.""" self.log_alpha.data = torch.as_tensor( - np.log(1e-37 if set_val < 1e-37 else set_val), - dtype=self.log_alpha.dtype, + np.log(1e-37 if set_val < 1e-37 else set_val), dtype=self.log_alpha.dtype, ) @property @@ -753,8 +749,7 @@ def labda(self): def labda(self, set_val): """Property used to make sure labda and log_labda are related.""" self.log_labda.data = torch.as_tensor( - np.log(1e-37 if set_val < 1e-37 else set_val), - dtype=self.log_labda.dtype, + np.log(1e-37 if set_val < 1e-37 else set_val), dtype=self.log_labda.dtype, ) @property @@ -1179,9 +1174,7 @@ def lac( policy, test_env, num_test_episodes, max_ep_len=max_ep_len ) logger.store( - TestEpRet=eps_ret, - TestEpLen=eps_len, - extend=True, + TestEpRet=eps_ret, TestEpLen=eps_len, extend=True, ) # Epoch based learning rate decay @@ -1218,13 +1211,11 @@ def lac( logger.log_tabular("LossQ", average_only=True) if adaptive_temperature: logger.log_tabular( - "LossAlpha", - average_only=True, + "LossAlpha", average_only=True, ) if use_lyapunov: logger.log_tabular( - "LossLambda", - average_only=True, + "LossLambda", average_only=True, ) if use_lyapunov: logger.log_tabular("LVals", with_min_and_max=True) diff --git a/machine_learning_control/control/utils/plot.py b/machine_learning_control/control/utils/plot.py index 1f5e6fdb0..3d3e20e57 100644 --- a/machine_learning_control/control/utils/plot.py +++ b/machine_learning_control/control/utils/plot.py @@ -94,7 +94,7 @@ def plot_data( Changes the colorscheme and the default legend style, though. """ plt.legend(loc="best").set_draggable(True) - # plt.legend(loc='upper center', ncol=3, handlelength=1, + # plt.legend(loc='upper center', ncol=6, handlelength=1, mode="expand" # borderaxespad=0., prop={'size': 13}) """ diff --git a/setup.py b/setup.py index a655487f8..9b32ee2f1 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,32 @@ """Setup file for the 'machine_learning_control' python package. """ +import os.path as osp import re +import sys from setuptools import find_namespace_packages, setup +# Script settings stand_alone_ns_pkgs = ["simzoo"] + +def submodules_available(submodules): + """Throws warning and stops the script if any of the submodules is not present.""" + for submodule in submodules: + submodule_setup_path = osp.join( + osp.abspath(osp.dirname(__file__)), + "machine_learning_control", + submodule, + "setup.py", + ) + + if not osp.exists(submodule_setup_path): + print("Could not find {}".format(submodule_setup_path)) + print("Did you run 'git submodule update --init --recursive'?") + sys.exit(1) + + # Add extra virtual shortened package for each stand-alone namespace package # NOTE: This only works if you don't have a __init__.py file in your parent folder and # stand alone_ns_pkgs folder. @@ -32,9 +52,9 @@ if short_child not in PACKAGES: PACKAGES.append(short_child) +# Throw warning if submodules were not pulled +submodules_available(stand_alone_ns_pkgs) + setup( - packages=PACKAGES, - package_dir=PACKAGE_DIR, + packages=PACKAGES, package_dir=PACKAGE_DIR, ) - -# TODO: Add submodule check like in pytorch!