提交 13b76018 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #4505 from kmike/d3viz

d3viz improvements for Python 3
...@@ -35,7 +35,7 @@ install: ...@@ -35,7 +35,7 @@ install:
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then conda create --yes -q -n pyenv mkl python=2.6 numpy=1.7.1 scipy=0.11 nose=1.3.0 pyparsing=1.5 pip flake8=2.3 six=1.9.0 pep8=1.6.2 pyflakes=0.8.1 sphinx; fi - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then conda create --yes -q -n pyenv mkl python=2.6 numpy=1.7.1 scipy=0.11 nose=1.3.0 pyparsing=1.5 pip flake8=2.3 six=1.9.0 pep8=1.6.2 pyflakes=0.8.1 sphinx; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then conda create --yes -q -n pyenv mkl python=3.3 numpy=1.9.1 scipy=0.14.0 nose=1.3.4 pyparsing=1.5 pip flake8=2.3 six=1.9.0 pep8=1.6.2 pyflakes=0.8.1 sphinx; fi - if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then conda create --yes -q -n pyenv mkl python=3.3 numpy=1.9.1 scipy=0.14.0 nose=1.3.4 pyparsing=1.5 pip flake8=2.3 six=1.9.0 pep8=1.6.2 pyflakes=0.8.1 sphinx; fi
- source activate pyenv - source activate pyenv
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install pydot; fi - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install pydot; else pip install pydot-ng; fi
- pip install . --no-deps - pip install . --no-deps
- pip install flake8-future-import nose-parameterized==0.5.0 - pip install flake8-future-import nose-parameterized==0.5.0
......
...@@ -464,7 +464,7 @@ The graph after optimization: ...@@ -464,7 +464,7 @@ The graph after optimization:
Picture Printing of Graphs Picture Printing of Graphs
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
``pydotprint`` requires graphviz and pydot. ``pydotprint`` requires graphviz and either pydot or pydot-ng.
The graph before optimization: The graph before optimization:
......
...@@ -202,7 +202,7 @@ The graph after optimization: ...@@ -202,7 +202,7 @@ The graph after optimization:
Picture Printing of Graphs Picture Printing of Graphs
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
``pydotprint`` requires graphviz and pydot. ``pydotprint`` requires graphviz and either pydot or pydot-ng.
The graph before optimization: The graph before optimization:
......
...@@ -59,7 +59,7 @@ The following libraries and software are optional: ...@@ -59,7 +59,7 @@ The following libraries and software are optional:
`Git <http://git-scm.com>`_ `Git <http://git-scm.com>`_
To download bleeding-edge versions of Theano. To download bleeding-edge versions of Theano.
`pydot-ng <https://github.com/pydot/pydot-ng>`_ or `pydot <https://code.google.com/p/pydot/>`_ `graphiz <http://www.graphviz.org/>`__ and either `pydot-ng <https://github.com/pydot/pydot-ng>`__ or `pydot <https://code.google.com/p/pydot/>`__
To be able to make picture of Theano computation graph. To be able to make picture of Theano computation graph.
pydot-ng is a pydot compatible replacement that support newer Python. pydot-ng is a pydot compatible replacement that support newer Python.
...@@ -613,7 +613,7 @@ To install the missing Theano optional dependency (pydot): ...@@ -613,7 +613,7 @@ To install the missing Theano optional dependency (pydot):
.. code-block:: bash .. code-block:: bash
$ conda install pydot $ conda install pydot-ng
If you want the bleeding edge version instead execute this command: If you want the bleeding edge version instead execute this command:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -17,11 +17,14 @@ Requirements ...@@ -17,11 +17,14 @@ Requirements
------------ ------------
``d3viz`` requires the `pydot <https://pypi.python.org/pypi/pydot>`__ ``d3viz`` requires the `pydot <https://pypi.python.org/pypi/pydot>`__
package, which can be installed with ``pip``: package. `pydot-ng <https://github.com/pydot/pydot-ng>`__ fork is better
maintained, and it works both in Python 2.x and 3.x. Install it with pip::
:: pip install pydot-ng
pip install pydot Like Theano’s `printing module
<http://deeplearning.net/software/theano/library/printing.html>`__, ``d3viz``
requires `graphviz <http://www.graphviz.org/>`__ binary to be available.
Overview Overview
-------- --------
...@@ -123,6 +126,19 @@ may not be perfect. In this case, you can press the ``Release node`` ...@@ -123,6 +126,19 @@ may not be perfect. In this case, you can press the ``Release node``
button in the top-left corner to automatically arrange nodes. To reset button in the top-left corner to automatically arrange nodes. To reset
nodes to their default position, press the ``Reset nodes`` button. nodes to their default position, press the ``Reset nodes`` button.
You can also display the interactive graph inline in
IPython using ``IPython.display.IFrame``:
.. code:: python
from IPython.display import IFrame
d3v.d3viz(predict, 'examples/mlp.html')
IFrame('examples/mlp.html', width=700, height=500)
Currently if you use display.IFrame you still have to create a file,
and this file can't be outside notebooks root (e.g. usually it can't be
in /tmp/).
Profiling Profiling
--------- ---------
......
...@@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, division ...@@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, division
import os import os
import shutil import shutil
import re import re
import six
from six import iteritems from six import iteritems
from theano.d3viz.formatting import PyDotFormatter from theano.d3viz.formatting import PyDotFormatter
...@@ -78,7 +79,10 @@ def d3viz(fct, outfile, copy_deps=True, *args, **kwargs): ...@@ -78,7 +79,10 @@ def d3viz(fct, outfile, copy_deps=True, *args, **kwargs):
# Create DOT graph # Create DOT graph
formatter = PyDotFormatter(*args, **kwargs) formatter = PyDotFormatter(*args, **kwargs)
graph = formatter(fct) graph = formatter(fct)
dot_graph = escape_quotes(str(graph.create_dot())).replace('\n', '').replace('\r', '') dot_graph_raw = graph.create_dot()
if not six.PY2:
dot_graph_raw = dot_graph_raw.decode('utf8')
dot_graph = escape_quotes(dot_graph_raw).replace('\n', '').replace('\r', '')
# Create output directory if not existing # Create output directory if not existing
outdir = os.path.dirname(outfile) outdir = os.path.dirname(outfile)
......
...@@ -52,8 +52,9 @@ class PyDotFormatter(object): ...@@ -52,8 +52,9 @@ class PyDotFormatter(object):
def __init__(self, compact=True): def __init__(self, compact=True):
"""Construct PyDotFormatter object.""" """Construct PyDotFormatter object."""
if not pydot_imported: if not pydot_imported:
raise ImportError('Failed to import pydot. You must install pydot' raise ImportError('Failed to import pydot. You must install '
' and graphviz for `PyDotFormatter` to work.') 'graphviz and either pydot or pydot-ng for '
'`PyDotFormatter` to work.')
self.compact = compact self.compact = compact
self.node_colors = {'input': 'limegreen', self.node_colors = {'input': 'limegreen',
......
...@@ -747,8 +747,9 @@ def pydotprint(fct, outfile=None, ...@@ -747,8 +747,9 @@ def pydotprint(fct, outfile=None,
outputs = fct.outputs outputs = fct.outputs
topo = fct.toposort() topo = fct.toposort()
if not pydot_imported: if not pydot_imported:
raise RuntimeError("Failed to import pydot. You must install pydot" raise RuntimeError("Failed to import pydot. You must install graphviz"
" and graphviz for `pydotprint` to work.", " and either pydot or pydot-ng for "
"`pydotprint` to work.",
pydot_imported_msg) pydot_imported_msg)
g = pd.Dot() g = pd.Dot()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论