Exemple #1
0
def dojo_make_hints(options):
    from pymatgen.util.io_utils import ask_yesno, prompt
    import numpy as np

    for pseudo in options.pseudos:
        try:
            report = pseudo.dojo_report

            hints = report.compute_hints()
            print("hints for %s computed from deltafactor prime: %s" % (pseudo.basename, hints))
            report.plot_deltafactor_convergence()

            ans = ask_yesno("Do you accept the hints? [Y]")
            if ans:
                report.add_hints(hints)
                print(report.has_hints)
                pseudo.write_dojo_report(report)
            else:
                print("The dojoreport contains ecuts :\n%s" % report.ecuts)
                new_ecuts = prompt("Enter new ecuts to compute (comma-separated values or empty string to abort)")
                if len(new_ecuts) == 0:
                    print("Exit requested by user")
                    return
                new_ecuts = np.array([float(k) for k in new_ecuts.strip().split(",")])
                print(new_ecuts)
                report.add_ecuts(new_ecuts)
                pseudo.write_dojo_report(report)

        except None:  # Exception as exc:
            print(pseudo.basename, "raised: ", str(exc))
Exemple #2
0
    def start(self):
        """
        Starts the scheduler in a new thread. Returns 0 if success.
        In standalone mode, this method will block until there are no more scheduled jobs.
        """
        self.history.append("Started on %s" % time.asctime())
        self.start_time = time.time()

        if not has_apscheduler:
            raise RuntimeError("Install apscheduler with pip")

        if has_sched_v3:
            self.sched.add_job(self.callback, "interval", **self.sched_options)
        else:
            self.sched.add_interval_job(self.callback, **self.sched_options)

        errors = self.flow.look_before_you_leap()
        if errors:
            self.exceptions.append(errors)
            return 1

        # Try to run the job immediately. If something goes wrong return without initializing the scheduler.
        self._runem_all()

        if self.exceptions:
            self.cleanup()
            self.send_email(
                msg=
                "Error while trying to run the flow for the first time!\n %s" %
                self.exceptions)
            return 1

        try:
            self.sched.start()
            return 0

        except KeyboardInterrupt:
            self.shutdown(msg="KeyboardInterrupt from user")
            if ask_yesno(
                    "Do you want to cancel all the jobs in the queue? [Y/n]"):
                print("Number of jobs cancelled:", self.flow.cancel())

            self.flow.pickle_dump()
            return -1
Exemple #3
0
    def start(self):
        """
        Starts the scheduler in a new thread. Returns 0 if success.
        In standalone mode, this method will block until there are no more scheduled jobs.
        """
        self.history.append("Started on %s" % time.asctime())
        self.start_time = time.time()

        if not has_apscheduler:
            raise RuntimeError("Install apscheduler with pip")

        if has_sched_v3:
            self.sched.add_job(self.callback, "interval", **self.sched_options)
        else:
            self.sched.add_interval_job(self.callback, **self.sched_options)

        errors = self.flow.look_before_you_leap()
        if errors:
            self.exceptions.append(errors)
            return 1

        # Try to run the job immediately. If something goes wrong return without initializing the scheduler.
        self._runem_all()

        if self.exceptions:
            self.cleanup()
            self.send_email(msg="Error while trying to run the flow for the first time!\n %s" % self.exceptions)
            return 1

        try:
            self.sched.start()
            return 0

        except KeyboardInterrupt:
            self.shutdown(msg="KeyboardInterrupt from user")
            if ask_yesno("Do you want to cancel all the jobs in the queue? [Y/n]"):
                print("Number of jobs cancelled:", self.flow.cancel())

            self.flow.pickle_dump()
            return -1
Exemple #4
0
def dojo_make_hints(options):
    """Add hints for energy cutoffs"""
    for pseudo in options.pseudos:

        if not pseudo.has_dojo_report:
            cprint("[%s] No DojoReport. Ignoring pseudo" % p.basename, "red")
            continue

        report = pseudo.dojo_report

        try:
            hints = report.compute_hints()
            print("hints for %s computed from deltafactor prime: %s" % (pseudo.basename, hints))
            report.plot_deltafactor_convergence(xc=pseudo.xc)

            ans = ask_yesno("Do you accept the hints? [Y]")
            if ans:
                report.add_hints(hints)
                print(report.has_hints)
                report.json_write()
            else:
                print("The dojoreport contains ecuts :\n%s" % report.ecuts)
                new_ecuts = prompt("Enter new ecuts to compute (comma-separated values or empty string to abort)")
                if not new_ecuts:
                    print("Exit requested by user")
                    return
                new_ecuts = np.array([float(k) for k in new_ecuts.strip().split(",")])
                print("new_ecuts", new_ecuts)
                report.add_ecuts(new_ecuts)
                report.json_write()

        except Exception as exc:
            cprint("[%s]: python exception: %s" % (pseudo.basename, type(exc)), "red")
            if options.verbose: print(straceback())

    return 0
Exemple #5
0
def dojo_validate(options):
    """Validate the pseudo."""
    pseudos = options.pseudos
    data, errors = pseudos.get_dojo_dataframe()

    for p in pseudos:
        try:
            # test if report is present
            if not p.has_dojo_report:
                cprint("[%s] No DojoReport. Ignoring pseudo" % p.basename, "red")
                continue
            report = p.dojo_report

            # test if already validated
            if 'validation' in report:
                cprint('this pseudo was validated by %s on %s.' % (
                       report['validation']['validated_by'], report['validation']['validated_on']), "red")
		if not ask_yesno('Would you like to validate it again? [Y/n]'):
		    continue

            # test for ghosts
            print('\n= GHOSTS TEST ===========================================\n')
            if report.has_trial('ghosts'):
                for ecut in report['ghosts']:
                    if "ghost_free_upto_eV" in report["ghosts"][ecut]:
                        print('%s: Pseudo is reported to be ghost free up to %s eV' % (
                          ecut, report["ghosts"][ecut]["ghost_free_upto_eV"]))
                    else:
                        report.plot_ebands(ecut=ecut)
                        ans = float(prompt('Please enter the energy (eV) up until there is no sign of ghosts:\n'))
                        if ans > 0:
                            report["ghosts"][ecut]["ghost_free_upto_eV"] = ans
                            report.json_write()
            else:
                cprint('no ghosts trial present, pseudo cannot be validated', "red")
                continue

            # test trials
            print('\n= TRIALS TEST ===========================================\n')
            try:
                error = report.check(check_trials=None)
                if error:
                    cprint("[%s] Validation problem" % p.basename, "red")
                    if options.verbose:
                        print(error)
                        print()

            except Exception as exc:
                cprint("[%s] Python exception: %s" % (p.basename, type(exc)), "red")
                if options.verbose:
                    print(exc)
                    print("")

            accuracies = ["low", "normal", "high"]
            keys = ['hint', 'deltafactor', 'gbrv_bcc', 'gbrv_fcc', 'phonon']

            tablefmt = "grid"
            floatfmt=".2f"

            print('\n= ECUTS  TEST ===========================================\n')
            for acc in accuracies:
                columns = ["symbol"]
                headers = ["symbol"]
                for k in keys:
                    entry = acc + "_ecut_" + k
                    if entry in data:
                        columns.append(entry)
                        headers.append(k)
                print('ECUTS for accuracy %s:' % acc)
                print(tabulate(data[columns], headers=headers, tablefmt=tablefmt, floatfmt=floatfmt))

            # TODO
            # test hash
            # plot the model core charge

        except Exception as exc:
            cprint("[%s] python exception" % p.basename, "red")
            if options.verbose: print(straceback())

        # ask the final question
        if ask_yesno('Will you validate this pseudo? [n]'):
            name = prompt("Please enter your name for later reference: ")
            report['validation'] = {'validated_by': name, 'validated_on': strftime("%Y-%m-%d %H:%M:%S", gmtime())}
            report.json_write()

    return 0