This page summarizes the public API most users need.
from graphot import (
GraphSpec,
LogMeanOps,
OTConfig,
OTProblem,
TimeDiscretization,
solve_ot,
)Represents the graph.
Most users should build it with one of these constructors:
GraphSpec.from_undirected_weights(...)GraphSpec.from_directed_rates(...)
Useful fields:
graph.num_nodesgraph.num_edgesgraph.pigraph.srcgraph.dstgraph.q
Use graph.pi when converting ordinary masses to solver densities.
TimeDiscretization(num_steps: int)This sets how finely the transport path is split in time.
- smaller
num_stepsis cheaper, - larger
num_stepsgives a finer path.
For a first run, 32 to 64 steps is usually a sensible range.
LogMeanOps()This is the mean model used by the current solver. In normal use, create it and
pass it into OTProblem.
OTConfig(...)Controls solver behavior.
Most users only need these fields:
max_iterscheck_everycg_max_itersrecord_debug_trace
The defaults are a good starting point. Tune further only if a problem is slow or does not converge.
OTConfig does not control CPU threading.
If the installed graphot build includes OpenMP, the solver uses all available
CPU threads by default. To override that, set an environment variable before
Python starts:
GRAPHOT_NUM_THREADS=16 python your_script.pyIf you already use standard OpenMP environment settings, OMP_NUM_THREADS is
also respected:
OMP_NUM_THREADS=16 python your_script.pyIf graphot was built without OpenMP, solves run single-threaded regardless of
these settings.
OTProblem(
graph=graph,
time=TimeDiscretization(...),
rho_a=rho_a,
rho_b=rho_b,
mean_ops=LogMeanOps(),
)Bundles all inputs for one solve.
Requirements for rho_a and rho_b:
- shape
(num_nodes,), - finite,
- nonnegative,
- normalized so that
sum(graph.pi * rho) == 1.
solution = solve_ot(problem, config=OTConfig(), initial_state=None)This is the main entry point.
initial_state is optional. Pass a previous solution.state when you want to
warm-start a nearby solve, for example in a continuation scheme.
It returns an OTSolution.
The fields most users inspect are:
solution.distancesolution.convergedsolution.iterations_usedsolution.statesolution.diagnosticssolution.debug_trace
The state contains the full time-dependent result.
Most users look at:
solution.state.rhosolution.state.m
Both are NumPy arrays.
This dictionary contains compact status values from the final checkpoint.
The most useful keys are:
continuity_residualprimal_deltadual_deltamax_constraint_residualendpoint_residual
If a solve is slow or unstable, look here first.
Available when record_debug_trace=True.
Useful fields:
trace.iterationstrace.actiontrace.continuity_residualtrace.primal_deltatrace.dual_deltatrace.min_varthetatrace.num_records
Only the first trace.num_records entries are valid.