Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Copy over module algorithms correctly #184

Merged
merged 4 commits into from
Jun 28, 2019
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
4 changes: 2 additions & 2 deletions mxfusion/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ def _clone_algorithms(self, algorithms, replicant):
graphs_index = {g: i for i,g in enumerate(self._extra_graphs)}
extra_graphs = [replicant._extra_graphs[graphs_index[graph]] for graph in algorithm.graphs
if graph in graphs_index]
algs[conditionals] = (targets,
algs[conditionals] = [(targets,
algorithm.replicate_self(replicant._module_graph, extra_graphs),
alg_name)
alg_name)]
return algs

def reconcile_with_module(self, previous_module):
Expand Down
1 change: 1 addition & 0 deletions requirements/test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ GPy>=1.9.6
matplotlib
mxnet>=1.3
mxboard>=0.1.0
mock>=3.0.5
30 changes: 30 additions & 0 deletions testing/modules/module_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import mock

from mxfusion import Variable
from mxfusion.inference.inference_alg import SamplingAlgorithm
from mxfusion.models import Model
from mxfusion.modules.module import Module


def test_module_clone_algorithms():
m = Model()
m.X = Variable()
m.Y = Variable()

module = Module([('X', m.X)], [('Y', m.Y)], ['in'], 'out')
module._module_graph = Model()

sampling_alg = mock.create_autospec(SamplingAlgorithm)
sampling_alg.replicate_self.return_value = sampling_alg
module.attach_draw_samples_algorithms([m.Y], [m.X], sampling_alg)

cloned_module = module.replicate_self()

# Check dictionary contains 1 entry
assert len(cloned_module._draw_samples_algorithms) == 1
# Check dictionary key is a tuple containing m.X
assert list(cloned_module._draw_samples_algorithms.keys())[0] == (m.X, )
# Check dictionary value is a list containing a tuple with 3 entries
assert isinstance(cloned_module._draw_samples_algorithms[(m.X,)], list)
assert isinstance(cloned_module._draw_samples_algorithms[(m.X,)][0], tuple)
assert len(cloned_module._draw_samples_algorithms[(m.X,)][0]) == 3