takuseno/mvc-drl

View on GitHub

Showing 12 of 36 total issues

Cyclomatic complexity is too high in function log_parameters. (7)
Open

def log_parameters(hyper_params):
    assert isinstance(hyper_params, dict)
    assert SETTING['experiment_name'] is not None
    if SETTING['disable']:
        return
Severity: Minor
Found in mvc/logger/__init__.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in function log_metric. (7)
Open

def log_metric(name, metric, step):
    assert isinstance(name, str)
    assert isinstance(step, int)
    assert SETTING['experiment_name'] is not None
    if SETTING['disable']:
Severity: Minor
Found in mvc/logger/__init__.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in function q_function. (6)
Open

def q_function(fcs,
               inpt,
               action,
               concat_index,
               activation=tf.nn.tanh,
Severity: Minor
Found in mvc/parametric_function.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function loop has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def loop(env, view, hook=None):
    while True:
        obs, reward, done, info = env.reset(), 0.0, False, {}
        while not done:
            obs, reward, done, info = step(env, view, obs, reward, done, info)
Severity: Minor
Found in mvc/interaction.py - About 55 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 main has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def main(args):
    sns.set()
    for i, path in enumerate(args.path):
        steps, values = load_csv(path)
        if args.label is None:
Severity: Minor
Found in tools/plot_csv.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 interact has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

def interact(env, view, eval_env=None, eval_view=None, hook=None, batch=False):
    _loop = batch_loop if batch else loop

    def _hook(view):
        if eval_view is not None and view.should_eval():
Severity: Minor
Found in mvc/interaction.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

Method "__init__" has 11 parameters, which is greater than the 7 authorized.
Open

    def __init__(self,
                 network,
                 buffer,
                 metrics,
                 noise,
Severity: Major
Found in mvc/controllers/ddpg.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

Function "q_function" has 9 parameters, which is greater than the 7 authorized.
Open

def q_function(fcs,
               inpt,
               action,
               concat_index,
               activation=tf.nn.tanh,
Severity: Major
Found in mvc/parametric_function.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

Method "__init__" has 14 parameters, which is greater than the 7 authorized.
Open

    def __init__(self,
                 network,
                 rollout,
                 metrics,
                 num_envs,
Severity: Major
Found in mvc/controllers/ppo.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

Rename field "metrics"
Open

        self.metrics = {}
Severity: Major
Found in mvc/models/metrics/metrics.py by sonar-python

It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.

Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.

Noncompliant Code Example

class Foo:
  foo = ''

  def getFoo(self):
    ...

foo = Foo()
foo.getFoo() # what does this return?

Compliant Solution

class Foo:
  name = ''

  def getName(self):
    ...

foo = Foo()
foo.getName()

Function "stochastic_policy_function" has 9 parameters, which is greater than the 7 authorized.
Open

def stochastic_policy_function(fcs,
                               inpt,
                               num_actions,
                               activation=tf.nn.tanh,
                               share=False,
Severity: Major
Found in mvc/parametric_function.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

Function "deterministic_policy_function" has 8 parameters, which is greater than the 7 authorized.
Open

def deterministic_policy_function(fcs,
                                  inpt,
                                  num_actions,
                                  activation=tf.nn.tanh,
                                  w_init=None,
Severity: Major
Found in mvc/parametric_function.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...
Severity
Category
Status
Source
Language