pyomeca/bioptim

View on GitHub

Showing 631 of 631 total issues

File variational_optimal_control_program.py has 471 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Optimal control program with the variational integrator for the dynamics.
"""

import numpy as np
Severity: Minor
Found in bioptim/optimization/variational_optimal_control_program.py - About 7 hrs to fix

    Function plot_results has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
    Open

    def plot_results(
        sol_socp,
        states,
        controls,
        time,

    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 non_linear_program.py has 450 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from typing import Callable, Any
    
    import casadi
    from casadi import SX, MX, vertcat
    
    
    Severity: Minor
    Found in bioptim/optimization/non_linear_program.py - About 6 hrs to fix

      File mapping.py has 448 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import numpy as np
      from casadi import MX, SX, DM
      
      from .options import OptionDict, OptionGeneric
      from .enums import Node
      Severity: Minor
      Found in bioptim/misc/mapping.py - About 6 hrs to fix

        File optimization_vector.py has 442 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import numpy as np
        from casadi import vertcat, DM, SX, MX
        
        from ..misc.enums import ControlType, InterpolationType
        
        
        Severity: Minor
        Found in bioptim/optimization/optimization_vector.py - About 6 hrs to fix

          ACADOS has 47 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class ACADOS(GenericSolver):
              """
              Class for Solver Options of ACADOS
          
              Methods
          Severity: Minor
          Found in bioptim/interfaces/acados_options.py - About 6 hrs to fix

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

            for i in range(2):
                axs[1, i].step(stepwise_time, stepwise_controls["tau"][i, :], label="Stepwise tau", where="post")
                axs[1, i].set_xlabel("Time [s]")
                axs[1, i].grid(True)
                axs[1, i].legend()
            Severity: Major
            Found in bioptim/examples/getting_started/how_to_plot.py and 1 other location - About 6 hrs to fix
            bioptim/examples/getting_started/how_to_plot.py on lines 38..42

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

            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

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

            for i in range(2):
                axs[0, i].step(decision_time, decision_controls["tau"][i, :], label="Decision tau", where="post")
                axs[0, i].set_xlabel("Time [s]")
                axs[0, i].grid(True)
                axs[0, i].legend()
            Severity: Major
            Found in bioptim/examples/getting_started/how_to_plot.py and 1 other location - About 6 hrs to fix
            bioptim/examples/getting_started/how_to_plot.py on lines 47..51

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

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

                    def define_parameters_phase_time(
                        ocp: OptimalControlProgram,
                        penalty_functions: ObjectiveList | ConstraintList,
                        _has_penalty: list = None,
                    ) -> list:
            Severity: Minor
            Found in bioptim/optimization/optimal_control_program.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 FatigueBounds has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
            Open

            def FatigueBounds(fatigue: FatigueList, variable_type=VariableType.STATES, fix_first_frame=False):
                """
                Parameters
                ----------
                fatigue: FatigueList
            Severity: Minor
            Found in bioptim/limits/fatigue_path_conditions.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 _dispatch_state_bounds has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
            Open

            def _dispatch_state_bounds(nlp, states, states_bounds, states_scaling, n_steps_callback):
                states.node_index = 0
                repeat = n_steps_callback(0)
            
                for key in states.keys():
            Severity: Minor
            Found in bioptim/optimization/optimization_vector.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 _dispatch_state_initial_guess has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
            Open

            def _dispatch_state_initial_guess(nlp, states, states_init, states_scaling, n_steps_callback):
                states.node_index = 0
                repeat = n_steps_callback(0)
            
                for key in states.keys():
            Severity: Minor
            Found in bioptim/optimization/optimization_vector.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 __init__ has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
            Open

                def __init__(
                    self,
                    nb_elements: int = None,
                    independent_indices: tuple[int, ...] = None,
                    dependencies: tuple[Dependency, ...] = None,
            Severity: Minor
            Found in bioptim/misc/mapping.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

            File holonomic_biorbd_model.py has 415 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            from typing import Callable
            
            import biorbd_casadi as biorbd
            from biorbd_casadi import (
                GeneralizedCoordinates,
            Severity: Minor
            Found in bioptim/models/biorbd/holonomic_biorbd_model.py - About 5 hrs to fix

              Function _check_arguments_and_build_nlp has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _check_arguments_and_build_nlp(
                      self,
                      dynamics,
                      objective_functions,
                      constraints,
              Severity: Minor
              Found in bioptim/optimization/optimal_control_program.py - About 5 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 _set_penalty_function has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _set_penalty_function(self, controllers: list[PenaltyController], fcn: MX | SX):
                      """
                      Finalize the preparation of the penalty (setting function and weighted_function)
              
                      Parameters
              Severity: Minor
              Found in bioptim/limits/penalty_option.py - About 5 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 _auto_initialize has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _auto_initialize(self, x_init, u_init, parameter_init, a_init):
                      def replace_initial_guess(key, n_var, var_init, a_init, i_phase):
                          if n_var != 0:
                              if key in a_init:
                                  a_init[key] = InitialGuess(var_init, interpolation=InterpolationType.EACH_FRAME, phase=i_phase)
              Severity: Minor
              Found in bioptim/optimization/stochastic_optimal_control_program.py - About 5 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 a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
              Open

                  def __init__(
                      self,
                      bio_model: VariationalBioModel,
                      n_shooting: int,
                      final_time: float,
              Severity: Minor
              Found in bioptim/optimization/variational_optimal_control_program.py - About 5 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 _compute_y_from_plot_func has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _compute_y_from_plot_func(
                      self, custom_plot: CustomPlot, phase_idx, time_stepwise, dt, x_decision, x_stepwise, u, p, a, d
                  ) -> list[np.ndarray | list]:
                      """
                      Compute the y data from the plot function
              Severity: Minor
              Found in bioptim/gui/plot.py - About 5 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_u has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _get_u(self, ocp, p_idx, n_idx, sn_idx):
                      nlp = ocp.nlp[p_idx]
                      controls = nlp.controls
                      controls.node_index = n_idx
              
              
              Severity: Minor
              Found in bioptim/limits/penalty_option.py - About 5 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

              Severity
              Category
              Status
              Source
              Language