Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure signal ordering is deterministic #10

Merged
merged 1 commit into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Release History
**Fixed**

- ``sim.data`` now implements the full ``collections.Mapping`` interface
- Fixed bug where signal order was non-deterministic for Networks containing
objects with duplicate names
(`#9 <https://github.com/nengo/nengo_dl/issues/9>`_)

0.5.1 (August 28, 2017)
-----------------------
Expand Down
9 changes: 6 additions & 3 deletions nengo_dl/graph_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,12 @@ def order_signals(plan, n_passes=10):
of signals
"""

# get all the unique base signals
all_signals = sorted(set([s.base for ops in plan for op in ops
for s in op.all_signals]), key=lambda s: s.name)
# get all the unique base signals (we use OrderedDict to drop the duplicate
# bases without changing their order, so that signal order will be
# deterministic for a given model)
all_signals = list(OrderedDict(
[(s.base, None) for ops in plan for op in ops
for s in op.all_signals]).keys())

# figure out all the read blocks in the plan (in theory we would like each
# block to become a contiguous chunk in the base array)
Expand Down
19 changes: 19 additions & 0 deletions nengo_dl/tests/test_tensor_graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nengo
import numpy as np
import pytest
import tensorflow as tf

Expand Down Expand Up @@ -237,3 +238,21 @@ def test_planner_config(config_planner):
tg = tensor_graph.TensorGraph(model, None, None, tf.float32, 1, None)

assert len(tg.plan) == (2 if config_planner else 1)


def test_signal_order_deterministic(Simulator, seed):
with nengo.Network(seed=seed) as net:
inp = nengo.Node([0])
ens0 = nengo.Ensemble(10, 1, label="ens")
ens1 = nengo.Ensemble(10, 1, label="ens")
nengo.Connection(inp, ens0, synapse=None)
nengo.Connection(inp, ens1, synapse=None)

with Simulator(net, seed=seed) as sim1:
pass

with Simulator(net, seed=seed) as sim2:
for (k, v), (k2, v2) in zip(
sim1.tensor_graph.base_arrays_init.items(),
sim2.tensor_graph.base_arrays_init.items()):
assert np.allclose(v[0], v2[0])