Beispiel #1
0
    def test2a(self):
        'normalize: large buffer'
        import mcni
        # create a dummy input
        neutrons = mcni.neutron_buffer(int(3e6))
        narr = neutrons.to_npyarr()
        narr[:, -1] = 1
        neutrons.from_npyarr(narr)
        out = 'tmp-nst-test2a.ns'
        mns.dump(neutrons, out)
        del neutrons

        # try normalize out-of-place
        out2 = 'tmp-nst-test2a-normalized.ns'
        if os.path.exists(out2): os.remove(out2)
        mns.normalize(out, 10., out2)
        neutrons2 = mns.load(out2)
        # and see if it is done correctly
        narr = neutrons2.to_npyarr()
        self.assertTrue((narr[:, -1] == .1).all())
        del neutrons2, narr

        # try normalize in-place
        mns.normalize(out, 10.)
        neutrons2 = mns.load(out)
        # and see if it is done correctly
        narr = neutrons2.to_npyarr()
        self.assertTrue((narr[:, -1] == .1).all())
        return
 def test2a(self):
     'normalize: large buffer'
     import mcni
     # create a dummy input
     neutrons = mcni.neutron_buffer( int(3e6) )
     narr = neutrons.to_npyarr()
     narr[:, -1] = 1
     neutrons.from_npyarr(narr)
     out = 'tmp-nst-test2a.ns'
     mns.dump(neutrons, out)
     del neutrons
     
     # try normalize out-of-place
     out2 = 'tmp-nst-test2a-normalized.ns'
     if os.path.exists(out2): os.remove(out2)
     mns.normalize(out, 10., out2)
     neutrons2 = mns.load(out2)
     # and see if it is done correctly
     narr = neutrons2.to_npyarr()
     self.assertTrue((narr[:, -1] == .1).all())
     del neutrons2, narr
     
     # try normalize in-place
     mns.normalize(out, 10.)
     neutrons2 = mns.load(out)
     # and see if it is done correctly
     narr = neutrons2.to_npyarr()
     self.assertTrue((narr[:, -1] == .1).all())
     return
Beispiel #3
0
    def test2(self):
        'normalize'
        import mcni
        # create a dummy input
        neutrons = mcni.neutron_buffer(10)
        for n in neutrons:
            n.probability = 1
            continue
        out = 'tmp-nst-test2.ns'
        mns.dump(neutrons, out)

        # try normalize out-of-place
        out2 = 'tmp-nst-test2-normalized.ns'
        if os.path.exists(out2): os.remove(out2)
        mns.normalize(out, 10., out2)
        neutrons2 = mns.load(out2)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue

        # try normalize in-place
        mns.normalize(out, 10.)
        neutrons2 = mns.load(out)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue
        return
    def test2(self):
        'normalize'
        import mcni
        # create a dummy input
        neutrons = mcni.neutron_buffer( 10 )
        for n in neutrons:
            n.probability = 1
            continue
        out = 'tmp-nst-test2.ns'
        mns.dump(neutrons, out)

        # try normalize out-of-place
        out2 = 'tmp-nst-test2-normalized.ns'
        if os.path.exists(out2): os.remove(out2)
        mns.normalize(out, 10., out2)
        neutrons2 = mns.load(out2)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue

        # try normalize in-place
        mns.normalize(out, 10.)
        neutrons2 = mns.load(out)
        # and see if it is done correctly
        for n in neutrons2:
            self.assertAlmostEqual(n.probability, .1)
            continue
        return
Beispiel #5
0
def test():
    from mcni.neutron_storage import load
    neutron_file = 'data/before_guide-n1e8.mcv'
    neutrons = load(neutron_file)
    from mcvine.acc.components.optics import guide
    g = guide.Guide(
        name = 'guide',
        w1=0.035, h1=0.035, w2=0.035, h2=0.035, l=10,
        R0=0.99, Qc=0.0219, alpha=6.07, m=3, W=0.003,
    )
    t1 = time.time()
    g.process(neutrons)
    print("GPU processing time:", time.time()-t1)

    neutrons = load(neutron_file)
    import mcvine.components as mc
    g = mc.optics.Guide(
        name = 'guide',
        w1=0.035, h1=0.035, w2=0.035, h2=0.035, l=10,
        R0=0.99, Qc=0.0219, alpha=6.07, m=3, W=0.003,
    )
    t1 = time.time()
    g.process(neutrons)
    print("CPU processing time:", time.time()-t1)
    return
Beispiel #6
0
 def test1(self):
     'neutron_storage: mix npy implementation and non-npy one'
     import mcni
     neutrons = mcni.neutron_buffer(7)
     out = 'tmp-nst-test1.ns'
     if os.path.exists(out): os.remove(out)
     storage = mns.storage(out, mode='w')
     storage.write(neutrons)
     neutrons1 = mns.load('neutrons.dat')
     return
 def test1(self):
     'neutron_storage: mix npy implementation and non-npy one'
     import mcni
     neutrons = mcni.neutron_buffer( 7 )
     out = 'tmp-nst-test1.ns'
     if os.path.exists(out): os.remove(out)
     storage = mns.storage(out, mode='w')
     storage.write(neutrons)
     neutrons1 = mns.load( 'neutrons.dat' )
     return
Beispiel #8
0
 def test(self):
     'neutron_storage'
     import mcni
     neutrons = mcni.neutron_buffer(7)
     neutrons[5] = mcni.neutron(v=(8, 9, 10))
     mns.dump(neutrons, 'neutrons.dat')
     neutrons1 = mns.load('neutrons.dat')
     n5 = neutrons1[5]
     v = n5.state.velocity
     self.assertAlmostEqual(v[0], 8)
     self.assertAlmostEqual(v[1], 9)
     self.assertAlmostEqual(v[2], 10)
     return
 def test(self):
     'neutron_storage'
     import mcni
     neutrons = mcni.neutron_buffer( 7 )
     neutrons[5] = mcni.neutron( v = (8,9,10) )
     mns.dump(neutrons, 'neutrons.dat')
     neutrons1 = mns.load( 'neutrons.dat' )
     n5 = neutrons1[5]
     v = n5.state.velocity
     self.assertAlmostEqual( v[0], 8 )
     self.assertAlmostEqual( v[1], 9 )
     self.assertAlmostEqual( v[2], 10 )
     return
Beispiel #10
0
def test(neutron_fn=DEFAULT_NEUTRON_FILE, niter=1):
    # load file and store copy to avoid reloading for multiple iterations
    from mcni.neutron_storage import load, neutrons_from_npyarr, \
        neutrons_as_npyarr, ndblsperneutron
    neutrons_orig = load(neutron_fn)
    neutrons_orig = neutrons_as_npyarr(neutrons_orig)
    neutrons_orig.shape = -1, ndblsperneutron

    from mcvine.acc.components.optics import guide_tapering
    g = guide_tapering.Guide(
        name='guide',
        option="file={}".format(guide11_dat),
        l=guide11_len,
        mx=guide11_mx,
        my=guide11_my,
    )
    times = []
    for i in range(niter):
        neutrons = neutrons_from_npyarr(neutrons_orig)
        t1 = time.time_ns()
        g.process(neutrons)
        delta = time.time_ns() - t1
        times.append(delta)
        print("GPU processing time: {} ms ({} s)".format(
            1e-6 * delta, 1e-9 * delta))

    if niter > 1:
        # report average time over niter
        times = np.asarray(times)
        avg = times.sum() / len(times)
        print("--------")
        print("Average GPU time ({} iters): {} ms ({} s)".format(
            niter, 1e-6 * avg, 1e-9 * avg))
        print("--------")

    neutrons = neutrons_from_npyarr(neutrons_orig)
    import mcvine.components as mc
    g = mc.optics.Guide_tapering(
        name='guide',
        option="file={}".format(guide11_dat),
        l=guide11_len,
        mx=guide11_mx,
        my=guide11_my,
    )
    t1 = time.time()
    g.process(neutrons)
    print("CPU processing time:", time.time() - t1)
    return
Beispiel #11
0
def readNeutron():
    neutrons = 'out/scattered-neutrons'
    from mcni.neutron_storage import load
    neutrons = load(neutrons)
    assert len(neutrons) == 1
    return neutrons[0]