Ejemplo n.º 1
0
def run(slhadata, inputs=None, update=False) :
    SIout = SuperISOPrecObs()
    fname = "/tmp/mc-{u}".format(u=tools.unique_str())
    slhadata.write(fname)
    SIlib.run_superiso(c_char_p(fname.encode('ascii')), byref(SIout))
    tools.rm(fname)
    return tools.ctypes_field_values(SIout, name)
Ejemplo n.º 2
0
 def __str__(self):
     tmp_name=unique_filename(self._tmp_dir)
     self.write(tmp_name)
     f=open(tmp_name)
     txt=f.read()
     f.close()
     rm(tmp_name)
     return txt
Ejemplo n.º 3
0
def run(slhadata, inputs=None, update=False):
    if inputs is None:
        inputs = {}
    SIout = SuperISOPrecObs()
    fname = unique_filename(inputs.get("tmp_dir"))
    slhadata.write(fname)
    SIlib.run_superiso(c_char_p(fname.encode("ascii")), byref(SIout))
    rm(fname)
    # FIXME: No error handling yet
    return ctypes_field_values(SIout, name)
Ejemplo n.º 4
0
def run(slhadata, inputs=None, update=False) :
    MOout = MicromegasPrecObs()
    reader = lambda f: MOlib.run_micromegas(c_char_p(f.encode('ascii')), byref(MOout))
    writer = lambda f: slhadata.write(f)

    fname = "/tmp/mc-{u}".format(u=unique_str())
    writer(fname)
    reader(fname)
    rm(fname)
    return ctypes_field_values(MOout, name)
Ejemplo n.º 5
0
def run( inputs,verbose=None):          
    try:
        version=inputs['version']
    except KeyError:
        version=default_version
    print(version)
    if inputs.get('file'):
        fname=inputs['file']
        with open(fname,'r') as softpoint_input_file:
            try:
                my_out = subprocess.check_output(['./packages/bin/softpoint{}.x'.format(version),'leshouches'],stdin=softpoint_input_file)
                my_out=my_out.decode('utf-8')
                error =  ('invalid' in str(my_out)) or ('problem' in str(my_out))
            except subprocess.CalledProcessError:
                my_out=None
                error = 2
    elif inputs.get('model'):
        model=inputs['model']
        # set inputs to default
        slha_params=default_inputs.copy()
        # update to get the parsed inputs
        slha_params.update(inputs)

        if   model=='cMSSM':
            inputslha=get_cmssm_input_slha(slha_params)
        elif model=='NUHM1':
            inputslha=get_nuhm1_input_slha(slha_params)
        elif model=='pMSSM':
            inputslha=get_pmssm_input_slha(slha_params)
        elif model=='pMSSM8':
            inputslha=get_pmssm8_input_slha(slha_params)
        elif model=='pMSSM10':
            inputslha=get_pmssm10_input_slha(slha_params)
        else:
            print("ERROR: No valid model provided")
            return "", 1
        if verbose: print(inputslha)

        # then run on the inputslha file
        fname=unique_filename(inputs.get('tmp_dir'))
        with open(fname,'w') as softpoint_input_file:
            softpoint_input_file.write(inputslha)
        with open(fname,'r') as softpoint_input_file:
            try:
                my_out = subprocess.check_output(['./packages/bin/softpoint{}.x'.format(version),'leshouches'],stdin=softpoint_input_file)
                my_out=my_out.decode('utf-8')
                error =  ('invalid' in str(my_out)) or ('problem' in str(my_out))
            except subprocess.CalledProcessError:
                my_out=None
                error = 2
        rm(fname)
    return my_out, error
Ejemplo n.º 6
0
    def __init__(self, data="",lookup=None,tmp_dir=None):
        self._tmp_dir=tmp_dir
        if lookup:
            self.lookup=lookup
        else:
            self.lookup=self.create_lookup()
        if data:
#            #cannot do produce lookup on the fly with the pipe_object_to_function
#            #therefore, do it separate
            fname=unique_filename(self._tmp_dir)
            with open(fname,'w') as softpoint_input_file:
                softpoint_input_file.write(data)
            self.read(fname)
            rm(fname)
def run(slhadata, inputs=None, update=False) :
    if inputs is None: inputs={}
    try:
        versions=inputs['versions']
    except KeyError:
        versions=[default_version]
    #write out slha file
    fname=unique_filename(inputs.get('tmp_dir'))
    slhadata.write(fname)
    #define default outputs
    return_output={}
    for version in versions:
        executable='packages/bin/micromegas-{}.x'.format(version)
        try:
            std_out=(subprocess.check_output([executable,fname])).decode('utf-8') 
            #define empty and then fill
            output={}
            #get Omega and sigma_p_si and possibly other variables from standard out
            lines=std_out.split('\n')
            nanflag=False
            for line in lines:
                if ('MastercodeTag' in line) :
                    if not ('nan' in line):
                        tag, obs, val = json.loads(line)
                        output[obs]=val
                    else :
                        nanflag=True
            output['error']=int(nanflag)
        except subprocess.CalledProcessError as e:
            #if micromegas fails, it exits with non zero code. This is cought by subprocess.CalledProcessError
            std_out=e.output.decode('utf-8')
            #only output error, since no calculation has been made
            output={'error':1}
        if len(versions)==1:
            return_output={(name,key): val for key, val in output.items() }
        else:
            return_output.update({(name+version,key): val for key, val in output.items() })
    #rm slha file
    rm(fname)
    #handle verbosity
    if 'verbose' in inputs:
        print(std_out)
    return return_output 
Ejemplo n.º 8
0
 def __str__(self):
     tmp_name = "/tmp/mc-{u}".format(u=unique_str())
     self.write(tmp_name)
     txt=open(tmp_name).read()
     rm(tmp_name)
     return txt