kengz/SLM-Lab

View on GitHub

Showing 10 of 90 total issues

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

    def train(self):
        if util.in_eval_lab_modes():
            return np.nan
        clock = self.body.env.clock
        if self.to_train == 1:
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 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 init_nets has 27 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 make_gym_env has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      def make_gym_env(name, seed=None, frame_op=None, frame_op_len=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 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 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

      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 tick has a Cognitive Complexity of 11 (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 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