FW-APH (compiled hub)

FW-APH is asynchronous projective hedging (see APH) whose scenario subproblems are solved by Frank-Wolfe steps. It runs as a hub, selected with --aphfw-hub, and works with the usual spokes. Unlike the other hubs, the algorithm is C++: the hub writes each scenario as an MPS file and hands it to a compiled module, aphfw_cpp, which solves the subproblems directly with Gurobi, CPLEX, Xpress or HiGHS.

That module is optional, and a normal mpi-sppy install does not build it. Nothing else in mpi-sppy depends on it: without it, every other hub and spoke works as usual, and only --aphfw-hub stops, with a message saying how to build it.

What you need

  • A clone of mpi-sppy from GitHub. The C++ sources are in mpisppy/aphfw_cpp/ of the repository; the package installed from PyPI does not contain them. Install mpi-sppy from the clone (pip install -e . in its root) and build from there.

  • MPI and mpi4py (see Install mpi4py). The module shares mpi4py’s communicator, so it must be compiled against the same MPI that mpi4py uses. A mismatch is not a build error; it shows up as a crash at run time, which is why the build command checks for it.

  • A C++ compiler with C++23 support, reached through that MPI’s mpicxx wrapper.

  • One of Gurobi, CPLEX or Xpress, as a full installation with its C or C++ libraries and headers. The module is built for exactly one of them. For Gurobi, this is the platform directory of a full install (e.g. .../gurobi1302/linux64): the gurobipy wheel does not contain the C++ library. The build looks for Gurobi 13.0 or 12.0. Or HiGHS, which needs no license: its home is the prefix it was installed into, e.g. a conda environment with conda-forge’s highs package (the highspy wheel has no C++ headers). HiGHS cannot solve mixed-integer QPs, so a HiGHS build refuses a model whose objective has quadratic terms.

  • CMake 3.16 or later. If there is no suitable CMake, pip fetches one during the build.

The build has been tested on Linux with GCC 14.3 (conda-forge), Open MPI 5.0.8 with mpi4py 4.1.0, Gurobi 13.0.2, CPLEX 22.1.1 and HiGHS 1.15.1. Xpress 9.8.1 has been built and run on one unit commitment model only. macOS and Windows have not been tested.

Building

From the root of your clone, in the Python environment where mpi-sppy and mpi4py are installed:

python -m mpisppy.aphfw_cpp.build --solver gurobi --solver-home /path/to/gurobi1302/linux64

For CPLEX, the home is the CPLEX_Studio... directory:

python -m mpisppy.aphfw_cpp.build --solver cplex --solver-home /opt/ibm/ILOG/CPLEX_Studio2211

For HiGHS, it is the installation prefix:

python -m mpisppy.aphfw_cpp.build --solver highs --solver-home /path/to/prefix

Without --solver, the command uses whichever of GUROBI_HOME, CPLEX_ROOT, XPRESS_HOME (or XPRESSDIR) or HIGHS_HOME is set in the environment, and asks you to choose if more than one is set. The command:

  1. checks that the solver home holds what the build needs;

  2. picks the MPI C++ compiler: --cxx if given, else the mpicxx that mpi4py recorded at its own build, else the mpicxx in the same directory as the running python (as in a conda environment), else the one on PATH;

  3. runs pip install on mpisppy/aphfw_cpp, which compiles the module (about 20 seconds on the 8-core test machine) and installs it into the environment’s site-packages;

  4. imports the new module in a fresh interpreter and checks that it and mpi4py load the same MPI library (on Linux; elsewhere it says that it could not check).

It prints each choice before acting on it, so --dry-run shows the solver, the compiler and the pip command without building anything. Arguments after -- go to pip (e.g. -- -q). Running the command again rebuilds the module and replaces the installed one, e.g. to switch solver. python -m mpisppy.aphfw_cpp.build --help lists the options.

A successful build ends with lines like:

aphfw_cpp installed at .../site-packages/aphfw_cpp.cpython-311-x86_64-linux-gnu.so, built for gurobi
aphfw_cpp and mpi4py both load .../lib/libmpi.so.40.40.7

The installed module records where the solver and MPI libraries are, so it needs no LD_LIBRARY_PATH.

Building without the wrapper

The command is a convenience over a plain pip build, which you can run yourself. CXX must be the mpicxx of mpi4py’s MPI, and the solver and its home have to be named; there is no default solver:

CXX=mpicxx pip install ./mpisppy/aphfw_cpp \
    -C cmake.define.USE_GUROBI=ON -C cmake.define.GUROBI_HOME=/path/to/gurobi1302/linux64

For CPLEX (Xpress likewise, with USE_XPRESS and XPRESS_HOME):

CXX=mpicxx pip install ./mpisppy/aphfw_cpp \
    -C cmake.define.USE_CPLEX=ON -C cmake.define.CPLEX_ROOT=/opt/ibm/ILOG/CPLEX_Studio2211

This skips the checks, including the one for a mismatched MPI.

Checking the build

python -c "import aphfw_cpp" should succeed from any directory. The tests in mpisppy/tests/test_aphfw_hub.py run end to end once the module is built, including eight MPI tests that each start their own mpiexec job (3 or 6 ranks):

cd mpisppy/tests
python -m pytest test_aphfw_hub.py

Without the module these tests are skipped, not failed. One of the MPI tests needs 6 MPI slots. The Pyomo solver they use on the Python side is set by the environment variable MPISPPY_APHFW_TEST_SOLVER (for example gurobi_persistent or appsi_highs); without it, the MPI tests use Pyomo’s gurobi and the others the first of CPLEX, Gurobi and Xpress that Pyomo can use. A solver named in the variable that Pyomo cannot use is an error, not a skip.

The C++ tests

For work on the C++ itself, mpisppy/aphfw_cpp/tests holds its own tests: GoogleTest cases on small bundled problems, runs of the standalone driver main_aph_<solver>, and tests of the Python bindings against the module the same build produces. They are built only on request, with CMake directly rather than pip:

cmake -S mpisppy/aphfw_cpp -B aphfw_build -DUSE_GUROBI=ON \
    -DGUROBI_HOME=/path/to/gurobi1302/linux64 -DCMAKE_CXX_COMPILER=mpicxx \
    -Dpybind11_DIR=$(python -m pybind11 --cmakedir) -DAPHFW_BUILD_TESTS=ON
cmake --build aphfw_build --parallel
ctest --test-dir aphfw_build --output-on-failure

The configure step downloads GoogleTest. The numeric-retry tests exist only in a Gurobi build, and the tests of a quadratic objective only in a Gurobi, CPLEX or Xpress build.

Testing with other solvers

mpi-sppy’s CI (the aphfw-highs job in .github/workflows/test_pr_and_main.yml) tests only a HiGHS build, since HiGHS is the one solver whose C++ library needs no license. Changes to the C++, and in particular to a solver’s backend in mpisppy/aphfw_cpp/solver_interfaces/<solver>, should also be tested with every licensed solver you have, by running the same steps locally. For each solver:

  1. Build and install the module for it (see Building), e.g. python -m mpisppy.aphfw_cpp.build --solver cplex --solver-home /opt/ibm/ILOG/CPLEX_Studio2211. This replaces the module built for any other solver.

  2. Run the C++ tests from a build directory of its own, configured with that solver’s option and home in place of the Gurobi ones above: -DUSE_CPLEX=ON -DCPLEX_ROOT=..., -DUSE_XPRESS=ON -DXPRESS_HOME=... or -DUSE_HIGHS=ON -DHIGHS_HOME=.... These do not use the installed module.

  3. Run the hub tests with the matching Pyomo solver:

    cd mpisppy/tests
    MPISPPY_APHFW_TEST_SOLVER=cplex_persistent python -m pytest test_aphfw_hub.py
    

The hub tests use the installed module, so test one solver’s build at a time. To check a change to CI itself, the job’s steps can be run as they are in a fresh conda-forge environment holding the packages its “Install dependencies” step names; that environment has no licensed solver, so it is also a check that nothing in the tests depends on one.

Running

Select the hub with --aphfw-hub in generic_cylinders (see generic_cylinders.py) and add spokes as with any other hub:

mpiexec -np 3 python -m mpi4py -m mpisppy.generic_cylinders \
    --module-name mpisppy.tests.examples.farmer --num-scens 3 \
    --solver-name gurobi_persistent --aphfw-hub --default-rho 1 \
    --max-iterations 50 --lagrangian --xhatshuffle --rel-gap 0.001

The hub’s subproblems are solved in C++ by the solver the module was built for, and each run prints which one that is. --solver-name is still needed, for the spokes; it may name a different solver, in which case the run logs a warning. To change the hub’s solver, build the module again (see Building). The C++ solves take only a MIP gap, a time limit and a thread count, set by these options:

Table 3 Settings for the hub’s C++ solves

Option

Default

Applies to

--iter0-mipgap

the solver’s

The Lagrangian solves, at startup and (with --aphfw-final-lagrangian) at the end

--iterk-mipgap

\(10^{-4}\)

The Frank-Wolfe linear subproblems, or with --aphfw-no-fw the proximal subproblems

--aphfw-solve-time-limit

300

Every C++ solve, in seconds

--max-solver-threads

1

Every C++ solve

As for the other hubs, --iter0-mipgap and --iterk-mipgap exist only when the model’s inparser_adder calls cfg.mip_options(), and they also reach the spokes. --solver-options and --solver-options-file do not reach the C++ solves; the hub says so in a warning, and they still apply to the spokes.

Options of the APH algorithm begin with --aph-, and some of them are shared with APH; the ones only this hub reads are refused by --APH. Options that begin with --aphfw- are about Frank-Wolfe or the compiled hub itself. The hub also takes --max-iterations, --time-limit and --default-rho. The ones most often set:

Table 4 FW-APH hub options

Option

Default

Description

--default-rho

Proximal term multiplier, as for PH and APH

--aph-nu

1.0

Step size multiplier (shared with APH)

--max-iterations

1

Maximum number of cycles, as for the other hubs’ iterations; at least 1

--aphfw-no-fw

off

Solve each subproblem in one solver call instead of by Frank-Wolfe (see below)

--aphfw-fw-tmax

1

Maximum Frank-Wolfe iterations (linear subproblem solves) per scenario solve

--aphfw-fw-tau

0.01

Frank-Wolfe gap at which a scenario solve stops early

--aph-primal-term-thresh

0.01

Primal termination tolerance (on \(u\))

--aph-dual-term-thresh

0.01

Dual termination tolerance (on \(v\))

--aph-gamma

1.0

Primal/dual scaling \(\gamma\), as in \(\|u\|^2 + \|v\|^2/\gamma\) (shared with APH)

--aph-frac-needed

1.0

Fraction of the scenario solves needed before a projection (shared with APH, which counts ranks instead)

--aph-block-sync

off

Allow only block asynchronism

--aphfw-final-lagrangian

off

After the main loop, solve a Lagrangian bound in the hub and let it compete with the bound spokes

--aphfw-verbosity

0

C++ output; 1 adds a line per subproblem solve and per cycle

--aphfw-scenario-dir

the system’s temporary directory

Where each hub rank writes the scenario files its C++ reads, in a subdirectory of its own, aphfw_r<rank>_*, that is removed when the run finishes normally. It must exist on every node the hub runs on but need not be on a shared filesystem.

--aphfw-keep-scenario-files

off

Keep those subdirectories, with each rank’s solver.log, after the run.

--help (with a --module-name) lists the rest. The hub refuses the APH options it does not use, such as --aph-dispatch-frac and --aph-sleep-seconds. Its \(\|u\|^2\) is weighted by omicron, which by default is \(\rho\) from iteration 1 on, so a given --aph-gamma does not balance \(u\) and \(v\) exactly as it does for APH; --aph-omicron-all 1 removes the weights. --aphfw-hub cannot be combined with --integer-relax-then-enforce: the C++ hub solves from the MPS files and does not see changes to Pyomo variable types. The hub also refuses maximization models, models with variable_probability, and a converger (it stops on its own convergence test, the spokes’ gap, --max-iterations or --time-limit, which it checks after each cycle).

Without Frank-Wolfe

With --aphfw-no-fw the hub solves each scenario’s proximal subproblem, minimize \(f_s(x) + W_s^\top x + \frac{\rho}{2}\|x - z_s\|^2\) over the scenario’s feasible set, in one solver call, as the Python APH hub does. For a mixed-integer model that is a mixed-integer QP, so a HiGHS build refuses --aphfw-no-fw on a model with integer variables. Everything else about the hub is the same. --aphfw-fw-tmax, --aphfw-fw-tau and --aphfw-obj-cutoff steer only Frank-Wolfe, so with --aphfw-no-fw they must keep their defaults. --aphfw-iter0-fw-step still applies; the step it adds is a proximal solve.

--warmstart-subproblems gives each proximal solve the solver’s last solution as a start. Without --aphfw-no-fw it does not reach the hub’s solves, where the Frank-Wolfe linear subproblems always get such a start. In both cases it still applies to the spokes.

--aphfw-no-fw needs --aphfw-hub too. With both, a command line written for --APH runs if it avoids what the hub refuses (above).

Troubleshooting

Its C++ sources come only with a clone of the mpi-sppy repository / No aphfw_cpp sources in ...

mpi-sppy was installed from PyPI. Clone it from GitHub, install it from the clone, and build there.

No solver found / More than one solver is set

Pass --solver and --solver-home, or set exactly one of GUROBI_HOME, CPLEX_ROOT, XPRESS_HOME.

No include/gurobi_c++.h under ... (and the CPLEX, Xpress and HiGHS equivalents)

--solver-home must be the solver’s installation directory: for Gurobi the platform directory holding include/ and lib/, for CPLEX the CPLEX_Studio... directory holding cplex/ and concert/, for Xpress the directory holding include/xprs.h and lib/, for HiGHS the prefix holding include/highs/Highs.h and, under lib, lib64 or lib/<arch>, the library and cmake/highs/. The message names what is missing.

Hub rank ... could not make a FW-APH scenario directory

The directory given with --aphfw-scenario-dir, or the system’s temporary directory if none was given, is missing or not writable on at least one node the hub runs on.

aphfw_cpp loads ... but mpi4py loads ...

The module was compiled against a different MPI than mpi4py’s. Rebuild with --cxx set to the mpicxx of mpi4py’s MPI.

Name the solver to build for

A plain pip build was run without -C cmake.define.USE_GUROBI=ON (or USE_CPLEX / USE_XPRESS). Name the solver and its home, or use the build command.

pip install failed

The CMake or compiler error is printed above this line. The usual causes are a compiler without C++23 support and a solver version the build does not look for.

The aphfw hub (--aphfw-hub) needs the compiled aphfw_cpp module

aphfw_cpp cannot be imported in the Python running the hub. Build it in that environment.