Using physics in SageCell

209 views
Skip to first unread message

Ingo Dahn

unread,
Dec 10, 2020, 2:32:25 PM12/10/20
to sage-cell
Is there a way to use the IPython module physics (https://github.com/birkenfeld/ipython-physics)  in SageCell?

Andrey Novoseltsev

unread,
Dec 10, 2020, 11:30:17 PM12/10/20
to sage-cell
I think so - will look into installing it on our servers. You may be able to do it right away by downloading the file from a cell and loading extension from it, but that's certainly not ideal.

Andrey Novoseltsev

unread,
Dec 13, 2020, 1:20:49 PM12/13/20
to sage-cell
IPython extension are supposed to be pip-installable, which physics module is not and I would prefer not to custom patch into some place.

Getting it just for a single cell and loading works:

but I am unable to use it afterwards. What does work, however, is downloading and loading this module in one cell, then using in another linked cell. If this is a suitable option for you - great! If not - I can't say that I am excited about digging deeper into why it does not work ;-)

Ingo Dahn

unread,
Dec 13, 2020, 3:19:07 PM12/13/20
to Andrey Novoseltsev, sage-cell
Great, it is sufficient for me when it works with linked cells. 
Though it is strange and it would be attempting to have one interactive SageCell to translate any magnitude measured in SI units to a standard form.

--
You received this message because you are subscribed to a topic in the Google Groups "sage-cell" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-cell/yCbU9fnkLM8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-cell+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cell/5e9fe2a0-a8f1-4a64-9d82-f43f540f162fn%40googlegroups.com.

Andrey Novoseltsev

unread,
Dec 13, 2020, 10:33:11 PM12/13/20
to Elimboto Yohana, sage-cell
healpy and astropy are now installed, any pip-installable packages are easy to add if there is use for them!

On Fri, Dec 11, 2020 at 5:21 AM Elimboto Yohana <e...@tssfl.com> wrote:
Hi Andrey,

It is not wise to bump on others' topics, but I would recommend you consider installing these two very prominent packages, used by many astronomers/astrophysicists:



Kind regards,

Elimboto

--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cell/63d0c899-47a2-4d64-a10a-867b1b82dd12n%40googlegroups.com.

Andrey Novoseltsev

unread,
Dec 14, 2020, 1:37:55 PM12/14/20
to Elimboto Yohana, sage-cell
Hi Elimboto!

If there are cases when they don't work because of some missing optional dependencies, I'll be happy to install those as well!

I am also a bit puzzled why your messages do not show up in the google group - as far as I can tell you are allowed to post and there are no messages in moderation.

Best,
Andrey

Andrey Novoseltsev

unread,
Dec 14, 2020, 4:14:57 PM12/14/20
to Elimboto Yohana, sage-cell
You have internet access from SageCell, so you definitely can read data from GitHub - as far as for interpreting and parsing them it depends on what you want and need to process them. I think panda is installed, so your code should work - does it not? If something else needs to be installed - let me know!

On Mon, Dec 14, 2020 at 12:05 PM Elimboto Yohana <e...@tssfl.com> wrote:
Thank you, Andrey,

I will let you know If I encounter any issues. There are some warnings, but they don't cause any harm so far. I also hope the available dependencies suffice for current use. 

I do not know why my messages do not appear in the Google group, I have actually been replying to both your email and the google group!

One thing I would like to ask, If I have some astronomical data on a public repository such as GitHub, say the data is in .fits, or .h5 (HDF5) formats, can the data in these file formats be read by parsing the repo URL? Or how can this be done? Is there a limitation for some data formats?

For example, using pandas we can read .csv data file on GitHub as


Kind regards,

Elimboto


--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.

Ingo Dahn

unread,
Dec 16, 2020, 8:24:38 AM12/16/20
to sage-cell
Hi, Andrej,
With your example I get the same error in another cell and when I do load(../physics.py) and in another linked cell import physics I get the old physics not found error.
Can you point me to a page with linked cells where it works?

Ingo Dahn

unread,
Dec 16, 2020, 2:15:23 PM12/16/20
to sage-cell
Strange, when I load(physics.py), it's function Q is available even in the same cell and without any import. But s=Q(10,'m');s**2 gives the output
----> 3 s**Integer(2)  
raise UnitError('Exponents must be dimensionless') 
UnitError: Only integer and inverse integer exponents allowed

The same error occurs in linked cells. 

samuel....@gmail.com

unread,
Dec 16, 2020, 6:03:56 PM12/16/20
to sage-cell
It expects Python integers and is not happy with Sage integers.

Sage's preparser converts your 2 into Integer(2).
You can convert it back with `int`, or, better,
prevent it from converting by marking it as "raw" with `r`.

Try these:

    s**int(2)
    s**2r

Ingo Dahn

unread,
Dec 18, 2020, 12:17:02 PM12/18/20
to sage-cell
Yes, that is working, but working with physical units in SageCell remains problematic.
For example

Q(20,'g/cm^3').base is working, 
but

si(x)=Q(x,'g/cm^3').base
si(20.0)

is not, while 

def si(x, u):
    return Q(x,u).base
si(20.0, 'g/cm^3')

is working again.

Andrey Novoseltsev

unread,
Dec 20, 2020, 12:49:13 PM12/20/20
to sage-cell
Hi Ingo,

Here is what works for me:

2) put into the first cell
import urllib.request
urllib.request.urlretrieve('https://raw.githubusercontent.com/birkenfeld/ipython-physics/master/physics.py', 'physics.py')
%load_ext physics

3) execute and put into the second cell
x = 1 m
x

4) execute and get "1 m" as output, so it seems to work.

Regarding preparser issues - your life may be easier if you use "Python" as the mode for cells instead of the default "Sage".

Best,
Andrey

Andrey Novoseltsev

unread,
Dec 20, 2020, 12:58:18 PM12/20/20
to Elimboto Yohana, sage-cell
Hi Elimboto,

You typically can't feed URLs into functions that expect local file names, try something like

import h5py
import healpy

import urllib.request
urllib.request.urlretrieve('https://github.com/TSSFL/cosmo_datasets/tree/master/hdf5_data.h5', 'hdf5_data.h5')
urllib.request.urlretrieve('https://github.com/TSSFL/cosmo_datasets/blob/main/avgmap_nside512_f1250.00MHz.fits', 'avgmap_nside512_f1250.00MHz.fits')

f1 = h5py.File('./hdf5_data.h5', 'r')
f2 = maps = healpy.fitsfunc.read_map('avgmap_nside512_f1250.00MHz.fits', field=0)

Both commands still fail for me, but now because of some issues with files (perhaps some accompanying files are missing) rather than not being able to find them.

Best,
Andrey

On Tue, Dec 15, 2020 at 11:16 AM Elimboto Yohana <e...@tssfl.com> wrote:
Hi Andrey,

How do I read the following files on Github in Sage Cell?


They respectively require h5py and healpy packages to read them, so locally I would import the libraries and read them as follows:

import h5py

f1 = h5py.File('..../hdf5_data.h5', 'r') #... stands for path to the file

import healpy as hp

f2 = hp.fitsfunc.read_map('..../avgmap_nside512_f1250.00MHz.fits', field=0)

I tried


on Sage Cell but failed, I get some errors.

Kind regards,

Elimboto

On Tue, Dec 15, 2020 at 4:21 AM Elimboto Yohana <e...@tssfl.com> wrote:
Pandas works great, but so far I have tested pandas with .csv data files. I will test reading other data files such as .fits, .h5 and so on.

Thank you,

Elimboto

Andrey Novoseltsev

unread,
Dec 20, 2020, 1:10:01 PM12/20/20
to Elimboto Yohana, sage-cell
All will be available soon!

On Wed, Dec 16, 2020 at 4:12 AM Elimboto Yohana <e...@tssfl.com> wrote:
Hi Andrey,

I would suggest the installation of the following libraries/software should it be possible (most of these tools are great for animations and visualizations):

1. Plotly: pip install plotly (https://pypi.org/project/plotly/) or specify version: pip install plotly==4.14.1

3.  Python wrapper for Gnuplot (http://www.gnuplot.info/), PyGnuplot: pip install PyGnuplot (https://pypi.org/project/PyGnuplot/). Gnuplot can be installed as stand-alone. You could also install Gnuplot.py: http://gnuplot-py.sourceforge.net/ ( see demo usage here: https://www.tssfl.com/gnuplot-py-usage-4670)

4.  Mathematical Animation Engine, Manim:  pip3 install manimlib (https://github.com/3b1b/manim, see also the community version https://github.com/ManimCommunity/manim/)

5. Bokeh: pip install bokeh (https://pypi.org/project/bokeh/)

6. Gif:  pip install -U gif (https://pypi.org/project/gif/)

In addition you can install OpenCv: https://pypi.org/project/opencv-python/

Kind regards,

Elimboto

On Tue, Dec 15, 2020 at 7:15 PM Elimboto Yohana <e...@tssfl.com> wrote:
Hi Andrey,

How do I read the following files on Github in Sage Cell?


They respectively require h5py and healpy packages to read them, so locally I would import the libraries and read them as follows:

import h5py

f1 = h5py.File('..../hdf5_data.h5', 'r') #... stands for path to the file

import healpy as hp

f2 = hp.fitsfunc.read_map('..../avgmap_nside512_f1250.00MHz.fits', field=0)

I tried


on Sage Cell but failed, I get some errors.

Kind regards,

Elimboto

On Tue, Dec 15, 2020 at 4:21 AM Elimboto Yohana <e...@tssfl.com> wrote:
Pandas works great, but so far I have tested pandas with .csv data files. I will test reading other data files such as .fits, .h5 and so on.

Thank you,

Elimboto

On Tuesday, December 15, 2020, Andrey Novoseltsev <novo...@gmail.com> wrote:

Ingo Dahn

unread,
Dec 20, 2020, 4:01:17 PM12/20/20
to Andrey Novoseltsev, sage-cell
Thanks, Andrey, that works also in my linked cells.
When I use load() instead of urllib it works also in a single cell and I can use Q(x,u) from physics.py in that cell and in linked cells, e.g.
x=Q(1,'m')
x^2r
but 
x= 1 m
gives a syntax error (also in linked cells).
Now I have made up a unit transformer, which satisfies my current needs. I'll be back should I run into troubles which I cannot circumvent.
I'd prefer to stay with a SageMath kernel since I appreciate the SageMath features.
Thanks again
Ingo



--
You received this message because you are subscribed to a topic in the Google Groups "sage-cell" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-cell/yCbU9fnkLM8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-cell+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cell/5e1b2716-2759-4bd7-b03f-c518d1eedd47n%40googlegroups.com.

Andrey Novoseltsev

unread,
Dec 24, 2020, 7:29:03 PM12/24/20
to Elimboto Yohana, sage-cell
selenium and chart-studio are installed!

On Wed, Dec 23, 2020 at 6:47 AM Elimboto Yohana <e...@tssfl.com> wrote:
Bokeh dependence:

However, exporting images with bokeh to formats like png, or others, requires selenium (https://docs.bokeh.org/en/latest/docs/user_guide/export.html):

pip install selenium

Kind regards,

Elimboto

On Wed, Dec 23, 2020 at 12:39 PM Elimboto Yohana <e...@tssfl.com> wrote:
Hi Andrey,

Looks like you have installed all the modules I requested, thank you so much. I have a request for one "Plotly" dependence -- chart-studio, which can be installed as

pip install chart_studio

The previously used module plotly.plotly is deprecated.

Kind regards,

Elimboto




Elimboto Yohana

unread,
Jan 1, 2021, 3:27:54 PM1/1/21
to Andrey Novoseltsev, sage-cell
Dear Andrey,

I know I have been too demanding, making a number of installation requests. Even though, my requests intend to help make a SageCell a full-fledged computing interface. While I and users of our forum benefit a lot, I'm sure, many more people from around the globe will benefit too. Shall that be possible, I request the following software:

1. TensorFlow (https://www.tensorflow.org/) and Keras (https://keras.io/) - for Machine/deep learning, AI, data science (we want to use it for teaching and prototyping)

- pip install tensorflow
- pip install keras

2. Astroquery:  pip install --pre astroquery   (https://astroquery.readthedocs.io/en/latest/) (for astronomy/astrophysics)

This has a number of dependencies:

- numpy, astropy, requests, html5lib, six  -- they are already installed according to my tests
- beautifulsoup (pip install beautifulsoup4 -- https://pypi.org/project/beautifulsoup4/), in itself, is very needed and great for web scraping -- data science
- pyVO, keyring ( pip install pyvo, pip install keyring)

3. GetDist: pip install getdist (https://getdist.readthedocs.io/en/latest/intro.html) -- for MCMC sample analysis, plotting and GUI


5. Dash: pip install dash (https://pypi.org/project/dash/, see here https://www.datacamp.com/community/tutorials/learn-build-dash-python too) -- for machine learning/data science apps

6. Scrapy: pip install Scrapy (https://docs.scrapy.org/en/latest/intro/install.html) -- https://scrapy.org/, a web-spider/web scraper framework for data science.

7. Itikz: pip install itikz (https://pypi.org/project/itikz/#description) - Cell magic for PGF/TikZ-to-SVG rendering in Jupyter - hope it will work with SageCell (useful for teaching TikZ/PGF LaTeX)

8. Tikzplotlib: pip install tikzplotlib (https://pypi.org/project/tikzplotlib/) -- a Python tool for converting matplotlib figures into PGFPlots (PGF/TikZ), into a code that can be inserted directly in LaTeX.

Kind regards,

Elimboto




On Fri, Dec 25, 2020 at 7:56 AM Elimboto Yohana <e...@tssfl.com> wrote:
Thank you very much Andrey, appreciating.

Kind regards,
Elimboto

Andrey Novoseltsev

unread,
Jan 2, 2021, 7:46:23 PM1/2/21
to sage-cell
Happy New Year, Elimboto!

I've installed all these packages apart from nbodykit - I can't install mpi4py which is one of the required dependencies and don't understand yet what's the problem is. The rest will be available in a few hours.

Andrey Novoseltsev

unread,
Jan 2, 2021, 8:16:21 PM1/2/21
to sage-cell
Figured out nbodykit installation as well, will be available soon!

Elimboto Yohana

unread,
Jan 3, 2021, 8:11:32 AM1/3/21
to Andrey Novoseltsev, sage-cell
Happy New Year, thank you Andrey, confirming that all tools are available, already tested some and they are working great!

Kind regards,

Elimboto
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cell/105f6dd0-c4fa-4657-a83e-280643c67d7dn%40googlegroups.com.
>

Elimboto Yohana

unread,
Jan 3, 2021, 8:12:26 AM1/3/21
to Andrey Novoseltsev, sage-cell
I appreciate!


Kind regards,

Elimboto

On Sunday, January 3, 2021, Andrey Novoseltsev <novo...@gmail.com> wrote:
> Figured out nbodykit installation as well, will be available soon!
>
> --
> You received this message because you are subscribed to the Google Groups "sage-cell" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cell/a94f0b9e-faff-46da-9865-a9b8cfab3237n%40googlegroups.com.
>

Elimboto Yohana

unread,
Jan 3, 2021, 11:22:00 AM1/3/21
to Andrey Novoseltsev, sage-cell
Hi Andrey,

I was testing nbodykit, so

from nbodykit.lab import *

I got the error message

"ImportError: No module named 'tlz'

Dask array requirements are not installed.

Please either conda or pip install as follows:

  conda install dask                 # either conda install
  python -m pip install "dask[array]" --upgrade  # or python -m pip install"

Hope you can check this.

Kind regards,

Elimboto

Elimboto Yohana

unread,
Jan 3, 2021, 12:46:47 PM1/3/21
to Andrey Novoseltsev, sage-cell
I also got another error "AttributeError: 'DummyMod' object has no attribute 'startswith'" when testing Dash:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

The error is caused by the last line, "app =...". It may have something to do with setting the environment variable.

Kind regards,

Elimboto


Andrey Novoseltsev

unread,
Jan 10, 2021, 10:53:31 PM1/10/21
to sage-cell
Done!

Andrey Novoseltsev

unread,
Jan 10, 2021, 10:55:20 PM1/10/21
to sage-cell
Hi Elimboto,

No idea what is happening here, it is installed via pip just like other packages - if you figure out what exactly does it want, please do let me know!

Best,
Andrey

Elimboto Yohana

unread,
Jan 11, 2021, 1:56:49 AM1/11/21
to Andrey Novoseltsev, sage-cell
Thank you, Andrey, tested NBODYKIT, works well so far.

I also find it is worth installing NLTK: http://www.nltk.org/install.html

Kind regards

Elimboto



--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.

Elimboto Yohana

unread,
Jan 11, 2021, 1:59:18 AM1/11/21
to Andrey Novoseltsev, sage-cell
Hi Andrey,

Thank you. Regarding Dash, I will keep on exploring, and let you know as soon as possible once I figure out what would be the fix.

Kind regards,

Elimboto

--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.

Andrey Novoseltsev

unread,
Jan 11, 2021, 6:07:03 PM1/11/21
to sage-cell
NLTK is installed!

Elimboto Yohana

unread,
Jan 12, 2021, 3:47:00 AM1/12/21
to Andrey Novoseltsev, sage-cell
Thank you Andrey. I quickly tested NLTK, there is a module called tkinter (used for some tasks with NLTK) missing according to this error message "
ModuleNotFoundError: No module named '_tkinter'".

tkinter (for Python 3, and Tkinter for Python 2) is a standard GUI library for Python.

I'm not sure if it can be installed using pip, but for Python 3, it can be installed via the command 
(change the command appropriately depending on the type of the Linux server):

sudo apt-get install python3-tk

There are a number of suggestions here: https://askubuntu.com/questions/1224230/how-to-install-tkinter-for-python-3-8

Kind regards,

Elimboto

Elimboto Yohana

unread,
Jan 12, 2021, 5:38:38 AM1/12/21
to Andrey Novoseltsev, sage-cell
Hi Andrey,

I tested,

from flask import Flask
import dash

server = Flask(__name__)

and got the same error as before (with Dash application) "AttributeError: 'DummyMod' object has no attribute 'startswith'".

Since Dash is written on top of Flask, Plotly. js, and React. js, the error seems to be related to Python Flask, it may have to do with the environment variable settings: https://stackoverflow.com/questions/31431755/flask-error-attributeerror-nonetype-object-has-no-attribute-startswith.

Kind regards,

Elimboto

--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.

Elimboto Yohana

unread,
Jan 12, 2021, 7:23:19 AM1/12/21
to Andrey Novoseltsev, sage-cell
I will take a break from requesting installations of new packages unless there will be something so much needed (I can for the time being report on dependencies for the already installed packages, if any). Here are packages I used locally, hoping they can benefit others on Sage Cell Server:

1. SpicePy: pip install spiceypy (https://pypi.org/project/spiceypy/ -- an essential tool for scientists and engineers alike in the planetary science field for Solar System Geometry).

2. Theano: pip install Theano: (https://pypi.org/project/spiceypy/ -- for defining, optimizing, and efficiently evaluating mathematical expressions involving multi-dimensional arrays).

3. Xarray: pip install xarray (This has some optional dependencies, http://xarray.pydata.org/en/stable/installing.html) - I actually need it because I wanted to play with some weather data from GitHub, Scipy netcdf fails to open and read the files, and the alternative to that seems to be xarray.

Kind regards,

Elimboto

Andrey Novoseltsev

unread,
Jan 24, 2021, 11:32:51 AM1/24/21
to sage-cell
Hi Elimboto!

Thanks for your patience - I've finally installed the packages you have asked for and compiled Python with tkinter support, although I am not sure it will achieve what you want - you can't open TK windows via SageMathCell. What all other graphics backends are doing is saving results to a file and then this file is displayed in the user browser. Do you plan to do the same? Incidentally, I just got a question about turtle graphics support which also relies on tkinter, but their examples are not working right away because of display issues.

As for dash - what are you trying to achieve with it? We can set environment variables or create some configuration files, but I need to have more direct instructions and understanding of what is going on. There are plenty of packages installed on public servers and vast majority just needs to be installed without any extra tinkering.

Best,
Andrey

Samuel Lelièvre

unread,
Jan 24, 2021, 11:40:03 AM1/24/21
to Andrey Novoseltsev, sage-cell
Le dim. 24 janv. 2021 à 17:32, Andrey Novoseltsev:
>
> [...] Incidentally, I just got a question about turtle graphics support
> which also relies on tkinter, but their examples are not working
> right away because of display issues.

Maybe ipyturtle would help?

https://pypi.org/project/ipyturtle/
https://github.com/gkvoelkl/ipython-turtle-widget

Elimboto Yohana

unread,
Jan 25, 2021, 1:34:44 AM1/25/21
to Andrey Novoseltsev, sage-cell
Thank you Andrey for your reply and for installing the packages.

Tkinter and turtle are installed but none of the examples that use them seem to work as you already pointed out. For tkinter I have tried to save results to a file and then try to plot, but the common error for now is "TclError: no display name and no $DISPLAY environment variable". Try for example the code below and see how you could figure out to save results and then plot:

import nltk
from nltk.corpus import treebank
nltk.download('treebank')
t = treebank.parsed_sents('wsj_0001.mrg')[0]
print(t)
t.draw()

There are a number of discussions on the internet on how to do this, but I have not succeeded, they need more time to explore and test.

Yes, for other plotting backends, the option is either displaying the plots by inlining them on the web or saving the results to html and then displaying the figure on a browser upon clicking, the second option works well for interactive Plotly plots (see attached).

As for Dash, the problem seems to be Flask environment variable settings (PATH environment variable) because Dash is built on top of it. This may look something close to what is discussed at https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-files

Dash is useful for creating interactive web analytics/apps.

Kind regards,

Elimboto
--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.
test-plot.png

William Stein

unread,
Jan 25, 2021, 1:57:30 AM1/25/21
to e...@tssfl.com, Andrey Novoseltsev, sage-cell
> There are a number of discussions on the internet on how to do this, but I have not succeeded, they need more time to explore and test.

For what it is worth (since cocalc is not sagecell), you can do this in https://cocalc.com as follows:

1. In a CoCalc project, click +New --> "X11 Desktop"
2. In the terminal in the upper left, type "python3".
3. Paste in your code. 

This is what it looks like:

image.png

NOTE: Your code downloads a data file from the internet and free cocalc project block outside network, so you'll have to upload the file to cocalc first.

CoCalc does have a button to share things publicly (to https://share.cocalc.com/share/), and things shared there can be used by people without creating a cocalc account.

> Yes, for other plotting backends, the option is either displaying the plots by inlining them on the web or saving the results to html and then displaying the figure on a browser upon clicking

Technically the way cocalc is solving this particular problem is a third option -- run an X11 server (in this case xpra), and implement an X11 client right in the browser.     It was a lot of work, but it at least results in something that fullly supports tkinter, which is sometimes very valuable to people...

 -- William

Elimboto Yohana

unread,
Jan 25, 2021, 10:56:51 AM1/25/21
to William Stein, Andrey Novoseltsev, sage-cell
Thank you William for pointing out CoCalc. I tested the code, it took some time before producing results, there is stricter limitation on CPU usage and time I guess.

Hope Tkinter will be installed on Sage Server sometime in the future, it is community-driven, conveniently brings many things together, and works very well out of the box for most of the installed applications.


I tested Theano and some printing/graphing dependencies seem to be lacking following the error "RuntimeError: ('Failed to import pydot. You must install graphviz and either pydot or pydot-ng for `pydotprint` to work.', 'Install the python package pydot or pydot-ng. Install graphviz.')".

The missing dependencies are all pip installable:

- pip install pydot (https://pypi.org/project/pydot/)
- pip install graphviz (https://pypi.org/project/graphviz/)

Kind regards,

Elimboto

Ingo Dahn

unread,
Feb 6, 2021, 7:26:52 AM2/6/21
to sage-cell
I am experimenting with another module (pyswarms) which isn't installed on Sagecells. I can work with it in CoCalc after installing it into my project.
Such a situation, requiring particular modules for particular purposes, may happen frequently and I wonder whether there could be provided a way to install modules for a session such that they can be called using import, perhaps as another parameter for sagecells or for collections of linked sagecells. Perhaps internally some statistics could be maintained for Andrey to decide whether a permanent installation on the Sagecell system is worth the effort.

Andrey Novoseltsev

unread,
Feb 7, 2021, 12:05:29 PM2/7/21
to sage-cell
Ingo: SageMathCell uses preforked kernels, so when you are trying to execute a cell it is already up and running, waiting for your code. If you can activate extra modules from a running session, e.g. by downloading and importing a module, you can already do it. If you want to install something on the system and then start a kernel - that's completely different approach (which is available to you in CoCalc). The rate of requests for new modules is not that big, so I am happy to add anything you want and it will be available by default. Of course, this assumes that this anything can be installed via standard means and be functional.

Elimboto: this is not the case for Tk, Turtle, or Dash/Flask. I could not figure out a way to use Turtle on on a headless machine without displaying anything, although it seems there are ways to save plots after they have been shown. If you can dig up instructions on how to do it - I will be happy to incorporate them. For Dash I am still unclear what exactly you are are trying to accomplish and so what should work. If you are trying to create some interactive interface, you are unlikely to do anything apart from using ipywidgets or its @interact wrappers. All communication in SageMathCell is passing through IPython framework, nothing else is going to work without substantial efforts like implementing X11 protocol similar to William's work in CoCalc.

pyswarms, pydot, graphviz, folium and openpyxl have been added to public servers!

Best,
Andrey

matteo.mi...@gmail.com

unread,
Feb 9, 2021, 11:24:48 AM2/9/21
to sage-cell
Hi all! First of all thank you Andrey for SageMathCell. Sorry if I use this thread but I have seen that here there are many requests about installation of specific python libraries.

So, if it's useful for you too and Andrey agrees, I'd like to try the following libraries in SageMathCell (that I use mainly with a modified version of the script sagecell-client.py that works easily on a smartphone with python installed as app) to find numerical solutions of PDEs:
Thank you
Regards
Matteo

Elimboto Yohana

unread,
Feb 10, 2021, 1:09:47 PM2/10/21
to Andrey Novoseltsev, sage-cell
Hi Andrey,

Thank you very much for the great work. I think we can suspend some installations/configurations until later when we are confident about instructions. Until now, there are already enough packages installed, I'm sure some can be used in a clever way to achieve what would be done by the missing packages.

Kind regards,

Elimboto



--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.

Andrey Novoseltsev

unread,
Feb 14, 2021, 5:05:39 PM2/14/21
to sage-cell
Hi Matteo,

I've install fipy (should be available in a few hours), but sfepy is not available via pip, so it is not obvious to me how to make it available to Sage.

Best,
Andrey

matteo.mi...@gmail.com

unread,
Feb 18, 2021, 12:55:20 AM2/18/21
to sage-cell
Hi Andrey, thank you very much for your time!

I tried Fipy and it works very well. I used an example script (slightly modified) by Fipy authors (only to test the package) and I've seen that it works only if I enable "Python" as interpreter. If I use "Sage" interpreter I obtain error  "No attribute 'shape'".

The two permalink are the following: the first is ok with Python interpreter, the second can't work due to the "Shape" error when executed with Sage interpreter:


I'm just curious: why it happens?

Another question: can I choose the interpreter (maxima, python, octave, sage, gap, html, ecc...) available on web page of SageMathCell also by using the script sagecell-client.py? Inside this script, where I should set the interpreter for execution of the string in the filed "a.execute_request(...)"?

About Sfepy you are right, I know it is not available a pip version of it. Do you think a possible solution could be to install permanently Miniconda for Linux, so user could use both "!pip install ..." and "!conda install ...." in the temporary opened cell before a calculation? Every installation on local cell (via pip or conda) would be deleted after execution. I propose this only to solve problems related to python libraries that can't be installed with common "pip" but that can be installed only with "conda" when user needs to try some of these libraries, only for quick tests, because installable conda packages are usually pre-compiled libraries for some platforms, like Sfepy as we can see at https://anaconda.org/conda-forge/sfepy.

Do you think the command "!conda install ..." could work like "!pip install ..." in current cell by using the "--target" option, in order to install temporary a python lib inside the working cell, only to test it, not to install it permanently?

And last question, with both "!conda install ..." and "!pip install ..." executed inside the current working cell is it possible to ignore dependencies installation by using the pip option "--no-dependencies"? This because I prefer that, for example, a Scipy based python library (that I'd like to test on SageMathCell only one time) uses the SageMathCell built-in Scipy version instead of to install in current cell the entire Scipy lib as dependency (that is time consuming).


Thank you!
Regards
Matteo

Elimboto Yohana

unread,
Mar 3, 2021, 1:35:28 AM3/3/21
to matteo.mi...@gmail.com, sage-cell
Hi Andrey,

I was manipulating and automating excel/Google spreadsheet reports with Python, Pandas and Jinja2, I found that I need WeasyPrint to convert HTML reports to PDF. You can install WeasyPrint, https://pypi.org/project/WeasyPrint/ as deems fit.

Thank you and kind regards,

Elimboto

--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.

Andrey Novoseltsev

unread,
Mar 7, 2021, 5:09:27 PM3/7/21
to sage-cell
WeasyPrint will be available shortly!

Andrey Novoseltsev

unread,
Mar 7, 2021, 5:20:15 PM3/7/21
to sage-cell
On Wednesday, 17 February 2021 at 22:55:20 UTC-7 matteo.mi...@gmail.com wrote:
Hi Andrey, thank you very much for your time!

I tried Fipy and it works very well. I used an example script (slightly modified) by Fipy authors (only to test the package) and I've seen that it works only if I enable "Python" as interpreter. If I use "Sage" interpreter I obtain error  "No attribute 'shape'".

The two permalink are the following: the first is ok with Python interpreter, the second can't work due to the "Shape" error when executed with Sage interpreter:


I'm just curious: why it happens?

Hi Matteo,

I see what is happening, but don't understand what is the issue. It is, however, not specific to SageMathCell, perhaps ask on sage-support for more help?


Another question: can I choose the interpreter (maxima, python, octave, sage, gap, html, ecc...) available on web page of SageMathCell also by using the script sagecell-client.py? Inside this script, where I should set the interpreter for execution of the string in the filed "a.execute_request(...)"?

No, handling of the language setting is done in JavaScript https://github.com/sagemath/sagecell/blob/master/js/session.js#L322 which is bypassed by Python scripts. For your case, however, all is done is wrapping the code in exec.

About Sfepy you are right, I know it is not available a pip version of it. Do you think a possible solution could be to install permanently Miniconda for Linux, so user could use both "!pip install ..." and "!conda install ...." in the temporary opened cell before a calculation? Every installation on local cell (via pip or conda) would be deleted after execution. I propose this only to solve problems related to python libraries that can't be installed with common "pip" but that can be installed only with "conda" when user needs to try some of these libraries, only for quick tests, because installable conda packages are usually pre-compiled libraries for some platforms, like Sfepy as we can see at https://anaconda.org/conda-forge/sfepy.

Do you think the command "!conda install ..." could work like "!pip install ..." in current cell by using the "--target" option, in order to install temporary a python lib inside the working cell, only to test it, not to install it permanently?

"pip installed" packages are actually installed by pip included in Sage, so to make it work in the same way conda has to be included into Sage. I think that the efforts now are on making Sage a pip-installable  library instead of adding more package managers into Sage.

And last question, with both "!conda install ..." and "!pip install ..." executed inside the current working cell is it possible to ignore dependencies installation by using the pip option "--no-dependencies"? This because I prefer that, for example, a Scipy based python library (that I'd like to test on SageMathCell only one time) uses the SageMathCell built-in Scipy version instead of to install in current cell the entire Scipy lib as dependency (that is time consuming).

Can you give a full example you are working with so I can see what is happening? Seems to me that you can pass --no-dependencies option just fine.

Thank you!
Andrey

Elimboto Yohana

unread,
Mar 10, 2021, 6:09:59 PM3/10/21
to Andrey Novoseltsev, sage-cell
Thank you Andrey for installing WeasyPrint, I tested it, and working fine.

Kind regards,

Elimboto

--
You received this message because you are subscribed to the Google Groups "sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-cell+...@googlegroups.com.

matteo.mi...@gmail.com

unread,
Mar 16, 2021, 1:57:33 PM3/16/21
to sage-cell
Hi Andrey! Thank you for your answer and sorry for my delay.

For fipy the 'exec' is the solution and it helps me a lot during manipulating of strings to send to SageMathCell with sagecell-client, so to use fipy with the sagecell-client script user needs only to execute python string with 'exec' inside Sage language.

About sfepy and other python libraries installable via conda (no pip), I tested a way to install temporary a miniconda distribution in order to install some python libraries that can't be installed with common pip: this way is not so convenient because it is time/power consuming, but could be a starting point for me:


I have a problem about activating personal environment with 'conda activate myenv', I will try to solve it if I can.

'conda install' has  --no-deps option to install package without dependencies, but I'm trying to understand if it is possible to install temporarily only dependencies not present in SageMathCell (I'd like to avoid to install scipy, numpy, etc.. in conda environment, because them are already built-in).

For now I'm doing some experiments with conda on linux by using SageMathCell and when I will have a working solution that can install sfepy and run any example script of that package, I will try to download from the cell the zipped folder with miniconda, sfepy and all dependencies for future use. This only to test on the fly some not-pip installable python libraries, available only via conda-forge or conda.


Thank you again Andrey for your continued support on this powerful and versatile cloud computing software (SageMathCell).
Best regards
Matteo
Reply all
Reply to author
Forward
0 new messages