---
title: 'PyKEP: Open-Source Toolkit for Interplanetary Design'
url: https://www.emergentmind.com/topics/pykep
type: topic
---

# PyKEP: Open-Source Toolkit for Interplanetary Design

Searching arXiv for the specified paper to ground the response.
PyKEP is an open-source library focused on preliminary interplanetary mission design. In the treatment centered on "Designing Complex Interplanetary Trajectories for the Global Trajectory Optimization Competitions" [1511.00821], it is presented as a software environment that wraps fast, well-tested astrodynamics primitives and transcriptions to quickly assemble trajectory building blocks, evaluate feasibility, and feed optimization or tree-search algorithms. The chapter uses PyKEP both to introduce fundamental problems of space flight mechanics and to formulate a multiple asteroid rendezvous strategy related to the 7th edition of the Global Trajectory Optimization Competition, with particular emphasis on Lambert transfers, low-thrust transcriptions, phasing indicators, clustering, and beam-search-based global exploration [1511.00821].

## 1. Position within preliminary interplanetary design

PyKEP is used for a typical preliminary-design workflow in which bodies, ephemerides, and epochs are first defined; transfer legs are then computed via Lambert methods under impulsive assumptions or via transcribed low-thrust arcs; $\Delta v$, mass, and time budgets are sized; coarse grids such as porkchops are generated to identify windows; and a global search is performed using beam search, tree search, or heuristics guided by surrogate metrics, after which promising sequences are refined [1511.00821].

Within that workflow, the chapter employs PyKEP to query ephemerides and simple planet models, including JPL low-precision models for Earth and Mars; solve the Kepler initial value problem with Lagrange coefficients through `propagate_lagrangian`; solve Lambert’s boundary value problem through `lambert_problem`, including multi-revolution branches when desired; numerically propagate constant-thrust arcs with a Taylor-series integrator through `propagate_taylor`; transcribe and evaluate low-thrust optimal control problems with the Sims–Flanagan method through `sims_flanagan` spacecraft and leg objects; compute and use phasing indicators and clustering; and orchestrate tree searches, including beam search and MOBS, to generate, rank, and prune trajectory candidates [1511.00821].

The chapter also notes that PyKEP ships tools for gravity-assist sequence exploration, such as MGA and MGA-1DS, and that porkchop-style grid generation can be built by sweeping Lambert solves across departure and arrival grids. These are described as typical preliminary-design tools even though they are not the main focus of the chapter. A plausible implication is that the library is intended less as a monolithic mission optimizer than as a composable toolkit for rapid assembly of trajectory-analysis pipelines.

## 2. Core astrodynamics primitives and transcriptions

A central building block is Lambert’s problem, formulated as a two-body boundary-value problem,
$$
\ddot{\mathbf r} = -\mu \frac{\mathbf r}{r^3},\quad
\mathbf r(t_s) = \mathbf r_s,\quad
\mathbf r(t_f) = \mathbf r_f.
$$
The inputs are $\mu$, $\mathbf r_s$, $\mathbf r_f$, $T=t_f-t_s$, the transfer geometry, and the multi-revolution index; the outputs are the departure and arrival velocities $v_s^\ast=v_1$ and $v_f^\ast=v_2$, with possibly multiple branches, including $0$-rev and higher-revolution solutions, and prograde or retrograde cases. PyKEP exposes this through the pattern
```python
l = lambert_problem(rs, rf, tof, mu, is_retrograde, mr_max)
v1 = l.get_v1()[i]
v2 = l.get_v2()[i]
```
and uses Izzo’s solver. For zero-revolution transfers, the chapter reports near-constant runtime across geometries; in the chapter’s measurements, a $0$-rev Lambert problem took approximately $40\,\mu s$ on a single thread of an Intel i7-4600U, corresponding to roughly $250$k Lambert problems per second [1511.00821].

For unperturbed two-body propagation, PyKEP wraps the Lagrange $f$–$g$ formulation,
$$
\mathbf r_2 = f(\Delta t)\,\mathbf r_1 + g(\Delta t)\,\mathbf v_1,\qquad
\mathbf v_2 = \dot f(\Delta t)\,\mathbf r_1 + \dot g(\Delta t)\,\mathbf v_1,
$$
via `propagate_lagrangian(rs, vs, dt, mu)`. The coefficients depend on $\mu$, the universal variable $\chi$, the Stumpff functions $c_2(\chi)$ and $c_3(\chi)$, and the geometry, allowing propagation without explicit numerical integration for the unperturbed two-body motion.

For constant-thrust propagation, the chapter uses `propagate_taylor`, described as a Taylor-series integrator for perturbed Keplerian motion with constant thrust and mass flow. For low-thrust optimal control problems, the principal transcription is the Sims–Flanagan method. The chapter’s representative pattern constructs a `sims_flanagan.spacecraft`, defines initial and final spacecraft states through `sims_flanagan.sc_state`, and builds a `sims_flanagan.leg`; mismatch constraints and throttle constraints are then evaluated through `leg.mismatch_constraints()` and `leg.throttles_constraints()`. This makes the transcription directly usable as a feasibility filter or as a component in broader search strategies [1511.00821].

These components are used as interoperable primitives rather than as isolated solvers. Lambert arcs support impulsive screening and seeding, while Sims–Flanagan legs support low-thrust feasibility analysis and resource accounting. This suggests that PyKEP’s design emphasizes high-throughput evaluation of candidate transfers under preliminary-design assumptions.

## 3. Mechanical relations and trajectory evaluation

The chapter places PyKEP’s software abstractions within standard space-flight mechanics. In addition to Lambert’s boundary-value problem and the Kepler initial value problem,
$$
\ddot{\mathbf r} = - \frac{\mu}{r^3}\mathbf r,\quad
\mathbf r(t_s) = \mathbf r_s,\quad
\mathbf v(t_s) = \mathbf v_s,
$$
it recalls elliptic Kepler’s equation,
$$
M = E - e \sin E,
$$
and the vis-viva relation,
$$
v^2 = \mu \left( \frac{2}{r} - \frac{1}{a} \right).
$$
These are described as relations used internally by `lambert_problem` and ephemerides routines and as underpinning analytics in two-body propagation and orbital energy checks [1511.00821].

Mass and velocity budgeting are organized around the Tsiolkovsky rocket equation,
$$
\Delta v = I_{sp} g_0 \ln\!\left(\frac{m_0}{m_f}\right),
$$
and, for constant thrust,
$$
\dot m = -\frac{T}{I_{sp} g_0}.
$$
For impulsive Lambert legs, $\Delta v$ accounting is performed by matching encounter relative velocities:
$$
\Delta V = \Delta V_1 + \Delta V_2,\quad
\Delta V_1 = \|v_1 - v_{dep}\|,\quad
\Delta V_2 = \|v_{arr} - v_2\|.
$$
For low-thrust legs, mass flow enters the Sims–Flanagan and Taylor propagators directly.

The chapter also describes porkchop data generation as a grid over departure times $t_s$ and arrival times $t_f$, with metrics such as $C_3$, $\Delta v$, and time of flight. PyKEP facilitates these grids by looping ephemerides queries and Lambert solves. The concrete examples use `planet.jpl_lp('earth')`, `planet.jpl_lp('mars')`, and epochs in `mjd2000`, with explicit conversion of time of flight to seconds before calling `lambert_problem`. The text explicitly warns that misaligned units, for example mixing days and seconds, will corrupt time of flight and $\Delta v$; it also notes that the chapter’s examples often use non-dimensional units inside PyKEP and therefore require consistent unit handling when mixing m/s, AU/day, and related conventions [1511.00821].

A common misconception in preliminary mission design is that coarse dynamical models are intrinsically inappropriate for algorithmic search. The chapter instead adopts heliocentric two-body dynamics, Keplerian asteroid ephemerides, and constant-thrust arcs for the preliminary phase. This does not assert sufficiency for final flight design; rather, it identifies a deliberate trade between dynamical fidelity and tractable global exploration.

## 4. GTOC7-inspired multiple-asteroid rendezvous formulation

The chapter’s principal case study is a multiple asteroid rendezvous problem related to GTOC7. The target set contains $N=16256$ main-belt asteroids with Keplerian ephemerides. The spacecraft parameters are $m_0=2000\,\mathrm{kg}$, propellant mass $m_p=1200\,\mathrm{kg}$, $T_{max}=0.3\,\mathrm{N}$, and $I_{sp}=3000\,\mathrm{s}$. The mission duration is limited to $\mathrm{tof}=6$ years, with a minimum stay time per asteroid of $t_w=30$ days. The start date lies in $t_0 \in [7500,12000]$ MJD2000, and the spacecraft can be placed on a chosen starting asteroid at a chosen date. Rendezvous requires perfect position and velocity match; the dynamics are heliocentric two-body; and low-thrust propulsion is used for transfers, evaluated through Sims–Flanagan and Taylor propagation. The stated objective is to maximize the number of asteroid rendezvous under the remaining time and remaining mass resources [1511.00821].

The global-search strategy is MOBS, a multi-objective beam search. A node is defined by the sequence of visited asteroids together with the non-dimensional remaining resources
$$
r_t = 1 - \frac{t-t_0}{\mathrm{tof}},\qquad
r_m = \frac{m-m_s}{m_p}.
$$
At each node, the branch procedure first selects up to $BF$ candidate next asteroids through $k$-nearest neighbors in the orbital-indicator metric $d_o$; for each candidate, it then solves an earliest-arrival low-thrust optimal control problem to obtain the earliest feasible arrival time $t^\ast$; if such a solution exists, it solves a set of fixed-arrival minimum-mass optimal control problems with
$$
t_f = t^\ast + i\cdot dt,\qquad i=1,\dots,\ell,
$$
to capture feasible variants; and each feasible solution yields updated $r_t$ and $r_m$ and therefore an extended node [1511.00821].

Nodes at the same depth are ranked through a node value $r$. The options tested in the chapter are best mass $r_1=r_m$, best time $r_2=r_t$, the soft minimum
$$
r_4 = \frac{r_m r_t}{r_m + r_t},
$$
and Pareto dominance $r_6$. The beam keeps the best $BS$ nodes for further expansion. The compact pseudocode in the chapter is:

```text
Procedure MOBS(t0, A0):
    B = { [[A0], 1, 1] }; best = [[A0], 1, 1]
    while B not empty:
        L = ∅
        for N in B:
            L = L ∪ Branch(N)      # up to BF new nodes
        best = UpdateBest(L)
        B = Beam(L)                # select up to BS nodes
    return best
```

The constraints handled in this formulation include departure and arrival windows $t_s, t_f \in [t_0, t_0+T_M]$ when computing phasing, mission-horizon tracking through $r_t$ across legs, and enforcement of the minimum stay time $t_w$ between rendezvous events. Maximum time of flight per leg is enforced implicitly by the earliest-arrival and fixed-arrival checks. The chapter also notes that launch $C_3$ limits are not central to this belt-mission setup because the spacecraft is delivered to the starting asteroid [1511.00821].

## 5. Phasing value, surrogates, and clustering

The chapter introduces the phasing value as a multi-objective measure of the transfer quality between asteroids. With the spacecraft $S$ at asteroid $A_s$ at time $t_0$, Lambert problems are considered to a target asteroid $A_f$ over $(t_s,t_f)\in[t_0,t_0+T_M]$, with thrust feasibility constrained by
$$
\Delta V \le \alpha_M \Delta T,\qquad \alpha_M = \frac{\tau_M}{m_s},\qquad \Delta T=t_f-t_s.
$$
The associated objectives are
$$
f_1 = \Delta V,\qquad f_2 = t_f,
$$
subject to $t_s<t_f$. The phasing value is the hypervolume of the Pareto front for $(\Delta V,t_f)$, using the reference point
$$
p^\ast = \left[ \Delta T \frac{\tau_M}{m_s},\ t_0 + \Delta T \right].
$$
A larger hypervolume corresponds to better phasing, meaning more and deeper feasible trade-offs between lower $\Delta V$ and earlier arrival [1511.00821].

Because direct phasing-value computation is expensive, the chapter introduces two fast surrogates. The Euclidean indicator is
$$
d_e = \left\|\begin{bmatrix}\mathbf r_f\\\mathbf v_f\end{bmatrix} -
\begin{bmatrix}\mathbf r_s\\\mathbf v_s\end{bmatrix}\right\|
= \sqrt{\|\Delta\mathbf r\|^2 + \|\Delta\mathbf v\|^2},
$$
which captures proximity in phase space but cannot distinguish converging from diverging relative motion. The orbital indicator is based on a linearized transfer model:
$$
\Delta \mathbf V_0 = \frac{1}{\Delta T} \Delta \mathbf r + \Delta \mathbf v,\qquad
\Delta \mathbf V_1 = \frac{1}{\Delta T} \Delta \mathbf r,
$$
with
$$
d_o = \sqrt{\|\Delta \mathbf V_0\|^2 + \|\Delta \mathbf V_1\|^2}.
$$
If asteroid $i$ at epoch $t_0$ is mapped to
$$
\mathbf x_i = \left[\frac{1}{\Delta T}\mathbf r_i + \mathbf v_i,\ \frac{1}{\Delta T}\mathbf r_i\right],
$$
then $d_o(A_i,A_j)=\|\mathbf x_i-\mathbf x_j\|$, i.e. Euclidean distance in $6$D [1511.00821].

This representation enables $k$-d-tree acceleration. The chapter gives complexity figures of $O(N\log N)$ to build the tree and $O(k\log N)$ to query $k$ nearest neighbors. In the reported tests, one $k$-NN computation, including tree construction, took approximately $0.25$ s, whereas computing all phasing values $\phi$ took about $5$ minutes; Kendall-$\tau$ correlations confirmed that $d_o$ performed better than $d_e$ as a ranking surrogate [1511.00821]. The practical implication is direct: a computationally expensive multi-objective transfer-quality calculation can be replaced by an inexpensive metric that preserves the search order sufficiently well for large-scale branching.

The same orbital-indicator vectors support clustering. A cluster is defined as a subset of asteroids at a given epoch $t_0$ whose pairwise $d_o$ distances are small, specifically within $\varepsilon$. The chapter proposes DBSCAN with Euclidean metric on the orbital-indicator vectors, using parameters $\varepsilon$ and $m_{pts}$, where $\varepsilon$ is interpretable as a $\Delta V$ budget under the linear model and $m_{pts}$ is the minimum number of neighbors for a core point. The stated procedure is to compute the $6$D vectors, run DBSCAN, identify core and border points, discard outliers, and then choose the start epoch by scanning for epochs with large clusters, selecting the initial asteroid from the core of the largest cluster. Runtime is described as scaling well for $N\approx10^4$–$10^5$ because the index build is $O(N\log N)$ and region queries are fast [1511.00821].

## 6. Reported performance, limitations, and comparative context

Under the parameter set $m_0=2000\,\mathrm{kg}$, $m_p=1200\,\mathrm{kg}$, $T_{max}=0.3\,\mathrm{N}$, $I_{sp}=3000\,\mathrm{s}$, $\mathrm{tof}=6$ years, and $t_w=30$ days, the chapter reports that MOBS consistently found sequences of length $12$, occasionally found $13$, and did not reach $14$ in the reported runs; the best sequence length reported in the competition was $13$ [1511.00821]. For node ranking, best time $r_t$ was the most effective node value, while best mass $r_m$ performed poorly; soft-min and Pareto-based ranking were intermediate. The chapter interprets this as evidence that time is the scarcer resource in the stated setup.

Clustering materially affected success rates. Starting inside a large cluster with $\varepsilon=1650\,\mathrm{m/s}$ and $m_{pts}=5$ significantly improved outcomes, and epochs near approximately $10500$ MJD2000 exhibited notably large clusters, identified as good-phasing epochs [1511.00821]. This suggests that start-state selection is not merely an initialization detail but a dominant determinant of reachable sequence length.

The computational campaign was substantial. The chapter reports approximately $30$ million optimal control problem evaluations across $4000$ MOBS runs; one MOBS run required approximately $1$ hour on a $3.1$ GHz multi-core machine; and the overall campaign ran in about $4$ days on $20$ cores with $40$ hyperthreads [1511.00821]. Several practical guidelines are stated explicitly: keep `mr=0` for most Lambert calls unless multi-revolution branches are needed; use $k$-d trees for nearest-neighbor selection and DBSCAN neighborhood operations; use the Taylor integrator for constant-thrust propagation because its runtime scales roughly linearly with integration time; enforce throttle constraints in Sims–Flanagan legs; and drive mismatch constraints near zero for feasibility.

The limitations are also explicit. Full phasing-value computation through a multi-objective Lambert search with hypervolume is expensive at scale, whereas the orbital indicator $d_o$ provides an effective surrogate with strong rank correlation. Global search trees grow rapidly, so beam search with cluster-guided starts is used to provide predictable runtime per depth, approximately $BF \times$ cost per branch, and thereby budget control [1511.00821].

In comparative terms, PyKEP is described as providing fast, open-source implementations of Lambert solvers, ephemerides, low-thrust transcriptions such as Sims–Flanagan, and numerical propagators, making rapid prototyping of global search strategies tractable and allowing integration with external optimizers including IPOPT, SNOPT, and WORHP without vendor lock-in. Tree-search strategies such as beam search and Monte Carlo Tree Search are characterized as algorithmic layers on top of these building blocks. Compared with dedicated flight-dynamics environments, PyKEP is said to trade high-fidelity perturbations for speed and simplicity in preliminary design, precisely the regime exploited in the chapter through Keplerian asteroids, a heliocentric two-body baseline, and constant-thrust arcs [1511.00821].

Source: https://www.emergentmind.com/topics/pykep