JohannesHeidecke/irl-benchmark

View on GitHub

Showing 29 of 61 total issues

File reward_function.py has 320 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Module containing reward functions to be used for IRL."""
from abc import ABC, abstractmethod
from copy import copy
from typing import NamedTuple, Union

Severity: Minor
Found in irl_benchmark/irl/reward/reward_function.py - About 3 hrs to fix

    Function train has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def train(self, no_irl_iterations: int,
                  no_rl_episodes_per_irl_iteration: int,
                  no_irl_episodes_per_irl_iteration: int
                  ) -> Tuple[BaseRewardFunction, BaseRLAlgorithm]:
            """Train the apprenticeship learning IRL algorithm.
    Severity: Minor
    Found in irl_benchmark/irl/algorithms/appr_irl.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 collect_trajs has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def collect_trajs(env: gym.Env,
                      agent: BaseRLAlgorithm,
                      no_trajectories: int,
                      max_steps_per_episode: Union[int, None] = None,
                      store_to: Union[str, None] = None,
    Severity: Minor
    Found in irl_benchmark/irl/collect/__init__.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 preprocess_config has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def preprocess_config(config_for: object, domains: dict, config: dict) -> dict:
        """ Pre-processes a config dictionary.
    
        This is based on the values specified for each IRL algorithm in
        IRL_CONFIG_DOMAINS. The following steps are performed:
    Severity: Minor
    Found in irl_benchmark/config/__init__.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

    File feature_wrapper.py has 255 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    """Module for feature wrappers providing features for different environments."""
    
    from abc import abstractmethod
    import functools
    from typing import Union, Tuple
    Severity: Minor
    Found in irl_benchmark/irl/feature/feature_wrapper.py - About 2 hrs to fix

      Function _domain_to_features has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def _domain_to_features(
                  self, domain_batch: Union[State, StateAction, StateActionState]
          ) -> np.ndarray:
              """Convert elements of the domain to features.
      
      
      Severity: Minor
      Found in irl_benchmark/irl/reward/reward_function.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 occupancy_measure has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def occupancy_measure(self,
                                policy,
                                initial_state_dist,
                                t_max=None,
                                threshold=1e-6):
      Severity: Minor
      Found in irl_benchmark/irl/algorithms/mce_irl.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 get_transition_array has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_transition_array(self):
              env = unwrap_env(self.env, DiscreteEnv)
      
              # adding +1 to account for absorbing state
              # (reached whenever game ended)
      Severity: Minor
      Found in irl_benchmark/rl/model/discrete_env.py - About 1 hr 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 step has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def step(self, action):
              """Do a step with the provided action."""
              state = np.copy(self.current_state)
              assert len(state) == self.num_rewards * 2
              assert action < self.num_rewards
      Severity: Minor
      Found in irl_benchmark/envs/maze_world.py - About 1 hr 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 expected_svf has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def expected_svf(self, policy: np.ndarray) -> np.ndarray:
              """Calculate the expected state visitation frequency for the trajectories
              under the given policy. Returns vector of state visitation frequencies.
              Uses self.transition_matrix.
      
      
      Severity: Minor
      Found in irl_benchmark/irl/algorithms/me_irl.py - About 1 hr 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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, env_id: str, expert_trajs_path: str,
      Severity: Major
      Found in irl_benchmark/experiment/run.py - About 50 mins to fix

        Function collect_trajs has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def collect_trajs(env: gym.Env,
        Severity: Minor
        Found in irl_benchmark/irl/collect/__init__.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if reward_wrapper is None:
                                      rewards[s, a] = REWARD_MOVE
                                      if state[num_rewards + a] != 0:
                                          rews_where = self.maze_env.rews_where
                                          rewards[s, a] += float(
          Severity: Major
          Found in irl_benchmark/rl/model/maze_world.py - About 45 mins to fix

            Function make_wrapped_env has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            def make_wrapped_env(env_id: str,
                                 with_feature_wrapper: bool = False,
                                 reward_function_factory: Callable = None,
                                 with_model_wrapper: bool = False):
                """Make an environment, potentially wrapped in FeatureWrapper, RewardWrapper,
            Severity: Minor
            Found in irl_benchmark/envs/__init__.py - About 45 mins 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 get_reward_input_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_reward_input_for(self, state: Union[np.ndarray, int, float],
                                         action: Union[np.ndarray, int, float],
                                         next_state: Union[np.ndarray, int, float]
                                         ) -> Union[State, StateAction, StateActionState]:
                    """
            Severity: Minor
            Found in irl_benchmark/irl/reward/reward_wrapper.py - About 45 mins 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 features has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def features(self, current_state: np.ndarray, action: int,
                             next_state: None) -> np.ndarray:
                    """Return features to be saved in step method's info dictionary.
            
                    There are four feature variables: expected walking distance,
            Severity: Minor
            Found in irl_benchmark/irl/feature/feature_wrapper.py - About 45 mins 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

            Avoid deeply nested control flow statements.
            Open

                                    if state[num_rewards + a] == 0:
                                        # if reward is already collected at this field:
                                        rew_value = 0
                                    else:
                                        rews_where = self.maze_env.rews_where
            Severity: Major
            Found in irl_benchmark/rl/model/maze_world.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if reward_wrapper is None:
                                          rewards[s, a] = 0
                                      else:
                                          rewards[s, a] = wrapped_reward
                                  continue
              Severity: Major
              Found in irl_benchmark/rl/model/maze_world.py - About 45 mins to fix

                Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def __init__(self, env: gym.Env, expert_trajs: List[Dict[str, list]],
                Severity: Minor
                Found in irl_benchmark/irl/algorithms/appr_irl.py - About 35 mins to fix

                  Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def __init__(self, env: gym.Env, expert_trajs: List[Dict[str, list]],
                  Severity: Minor
                  Found in irl_benchmark/irl/algorithms/mce_irl.py - About 35 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language