MushroomRL/mushroom-rl

View on GitHub

Showing 316 of 411 total issues

File replay_memory.py has 455 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import numpy as np
import torch

from mushroom_rl.core import DatasetInfo, Dataset, Serializable
from mushroom_rl.rl_utils.parameters import to_parameter
Severity: Minor
Found in mushroom_rl/rl_utils/replay_memory.py - About 6 hrs to fix

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            if wrappers is not None:
                if wrappers_args is None:
                    wrappers_args = [dict()] * len(wrappers)
                for wrapper, args in zip(wrappers, wrappers_args):
                    if isinstance(wrapper, tuple):
    Severity: Major
    Found in mushroom_rl/environments/gymnasium_env.py and 1 other location - About 6 hrs to fix
    mushroom_rl/environments/gym_env.py on lines 54..61

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 109.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            if wrappers is not None:
                if wrappers_args is None:
                    wrappers_args = [dict()] * len(wrappers)
                for wrapper, args in zip(wrappers, wrappers_args):
                    if isinstance(wrapper, tuple):
    Severity: Major
    Found in mushroom_rl/environments/gym_env.py and 1 other location - About 6 hrs to fix
    mushroom_rl/environments/gymnasium_env.py on lines 58..65

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 109.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Dataset has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Dataset(Serializable):
        def __init__(self, dataset_info, n_steps=None, n_episodes=None):
            assert (n_steps is not None and n_episodes is None) or (n_steps is None and n_episodes is not None)
    
            self._array_backend = ArrayBackend.get_array_backend(dataset_info.backend)
    Severity: Minor
    Found in mushroom_rl/core/dataset.py - About 5 hrs to fix

      Identical blocks of code found in 4 locations. Consider refactoring.
      Open

              if absorbing:
                  # large penalty if agent coincides a goal
                  if puck_pos[0] + self.env_spec['table']['length'] / 2 < 0 and \
                          np.abs(puck_pos[1]) - self.env_spec['table']['goal'] < 0:
                      r = -50
      Severity: Major
      Found in mushroom_rl/environments/pybullet_envs/air_hockey/defend.py and 3 other locations - About 5 hrs to fix
      mushroom_rl/environments/mujoco_envs/air_hockey/defend.py on lines 63..67
      mushroom_rl/environments/mujoco_envs/air_hockey/repel.py on lines 66..70
      mushroom_rl/environments/pybullet_envs/air_hockey/repel.py on lines 79..83

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 90.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 4 locations. Consider refactoring.
      Open

              if absorbing:
                  # large penalty if agent coincides a goal
                  if puck_pos[0] + self.env_spec['table']['length'] / 2 < 0 and \
                          np.abs(puck_pos[1]) - self.env_spec['table']['goal'] < 0:
                      r = -50
      Severity: Major
      Found in mushroom_rl/environments/mujoco_envs/air_hockey/defend.py and 3 other locations - About 5 hrs to fix
      mushroom_rl/environments/mujoco_envs/air_hockey/repel.py on lines 66..70
      mushroom_rl/environments/pybullet_envs/air_hockey/defend.py on lines 78..82
      mushroom_rl/environments/pybullet_envs/air_hockey/repel.py on lines 79..83

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 90.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 4 locations. Consider refactoring.
      Open

              if absorbing:
                  # big penalty if we coincide a goal
                  if puck_pos[0] + self.env_spec['table']['length'] / 2 < 0 and \
                          np.abs(puck_pos[1]) - self.env_spec['table']['goal'] < 0:
                      r = -50
      Severity: Major
      Found in mushroom_rl/environments/mujoco_envs/air_hockey/repel.py and 3 other locations - About 5 hrs to fix
      mushroom_rl/environments/mujoco_envs/air_hockey/defend.py on lines 63..67
      mushroom_rl/environments/pybullet_envs/air_hockey/defend.py on lines 78..82
      mushroom_rl/environments/pybullet_envs/air_hockey/repel.py on lines 79..83

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 90.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 4 locations. Consider refactoring.
      Open

              if absorbing:
                  # big penalty if we coincide a goal
                  if puck_pos[0] + self.env_spec['table']['length'] / 2 < 0 and \
                          np.abs(puck_pos[1]) - self.env_spec['table']['goal'] < 0:
                      r = -50
      Severity: Major
      Found in mushroom_rl/environments/pybullet_envs/air_hockey/repel.py and 3 other locations - About 5 hrs to fix
      mushroom_rl/environments/mujoco_envs/air_hockey/defend.py on lines 63..67
      mushroom_rl/environments/mujoco_envs/air_hockey/repel.py on lines 66..70
      mushroom_rl/environments/pybullet_envs/air_hockey/defend.py on lines 78..82

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 90.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          def __init__(self, shape, window_size, backend, init_value=None):
              """
              Constructor.
      
              Args:
      Severity: Major
      Found in mushroom_rl/rl_utils/running_stats.py and 1 other location - About 4 hrs to fix
      mushroom_rl/rl_utils/running_stats.py on lines 92..109

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 83.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          def __init__(self, shape, alpha, backend, init_value=None):
              """
              Constructor.
      
              Args:
      Severity: Major
      Found in mushroom_rl/rl_utils/running_stats.py and 1 other location - About 4 hrs to fix
      mushroom_rl/rl_utils/running_stats.py on lines 157..174

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 83.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          def __init__(self, mdp_info, policy, learning_rate, lambda_coeff,
                       trace='replacing'):
              """
              Constructor.
      
      
      Severity: Major
      Found in mushroom_rl/algorithms/value/td/q_lambda.py and 1 other location - About 4 hrs to fix
      mushroom_rl/algorithms/value/td/sarsa_lambda.py on lines 12..30

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          def __init__(self, mdp_info, policy, learning_rate, lambda_coeff, trace='replacing'):
              """
              Constructor.
      
              Args:
      Severity: Major
      Found in mushroom_rl/algorithms/value/td/sarsa_lambda.py and 1 other location - About 4 hrs to fix
      mushroom_rl/algorithms/value/td/q_lambda.py on lines 15..34

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Function create_sim_state has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_sim_state(self):
              data_obs = list()
      
              self._contacts.compute_contacts()
      
      
      Severity: Minor
      Found in mushroom_rl/utils/pybullet/index_map.py - About 4 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function reset has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          def reset(self, mask=None):
              policy_states = None
              if self.policy_state_shape is None:
                  if mask is None:
                      for policy in self._policy_vector:
      Severity: Minor
      Found in mushroom_rl/policy/vector_policy.py - About 4 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function predict has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          def predict(self, *z, idx=None, prediction=None, compute_variance=False,
                      **predict_params):
              """
              Predict.
      
      
      Severity: Minor
      Found in mushroom_rl/approximators/ensemble.py - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      class WindowedVarianceIncreasingParameter(WindowedVarianceParameter):
          """
          Class implementing a parameter that decreases with the target
          variance, where the variance is computed in a fixed length
          window.
      Severity: Major
      Found in mushroom_rl/rl_utils/variance_parameters.py and 1 other location - About 3 hrs to fix
      mushroom_rl/rl_utils/variance_parameters.py on lines 84..94

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 73.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      class VarianceIncreasingParameter(VarianceParameter):
          """
          Class implementing a parameter that increases with the target
          variance.
      
      
      Severity: Major
      Found in mushroom_rl/rl_utils/variance_parameters.py and 1 other location - About 3 hrs to fix
      mushroom_rl/rl_utils/variance_parameters.py on lines 200..211

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 73.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      File viewer.py has 329 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import os
      if 'PYGAME_HIDE_SUPPORT_PROMPT' not in os.environ:
          os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
      
      import pygame
      Severity: Minor
      Found in mushroom_rl/utils/viewer.py - About 3 hrs to fix

        File array_backend.py has 325 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        from collections import deque
        import numpy as np
        import torch
        
        from mushroom_rl.utils.torch import TorchUtils
        Severity: Minor
        Found in mushroom_rl/core/array_backend.py - About 3 hrs to fix

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                  if info['lives'] != self._lives:
                      if self._episode_ends_at_life:
                          absorbing = True
                      self._lives = info['lives']
                      self._force_fire = self.env.unwrapped.get_action_meanings()[1] == 'FIRE'
          Severity: Major
          Found in mushroom_rl/environments/atari.py and 1 other location - About 3 hrs to fix
          mushroom_rl/environments/gymnasium_atari.py on lines 134..138

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 69.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Severity
          Category
          Status
          Source
          Language