提交 44e57b3c authored 作者: David Warde-Farley's avatar David Warde-Farley

Merge pull request #752 from goodfeli/rename_env

Rename env
...@@ -36,32 +36,32 @@ Here is an overview of the various steps that are done with the ...@@ -36,32 +36,32 @@ Here is an overview of the various steps that are done with the
computation graph in the compilation phase: computation graph in the compilation phase:
Step 1 - Create an Env Step 1 - Create a FunctionGraph
^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
The subgraph given by the end user is wrapped in a structure called The subgraph given by the end user is wrapped in a structure called
*Env*. That structure defines several hooks on adding and *FunctionGraph*. That structure defines several hooks on adding and
removing (pruning) nodes as well as on modifying links between nodes removing (pruning) nodes as well as on modifying links between nodes
(for example, modifying an input of an :ref:`apply` node) (see the (for example, modifying an input of an :ref:`apply` node) (see the
article about :ref:`libdoc_gof_env` for more information). article about :ref:`libdoc_gof_env` for more information).
Env provides a method to change the input of an Apply node from one FunctionGraph provides a method to change the input of an Apply node from one
Variable to another and a more high-level method to replace a Variable Variable to another and a more high-level method to replace a Variable
with another. This is the structure that :ref:`Optimizers with another. This is the structure that :ref:`Optimizers
<optimization>` work on. <optimization>` work on.
Some relevant :ref:`Features <libdoc_gof_envfeature>` are typically added to the Some relevant :ref:`Features <libdoc_gof_envfeature>` are typically added to the
Env, namely to prevent any optimization from operating inplace on FunctionGraph, namely to prevent any optimization from operating inplace on
inputs declared as immutable. inputs declared as immutable.
Step 2 - Execute main Optimizer Step 2 - Execute main Optimizer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Once the Env is made, an :term:`optimizer` is produced Once the FunctionGraph is made, an :term:`optimizer` is produced
by the :term:`mode` passed to ``function`` or to the Method/Module's by the :term:`mode` passed to ``function`` or to the Method/Module's
``make`` (the Mode basically has two important fields, ``linker`` and ``make`` (the Mode basically has two important fields, ``linker`` and
``optimizer``). That optimizer is applied on the Env using its ``optimizer``). That optimizer is applied on the FunctionGraph using its
optimize() method. optimize() method.
The optimizer is typically obtained through :attr:`optdb`. The optimizer is typically obtained through :attr:`optdb`.
...@@ -71,7 +71,8 @@ Step 3 - Execute linker to obtain a thunk ...@@ -71,7 +71,8 @@ Step 3 - Execute linker to obtain a thunk
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Once the computation graph is optimized, the :term:`linker` is Once the computation graph is optimized, the :term:`linker` is
extracted from the Mode. It is then called with the Env as argument to extracted from the Mode. It is then called with the FunctionGraph as
argument to
produce a ``thunk``, which is a function with no arguments that produce a ``thunk``, which is a function with no arguments that
returns nothing. Along with the thunk, one list of input containers (a returns nothing. Along with the thunk, one list of input containers (a
theano.gof.Container is a sort of object that wraps another and does theano.gof.Container is a sort of object that wraps another and does
......
...@@ -13,7 +13,7 @@ import numpy ...@@ -13,7 +13,7 @@ import numpy
import theano import theano
from theano import gof from theano import gof
from theano.gof import Env, graph, utils, link, ops_with_inner_function from theano.gof import FunctionGraph as Env, graph, utils, link, ops_with_inner_function
from theano.gof.link import raise_with_op from theano.gof.link import raise_with_op
from theano.gof.cc import CLinker from theano.gof.cc import CLinker
from theano.gof.python25 import all, any, product as itertools_product from theano.gof.python25 import all, any, product as itertools_product
...@@ -667,7 +667,7 @@ def _optcheck_env(input_specs, output_specs, accept_inplace=False): ...@@ -667,7 +667,7 @@ def _optcheck_env(input_specs, output_specs, accept_inplace=False):
inputs, outputs = gof.graph.clone(orig_inputs, orig_outputs) inputs, outputs = gof.graph.clone(orig_inputs, orig_outputs)
equivalence_tracker = _VariableEquivalenceTracker() equivalence_tracker = _VariableEquivalenceTracker()
env = gof.env.Env(inputs, outputs, env = gof.fg.FunctionGraph(inputs, outputs,
#DestroyHandler is not needed because it is actually installed by an optimization #DestroyHandler is not needed because it is actually installed by an optimization
# after canonicalization. This variables in a big speed gain. # after canonicalization. This variables in a big speed gain.
#features=[equivalence_tracker, gof.DestroyHandler(do_imports_on_attach=False)]) #features=[equivalence_tracker, gof.DestroyHandler(do_imports_on_attach=False)])
......
...@@ -129,7 +129,7 @@ def std_env(input_specs, output_specs, accept_inplace = False): ...@@ -129,7 +129,7 @@ def std_env(input_specs, output_specs, accept_inplace = False):
orig_outputs = [spec.variable for spec in output_specs] + updates orig_outputs = [spec.variable for spec in output_specs] + updates
inputs, outputs = gof.graph.clone(orig_inputs, orig_outputs) inputs, outputs = gof.graph.clone(orig_inputs, orig_outputs)
env = gof.env.Env(inputs, outputs) env = gof.fg.FunctionGraph(inputs, outputs)
for node in env.nodes: for node in env.nodes:
if getattr(node.op, 'destroy_map', None): if getattr(node.op, 'destroy_map', None):
......
...@@ -42,8 +42,10 @@ from cc import \ ...@@ -42,8 +42,10 @@ from cc import \
import compiledir # adds config vars import compiledir # adds config vars
from env import \ from fg import \
InconsistencyError, MissingInputError, Env InconsistencyError, MissingInputError, FunctionGraph
#deprecated alias to support code written with old name
Env = FunctionGraph
from destroyhandler import \ from destroyhandler import \
DestroyHandler DestroyHandler
......
...@@ -10,7 +10,7 @@ import toolbox ...@@ -10,7 +10,7 @@ import toolbox
import graph import graph
from theano.gof.python25 import deque from theano.gof.python25 import deque
from env import InconsistencyError from fg import InconsistencyError
class ProtocolError(Exception): class ProtocolError(Exception):
"""WRITEME""" """WRITEME"""
......
...@@ -21,7 +21,7 @@ from theano import config ...@@ -21,7 +21,7 @@ from theano import config
import cc import cc
import graph import graph
import utils import utils
from env import Env from fg import FunctionGraph as Env
class CLinkerObject(object): class CLinkerObject(object):
......
...@@ -11,7 +11,7 @@ import time ...@@ -11,7 +11,7 @@ import time
import numpy import numpy
import graph import graph
from env import InconsistencyError from fg import InconsistencyError
import op import op
import utils import utils
import unify import unify
...@@ -598,7 +598,7 @@ def is_same_graph_with_merge(var1, var2, givens=None): ...@@ -598,7 +598,7 @@ def is_same_graph_with_merge(var1, var2, givens=None):
givens = copied[2] givens = copied[2]
# Create Env. # Create Env.
inputs = theano.gof.graph.inputs(vars) inputs = theano.gof.graph.inputs(vars)
env = theano.gof.env.Env(inputs, vars) env = theano.gof.fg.FunctionGraph(inputs, vars)
# Perform Variable substitution. # Perform Variable substitution.
for to_replace, replace_by in givens.iteritems(): for to_replace, replace_by in givens.iteritems():
env.replace(to_replace, replace_by) env.replace(to_replace, replace_by)
......
...@@ -6,7 +6,8 @@ from theano.gof.cc import * ...@@ -6,7 +6,8 @@ from theano.gof.cc import *
from theano.gof.type import Type from theano.gof.type import Type
from theano.gof.graph import Variable, Apply, Constant from theano.gof.graph import Variable, Apply, Constant
from theano.gof.op import Op from theano.gof.op import Op
from theano.gof import env from theano.gof import fg
env = fg
from theano.gof import toolbox from theano.gof import toolbox
...@@ -171,7 +172,7 @@ def inputs(): ...@@ -171,7 +172,7 @@ def inputs():
def Env(inputs, outputs): def Env(inputs, outputs):
e = env.Env(inputs, outputs) e = fg.FunctionGraph(inputs, outputs)
return e return e
......
...@@ -8,7 +8,7 @@ from theano.gof.op import Op ...@@ -8,7 +8,7 @@ from theano.gof.op import Op
from theano.gof.opt import * from theano.gof.opt import *
from theano.gof import destroyhandler from theano.gof import destroyhandler
from theano.gof.env import Env, InconsistencyError from theano.gof.fg import FunctionGraph as Env, InconsistencyError
from theano.gof.toolbox import ReplaceValidate from theano.gof.toolbox import ReplaceValidate
from copy import copy from copy import copy
......
...@@ -4,7 +4,7 @@ from theano.gof import graph ...@@ -4,7 +4,7 @@ from theano.gof import graph
from theano.gof.graph import Variable, Apply, Constant from theano.gof.graph import Variable, Apply, Constant
from theano.gof.type import Type from theano.gof.type import Type
from theano.gof.op import Op from theano.gof.op import Op
from theano.gof import env from theano.gof import fg
from theano.gof import toolbox from theano.gof import toolbox
from theano.gof.link import * from theano.gof.link import *
...@@ -75,7 +75,7 @@ def perform_linker(env): ...@@ -75,7 +75,7 @@ def perform_linker(env):
def Env(inputs, outputs): def Env(inputs, outputs):
e = env.Env(inputs, outputs) e = fg.FunctionGraph(inputs, outputs)
return e return e
......
...@@ -3,7 +3,7 @@ from theano.gof.type import Type ...@@ -3,7 +3,7 @@ from theano.gof.type import Type
from theano.gof.graph import Variable, Apply, Constant from theano.gof.graph import Variable, Apply, Constant
from theano.gof.op import Op from theano.gof.op import Op
from theano.gof.opt import * from theano.gof.opt import *
from theano.gof.env import Env from theano.gof.fg import FunctionGraph as Env
from theano.gof.toolbox import * from theano.gof.toolbox import *
......
...@@ -3,7 +3,7 @@ from theano.gof.graph import Variable, Apply ...@@ -3,7 +3,7 @@ from theano.gof.graph import Variable, Apply
from theano.gof.type import Type from theano.gof.type import Type
from theano.gof.op import Op from theano.gof.op import Op
from theano.gof.env import Env, InconsistencyError from theano.gof.fg import FunctionGraph as Env, InconsistencyError
from theano.gof.toolbox import * from theano.gof.toolbox import *
...@@ -85,4 +85,4 @@ class TestNodeFinder: ...@@ -85,4 +85,4 @@ class TestNodeFinder:
raise Exception("Expected: %i times %s" % (num, type)) raise Exception("Expected: %i times %s" % (num, type))
...@@ -3,7 +3,7 @@ from theano.gof.type import Type ...@@ -3,7 +3,7 @@ from theano.gof.type import Type
from theano.gof.graph import Variable, Apply, Constant from theano.gof.graph import Variable, Apply, Constant
from theano.gof.op import Op from theano.gof.op import Op
from theano.gof.opt import * from theano.gof.opt import *
from theano.gof.env import Env from theano.gof.fg import FunctionGraph as Env
from theano.gof.toolbox import * from theano.gof.toolbox import *
import theano.tensor.basic as T import theano.tensor.basic as T
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论