OpenJij/OpenJij

View on GitHub

Showing 464 of 464 total issues

Refactor this function to reduce its Cognitive Complexity from 48 to the 15 allowed.
Open

def make_BinaryPolynomialModel_from_hubo(*args, **kwargs):
Severity: Critical
Found in openjij/model/model.py by sonar-python

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Refactor this function to reduce its Cognitive Complexity from 66 to the 15 allowed.
Open

def BinaryPolynomialModel(*args, **kwargs):
Severity: Critical
Found in openjij/model/model.py by sonar-python

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Rename function "_BinaryPolynomialModel_from_list" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def _BinaryPolynomialModel_from_list(keys: list, values: list, vartype):
Severity: Major
Found in openjij/model/model.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Rename function "make_BinaryPolynomialModel_from_hising" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def make_BinaryPolynomialModel_from_hising(*args, **kwargs):
Severity: Major
Found in openjij/model/model.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Rename function "KingGraph" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def KingGraph(
Severity: Major
Found in openjij/model/king_graph.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Rename function "make_BinaryPolynomialModel_from_hubo" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def make_BinaryPolynomialModel_from_hubo(*args, **kwargs):
Severity: Major
Found in openjij/model/model.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Method "_cxxjij_sampling" has 8 parameters, which is greater than the 7 authorized.
Open

        self,
        model,
        init_generator,
        algorithm,
        system,
Severity: Major
Found in openjij/sampler/sampler.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 "_sample_hubo_old" has 12 parameters, which is greater than the 7 authorized.
Open

        self,
        J: Union[
            dict, "openj.model.model.BinaryPolynomialModel", cimod.BinaryPolynomialModel
        ],
        vartype: Optional[str] = None,
Severity: Major
Found in openjij/sampler/sa_sampler.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):
    ...

Either merge this branch with the identical one on line "375" or change one of the implementations.
Open

            if vartype is not None:
                raise ValueError("vartype must not be specified")
            model = J
Severity: Major
Found in openjij/sampler/sa_sampler.py by sonar-python

Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

Noncompliant Code Example

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_thing()  # Noncompliant; duplicates first condition
else:
    do_the_rest()

b = 4 if a > 12 else 4

Compliant Solution

if (0 <= a < 10) or (20 <= a < 50):
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
else:
    do_the_rest()

b = 4

or

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_third_thing()
else:
    do_the_rest()

b = 8 if a > 12 else 4

Rename function "ChimeraModel" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def ChimeraModel(
Severity: Major
Found in openjij/model/chimera_model.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Rename function "make_KingGraph_from_JSON" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def make_KingGraph_from_JSON(obj):
Severity: Major
Found in openjij/model/king_graph.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Refactor this function to reduce its Cognitive Complexity from 24 to the 15 allowed.
Open

    def sample(
Severity: Critical
Found in openjij/sampler/sqa_sampler.py by sonar-python

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Either merge this branch with the identical one on line "313" or change one of the implementations.
Open

            raise TypeError("Invalid argument for this function")
Severity: Major
Found in openjij/model/model.py by sonar-python

Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

Noncompliant Code Example

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_thing()  # Noncompliant; duplicates first condition
else:
    do_the_rest()

b = 4 if a > 12 else 4

Compliant Solution

if (0 <= a < 10) or (20 <= a < 50):
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
else:
    do_the_rest()

b = 4

or

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_third_thing()
else:
    do_the_rest()

b = 8 if a > 12 else 4

Method "sample" has 13 parameters, which is greater than the 7 authorized.
Open

        self,
        bqm: Union[
            "openjij.model.model.BinaryQuadraticModel", dimod.BinaryQuadraticModel
        ],
        beta: Optional[float] = None,
Severity: Major
Found in openjij/sampler/sqa_sampler.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 function "_make_BinaryPolynomialModel_from_hising_from_list" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def _make_BinaryPolynomialModel_from_hising_from_list(keys: list, values: list):
Severity: Major
Found in openjij/model/model.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Method "sample_ising" has 12 parameters, which is greater than the 7 authorized.
Open

        self,
        h,
        J,
        beta=None,
        gamma=None,

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):
    ...

Either merge this branch with the identical one on line "186" or change one of the implementations.
Open

                raise TypeError(
                    f"Offset or vartype is configured incorrectly. Vartype must be set."
                )
Severity: Major
Found in openjij/model/model.py by sonar-python

Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

Noncompliant Code Example

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_thing()  # Noncompliant; duplicates first condition
else:
    do_the_rest()

b = 4 if a > 12 else 4

Compliant Solution

if (0 <= a < 10) or (20 <= a < 50):
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
else:
    do_the_rest()

b = 4

or

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_third_thing()
else:
    do_the_rest()

b = 8 if a > 12 else 4

Either merge this branch with the identical one on line "500" or change one of the implementations.
Open

            raise TypeError("Invalid argument for this function")
Severity: Major
Found in openjij/model/model.py by sonar-python

Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

Noncompliant Code Example

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_thing()  # Noncompliant; duplicates first condition
else:
    do_the_rest()

b = 4 if a > 12 else 4

Compliant Solution

if (0 <= a < 10) or (20 <= a < 50):
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
else:
    do_the_rest()

b = 4

or

if 0 <= a < 10:
    do_the_thing()
elif 10 <= a < 20:
    do_the_other_thing()
elif 20 <= a < 50:
    do_the_third_thing()
else:
    do_the_rest()

b = 8 if a > 12 else 4

Rename function "make_KingGraph" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def make_KingGraph(linear=None, quadratic=None, king_graph=None):
Severity: Major
Found in openjij/model/king_graph.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Refactor this function to reduce its Cognitive Complexity from 39 to the 15 allowed.
Open

    def _sample_hubo_old(
Severity: Critical
Found in openjij/sampler/sa_sampler.py by sonar-python

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Severity
Category
Status
Source
Language