Ejemplo n.º 1
0
 def drawStuff(self, background=False):
     Samp = Sampler()
     if background:
         Points = [-2, -1, 4, -1, 4, 1, -2, 1]
     else:
         Points = [-1, -1, 1, -1, 1, 1, -1, 1]
     Indicies = [0, 1, 2, 0, 2, 3]
     for i in range(len(Points)):
         Points[i] = Points[i] * self.scale
     Array = array.array("f", Points)
     ArrayBuffer = Buffer(Array)
     IndicieArray = array.array("I", Indicies)
     IndicieBuffer = Buffer(IndicieArray)
     TextureBuffer = Buffer(array.array("f", [0, 0, 1, 0, 1, 1, 0, 1]))
     tmp = array.array("I", [0])
     glGenVertexArrays(1, tmp)
     vao = tmp[0]
     glBindVertexArray(vao)
     ArrayBuffer.bind(GL_ARRAY_BUFFER)
     IndicieBuffer.bind(GL_ELEMENT_ARRAY_BUFFER)
     glEnableVertexAttribArray(0)
     glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0)
     TextureBuffer.bind(GL_ARRAY_BUFFER)
     glEnableVertexAttribArray(1)
     glVertexAttribPointer(1, 2, GL_FLOAT, False, 2 * 4, 0)
     glBindVertexArray(0)
     self.samp = Samp
     self.vao = vao
Ejemplo n.º 2
0
def model_eval(nspins,alpha,op,nsweeps,model_file,state_file=None,opname = 'energy'):
	wf = Nqs.Nqs(nspins,alpha)
	wf.load_parameters(model_file)

	samp = Sampler.Sampler(wf,op,opname=opname)
	estav = samp.run(nsweeps,state_file)
	return estav
Ejemplo n.º 3
0
	def update_vector(self, wf, init_state, batch_size, gamma, step, therm=False):
		self.nvar = wf.N + wf.M + wf.N*wf.M
		wf.init_theta(init_state)
		samp = Sampler.Sampler(wf,self.h,mag0=self.m)
		# if init_state = np.array([]), Sampler.run() will do init_random_state()
		samp.state = np.copy(init_state)
		if therm == True:
			# where change the samp.state
			samp.thermalize(batch_size)
		#print(samp.state)

		results = Parallel(n_jobs=self.parallel_cores)(\
			delayed(get_sampler)(samp,self) for i in range(batch_size))

		#print(samp.state)
		#print("parallel_process\n")

		# three kinds of results with extra dimension "batch_size for" statistic average
		elocals = np.array([i[0] for i in results])
		deriv_vectors = np.array([i[1] for i in results])
		states = np.array([i[2] for i in results])

		# v = S^(-1)*F; W(p+1) = W(p) - gamma(p)*v; W are all the wf variables
		# S*v = F; So this is a problem to solve the quation and find v
		# Thus the cov_operator*v represent S*v, i.e. self.cov_operator
		'''
		cov_operator = LinearOperator((wf.N,wf.N), dtype=complex,\
			matvec=lambda v: self.cov_operator(v,deriv_vectors,step))
			'''
		forces = self.get_forces(elocals, deriv_vectors)
		vec, info = cg(self.cov_operator(deriv_vectors,step), forces)
		updates = -gamma * vec

		self.step_count += batch_size
		return updates, samp.state, np.mean(elocals) / self.nspins
Ejemplo n.º 4
0
def setup():
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    glEnable(GL_MULTISAMPLE)
    
    samp = Sampler()
    samp.bind(0)
    
    glClearColor(0.2,0.4,0.6,0)
    
    prog = Program("vs.txt","fs.txt")
    prog.use()
    
    globs.car = Car()
Ejemplo n.º 5
0
    def __init__(self, fontname, size):
        if Text.prog == None:
            Text.prog = Program("TextVertexShader.txt",
                                "TextFragmentShader.txt")

        self.txt = "temp"
        self.samp = Sampler()
        self.font = TTF_OpenFont(
            os.path.join("assets", fontname).encode(), size)
        open(os.path.join("assets", fontname))
        vbuff = Buffer(array.array("f", [0, 0, 1, 0, 1, 1, 0, 1]))
        ibuff = Buffer(array.array("I", [0, 1, 2, 0, 2, 3]))
        tmp = array.array("I", [0])
        glGenVertexArrays(1, tmp)
        self.vao = tmp[0]
        glBindVertexArray(self.vao)
        ibuff.bind(GL_ELEMENT_ARRAY_BUFFER)
        vbuff.bind(GL_ARRAY_BUFFER)
        glEnableVertexAttribArray(0)
        glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0)
        glBindVertexArray(0)
        self.tex = DataTexture2DArray(1, 1, 1, array.array("B", [0, 0, 0, 0]))
        self.textQuadSize = vec2(0, 0)
        self.pos = vec2(0, 0)
        self.dirty = False
        surf1p = TTF_RenderUTF8_Blended(self.font, self.txt.encode(),
                                        SDL_Color(255, 255, 255, 255))
        surf2p = SDL_ConvertSurfaceFormat(surf1p, SDL_PIXELFORMAT_ABGR8888, 0)
        w = surf2p.contents.w
        h = surf2p.contents.h
        pitch = surf2p.contents.pitch
        if pitch != w * 4:
            print("Uh Oh!", pitch, w)
        pix = surf2p.contents.pixels
        B = string_at(pix, pitch * h)
        self.tex.setData(w, h, 1, B)
        SDL_FreeSurface(surf2p)
        SDL_FreeSurface(surf1p)
        self.textQuadSize = vec2(w, h)
        self.dirty = False

        Program.setUniform("textPosInPixels", self.pos)
        Program.setUniform("textQuadSizeInPixels", self.textQuadSize)
        Program.updateUniforms()
Ejemplo n.º 6
0
    raw_input("Press enter to exit...")

    # =================================================
    # PHASE I: scan for transition configurations
    # =================================================

    with env:

        # instantitate multi-modal sampler
        query = [np.array([-5, 0, 20.3]), np.array(final_task[0])]
        n = float(robots.instance_number - 1)
        pr = (float(RADIUS * 2) * (n - 2)) / 100
        pair0 = (UNLOCK, LOCK0)
        pair1 = (UNLOCK, LOCKN)
        sampler01 = Sampler(mode=3, is_trans=True, pair=pair0, pair_range=pr)
        sampler02 = Sampler(mode=4, is_trans=True, pair=pair1, pair_range=pr)
        trans_samplers = [sampler01]
        #trans_samplers = [sampler01, sampler02]

        # multiModalPlanning
        init_node, goal_node, _ = effMultiModalPlanner(query, robots,
                                                       trans_samplers, CLIFF,
                                                       pr)

        # heuristic search
        frontier = [(0, init_node)]
        parent = {init_node: (0, None)}
        while True:
            cost, node = hq.heappop(frontier)
            if node == goal_node:
Ejemplo n.º 7
0
keys = ['event_info', 'jet1_PFCands', 'jet1_extraInfo', 'jet2_PFCands', 'jet2_extraInfo', 'jet_kinematics',  'truth_label']


base_dir = "/eos/user/t/tloesche/CASE_data/CASE_pancakes/"
out_dir = "/eos/cms/store/group/phys_b2g/CASE/h5_files/2017/BB_norepeats_v3_2500/"
qcd1_name = base_dir + "QCD/qcd_1000to1500_merge.h5"
qcd2_name = base_dir + "QCD/qcd_1500to2000_merge.h5"
qcd3_name = base_dir + "QCD/qcd_2000toInf_merge.h5"

sig1_name = base_dir +  "signal/grav_merge.h5"
sig2_name = base_dir +  "signal/wprime_0.h5"
sig3_name = base_dir +  "signal/wkk_0.h5"
sig4_name = base_dir +  "signal/bstar_merge.h5"


qcd1 = Sampler( qcd1_name, pbTofb * 1088., lumi, holdout_frac = bkg_holdout_frac)
qcd2 = Sampler( qcd2_name, pbTofb * 99.11, lumi, holdout_frac = bkg_holdout_frac)
qcd3 = Sampler( qcd3_name, pbTofb * 20.23, lumi, holdout_frac = bkg_holdout_frac)

sig1 = Sampler(sig1_name, n_sig, 1., isSignal = True, holdout_frac = sig_holdout_frac)
sig2 = Sampler(sig2_name, n_sig, 1., isSignal = True, holdout_frac = sig_holdout_frac)
sig3 = Sampler(sig3_name, n_sig, 1., isSignal = True, holdout_frac = sig_holdout_frac)
sig4 = Sampler(sig4_name, n_sig, 1., isSignal = True, holdout_frac = sig_holdout_frac)

ws = [qcd1, qcd2, qcd3, sig1, sig2, sig3, sig4]
BB = BlackBox(ws, keys, nBatches = options.nBatch)
os.system("mkdir %s" % out_dir)
f_out_name = out_dir + 'BB'
BB.writeOut(f_out_name)
#h_name = out_dir + "BB_testset"
#BB.writeHoldOut(h_name + ".h5")
Ejemplo n.º 8
0
#!python3.6
#coding:utf-8
import time
import Player
import Sampler
import BaseWaveMaker
import MusicTheory.EqualTemperament
import MusicTheory.Scale
import MusicTheory.tempo
import WaveFile
if __name__ == "__main__":
    wm = BaseWaveMaker.BaseWaveMaker()
    sampler = Sampler.Sampler()

    et = MusicTheory.EqualTemperament.EqualTemperament()
    scale = MusicTheory.Scale.Scale()
    timebase = MusicTheory.tempo.TimeBase()
    timebase.BPM = 120
    timebase.Metre = (4, 4)
    nv = MusicTheory.tempo.NoteValue(timebase)

    p = Player.Player()
    p.Open()
    print('---------- メジャー・スケール ----------')
    for key in [
            'C', 'C+', 'D', 'D+', 'E', 'F', 'F+', 'G', 'G+', 'A', 'A+', 'B'
    ]:
        print(key, 'メジャー・スケール')
        scale.Major(key=key)
        #        print(','.join([MusicTheory.Key.Key.ValueToName(k) for k in scale.Scales]))
        #        print(','.join([str(f0) for f0 in scale.Frequencies]))
Ejemplo n.º 9
0
from Sampler import *

np.random.seed(123)

pbTofb = 1000.
qcd1 = Sampler("../H5_maker/test_files/QCD_HT1000to1500_test.h5",
               pbTofb * 1088., 1.)
qcd2 = Sampler("../H5_maker/test_files/QCD_HT1500to2000_test.h5",
               pbTofb * 99.11, 1.)
qcd3 = Sampler("../H5_maker/test_files/QCD_HT2000toInf_test.h5",
               pbTofb * 20.23, 1.)
sig = Sampler(
    "../H5_maker/test_files/WprimeToWZToWhadZhad_narrow_M-3500_TuneCP5_13TeV-madgraph_test.h5",
    30000., 1.)

ws = [qcd1, qcd2, qcd3, sig]
#keys= ['event_info', 'jet_kinematics', 'truth_label', 'jet1_extraInfo', 'jet1_PFCands']
keys = []
BB = BlackBox(ws, keys)
#print(BB['truth_label'].shape)
#print(BB['jet_kinematics'].shape)

BB.writeOut('BB_test_Wprime.h5')
Ejemplo n.º 10
0
from Sampler import *

np.random.seed(123)

pbTofb = 1000.
bkg_holdout_frac = 0.05
sig_holdout_frac = 0.2
nBatches = 2
lumi = 1.
qcd1 = Sampler("../H5_maker/test_files/QCD_HT1000to1500_test.h5",
               pbTofb * 1088.,
               lumi,
               holdout_frac=bkg_holdout_frac)
qcd2 = Sampler("../H5_maker/test_files/QCD_HT1500to2000_test.h5",
               pbTofb * 99.11,
               lumi,
               holdout_frac=bkg_holdout_frac)
qcd3 = Sampler("../H5_maker/test_files/QCD_HT2000toInf_test.h5",
               pbTofb * 20.23,
               lumi,
               holdout_frac=bkg_holdout_frac)
sig = Sampler(
    "../H5_maker/test_files/WprimeToWZToWhadZhad_narrow_M-3500_TuneCP5_13TeV-madgraph_test.h5",
    20000.,
    lumi,
    isSignal=True,
    holdout_frac=sig_holdout_frac)

ws = [qcd1, qcd2, qcd3, sig]
#ws = [qcd1]
keys = [
Ejemplo n.º 11
0
np.random.seed(123)

pbTofb = 1000.
lumi = 41.5
n_sig = 100000.
n_batches = 40
keys = []  #everything

base_dir = "/eos/cms/store/group/phys_b2g/CASE/h5_files/2017/"
qcd1_name = base_dir + "QCD_HT1000to15000_merge.h5"
qcd2_name = base_dir + "QCD_HT1500to2000_merge.h5"
qcd3_name = base_dir + "QCD_HT2000toInf_merge.h5"

sig1_name = base_dir + "BulkGravToZZToZhadZhad_narrow_M-2500.h5"
sig2_name = base_dir + "WprimeToWZToWhadZhad_narrow_M-3500.h5"
sig3_name = base_dir + "WkkToWRadionToWWW_M2500-R0-08.h5"

for i in range(n_batches):
    print("starting batch %i" % i)
    qcd1 = Sampler(qcd1_name, pbTofb * 1088., lumi / n_batches)
    qcd2 = Sampler(qcd2_name, pbTofb * 99.11, lumi / n_batches)
    qcd3 = Sampler(qcd3_name, pbTofb * 20.23, lumi / n_batches)

    sig1 = Sampler(sig1_name, n_sig / n_batches, 1., isSignal=True)
    sig2 = Sampler(sig2_name, n_sig / n_batches, 1., isSignal=True)
    sig3 = Sampler(sig3_name, n_sig / n_batches, 1., isSignal=True)

    ws = [qcd1, qcd2, qcd3, sig1, sig2, sig3]
    BB = BlackBox(ws, keys)
    BB.writeOut(base_dir + 'BB_batch%i.h5' % i)