Ejemplo n.º 1
0
    def compute_variables(self, experiments):
        """Main entry point - compute all variables in all experiments.

        Args:
            experiments (list): A list of experiments that needs to be computed. It's modified in place.
        """
        for experiment in experiments:
            # Convert all lists to strings
            DictUtils.lists_to_strings(experiment)
            # Build initial version of a forward index (variables -> their dependencies)
            self.fwd_index = {}
            for variable in experiment:
                self.update_index(experiment, variable)
            # iteratively compute variables
            while len(self.fwd_index) > 0:
                computable_vars = self.get_computable_variables()
                # print("Computable vars: %s" % (str(computable_vars)))
                if len(computable_vars) == 0:
                    self.report_unsatisfied_deps(experiment)
                    exit(1)
                # Compute  variables. We are either done with a variable or
                # this variable has nested references and we need to continue
                # computing it.
                computed, partially_computed = self.compute_current_variables(
                    experiment, computable_vars)
                # print("Computed vars: %s" % (str(computed)))
                # print("Partially computed vars: %s" % (str(partially_computed)))
                # Remove computed vars from index and update dependencies of
                # remaining variables
                for computed_var in computed:
                    self.fwd_index.pop(computed_var)
                for var in self.fwd_index:
                    self.fwd_index[var]['udeps'].difference_update(
                        set(computed))
                # Update partially computed variables - these are variables
                # that have nested references.
                for var in partially_computed:
                    self.update_index(experiment, var)
                    deps = self.fwd_index[var]['udeps'].copy()
                    for dep in deps:
                        if dep not in self.fwd_index:
                            self.fwd_index[var]['udeps'].remove(dep)
                # exit(0)

            # We need to remove all internal temp variables
            # We need to remove all internal temp variables.
            # In P2, keys() makes a copy. In P3 it returns an iterator -> this
            # 'dictionary changed size during iteration' error. So, making copy
            for name in list(experiment.keys()):
                if name.startswith('__dlbs_'):
                    experiment.pop(name)
Ejemplo n.º 2
0
    def test_lists_to_strings_2(self):
        """dlbs  ->  TestDictUtils::test_lists_to_strings_2              [Testing lists-to-strings helpers #2]"""
        DictUtils.lists_to_strings(self.dictionary, separator=';')

        self.assertEqual('exp.framework' in self.dictionary, True)
        self.assertEqual('exp.model' in self.dictionary, True)
        self.assertEqual('exp.device_batch' in self.dictionary, True)

        self.assertEqual(self.dictionary['exp.framework'], self.framework)
        self.assertEqual(self.dictionary['exp.model'],
                         "ResNet50;ResNet101;ResNet152")
        self.assertEqual(self.dictionary['exp.device_batch'],
                         self.device_batch)

        self.assertEqual(len(self.dictionary), 3)