OpenJij/cimod

View on GitHub

Showing 34 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

    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

    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

        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

        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

          Consider simplifying this complex logical expression.
          Open

                  if "keys" in kwargs and "values" in kwargs and "vartype" in kwargs:
                      key_condition = isinstance(kwargs["keys"], list) or isinstance(
                          kwargs["keys"], tuple
                      )
                      val_condition = isinstance(kwargs["values"], list) or isinstance(
          Severity: Critical
          Found in cimod/model/binary_polynomial_model.py - About 1 hr to fix

            Function from_numpy_matrix has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    def from_numpy_matrix(
            Severity: Minor
            Found in cimod/model/binary_quadratic_model.py - About 45 mins to fix

              Function _make_BinaryPolynomialModel_from_hubo_from_list has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def _make_BinaryPolynomialModel_from_hubo_from_list(keys: list, values: list):
                  if len(keys) == 0:
                      return make_BinaryPolynomialModel({}).from_hubo(keys, values)
              
                  i = 0
              Severity: Minor
              Found in cimod/model/binary_polynomial_model.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 get_state_and_energy has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def get_state_and_energy(
                  model, result_state, offset=0, model_variables=[]
              ) -> tuple[dict, float]:
                  """get converted state and energy.
                  This function receives raw array of spins or binaries.
              Severity: Minor
              Found in cimod/utils/response.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 _make_BinaryPolynomialModel_from_hising_from_list has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def _make_BinaryPolynomialModel_from_hising_from_list(keys: list, values: list):
                  if len(keys) == 0:
                      return make_BinaryPolynomialModel({}).from_hising(keys, values)
              
                  i = 0
              Severity: Minor
              Found in cimod/model/binary_polynomial_model.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 _BinaryPolynomialModel_from_list has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def _BinaryPolynomialModel_from_list(keys: list, values: list, vartype):
                  if len(keys) == 0:
                      Model = make_BinaryPolynomialModel({})
                      return Model(keys, values, to_cxxcimod(vartype))
                  i = 0
              Severity: Minor
              Found in cimod/model/binary_polynomial_model.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

              Consider simplifying this complex logical expression.
              Open

                      if "keys" in kwargs and "values" in kwargs:
                          key_condition = isinstance(kwargs["keys"], list) or isinstance(
                              kwargs["keys"], tuple
                          )
                          val_condition = isinstance(kwargs["values"], list) or isinstance(
              Severity: Major
              Found in cimod/model/binary_polynomial_model.py - About 40 mins to fix

                Consider simplifying this complex logical expression.
                Open

                        if "keys" in kwargs and "values" in kwargs:
                            key_condition = isinstance(kwargs["keys"], list) or isinstance(
                                kwargs["keys"], tuple
                            )
                            val_condition = isinstance(kwargs["values"], list) or isinstance(
                Severity: Major
                Found in cimod/model/binary_polynomial_model.py - About 40 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language