MushroomRL/mushroom-rl

View on GitHub

Showing 119 of 411 total issues

Consider simplifying this complex logical expression.
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 - About 40 mins to fix

    Function render has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def render(self, record=False):
            if self._first or self._not_pybullet:
                img = self.env.render()
    
                if self._first:
    Severity: Minor
    Found in mushroom_rl/environments/gymnasium_env.py - About 35 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 _load_all_models has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def _load_all_models(self, files, enforce_joint_velocity_limits):
            for file_name, kwargs in files.items():
                model_id = self._load_model(file_name, kwargs)
                model_name = self._client.getBodyInfo(model_id)[1].decode('UTF-8')
                self._model_map[model_name] = model_id
    Severity: Minor
    Found in mushroom_rl/environments/pybullet.py - About 35 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_mask has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_mask(self, last):
            terminated_episodes = (last & self._running_envs).sum().item()
            running_episodes = (~last & self._running_envs).sum().item()
    
            first_batch = running_episodes == 0 and terminated_episodes == 0
    Severity: Minor
    Found in mushroom_rl/core/_impl/vectorized_core_logic.py - About 35 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 from_array has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def from_array(cls, states, actions, rewards, next_states, absorbings, lasts, policy_states=None,
                       policy_next_states=None):
            is_stateful = (policy_states is not None) and (policy_next_states is not None)
    
            dataset = cls(is_stateful, False)
    Severity: Minor
    Found in mushroom_rl/core/_impl/list_dataset.py - About 35 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 fit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def fit(self, dataset):
            state, action, reward, next_state, absorbing, _ = dataset.parse(to='numpy')
            for _ in trange(self._n_iterations(), dynamic_ncols=True, disable=self._quiet, leave=False):
                if self._target is None:
                    self._target = reward
    Severity: Minor
    Found in mushroom_rl/algorithms/value/batch_td/boosted_fqi.py - About 35 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 initialize_run has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_run(self, n_steps, n_episodes, initial_states, quiet):
            assert n_episodes is not None and n_steps is None and initial_states is None\
                or n_episodes is None and n_steps is not None and initial_states is None\
                or n_episodes is None and n_steps is None and initial_states is not None
    
    
    Severity: Minor
    Found in mushroom_rl/core/_impl/core_logic.py - About 35 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 compute_contacts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def compute_contacts(self):
            if len(self._contact_list) == 0:
                return
    
            self._reset_computed_contacts()
    Severity: Minor
    Found in mushroom_rl/utils/pybullet/contacts.py - About 35 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 step has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def step(self, action):
            cur_obs = self._obs.copy()
    
            action = self._preprocess_action(action)
    
    
    Severity: Minor
    Found in mushroom_rl/environments/mujoco.py - About 35 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 _load_numpy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def _load_numpy(self):
            for file in self._results_dir.iterdir():
                if file.is_file() and file.suffix == '.npy':
                    if file.stem.endswith(self._suffix):
                        name = re.split(r'-\d+$', file.stem)[0]
    Severity: Minor
    Found in mushroom_rl/core/logger/data_logger.py - About 35 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 _reset_computed_contacts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def _reset_computed_contacts(self):
            for contact in self._contact_name_map.values():
                model_a, model_b, link_a, link_b = self._order_contact(*contact)
    
                if model_a not in self._computed_contacts:
    Severity: Minor
    Found in mushroom_rl/utils/pybullet/contacts.py - About 35 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 __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, dimensions=None, degrees=None, low=None, high=None):
            """
            Constructor. If both parameters are None, the constant feature is built.
    
            Args:
    Severity: Minor
    Found in mushroom_rl/features/basis/polynomial.py - About 35 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 fit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def fit(self, dataset):
            self._replay_memory.add(dataset, np.ones(len(dataset)) * self._replay_memory.max_priority,
                                    n_steps_return=self._n_steps_return, gamma=self.mdp_info.gamma)
            if self._replay_memory.initialized:
                state, action, reward, next_state, absorbing, _, idxs, is_weight = \
    Severity: Minor
    Found in mushroom_rl/algorithms/value/dqn/rainbow.py - About 35 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 __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, mdp_info, policy, approximator, approximator_params, batch_size, target_update_frequency,
                     replay_memory=None, initial_replay_size=500, max_replay_size=5000, fit_params=None,
                     predict_params=None, clip_reward=False):
            """
            Constructor.
    Severity: Minor
    Found in mushroom_rl/algorithms/value/dqn/abstract_dqn.py - About 35 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 step_all has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def step_all(self, env_mask, action):
            for i, remote in enumerate(self._remotes):
                if env_mask[i]:
                    remote.send(('step', action[i, :]))
    
    
    Severity: Minor
    Found in mushroom_rl/core/multiprocess_environment.py - About 35 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 too many return statements within this function.
    Open

                return False
    Severity: Major
    Found in mushroom_rl/environments/pybullet_envs/air_hockey/prepare.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return False
      Severity: Major
      Found in mushroom_rl/environments/mujoco_envs/air_hockey/prepare.py - About 30 mins to fix

        Function from_array has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def from_array(cls, states, actions, rewards, next_states, absorbings, lasts,
                           policy_states=None, policy_next_states=None):
                if not isinstance(states, np.ndarray):
                    states = states.numpy()
                    actions = actions.numpy()
        Severity: Minor
        Found in mushroom_rl/core/_impl/numpy_dataset.py - About 25 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 _simulation_post_step has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def _simulation_post_step(self):
                if not self.has_hit:
                    collision_count = len(self.client.getContactPoints(self._model_map['puck'],
                                                                       self._indexer.link_map['planar_robot_1/'
                                                                                              'link_striker_ee'][0],
        Severity: Minor
        Found in mushroom_rl/environments/pybullet_envs/air_hockey/defend.py - About 25 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 apply_control has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def apply_control(self, action):
        
                i = 0
                for model_id, joint_id, mode in self.action_data:
                    u = action[i]
        Severity: Minor
        Found in mushroom_rl/utils/pybullet/index_map.py - About 25 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

        Severity
        Category
        Status
        Source
        Language