Ask Your Question

droberts01's profile - activity

2023-11-17 09:50:36 +0100 received badge  Notable Question (source)
2022-04-28 21:22:25 +0100 received badge  Popular Question (source)
2021-07-21 09:06:00 +0100 received badge  Famous Question (source)
2020-09-03 14:13:57 +0100 received badge  Great Question (source)
2020-09-03 04:02:44 +0100 received badge  Notable Question (source)
2020-09-02 07:17:54 +0100 commented question Fast numerical computation of eigenvalues

I'm having a similar issue with Sage notebooks on my AMD machine! Maybe OpenBLAS is being forced to run in single-threaded mode? I wish I knew how to change this...

2020-09-01 09:08:28 +0100 received badge  Good Question (source)
2020-09-01 03:55:33 +0100 received badge  Nice Question (source)
2020-09-01 00:21:03 +0100 asked a question Why is Numpy slower inside of a Sage notebook?

The Issue

I'm running the following numpy benchmark inside of Sage, and comparing it with the results I get by just running Python.

import numpy as np
import time
n = int(10000)
A = np.random.randn(n,n).astype('float64')
B = np.random.randn(n,n).astype('float64')
start_time = time.time()
nrm = np.linalg.norm(np.matmul(A,B))
print(" took {} seconds ".format(time.time() - start_time))
print(" norm = ",nrm)

Output from my Python3 Jupyter notebook:

 took 3.2952768802642822 seconds 
 norm =  999954.1727829538

Output from my SageMath Jupyter notebook:

 took 35.73347020149231 seconds 
 norm =  999976.601519372

Wow. So Numpy runs 10x faster when run inside of a standard Python environment, rather than, e.g. inside of a Sage environment in a Jupyter notebook.

The Cause

I checked the version of numpy installed, especially the BLAS info, and got identical results for both the Sage and standard Python notebook environments. I then checked htop and found the issue: the Python notebook fully utilizes all of the threads on my AMD CPU (all 32 of them) whereas the Sage notebook only uses a single core. This is enough to explain the massive speed difference on my machine.

Is there a way to enable Jupyter's Sage environment to give Numpy access to all of the CPU cores? I tried adjusting the SAGE_NUM_THREADS environment variable to be greater than one but when I launch the Jupyter service and then open a Sage environment SAGE_NUM_THREADS is somehow auto-set back to 1. This bug doesn't show up when I launch the standard Python environment using the same Jupyter service.

Related:

https://ask.sagemath.org/question/445...

Note: Something interesting to note: this slowdown is not observed on my Intel CPU, which uses MKL and runs at the same speed independent of which environment is calling Numpy.

2020-05-29 12:23:30 +0100 received badge  Popular Question (source)
2019-09-05 01:02:25 +0100 commented question Sagemath for Windows: a giant headache

Haha PhD candidate here, definitely will fund, maybe later in my career though!

2019-09-04 06:33:12 +0100 received badge  Scholar (source)
2019-09-04 06:33:10 +0100 received badge  Supporter (source)
2019-09-03 08:49:36 +0100 received badge  Nice Question (source)
2019-09-03 08:45:18 +0100 received badge  Student (source)
2019-09-03 08:41:51 +0100 received badge  Editor (source)
2019-09-03 07:22:24 +0100 asked a question Sagemath for Windows: a giant headache

Hi everyone,

I've encountered two serious issues when trying to use Sagemath on Windows:

1) It is incompatible with any package that requires Anaconda for installation (e.g. QuTiP, etc..)

2) It is incompatible with popular commercial-grade Python IDE's (e.g. PyCharm will not recognize the Sage interpreter)

The reason why this is specific to Windows is because, on Mac, Sage can be installed through Anaconda (see https://anaconda.org/conda-forge/sage (anaconda.org/conda-forge/sage) for details), thus circumventing the above issues. So everything works like a dream on Mac OS X. Here are my questions:

1) Why is there such a disparity between the Windows and Mac situations?

2) Can we expect Anaconda support anytime soon? Or is it a waste of time refreshing the sagemath section of the https://anaconda.org/conda-forge/sage (conda-forge) site from time to time?

If anyone knows how any of these issues might be resolved (possibly by not needing to use Anaconda), please let me know! In any case, if I can't resolve these issues, then I am most likely going to revert to using Mathematica, which is sad, because I like how Sage is designed.

2019-09-03 06:42:09 +0100 received badge  Organizer (source)