Esempio n. 1
0
def do_process(args):
    """Process arguments of the script
    
    """

    if args.filename:
        fname = args.filename[0]
        print("Processing file: ", fname)

        try:
            INP = qr.Input(fname)
            code = tasks(INP.tasks, INP)
        except:
            print(traceback.format_exc())
            return

    if args.output:

        print("Script saved as: ", args.output)

    else:

        print("\nResulting code:\n")
        print(code)
Esempio n. 2
0
def do_command_run(args):
    """Runs a script 
    
    
    """

    m = qr.Manager().log_conf
    dc = qr.Manager().get_DistributedConfiguration()

    #
    # analyzing --verbosity option
    #
    verb = args.verbosity
    try:
        vrbint = int(verb)
        m.verbosity = vrbint
        m.fverbosity = vrbint + 2
    except:
        try:
            vrbint = verb.split(",")
            m.verbosity = int(vrbint[0])
            m.fverbosity = int(vrbint[1])
        except:
            raise Exception(
                "Integer or two comma separated integers required" +
                " for -y/--verbosity option")

    # we set the verbosity lower for other than the leading process
    if dc.rank != 0:
        m.verbosity -= 2
        m.fverbosity -= 2

    #
    # log into file
    #
    m.log_to_file = args.logtofile

    if m.log_to_file:
        m.log_file_name = args.filename

    #
    # parallel options
    #
    nprocesses = args.nprocesses
    flag_parallel = args.parallel
    hostfile = ""
    if len(args.hostfile) > 0:
        hostfile = args.hostfile

    #
    # some other logging option
    #
    flag_silent = args.silent
    flag_quiet = args.quiet
    if args.silent:
        m.verbosity = 0

    #
    # Run benchmark
    #
    if args.benchmark > 0:
        import time

        qr.printlog("Running benchmark no. ",
                    args.benchmark,
                    verbose=True,
                    loglevel=1)
        import quantarhei.benchmarks.bm_001 as bm
        t1 = time.time()
        bm.main()
        t2 = time.time()
        qr.printlog("... done in", t2 - t1, "sec", verbose=True, loglevel=1)

        return

    #
    # Script name
    #
    if args.script:
        scr = args.script[0]

    #
    # if the file is yaml, look into it to find the script file name
    #
    # get the file extension
    extsplt = os.path.splitext(scr)
    ext = extsplt[1]

    #
    # Reading configuration file
    #

    # yaml
    if ext in [".yaml", ".yml"]:
        INP = qr.Input(scr)
        # see if the script name is specified, if not use the conf name + .py
        try:
            script = INP.script
        except:
            script = extsplt[0] + ".py"
        # see if path is defined, if not use local directory
        try:
            spath = INP.path
        except:
            spath = "."

        scr = os.path.join(spath, script)

    #
    # Greeting
    #
    if not flag_quiet:
        qr.printlog("", verbose=True, loglevel=qr.LOG_URGENT)
        qr.printlog("Running Quantarhei (python) script file: ",
                    scr,
                    verbose=True,
                    loglevel=qr.LOG_URGENT)

    #
    # Run serial or parallel
    #

    if flag_parallel:

        #
        # If this is set to True, we use one more processes than processor
        # number to steer other processes
        #
        # Also set the corresponding flag in the parallel module
        #
        use_steerer = False
        if use_steerer:
            nsteerer = 1
        else:
            nsteerer = 0

        #
        # get parallel configuration
        #
        cpu_count = 0
        try:
            import multiprocessing
            cpu_count = multiprocessing.cpu_count()
        except (ImportError, NotImplementedError):
            pass

        prl_exec = "mpirun"
        prl_n = "-n"
        prl_h = ""
        if len(hostfile) > 0:
            prl_h += " --hostfile " + hostfile + " "

        if cpu_count != 0:
            prl_np = cpu_count + nsteerer
        else:
            prl_np = 4

        if nprocesses != 0:
            prl_np = nprocesses + nsteerer

        #
        engine = "qrhei"
        if m.log_to_file:
            engine += " -lf " + m.log_file_name
        engine += " -y " + str(m.verbosity) + "," + str(
            m.fverbosity) + " run -q "

        # running MPI with proper parallel configuration
        prl_cmd = prl_exec + " " + prl_n + " " + str(prl_np) + " " + prl_h
        cmd = prl_cmd + engine + scr

        if not flag_silent:
            qr.printlog("System reports", cpu_count, "processors")
            qr.printlog("Starting parallel execution with", prl_np,
                        "processes (executing command below)")
            qr.printlog(">>>", cmd)
            qr.printlog("")

        try:
            p = subprocess.Popen(cmd,
                                 shell=True,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)

            if not flag_silent and (not flag_quiet):
                qr.printlog(" --- output below ---\n",
                            verbose=True,
                            loglevel=1)

            # read and print output
            for line in iter(p.stdout.readline, b''):
                #for line in p.stdout.readlines():
                ln = line.decode()
                # line is returned with a \n character at the end
                # ln = ln[0:len(ln)-2]
                print(ln, end="", flush=True)

            retval = p.wait()

        except SystemExit:

            qr.printlog("", verbose=True, loglevel=qr.LOG_DETAIL)
            qr.printlog(" --- Exited by SystemExit --- ",
                        verbose=True,
                        loglevel=qr.LOG_DETAIL)
            pass

    else:

        if not flag_silent and (not flag_quiet):
            qr.printlog(" --- output below ---\n",
                        verbose=True,
                        loglevel=qr.LOG_URGENT)

        # running the script within the same interpreter
        try:

            # launch this properly, so that it gives information
            # on the origin of exceptions
            with open(scr, 'U') as fp:
                code = fp.read()
            exec(compile(code, scr, "exec"), globals())

        except SystemExit:

            qr.printlog("", verbose=True, loglevel=qr.LOG_DETAIL)
            qr.printlog(" --- Exited by SystemExit --- ",
                        verbose=True,
                        loglevel=qr.LOG_DETAIL)

        except:

            print(traceback.format_exc())

        retval = 0

    #
    # Saying good bye
    #
    if retval == 0:
        if not flag_silent and (not flag_quiet):
            qr.printlog("", verbose=True, loglevel=1)
            qr.printlog(" --- output above --- \n",
                        verbose=True,
                        loglevel=qr.LOG_URGENT)
            qr.printlog("Finished sucessfully; exit code: ",
                        retval,
                        verbose=True,
                        loglevel=1)
    else:
        qr.printlog("Warning, exit code: ",
                    retval,
                    verbose=True,
                    loglevel=qr.LOG_URGENT)
Esempio n. 3
0
import numpy

import quantarhei as qr

from quantarhei.utils.vectors import X
import quantarhei.functions as func
from quantarhei.core.units import kB_int

from quantarhei import printlog as print

print("\n***** Rc Simulation Script" + " *****")

input_file = "ex_853_RC.yaml"

INP = qr.Input(input_file, show_input=False)  #,
#math_allowed_in =["E0",
#                  ["params", ["HR", "omega", "rate"]] ])

make_movie = INP.make_movie
show_plots = INP.show_plots
save_containers = INP.save_containers
detailed_balance = INP.detailed_balance


def init_containers():
    """Initialized containers

    """

    cont_p_re = qr.TwoDSpectrumContainer()
Esempio n. 4
0
import shutil
import gc

import numpy

import quantarhei as qr

from quantarhei.utils.vectors import X 
import quantarhei.functions as func
from quantarhei.core.units import kB_int

print("\n***** Calculation of material for disorder integration (dimer version) *****")

input_file = "ex_853_RC.yaml"
#input_file = {'E0': 10000.0, 'resonance_coupling': 100.0, 'no_g_vib': 2, 'no_e_vib': 2, 'params': {'HR': 0.01, 'omega': 500.0, 'use_vib': True}, 'location_of_vibrations': 'up', 'append_to_dirname': '_center=600_FWHM=100', 'dip1': [1.5, 0.0, 0.0], 'dip2': [-1.0, -1.0, 0.0], 'rate': '1.0/500.0', 'temperature': 77.0, 't2_N_steps': 100, 't2_time_step': 10.0, 'fine_splitting': 10, 't1_N_steps': 100, 't1_time_step': 10.0, 't3_N_steps': 100, 't3_time_step': 10.0, 'feature_width': 100.0, 'trim_maps_to': [9900, 11500, 9000, 11500], 'omega_uncertainty': 200.0, 'tukey_window_r': 0.3, 'center': 600.0, 'step': 2.0, 'max_available_fwhm': 100.0, 'how_many_fwhm': 2, 'make_movie': False, 'show_plots': False, 'save_containers': False, 'detailed_balance': True, 't2_save_pathways': [50.0, 100.0, 200.0, 300.0], 'copy_input_file_to_results': True, '_math_allowed_in': ['E0', 'resonance_coupling', 'rate', ['params', ['HR', 'omega', 'rate']], 'center', 'step', 'max_available_fwhm', 'how_many_fwhm', 't2_save_pathways']}
INP = qr.Input(input_file, show_input=True) #, 
               #math_allowed_in =["E0", 
               #                  ["params", ["HR", "omega", "rate"]] ])

make_movie = INP.make_movie
show_plots = INP.show_plots
save_containers = INP.save_containers
detailed_balance = INP.detailed_balance



def run(omega, HR, dE, JJ, rate, E0, vib_loc="up", use_vib=True,
        stype=qr.signal_REPH, make_movie=False, save_eUt=False,
        t2_save_pathways=[], dname=None, trimer=None):
    """Runs a complete set of simulations for a single set of parameters
    
  This example assumes 2D spectra of a dimer with a range of energy gaps
  to be precalculated in a designated directory ("sim_up" by default)




"""

import os
import numpy
import quantarhei as qr



INP = qr.Input("ex_854_2DSpectrum_DimerDisorder.yaml") 
               #math_allowed_in=["E1", "E2", "width_dis"])

if INP.input_file_from_results:
    ifile = os.path.join(INP.dname, INP.input_file)
else:
    ifile = INP.input_file
    
INP_pre = qr.Input(ifile, math_allowed_in=INP.with_math_allowed_in)

# directory with the precalculated results
dname = INP.dname #"sim_up"

#
# Transition energy for which the spectra are calculated
#
Esempio n. 6
0
#
#
###############################################################################
#
# Script initialization
#
###############################################################################
#
#
import quantarhei as qr


#
# Read QTask input file
#
INP = qr.Input()


#
#
###############################################################################
#
#  End of initialization
#
###############################################################################
#
#