pykep Documentation

repository·master·Indexed 19 days ago

https://github.com/esa/pykep

A high-performance astrodynamics toolbox for space flight mechanics research, trajectory optimization, and mission design. Developed by the ESA Advanced Concepts Team, it consists of a C++ library (kep3) and a Python interface (pykep). It features tools for solving Lambert's problem, low-thrust and multiple asteroid rendezvous problems, and includes a Trajectory Optimization Gym with benchmarks for MGA and TOPS. Supports JPL SPICE, SGP4 propagation, and the Heyoka Taylor integration suite.

Tokens
15K
Snippets
39
Records
67
Agent score
65%

What's inside pykep

  1. Overview of pykep

    master

    pykep is a research toolbox developed by the European Space Agency (ESA) Advanced Concepts Team for fast prototyping of interplanetary trajectory design. It provides efficient implementations of algorithms for solving:

    • Multiple revolutions Lambert's problem
    • Low-thrust problems
    • Multiple asteroid rendezvous problems

    It also provides support for:

    • JPL SPICE
    • SGP4 propagation
    • Heyoka Taylor integration suite
  2. Overview of pykep for space flight mechanics

    master

    pykep is a Python research library designed for the preliminary analysis of interplanetary spacecraft trajectories. It is a research instrument for prototyping algorithms and conducting large-scale parametric studies, rather than an operational flight dynamics tool.

    Core Capabilities:

    • Orbit Propagation: Mathematical building blocks for propagating orbits.
    • Orbital Element Conversions: Tools for switching between different orbital representations.
    • Lambert Arc Solvers: Fast, multi-revolution solvers for transfer arcs.
    • Gravity-Assist Modelling: Tools for modeling flyby sequences.
    • Low-Thrust Transcription: Support for both direct (e.g., Sims-Flanagan, zero-order-hold) and indirect (Pontryagin-based) low-thrust models.
    • Optimization Integration: Native coupling with pagmo for global and multi-objective optimization.
    • High-Accuracy Propagation: Integration with Heyoka for Taylor-based integration.
    • Benchmarking: Includes a gym suite of benchmark problems based on Global Trajectory Optimization Competitions (GTOC).
  3. Use the Trajectory Optimization Gym for benchmarking

    master

    The pykep gym provides a collection of interplanetary trajectory optimization benchmarks as User Defined Problems (UDPs). These are compatible with pygmo and are designed to test both evolutionary and gradient-based optimization methods. All gym problems are instantiated automatically upon importing pykep and can be used directly.

    The gym is categorized into several problem types:

    • MGA (Multiple Gravity Assist): Based on planetary fly-by sequences (e.g., cassini1, rosetta, juice).
    • MGA-1DSM: MGA problems that allow one Deep Space Maneuver (DSM) per leg.
    • Multiple-Impulse: Earth-Moon transfer problems with a fixed number of impulses (e.g., em3imp, em5imp).
    • TOPS (Trajectory Optimisation Problems in Space): Low-thrust trajectory optimization problems available as JSON datasets or NLP transcriptions.
  4. What is kep3 and pykep?

    master

    kep3

    kep3 is a high-performance C++ library designed for space flight mechanics research. It provides rigorous numerics for tasks such as computing Lambert arcs, propagating Keplerian orbits, and designing multi-gravity-assist trajectories.

    pykep

    pykep is the Python package that provides a rich interface to the kep3 C++ library, making its astrodynamics tools accessible within a Python scientific workflow.

  5. Distinguish between Fixed and Moving Boundary TOPS problems

    master

    TOPS problems in the gym are categorized by how their boundary conditions are handled:

    Fixed Boundaries

    These instances have fixed initial/final states and, typically, fixed time-of-flight. They are recommended as an entry point for algorithm comparison.

    • Non-solar-sail variants use pykep.trajopt.zoh_point2point.
    • Solar-sail variants use pykep.trajopt.zoh_ss_point2point.
    • Examples: tops_twobody, tops_mee, tops_ss, tops_cr3bp.

    Moving Boundaries

    These formulations allow departure and arrival epochs to vary. Endpoint states are tied to pykep.planet ephemerides, and optional relative-velocity constraints are applied. This makes the optimization harder as boundary epochs become decision variables.

    • Non-solar-sail variants use pykep.trajopt.zoh_pl2pl.
    • Solar-sail variants use pykep.trajopt.zoh_ss_pl2pl.

    Note: Currently, only the fixed-boundary TOPS classes are exposed under pykep.trajopt.gym.

  6. Perform spacecraft trajectory optimization in pykep

    master

    Trajectory optimization in pykep is achieved through three main approaches:

    1. Direct Methods: These discretize the optimal control problem (OCP) into a Non-Linear Programming (NLP) problem by introducing a time grid. Most classes in this module are provided as User Defined Problems (UDP) compatible with the pygmo package.
    2. Indirect Methods: These are based on the Pontryagin Maximum Principle (PMP) and solve a two-point boundary value problem (TPBVP) to derive optimal control laws and state trajectories.
    3. Evolutionary Encodings: These provide classes designed for interplanetary trajectory design using genetic and evolutionary computation techniques.

    Most optimization problems are structured as NLPs that can be passed to pygmo solvers.

  7. Use evolutionary encodings for interplanetary trajectories

    master

    For trajectories amenable to genetic and evolutionary computation, pykep provides specialized encoding classes:

    • mga: Supports .pretty(), .plot(), and .to_planet() methods.
    • mga_1dsm: Supports .pretty() and .plot() methods.
    • pl2pl_N_impulses: Supports .pretty(), .plot(), and .plot_primer_vector() methods.
  8. Use basic orbital transfer models

    master

    For preliminary mission design phases where exact optimal transfer computations are too expensive, pykep provides basic ideal transfer models to establish bounds or assess the difficulty of specific orbital geometries. These functions serve as fast surrogates for complete computations.

    Available models include:

    • hohmann: Computes a Hohmann transfer.
    • bielliptic: Computes a bi-elliptic transfer.
  9. Select MGA time-of-flight encodings

    master

    When using MGA benchmarks, you can choose different time-of-flight (TOF) encodings depending on your optimization requirements:

    • Standard encoding: Used in base classes like cassini1 or eve_mga1dsm.
    • alpha encoding: Available in variants like cassini1_a or eve_mga1dsm_a. This introduces an additional decision variable for total TOF, making it ideal for multi-objective formulations where mission duration is an explicit objective or when per-leg TOF bounds are unknown.
    • eta encoding: Available in variants like cassini1_n or eve_mga1dsm_n. Similar to alpha, this is useful when direct per-leg TOF bounds are not available a priori.
  10. Estimate maximum initial mass (MIM) for low-thrust transfers

    master

    When computing low-thrust transfers between two arbitrary orbits with known start and arrival times, you can use Maximum Initial Mass (MIM) approximations to determine if a transfer is feasible. If a spacecraft's mass exceeds the calculated MIM, the transfer is considered infeasible.

    While neural methods and machine learning are often the most accurate ways to approximate MIM, pykep provides several analytical approximations for cases where precomputed trajectory databases are unavailable:

    • mima: Maximum Initial Mass Approximation.
    • mima2: An alternative MIMA implementation.
    • mim_from_hop: Computes MIM based on a Hohmann transfer baseline.
    • mima_from_hop: Computes MIMA based on a Hohmann transfer baseline.
    • mima2_from_hop: Computes MIMA2 based on a Hohmann transfer baseline.
  11. Use direct transcription methods (Sims-Flanagan and Zero-Order-Hold)

    master

    Direct methods transform infinite-dimensional control problems into finite-dimensional NLP problems via discretization.

    Sims-Flanagan Transcription

    Historical transcription methods based on the Sims approach. Available classes:

    • sf_point2point
    • sf_pl2pl
    • sf_pl2pl_alpha

    Zero-Order-Hold (ZOH) Transcription

    A high-fidelity extension of the Sims-Flanagan model that substitutes impulses with constant control segments. Available classes:

    • zoh_point2point
    • zoh_pl2pl
    • zoh_ss_point2point
  12. Understand anomaly naming conventions in pykep

    master

    In pykep, anomaly types are represented by specific mathematical symbols. In function and variable names, these symbols may be spelled out (e.g., zeta for $\zeta$) or represented by lowercase letters (e.g., m for $M$).

    SymbolName
    $M$Mean Anomaly
    $E$Eccentric Anomaly
    $L$True Longitude
    $\lambda$Mean Longitude
    $H$Hyperbolic Anomaly
    $N$Mean Hyperbolic Anomaly
    $\zeta$Gudermannian