Wednesday, September 23, 2015

Getting Started with islplot

Tomofumi Yuki sent me email about islplot in January 2014.  It is a seriously cool visualization tool for iteration spaces, tiles, data dependences, etc. developed by Tobias Grosser.  Here are some notes on how to get started with this tool.  The below instructions work on a Mac with OS X 10.10.5 with Anaconda for Python 3 installed.  It might help someone with a linux machine as well.

First check that you have a recent version of python, ipython, and jupyter installed.  I used the free Anaconda package to obtain all of these items.  Install Anaconda for Python 3 and then do the following:
  $ conda update conda
  $ conda update ipython ipython-notebook ipython-qtconsole
  $ conda install jupyter

For more information about ipython-notebook becoming jupyter see the iPython website.


Before you can use islplot, you are going to need islpy, which is a python wrapper for the Integer Set Library (ISL).
  $ pip install islpy

Then download islplot (git clone https://github.com/tobig/islplot) and in the islplot directory type the following:
  $ python setup.py install

Now the fun begins!  Run the jupyter notebook.  It will show up in your web browser.
  $ jupyter notebook

Then select New-->Python 3 notebook.  Copy the islplot 2D examples and 3D examples.   For me the 2D examples render better if run in ipython instead of jupyter and replace
  %pylab inline
with
  %pylab OS X

Have fun and let me know if you find a way to generate pdfs from the generated pictures.

6 comments:

  1. Hi,

    To save 2D figures as PDF, try the following:

    savefig("/path/to/your/file.pdf", dpi=300)

    You need to put this in the same cell as your plotting commands (otherwise, you will have a blank picture).

    It doesn't work with 3D pictures, as they're rendered with the HTML canvas. There is a way, though, but it is a bit more involved. You need to retrieve the canvas object in JavaScript, convert the content to an image using the "toDataURL()" method, create an image tag with this URL and save that image to file...

    There may be an easier way. I'll let you know if I find something.

    Gaël Deest

    ReplyDelete
  2. Thanks Gael! Your suggestion for the 2D figures works great.

    ReplyDelete
  3. When I installed islpy 2016.1 with "pip install islpy", I got errors from almost all the functions "multiple definition" and it failed to install.

    I am using Ubuntu 14.10 and the python version is 2.7.3. I have changed to python 3.5 the error is also there.


    ReplyDelete
    Replies
    1. I have successfully install islpy by "pip install git+https://github.com/inducer/islpy.git", guided by inducer https://github.com/inducer/islpy/issues/2

      Delete
  4. I am trying to get a pdf file for the 2D sets. I want to
    run this under a Makefile, not in a browser window.
    This code:

    from islpy import *
    from islplot.plotter import *

    plot_set_points(Set("{S[x,y]: 0 <= x <= 8 and -7 <= y <= 5}"),
    marker=".", color="gray", size=3)
    savefig("test2.pdf", bbox_inches='tight')

    complains about savefig being undefined. Any suggestions?


    ReplyDelete
    Replies
    1. I was missing some boilerplate. Tobias Grosser kindly provided the needed text for me. Here is what works for me:

      ### export PYTHONPATH=/home/sac/islplot

      # Load islpy and islplot
      from islpy import *
      from islplot.plotter import *
      import matplotlib as mpl
      import matplotlib.pyplot as plt

      fig = plt.figure()
      plot_set_points(Set("{S[x,y]: 0 <= x <= 8 and -7 <= y <= 5}"),
      marker=".", color="gray", size=3)

      plot_set_points(Set("{S[x,y]: 0 < x < 8 and 0 < y + x < 5}"),
      marker="o")

      plot_set_points(Set("{S[x,y]: 4 < x < 8 and 0 < y < 5}"),
      marker="s", color="red")

      plot_set_points(Set("{S[x,y]: 0 < x and y > -6 and y + x < 0}"),
      marker="D", color="blue")

      fig.savefig("PlotSetPoints.pdf", bbox_inches='tight', dpi=fig.dpi)

      Delete