SforAiDl/genrl

View on GitHub

Showing 58 of 58 total issues

File actor_critic.py has 393 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from typing import Tuple

import torch  # noqa
import torch.nn as nn  # noqa
from gym import spaces
Severity: Minor
Found in genrl/core/actor_critic.py - About 5 hrs to fix

    Function evolve has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def evolve(self, population):
            """
            Evolve the population of the network
    
            Args:
    Severity: Minor
    Found in genrl/evolutionary/genetic_hyperparam.py - About 3 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 train has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def train(self) -> List[float]:
            """
            general training loop for classical RL
            """
            timestep = 0
    Severity: Minor
    Found in genrl/trainers/classical.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

    Function train has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def train(self) -> None:
            """Main training method"""
            if self.load_weights is not None or self.load_hyperparams is not None:
                self.load()
    
    
    Severity: Minor
    Found in genrl/trainers/offpolicy.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

    Function tune_A2C has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def tune_A2C(trial):
        # Define hyperparameters that are relevant for training
        # Choose a suggestion type and range (float/int and log/uniform)
        lr_value = trial.suggest_float("lr_value", 1e-5, 1e-2, log=True)
        lr_policy = trial.suggest_float("lr_policy", 1e-5, 1e-2, log=True)
    Severity: Minor
    Found in examples/hyperparameters/optuna/a2c_cartpole-v0.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

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

        def evaluate(self, render: bool = False) -> None:
            """Evaluate performance of Agent
    
            Args:
                render (bool): Option to render the environment during evaluation
    Severity: Minor
    Found in genrl/trainers/base.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

    Function objective has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def objective(trial):
        lr_value = trial.suggest_float("lr_value", 1e-6, 1e-1, log=True)
        lr_policy = trial.suggest_float("lr_policy", 1e-6, 1e-1, log=True)
        replay_size = trial.suggest_int("replay_size", 1e2, 1e5, log=True)
        max_ep_len = trial.suggest_int("max_ep_len", 1e3, 50000, log=True)
    Severity: Minor
    Found in examples/hyperparameters/optuna/td3_pendulum-v0.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

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

        def __init__(
    Severity: Major
    Found in genrl/trainers/base.py - About 2 hrs to fix

      File vector_envs.py has 251 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import multiprocessing as mp
      from abc import ABC, abstractmethod
      from copy import deepcopy
      from typing import Any, Iterator, List, Tuple
      
      
      Severity: Minor
      Found in genrl/environments/vec_env/vector_envs.py - About 2 hrs to fix

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

            if parameter in agent_hyperparameters:
                exec("agent." + parameter + "=" + str(parameter_value))
            else:
                raise Exception("Hyperparameter key doesn't match")
        Severity: Major
        Found in genrl/evolutionary/utils.py and 1 other location - About 1 hr to fix
        genrl/evolutionary/utils.py on lines 71..74

        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 43.

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

            def train(self) -> None:
                """Main training method"""
                if self.load_weights is not None or self.load_hyperparams is not None:
                    self.load()
        
        
        Severity: Minor
        Found in genrl/trainers/onpolicy.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

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

                if key in agent_hyperparameters:
                    exec("rnd_agent." + key + "=" + str(value))
                else:
                    raise Exception("Hyperparameter key doesn't match")
        Severity: Major
        Found in genrl/evolutionary/utils.py and 1 other location - About 1 hr to fix
        genrl/evolutionary/utils.py on lines 43..46

        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 43.

        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 __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Major
        Found in genrl/agents/deep/base/base.py - About 1 hr to fix

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

              def __init__(
          Severity: Major
          Found in genrl/trainers/classical.py - About 1 hr to fix

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

                    if trainer.off_policy:
                        action = trainer.agent.select_action(state, deterministic=True)
                    else:
                        action, _, _ = trainer.agent.select_action(state)
            Severity: Major
            Found in examples/hyperparameters/optuna/a2c_cartpole-v0.py and 1 other location - About 1 hr to fix
            examples/hyperparameters/optuna/td3_pendulum-v0.py on lines 37..40

            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 41.

            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

                    if trainer.off_policy:
                        action = trainer.agent.select_action(state, deterministic=True)
                    else:
                        action, _, _ = trainer.agent.select_action(state)
            Severity: Major
            Found in examples/hyperparameters/optuna/td3_pendulum-v0.py and 1 other location - About 1 hr to fix
            examples/hyperparameters/optuna/a2c_cartpole-v0.py on lines 41..44

            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 41.

            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 run_experiment has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            def run_experiment(args):
                start_time = datetime.now
                print(f"\nStarting experiment at {start_time():%d-%m-%y %H:%M:%S}\n")
                results = {}
            
            
            Severity: Minor
            Found in examples/run_cb.py - About 1 hr to fix

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

                  def __init__(
              Severity: Major
              Found in genrl/core/actor_critic.py - About 1 hr to fix

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

                    def __init__(
                Severity: Major
                Found in genrl/core/actor_critic.py - About 1 hr to fix

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

                      def __init__(
                  Severity: Major
                  Found in genrl/trainers/offpolicy.py - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language