ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 10 Jan 2019 01:54:55 -0600Is it possible to import machine learning libraries in Sage?http://ask.sagemath.org/question/44977/is-it-possible-to-import-machine-learning-libraries-in-sage/I'm doing a machine learning program in Sage and I wish to use Tensorflow or Scikit learn. However, I don't see any way to import the modules in Sage. I'm wondering if it is possible to import other modules outside of Sage into Sage, or if Sage is essentially a black box system that doesn't work with any other module. Stockfish3709Thu, 10 Jan 2019 01:54:55 -0600http://ask.sagemath.org/question/44977/Differences between Python2 Sagemath and Python3 Sagemath?http://ask.sagemath.org/question/42932/differences-between-python2-sagemath-and-python3-sagemath/ With sagemath looking to move away from python2 in 2020 and as a new user of sagemath, I wanted to know what the differences are between Python2 Sagemath and Python3 Sagemath?
At the moment sagemath is not fully compatible with python3 and I have been told to expect problems. I want to know how serious these problems are and how frequent they are. I would then be able to know if using python3 sagemath is worth the trouble.number123Wed, 11 Jul 2018 14:35:20 -0500http://ask.sagemath.org/question/42932/cokernel of a map between modules over polynomial ringshttp://ask.sagemath.org/question/42154/cokernel-of-a-map-between-modules-over-polynomial-rings/Define a polynomial ring $R$ as $F_{2}\left[x_{1},x_{1}^{-1},....x_{D},x_{D}^{-1}\right]$ where $D$ is the dimension and $\mathbb{F}_{2}$ is a binary field.
Let $G$ be a free $R$-module of some labels and has rank $t$. $P$
be a free $R$-module of Pauli operators. $\sigma$ is a map from
$G$ to $P$. I want to write a snippet to calculate the cokernel
of this map.
Just for example (taken from page 54 of arxiv.1305.6973 or page 41 of arxiv.1607.01387),
though this is not essential for the question, I can have two ``interaction''
terms in terms of 2-dimensional Pauli operators $X$, $Z$ and Identity
operator $I$ on 4 sites with two 2-dimensional systems per site as
$
II(0,0)-IX(0,1)-XI(1,0)-XX(1,1)
$
and
$
ZZ(0,0)-IZ(0,1)-ZI(1,0)-II(1,1)
$
where on each site $\left(x,y\right)$ (mentioned in the bracket after
the Pauli operators), the first(second) Pauli acts on the first(second)
two dimensional system on that site. The map $\sigma$ can be written
as
$
\sigma=\left(\begin{array}{cc}
y+xy & 0 \\
x+xy & 0 \\
0 & 1+y \\
0 & 1+x
\end{array}\right)
$
where for example, $y+xy$ is a polynomial that specifies the action
on the first two dimensional system as
$
y+x y=0 \hspace{1mm} x^0 y^0+ 1 \hspace{1mm} x^0 y^1+0 \hspace{1mm} x^1 y^0 +1 \hspace{1mm} x^1 y^1
$
where the exponents are the coordinates of the sites and coefficients
$0$ and $1$ imply whether there is a Pauli acting or not.arpitTue, 24 Apr 2018 21:02:38 -0500http://ask.sagemath.org/question/42154/Modules over non PID'shttp://ask.sagemath.org/question/36920/modules-over-non-pids/ Is there any way how to work with modules over general rings? Most of the functions work only for modules over PID. For instance `span` and `submodule`do not work if there are zero divisors. Ho does one work with submodules, say over `Integers(8)`, or take the span of vectors over a non PID?xhimiSun, 12 Mar 2017 10:46:37 -0500http://ask.sagemath.org/question/36920/Can I create a sage file, and import it as a Python module?http://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/ I am trying to create a file that produces some data using sage specific modules (eg graphs. ).
Is there a way that I can save this file and then import it in a Python shell and / or in a Sage shell?
The problems I have encountered so far are:
- if I try to save the file as filename.py and import it as a module in a Python or Sage shell, Python/ Sage won't recognize the sage specific functions (which makes sense)
- if I try to save the file as filename.sage and import it as a module in a Sage shell, I get the error "No module named filename"
I am working from an Ubuntu terminal.
Thank you!silvia_n_netsTue, 28 Jun 2016 11:14:23 -0500http://ask.sagemath.org/question/33954/Organizing files in Sage Cloud/moduleshttp://ask.sagemath.org/question/27081/organizing-files-in-sage-cloudmodules/ I am working in sage cloud, in a worksheet (sagews). I wrote some classes and methods so far and I wish to keep them separated from my new code/organize my projects in files that I can import from.
I want something like
file Resources.(.py? .sage? .sagews?) with classes Foo, Foo2, Foo3
and to use this in a new spreadsheet:
<code>
from Resources import Foo2
</code>
While this seems like a basic question, the only thing I could discover on this topic was a similar unanswered question: http://ask.sagemath.org/question/26040/import-module-from-another-file-in-cloud/
How do I do this? How do I split a project in several files(modules?) that I could import from?
WizqWed, 10 Jun 2015 06:43:12 -0500http://ask.sagemath.org/question/27081/Import Module from Another File in Cloudhttp://ask.sagemath.org/question/26040/import-module-from-another-file-in-cloud/Hi,
I am using Sage in the cloud. I have a project folder (obviously) and within that I created a worksheet and a sub-dir called "functions". Can I create files within "function" and then import modules from within those files in my main worksheet.
e.g. in top level main file:
import myFunc from functions/function_file.py
This would help keep things a bit tidier.
Thanks in advance. j0nrThu, 05 Mar 2015 13:51:27 -0600http://ask.sagemath.org/question/26040/calling sage from pythonhttp://ask.sagemath.org/question/24419/calling-sage-from-python/ Hi everyone,
I use python 2.7 anaconda distribution, and I'm really happy with it, except I'd like to use a sage module inside anaconda python.
Is a way to import some sage modules into a anaconda python, in a "from sage.all import *" fashion ?
thank you in advance,
cheers,
yan
yanncheTue, 07 Oct 2014 09:58:16 -0500http://ask.sagemath.org/question/24419/Does sage have facilities to help prove theorems?http://ask.sagemath.org/question/23222/does-sage-have-facilities-to-help-prove-theorems/ Does sage have modules that assist with proving theorems? Example, we give a few axioms and then a statement we want to prove. Then sage will list the formal proof.ensabaSat, 05 Jul 2014 06:47:36 -0500http://ask.sagemath.org/question/23222/How to use Sage in terminal?http://ask.sagemath.org/question/8842/how-to-use-sage-in-terminal/Dear All,
I am trying to use sage in Mac OSX. I already installed the binary distribution.
The problem is I cannot access the sage environment in terminal and when I
run sage in Mac it opens Sage Notebook. The thing is I am trying to install
PyMVPA and Nibabel in Sage, but as I look into guides I need to go through these
steps according to:
http://sites.google.com/site/neuroinformaticsimageanalysis/home/sage-in-medical-imaging
Install pynifti and pymvpa
-Download latest versions of pynifti and pymvpa
-In the unpacked directories of pynifti and pymvpa and within a Sage environment
(i.e. " $ sage -sh "), install the modules. I.e. " $ make all " and " $ python setup install ".
Check installation by " sage: import pynifti " and " sage: import mvpa "
and when I type "sage -sh" in terminal it opens the sage process and the notebook in Safari!
So I don't know where and when I need to type the rest which are "make all" and "python setup install"
I would be really grateful if someone helps.NajiSun, 01 Apr 2012 10:34:26 -0500http://ask.sagemath.org/question/8842/How do I install python modules, or use a different version of python? (with sage)http://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/I have several versions of python, as well as the one included with sage. I want to use the svgwrite module in /Library/Frameworks/Python.framework/Versions/2.7/bin/python , but sage does not have it.
I want to run the following (combined with some output from sage)
import svgwrite
dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.line((0, 0), (10, 0), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.text('Test', insert=(0, 0.2), fill='red'))
dwg.save()
It runs fine with the calls
python drawT.sage
python2.7 drawT.sage
But when I try to call it directly or with a system call in sage I have problems.
sage: import sys
sage: os.system("python /path/drawT.sage")
Traceback (most recent call last):
File "/path/drawT.sage", line 1, in <module>
import svgwrite
ImportError: No module named svgwrite
256
sage: os.system("which python")
/Applications/sage/local/bin/python
0
Okay fine, sage's installation does not have the module. But now I try to force it to use the installation that does have it:
sage: os.system("which python2.7")
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
0
sage: os.system("python2.7 /path/drawT.sage")
Traceback (most recent call last):
File "/path/drawT.sage", line 1, in <module>
import svgwrite
ImportError: No module named svgwrite
256
How can I install svgwrite, or invoke a given python installation from sage?
alejandroericksonMon, 30 Apr 2012 16:21:41 -0500http://ask.sagemath.org/question/8927/How to import 3rd party modules into SAGE?http://ask.sagemath.org/question/9754/how-to-import-3rd-party-modules-into-sage/In SAGE, I can import math or numpy from within a script, but I'm unable to import stuff located in, for example, /usr/lib/python2.7/dist-packages/. How could I fix that?
Thanks in advance.FaustoThu, 31 Jan 2013 00:38:17 -0600http://ask.sagemath.org/question/9754/Sage is not updating modules imported by an attached filehttp://ask.sagemath.org/question/9221/sage-is-not-updating-modules-imported-by-an-attached-file/My file structure looks like:
<pre>
project/
__init__.py
project.py
bounds.py
</pre>
project.py looks approximately like:
<pre>
import sys
import os
import bounds
def myfunction(g):
if has_bound(g):
...
def has_bound(g):
lbound = 1
for name, obj in inspect.getmembers(bounds, inspect.isclass):
if obj.__module__ == 'bounds':
new_bound = obj.bound(g)
if new_bound > lbound:
lbound = new_bound
return lbound
</pre>
bounds.py:
<pre>
import abc
class BoundBase(object):
@staticmethod
@abc.abstractmethod
def bound(g):
return
class SpecificBound(LowerBoundBase):
@staticmethod
def bound(g):
return 5
</pre>
Now, I start a Sage session in the Terminal and do <code>attach project.py</code>. I can even make changes in project.py and see the results immediately in Sage. The problem is that if I change something in bounds.py, Sage won't pick up on the changes. I've tried combinations of reset(), detach(), attach(), load(), but the only thing that works is quitting Sage completely and restarting it. There must be a better way!patronicsThu, 09 Aug 2012 09:18:57 -0500http://ask.sagemath.org/question/9221/Structuring and naming moduleshttp://ask.sagemath.org/question/9219/structuring-and-naming-modules/I'm starting a new research project, and I'm confused about the best way to organize everything.
I'll need to write a few functions that compute invariants on Graphs, but the trick is that each function needs to call lots of smaller functions that compute bounds for the invariant, and then choose the min/max of these bounds and return it. I'd like the smaller functions to be "plug and play," so that other people on the project can come up with new bounds computers, drop them in the folder, and have them automatically used.
Currently, my file structure looks like this:
<pre>
project/
__init__.py
project.py
bounds/
__init__.py
boundcomputer1.py
boundcomputer2.py
...
</pre>
If I start a Sage session and <code>attach project.py</code>, the code seems to work correctly.
If I do <code>sage -t project.py</code>, it complains about not being able to find the <code>bounds</code> module.
Also, how do I get the functions in <code>project.py</code> to show up under a <code>project</code> namespace, so that I can type <code>project.compute_invariant()</code>, where <code>compute_invariant()</code> is a function defined inside <code>project.py</code>?
I'm happy to take any advice on best practice for a project like this.patronicsWed, 08 Aug 2012 10:17:21 -0500http://ask.sagemath.org/question/9219/How to import a module at startup?http://ask.sagemath.org/question/8929/how-to-import-a-module-at-startup/Hello, I'm new to sage and have been trying to import numpy when starting up sage for a few hours now. I've searched everywhere and so far i've tried the following options:
Editing the import_all variable in .sage/ipython/ipythonrc
import_all numpy
I've also tried adding some execute instructions in the ipythonrc
execute print "test"
execute from numpy import *
The thing is, the first line works and writes "test" to the console, but the import statement doesn't seem to work.
Finally, I've edited the main function in .sage/ipython/ipy_user_conf like this:
def main():
from numpy import *
o = ip.options
ip.ex('from numpy import *')
main()
But this doesn't seem to work either. When I try to create a new column matrix like this:
a=matrix("[1; 2; 3; 4]")
I get an error which is solved by manually importing the numpy libs.
Is there any other way to automatically load modules at startup? Am I missing something?
Thanks in advance for any help.
LevelpartWed, 25 Apr 2012 12:28:21 -0500http://ask.sagemath.org/question/8929/