Пример #1
0
    def checkpoint(self):
        """ Make a shallow copy of the context.

        Technically, this is actually a fairly deep copy. All of the object
        structure should be replicated, but the actual dictionary storage will
        be shallowly copied::

            copy = context.shallow_copy()
            copy[key] is context[key] for key in context.keys()

        These semantics are useful for saving out checkpointed versions of the
        context for implementing an undo/redo stack. They may not be useful for
        other purposes.

        Returns
        -------
        copy : IContext
        """
        copy = self.clone_traits()
        new_subcontexts = []
        for context in self.subcontexts:
            checkpointable_subcontext = adapt(context, ICheckpointable)
            new_subcontexts.append(checkpointable_subcontext.checkpoint())
        copy.subcontexts = new_subcontexts
        return copy
    def execute(self, context, globals=None, inputs=None, outputs=None):
        """ Execute code in context, optionally restricting on inputs or
        outputs if supplied

        Parameters
        ----------
        context : Dict-like
        globals : Dict-like, optional
        inputs : List of strings, options
        outputs : List of strings, optional

        Returns
        -------
        inputs : set
            the inputs to the restricted block
        outpus : set
            the outputs of the restricted block

        """
        icontext = adapt(context, IContext)

        if globals is None:
            globals = {}
        if inputs is None:
            inputs = []
        if outputs is None:
            outputs = []

        #If called with no inputs or outputs the full block executes
        if inputs or outputs:
            block = self._block.restrict(inputs=inputs, outputs=outputs)
        else:
            block = self._block
        block.execute(icontext, global_context=globals)
        return block.inputs, block.outputs
Пример #3
0
    def checkpoint(self):
        """ Make a shallow copy of the context.

        Technically, this is actually a fairly deep copy. All of the object
        structure should be replicated, but the actual dictionary storage will
        be shallowly copied::

            copy = context.shallow_copy()
            copy[key] is context[key] for key in context.keys()

        These semantics are useful for saving out checkpointed versions of the
        context for implementing an undo/redo stack. They may not be useful for
        other purposes.

        Returns
        -------
        copy : IContext
        """
        copy = self.clone_traits()
        new_subcontexts = []
        for context in self.subcontexts:
            checkpointable_subcontext = adapt(context, ICheckpointable)
            new_subcontexts.append(checkpointable_subcontext.checkpoint())
        copy.subcontexts = new_subcontexts
        return copy
Пример #4
0
    def execute(self, context, globals=None, inputs=None, outputs=None):
        """ Execute code in context, optionally restricting on inputs or
        outputs if supplied

        Parameters
        ----------
        context : Dict-like
        globals : Dict-like, optional
        inputs : List of strings, options
        outputs : List of strings, optional

        Returns
        -------
        inputs : set
            the inputs to the restricted block
        outpus : set
            the outputs of the restricted block

        """
        icontext = adapt(context, IContext)

        if globals is None:
            globals = {}
        if inputs is None:
            inputs = []
        if outputs is None:
            outputs = []

        #If called with no inputs or outputs the full block executes
        if inputs or outputs:
            block = self._block.restrict(inputs=inputs, outputs=outputs)
        else:
            block = self._block
        block.execute(icontext, global_context=globals)
        return block.inputs, block.outputs
 def test_user_ds_direct_adaptation(self):
     objects_checked = 0
     for object_list in self.user_ds_objects:
         objects_checked += 1
         model = object_list[0]
         tree_node = adapt(model, ITreeNode)
         self.assertIsInstance(tree_node, BaseChromatographyDataToITreeNode)
     self.assertEqual(objects_checked, len(self.user_ds_objects))
 def test_optimizer_to_itree_node(self):
     model = make_sample_brute_force_optimizer()
     analysis_tools = self.study.analysis_tools
     analysis_tools.optimizations.append(model)
     tree_node = adapt(model, ITreeNode)
     self.assertIsInstance(tree_node, ExperimentOptimizerToITreeNode)
     assert_list_element_menu_content_equal(analysis_tools, "optimizations",
                                            {DeleteAction})
Пример #7
0
    def _models_default(self):
        from attractors.model.henon import Henon
        from attractors.model.lorenz import Lorenz
        from attractors.model.rossler import Rossler

        models = [Henon(), Lorenz(), Rossler()]

        return [adapt(model, IPlottable2d) for model in models]
Пример #8
0
    def _models_default(self):
        from model.henon import Henon
        from model.lorenz import Lorenz
        from model.rossler import Rossler

        models = [Henon(), Lorenz(), Rossler()]

        return [adapt(model, IPlottable2d) for model in models]
 def test_sim_group_to_itree_node_menu(self):
     model = make_sample_simulation_group()
     analysis_tools = self.study.analysis_tools
     analysis_tools.simulation_grids.append(model)
     tree_node = adapt(model, ITreeNode)
     self.assertIsInstance(tree_node, SimulationGroupToITreeNode)
     expected = {DeleteAction}
     assert_list_element_menu_content_greater(analysis_tools,
                                              "simulation_grids", expected)
Пример #10
0
    def execute(self, context, globals=None, inputs=None, outputs=None):
        icontext = adapt(context, IContext)

        if inputs is None:
            inputs = []
        if outputs is None:
            outputs = []

        if globals is None:
            globals = {}

        exec_(self.code, globals, icontext)
        return set(inputs), set(outputs)
Пример #11
0
    def execute(self, context, globals=None, inputs=None, outputs=None):
        icontext = adapt(context, IContext)

        if inputs is None:
            inputs = []
        if outputs is None:
            outputs = []

        if globals is None:
            globals = {}

        exec(self.code, globals, icontext)
        return set(inputs), set(outputs)
 def test_direct_adaptation(self):
     tree_node = adapt(self.model, ITreeNode)
     self.assertIsInstance(tree_node, SimulationToITreeNode)
 def test_simulation2(self):
     model = make_sample_simulation2()
     view = adapt(model, ModelView)
     ui = view.edit_traits()
     ui.dispose()
Пример #14
0
 def __ext_langmuir_model_view_default(self):
     view = adapt(self._ext_langmuir_model, ModelView)
     return view
Пример #15
0
 def __ph_sma_model_view_default(self):
     view = adapt(self._ph_sma_model, ModelView)
     return view