differt 0.0.19__tar.gz → 0.0.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {differt-0.0.19 → differt-0.0.20}/PKG-INFO +2 -2
- {differt-0.0.19 → differt-0.0.20}/pyproject.toml +1 -1
- {differt-0.0.19 → differt-0.0.20}/src/differt/rt/utils.py +4 -4
- {differt-0.0.19 → differt-0.0.20}/src/differt/scene/triangle_scene.py +121 -58
- {differt-0.0.19 → differt-0.0.20}/.gitignore +0 -0
- {differt-0.0.19 → differt-0.0.20}/LICENSE.md +0 -0
- {differt-0.0.19 → differt-0.0.20}/README.md +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/__init__.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/em/__init__.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/em/constants.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/em/special.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/em/utd.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/em/utils.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/geometry/__init__.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/geometry/paths.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/geometry/triangle_mesh.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/geometry/utils.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/plotting/__init__.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/plotting/_core.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/plotting/_utils.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/rt/__init__.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/rt/fermat.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/rt/image_method.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/scene/__init__.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/scene/sionna.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/utils.py +0 -0
- {differt-0.0.19 → differt-0.0.20}/src/differt/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.20
|
|
4
4
|
Summary: Differentiable Ray Tracing Toolbox for Radio Propagation Simulations
|
|
5
5
|
Project-URL: Changelog, https://github.com/jeertmans/DiffeRT/releases
|
|
6
6
|
Project-URL: Documentation, https://eertmans.be/DiffeRT
|
|
@@ -21,7 +21,7 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
21
21
|
Requires-Python: >=3.10
|
|
22
22
|
Requires-Dist: beartype>=0.17.2
|
|
23
23
|
Requires-Dist: chex>=0.1.86
|
|
24
|
-
Requires-Dist: differt-core==0.0.
|
|
24
|
+
Requires-Dist: differt-core==0.0.20
|
|
25
25
|
Requires-Dist: equinox>=0.11.5
|
|
26
26
|
Requires-Dist: filelock>=3.15.4
|
|
27
27
|
Requires-Dist: jax>=0.4.32
|
|
@@ -76,17 +76,17 @@ class SizedIterator(Iterator, Sized, Generic[T]):
|
|
|
76
76
|
|
|
77
77
|
__slots__ = ("_iter", "_size")
|
|
78
78
|
|
|
79
|
-
def __init__(self, iter: Iterator[T], size: int | Callable[[], int]) -> None:
|
|
79
|
+
def __init__(self, iter: Iterator[T], size: int | Callable[[], int]) -> None: # noqa: A002,D107
|
|
80
80
|
self._iter = iter
|
|
81
81
|
self._size = size
|
|
82
82
|
|
|
83
|
-
def __iter__(self) -> Self:
|
|
83
|
+
def __iter__(self) -> Self: # noqa: D105
|
|
84
84
|
return self
|
|
85
85
|
|
|
86
|
-
def __next__(self) -> T:
|
|
86
|
+
def __next__(self) -> T: # noqa: D105
|
|
87
87
|
return next(self._iter)
|
|
88
88
|
|
|
89
|
-
def __len__(self) -> int:
|
|
89
|
+
def __len__(self) -> int: # noqa: D105
|
|
90
90
|
if isinstance(self._size, int):
|
|
91
91
|
return self._size
|
|
92
92
|
return self._size()
|
|
@@ -10,7 +10,11 @@ import jax
|
|
|
10
10
|
import jax.numpy as jnp
|
|
11
11
|
import numpy as np
|
|
12
12
|
from beartype import beartype as typechecker
|
|
13
|
-
from
|
|
13
|
+
from jax.experimental import mesh_utils
|
|
14
|
+
from jax.experimental.shard_map import shard_map
|
|
15
|
+
from jax.sharding import Mesh
|
|
16
|
+
from jax.sharding import PartitionSpec as P # noqa: N814
|
|
17
|
+
from jaxtyping import Array, ArrayLike, Bool, Float, Int, jaxtyped
|
|
14
18
|
|
|
15
19
|
import differt_core.scene.triangle_scene
|
|
16
20
|
from differt.geometry.paths import Paths
|
|
@@ -44,6 +48,8 @@ def _compute_paths(
|
|
|
44
48
|
from_vertices: Float[Array, "num_from_vertices 3"],
|
|
45
49
|
to_vertices: Float[Array, "num_to_vertices 3"],
|
|
46
50
|
path_candidates: Int[Array, "num_path_candidates order"],
|
|
51
|
+
*,
|
|
52
|
+
parallel: bool = False,
|
|
47
53
|
**kwargs: Any,
|
|
48
54
|
) -> Paths:
|
|
49
55
|
epsilon = kwargs.pop("epsilon", None)
|
|
@@ -69,67 +75,106 @@ def _compute_paths(
|
|
|
69
75
|
# [num_path_candidates order 3]
|
|
70
76
|
mirror_normals = jnp.take(mesh.normals, path_candidates, axis=0)
|
|
71
77
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
paths
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
# [tx_batch_flat rx_batch_flat num_path_candidates order+1 3]
|
|
92
|
-
ray_origins = full_paths[..., :-1, :]
|
|
93
|
-
# [tx_batch_flat rx_batch_flat num_path_candidates order+1 3]
|
|
94
|
-
ray_directions = jnp.diff(full_paths, axis=-2)
|
|
95
|
-
|
|
96
|
-
# 3.1 - Check if paths vertices are inside respective triangles
|
|
97
|
-
|
|
98
|
-
# [tx_batch_flat rx_batch_flat num_path_candidates]
|
|
99
|
-
inside_triangles = rays_intersect_triangles(
|
|
100
|
-
ray_origins[..., :-1, :],
|
|
101
|
-
ray_directions[..., :-1, :],
|
|
102
|
-
triangle_vertices,
|
|
103
|
-
epsilon=epsilon,
|
|
104
|
-
)[1].all(axis=-1) # Reduce on 'order' axis
|
|
78
|
+
@jaxtyped(typechecker=typechecker)
|
|
79
|
+
def fun(
|
|
80
|
+
from_vertices: Float[Array, "num_from_vertices 3"],
|
|
81
|
+
to_vertices: Float[Array, "num_to_vertices 3"],
|
|
82
|
+
) -> tuple[
|
|
83
|
+
Float[
|
|
84
|
+
Array, "num_from_vertices num_to_vertices num_path_candidates path_length 3"
|
|
85
|
+
],
|
|
86
|
+
Bool[Array, "num_from_vertices num_to_vertices num_path_candidates"],
|
|
87
|
+
]:
|
|
88
|
+
# 2 - Trace paths
|
|
89
|
+
|
|
90
|
+
# [num_from_vertices num_to_vertices num_path_candidates order 3]
|
|
91
|
+
paths = image_method(
|
|
92
|
+
from_vertices[:, None, None, :],
|
|
93
|
+
to_vertices[None, :, None, :],
|
|
94
|
+
mirror_vertices,
|
|
95
|
+
mirror_normals,
|
|
96
|
+
)
|
|
105
97
|
|
|
106
|
-
|
|
98
|
+
# [num_from_vertices num_to_vertices num_path_candidates order+2 3]
|
|
99
|
+
full_paths = assemble_paths(
|
|
100
|
+
from_vertices[:, None, None, None, :],
|
|
101
|
+
paths,
|
|
102
|
+
to_vertices[None, :, None, None, :],
|
|
103
|
+
)
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
# 3 - Identify invalid paths
|
|
106
|
+
|
|
107
|
+
# [num_from_vertices num_to_vertices num_path_candidates order+1 3]
|
|
108
|
+
ray_origins = full_paths[..., :-1, :]
|
|
109
|
+
# [num_from_vertices num_to_vertices num_path_candidates order+1 3]
|
|
110
|
+
ray_directions = jnp.diff(full_paths, axis=-2)
|
|
111
|
+
|
|
112
|
+
# 3.1 - Check if paths vertices are inside respective triangles
|
|
113
|
+
|
|
114
|
+
# [num_from_vertices num_to_vertices num_path_candidates]
|
|
115
|
+
inside_triangles = rays_intersect_triangles(
|
|
116
|
+
ray_origins[..., :-1, :],
|
|
117
|
+
ray_directions[..., :-1, :],
|
|
118
|
+
triangle_vertices,
|
|
119
|
+
epsilon=epsilon,
|
|
120
|
+
)[1].all(axis=-1) # Reduce on 'order' axis
|
|
121
|
+
|
|
122
|
+
# 3.2 - Check if consecutive path vertices are on the same side of mirrors
|
|
123
|
+
|
|
124
|
+
# [num_from_vertices num_to_vertices num_path_candidates]
|
|
125
|
+
valid_reflections = consecutive_vertices_are_on_same_side_of_mirrors(
|
|
126
|
+
full_paths,
|
|
127
|
+
mirror_vertices,
|
|
128
|
+
mirror_normals,
|
|
129
|
+
).all(axis=-1) # Reduce on 'order'
|
|
130
|
+
|
|
131
|
+
# 3.3 - Identify paths that are blocked by other objects
|
|
132
|
+
|
|
133
|
+
# [num_from_vertices num_to_vertices num_path_candidates]
|
|
134
|
+
blocked = rays_intersect_any_triangle(
|
|
135
|
+
ray_origins,
|
|
136
|
+
ray_directions,
|
|
137
|
+
mesh.triangle_vertices,
|
|
138
|
+
epsilon=epsilon,
|
|
139
|
+
hit_tol=hit_tol,
|
|
140
|
+
).any(axis=-1) # Reduce on 'order'
|
|
141
|
+
|
|
142
|
+
# TODO: we also need to somehow mask degenerate paths, e.g., when two reflections occur on an edge
|
|
143
|
+
|
|
144
|
+
mask = inside_triangles & valid_reflections & ~blocked
|
|
145
|
+
|
|
146
|
+
return full_paths, mask
|
|
147
|
+
|
|
148
|
+
if parallel:
|
|
149
|
+
num_devices = jax.device_count()
|
|
150
|
+
|
|
151
|
+
# TODO: allow also to have i,i mesh if product of both is a multiple of 'num_devices'
|
|
152
|
+
if from_vertices.shape[0] % num_devices == 0:
|
|
153
|
+
in_specs = (P("i", None), P(None, None))
|
|
154
|
+
out_specs = (P("i", None, None, None, None), P("i", None, None))
|
|
155
|
+
elif to_vertices.shape[0] % num_devices == 0:
|
|
156
|
+
in_specs = (P(None, None), P("i", None))
|
|
157
|
+
out_specs = (P(None, "i", None, None, None), P(None, "i", None))
|
|
158
|
+
else:
|
|
159
|
+
msg = (
|
|
160
|
+
f"Found {num_devices} devices available, "
|
|
161
|
+
"but could not find any input with a size that is a multiple of that value. "
|
|
162
|
+
"Please user a number of transmitter or receiver points that is a "
|
|
163
|
+
f"multiple of {num_devices}."
|
|
164
|
+
)
|
|
165
|
+
raise ValueError(msg)
|
|
114
166
|
|
|
115
|
-
|
|
167
|
+
fun = shard_map( # type: ignore[reportAssigmentType]
|
|
168
|
+
fun,
|
|
169
|
+
Mesh(mesh_utils.create_device_mesh((num_devices,)), axis_names=("i",)),
|
|
170
|
+
in_specs=in_specs,
|
|
171
|
+
out_specs=out_specs,
|
|
172
|
+
)
|
|
116
173
|
|
|
117
|
-
|
|
118
|
-
blocked = rays_intersect_any_triangle(
|
|
119
|
-
ray_origins,
|
|
120
|
-
ray_directions,
|
|
121
|
-
mesh.triangle_vertices,
|
|
122
|
-
epsilon=epsilon,
|
|
123
|
-
hit_tol=hit_tol,
|
|
124
|
-
).any(axis=-1) # Reduce on 'order'
|
|
174
|
+
vertices, mask = fun(from_vertices, to_vertices)
|
|
125
175
|
|
|
126
176
|
# 4 - Generate output paths and reshape
|
|
127
177
|
|
|
128
|
-
vertices = full_paths
|
|
129
|
-
mask = inside_triangles & valid_reflections & ~blocked
|
|
130
|
-
|
|
131
|
-
# TODO: we also need to somehow mask degenerate paths, e.g., when two reflections occur on an edge
|
|
132
|
-
|
|
133
178
|
object_dtype = path_candidates.dtype
|
|
134
179
|
|
|
135
180
|
tx_objects = jnp.arange(from_vertices.shape[0], dtype=object_dtype)
|
|
@@ -303,7 +348,12 @@ class TriangleScene(eqx.Module):
|
|
|
303
348
|
return cls.from_core(core_scene)
|
|
304
349
|
|
|
305
350
|
def compute_paths(
|
|
306
|
-
self,
|
|
351
|
+
self,
|
|
352
|
+
order: int,
|
|
353
|
+
*,
|
|
354
|
+
chunk_size: int | None = None,
|
|
355
|
+
parallel: bool = False,
|
|
356
|
+
**kwargs: Any,
|
|
307
357
|
) -> Paths | SizedIterator[Paths]:
|
|
308
358
|
"""
|
|
309
359
|
Compute paths between all pairs of transmitters and receivers in the scene, that undergo a fixed number of interaction with objects.
|
|
@@ -312,6 +362,9 @@ class TriangleScene(eqx.Module):
|
|
|
312
362
|
order: The number of interaction, i.e., the number of bounces.
|
|
313
363
|
chunk_size: If specified, it will iterate through chunks of path
|
|
314
364
|
candidates, and yield the result as an iterator over paths chunks.
|
|
365
|
+
parallel: If :data:`True`, ray tracing is performed in parallel across all available
|
|
366
|
+
devices. Either the number of transmitters or the number of receivers
|
|
367
|
+
**must** be a multiple of :func:`jax.device_count`, otherwise an error is raised.
|
|
315
368
|
kwargs: Keyword arguments passed to
|
|
316
369
|
:func:`rays_intersect_any_triangle<differt.rt.utils.rays_intersect_any_triangle>`.
|
|
317
370
|
|
|
@@ -336,7 +389,12 @@ class TriangleScene(eqx.Module):
|
|
|
336
389
|
size = path_candidates_iter.__len__
|
|
337
390
|
it = (
|
|
338
391
|
_compute_paths(
|
|
339
|
-
self.mesh,
|
|
392
|
+
self.mesh,
|
|
393
|
+
from_vertices,
|
|
394
|
+
to_vertices,
|
|
395
|
+
path_candidates,
|
|
396
|
+
parallel=parallel,
|
|
397
|
+
**kwargs,
|
|
340
398
|
).reshape(*tx_batch, *rx_batch, path_candidates.shape[0])
|
|
341
399
|
for path_candidates in path_candidates_iter
|
|
342
400
|
)
|
|
@@ -345,7 +403,12 @@ class TriangleScene(eqx.Module):
|
|
|
345
403
|
|
|
346
404
|
path_candidates = generate_all_path_candidates(num_triangles, order)
|
|
347
405
|
return _compute_paths(
|
|
348
|
-
self.mesh,
|
|
406
|
+
self.mesh,
|
|
407
|
+
from_vertices,
|
|
408
|
+
to_vertices,
|
|
409
|
+
path_candidates,
|
|
410
|
+
parallel=parallel,
|
|
411
|
+
**kwargs,
|
|
349
412
|
).reshape(*tx_batch, *rx_batch, path_candidates.shape[0])
|
|
350
413
|
|
|
351
414
|
def plot(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|