Skip to main content

pymonge

Minimum-work transport protocols for trapped colloidal particles, found with the Ritz method: the trap protocol λ(t) is expanded in Chebyshev polynomials and its coefficients are optimised with Adam (exact pathwise gradients through the stochastic integrator) or a genetic algorithm. Only the ability to simulate stochastic trajectories is needed. The built-in model is an active particle (stresslet) near a plane no-slip wall.

Why Monge

Gaspard Monge (1746–1818) was a French mathematician, the founder of descriptive geometry. In his 1781 memoir Mémoire sur la théorie des déblais et des remblais he asked how to move a pile of earth into an excavation of the same volume while doing the least total work of transport. This is the first optimal-transport problem, and the question this package answers is of the same kind: how to move a colloidal particle from one place to another, in a fixed time, with the least work. The link is more than an analogy: for overdamped dynamics, the minimum dissipation of a finite-time process is set by an optimal-transport distance between the initial and final distributions.

Companion code for Optimal protocols for the transport of an active particle near a plane wall (Maurya, Swaminathan, Ashraf & Singh).

Install

pip install -e .            # from this folder; needs numpy and matplotlib
pip install -e .[test]      # with pytest
pytest                      # 12 tests, a few seconds

Quick start

import pymonge as pm

model   = pm.NearWallModel.paper(alpha=25)              # puller near a wall
problem = pm.TransportProblem(model, H0=2.0, dH=5.0)    # trap moves from 2 to 7

res = pm.optimize_adam(problem, n_trials=6, epochs=100)
lam = problem.protocol(res.coeffs.mean(0))              # full protocol, jumps included

opt = problem.evaluate(res.coeffs.mean(0), n_traj=100_000)
ss  = problem.evaluate(problem.ansatz.ramp_coeffs(), n_traj=100_000)   # bulk protocol
print(opt.mean / problem.W_star, ss.mean / problem.W_star)

What is in the package

module contents
model NearWallModel with pluggable BrennerMobility / BulkMobility and StressletDrift / NoDrift; NearWallModel.paper(alpha) builds the model of the paper
protocol TimeGrid, ChebyshevProtocol, PiecewiseLinearProtocol, schmiedl_seifert, schmiedl_seifert_work
simulate Itô–Euler–Maruyama integrator, simulate for trajectories, WorkEvaluator (Monte-Carlo ⟨W⟩ with common random numbers, multi-process)
gradient work_and_grad: hand-written adjoint of the integrator; exact gradient of the discretised ⟨W⟩ with respect to every protocol value
problem TransportProblem: physics, end points, time grid and ansatz in one object
optimize optimize_adam (trials vectorised), evaluate_history, optimize_ga (two-stage genetic algorithm)
plotting small matplotlib helpers used by the examples

Folders

folder contents
src/pymonge/ the package
tests/ unit tests (derivatives, adjoint against finite differences, bulk limit, reproducibility)
examples/ four short tutorials; each takes --quick
paper/ scripts, data and figures of the paper; see paper/README.md

Examples:

file what it shows
01_bulk_validation.py Adam started from a straight line recovers the Schmiedl–Seifert ramp and W* = 6.25
02_activity_near_wall.py pushers, passive particles and pullers close to the wall
03_symmetry_breaking.py away against towards transport
04_custom_physics.py adding your own drift (gravity) to the model

Conventions

Notation. Lengths are in units of the particle radius. In the paper the initial trap position is Λ₀ and the displacement ΔΛ; in the code these are the arguments H0 and dH of TransportProblem (the name is historical: H0 is a trap position, not a particle height).

Activity. alpha > 0 is a puller, whose wall-induced drift is towards the wall; alpha < 0 is a pusher, drifting away from the wall.

Dynamics. dh = [−μ(h) k (h − λ) + v_A(h) + k_BT μ'(h)] dt + √(2 k_BT μ(h)) dB (Itô; the term k_BT μ' makes a passive particle relax to the Boltzmann distribution).

Discretisation. A protocol on n_steps steps is an array of length n_steps + 2: [λ_i, λ(t_1), …, λ(t_N), λ_f]. At each step the trap moves first, with the particle fixed, and then the particle moves for dt. The end points are not part of the Chebyshev expansion, so the jumps at t = 0 and t = t_f come out of the optimisation.

Wall. Trajectories are reflected at contact, h_min = 1. Change it with NearWallModel(..., h_min=...).

Initial condition. TransportProblem(initial=...): "boltzmann" (default; equilibrium in the initial trap, cut off at the wall), "relaxed" (relaxed with the active dynamics) or "trap" (all particles at the trap centre). Near the wall the work depends noticeably on this choice.

Common random numbers. WorkEvaluator with the same seed uses the same initial positions and noise for every protocol, so differences between protocols are resolved far better than each absolute value (whose standard error is about 0.002 W* at 100,000 trajectories).

Optimiser settings

Adam defaults (AdamConfig): 1000 trajectories per step, learning rate 0.05 with cosine decay to 10⁻³, gradient-norm clipping at 5, β₁ = 0.9, β₂ = 0.999, initial protocol equal to the bulk ramp plus Gaussian noise of standard deviation 0.05. The genetic algorithm (GAConfig) uses 150 individuals, 30 generations at 500 trajectories followed by 70 at 2000, 10% elites, tournament size 10 and mutation annealed from 0.2 to 0.005; hifi_top and elite_traj set how many candidates are re-evaluated at high fidelity in each generation.

Metadata

Release files for pymonge 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymonge 0.1.0
File Size Uploaded Provenance Actions
pymonge-0.1.0.tar.gz 22.6 kB Without provenance Details for pymonge-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymonge 0.1.0
File Interpreter ABI Platform Actions
pymonge-0.1.0-py3-none-any.whl Python 3 none any Details for pymonge-0.1.0-py3-none-any.whl

Total release size: 44.7 kB

Release files / pymonge-0.1.0.tar.gz

Download URL pymonge-0.1.0.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
948b8c32be18f1e68659e6c5451eb886d67e278732808f84244a0fbe2812998b
BLAKE2b-256 checksum
How to use checksums
95fd0fe441b292a6d8ee63e2978a82564e30492109c26cb3796ee1cceb6b133d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release files / pymonge-0.1.0-py3-none-any.whl

Download URL pymonge-0.1.0-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a871b13708791aaab244a05481fcd518fd764c45021d783f0706ede0d9d1a8aa
BLAKE2b-256 checksum
How to use checksums
6e67ec7479020a3dbaf02f57cd2801516180da16854c1e521ea76a24073d2a3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Security for pymonge 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page