Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e9d9aa9
added method `forward_distance_in_shape`: acc/geometry/propagation.py
yxqd Apr 28, 2023
e478f4d
added acc.scatterers.homogeneous_scatterer module: currently only imp…
yxqd Apr 29, 2023
5e97e55
added acc.scatterers subpkg: setup.py
yxqd Apr 29, 2023
38a6659
ignore test outputs and build dirs: .gitignore
yxqd Apr 29, 2023
4f82ed2
refactored using new object _numba.coder: acc/kernels/composite.py
yxqd May 1, 2023
bb617f0
trivial cosmetic changes: acc/kernels/composite.py
yxqd May 1, 2023
805d780
use method factory instead of pickle: acc/kernels/composite.py
yxqd May 1, 2023
9b66016
refactored so that only one module needed for all composite kernels w…
yxqd May 1, 2023
df0a2ee
handle overflow: acc/geometry/arrow_intersect.py
yxqd May 1, 2023
2ad8744
started implementing acc.geometry.composite with an example methods f…
yxqd May 2, 2023
4de8a86
implemented `find_1st_hit` and added a test: acc/geometry/composite.py
yxqd May 4, 2023
5369c92
fixed assertion: tests/components/samples/test_homogeneous_multiple_s…
yxqd May 7, 2023
d158181
set pytest marker: tests/scatterers/test_homogeneous_scatterer.py
yxqd May 7, 2023
0c6ee4d
geometry.composite: added method "intersect_all"
yxqd May 7, 2023
2dc4f88
geometry.composite: added locate method for union of 3 shapes and a test
yxqd May 7, 2023
958dbf6
partial implementation to handle translation and rotation for locate/…
yxqd May 7, 2023
a95a79d
expose `calculate_attenuation`: acc/scatterers/homogeneous_scatterer.py
yxqd May 7, 2023
7df43ed
composite_scatterer.intersect_path1 preliminary implementation and test
yxqd May 7, 2023
ab984dd
preliminary implementation of acc.scatterers.ScatterFuncFactory.onCom…
yxqd May 7, 2023
3ae877a
added a real CUDA test of homogenouse_scatterer interact_path1 and fi…
yxqd May 8, 2023
5fa2fe9
minor refactor: tests/scatterers/test_homogeneous_scatterer.py
yxqd May 8, 2023
72ed97a
minor (increase ncount to 1e5): tests/scatterers/test_homogeneous_s…
yxqd May 8, 2023
de67bc2
simplify with pytest fixtures: tests/scatterers/test_homogeneous_sc…
yxqd May 8, 2023
0beaf02
composite_scatterer.interact_path1 for three elements passed the sani…
yxqd May 8, 2023
10cfe20
refactor: moved methods for 3-element composite from acc.geometry.com…
yxqd May 8, 2023
52fd950
minor refactor: acc/geometry/composite_3.py
yxqd May 8, 2023
3bb47ae
minor refactor: acc/geometry/composite_3.py
yxqd May 8, 2023
d4d7598
renamed: tests/geometry/test_composite_shape.py -> test_composite_…
yxqd May 8, 2023
9eed2b1
simplified loops for intersect_all methods: acc/geometry/composite_…
yxqd May 8, 2023
e6149da
started working on coder -- added _intersect_all: acc/geometry/comp…
yxqd May 8, 2023
5b825ad
implemented method to create `createMethods` for N-element composite:…
yxqd May 9, 2023
9880dcb
trivial cosmetic: acc/geometry/composite.py
yxqd May 9, 2023
ee8ae4e
method factories are classes now: acc/geometry/composite.py
yxqd May 9, 2023
38feaa7
test the module made by the composite-shape ray-tracing method factory
yxqd May 9, 2023
05ad8a0
added a real CUDA test: tests/geometry/test_composite_shape.py
yxqd May 9, 2023
6e687cc
renamed acc.scatterers.composite_scatterer to ..composite_3
yxqd May 11, 2023
e6dff8b
trivial: acc/geometry/composite_3.py
yxqd May 11, 2023
946a551
make most methods protected in geometry.composite, and added two publ…
yxqd May 13, 2023
35f2e53
added a sanity check of public methods in geometry.composite: tests…
yxqd May 13, 2023
67b87f3
minor: made method names in geometry.composite_3 consistent with thos…
yxqd May 13, 2023
52b93ab
fixed bugs introduced in the last couple commits (method renames): …
yxqd May 13, 2023
994272d
refactored codes around composite_scatterer so that we can add "coder…
yxqd May 13, 2023
2ed20ce
added scatterers.composite_scatterer._makeModule
yxqd May 13, 2023
ed64b71
use module created by "coder": acc/scatterers/composite_scatterer.py
yxqd May 13, 2023
5075426
composite: implement and test single-scatter methods
yxqd May 14, 2023
dafc8bb
added composite sample component and started writing a test module
yxqd Jun 11, 2023
883423c
part of an effort to simplify test instruments. see #111
yxqd Jun 11, 2023
3f65d73
refactoring: tests/components/samples/test_composite_isotropic_spher…
yxqd Jun 11, 2023
7725e57
scatter method - match signature to component.propagate: acc/scatte…
yxqd Jun 15, 2023
235529f
composite.py: 1.added SampleAssemblyFromXml method to create the comp…
yxqd Jun 15, 2023
fc7e27e
make sure mcweights and packing_factor are floats: acc/scatterers/_…
yxqd Jun 15, 2023
5d7ac94
Merge branch 'sans_kernel' into mccomposite
yxqd Jul 23, 2023
2c289b6
minor (inline doc): components/samples/composite.py
yxqd Jul 26, 2023
4e2367e
debugging: tests/components/samples/test_composite_isotropic_sphere.py
yxqd Jul 26, 2023
ec256ce
Merge branch 'main' into mccomposite: fixed Conflicts in .gitignore
yxqd Aug 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.dat
*.mcv
out.*
log.*
compiled_composite*
composite_kernel_*

Expand Down Expand Up @@ -164,4 +165,4 @@ dmypy.json
cython_debug/

# PyCharm
.idea/
.idea/
36 changes: 36 additions & 0 deletions acc/_numba.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os, tempfile
import numpy as np
from numba.core import config
if config.ENABLE_CUDASIM:
Expand All @@ -6,3 +7,38 @@ def xoroshiro128p_uniform_float32(rng_states, threadindex):
from numba.cuda.random import xoroshiro128p_type
else:
from numba.cuda.random import xoroshiro128p_uniform_float32, xoroshiro128p_type

class Coder:

def __init__(self, workdir=None):
self.workdir = workdir = workdir or os.path.abspath(".mcvine.acc.coder")
if not os.path.exists(workdir):
os.makedirs(workdir)
self.modules = dict()

def getModule(self, type, N):
container = coder.createDir(type)
modulepath = os.path.join(container, f'compiled_{N}.py')
key = type, N
if os.path.exists(modulepath) and key not in self.modules:
self.modules[key] = modulepath
return modulepath

def createUniqueDir(self, prefix):
return tempfile.mkdtemp(prefix=prefix, dir=self.workdir)

def createDir(self, name):
wd = os.path.join(self.workdir, name)
if not os.path.exists(wd):
os.makedirs(wd)
return wd

@classmethod
def unrollLoop(cls, N, indent=4*' ', before_loop=None, in_loop=None, after_loop=None):
lines=[indent+line for line in before_loop or []]
for i in range(N):
lines+=[indent+line.format(i=i) for line in in_loop or []]
lines+=[indent+line for line in after_loop or []]
return lines

coder = Coder()
48 changes: 48 additions & 0 deletions acc/components/samples/composite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import numpy as np, numba
from numba import cuda, void, int64
from numba.cuda.random import xoroshiro128p_uniform_float32, xoroshiro128p_type
from ...config import get_numba_floattype
NB_FLOAT = get_numba_floattype()

from .SampleBase import SampleBase

category = 'samples'

def sampleassembly_from_xml(name, samplexml):
"""factory method to create sample assembly component.
can only be used in nonacc instrument script
"""
klass = SampleAssemblyFromXml(samplexml)
return klass(name)

def SampleAssemblyFromXml(samplexml):
from . import loadScattererComposite
composite = loadScattererComposite(samplexml)
return factory(composite)

def factory(composite):
from ...scatterers import scatter_func_factory
methods = scatter_func_factory.render(composite)
scatter = methods['scatter']
class Composite(SampleBase):

def __init__(self, name):
self.name = name
self.propagate_params = ()

# Aim neutrons toward the sample to cause JIT compilation.
import mcni
neutrons = mcni.neutron_buffer(1)
neutrons[0] = mcni.neutron(r=(0, 0, -1), v=(0, 0, 1), prob=1, time=0)
self.process(neutrons)

@cuda.jit(
void(int64, xoroshiro128p_type[:], NB_FLOAT[:]),
device=True, inline=True,
)
def propagate(threadindex, rng_states, neutron):
return
Composite.propagate = scatter
Composite.register_propagate_method(scatter)
return Composite
37 changes: 35 additions & 2 deletions acc/geometry/arrow_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ def render(self, shape):
return shape.identify(self)

def onUnion(self, u):
nelements = len(u.shapes)
if nelements == 1:
return u.shapes[0].identify(self)
elif nelements == 2:
return self.onUnion2(u)
elif nelements == 3:
from .composite_3 import createRayTracingMethods_NonOverlappingShapes as createMethods
return createMethods(u.shapes)['intersect_all']
else:
raise NotImplementedError(f"locate for union of {nelements} elements")

def onUnion2(self, u):
locate1 = self.locate_func_factory.onUnion(u)
s1, s2 = u.shapes
f1 = s1.identify(self)
Expand Down Expand Up @@ -85,6 +97,22 @@ def intersectBlock(x, y, z, vx, vy, vz, ts):

return intersectBlock

def onTranslation(self, t):
x0,y0,z0 = [_/units.length.meter for _ in t.vector]
body = t.body
intersect_body = self.render(body)
@cuda.jit(device=True, inline=True)
def intersectTranslation(x,y,z, vx,vy,vz, ts):
return intersect_body(x-x0,y-y0,z-z0, vx,vy,vz, ts)
return intersectTranslation

def onRotation(self, r):
euler_angles = [_/units.angle.rad for _ in r.euler_angles]
# hack
if not np.allclose(euler_angles, [0,0,0]):
raise NotImplementedError
return self.render(r.body)

def onDifference(self, s):
locate1 = self.locate_func_factory.onDifference(s)
f1 = s.op1.identify(self)
Expand Down Expand Up @@ -150,8 +178,13 @@ def remove_item(idx, l, N):

@cuda.jit(device=True)
def insert_into_sorted_list(d, l, N):
'insert data "d" into existing sorted array (low to high) of length N'
if N>=len(l): return N
'''insert data "d" into existing sorted array (low to high) of length N
and keep the lower number when there are too many elements
'''
if N>=len(l):
if l[N-1] <= d:
return N
N = N - 1
if N==0:
l[0] = d
return 1
Expand Down
Loading