ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 14 Aug 2013 08:01:54 -0500sparse differential of a chain complexhttp://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/I'm trying to convert a simplicial complex into a chain complex and then extract the differential map. However the simplicial complex is rather large and sage runs out of memory when it tries to make the conversion. However, the differential should be a very sparse matrix and there should be plenty of memory to store a sparse representation of the differential. Is it possible to have sage compute the differential as a sparse matrix? Specifically the method which gives the out of memory error is `chain_complex()`.Mon, 05 Aug 2013 11:16:29 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/Comment by John Palmieri for <p>I'm trying to convert a simplicial complex into a chain complex and then extract the differential map. However the simplicial complex is rather large and sage runs out of memory when it tries to make the conversion. However, the differential should be a very sparse matrix and there should be plenty of memory to store a sparse representation of the differential. Is it possible to have sage compute the differential as a sparse matrix? Specifically the method which gives the out of memory error is <code>chain_complex()</code>.</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17185#post-id-17185For the method, do you mean `chain_complex` rather than `simplicial_complex`?Tue, 06 Aug 2013 04:34:37 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17185#post-id-17185Comment by parsons.kyle.89 for <p>I'm trying to convert a simplicial complex into a chain complex and then extract the differential map. However the simplicial complex is rather large and sage runs out of memory when it tries to make the conversion. However, the differential should be a very sparse matrix and there should be plenty of memory to store a sparse representation of the differential. Is it possible to have sage compute the differential as a sparse matrix? Specifically the method which gives the out of memory error is <code>chain_complex()</code>.</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17184#post-id-17184Yes sorry I've corrected that.Tue, 06 Aug 2013 04:56:45 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17184#post-id-17184Answer by John Palmieri for <p>I'm trying to convert a simplicial complex into a chain complex and then extract the differential map. However the simplicial complex is rather large and sage runs out of memory when it tries to make the conversion. However, the differential should be a very sparse matrix and there should be plenty of memory to store a sparse representation of the differential. Is it possible to have sage compute the differential as a sparse matrix? Specifically the method which gives the out of memory error is <code>chain_complex()</code>.</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?answer=15322#post-id-15322The `chain_complex` method already produces sparse matrices:
sage: Y = simplicial_complexes.NotIConnectedGraphs(6,2)
sage: Y.f_vector()
[1, 15, 105, 455, 1365, 3003, 4945, 5715, 3990, 1470, 306, 30]
sage: C = Y.chain_complex()
sage: C.differential(4)
1365 x 3003 sparse matrix over Integer Ring
How big is your simplicial complex? What is its f-vector?
Tue, 06 Aug 2013 04:51:06 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?answer=15322#post-id-15322Comment by John Palmieri for <p>The <code>chain_complex</code> method already produces sparse matrices:</p>
<pre><code>sage: Y = simplicial_complexes.NotIConnectedGraphs(6,2)
sage: Y.f_vector()
[1, 15, 105, 455, 1365, 3003, 4945, 5715, 3990, 1470, 306, 30]
sage: C = Y.chain_complex()
sage: C.differential(4)
1365 x 3003 sparse matrix over Integer Ring
</code></pre>
<p>How big is your simplicial complex? What is its f-vector?</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17181#post-id-17181Can you tell in which dimension it fails? If you do `X.chain_complex(dimensions=range(2))`, for example, does it work? Also, how much RAM does your computer have?Tue, 06 Aug 2013 05:41:29 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17181#post-id-17181Comment by parsons.kyle.89 for <p>The <code>chain_complex</code> method already produces sparse matrices:</p>
<pre><code>sage: Y = simplicial_complexes.NotIConnectedGraphs(6,2)
sage: Y.f_vector()
[1, 15, 105, 455, 1365, 3003, 4945, 5715, 3990, 1470, 306, 30]
sage: C = Y.chain_complex()
sage: C.differential(4)
1365 x 3003 sparse matrix over Integer Ring
</code></pre>
<p>How big is your simplicial complex? What is its f-vector?</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17180#post-id-17180Restricting the dimension still fails. It also fails if dimensions = [1,2]. I'm running sage as a virtual machine image on Windows. The virtual machine has 512 MB of RAM (is that a lot or a little?). In actuality my computer has 4 GB.Tue, 06 Aug 2013 11:21:20 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17180#post-id-17180Comment by John Palmieri for <p>The <code>chain_complex</code> method already produces sparse matrices:</p>
<pre><code>sage: Y = simplicial_complexes.NotIConnectedGraphs(6,2)
sage: Y.f_vector()
[1, 15, 105, 455, 1365, 3003, 4945, 5715, 3990, 1470, 306, 30]
sage: C = Y.chain_complex()
sage: C.differential(4)
1365 x 3003 sparse matrix over Integer Ring
</code></pre>
<p>How big is your simplicial complex? What is its f-vector?</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17162#post-id-17162(By "that's not very much RAM", I meant 512 MB, not 4 GB.)Wed, 14 Aug 2013 08:01:54 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17162#post-id-17162Comment by John Palmieri for <p>The <code>chain_complex</code> method already produces sparse matrices:</p>
<pre><code>sage: Y = simplicial_complexes.NotIConnectedGraphs(6,2)
sage: Y.f_vector()
[1, 15, 105, 455, 1365, 3003, 4945, 5715, 3990, 1470, 306, 30]
sage: C = Y.chain_complex()
sage: C.differential(4)
1365 x 3003 sparse matrix over Integer Ring
</code></pre>
<p>How big is your simplicial complex? What is its f-vector?</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17178#post-id-17178That's not very much RAM, probably the bare minimum to run Sage. If you can double or quadruple it, that might help.Wed, 07 Aug 2013 04:39:53 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17178#post-id-17178Comment by parsons.kyle.89 for <p>The <code>chain_complex</code> method already produces sparse matrices:</p>
<pre><code>sage: Y = simplicial_complexes.NotIConnectedGraphs(6,2)
sage: Y.f_vector()
[1, 15, 105, 455, 1365, 3003, 4945, 5715, 3990, 1470, 306, 30]
sage: C = Y.chain_complex()
sage: C.differential(4)
1365 x 3003 sparse matrix over Integer Ring
</code></pre>
<p>How big is your simplicial complex? What is its f-vector?</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17182#post-id-17182The f-vector is [1, 4096, 18945, 14850]. I would ideally like to work with complexes much larger than this if possible. The reason I thought that sage would return a dense matrix is the error I got.
> File "matrix_integer_dense.pyx", line 226, in sage.matrix.matrix_integer_dense.Matrix_integer_dense.__cinit__ (sage/matrix/matrix_integer_dense.c:6865)
MemoryError: out of memory allocating a matrixTue, 06 Aug 2013 05:14:25 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17182#post-id-17182Answer by John Palmieri for <p>I'm trying to convert a simplicial complex into a chain complex and then extract the differential map. However the simplicial complex is rather large and sage runs out of memory when it tries to make the conversion. However, the differential should be a very sparse matrix and there should be plenty of memory to store a sparse representation of the differential. Is it possible to have sage compute the differential as a sparse matrix? Specifically the method which gives the out of memory error is <code>chain_complex()</code>.</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?answer=15323#post-id-15323One option, if you can't get Sage to work, is to use [CHomP](http://chomp.rutgers.edu/software/). You could define your simplicial complex `X` in Sage and then do
sage: f = open('filename.txt', 'w')
sage: f.write(X._chomp_repr_())
sage: f.close()
This will save `X` in CHomP format in the file `filename.txt`. Also, from a shell prompt ("$"), run
$ sage -i -s chomp
This will compile several [CHomP programs](http://chomp.rutgers.edu/software/programs.php), including `simchain`, which you should be able to run using
$ /path/to/sage/spkg/build/chomp-20130518.p1/src/bin/simchain filename.txt output.txt
Then the file `output.txt` will have the chain complex data for your simplicial complex. It will be stored in CHomP format, but it's readable. You might be able to extract what you need straight from this file, or you can write some code to process the file, say read it into Sage and convert it to Sage matrices, and then work with those.
Tue, 06 Aug 2013 05:50:32 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?answer=15323#post-id-15323Comment by parsons.kyle.89 for <p>One option, if you can't get Sage to work, is to use <a href="http://chomp.rutgers.edu/software/">CHomP</a>. You could define your simplicial complex <code>X</code> in Sage and then do</p>
<pre><code>sage: f = open('filename.txt', 'w')
sage: f.write(X._chomp_repr_())
sage: f.close()
</code></pre>
<p>This will save <code>X</code> in CHomP format in the file <code>filename.txt</code>. Also, from a shell prompt ("$"), run</p>
<pre><code>$ sage -i -s chomp
</code></pre>
<p>This will compile several <a href="http://chomp.rutgers.edu/software/programs.php">CHomP programs</a>, including <code>simchain</code>, which you should be able to run using</p>
<pre><code>$ /path/to/sage/spkg/build/chomp-20130518.p1/src/bin/simchain filename.txt output.txt
</code></pre>
<p>Then the file <code>output.txt</code> will have the chain complex data for your simplicial complex. It will be stored in CHomP format, but it's readable. You might be able to extract what you need straight from this file, or you can write some code to process the file, say read it into Sage and convert it to Sage matrices, and then work with those.</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17165#post-id-17165I've actually found the answer to my own question. Asking for X._numeric_representation gives the desired list.Tue, 13 Aug 2013 07:00:14 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17165#post-id-17165Comment by parsons.kyle.89 for <p>One option, if you can't get Sage to work, is to use <a href="http://chomp.rutgers.edu/software/">CHomP</a>. You could define your simplicial complex <code>X</code> in Sage and then do</p>
<pre><code>sage: f = open('filename.txt', 'w')
sage: f.write(X._chomp_repr_())
sage: f.close()
</code></pre>
<p>This will save <code>X</code> in CHomP format in the file <code>filename.txt</code>. Also, from a shell prompt ("$"), run</p>
<pre><code>$ sage -i -s chomp
</code></pre>
<p>This will compile several <a href="http://chomp.rutgers.edu/software/programs.php">CHomP programs</a>, including <code>simchain</code>, which you should be able to run using</p>
<pre><code>$ /path/to/sage/spkg/build/chomp-20130518.p1/src/bin/simchain filename.txt output.txt
</code></pre>
<p>Then the file <code>output.txt</code> will have the chain complex data for your simplicial complex. It will be stored in CHomP format, but it's readable. You might be able to extract what you need straight from this file, or you can write some code to process the file, say read it into Sage and convert it to Sage matrices, and then work with those.</p>
http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17166#post-id-17166Thank you for your help. I am having success with this, but the problem now is that _chomp_repr_ renames all my vertices to integers. However, the names of the vertices are important. Is there a way to also output a table that matches up the new and old names? Mon, 12 Aug 2013 16:38:49 -0500http://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/?comment=17166#post-id-17166