ENH: prune the graph based on the initial workspace

This commit is contained in:
Joe Jevnik
2016-10-28 15:04:18 -04:00
parent e3e4ad2735
commit 0123bb8a97
5 changed files with 78 additions and 38 deletions
+25 -17
View File
@@ -66,6 +66,7 @@ from zipline.pipeline.term import InputDates
from zipline.testing import (
AssetID,
AssetIDPlusDay,
ExplodingObject,
check_arrays,
make_alternating_boolean_array,
make_cascading_boolean_array,
@@ -1320,18 +1321,11 @@ class StringColumnTestCase(WithSeededRandomPipelineEngine,
class PopulateInitialWorkspaceTestCase(WithConstantInputs, ZiplineTestCase):
def make_engine(self, populate_initial_workspace):
return SimplePipelineEngine(
lambda column: self.loader,
self.dates,
self.asset_finder,
populate_initial_workspace=populate_initial_workspace,
)
def test_populate_default_workspace(self):
column = USEquityPricing.low
base_term = column.latest
term = base_term + 1
term = (base_term + 1).alias('term')
composed_term = term + 1
column_value = self.constants[column]
precomputed_value = -column_value
@@ -1343,25 +1337,39 @@ class PopulateInitialWorkspaceTestCase(WithConstantInputs, ZiplineTestCase):
return assoc(
initial_workspace,
term,
full((len(dates), len(assets)), precomputed_value),
full(
(len(dates), len(assets)),
precomputed_value,
dtype=float64,
),
)
# I resisted the urge to use ``make_engine`` as a decorator here
# because Scott would have yelled at me.
engine = self.make_engine(populate_initial_workspace)
def dispatcher(column):
if column is base_term:
# the base_term should never be loaded, its initial refcount
# should be zero
return ExplodingObject()
return self.loader
engine = SimplePipelineEngine(
dispatcher,
self.dates,
self.asset_finder,
populate_initial_workspace=populate_initial_workspace,
)
results = engine.run_pipeline(
Pipeline({
'term-in-initial-workspace': term,
'term-not-in-initial-workspace': base_term,
'term': term,
'composed_term': composed_term,
}),
self.dates[0],
self.dates[-1],
)
self.assertTrue(
(results['term-in-initial-workspace'] == precomputed_value).all(),
(results['term'] == precomputed_value).all(),
)
self.assertTrue(
(results['term-not-in-initial-workspace'] == column_value).all(),
(results['composed_term'] == (precomputed_value + 1)).all(),
)
+8 -2
View File
@@ -195,8 +195,14 @@ class DependencyResolutionTestCase(WithTradingSessions, ZiplineTestCase):
self.assertIn(SomeDataSet.bar, resolution_order)
self.assertIn(SomeFactor(), resolution_order)
self.assertEqual(graph.node[SomeDataSet.foo]['extra_rows'], 4)
self.assertEqual(graph.node[SomeDataSet.bar]['extra_rows'], 4)
self.assertEqual(
graph.graph.node[SomeDataSet.foo]['extra_rows'],
4,
)
self.assertEqual(
graph.graph.node[SomeDataSet.bar]['extra_rows'],
4,
)
for foobar in gen_equivalent_factors():
check_output(self.make_execution_plan(to_dict([foobar])))