ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 28 Oct 2018 15:45:02 +0100ChainComplex() runs 24 times slower than homology()https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/I load a list of matrices `bdrs` representing a chain complex, their dimensions are
{1, 21, 210, 1330, 5985, 20349, 54264, 116280, 203490, 293930, 352716, 352716, 293930, 203490, 116280, 54264, 20349, 5985, 1330, 210, 21, 1}, and the largest has density 3.91*10^-6. In total they take up 50MB of disk space. This finishes in 63sec.
When I run `chcx=ChainComplex(bdrs,base_ring=GF(2))`, it takes 7hrs20min, but `chcx.homology()` finishes in only 18min. **Why does it take so long to just store a few matrices?** At first I thought that `ChainComplex()` also does some simplifications/reductions, but `[chcx.free_module_rank(i) for i in range(0,21)]` shows the original dimensions of matrices :/.
**Is there a faster way to compute the homology** of a chain complex (over $\mathbb{Z}$ or $\mathbb{Z}_p$)?Sun, 28 Oct 2018 09:55:39 +0100https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/Answer by rburing for <p>I load a list of matrices <code>bdrs</code> representing a chain complex, their dimensions are
{1, 21, 210, 1330, 5985, 20349, 54264, 116280, 203490, 293930, 352716, 352716, 293930, 203490, 116280, 54264, 20349, 5985, 1330, 210, 21, 1}, and the largest has density 3.91*10^-6. In total they take up 50MB of disk space. This finishes in 63sec.</p>
<p>When I run <code>chcx=ChainComplex(bdrs,base_ring=GF(2))</code>, it takes 7hrs20min, but <code>chcx.homology()</code> finishes in only 18min. <strong>Why does it take so long to just store a few matrices?</strong> At first I thought that <code>ChainComplex()</code> also does some simplifications/reductions, but <code>[chcx.free_module_rank(i) for i in range(0,21)]</code> shows the original dimensions of matrices :/.</p>
<p><strong>Is there a faster way to compute the homology</strong> of a chain complex (over $\mathbb{Z}$ or $\mathbb{Z}_p$)?</p>
https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?answer=44102#post-id-44102According to the [documentation of ChainComplex](http://doc.sagemath.org/html/en/reference/homology/sage/homology/chain_complex.html#sage.homology.chain_complex.ChainComplex) there is an optional argument
> `check` – boolean (optional, default `True`). If `True`, check that each consecutive pair of differentials are composable and have composite equal to zero.
I can imagine this takes a while. How fast is it with `check=False`?Sun, 28 Oct 2018 10:51:41 +0100https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?answer=44102#post-id-44102Comment by Leon for <p>According to the <a href="http://doc.sagemath.org/html/en/reference/homology/sage/homology/chain_complex.html#sage.homology.chain_complex.ChainComplex">documentation of ChainComplex</a> there is an optional argument</p>
<blockquote>
<p><code>check</code> – boolean (optional, default <code>True</code>). If <code>True</code>, check that each consecutive pair of differentials are composable and have composite equal to zero.</p>
</blockquote>
<p>I can imagine this takes a while. How fast is it with <code>check=False</code>?</p>
https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?comment=44104#post-id-44104Aaah, you're right, with `check=False`, it only takes 3sec. Sorry for not noticing this option in the documentation, and thank you for your help!Sun, 28 Oct 2018 15:42:00 +0100https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?comment=44104#post-id-44104Answer by tmonteil for <p>I load a list of matrices <code>bdrs</code> representing a chain complex, their dimensions are
{1, 21, 210, 1330, 5985, 20349, 54264, 116280, 203490, 293930, 352716, 352716, 293930, 203490, 116280, 54264, 20349, 5985, 1330, 210, 21, 1}, and the largest has density 3.91*10^-6. In total they take up 50MB of disk space. This finishes in 63sec.</p>
<p>When I run <code>chcx=ChainComplex(bdrs,base_ring=GF(2))</code>, it takes 7hrs20min, but <code>chcx.homology()</code> finishes in only 18min. <strong>Why does it take so long to just store a few matrices?</strong> At first I thought that <code>ChainComplex()</code> also does some simplifications/reductions, but <code>[chcx.free_module_rank(i) for i in range(0,21)]</code> shows the original dimensions of matrices :/.</p>
<p><strong>Is there a faster way to compute the homology</strong> of a chain complex (over $\mathbb{Z}$ or $\mathbb{Z}_p$)?</p>
https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?answer=44103#post-id-44103Apparently (unfortunately), there is no way to specify/detect that your objects are sparse when defining the chain complex.
You could try to enforce that by giving as few choice as possible to the `ChainComplex` by defining `bdrs` to be sparse matrices explicitely defined over `GF(2)`.
Please tell us if is works. Otherwise, could you please provide your code so that we can handle a concrete example and see what is going on ?
Sun, 28 Oct 2018 12:15:18 +0100https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?answer=44103#post-id-44103Comment by Leon for <p>Apparently (unfortunately), there is no way to specify/detect that your objects are sparse when defining the chain complex. </p>
<p>You could try to enforce that by giving as few choice as possible to the <code>ChainComplex</code> by defining <code>bdrs</code> to be sparse matrices explicitely defined over <code>GF(2)</code>.</p>
<p>Please tell us if is works. Otherwise, could you please provide your code so that we can handle a concrete example and see what is going on ?</p>
https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?comment=44105#post-id-44105Surely, `ChainComplex()` detects that these are sparse matrices, otherwise I wouldn't have enough RAM to store $10^6\times10^6=10^{12}$ entries... But still, thank you for your help!Sun, 28 Oct 2018 15:45:02 +0100https://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/?comment=44105#post-id-44105