Skip to main content
Glama

optimize_thrust_profile

Optimize rocket thrust profiles for improved trajectory performance by adjusting thrust segments to meet specific impulse targets and objectives.

Instructions

Optimize rocket thrust profile for better performance using trajectory optimization.

Args: rocket_geometry: Rocket geometry parameters burn_time_s: Burn time in seconds total_impulse_target: Target total impulse in N⋅s n_segments: Number of thrust segments objective: Optimization objective

Returns: JSON string with optimized thrust profile

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rocket_geometryYes
burn_time_sYes
total_impulse_targetYes
n_segmentsNo
objectiveNomax_altitude

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Import of the optimize_thrust_profile tool handler from tools/optimization.py
    from .tools.optimization import (
        genetic_algorithm_optimization,
        monte_carlo_uncertainty_analysis,
        optimize_thrust_profile,
        particle_swarm_optimization,
        porkchop_plot_analysis,
        trajectory_sensitivity_analysis,
    )
  • MCP registration of the optimize_thrust_profile tool handler
    mcp.tool(optimize_thrust_profile)
  • MCP tool handler: wrapper that converts inputs to RocketGeometry, delegates to trajopt implementation, formats results as JSON string
    def optimize_thrust_profile(
        rocket_geometry: dict,
        burn_time_s: float,
        total_impulse_target: float,
        n_segments: int = 5,
        objective: Literal[
            "max_altitude", "min_max_q", "min_gravity_loss"
        ] = "max_altitude",
    ) -> str:
        """Optimize rocket thrust profile for better performance using trajectory optimization.
    
        Args:
            rocket_geometry: Rocket geometry parameters
            burn_time_s: Burn time in seconds
            total_impulse_target: Target total impulse in N⋅s
            n_segments: Number of thrust segments
            objective: Optimization objective
    
        Returns:
            JSON string with optimized thrust profile
        """
        try:
            from ..integrations.trajopt import (
                RocketGeometry,
            )
            from ..integrations.trajopt import (
                optimize_thrust_profile as _optimize,
            )
    
            geometry = RocketGeometry(**rocket_geometry)
    
            result = _optimize(
                geometry, burn_time_s, total_impulse_target, n_segments, objective
            )
    
            return json.dumps(
                {
                    "optimization_result": result.optimization_result,
                    "optimal_objective": result.optimal_objective,
                    "optimal_parameters": result.optimal_parameters,
                    "performance": {
                        "max_altitude_m": result.performance.max_altitude_m,
                        "max_velocity_ms": result.performance.max_velocity_ms,
                        "total_impulse_ns": result.performance.total_impulse_ns,
                        "apogee_time_s": result.performance.apogee_time_s,
                    },
                },
                indent=2,
            )
    
        except ImportError:
            return "Trajectory optimization not available - install optimization packages"
        except Exception as e:
            logger.error(f"Thrust profile optimization error: {str(e)}", exc_info=True)
            return f"Thrust profile optimization error: {str(e)}"
  • Core helper implementation: optimizes thrust multipliers using simple gradient descent, normalizes thrust curve to target impulse, simulates trajectory with rocket_3dof_trajectory, returns structured TrajectoryOptimizationResult
    def optimize_thrust_profile(
        geometry: RocketGeometry,
        burn_time_s: float,
        total_impulse_target: float,
        n_segments: int = 5,
        objective: str = "max_altitude",
    ) -> TrajectoryOptimizationResult:
        """
        Optimize thrust profile for better performance.
    
        Args:
            geometry: Base rocket geometry
            burn_time_s: Total burn time
            total_impulse_target: Target total impulse
            n_segments: Number of thrust profile segments
            objective: "max_altitude", "min_max_q", or "min_gravity_loss"
    
        Returns:
            Optimization result
        """
        # Create initial thrust profile (constant thrust)
        avg_thrust = total_impulse_target / burn_time_s
        segment_time = burn_time_s / n_segments
    
        # Initial parameters: thrust multipliers for each segment
        initial_multipliers = [1.0] * n_segments
        multiplier_bounds = [(0.1, 3.0)] * n_segments  # 10% to 300% of average
    
        def objective_function(multipliers: list[float]) -> float:
            """Objective function for thrust profile optimization."""
            try:
                # Create thrust curve from multipliers
                thrust_curve = []
                for i, mult in enumerate(multipliers):
                    time_start = i * segment_time
                    time_end = (i + 1) * segment_time
                    thrust_level = avg_thrust * mult
                    thrust_curve.append([time_start, thrust_level])
                    if i == len(multipliers) - 1:  # Last segment
                        thrust_curve.append([time_end, 0.0])  # End thrust
    
                # Normalize to maintain total impulse
                current_impulse = sum(
                    avg_thrust * mult * segment_time for mult in multipliers
                )
                if current_impulse <= 0:
                    return float("inf")
    
                scale_factor = total_impulse_target / current_impulse
                thrust_curve = [[t, thrust * scale_factor] for t, thrust in thrust_curve]
    
                # Update geometry with new thrust curve
                opt_geometry = RocketGeometry(
                    dry_mass_kg=geometry.dry_mass_kg,
                    propellant_mass_kg=geometry.propellant_mass_kg,
                    diameter_m=geometry.diameter_m,
                    length_m=geometry.length_m,
                    cd=geometry.cd,
                    thrust_curve=thrust_curve,
                )
    
                # Run trajectory simulation with reasonable parameters
                trajectory = rocket_3dof_trajectory(
                    opt_geometry, dt_s=0.2, max_time_s=150.0
                )
                if not trajectory:
                    return 1e6  # Large penalty instead of inf
    
                performance = analyze_rocket_performance(trajectory)
    
                if objective == "max_altitude":
                    # Return negative altitude for minimization, but ensure it's not zero
                    result = -max(
                        1.0, performance.max_altitude_m
                    )  # At least -1 to avoid zero
                    return result
                elif objective == "min_max_q":
                    return performance.max_q_pa
                elif objective == "min_gravity_loss":
                    # Estimate gravity loss (simplified)
                    gravity_loss = 9.80665 * performance.burnout_time_s
                    return gravity_loss
                else:
                    return 1e6
    
            except Exception:
                return 1e6  # Large penalty for failed cases
    
        # Optimize using gradient descent
        optimal_multipliers, optimal_value, iterations, converged = simple_gradient_descent(
            objective_function,
            initial_multipliers,
            multiplier_bounds,
            learning_rate=0.05,
            tolerance=1e-3,
            max_iterations=100,
        )
    
        # Generate final thrust curve and trajectory
        final_thrust_curve = []
        for i, mult in enumerate(optimal_multipliers):
            time_start = i * segment_time
            time_end = (i + 1) * segment_time
            thrust_level = avg_thrust * mult
            final_thrust_curve.append([time_start, thrust_level])
            if i == len(optimal_multipliers) - 1:
                final_thrust_curve.append([time_end, 0.0])
    
        # Normalize final curve
        current_impulse = sum(
            avg_thrust * mult * segment_time for mult in optimal_multipliers
        )
        scale_factor = total_impulse_target / current_impulse
        final_thrust_curve = [
            [t, thrust * scale_factor] for t, thrust in final_thrust_curve
        ]
    
        # Generate final trajectory
        final_geometry = RocketGeometry(
            dry_mass_kg=geometry.dry_mass_kg,
            propellant_mass_kg=geometry.propellant_mass_kg,
            diameter_m=geometry.diameter_m,
            length_m=geometry.length_m,
            cd=geometry.cd,
            thrust_curve=final_thrust_curve,
        )
    
        final_trajectory = rocket_3dof_trajectory(final_geometry)
        final_performance = analyze_rocket_performance(final_trajectory)
    
        # Prepare optimal parameters
        optimal_params = {
            f"thrust_mult_seg_{i + 1}": mult for i, mult in enumerate(optimal_multipliers)
        }
        optimal_params["thrust_curve"] = final_thrust_curve
    
        return TrajectoryOptimizationResult(
            optimal_parameters=optimal_params,
            optimal_objective=(
                -optimal_value if objective == "max_altitude" else optimal_value
            ),
            iterations=iterations,
            converged=converged,
            trajectory_points=final_trajectory,
            performance=final_performance,
        )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'optimize' and 'trajectory optimization', implying a computational process, but doesn't describe what 'optimize' entails (e.g., iterative calculations, potential runtime, or accuracy). It also doesn't cover error handling, performance characteristics, or whether this is a read-only or mutating operation, which is critical for a tool with complex inputs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with the core purpose stated first, followed by a structured 'Args' and 'Returns' section. However, the 'Args' section could be more concise by integrating explanations into the main text, and the repetition of 'Optimize' in the first sentence is slightly redundant.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (5 parameters, nested objects, no annotations) and the presence of an output schema (implied by 'Returns: JSON string'), the description is moderately complete. It covers inputs and output format but lacks behavioral details and usage guidelines. The output schema reduces the need to explain return values, but more context on the optimization process is needed for full understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It lists all parameters in the 'Args' section but only provides minimal semantic context (e.g., 'Burn time in seconds'). It doesn't explain the structure of 'rocket_geometry' or the meaning of 'n_segments' and 'objective' beyond their names, leaving gaps that the schema's titles and enums partially fill but not fully.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Optimize rocket thrust profile for better performance using trajectory optimization.' It specifies the verb ('optimize'), resource ('rocket thrust profile'), and method ('trajectory optimization'), making it distinct from most siblings like 'optimize_launch_angle' or 'rocket_3dof_trajectory'. However, it doesn't explicitly differentiate from 'genetic_algorithm_optimization' or 'particle_swarm_optimization', which might also involve optimization techniques.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, such as needing rocket geometry data, or compare it to sibling tools like 'optimize_launch_angle' or 'trajectory_sensitivity_analysis'. The lack of context leaves the agent to infer usage based on the name and parameters alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cheesejaguar/aerospace-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server