-
Notifications
You must be signed in to change notification settings - Fork 228
C++-based CHRR implementation #1453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Conversation
Sorry for the delay, currently on paternity leave. I will try to review in the next weeks. I think it's a great addition and indeed something people have asked for a lot. Regarding the Glnac flux this is because in the other implementations fluxes with a bound difference smaller than the solver tolerance are considered fixed. So a flux with [-1e-12, 1e-12] would be fixed to zero. |
Sure, no rush :) Thanks for having a look at it! Regarding the GLNabc flux, I will check on that again. Afaik, PolyRound, the tool we use for the rounding transformation should have a similar option for just fixing fluxes dimensions with very tight bounds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good except for the default method thing.
src/cobra/sampling/sampling.py
Outdated
model: "Model", | ||
n: int, | ||
method: str = "optgp", | ||
method: str = "chrr", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the default should work on any installation. Maybe add an "auto" option that used hopsy if installed and optgp otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an "auto" option and set it to be the default. Is that how you had in mind? Or would you still suggest to put "optgp" as default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is exactly what I meant, thanks!
from cobra.core import Metabolite, Model, Reaction | ||
from cobra.flux_analysis.parsimonious import pfba | ||
from cobra.sampling import ACHRSampler, OptGPSampler, sample | ||
from cobra.sampling import ACHRSampler, OptGPSampler, hopsy_is_available, sample |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the new auto option most of the tests will fall back to ootgp here now. The sample calls have to be adjusted to force chrr I think and it might need some fences to check whether hopsy is installed. Also need to adjust the tox.ini so hopsy is installed during the CI. Thx
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.