OpenJij/cimod

View on GitHub

Showing 247 of 247 total issues

Function make_BinaryPolynomialModel has a Cognitive Complexity of 221 (exceeds 5 allowed). Consider refactoring.
Open

def make_BinaryPolynomialModel(polynomial, index_type=None, tuple_size=0):
    """BinaryPolynomialModel factory.
       Generate BinaryPolynomialModel class with the base class specified by the arguments linear and quadratic
    Args:
        polynomial (dict): polynomial bias including linear bias
Severity: Minor
Found in cimod/model/binary_polynomial_model.py - About 4 days 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

File binary_polynomial_model.py has 659 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2022 Jij Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in cimod/model/binary_polynomial_model.py - About 1 day to fix

    Function make_BinaryQuadraticModel has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
    Open

    def make_BinaryQuadraticModel(linear, quadratic):
        """BinaryQuadraticModel factory.
           Generate BinaryQuadraticModel class with the base class specified by the arguments linear and quadratic
        Args:
            linear (dict): linear bias
    Severity: Minor
    Found in cimod/model/legacy/binary_quadratic_model.py - About 1 day 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 BinaryPolynomialModel has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
    Open

    def BinaryPolynomialModel(*args, **kwargs):
        if kwargs == {}:
            if len(args) <= 1:
                raise TypeError("Invalid argument for this function")
            elif len(args) == 2:
    Severity: Minor
    Found in cimod/model/binary_polynomial_model.py - About 1 day 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_BinaryQuadraticModel has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
    Open

    def make_BinaryQuadraticModel(linear, quadratic, sparse):
        """BinaryQuadraticModel factory.
           Generate BinaryQuadraticModel class with the base class specified by the arguments linear and quadratic
        Args:
            linear (dict): linear bias
    Severity: Minor
    Found in cimod/model/binary_quadratic_model.py - About 7 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 make_BinaryPolynomialModel_from_hubo has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

    def make_BinaryPolynomialModel_from_hubo(*args, **kwargs):
        if kwargs == {}:
            if len(args) == 0:
                raise TypeError("Invalid argument for this function")
            elif len(args) == 1:
    Severity: Minor
    Found in cimod/model/binary_polynomial_model.py - About 6 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 make_BinaryPolynomialModel_from_hising has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

    def make_BinaryPolynomialModel_from_hising(*args, **kwargs):
        if kwargs == {}:
            if len(args) == 0:
                raise TypeError("Invalid argument for this function")
            elif len(args) == 1:
    Severity: Minor
    Found in cimod/model/binary_polynomial_model.py - About 6 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

    Cyclomatic complexity is too high in function BinaryPolynomialModel. (35)
    Open

    def BinaryPolynomialModel(*args, **kwargs):
        if kwargs == {}:
            if len(args) <= 1:
                raise TypeError("Invalid argument for this function")
            elif len(args) == 2:

    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 make_BinaryPolynomialModel_from_hubo. (25)
    Open

    def make_BinaryPolynomialModel_from_hubo(*args, **kwargs):
        if kwargs == {}:
            if len(args) == 0:
                raise TypeError("Invalid argument for this function")
            elif len(args) == 1:

    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 make_BinaryPolynomialModel_from_hising. (25)
    Open

    def make_BinaryPolynomialModel_from_hising(*args, **kwargs):
        if kwargs == {}:
            if len(args) == 0:
                raise TypeError("Invalid argument for this function")
            elif len(args) == 1:

    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 get_cxxcimod_class has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_cxxcimod_class(linear, quadratic, sparse):
        # select base class
        index = set()
        base = None
    
    
    Severity: Minor
    Found in cimod/model/binary_quadratic_model.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

    Cyclomatic complexity is too high in function get_cxxcimod_class. (18)
    Open

    def get_cxxcimod_class(linear, quadratic, sparse):
        # select base class
        index = set()
        base = None
    
    
    Severity: Minor
    Found in cimod/model/binary_quadratic_model.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

    File binary_quadratic_model.py has 319 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    # Copyright 2022 Jij Inc.
    
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    Severity: Minor
    Found in cimod/model/binary_quadratic_model.py - About 3 hrs to fix

      File binary_quadratic_model.py has 299 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      # Copyright 2022 Jij Inc.
      
      # Licensed under the Apache License, Version 2.0 (the "License");
      # you may not use this file except in compliance with the License.
      # You may obtain a copy of the License at
      Severity: Minor
      Found in cimod/model/legacy/binary_quadratic_model.py - About 3 hrs to fix

        Cyclomatic complexity is too high in function extract_offset_and_vartype. (13)
        Open

        def extract_offset_and_vartype(*args, **kwargs):
            if kwargs == {}:
                if len(args) == 0:
                    raise TypeError(
                        f"Offset or vartype is configured incorrectly. Vartype must be set."
        Severity: Minor
        Found in cimod/model/binary_quadratic_model.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 extract_offset_and_vartype has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

        def extract_offset_and_vartype(*args, **kwargs):
            if kwargs == {}:
                if len(args) == 0:
                    raise TypeError(
                        f"Offset or vartype is configured incorrectly. Vartype must be set."
        Severity: Minor
        Found in cimod/model/binary_quadratic_model.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

        Cyclomatic complexity is too high in function make_BinaryPolynomialModel. (12)
        Open

        def make_BinaryPolynomialModel(polynomial, index_type=None, tuple_size=0):
            """BinaryPolynomialModel factory.
               Generate BinaryPolynomialModel class with the base class specified by the arguments linear and quadratic
            Args:
                polynomial (dict): polynomial bias including linear bias

        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

        Consider simplifying this complex logical expression.
        Open

                        if "keys" in kwargs and "values" in kwargs and "vartype" in kwargs:
                            if len(args) != 0:
                                raise TypeError("Invalid argument for this function")
                            super().add_interactions_from(
                                kwargs["keys"], kwargs["values"], to_cxxcimod(kwargs["vartype"])
        Severity: Critical
        Found in cimod/model/binary_polynomial_model.py - About 2 hrs to fix

          Cyclomatic complexity is too high in function make_BinaryQuadraticModel. (11)
          Open

          def make_BinaryQuadraticModel(linear, quadratic):
              """BinaryQuadraticModel factory.
                 Generate BinaryQuadraticModel class with the base class specified by the arguments linear and quadratic
              Args:
                  linear (dict): linear bias

          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 make_BinaryPolynomialModel_from_JSON. (7)
          Open

          def make_BinaryPolynomialModel_from_JSON(obj):
              if obj["type"] != "BinaryPolynomialModel":
                  raise Exception('Type must be "BinaryPolynomialModel"')
              mock_polynomial = {}
              if obj["index_type"] == "IndexType.INT":

          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

          Severity
          Category
          Status
          Source
          Language