示例#1
0
    def run_task(self, fw_spec):
        if self.get('contents', None) is not None:
            # where the template can be found
            target = utils.dump_directory(
                os.path.join(self.get('workdir', ''), 'template'), self['contents'])

            return fw.FWAction(
                update_spec={
                    # pass reference to this Treant to future Fireworks
                    'template': target,
                }
            )
        else:
            return fw.FWAction()
示例#2
0
    def run_rask(self, fw_spec):
        # results are given as (T, P, mean, std, g)
        results = (fw_spec['results_array'] + self.get('previous_results', []))

        finished = self.decide_if_flat(results)

        if not finished:
            # issue detour with more pressures
            return fw.FWAction(detours=self.make_detour(
                previous=results,
                nparallel=self['nparallel'],
            ))
        else:
            # continue to IsothermCreate
            return fw.FWAction(update_spec={'results_array': results})
示例#3
0
    def run_task(self, fw_spec):
        sim_t = self.copy_template(
            workdir=self.get('workdir', ''),
            simhash=fw_spec.get('simhash', ''),
            template=fw_spec['template'],
            P=self['pressure'],
            T=self['temperature'],
            p_id=self.get('parallel_id', 0),
        )

        # Modify input to match the spec
        self.update_input(
            target=sim_t,
            fmt=self['fmt'],
            T=self['temperature'],
            P=self['pressure'],
            n=self.get('ncycles', None),
        )

        if self.get('previous_simdir', None) is not None:
            self.set_as_restart(
                self['fmt'],
                old=self['previous_simdir'],
                new=sim_t,
            )

        return fw.FWAction(
            update_spec={'simtree': os.path.abspath(sim_t)}
        )
示例#4
0
    def run_task(self, fw_spec):
        my_candidate = fw_spec['candidates'][self['candidate_id']]

        updater = utils.unpickle_func(self['updater'])
        updater(fw_spec['simtree'], my_candidate)

        return fw.FWAction()
示例#5
0
    def run_task(self, fw_spec):
        tarpath = self.write_tarball(fw_spec['template'].rstrip(os.path.sep),
                                     self.get('workdir', ''))

        # then rename tar according to hash of file
        sha1 = self.calc_hash(tarpath)
        os.rename(tarpath,
                  os.path.join(self.get('workdir', ''), '{}.tar.gz'.format(sha1)))

        return fw.FWAction(update_spec={'simhash': sha1})
示例#6
0
    def run_task(self, fw_spec):
        # merge candidates and fitness
        children = self.collate(fw_spec['candidates'], fw_spec['fitness'])
        new_parents = self.replace(fw_spec['parents'], children)

        return fw.FWAction(
            stored_data={
                'candidates': children,
                'population': new_parents,
            },
            update_spec={'parents': new_parents},
        )
示例#7
0
    def run_task(self, fw_spec):
        simtree = fw_spec['simtree']

        # check exit
        # will raise Error if simulation didn't finish
        finished = self.check_exit(self['fmt'], simtree)

        # parse results
        results = self.parse_results(self['fmt'], simtree)
        # save csv of results from *this* simulation
        utils.save_csv(results, os.path.join(simtree, 'this_sim_results.csv'))

        if self.get('previous_result', None) is not None:
            results = self.prepend_previous(self['previous_result'], results)
        # csv of results from all generations of this simulation
        utils.save_csv(results, os.path.join(simtree, 'total_results.csv'))

        if not finished:
            new_fws = self.prepare_restart(
                template=fw_spec['template']
                previous_simdir=simtree,
                current_result=results,
                wfname=fw_spec['_category'],
            )

            return fw.FWAction(
                detours=fw.Workflow(new_fws)
            )
        else:
            parallel_id = self['parallel_id']

            return fw.FWAction(
                stored_data={'result': results.to_csv()},
                mod_spec=[{
                    '_push': {
                        'results': (parallel_id, results.to_csv()),
                        'simpaths': (parallel_id, simtree),
                    }
                }]
            )
示例#8
0
    def run_task(self, fw_spec):
        # create sorted version
        results = sorted(fw_spec['results_array'],
                         key=lambda x: (x[0], x[1]))

        outfile = os.path.join(self.get('workdir', ''), 'results.csv')
        with open(outfile, 'w') as out:
            out.write('temperature,pressure,mean,std,g\n')
            for row in results:
                out.write(','.join(str(val) for val in row))
                out.write('\n')

        return fw.FWAction(
            stored_data={'final_result': results}
        )
示例#9
0
    def run_task(self, fw_spec):
        my_id = self['candidate_id']
        # final fitness is sum of square of errors
        my_fitness = sum(v**2 for v in fw_spec['error'])

        f = (my_id, my_fitness)

        return fw.FWAction(
            stored_data={'fitness': f},
            mod_spec=[{
                '_push': {
                    'fitness': f
                }
            }],
        )
示例#10
0
    def run_task(self, fw_spec):
        result = self.grab_result(fw_spec['simtree'], self['fmt'])

        ref = self['reference']
        my_fitness = abs(result - ref) / ref

        return fw.FWAction(
            stored_data={'error': my_fitness},
            mod_spec=[{
                '_push': {
                    'error':
                    my_fitness,
                    'results_array':
                    (self['temperature'], self['pressure'], result, 1, 1),
                }
            }],
        )
示例#11
0
    def run_task(self, fw_spec):
        timeseries = {p_id: utils.make_series(ts)
                      for (p_id, ts) in fw_spec['results']}

        simple = self.get('simple', True)

        g = 0.0
        means = []
        stds = []

        # starts True, turns false once a single sim wasn't equilibrated
        equilibrated = True

        for p_id, ts in timeseries.items():
            try:
                eq = analysis.find_eq(ts)
            except NotEquilibratedError:
                equilibrated &= False

            production = ts.loc[eq:]
            # how many eq periods have we sampled for?
            g += (production.index[-1] - production.index[0]) / eq
            means.append(production.mean())
            stds.append(production.std())

        if equilibrated and (simple or (g > 20.0)):
            finished = True
            mean = np.mean(means)
            std = np.mean(stds)
        else:
            finished = False

        if finished:
            return fw.FWAction(
                stored_data={'result': (mean, std)},
                mod_spec=[{
                    # push the results of this condition to the Create task
                    '_push': {'results_array': (self['temperature'],
                                                self['pressure'],
                                                mean, std, g)}
                }],
            )
        else:
            # TODO: Calc N remaining here
            # or estimate how many are required
            if not equilibrated:
                nreq = 'something'
            else:
                # make educated guess
                nreq = 'something else'

            return fw.FWAction(
                detours=self.prepare_resample(
                    previous_simdirs={p_id: path
                                      for (p_id, path) in fw_spec['simpaths']},
                    previous_results=timeseries,
                    ncycles=nreq,
                    wfname=fw_spec['_category'],
                    template=fw_spec['template'],
                )
            )
示例#12
0
    def run_task(self, fw_spec):
        candidates = self.blend_crossover(fw_spec['candidates'])
        candidates = self.gaussian_mutation(candidates)

        return fw.FWAction(update_spec={'candidates': candidates})
示例#13
0
    def run_task(self, fw_spec):
        candidates = self.tournament(fw_spec['parents'])

        return fw.FWAction(update_spec={'candidates': candidates})
示例#14
0
 def run_task(self, fw_spec):
     return fw.FWAction(update_spec={k: fw_spec[k] for k in self['keys']})
示例#15
0
 def run_task(self, fw_spec):
     return fw.FWAction(
         update_spec={
             'candidates': self['initial_population'],
             'parents': []  # no parents initially
         })