q-optimize/c3

View on GitHub
c3/optimizers/modellearning.py

Summary

Maintainability
C
1 day
Test Coverage

Consider possible security implications associated with pickle module.
Open

import pickle
Severity: Info
Found in c3/optimizers/modellearning.py by bandit

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
Open

                self.learn_data[target] = pickle.load(file)
Severity: Minor
Found in c3/optimizers/modellearning.py by bandit

File modellearning.py has 385 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Object that deals with the model learning."""

import os
import time
import pickle
Severity: Minor
Found in c3/optimizers/modellearning.py - About 5 hrs to fix

    Cyclomatic complexity is too high in method __init__. (11)
    Open

        def __init__(
            self,
            sampling,
            batch_sizes,
            pmap,
    Severity: Minor
    Found in c3/optimizers/modellearning.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 method goal_run_with_grad. (9)
    Open

        def goal_run_with_grad(self, current_params):
            """
            Same as goal_run but with gradient. Very resource intensive. Unoptimized at the
            moment.
            """
    Severity: Minor
    Found in c3/optimizers/modellearning.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 method goal_run. (8)
    Open

        def goal_run(self, current_params: tf.constant) -> tf.float64:
            """
            Evaluate the figure of merit for the current model parameters.
    
            Parameters
    Severity: Minor
    Found in c3/optimizers/modellearning.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 __init__ has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(
            self,
            sampling,
            batch_sizes,
            pmap,
    Severity: Minor
    Found in c3/optimizers/modellearning.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__ has 13 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Major
    Found in c3/optimizers/modellearning.py - About 1 hr to fix

      Function goal_run_with_grad has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def goal_run_with_grad(self, current_params):
              """
              Same as goal_run but with gradient. Very resource intensive. Unoptimized at the
              moment.
              """
      Severity: Minor
      Found in c3/optimizers/modellearning.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 goal_run has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def goal_run(self, current_params: tf.constant) -> tf.float64:
              """
              Evaluate the figure of merit for the current model parameters.
      
              Parameters
      Severity: Minor
      Found in c3/optimizers/modellearning.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_one_dataset has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def _log_one_dataset(
      Severity: Minor
      Found in c3/optimizers/modellearning.py - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status