Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TOPS low-thrust problems

TOPS transcribes a trajectory into a chronological sequence of held controls. The leg integrates from both ends and returns the difference at the selected cut. The source JSON stores physical scales and reference states. The Rust catalog retains the source units, then applies the normalization of each pinned PyKEP constructor. The problem metadata records both scale systems.

FamilyControl per segmentStateDefault fixed constraints and objective
Two-body CartesianThrottle fraction and three direction componentsPosition, velocity, massSeven mismatch equalities, direction inequalities, minimize negative final mass
MEEThrottle fraction and three direction componentsPrograde modified equinoctial elements, massSeven mismatch equalities with unwrapped longitude, direction inequalities, minimize negative final mass
CR3BPThrottle fraction and three direction componentsRotating position, velocity, massSeven mismatch equalities and direction equalities, minimize negative final mass
Solar sailSail cone and clock anglesPosition and velocitySix mismatch equalities, minimize flight time

Direction constraints use the squared norm minus one. The evaluator keeps the decision components as supplied. The solar-sail catalog’s six fixed-boundary entries all fix flight time, so their default optimization task is feasibility.

Uniform grids divide total duration equally. Softmax grids use one logit per segment and positive weights that sum to one. The Jacobian contracts the leg’s state, control and grid derivatives with the decoding maps. The softmax contraction uses a reverse cumulative sum for each residual row.

Moving problems add the departure offset, endpoint relative-velocity magnitudes and their direction components. The endpoint states follow Keplerian or CR3BP flow. The normalized epoch chain rule includes both the departure shift and the arrival shift due to flight time. MEE additionally applies the coordinate Jacobian and preserves the source revolution offset. The moving CR3BP source factory uses uniform time even when it receives softmax. The Rust softmax formulation carries the version tops-v1-cr3bp-moving-softmax.

The moving MEE Jacobian follows the selected longitude winding branch. At the P5 and P8 fixed-time anchors, varying the frozen epoch or TOF can change that branch. Optimizer adapters eliminate those frozen coordinates. The benchmark report records free-column checks at the anchors and full derivative checks away from the transition.

Known limitations

  • Moving CR3BP close lunar passes. Two moving-CR3BP stress vectors, in P1 and P13, differ from the PyKEP gradient by a scaled 1.07e-6 and 4.23e-6, above the 1e-7 gate used for the other rows. Both trajectories pass close to the Moon, where the transition matrices are ill-conditioned. Against a 1e-16 reference run, Rust Taylor gradients at tolerances 1e-12 to 1e-15 differ by up to a scaled 2.4e-5 on the same vectors, so the remaining source difference lies inside the double-precision conditioning spread rather than indicating a formulation error. The DOP853 backend agrees with the Taylor gradient within a scaled 5.1e-5, and central differences of the fitness agree to their truncation error. Both vectors are regression tests in crates/pykep-trajopt/tests/cr3bp_conditioning.rs.
  • Moving MEE source discrepancies. The pinned source applies a different MEE chain rule at the endpoints and returns nonfinite values for four configurations per encoding. The Rust formulation is checked against the source symbolic MEE map instead; see the benchmark report.
  • Moving CR3BP softmax. The source factory always uses uniform time. The Rust softmax variant is a separate formulation, tops-v1-cr3bp-moving-softmax, without an upstream reference.
  • Fixed sail P5 scaling. The source normalizes the sail characteristic acceleration by the acceleration unit. Because the sail acceleration scales with the inverse square of the distance, this equals the unnormalized constant only when the initial radius is one. P5 starts at radius 0.7, so tops.sail.P5 has 0.49 times the sail acceleration of tops.sail.P5.moving. The Rust catalog keeps the source behaviour.
  • DOP853 derivatives. With backend="dop853", the Cartesian two-body and CR3BP Jacobians use analytic model Jacobians. MEE and solar-sail Jacobians use centered-difference model Jacobians, so their accuracy is not set by the integrator tolerance. The default Taylor backend differentiates the coefficient recurrences for all four families.

Feasible replay examples

The bundled decisions were generated using a bounded least-squares search with the Rust Jacobian. They satisfy the raw bounds and constraints, and a tighter independent forward DOP853 integration checks the terminal state.

CaseSegmentsMaximum absolute forward residual
Cartesian P4164.88e-14
MEE P8241.59e-13
CR3BP P0301.59e-12
Solar sail P4248.15e-14

Cartesian two-body P4

The first coordinate is final mass. Each segment contributes a throttle fraction and three direction components. The last coordinate is time of flight. The integrator uses the initial radius and mass to set its units. Solve for the seven state and mass matching rows before comparing the final-mass objective.

python tools/gym-benchmark/solve_tops.py tops.twobody.P4 --nseg 16 \
  --seed 42 --evaluations 320 --output artifacts/gym/twobody-solved.json

Modified equinoctial P8

The integrator normalizes the initial semi-latus rectum and uses prograde MEE. The longitude residual includes its winding, so leave the longitude unwrapped in the terminal check. The saved control directions are expressed in the local radial, transverse and normal frame.

python tools/gym-benchmark/solve_tops.py tops.mee.P8 --nseg 24 \
  --seed 42 --evaluations 320 --output artifacts/gym/mee-solved.json

Rotating CR3BP P0

The dynamics use the dataset’s rotating coordinates and normalized mass ratio. The default fixed-boundary directions have unit-norm equality constraints. Inspect the terminal residual in the rotating frame after replaying the chronological controls.

python tools/gym-benchmark/solve_tops.py tops.cr3bp.P0 --nseg 30 \
  --seed 11 --evaluations 900 --output artifacts/gym/cr3bp-solved.json

Solar sail P4

Each segment holds cone and clock angles in radians. There is no spacecraft mass coordinate in the six-state integration. The source fixes the TOF, so the six terminal-state rows determine success.

python tools/gym-benchmark/solve_tops.py tops.sail.P4 --nseg 24 \
  --seed 11 --evaluations 900 --output artifacts/gym/sail-solved.json

The commands use SciPy’s bounded least-squares solver with the analytic Rust Jacobian and a 1e-8 feasibility gate. Each uses one thread when the environment sets OPENBLAS_NUM_THREADS=1 and OMP_NUM_THREADS=1.

After installing the wheel built from this checkout, replay a case from the repository root. The other three fixture names are mee.P8.json, cr3bp.P0.json and sail.P4.json.

python python/examples/gym/replay.py \
  --solution crates/pykep-trajopt/data/solutions/twobody.P4.json \
  --output artifacts/gym/twobody-trajectory.json

Use --solution with either the checked-in vector or a newly solved record. The replay includes the original decision, scaled controls, chronological time grid, endpoint states and separate forward/backward sample paths. The backward paths are ordered from the arrival end toward the cut. Use tools/gym-benchmark/solve_tops.py with SciPy to regenerate a feasible vector. Its output records the requested budget and actual fitness and gradient calls.

python python/examples/gym/plot.py artifacts/gym/twobody-trajectory.json \
  artifacts/gym/twobody-trajectory.png
python python/examples/gym/replay.py --problem tops.twobody.P4.moving --nseg 16

Plotting uses Matplotlib in a separate process. The moving-boundary command illustrates a finite midpoint evaluation.

Set the TOPS backend explicitly to taylor or dop853. Nominal and derivative tolerances are separate options. See measured objective and derivative performance.