Esempio n. 1
0
def mc_test(fname=None):
    import sampler
    global xmin, xmax, shape, scale, gshape, gscale, kappa, loc, dim, kappa0
    global fsamp
    global fscan
    global fsamplines
    global fscanlines
    global check_prob

    check_prob = True
    shape = 2.120
    scale = 9.767
    gshape = 10
    gscale = .2
    kappa = 1
    kappa0 = 1
    loc = -0.1

    dim = 1
    xmin = np.array([0])
    xmax = np.array([50])
    allns = [[20]]

    #    dim = 2
    #    xmin = np.array([0,-pi+0.001])
    #    xmax = np.array([30,pi-0.001])
    #    allns = [[5,9],[11,9],[21,9] , [100,100]  ]

    dim = 4
    xmin = np.array([1, -pi, 0, 0])
    xmax = np.array([30, pi, 6, 6])
    #    allns = [  [2,2,3,3], [3,3,3,3],  [4,4,3,3], [4,4,4,4], [8,8,6,6] ,[10,10,8,8] ]
    #    allns = [   [4,4,3,3], [8,8,6,6] , [16,16,12,12]    ]
    #    allns = [[2,2,3,3]  ]
    #    allns = [ [3,3,3,3], [4,4,4,4] ]
    allns = [[16, 16, 16, 16]]
    #    allns = [[6,6,4,4], [6,6,6,6]]
    sctx = sampler.Context(dim)

    if (fname != None):
        fsamplines = file(fname).readlines()
        ll = len(fsamplines) - 1
        allns = [[ll]]  ## hopefully just tricks code below
    for ns in allns:
        if (fname == None):
            fname = "mc_samples"
            for d in ns:
                fname += "%d" % d
            fname += ".out"
            fsamplines = file(fname).readlines()

        fsamplines = fsamplines[1:]
        fsamplines = [[float(x) for x in ln.split()] for ln in fsamplines]

        lsum2 = int_mc4_cumulative(sctx, ns, 10)
        print ns, lsum2
Esempio n. 2
0
def test_convergence(fname, use_prob, field_idx, minsamp, maxsamp, incr):
    sctx = sampler.Context()
    nsamp = minsamp
    foutname = "%s.conv" % (fname)
    fout = file(foutname, "w")
    while (nsamp < maxsamp):
        onedat = final_load_calc(sctx, fname, use_prob, field_idx, nsamp)
        fout.write("%d %e %e\n" % (onedat[0], onedat[1], onedat[2]))
        nsamp += incr
    fout.close()
Esempio n. 3
0
def rundlcs():
    """ 
    run the whole process, including startup and shutdown
    to do:
    parse input
    create load cases
    create app assembly
    create dispatcher
    send cases and app to dispatcher
    run cases
    collect and save output
    """

    options, arg = get_options()
    ctrl = parse_input(options.main_input, options)
    # ctrl will be just the input, but broken up into separate categories, e.g.
    # ctrl.cases, ctrl.app, ctrl.dispatch, ...

    if (options.cluster_allocator):
        cluster = ClusterAllocator()
        RAM.insert_allocator(0, cluster)

    ###  using "factory" functions to create specific subclasses (e.g. distinguish between FAST and HAWC2)
    # Then we use these to create the cases...
    cases = create_load_cases(ctrl.cases, options)
    # and a turbine
    turbine = create_turbine(ctrl.turbine)
    # and the appropriate wind code wrapper...
    aerocode = create_aerocode_wrapper(ctrl.aerocode, options)
    # and the appropriate dispatcher...
    dispatcher = create_dlc_dispatcher(ctrl.dispatcher)
    ### After this point everything should be generic, all appropriate subclass object created

    dispatcher.presetup_workflow(
        aerocode, turbine,
        cases)  # just makes sure parts are there when configure() is called
    dispatcher.configure()
    # Now tell the dispatcher to (setup and ) run the cases using the aerocode on the turbine.
    # calling configure() is done inside run().

    if (not options.norun):
        dispatcher.run()

    # TODO:  more complexity will be needed for difference between "run now" and "run later" cases.
    dispatcher.collect_output(ctrl.output)
    sctx = sampler.Context()

    field_idx = 20  # = RootMyc1Std
    final_load_calc(sctx, "dlcproto.out", not dispatcher.raw_cases, field_idx)
Esempio n. 4
0
from openruniec import final_load_calc as flc
import sampler
sctx = sampler.Context()
[cnt, lsum, psum] = flc(sctx, "dlcproto.out", True, 20)
Esempio n. 5
0
    def collect_output(self, output_params):
        print "RUNS ARE DONE:"

        sctx = sampler.Context()

        if (self.run_dakota):
            print "DAKOTA done, see dakota_tabular.dat"
        else:
            fields = [
                'RootMxc1', 'RootMyc1', 'LSSGagMya', 'LSSGagMza', 'YawBrMxp',
                'YawBrMyp', 'TwrBsMxt', 'TwrBsMyt', 'Fair1Ten', 'Fair2Ten',
                'Fair3Ten', 'Anch1Ten', 'Anch2Ten', 'Anch3Ten'
            ]
            print "collecting output from copied-back files (not from case recorder), see %s" % output_params[
                'main_output_file']
            fout = file(output_params['main_output_file'], "w")
            #            fout.write( "#Vs Hs Tp WaveDir, TwrBsMxt \n")
            fout.write("#Vs Hs Tp WaveDir Prob")
            for f in fields:
                fout.write(" %s " % f)
            for f in fields:
                fout.write(" %sStd " % f)
            fout.write("\n")

            fail_count = [0 for i in 2 * range(len(fields))]
            for fullcase in self.runcases:
                case = fullcase._inputs['runner.input']
                results_dir = os.path.join(self.aerocode.basedir, case.name)
                myfast = self.aerocode.runfast.rawfast
                #                fout.write( "%.2f %.2f %.2f %.2f   %.2f\n" % (case.ws, case.fst_params['WaveHs'], case.fst_params['WaveTp'],case.fst_params['WaveDir'], myfast.getMaxOutputValue('TwrBsMxt', directory=results_dir)))  ### this may not exist, just an example

                x = [
                    case.ws, case.fst_params['WaveDir'],
                    case.fst_params['WaveHs'], case.fst_params['WaveTp']
                ]
                x[1] *= pi / 180.0  ## sampler works in radians, and different order than we print results (because PG is an idiot!)
                prob = sctx.calc_prob(x)
                print "got ", x, "  prob= ", prob

                vals = myfast.getMaxOutputValues(fields, directory=results_dir)
                stdvals = myfast.getMaxOutputValueStdDevs(
                    fields, directory=results_dir)

                #                vals = []
                #                stdvals = []
                for i in range(len(fields)):
                    #                    vstr = fields[i]
                    #                    val = myfast.getMaxOutputValue(vstr, directory=results_dir)
                    #                    stdval = myfast.getMaxOutputValueStdDev(vstr, directory=results_dir)
                    val = vals[i]
                    stdval = stdvals[i]
                    if (val != None):
                        vals.append(val)
                    else:
                        fail_count[i] += 1
                        vals[i] = -99999.9999
                    if (stdval != None):
                        stdvals.append(stdval)
                    else:
                        fail_count[len(fields) + i] += 1
                        stdvals[i] = -99999.9999
                fout.write("%.16e %.16e %.16e %.16e   %.16e" %
                           (case.ws, case.fst_params['WaveHs'],
                            case.fst_params['WaveTp'],
                            case.fst_params['WaveDir'], prob))
                for i in range(len(fields)):
                    v = vals[i]
                    fout.write(" %.6e " % v)
                for i in range(len(fields)):
                    v = stdvals[i]
                    fout.write(" %.6e " % v)
                fout.write("\n")
                ### this may not exist, just an example
#                fout.write( "%.2f    %.2f\n" % (case.ws,  myfast.getMaxOutputValue('TwrBsMxt', directory=results_dir)))  ### this may not exist, just an example
            print "ran %d cases, failcounts:" % len(self.runcases)
            print fields, fields
            print fail_count
Esempio n. 6
0
def run_fast():
    import sampler
    global xmin, xmax, shape, scale, gshape, gscale, kappa, loc, dim, kappa0
    global fsamp
    global fscan
    global fsamplines
    global fscanlines

    shape = 2.120
    scale = 9.767
    gshape = 10
    gscale = .2
    kappa = 1
    kappa0 = 1
    loc = -0.1

    dim = 1
    xmin = np.array([0])
    xmax = np.array([50])
    allns = [[20]]

    #    dim = 2
    #    xmin = np.array([0,-pi+0.001])
    #    xmax = np.array([30,pi-0.001])
    #    allns = [[5,9],[11,9],[21,9] , [100,100]  ]

    dim = 4
    xmin = np.array([1, -pi, 0, 0])
    xmax = np.array([30, pi, 6, 6])
    #    allns = [  [2,2,3,3], [3,3,3,3],  [4,4,3,3], [4,4,4,4], [8,8,6,6] ,[10,10,8,8] ]
    #    allns = [   [4,4,3,3], [8,8,6,6] , [16,16,12,12]    ]
    #    ns = [16,16,16,16]
    ns = [10, 10, 8, 8]
    #    allns = [ [3,3,3,3], [4,4,4,4] ]
    #    allns = [ [10,10,8,8] ]
    #    allns = [[6,6,4,4], [6,6,6,6]]
    sctx = sampler.Context(dim)

    ## this code will go off a single ns that we can subdivide later, ie do one big run, then mine it.
    # these params generate big MC we can also consider sequentially

    # setup the samples for both MC and brute force
    base1 = "mc_samples"
    tag = ""
    for d in ns:
        tag += "%d" % d
    fname1 = base1 + tag + ".txt"
    fsamp = file(fname1, "w")
    fsamp.write("Vhub WaveDir Hs Tp\n")
    base2 = "int_samples"
    fname2 = base2 + tag + ".txt"
    fscan = file(fname2, "w")
    fscan.write("Vhub WaveDir Hs Tp\n")

    # will compute the test integral, but mainly write the samples
    lsum1 = int_det4(sctx, ns, True, False)
    lsum2 = int_mc4(sctx, ns, True, False)
    fsamp.close()
    fscan.close()
    print "for TEST integral:", ns, lsum1, lsum2

    # now actually do the runs, by calling openruniec.py
    os.system("python openruniec.py -i %s -p" % fname1)
    os.system("cp dlcproto.out %s.out" % (base1 + tag))
    os.system("python openruniec.py -i %s -p" % fname2)
    os.system("cp dlcproto.out %s.out" % (base2 + tag))

    # now compute the integrals
    fname1 = base1 + tag + ".out"
    fsamplines = file(fname1).readlines()
    fsamplines = fsamplines[1:]
    fsamplines = [[float(x) for x in ln.split()] for ln in fsamplines]
    fname2 = base2 + tag + ".out"
    fscanlines = file(fname2).readlines()
    fscanlines = fscanlines[1:]
    fscanlines = [[float(x) for x in ln.split()] for ln in fscanlines]

    # will compute the real integral, by reading the samples
    lsum1 = int_det4(sctx, ns, False, True)
    lsum2 = int_mc4(sctx, ns, False, True)
    print "for REAL integral:", ns, lsum1, lsum2
Esempio n. 7
0
def int_test(fnamein=None, head=None, tail=None):
    import sampler
    global xmin, xmax, shape, scale, gshape, gscale, kappa, loc, dim, kappa0
    global fsamp
    global fscan
    global fsamplines
    global fscanlines

    shape = 2.120
    scale = 9.767
    gshape = 10
    gscale = .2
    kappa = 1
    kappa0 = 1
    loc = -0.1

    dim = 1
    xmin = np.array([0])
    xmax = np.array([50])
    allns = [[20]]

    #    dim = 2
    #    xmin = np.array([0,-pi+0.001])
    #    xmax = np.array([30,pi-0.001])
    #    allns = [[5,9],[11,9],[21,9] , [100,100]  ]

    dim = 4
    xmin = np.array([1, -pi, 0, 0])
    xmax = np.array([30, pi, 6, 6])
    #    allns = [  [2,2,3,3], [3,3,3,3],  [4,4,3,3], [4,4,4,4], [8,8,6,6] ,[10,10,8,8] ]
    #    allns = [   [4,4,3,3], [8,8,6,6] , [16,16,12,12]    ]
    #    allns = [[2,2,3,3]  ]
    #    allns = [ [3,3,3,3], [4,4,4,4] ]
    allns = [[16, 16, 16, 16]]
    #    allns = [[6,6,4,4], [6,6,6,6]]
    sctx = sampler.Context(dim)

    allns = [[4, 4, 4, 4], [6, 6, 4, 4], [6, 6, 6, 6], [8, 8, 6, 6],
             [8, 8, 8, 8], [10, 10, 8, 8], [16, 16, 12, 12], [16, 16, 16, 16]]
    #int_samples101088.out    int_samples2222.out  int_samples3333.out  int_samples4444.out  int_samples6666.out  int_samples8888.out
    #int_samples16161616.out  int_samples2233.out  int_samples4433.out  int_samples6644.out  int_samples8866.out
    allns = [[4, 4, 4, 4], [6, 6, 4, 4], [6, 6, 6, 6], [8, 8, 6, 6],
             [8, 8, 8, 8], [10, 10, 8, 8], [16, 16, 16, 16]]
    allns = [[20, 20, 20, 20]]
    for ns in allns:
        if (fnamein != None):
            fname = fnamein
        else:
            if (head == None):
                fname = "int_samples"
            else:
                fname = head
            for d in ns:
                fname += "%d" % d
            if (tail == None):
                fname += ".out"
            else:
                fname += tail


#        print "reading from ", fname, "   ns = ", ns
        fscanlines = file(fname).readlines()
        fscanlines = fscanlines[1:]
        fscanlines = [[float(x) for x in ln.split()] for ln in fscanlines]

        res = int_det4_cumulative(sctx, ns, 1)
        print ns, prod(ns), res
Esempio n. 8
0
def real_test(write=False, read=False):
    import sampler
    global xmin, xmax, shape, scale, gshape, gscale, kappa, loc, dim, kappa0
    global fsamp
    global fscan
    global fsamplines
    global fscanlines

    shape = 2.120
    scale = 9.767
    gshape = 10
    gscale = .2
    kappa = 1
    kappa0 = 1
    loc = -0.1

    dim = 1
    xmin = np.array([0])
    xmax = np.array([50])
    allns = [[20]]

    #    dim = 2
    #    xmin = np.array([0,-pi+0.001])
    #    xmax = np.array([30,pi-0.001])
    #    allns = [[5,9],[11,9],[21,9] , [100,100]  ]

    dim = 4
    xmin = np.array([1, -pi, 0, 0])
    xmax = np.array([30, pi, 6, 6])
    #    allns = [ [2,2,2,2], [2,2,3,3], [3,3,3,3],  [4,4,3,3], [4,4,4,4], [6,6,4,4],[6,6,6,6],[8,8,6,6],
    #              [8,8,8,8],[10,10,8,8],[10,10,10,10],[12,12,12,12],[16,16,12,12],[16,16,16,16]]
    #    allns = [   [4,4,3,3], [8,8,6,6] , [16,16,12,12]    ]
    #    allns = [[2,2,3,3]  ]
    #    allns = [ [3,3,3,3], [4,4,4,4] ]
    #    allns = [ [10,10,8,8] ]
    allns = [[20, 20, 20, 20]]
    sctx = sampler.Context(dim)

    for ns in allns:
        if (write):
            fname = "mc_samples"
            for d in ns:
                fname += "%d" % d
            fname += ".txt"
            fsamp = file(fname, "w")
            fsamp.write("Vhub WaveDir Hs Tp\n")
            fname = "int_samples"
            for d in ns:
                fname += "%d" % d
            fname += ".txt"
            fscan = file(fname, "w")
            fscan.write("Vhub WaveDir Hs Tp\n")
        if (read):
            fname = "mc_samples"
            for d in ns:
                fname += "%d" % d
            fname += ".out"
            fsamplines = file(fname).readlines()
            fsamplines = fsamplines[1:]
            fsamplines = [[float(x) for x in ln.split()] for ln in fsamplines]
            fname = "int_samples"
            for d in ns:
                fname += "%d" % d
            fname += ".out"
            fscanlines = file(fname).readlines()
            fscanlines = fscanlines[1:]
            fscanlines = [[float(x) for x in ln.split()] for ln in fscanlines]

        lsum1 = int_det4(sctx, ns, write, read)
        lsum2 = int_mc4(sctx, ns, write, read)
        print ns, lsum1, lsum2
        #        print ns,  lsum2
        if (write):
            fsamp.close()
            fscan.close()