Skip to content

Commit

Permalink
refactor: fix flake8 and documentation formatting errors
Browse files Browse the repository at this point in the history
This commit fixes several flake8 and doc formatting errors.
  • Loading branch information
rickstaa committed Feb 14, 2024
1 parent 668f3ef commit f2a097b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 44 deletions.
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[flake8]
max-line-length = 89
extend-ignore = E266
exclude =
docs/source/conf.py,
build,
node_modules
node_modules,
tests,
stable_gym/version.py
per-file-ignores =
__init__.py: F401, E501
extend-ignore = E266, D400, D401, D205
4 changes: 2 additions & 2 deletions stable_gym/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def inject_value(input_item, value, round_accuracy=2, order=False, axis=0):
Returns:
union[list,dict]: The list or dictionary that contains the value.
"""
order_op = lambda *args, **kwargs: (
order_op = lambda *args, **kwargs: ( # noqa: E731
sorted(*args, **kwargs) if order else list(*args, **kwargs)
)
if isinstance(input_item, dict):
Expand Down Expand Up @@ -263,7 +263,7 @@ def verify_number_and_cast(x):


def maybe_parse_reset_bounds(options, default_low, default_high):
"""sThis function can be called during a reset() to customize the sampling
"""This function can be called during a reset() to customize the sampling
ranges for setting the initial state distributions.
Args:
Expand Down
21 changes: 11 additions & 10 deletions stable_gym/envs/biological/oscillator/oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Oscillator(gym.Env):
presented in `Han et al. 2020`_, which was not possible with the original
code's observation space.
- Added an adjustable ``max_cost`` threshold for episode termination,
defaulting to $100$ to match the original environment.
defaulting to 100 to match the original environment.
.. _`Han et al. 2020`: https://arxiv.org/abs/2004.14288
Expand All @@ -47,24 +47,24 @@ class Oscillator(gym.Env):
+-----+-----------------------------------------------+-------------------+-------------------+
| Num | Observation | Min | Max |
+=====+===============================================+===================+===================+
| 0 | Lacl mRNA transcripts concentration | 0 | $\infty$ |
| 0 | Lacl mRNA transcripts concentration | 0 | :math:`\infty` |
+-----+-----------------------------------------------+-------------------+-------------------+
| 1 | tetR mRNA transcripts concentration | 0 | $\infty$ |
| 1 | tetR mRNA transcripts concentration | 0 | :math:`\infty` |
+-----+-----------------------------------------------+-------------------+-------------------+
| 2 | CI mRNA transcripts concentration | 0 | $\infty$ |
| 2 | CI mRNA transcripts concentration | 0 | :math:`\infty` |
+-----+-----------------------------------------------+-------------------+-------------------+
| 3 || lacI (repressor) protein concentration | 0 | $\infty$ |
| 3 || lacI (repressor) protein concentration | 0 | :math:`\infty` |
| || (Inhibits transcription of the tetR gene) | | |
+-----+-----------------------------------------------+-------------------+-------------------+
| 4 || tetR (repressor) protein concentration | 0 | $\infty$ |
| 4 || tetR (repressor) protein concentration | 0 | :math:`\infty` |
| || (Inhibits transcription of CI gene) | | |
+-----+-----------------------------------------------+-------------------+-------------------+
| 5 || CI (repressor) protein concentration | 0 | $\infty$ |
| 5 || CI (repressor) protein concentration | 0 | :math:`\infty` |
| || (Inhibits transcription of lacI gene) | | |
+-----+-----------------------------------------------+-------------------+-------------------+
| 6 | The reference we want to follow | 0 | $\infty$ |
| 6 | The reference we want to follow | 0 | :math:`\infty` |
+-----+-----------------------------------------------+-------------------+-------------------+
| (7) || **Optional** - The error between the current | $-\infty$ | $\infty$ |
| (7) || **Optional** - The error between the current | :math:`-\infty` | :math:`\infty` |
| || value of protein 1 and the reference | | |
+-----+-----------------------------------------------+-------------------+-------------------+
Expand Down Expand Up @@ -96,7 +96,8 @@ class Oscillator(gym.Env):
Episode Termination:
- An episode is terminated when the maximum step limit is reached.
- The step exceeds a threshold (default is $100$). This threshold can be adjusted using the `max_cost` environment argument.
- The step exceeds a threshold (default is 100). This threshold can be
adjusted using the `max_cost` environment argument.
Solved Requirements:
Considered solved when the average cost is lower than 300.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class is based on the :class:`~stable_gym.envs.biological.oscillator.oscillator.
presented in `Han et al. 2020`_, which was not possible with the original
code's observation space.
- Added an adjustable ``max_cost`` threshold for episode termination,
defaulting to $\infty$ to match the original environment.
defaulting to :math:`\infty` to match the original environment.
.. _`Han et al. 2020`: https://arxiv.org/abs/2004.14288
Expand All @@ -53,29 +53,29 @@ class is based on the :class:`~stable_gym.envs.biological.oscillator.oscillator.
+-----+-------------------------------------------------+-------------------+-------------------+
| Num | Observation | Min | Max |
+=====+=================================================+===================+===================+
| 0 | Lacl mRNA transcripts concentration | 0 | $\infty$ |
| 0 | Lacl mRNA transcripts concentration | 0 | :math:`\infty` |
+-----+-------------------------------------------------+-------------------+-------------------+
| 1 | tetR mRNA transcripts concentration | 0 | $\infty$ |
| 1 | tetR mRNA transcripts concentration | 0 | :math:`\infty` |
+-----+-------------------------------------------------+-------------------+-------------------+
| 2 | CI mRNA transcripts concentration | 0 | $\infty$ |
| 2 | CI mRNA transcripts concentration | 0 | :math:`\infty` |
+-----+-------------------------------------------------+-------------------+-------------------+
| 3 | Extra protein mRNA transcripts concentration | 0 | $\infty$ |
| 3 | Extra protein mRNA transcripts concentration | 0 | :math:`\infty` |
+-----+-------------------------------------------------+-------------------+-------------------+
| 4 || lacI (repressor) protein concentration | 0 | $\infty$ |
| 4 || lacI (repressor) protein concentration | 0 | :math:`\infty` |
| || (Inhibits transcription of the tetR gene) | | |
+-----+-------------------------------------------------+-------------------+-------------------+
| 5 || tetR (repressor) protein concentration | 0 | $\infty$ |
| 5 || tetR (repressor) protein concentration | 0 | :math:`\infty` |
| || (Inhibits transcription of CI gene) | | |
+-----+-------------------------------------------------+-------------------+-------------------+
| 6 || CI (repressor) protein concentration | 0 | $\infty$ |
| 6 || CI (repressor) protein concentration | 0 | :math:`\infty` |
| || (Inhibits transcription of extra protein gene) | | |
+-----+-------------------------------------------------+-------------------+-------------------+
| 7 || Extra (repressor) protein concentration | 0 | $\infty$ |
| 7 || Extra (repressor) protein concentration | 0 | :math:`\infty` |
| || (Inhibits transcription of lacI gene) | | |
+-----+-------------------------------------------------+-------------------+-------------------+
| 8 | The reference we want to follow | 0 | $\infty$ |
| 8 | The reference we want to follow | 0 | :math:`\infty` |
+-----+-------------------------------------------------+-------------------+-------------------+
| (9) || **Optional** - The error between the current | -$\infty$ | $\infty$ |
| (9) || **Optional** - The error between the current | -:math:`\infty` | :math:`\infty` |
| || value of protein 1 and the reference | | |
+-----+-------------------------------------------------+-------------------+-------------------+
Expand Down Expand Up @@ -110,7 +110,8 @@ class is based on the :class:`~stable_gym.envs.biological.oscillator.oscillator.
Episode Termination:
- An episode is terminated when the maximum step limit is reached.
- The step exceeds a threshold (default is $\infty$). This threshold can be adjusted using the `max_cost` environment argument.
- The step exceeds a threshold (default is :math:`\infty`). This threshold can
be adjusted using the `max_cost` environment argument.
Solved Requirements:
Considered solved when the average cost is lower than 300.
Expand Down
70 changes: 57 additions & 13 deletions stable_gym/envs/classic_control/ex3_ekf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,70 @@
"""Noisy master slave system (Ex3EKF) gymnasium environment.
r"""Noisy master slave system (Ex3EKF) gymnasium environment.
The dynamic system whose state is to be estimated:
Dynamics
========
The dynamics of the system whose state is to be estimated are given by:
.. math::
:nowrap:
\[
\begin{split}
x(k+1) &= A x(k) + w(k) \\
\end{split}
\]
In which the state vector :math:`(x(k)` is given by:
.. math::
:nowrap:
\[
\begin{align*}
x_1 &: \text{angle} \\
x_2 &: \text{frequency} \\
x_3 &: \text{amplitude}
\end{align*}
\]
x(k+1)=Ax(k)+w(k)
x_1: angle
x_2: frequency
x_3: amplitude
and the measurement vector :math:`(y(k))` is given by:
.. math::
:nowrap:
y(k)=x_3(k)*sin(x_1(k))+v(k)
A=[1,dt,0;0,1,0;0,0,1]
x(0)~N([0;10;1],[3,0,0;0,3,0;0,0,3])
w(k)~N([0;0;0],[1/3*(dt)^3*q_1,1/2*(dt)^2*q_1,0;1/2*(dt)^2*q_1,dt*q_1,0;0,0,dt*q_2])
v(k)~N(0,1)
\[
\begin{split}
y(k) &= x_3(k) \cdot \sin(x_1(k)) + v(k) \\
A &= \begin{bmatrix}
1 & dt & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix} \\
x(0) &\sim \mathcal{N}\left(\begin{bmatrix}0 \\ 10 \\ 1\end{bmatrix}, \begin{bmatrix}
3 & 0 & 0 \\
0 & 3 & 0 \\
0 & 0 & 3
\end{bmatrix}\right) \\
w(k) &\sim \mathcal{N}\left(\begin{bmatrix}0 \\ 0 \\ 0\end{bmatrix}, \begin{bmatrix}
\frac{1}{3}dt^3 q_1 & \frac{1}{2}dt^2 q_1 & 0 \\
\frac{1}{2}dt^2 q_1 & dt q_1 & 0 \\
0 & 0 & dt q_2
\end{bmatrix}\right) \\
v(k) &\sim \mathcal{N}(0, 1)
\end{split}
\]
Estimator design:
.. math::
:nowrap:
\\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(.,.)
\[
\begin{split}
\hat{x}(k+1) &= A \hat{x}(k) + u \\
\text{where } u &= [u1, u2, u3]', \ u = l(\hat{x}(k), y(k)) \text{ come from the policy network } l(.,.).
\end{split}
\]
"""

from stable_gym.envs.classic_control.ex3_ekf.ex3_ekf import Ex3EKF
4 changes: 2 additions & 2 deletions stable_gym/envs/classic_control/ex3_ekf/ex3_ekf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class Ex3EKF(gym.Env):
"""Noisy master slave system
r"""Noisy master slave system
Description:
The goal of the agent in the Ex3EKF environment is to act in such a way that
Expand Down Expand Up @@ -48,7 +48,7 @@ class Ex3EKF(gym.Env):
.. math::
C = {(\\hat{x}_1 - x_1)}^2 + {(\\hat{x}_2 - x_2)}^2
C = {(\hat{x}_1 - x_1)}^2 + {(\hat{x}_2 - x_2)}^2
Starting State:
All observations are assigned a uniform random value in ``[-0.05..0.05]``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# TODO: Update solving criteria after training.
class FetchReachCost(MujocoFetchReachEnv, utils.EzPickle):
"""Custom FetchReach gymnasium robotics environment.
r"""Custom FetchReach gymnasium robotics environment.
.. note::
Can also be used in a vectorized manner. See the
Expand Down Expand Up @@ -41,7 +41,7 @@ class FetchReachCost(MujocoFetchReachEnv, utils.EzPickle):
.. math::
cost = \\left | reward \\right |
cost = \left | reward \right |
Solved Requirements:
Considered solved when the average cost is less than or equal to 50 over
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ def compute_target_deltas(self, ang_pos, lin_pos, quarternion):
Returns:
(np.ndarray): The waypoints target deltas.
""" # noqa: E501

# Store waypoints targets, distances and yaw error scalar.
waypoints_targets = copy.copy(self.waypoints.targets)
old_waypoints_distance = copy.copy(self.waypoints.old_distance)
Expand Down

0 comments on commit f2a097b

Please sign in to comment.