SimonBlanke/Gradient-Free-Optimizers

View on GitHub

Showing 44 of 46 total issues

Identical blocks of code found in 3 locations. Consider refactoring.
Open

def set_random_seed(nth_process, random_state):
    """
    Sets the random seed separately for each thread
    (to avoid getting the same results in each thread)
    """
Severity: Major
Found in gradient_free_optimizers/utils.py and 2 other locations - About 6 hrs to fix
gradient_free_optimizers/optimizers/base_optimizer.py on lines 16..28
gradient_free_optimizers/search.py on lines 20..32

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 101.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 3 locations. Consider refactoring.
Open

def set_random_seed(nth_process, random_state):
    """
    Sets the random seed separately for each thread
    (to avoid getting the same results in each thread)
    """
Severity: Major
Found in gradient_free_optimizers/optimizers/base_optimizer.py and 2 other locations - About 6 hrs to fix
gradient_free_optimizers/search.py on lines 20..32
gradient_free_optimizers/utils.py on lines 9..21

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 101.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 3 locations. Consider refactoring.
Open

def set_random_seed(nth_process, random_state):
    """
    Sets the random seed separately for each thread
    (to avoid getting the same results in each thread)
    """
Severity: Major
Found in gradient_free_optimizers/search.py and 2 other locations - About 6 hrs to fix
gradient_free_optimizers/optimizers/base_optimizer.py on lines 16..28
gradient_free_optimizers/utils.py on lines 9..21

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 101.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function evaluate has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def evaluate(self, score_new):
        self.score_new = score_new

        if self.simplex_step != 0:
            self.prev_pos = self.positions_valid[-1]
Severity: Minor
Found in gradient_free_optimizers/optimizers/local_opt/downhill_simplex.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

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        for para in paras:
            dim = len(list(search_space[para]))
            if dim == 1:
                continue
            space_dims[para] = dim
gradient_free_optimizers/optimizers/exp_opt/_sub_search_spaces.py on lines 68..72

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 47.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        for para in paras:
            dim = len(list(search_space[para]))
            if dim == 1:
                continue
            space_dims[para] = dim
gradient_free_optimizers/optimizers/exp_opt/_sub_search_spaces.py on lines 94..98

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 47.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function _slice_dim has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def _slice_dim(self, search_space, para_slice, max_size):
        search_space_size = get_search_space_size(search_space)

        paras = list(search_space.keys())
        space_dims = {}
Severity: Minor
Found in gradient_free_optimizers/optimizers/exp_opt/_sub_search_spaces.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 search has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def search(
        self,
        objective_function,
        n_iter,
        max_time=None,
Severity: Minor
Found in gradient_free_optimizers/search.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 decrease_ss_reso has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def decrease_ss_reso(
        self, search_space, para_list=None, min_dim_size=20, margin=5, n_samples=20
    ):
        search_space_reso = {}
        # para_list = None

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

    def _slice_search_space(self, search_space, max_size):
        search_space_size = get_search_space_size(search_space)

        if search_space_size <= max_size:
            return [search_space]
Severity: Minor
Found in gradient_free_optimizers/optimizers/exp_opt/_sub_search_spaces.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 9 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def __init__(
Severity: Major
Found in gradient_free_optimizers/optimizers/smb_opt/forest_optimizer.py - About 1 hr to fix

    Function search has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def search(
    Severity: Major
    Found in gradient_free_optimizers/search.py - About 1 hr to fix

      Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(

        Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Major
        Found in gradient_free_optimizers/optimizers/exp_opt/ensemble_optimizer.py - About 1 hr to fix

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

              def get_pos_space(self):
                  if self.max_sample_size < self.conv.search_space_size:
                      n_samples_array = self.get_n_samples_dims()
                      return self.random_choices(n_samples_array)
                  else:
          Severity: Minor
          Found in gradient_free_optimizers/optimizers/smb_opt/sampling.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 no_change has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def no_change(score_new_list, early_stopping):
              if "n_iter_no_change" not in early_stopping:
                  print(
                      "Warning n_iter_no_change-parameter must be set in order for early stopping to work"
                  )
          Severity: Minor
          Found in gradient_free_optimizers/stop_run.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 print_info has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def print_info(
          Severity: Major
          Found in gradient_free_optimizers/print_info.py - About 50 mins to fix

            Function __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __init__(

              Function __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def __init__(

                Function __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def __init__(
                Severity: Major
                Found in gradient_free_optimizers/optimizers/exp_opt/random_annealing.py - About 50 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language