kengz/SLM-Lab

View on GitHub

Showing 16 of 95 total issues

Function train has a Cognitive Complexity of 38 (exceeds 10 allowed). Consider refactoring.
Open

    def train(self):
        clock = self.body.env.clock
        if self.to_train == 1:
            net_util.copy(self.net, self.old_net)  # update old net
            batch = self.sample()
Severity: Minor
Found in slm_lab/agent/algorithm/ppo.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 step has a Cognitive Complexity of 26 (exceeds 10 allowed). Consider refactoring.
Open

    def step(self, closure=None):
        loss = None
        if closure is not None:
            loss = closure()

Severity: Minor
Found in slm_lab/lib/optimizer.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 dev_check_train_step has a Cognitive Complexity of 22 (exceeds 10 allowed). Consider refactoring.
Open

def dev_check_train_step(fn):
    '''
    Decorator to check if net.train_step actually updates the network weights properly
    Triggers only if to_check_train_step is True (dev/test mode)
    @example
Severity: Minor
Found in slm_lab/agent/net/net_util.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 flatten_dict has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
Open

def flatten_dict(obj, delim='.'):
    '''Missing pydash method to flatten dict'''
    nobj = {}
    for key, val in obj.items():
        if ps.is_dict(val) and not ps.is_empty(val):
Severity: Minor
Found in slm_lab/lib/util.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 log_tensorboard has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
Open

    def log_tensorboard(self):
        '''
        Log summary and useful info to TensorBoard.
        NOTE this logging is comprehensive and memory-intensive, hence it is used in dev mode only
        '''
Severity: Minor
Found in slm_lab/agent/__init__.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 make_gym_env has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
Open

def make_gym_env(name, seed=None, frame_op=None, frame_op_len=None, image_downsize=None, reward_scale=None, normalize_state=False, episode_life=True):
    '''General method to create any Gym env; auto wraps Atari'''
    env = gym.make(name)
    if seed is not None:
        env.seed(seed)
Severity: Minor
Found in slm_lab/env/wrapper.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_nets has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def init_nets(self, global_nets=None):
        '''
        Networks: net(actor/policy), q1_net, target_q1_net, q2_net, target_q2_net
        All networks are separate, and have the same hidden layer architectures and optim specs, so tuning is minimal
        '''
Severity: Minor
Found in slm_lab/agent/algorithm/sac.py - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

                            for k, v in minibatch.items():
                                if k not in ('advs', 'v_targets'):
                                    minibatch[k] = math_util.venv_pack(v, self.body.env.num_envs)
                        advs, v_targets = minibatch['advs'], minibatch['v_targets']
    Severity: Major
    Found in slm_lab/agent/algorithm/ppo.py - About 45 mins to fix

      Function subproc_worker has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      def subproc_worker(
              pipe, parent_pipe, env_fn_wrapper,
              obs_bufs, obs_shapes, obs_dtypes, keys):
          '''
          Control a single environment instance using IPC and shared memory. Used by ShmemVecEnv.
      Severity: Minor
      Found in slm_lab/env/vec_env.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 plot_trial has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
      Open

      def plot_trial(trial_spec, trial_metrics, ma=False):
          '''
          Plot the trial graphs:
          - mean_returns, strengths, sample_efficiencies, training_efficiencies, stabilities (with error bar)
          - consistencies (no error bar)
      Severity: Minor
      Found in slm_lab/lib/viz.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 tick has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
      Open

      def tick(spec, unit):
          '''
          Method to tick lab unit (experiment, trial, session) in meta spec to advance their indices
          Reset lower lab indices to -1 so that they tick to 0
          spec_util.tick(spec, 'session')
      Severity: Minor
      Found in slm_lab/spec/spec_util.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 'multi_binary'
      Severity: Major
      Found in slm_lab/agent/algorithm/policy_util.py - About 30 mins to fix

        Function plot_multi_trial has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
        Open

        def plot_multi_trial(trial_metrics_path_list, legend_list, title, graph_prepath, ma=False, name_time_pairs=None, frame_scales=None, palette=None, showlegend=True):
            '''
            Plot multiple trial graphs together
            This method can be used in analysis and also custom plotting by specifying the arguments manually
            @example
        Severity: Minor
        Found in slm_lab/lib/viz.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 step has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
        Open

            def step(self, action):
                obs, reward, done, info = self.env.step(action)
                self.tracked_reward += reward
                # fix shape by inferring from reward
                if np.isscalar(self.total_reward) and not np.isscalar(reward):
        Severity: Minor
        Found in slm_lab/env/wrapper.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 init_global_nets has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
        Open

        def init_global_nets(algorithm):
            '''
            Initialize global_nets for Hogwild using an identical instance of an algorithm from an isolated Session
            in spec.meta.distributed, specify either:
            - 'shared': global network parameter is shared all the time. In this mode, algorithm local network will be replaced directly by global_net via overriding by identify attribute name
        Severity: Minor
        Found in slm_lab/agent/net/net_util.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 init_params has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
        Open

        def init_params(module, init_fn):
            '''Initialize module's weights using init_fn, and biases to 0.0'''
            bias_init = 0.0
            classname = util.get_class_name(module)
            if 'Net' in classname:  # skip if it's a net, not pytorch layer
        Severity: Minor
        Found in slm_lab/agent/net/net_util.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