C++-based CHRR implementation #1453
Open
+333
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR
Upon popular demand, this PR implements the CHRR algorithm for asymptotically unbiased flux sampling. The provided implementation is blazingly fast due to using the hopsy module, which provides a Python interface to the C++-implemented sampling algorithms from HOPS.
Changes
A
HopsySampler
class which inherits fromHRSampler
is implemented, which interfaces to the hopsy library. TheHopsySampler
applies a rounding transformation and samples the polytope defined by the COBRApymodel
using the uniform Coordinate Hit-and-Run algorithm.Based on the improved performance at high numbers of samples, the default method in
cobra.sampling.sample
is changed tochrr
, though dependent on the availability of the hopsy package. In the case that it is not available, we switch back to the OptGP sampler and raise a warning.As hopsy is a pre-compiled package, guaranteeing its availability on all platforms is not an easy task. Therefore, it is only added as an optional dependency. A corresponding installation option
cobra[chrr]
is added.The tests were extended to cover CHRR.
Performance
A small test example shows the performance benefits from using hopsy's CHRR implementation:
The results shown were obtained on a 16-core AMD Ryzen Threadripper PRO 3955WX.



The main costs inflicted by the CHRR arise from the rounding transformation, which in this case is computed using PolyRound, optlang and Gurobi. Porting the rounding transformation to C++ may further improve performance.
Discussion
Regarding the final plot on the marginal flux distributions, it is not exactly clear to me what happens to the
GLNabc
flux, where OptGP seems to achieve very bad mixing (as measured by the ESS), which explains the bad performance of OptGP when considering the minimum ESS across all dimensions. In particular, it would be important to make sure which one of the samplers samples the correct distribution here. While I'm very confident that hopsy samples correctly in principle, it might be that I overlooked something in the problem setup. I would appreciate some double checking there. Also testing other problems than just thee_coli_core
might be meaningful.