Skip to content

Commit

Permalink
🏗️ Cleans up the respository structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rickstaa committed Mar 30, 2021
1 parent b895a4b commit 9d48be1
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 71 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "simzoo/envs/ex3_ekf"]
path = simzoo/envs/ex3_ekf
url = ../ex3_ekf.git
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A python package containing the bayesian_learning_control Openai gym environments. It currently contains the following environments:

- [Oscillator:](https://github.com/rickstaa/oscillator) A gym environment for a synthetic oscillatory network of transcriptional regulators called a repressilator.
- [Ex3_EKF:](https://github.com/rickstaa/ex3_ekf) A noisy master-slave environment that can be used to train a RL based stationary Kalman estimator.
- [Ex3EKF:](https://github.com/rickstaa/ex3_ekf) A noisy master-slave environment that can be used to train a RL based stationary Kalman estimator.

## Clone the repository

Expand Down
8 changes: 6 additions & 2 deletions simzoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
namespace_prefix = "bayesian_learning_control.simzoo."

ENVS = {
"name": ["Oscillator-v1", "Ex3_EKF-v0", "CartPoleCustom-v0"],
"module": ["simzoo.envs.oscillator:Oscillator", "simzoo.envs.ex3_ekf:Ex3_EKF", "simzoo.envs.cart_pole.CartPole:CartPoleCustom"],
"name": ["Oscillator-v1", "Ex3EKF-v1", "CartPoleCost-v0"],
"module": [
"simzoo.envs.biological.oscillator:Oscillator",
"simzoo.envs.classic_control.ex3_ekf:Ex3EKF",
"simzoo.envs.classic_control.cart_pole_cost:CartPoleCost",
],
"max_step": [800, 800, 800],
}

Expand Down
33 changes: 0 additions & 33 deletions simzoo/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1 @@
"""The Simzoo Gym environments."""
import importlib
import sys

# Import simzoo stand-alone package or name_space package (mlc)
if "simzoo" in sys.modules:
from simzoo.envs.oscillator.oscillator import Oscillator
from simzoo.envs.ex3_ekf.ex3_ekf import Ex3_EKF
from simzoo.envs.cart_pole.CartPole import CartPoleCustom
elif importlib.util.find_spec("simzoo") is not None:
Oscillator = getattr(
importlib.import_module("simzoo.envs.oscillator.oscillator"), "Oscillator"
)
Ex3_EKF = getattr(importlib.import_module("simzoo.envs.ex3_ekf.ex3_ekf"), "Ex3_EKF")
CartPole = getattr(importlib.import_module("simzoo.envs.ex3_ekf.cart_pole"), "CartPoleCustom")
else:
Oscillator = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.oscillator.oscillator"
),
"Oscillator",
)
Ex3_EKF = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.ex3_ekf.ex3_ekf"
),
"Ex3_EKF",
)
CartPole = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.cart_pole.CartPole"
),
"CartPoleCustom",
)
21 changes: 21 additions & 0 deletions simzoo/envs/biological/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Import biological environments onto namespace
"""

import sys
import importlib

# NOTE: Makes sure that it works both in the Simzoo stand-alone package and the name_space package (blc)
if "simzoo" in sys.modules:
from simzoo.envs.biological.oscillator.oscillator import Oscillator
elif importlib.util.find_spec("simzoo") is not None:
Oscillator = getattr(
importlib.import_module("simzoo.envs.biological.oscillator.oscillator"),
"Oscillator",
)
else:
Oscillator = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.biological.oscillator.oscillator"
),
"Oscillator",
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions simzoo/envs/classic_control/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Import classical_control environments onto namespace
"""

import sys
import importlib

# NOTE: Makes sure that it works both in the Simzoo stand-alone package and the name_space package (blc)
if "simzoo" in sys.modules:
from simzoo.envs.classic_control.ex3_ekf.ex3_ekf import Ex3EKF
from simzoo.envs.classic_control.cart_pole_cost.cart_pole_cost import CartPoleCost
elif importlib.util.find_spec("simzoo") is not None:
Ex3EKF = getattr(
importlib.import_module("simzoo.envs.classic_control.ex3_ekf.ex3_ekf"),
"Ex3EKF",
)
CartPoleCost = getattr(
importlib.import_module(
"simzoo.envs.classic_control.cart_pole_cost.cart_pole_cost"
),
"CartPoleCost",
)
else:
Ex3EKF = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.classic_control.ex3_ekf.ex3_ekf"
),
"Ex3EKF",
)
CartPoleCost = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.classic_control.cart_pole_cost.cart_pole_cost"
),
"CartPoleCost",
)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

# Import simzoo stand-alone package or name_space package (blc)
if "simzoo" in sys.modules:
from simzoo.envs.cart_pole.CartPole import CartPoleCustom
from simzoo.envs.cart_pole.CartPole import CartPoleCost
elif importlib.util.find_spec("simzoo") is not None:
CartPole = getattr(
importlib.import_module("simzoo.envs.cart_pole.CartPole"), "CartPoleCustom"
importlib.import_module("simzoo.envs.cart_pole.CartPole"), "CartPoleCost"
)
else:
CartPole = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.cart_pole.CartPole"
),
"CartPoleCustom",
"CartPoleCost",
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# }


class CartPoleCustom(gym.Env, Disturber):
class CartPoleCost(gym.Env, Disturber):
"""
Description:
A pole is attached by an un-actuated joint to a cart, which moves along a
Expand Down Expand Up @@ -387,7 +387,7 @@ def COST_V2(r1, r2, e1, e2, x, x_dot, theta, theta_dot):
if __name__ == "__main__":

print("Settting up Cartpole environment.")
env = CartPoleCustom()
env = CartPoleCost()

# Take T steps in the environment
T = 60000
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ex3_EKF gym environment
# Ex3EKF gym environment

A gym environment for a noisy master-slave system. This environment can be used to train a
RL based stationary Kalman filter.
Expand All @@ -17,7 +17,7 @@ RL based stationary Kalman filter.

## Environment goal

The goal of the agent in the Ex3_EKF environment is to act in such a way that
The goal of the agent in the Ex3EKF environment is to act in such a way that
estimator perfectly estimated the original noisy system. By doing this, it serves
as an RL based stationary Kalman filter.

Expand Down
18 changes: 18 additions & 0 deletions simzoo/envs/classic_control/ex3_ekf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Noisy master slave system (Ex3EKF) gym environment."""
import sys
import importlib

# Import simzoo stand-alone package or name_space package (blc)
if "simzoo" in sys.modules:
from simzoo.envs.classic_control.ex3_ekf.ex3_ekf import Ex3EKF
elif importlib.util.find_spec("simzoo") is not None:
Ex3EKF = getattr(
importlib.import_module("simzoo.envs.classic_control.ex3_ekf.ex3_ekf"), "Ex3EKF"
)
else:
Ex3EKF = getattr(
importlib.import_module(
"bayesian_learning_control.simzoo.simzoo.envs.classic_control.ex3_ekf.ex3_ekf"
),
"Ex3EKF",
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Noisy master slave system (Ex3_EKF) gym environment.
"""Noisy master slave system (Ex3EKF) gym environment.
The dynamic system whose state is to be estimated:
Expand All @@ -21,7 +21,7 @@
\\hat(x)(k+1)=A\\hat(x)(k)+u
where u=[u1,u2,u3]', u=l(\\hat(x)(k),y(k)) come from the policy network l(.,.)
"""
__VERSION__ = "0.6.3" # Ex3_EKF version
__VERSION__ = "0.6.3" # Ex3EKF version

import importlib
import sys
Expand Down Expand Up @@ -68,9 +68,9 @@
}


class Ex3_EKF(gym.Env, Disturber):
class Ex3EKF(gym.Env, Disturber):
"""Noisy master slave system
The goal of the agent in the Ex3_EKF environment is to act in such a way that
The goal of the agent in the Ex3EKF environment is to act in such a way that
estimator perfectly estimated the original noisy system. By doing this it serves
as a RL based stationary Kalman filter.
Expand All @@ -94,7 +94,7 @@ def __init__(self, seed=400):
self.t = 0
self.dt = 0.1

# Setup Ex3_EKF parameters
# Setup Ex3EKF parameters
self.q1 = 0.01
self.g = 9.81
self.l_net = 1.0
Expand Down Expand Up @@ -248,21 +248,21 @@ def render(self, mode="human"):
This currently is not yet implemented.
"""
raise NotImplementedError(
"No render method was implemented yet for the Ex3_EKF environment."
"No render method was implemented yet for the Ex3EKF environment."
)


if __name__ == "__main__":

print("Settting up Ex3_EKF environment.")
env = Ex3_EKF()
print("Settting up Ex3EKF environment.")
env = Ex3EKF()

# Take T steps in the environment
T = 10
path = []
t1 = []
s = env.reset()
print(f"Taking {T} steps in the Ex3_EKF environment.")
print(f"Taking {T} steps in the Ex3EKF environment.")
for i in range(int(T / env.dt)):
action = (
env.np_random.uniform(
Expand Down
File renamed without changes.
16 changes: 0 additions & 16 deletions simzoo/envs/ex3-ekf/__init__.py

This file was deleted.

0 comments on commit 9d48be1

Please sign in to comment.