MushroomRL/mushroom-rl

View on GitHub

Showing 316 of 411 total issues

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

    def __getitem__(self, index):
        return self._states[index], self._actions[index], self._rewards[index], self._next_states[index], \
               self._absorbing[index], self._last[index]
Severity: Major
Found in mushroom_rl/core/_impl/numpy_dataset.py and 1 other location - About 3 hrs to fix
mushroom_rl/core/_impl/torch_dataset.py on lines 199..201

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 65.

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 keyboard has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def keyboard(self, window, key, scancode, act, mods):
        """
        Keyboard callback for glfw.

        Args:
Severity: Minor
Found in mushroom_rl/utils/mujoco/viewer.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

Function reward has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def reward(self, state, action, next_state, absorbing):
        puck_pos = self.get_sim_state(next_state, "puck", PyBulletObservationType.BODY_POS)[:2]
        puck_vel = self.get_sim_state(next_state, "puck", PyBulletObservationType.BODY_LIN_VEL)[:2]
        ee_pos = self.get_sim_state(next_state, "planar_robot_1/link_striker_ee",
                                    PyBulletObservationType.LINK_POS)[:2]
Severity: Minor
Found in mushroom_rl/environments/pybullet_envs/air_hockey/prepare.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

Function reward has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def reward(self, state, action, next_state, absorbing):
        puck_pos, puck_vel, _ = self.get_puck(next_state)
        puck_pos = puck_pos[:2]
        puck_vel = puck_vel[:2]
        ee_pos = self.get_ee()[0][:2]
Severity: Minor
Found in mushroom_rl/environments/mujoco_envs/air_hockey/prepare.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

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

        self._weights_var[idx] = (
            1. - factor*parameter_value) ** 2 * self._weights_var[idx] + (
            factor * parameter_value) ** 2
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 75..77

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 63.

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

        self._weights_var[idx] = (
            1. - factor * parameter_value) ** 2 * self._weights_var[idx] + (
            factor * parameter_value) ** 2
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 190..192

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 63.

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

Consider simplifying this complex logical expression.
Open

    if basis_list is not None and tilings is None and tensor_list is None and n_outputs is None:
        return BasisFeatures(basis_list)
    elif basis_list is None and tilings is not None and tensor_list is None and n_outputs is None:
        return TilesFeatures(tilings)
    elif basis_list is None and tilings is None and tensor_list is not None and n_outputs is None:
Severity: Critical
Found in mushroom_rl/features/features.py - About 3 hrs to fix

    Function save_zip has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def save_zip(self, zip_file, full_save, folder=''):
            """
            Serialize and save the agent to the given path on disk.
    
            Args:
    Severity: Minor
    Found in mushroom_rl/core/serialization.py - About 2 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 load_zip has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def load_zip(cls, zip_file, folder=''):
            config_path = Serializable._append_folder(folder, 'config')
    
            try:
                object_type, save_attributes, primitive_dictionary = \
    Severity: Minor
    Found in mushroom_rl/core/serialization.py - About 2 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

    PyBullet has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class PyBullet(Environment):
        """
        Class to create a Mushroom environment using the PyBullet simulator.
    
        """
    Severity: Minor
    Found in mushroom_rl/environments/pybullet.py - About 2 hrs to fix

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

                  if obs_type is PyBulletObservationType.BODY_POS \
                     or obs_type is PyBulletObservationType.BODY_LIN_VEL \
                     or obs_type is PyBulletObservationType.BODY_ANG_VEL:
                      n_dim = 7 if obs_type is PyBulletObservationType.BODY_POS else 3
                      low += [-np.inf] * n_dim
      Severity: Major
      Found in mushroom_rl/utils/pybullet/index_map.py and 1 other location - About 2 hrs to fix
      mushroom_rl/utils/pybullet/index_map.py on lines 151..156

      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 58.

      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

                  elif obs_type is PyBulletObservationType.LINK_POS \
                          or obs_type is PyBulletObservationType.LINK_LIN_VEL \
                          or obs_type is PyBulletObservationType.LINK_ANG_VEL:
                      n_dim = 7 if obs_type is PyBulletObservationType.LINK_POS else 3
                      low += [-np.inf] * n_dim
      Severity: Major
      Found in mushroom_rl/utils/pybullet/index_map.py and 1 other location - About 2 hrs to fix
      mushroom_rl/utils/pybullet/index_map.py on lines 145..150

      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 58.

      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, mdp_info, distribution, policy, beta):
              """
              Constructor.
      
              Args:
      mushroom_rl/algorithms/policy_search/black_box_optimization/reps.py on lines 16..32

      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 57.

      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, mdp_info, distribution, policy, eps):
              """
              Constructor.
      
              Args:
      mushroom_rl/algorithms/policy_search/black_box_optimization/rwr.py on lines 14..29

      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 57.

      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

      NumpyBackend has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class NumpyBackend(ArrayBackend):
          @staticmethod
          def get_backend_name():
              return 'numpy'
      
      
      Severity: Minor
      Found in mushroom_rl/core/array_backend.py - About 2 hrs to fix

        TorchBackend has 23 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class TorchBackend(ArrayBackend):
        
            @staticmethod
            def get_backend_name():
                return 'torch'
        Severity: Minor
        Found in mushroom_rl/core/array_backend.py - About 2 hrs to fix

          Function __init__ has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              def __init__(self, model, dt, width=1920, height=1080, start_paused=False,
                           custom_render_callback=None, record=False, camera_params=None,
                           default_camera_mode="static", hide_menu_on_startup=None,
                           geom_group_visualization_on_startup=None, headless=False):
                  """
          Severity: Minor
          Found in mushroom_rl/utils/mujoco/viewer.py - About 2 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

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

                  constraints["ee_constraints"] = np.array([-ee_pos[0] + x_lb,
                                                            -ee_pos[1] + y_lb, ee_pos[1] - y_ub])
          Severity: Major
          Found in mushroom_rl/environments/mujoco_envs/air_hockey/single.py and 1 other location - About 2 hrs to fix
          mushroom_rl/environments/mujoco_envs/air_hockey/double.py on lines 138..139

          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 55.

          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

                      constraints[key]["ee_constraints"] = np.array([-ee_pos[0] + x_lb,
                                                                     -ee_pos[1] + y_lb, ee_pos[1] - y_ub])
          Severity: Major
          Found in mushroom_rl/environments/mujoco_envs/air_hockey/double.py and 1 other location - About 2 hrs to fix
          mushroom_rl/environments/mujoco_envs/air_hockey/single.py on lines 123..124

          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 55.

          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

          NumpyDataset has 22 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class NumpyDataset(Serializable):
              def __init__(self, state_type, state_shape, action_type, action_shape, reward_shape, flag_shape,
                           policy_state_shape, mask_shape):
          
                  self._state_type = state_type
          Severity: Minor
          Found in mushroom_rl/core/_impl/numpy_dataset.py - About 2 hrs to fix
            Severity
            Category
            Status
            Source
            Language