This method is called when all tasks reach S_OK
        Ir runs `mrgddb` in sequential on the local machine to produce
        the final DDB file in the outdir of the `Work`.
777932
def on_all_ok(self):
        
        # Merge DDB files.
        out_ddb = self.merge_ddb_files()
        return self.Results(node=self, returncode=0, message="DDB merge done")
712163
def cbk_qptdm_workflow(self, cbk):
        
        scr_input = cbk.data["input"]
        # Use the WFK file produced by the second
        # Task in the first Work (NSCF step).
        nscf_task = self[0][1]
        wfk_file = nscf_task.outdir.has_abiext("WFK")

        work = self[1]
        work.set_manager(self.manager)
        work.create_tasks(wfk_file, scr_input)
        work.add_deps(cbk.deps)

        work.set_flow(self)
        # Each task has a reference to its work.
        for task in work:
            task.set_work(work)
            # Add the garbage collector.
            if self.gc is not None: task.set_gc(self.gc)

        work.connect_signals()
        work.build()

        return work
1332865
def from_den_ddb_dvdb(cls, inp, den_path, ddb_path, dvdb_path, mpiprocs=1, remove_wfkq=True,
                          qpath=None, with_ddk=True, expand=True, manager=None):
        
        import abipy.abilab as abilab

        # Create file nodes
        den_file = FileNode(den_path)
        ddb_file = FileNode(ddb_path)
        dvdb_file = FileNode(dvdb_path)

        # Create new work
        new = cls(manager=manager)
        new.remove_wfkq = remove_wfkq
        new.wfkq_tasks = []
        new.wfkq_task_children = collections.defaultdict(list)
        if manager is None: manager = TaskManager.from_user_config()
        tm = manager.new_with_fixed_mpi_omp(mpiprocs, 1)

        # Create a WFK task
        kptopt = 1 if expand else 3
        nscf_inp = inp.new_with_vars(iscf=-2, kptopt=kptopt)
        wfk_task = new.register_nscf_task(nscf_inp, deps={den_file: "DEN"},manager=tm)
        new.wfkq_tasks.append(wfk_task)
        new.wfk_task = wfk_task

        # Read path and regular grid from DDB file
        with abilab.abiopen(ddb_path) as ddb:
            q_frac_coords = np.array([k.frac_coords for k in ddb.qpoints])
            ddb_ngqpt = ddb.guessed_ngqpt

        # If qpath is set, we read the list of q-points to be used to interpolate the DVDB file.
        # The DVDB and DDB file have to correspond to a regular grid.
        dvdb = dvdb_file
        if qpath is None:
            qpath = q_frac_coords
        else:
            interp_inp = inp.new_with_vars(optdriver=7, eph_task=-5, ddb_ngqpt=ddb_ngqpt,
                                           ph_nqpath=len(qpath), ph_qpath=qpath, prtphdos=0)
            dvdb = new.register_eph_task(interp_inp, deps={wfk_task: "WFK", ddb_file: "DDB", dvdb_file: "DVDB"},
                                          manager=tm)

        # Create a WFK expansion task
        if expand:
            fbz_nscf_inp = inp.new_with_vars(optdriver=8)
            fbz_nscf_inp.set_spell_check(False)
            fbz_nscf_inp.set_vars(wfk_task="wfk_fullbz")
            tm_serial = manager.new_with_fixed_mpi_omp(1,1)
            wfk_task = new.register_nscf_task(fbz_nscf_inp, deps={wfk_task: "WFK", den_file: "DEN"},
                                              manager=tm_serial)
            new.wfkq_tasks.append(wfk_task)
            new.wfk_task = wfk_task

        if with_ddk:
            kptopt = 3 if expand else 1
            ddk_inp = inp.new_with_vars(optdriver=8,kptopt=kptopt)
            ddk_inp.set_spell_check(False)
            ddk_inp.set_vars(wfk_task="wfk_ddk")
            ddk_task = new.register_nscf_task(ddk_inp, deps={wfk_task: "WFK", den_file: "DEN"}, manager=tm)
            new.wfkq_tasks.append(ddk_task)

        # For each qpoint
        for qpt in qpath:
            is_gamma = np.sum(qpt ** 2) < 1e-12
            if is_gamma:
                # Create a link from WFK to WFQ on_ok
                wfkq_task = wfk_task
                deps = {wfk_task: ["WFK","WFQ"], ddb_file: "DDB", dvdb: "DVDB" }
            else:
                # Create a WFQ task
                nscf_inp = nscf_inp.new_with_vars(kptopt=3, qpt=qpt, nqpt=1)
                wfkq_task = new.register_nscf_task(nscf_inp, deps={den_file: "DEN"}, manager=tm)
                new.wfkq_tasks.append(wfkq_task)
                deps = {wfk_task: "WFK", wfkq_task: "WFQ", ddb_file: "DDB", dvdb: "DVDB" }

            # Create a EPH task
            eph_inp = inp.new_with_vars(optdriver=7, prtphdos=0, eph_task=-2, kptopt=3,
                                        ddb_ngqpt=[1,1,1], nqpt=1, qpt=qpt)
            t = new.register_eph_task(eph_inp, deps=deps, manager=tm)
            new.wfkq_task_children[wfkq_task].append(t)

        return new
264143
private void processFiles(File protoNetwork) {
        // final StringBuilder bldr = new StringBuilder();
        // bldr.append("Executing ");
        // bldr.append(getApplicationName());
        // bldr.append(" of ");
        // bldr.append(protoNetwork);
        // phaseOutput(bldr.toString());

        phaseOutput(format("=== %s ===", getApplicationName()));

        ProtoNetworkDescriptor pnd = new BinaryProtoNetworkDescriptor(
                protoNetwork);

        BinaryProtoNetworkExternalizer bpne =
                new BinaryProtoNetworkExternalizer();
        ProtoNetwork gpn = null;
        try {
            gpn = bpne.readProtoNetwork(pnd);
        } catch (ProtoNetworkError e) {
            error("Unable to read merged network.");
            exit(ExitCode.NO_GLOBAL_PROTO_NETWORK);
        }

        stage1(gpn);
    }
622981
def on_clear(self, event):
        
        dia = pmag_menu_dialogs.ClearWD(self.parent, self.parent.WD)
        clear = dia.do_clear()
        if clear:
            # clear directory, but use previously acquired data_model
            if self.data_model_num == 2.5:
                self.parent.er_magic = builder.ErMagicBuilder(self.parent.WD, self.parent.er_magic.data_model)
            elif self.data_model_num == 3:
                self.parent.contribution = cb.Contribution(self.parent.WD,
                                                           dmodel=self.parent.contribution.data_model)
906007
private void complete(final InstallationManager.InstallationModification modification, final FinalizeCallback callback) {
        final List<File> processed = new ArrayList<File>();
        List<File> reenabled = Collections.emptyList();
        List<File> disabled = Collections.emptyList();
        try {
            try {
                // Update the state to invalidate and process module resources
                if (stateUpdater.compareAndSet(this, State.PREPARED, State.INVALIDATE)) {
                    if (mode == PatchingTaskContext.Mode.APPLY) {
                        // Only invalidate modules when applying patches; on rollback files are immediately restored
                        for (final File invalidation : moduleInvalidations) {
                            processed.add(invalidation);
                            PatchModuleInvalidationUtils.processFile(this, invalidation, mode);
                        }
                        if (!modulesToReenable.isEmpty()) {
                            reenabled = new ArrayList<File>(modulesToReenable.size());
                            for (final File path : modulesToReenable) {
                                reenabled.add(path);
                                PatchModuleInvalidationUtils.processFile(this, path, PatchingTaskContext.Mode.ROLLBACK);
                            }
                        }
                    } else if(mode == PatchingTaskContext.Mode.ROLLBACK) {
                        if (!modulesToDisable.isEmpty()) {
                            disabled = new ArrayList<File>(modulesToDisable.size());
                            for (final File path : modulesToDisable) {
                                disabled.add(path);
                                PatchModuleInvalidationUtils.processFile(this, path, PatchingTaskContext.Mode.APPLY);
                            }
                        }
                    }

                }
                modification.complete();
                callback.completed(this);
                state = State.COMPLETED;
            } catch (Exception e) {
                this.moduleInvalidations.clear();
                this.moduleInvalidations.addAll(processed);
                this.modulesToReenable.clear();
                this.modulesToReenable.addAll(reenabled);
                this.modulesToDisable.clear();
                this.moduleInvalidations.addAll(disabled);
                throw new RuntimeException(e);
            }
        } finally {
            if (state != State.COMPLETED) {
                try {
                    modification.cancel();
                } finally {
                    try {
                        undoChanges();
                    } finally {
                        callback.operationCancelled(this);
                    }
                }
            } else  {
                try {
                    if (checkForGarbageOnRestart) {
                        final File cleanupMarker = new File(installedImage.getInstallationMetadata(), "cleanup-patching-dirs");
                        cleanupMarker.createNewFile();
                    }
                    storeFailedRenaming();
                } catch (IOException e) {
                    PatchLogger.ROOT_LOGGER.debugf(e, "failed to create cleanup marker");
                }
            }
        }
    }
868468
def completed_task(self):
        
        # If its remote and finished running
        if self.remote_channel and self.remote_channel.exit_status_ready():
            # Collect all remaining stdout/stderr
            while self.remote_channel.recv_ready():
                self.stdout += self.remote_channel.recv(1024)
            while self.remote_channel.recv_stderr_ready():
                self.stderr += self.remote_channel.recv_stderr(1024)
            return self.remote_channel.recv_exit_status()
        # Otherwise check for finished local command
        elif self.process:
            self.stdout, self.stderr = (self._read_temp_file(self.stdout_file),
                                        self._read_temp_file(self.stderr_file))
            for temp_file in [self.stdout_file, self.stderr_file]:
                temp_file.close()
            return self.process.returncode
903787
def done(self):
        
        logger.info('Marking %s as done', self)

        fn = self.get_path()
        try:
            os.makedirs(os.path.dirname(fn))
        except OSError:
            pass
        open(fn, 'w').close()
1084794
private void partitionFinished(PartitionReplyMsg msg) {

        JoblogUtil.logToJobLogAndTraceOnly(Level.FINE, "partition.ended", new Object[] {
                                                                                         msg.getPartitionPlanConfig().getPartitionNumber(),
                                                                                         msg.getBatchStatus(),
                                                                                         msg.getExitStatus(),
                                                                                         msg.getPartitionPlanConfig().getStepName(),
                                                                                         msg.getPartitionPlanConfig().getTopLevelNameInstanceExecutionInfo().getInstanceId(),
                                                                                         msg.getPartitionPlanConfig().getTopLevelNameInstanceExecutionInfo().getExecutionId() },
                                           logger);

        finishedWork.add(msg);
    }
810525
def postprocess(self):
        
        for f in VASP_OUTPUT_FILES + [self.output_file]:
            if os.path.exists(f):
                if self.final and self.suffix != "":
                    shutil.move(f, "{}{}".format(f, self.suffix))
                elif self.suffix != "":
                    shutil.copy(f, "{}{}".format(f, self.suffix))

        if self.copy_magmom and not self.final:
            try:
                outcar = Outcar("OUTCAR")
                magmom = [m['tot'] for m in outcar.magnetization]
                incar = Incar.from_file("INCAR")
                incar['MAGMOM'] = magmom
                incar.write_file("INCAR")
            except:
                logger.error('MAGMOM copy from OUTCAR to INCAR failed')

        # Remove continuation so if a subsequent job is run in
        # the same directory, will not restart this job.
        if os.path.exists("continue.json"):
            os.remove("continue.json")
861099
def run_for_output(raw_output, threads, allresults)
      # check output files exist
      output_files = {}
      @target.output.each_pair do |key, glob|
        files = Dir[glob]
        size = files.reduce(1) { |sum, f| sum * File.size(f)}
        if files.empty? || size==0
          error = "output files for #{key} matching #{glob} do not exist" +
                  " or are empty"
          raise ObjectiveHandlerError, error
        end
        output_files[key] = files.map { |f| File.expand_path(f) }
      end

      # run all objectives for output
      results = {}
      @objectives.each_pair do |name, objective|
        results[name] = self.run_objective(objective, name, raw_output,
                                           output_files, threads)
      end

      if allresults
        return { :results => results,
                 :reduced => self.dimension_reduce(results) }
      else
        results.each_value do |value|
          return value.kind_of?(Hash) ? value[:result] : value
        end
      end
    end
255282
def check_complete(self):
        
        logger.debug('Running check_complete for task {0}'.format(self.name))

        # Tasks not completed
        if self.remote_not_complete() or self.local_not_complete():
            self._start_check_timer()
            return

        return_code = self.completed_task()

        # Handle task errors
        if self.terminate_sent:
            self.stderr += '\nDAGOBAH SENT SIGTERM TO THIS PROCESS\n'
        if self.kill_sent:
            self.stderr += '\nDAGOBAH SENT SIGKILL TO THIS PROCESS\n'
        if self.remote_failure:
            return_code = -1
            self.stderr += '\nAn error occurred with the remote machine.\n'

        self.stdout_file = None
        self.stderr_file = None

        self._task_complete(success=True if return_code == 0 else False,
                            return_code=return_code,
                            stdout=self.stdout,
                            stderr=self.stderr,
                            start_time=self.started_at,
                            complete_time=datetime.utcnow())
1019136
def atomic_output_file(dest_path, make_parents=False, backup_suffix=None, suffix=".partial.%s"):
  
  if dest_path == os.devnull:
    # Handle the (probably rare) case of writing to /dev/null.
    yield dest_path
  else:
    tmp_path = ("%s" + suffix) % (dest_path, new_uid())
    if make_parents:
      make_parent_dirs(tmp_path)

    yield tmp_path

    # Note this is not in a finally block, so that result won't be renamed to final location
    # in case of abnormal exit.
    if not os.path.exists(tmp_path):
      raise IOError("failure in writing file '%s': target file '%s' missing" % (dest_path, tmp_path))
    if backup_suffix:
      move_to_backup(dest_path, backup_suffix=backup_suffix)
    # If the target already exists, and is a directory, it has to be removed.
    if os.path.isdir(dest_path):
      shutil.rmtree(dest_path)
    shutil.move(tmp_path, dest_path)
1365592
def finalize_processes(self):
        # type: (_MultiprocessOffload) -> None
        
        self._term_signal.value = 1
        if self._check_thread is not None:
            self._check_thread.join()
        for proc in self._procs:
            proc.join()
1004086
def _post_run_hook(self, runtime):
        '''  '''

        self._anat_file = self.inputs.in_file
        self._mask_file = self.aggregate_outputs(runtime=runtime).mask_file
        self._seg_files = [self._mask_file]
        self._masked = True

        NIWORKFLOWS_LOG.info(
            'Generating report for nilearn.compute_epi_mask. file "%s", and mask file "%s"',
            self._anat_file, self._mask_file)

        return super(ComputeEPIMask, self)._post_run_hook(runtime)
187204
def prepare_outputs(self, job):
        
        outputs = flatten(job.output())
        for o in outputs:
            if isinstance(o, FileSystemTarget):
                parent_dir = os.path.dirname(o.path)
                if parent_dir and not o.fs.exists(parent_dir):
                    logger.info("Creating parent directory %r", parent_dir)
                    try:
                        # there is a possible race condition
                        # which needs to be handled here
                        o.fs.mkdir(parent_dir)
                    except FileAlreadyExists:
                        pass
1328573
private void jobComplete() {
    final JobTrackerInstrumentation metrics = jobtracker.getInstrumentation();
    //
    // All tasks are complete, then the job is done!
    //
    if (this.status.getRunState() == JobStatus.RUNNING ||
        this.status.getRunState() == JobStatus.PREP) {
      changeStateTo(JobStatus.SUCCEEDED);
      this.status.setCleanupProgress(1.0f);
      if (maps.length == 0) {
        this.status.setMapProgress(1.0f);
      }
      if (reduces.length == 0) {
        this.status.setReduceProgress(1.0f);
      }
      this.finishTime = JobTracker.getClock().getTime();
      LOG.info("Job " + this.status.getJobID() +
               " has completed successfully.");

      // Log the job summary (this should be done prior to logging to
      // job-history to ensure job-counters are in-sync
      JobSummary.logJobSummary(this, jobtracker.getClusterStatus(false));

      Counters counters = getCounters();
      // Log job-history
      JobHistory.JobInfo.logFinished(this.status.getJobID(), finishTime,
                                     this.finishedMapTasks,
                                     this.finishedReduceTasks, failedMapTasks,
                                     failedReduceTasks, killedMapTasks,
                                     killedReduceTasks, getMapCounters(),
                                     getReduceCounters(), counters);
      // Note that finalize will close the job history handles which garbage collect
      // might try to finalize
      garbageCollect();

      metrics.completeJob(this.conf, this.status.getJobID());
    }
  }