kengz/SLM-Lab

View on GitHub

Showing 12 of 37 total issues

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 plot_go has 17 arguments (exceeds 10 allowed). Consider refactoring.
Open

def plot_go(
Severity: Major
Found in slm_lab/lib/viz.py - About 1 hr to fix

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

        def run(self):
            run_trial = create_remote_fn(self.experiment)
            meta_spec = self.experiment.spec['meta']
            ray.init(**meta_spec.get('resources', {}))
            register_ray_serializer()
    Severity: Minor
    Found in slm_lab/experiment/search.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 retro_eval has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
    Open

    def retro_eval(predir, session_index=None):
        '''
        Method to run eval sessions by scanning a predir for ckpt files. Used to rerun failed eval sessions.
        @example
    
    
    Severity: Minor
    Found in slm_lab/experiment/retro_analysis.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 gen_assert_trained has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
    Open

    def gen_assert_trained(pre_model):
        '''
        Generate assert_trained function used to check weight updates
        @example
    
    
    Severity: Minor
    Found in slm_lab/agent/net/net_util.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 try_ckpt has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
    Open

        def try_ckpt(self, agent, env):
            '''Try to checkpoint agent at the start, save_freq, and the end'''
            tick = env.clock.get(env.max_tick_unit)
            to_ckpt = False
            if not util.in_eval_lab_modes() and tick <= env.max_tick:
    Severity: Minor
    Found in slm_lab/experiment/control.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 normalize_state has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
    Open

    def normalize_state(body, state):
        '''
        Normalizes one or more states using a running mean and standard deviation
        Details of the normalization from Deep RL Bootcamp, L6
        https://www.youtube.com/watch?v=8EcdaCk9KaQ&feature=youtu.be
    Severity: Minor
    Found in slm_lab/agent/algorithm/policy_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

    Function get_policy_out_dim has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
    Open

    def get_policy_out_dim(body):
        '''Helper method to construct the policy network out_dim for a body according to is_discrete, action_type'''
        action_dim = body.action_dim
        if body.is_discrete:
            if body.action_type == 'multi_discrete':
    Severity: Minor
    Found in slm_lab/agent/net/net_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/experiment/monitor.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return np.clip((state - body.state_mean) / body.state_std_dev, -10, 10)
      Severity: Major
      Found in slm_lab/agent/algorithm/policy_util.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return np.clip(state - body.state_mean, -10, 10)
        Severity: Major
        Found in slm_lab/agent/algorithm/policy_util.py - About 30 mins to fix

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

              def space_train(self):
                  '''
                  Completes one training step for the agent if it is time to train.
                  i.e. the environment timestep is greater than the minimum training timestep and a multiple of the training_frequency.
                  Each training step consists of sampling n batches from the agent's memory.
          Severity: Minor
          Found in slm_lab/agent/algorithm/hydra_dqn.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