コード例 #1
0
    def load_code_from_file(self, filename):

        # Clear out the old references
        self.canvas = self.controller = self.exec_model = None

        self.exec_model = ExecutionModel.from_file(filename)
        self.controller = BlockGraphController(execution_model=self.exec_model)
        self.canvas = BlockCanvas(graph_controller=self.controller)
        self.controller.canvas = self.canvas
コード例 #2
0
    def load_from_config(self, config, dirname, project=None):
        """ Loads the experiment.  The existing state of the experiment is
        completely modified.

        Parameters
        ----------
        config: a dict-like object
            The keys should correspond to the configspec for experiments as
            defined in project_config_spec.

        dirname: a string
            the absolute path to the subdirectory of the project that
            holds the experiment's saved data

        project: Project instance
            If provided, the project is used to hook up references to
            the shared context.
        """

        join = os.path.join
        self.name = config.get("name", "")

        if "code_file" in config:

            # Clear out the old references
            self.canvas = self.controller = self.exec_model = None

            self.exec_model = ExecutionModel.from_file(
                join(dirname, config["code_file"]))
            self.controller = BlockGraphController(
                execution_model=self.exec_model)
            self.canvas = BlockCanvas(graph_controller=self.controller)
            self.controller.canvas = self.canvas

        if "layout_file" in config:
            self.canvas.load_layout(join(dirname, config["layout_file"]))

        if "local_context" in config:
            self._local_context = DataContext.load(
                join(dirname, config["local_context"]))

        shared_context = None
        if project is not None:
            name = config.get("shared_context")
            if name != "":
                shared_context = project.find_context(name)

        self._shared_context = shared_context
        self._update_exec_context()
コード例 #3
0
    def __init__(self, code=None, shared_context=None, *args, **kwargs):
        super(Experiment, self).__init__(*args, **kwargs)

        if code is None:
            self.exec_model = ExecutionModel()
        else:
            self.exec_model = ExecutionModel.from_code(code)

        self.controller = BlockGraphController(execution_model=self.exec_model)
        self.canvas = BlockCanvas(graph_controller=self.controller)
        self.controller.canvas = self.canvas

        self._shared_context = shared_context
        self._local_context = DataContext(name=self._LOCAL_NAME_TEMPLATE())
        self._update_exec_context()