def __init__(self, plugin_cache): self.plugin_cache = plugin_cache self.ids_to_run = [] self.workloads = [] self._enabled_augmentations = toggle_set() self._enabled_instruments = None self._enabled_processors = None self._read_augmentations = False self.disabled_augmentations = set() self.job_spec_template = obj_dict(not_in_dict=['name']) self.job_spec_template.name = "globally specified job spec configuration" self.job_spec_template.id = "global" # Load defaults for cfg_point in JobSpec.configuration.values(): cfg_point.set_value(self.job_spec_template, check_mandatory=False) self.root_node = SectionNode(self.job_spec_template)
class JobGenerator(object): name = "Jobs Configuration" @property def enabled_instruments(self): self._read_augmentations = True if self._enabled_instruments is None: self._enabled_instruments = [] for entry in list(self._enabled_augmentations.merge_with(self.disabled_augmentations).values()): entry_cls = self.plugin_cache.get_plugin_class(entry) if entry_cls.kind == 'instrument': self._enabled_instruments.append(entry) return self._enabled_instruments @property def enabled_processors(self): self._read_augmentations = True if self._enabled_processors is None: self._enabled_processors = [] for entry in list(self._enabled_augmentations.merge_with(self.disabled_augmentations).values()): entry_cls = self.plugin_cache.get_plugin_class(entry) if entry_cls.kind == 'output_processor': self._enabled_processors.append(entry) return self._enabled_processors def __init__(self, plugin_cache): self.plugin_cache = plugin_cache self.ids_to_run = [] self.workloads = [] self._enabled_augmentations = toggle_set() self._enabled_instruments = None self._enabled_processors = None self._read_augmentations = False self.disabled_augmentations = set() self.job_spec_template = obj_dict(not_in_dict=['name']) self.job_spec_template.name = "globally specified job spec configuration" self.job_spec_template.id = "global" # Load defaults for cfg_point in JobSpec.configuration.values(): cfg_point.set_value(self.job_spec_template, check_mandatory=False) self.root_node = SectionNode(self.job_spec_template) def set_global_value(self, name, value): JobSpec.configuration[name].set_value(self.job_spec_template, value, check_mandatory=False) if name == "augmentations": self.update_augmentations(value) def add_section(self, section, workloads, group): new_node = self.root_node.add_section(section, group) with log.indentcontext(): for workload in workloads: new_node.add_workload(workload) def add_workload(self, workload): self.root_node.add_workload(workload) def disable_augmentations(self, augmentations): for entry in augmentations: if entry == '~~': continue if entry.startswith('~'): entry = entry[1:] try: self.plugin_cache.get_plugin_class(entry) except NotFoundError: raise ConfigError('Error disabling unknown augmentation: "{}"'.format(entry)) self.disabled_augmentations = self.disabled_augmentations.union(augmentations) def update_augmentations(self, value): if self._read_augmentations: msg = 'Cannot update augmentations after they have been accessed' raise RuntimeError(msg) self._enabled_augmentations = self._enabled_augmentations.merge_with(value) def only_run_ids(self, ids): if isinstance(ids, str): ids = [ids] self.ids_to_run = ids def generate_job_specs(self, target_manager): specs = [] for leaf in self.root_node.leaves(): workload_entries = leaf.workload_entries sections = [leaf] for ancestor in leaf.ancestors(): workload_entries = ancestor.workload_entries + workload_entries sections.insert(0, ancestor) for workload_entry in workload_entries: job_spec = create_job_spec(deepcopy(workload_entry), sections, target_manager, self.plugin_cache, self.disabled_augmentations) if self.ids_to_run: for job_id in self.ids_to_run: if job_id in job_spec.id: break else: continue self.update_augmentations(list(job_spec.augmentations.values())) specs.append(job_spec) return specs