differt 0.4.1__tar.gz → 0.5.0__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.4.1 → differt-0.5.0}/PKG-INFO +5 -5
- {differt-0.4.1 → differt-0.5.0}/README.md +3 -3
- {differt-0.4.1 → differt-0.5.0}/pyproject.toml +1 -1
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/_antenna.py +21 -21
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/_utd.py +3 -3
- {differt-0.4.1 → differt-0.5.0}/src/differt/geometry/_paths.py +3 -3
- {differt-0.4.1 → differt-0.5.0}/src/differt/geometry/_triangle_mesh.py +3 -3
- {differt-0.4.1 → differt-0.5.0}/src/differt/geometry/_utils.py +3 -3
- {differt-0.4.1 → differt-0.5.0}/src/differt/plotting/_core.py +3 -3
- {differt-0.4.1 → differt-0.5.0}/src/differt/plugins/_deepmimo_types.py +1 -1
- {differt-0.4.1 → differt-0.5.0}/src/differt/plugins/deepmimo.py +1 -1
- {differt-0.4.1 → differt-0.5.0}/src/differt/rt/_image_method.py +17 -10
- {differt-0.4.1 → differt-0.5.0}/src/differt/rt/_utils.py +5 -5
- {differt-0.4.1 → differt-0.5.0}/src/differt/scene/_sionna.py +3 -3
- {differt-0.4.1 → differt-0.5.0}/src/differt/scene/_triangle_scene.py +144 -255
- {differt-0.4.1 → differt-0.5.0}/src/differt/utils.py +1 -1
- {differt-0.4.1 → differt-0.5.0}/.gitignore +0 -0
- {differt-0.4.1 → differt-0.5.0}/LICENSE.md +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/__init__.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/_version.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/__init__.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/_constants.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/_fresnel.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/_interaction_type.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/_material.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/em/_utils.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/geometry/__init__.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/plotting/__init__.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/plotting/_utils.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/plugins/__init__.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/py.typed +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/rt/__init__.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/rt/_fermat.py +0 -0
- {differt-0.4.1 → differt-0.5.0}/src/differt/scene/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
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: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Topic :: Scientific/Engineering
|
|
22
22
|
Requires-Python: >=3.10
|
|
23
23
|
Requires-Dist: chex>=0.1.86
|
|
24
|
-
Requires-Dist: differt-core==0.
|
|
24
|
+
Requires-Dist: differt-core==0.5.0
|
|
25
25
|
Requires-Dist: equinox>=0.12.2
|
|
26
26
|
Requires-Dist: filelock>=3.15.4
|
|
27
27
|
Requires-Dist: jax>=0.4.32
|
|
@@ -78,7 +78,7 @@ Differentiable Ray Tracing toolbox for Radio Propagation powered by the [JAX eco
|
|
|
78
78
|
> **WARNING:**
|
|
79
79
|
> This package is still under important development, see
|
|
80
80
|
> the [v1.0.0](https://github.com/jeertmans/DiffeRT/milestone/2) milestone for future
|
|
81
|
-
> features, and the [CHANGELOG](https://github.com/jeertmans/DiffeRT/blob/main/
|
|
81
|
+
> features, and the [CHANGELOG](https://github.com/jeertmans/DiffeRT/blob/main/CHANGELOG.md)
|
|
82
82
|
> for versioning policy.
|
|
83
83
|
>
|
|
84
84
|
> If you have any suggestion regarding the development of this package,
|
|
@@ -116,7 +116,7 @@ if your issue does not fit one of the proposed topics.
|
|
|
116
116
|
The more precise you are in the description of your problem, the faster we will
|
|
117
117
|
be able to help you!
|
|
118
118
|
|
|
119
|
-
If you rather have question than a problem,
|
|
119
|
+
If you rather have a question than a problem,
|
|
120
120
|
then it is probably best suited to ask it in the
|
|
121
121
|
[Q&A category of the discussions](https://github.com/jeertmans/DiffeRT/discussions/categories/q-a).
|
|
122
122
|
|
|
@@ -140,7 +140,7 @@ If you use this software, please cite it as:
|
|
|
140
140
|
author = {Eertmans, Jérome},
|
|
141
141
|
url = {https://github.com/jeertmans/DiffeRT},
|
|
142
142
|
license = {MIT},
|
|
143
|
-
version = {v0.
|
|
143
|
+
version = {v0.5.0}
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
@@ -21,7 +21,7 @@ Differentiable Ray Tracing toolbox for Radio Propagation powered by the [JAX eco
|
|
|
21
21
|
> [!WARNING]
|
|
22
22
|
> This package is still under important development, see
|
|
23
23
|
> the [v1.0.0](https://github.com/jeertmans/DiffeRT/milestone/2) milestone for future
|
|
24
|
-
> features, and the [CHANGELOG](https://github.com/jeertmans/DiffeRT/blob/main/
|
|
24
|
+
> features, and the [CHANGELOG](https://github.com/jeertmans/DiffeRT/blob/main/CHANGELOG.md)
|
|
25
25
|
> for versioning policy.
|
|
26
26
|
>
|
|
27
27
|
> If you have any suggestion regarding the development of this package,
|
|
@@ -59,7 +59,7 @@ if your issue does not fit one of the proposed topics.
|
|
|
59
59
|
The more precise you are in the description of your problem, the faster we will
|
|
60
60
|
be able to help you!
|
|
61
61
|
|
|
62
|
-
If you rather have question than a problem,
|
|
62
|
+
If you rather have a question than a problem,
|
|
63
63
|
then it is probably best suited to ask it in the
|
|
64
64
|
[Q&A category of the discussions](https://github.com/jeertmans/DiffeRT/discussions/categories/q-a).
|
|
65
65
|
|
|
@@ -83,7 +83,7 @@ If you use this software, please cite it as:
|
|
|
83
83
|
author = {Eertmans, Jérome},
|
|
84
84
|
url = {https://github.com/jeertmans/DiffeRT},
|
|
85
85
|
license = {MIT},
|
|
86
|
-
version = {v0.
|
|
86
|
+
version = {v0.5.0}
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
89
|
|
|
@@ -24,16 +24,16 @@ def poynting_vector(
|
|
|
24
24
|
b: Inexact[ArrayLike, "*#batch 3"],
|
|
25
25
|
) -> Inexact[Array, "*batch 3"]:
|
|
26
26
|
r"""
|
|
27
|
-
Compute the
|
|
27
|
+
Compute the Poynting vector in vacuum from electric :math:`\vec{E}` and magnetic :math:`\vec{B}` fields.
|
|
28
28
|
|
|
29
29
|
Args:
|
|
30
30
|
e: The electrical field.
|
|
31
|
-
b: The
|
|
31
|
+
b: The magnetic field.
|
|
32
32
|
|
|
33
33
|
Returns:
|
|
34
|
-
The
|
|
34
|
+
The Poynting vector :math:`\vec{S}`.
|
|
35
35
|
|
|
36
|
-
It can be either real
|
|
36
|
+
It can be either real or complex-valued.
|
|
37
37
|
"""
|
|
38
38
|
return jnp.cross(jnp.asarray(e), jnp.asarray(b)) / mu_0
|
|
39
39
|
|
|
@@ -86,7 +86,7 @@ class Antenna(BaseAntenna):
|
|
|
86
86
|
def reference_power(self) -> Float[Array, " "]:
|
|
87
87
|
r"""The reference power (W) radiated by this antenna.
|
|
88
88
|
|
|
89
|
-
This is the maximal value of the
|
|
89
|
+
This is the maximal value of the Poynting vector at a distance
|
|
90
90
|
of one meter from this antenna, multiplied by the area of the sphere
|
|
91
91
|
(:math:`4\phi`),
|
|
92
92
|
to obtain a power.
|
|
@@ -109,7 +109,7 @@ class Antenna(BaseAntenna):
|
|
|
109
109
|
is assumed.
|
|
110
110
|
|
|
111
111
|
Returns:
|
|
112
|
-
The electric :math:`\vec{E}` and
|
|
112
|
+
The electric :math:`\vec{E}` and magnetic :math:`\vec{B}` fields.
|
|
113
113
|
|
|
114
114
|
Fields can be either real or complex-valued.
|
|
115
115
|
"""
|
|
@@ -131,9 +131,9 @@ class Antenna(BaseAntenna):
|
|
|
131
131
|
is assumed.
|
|
132
132
|
|
|
133
133
|
Returns:
|
|
134
|
-
The
|
|
134
|
+
The Poynting vector :math:`\vec{S}`.
|
|
135
135
|
|
|
136
|
-
It can be either real
|
|
136
|
+
It can be either real or complex-valued.
|
|
137
137
|
"""
|
|
138
138
|
e, b = self.fields(r, t)
|
|
139
139
|
return poynting_vector(e, b)
|
|
@@ -147,7 +147,7 @@ class Antenna(BaseAntenna):
|
|
|
147
147
|
Float[Array, "2*{num_points} {num_points}"],
|
|
148
148
|
]:
|
|
149
149
|
"""
|
|
150
|
-
Compute an estimate of the antenna directivity for
|
|
150
|
+
Compute an estimate of the antenna directivity for azimuthal and elevation angles.
|
|
151
151
|
|
|
152
152
|
.. note::
|
|
153
153
|
|
|
@@ -157,10 +157,10 @@ class Antenna(BaseAntenna):
|
|
|
157
157
|
Args:
|
|
158
158
|
num_points: The number of points to sample along the elevation axis.
|
|
159
159
|
|
|
160
|
-
Twice this number of points are sampled on the
|
|
160
|
+
Twice this number of points are sampled on the azimuthal axis.
|
|
161
161
|
|
|
162
162
|
Returns:
|
|
163
|
-
|
|
163
|
+
Azimuthal and elevation angles, as well as corresponding directivity values.
|
|
164
164
|
|
|
165
165
|
.. seealso::
|
|
166
166
|
|
|
@@ -220,12 +220,12 @@ class Antenna(BaseAntenna):
|
|
|
220
220
|
"""
|
|
221
221
|
Plot the radiation pattern (normalized power) of this antenna.
|
|
222
222
|
|
|
223
|
-
The power is computed on points on
|
|
223
|
+
The power is computed on points on a sphere around the antenna.
|
|
224
224
|
|
|
225
225
|
Args:
|
|
226
226
|
num_points: The number of points to sample along the elevation axis.
|
|
227
227
|
|
|
228
|
-
Twice this number of points are sampled on the
|
|
228
|
+
Twice this number of points are sampled on the azimuthal axis.
|
|
229
229
|
distance: The distance from the antenna at which power samples
|
|
230
230
|
are evaluated.
|
|
231
231
|
num_wavelengths: If provided, supersedes ``distance`` by setting
|
|
@@ -279,8 +279,8 @@ class Dipole(Antenna):
|
|
|
279
279
|
By default, the dipole is aligned with the z-axis.
|
|
280
280
|
current: The current (in A) flowing in the dipole.
|
|
281
281
|
|
|
282
|
-
If this is provided, which is the default,
|
|
283
|
-
vector is used, and its
|
|
282
|
+
If this is provided, which is the default, only the direction of the moment
|
|
283
|
+
vector is used, and its intensity is set to match the dipole moment with
|
|
284
284
|
specified current.
|
|
285
285
|
charge: The dipole charge (in Coulomb), assuming opposite charges on either ends of the dipole.
|
|
286
286
|
|
|
@@ -533,7 +533,7 @@ class RadiationPattern(BaseAntenna):
|
|
|
533
533
|
r: The array of positions.
|
|
534
534
|
|
|
535
535
|
Returns:
|
|
536
|
-
The electric :math:`\vec{E}` and
|
|
536
|
+
The electric :math:`\vec{E}` and magnetic :math:`\vec{B}` fields.
|
|
537
537
|
|
|
538
538
|
Fields can be either real or complex-valued.
|
|
539
539
|
"""
|
|
@@ -547,7 +547,7 @@ class RadiationPattern(BaseAntenna):
|
|
|
547
547
|
Float[Array, "2*{num_points} {num_points}"],
|
|
548
548
|
]:
|
|
549
549
|
"""
|
|
550
|
-
Compute an estimate of the antenna directivity for
|
|
550
|
+
Compute an estimate of the antenna directivity for azimuthal and elevation angles.
|
|
551
551
|
|
|
552
552
|
.. note::
|
|
553
553
|
|
|
@@ -557,10 +557,10 @@ class RadiationPattern(BaseAntenna):
|
|
|
557
557
|
Args:
|
|
558
558
|
num_points: The number of points to sample along the elevation axis.
|
|
559
559
|
|
|
560
|
-
Twice this number of points are sampled on the
|
|
560
|
+
Twice this number of points are sampled on the azimuthal axis.
|
|
561
561
|
|
|
562
562
|
Returns:
|
|
563
|
-
|
|
563
|
+
Azimuthal and elevation angles, as well as corresponding directivity values.
|
|
564
564
|
|
|
565
565
|
.. seealso::
|
|
566
566
|
|
|
@@ -616,12 +616,12 @@ class RadiationPattern(BaseAntenna):
|
|
|
616
616
|
"""
|
|
617
617
|
Plot the radiation pattern (normalized power) of this antenna.
|
|
618
618
|
|
|
619
|
-
The power is computed on points on
|
|
619
|
+
The power is computed on points on a sphere around the antenna.
|
|
620
620
|
|
|
621
621
|
Args:
|
|
622
622
|
num_points: The number of points to sample along the elevation axis.
|
|
623
623
|
|
|
624
|
-
Twice this number of points are sampled on the
|
|
624
|
+
Twice this number of points are sampled on the azimuthal axis.
|
|
625
625
|
distance: The distance from the antenna at which power samples
|
|
626
626
|
are evaluated.
|
|
627
627
|
num_wavelengths: If provided, supersedes ``distance`` by setting
|
|
@@ -100,10 +100,10 @@ def L_i(
|
|
|
100
100
|
|
|
101
101
|
where :math:`s^d` is the distance from the point of diffraction (:math:`Q_d`) to the observer
|
|
102
102
|
point (:math:`P`),
|
|
103
|
-
:math:`\rho_1^i` is the principal radius of curvature of the incident
|
|
103
|
+
:math:`\rho_1^i` is the principal radius of curvature of the incident wavefront at :math:`Q_d`
|
|
104
104
|
in the plane of incidence,
|
|
105
|
-
:math:`\rho_2^i` is the principal radius of curvature of the incident
|
|
106
|
-
in the
|
|
105
|
+
:math:`\rho_2^i` is the principal radius of curvature of the incident wavefront at :math:`Q_d`
|
|
106
|
+
in the plane transverse to the plane of incidence,
|
|
107
107
|
:math:`\rho_e^i` is radius of curvature of the incident wavefront in the edge-fixed
|
|
108
108
|
plane of incidence., and :math:`\beta_0` is the angle of diffraction.
|
|
109
109
|
|
|
@@ -102,7 +102,7 @@ class Paths(eqx.Module):
|
|
|
102
102
|
)
|
|
103
103
|
"""An optional mask to indicate which paths are valid and should be used.
|
|
104
104
|
|
|
105
|
-
The mask is kept separately to :attr:`vertices` so that we can keep information
|
|
105
|
+
The mask is kept separately to :attr:`vertices` so that we can keep information about
|
|
106
106
|
batch ``*batch`` dimensions, which would not be possible if we were to directly
|
|
107
107
|
store valid paths.
|
|
108
108
|
"""
|
|
@@ -451,7 +451,7 @@ class Paths(eqx.Module):
|
|
|
451
451
|
ValueError: If :attr:`mask` is None.
|
|
452
452
|
"""
|
|
453
453
|
if self.mask is None and self.confidence is None:
|
|
454
|
-
msg = "Cannot create
|
|
454
|
+
msg = "Cannot create multipath cells from non-existing mask (or confidence matrix)!"
|
|
455
455
|
raise ValueError(msg)
|
|
456
456
|
|
|
457
457
|
if self.mask is not None:
|
|
@@ -578,7 +578,7 @@ class SBRPaths(Paths):
|
|
|
578
578
|
|
|
579
579
|
Warning:
|
|
580
580
|
The ``mask`` argument is ignored as it will automatically
|
|
581
|
-
|
|
581
|
+
be overwritten with the last array in :attr:`masks`.
|
|
582
582
|
"""
|
|
583
583
|
|
|
584
584
|
_: KW_ONLY
|
|
@@ -206,7 +206,7 @@ class TriangleMesh(eqx.Module):
|
|
|
206
206
|
|
|
207
207
|
The array contains the material indices,
|
|
208
208
|
with a special placeholder value of ``-1``.
|
|
209
|
-
|
|
209
|
+
To obtain the name of the material, see :attr:`material_names`.
|
|
210
210
|
This attribute is :data:`None` if all face materials are unset.
|
|
211
211
|
"""
|
|
212
212
|
material_names: tuple[str, ...] = eqx.field(
|
|
@@ -268,7 +268,7 @@ class TriangleMesh(eqx.Module):
|
|
|
268
268
|
|
|
269
269
|
Warning:
|
|
270
270
|
As it is not possible to guarantee that indexing would not break existing
|
|
271
|
-
object bounds, the :attr:`object_bounds`
|
|
271
|
+
object bounds, the :attr:`object_bounds` attribute is simply dropped.
|
|
272
272
|
|
|
273
273
|
Args:
|
|
274
274
|
key: The key used to index :attr:`triangles`
|
|
@@ -630,7 +630,7 @@ class TriangleMesh(eqx.Module):
|
|
|
630
630
|
Return a new mesh by applying a scale factor to all triangle coordinates.
|
|
631
631
|
|
|
632
632
|
Args:
|
|
633
|
-
scale_factor: The
|
|
633
|
+
scale_factor: The scale factor.
|
|
634
634
|
|
|
635
635
|
Returns:
|
|
636
636
|
The new scaled mesh.
|
|
@@ -417,7 +417,7 @@ def fibonacci_lattice(
|
|
|
417
417
|
frustum: The spatial region where to sample points.
|
|
418
418
|
|
|
419
419
|
The frustum in an array of min. and max. values for
|
|
420
|
-
|
|
420
|
+
azimuthal and elevation angles, see :func:`viewing_frustum` for example.
|
|
421
421
|
|
|
422
422
|
It is allowed to pass a frustum with distance values, but it will be ignored
|
|
423
423
|
as the distance of from sampled points to origin is always 1.
|
|
@@ -781,10 +781,10 @@ def viewing_frustum(
|
|
|
781
781
|
a_min = jnp.min(a, axis=-1)
|
|
782
782
|
a_max = jnp.max(a, axis=-1)
|
|
783
783
|
|
|
784
|
-
# The discontinuity for
|
|
784
|
+
# The discontinuity for azimuthal angles near -pi;pi can create
|
|
785
785
|
# issues, leading to a larger angular sector that expected.
|
|
786
786
|
|
|
787
|
-
# We map
|
|
787
|
+
# We map azimuthal angles from [-pi;pi[ to [0;2pi[.
|
|
788
788
|
two_pi = 2 * jnp.pi
|
|
789
789
|
|
|
790
790
|
a_0 = (a + two_pi) % two_pi
|
|
@@ -284,7 +284,7 @@ def draw_rays(
|
|
|
284
284
|
The resulting plot output.
|
|
285
285
|
|
|
286
286
|
.. [#f1] Plotly's 3D quiver plot is just a cone, which does not look like an
|
|
287
|
-
arrow. To improve it, a line is prepended the cone.
|
|
287
|
+
arrow. To improve it, a line is prepended to the cone.
|
|
288
288
|
|
|
289
289
|
.. raw:: html
|
|
290
290
|
|
|
@@ -600,7 +600,7 @@ def draw_image(
|
|
|
600
600
|
Plot a 2D image on a 3D canvas, at a fixed z-coordinate.
|
|
601
601
|
|
|
602
602
|
Args:
|
|
603
|
-
data: The image data array. Can be grayscale, RGB or RGBA.
|
|
603
|
+
data: The image data array. Can be grayscale, RGB, or RGBA.
|
|
604
604
|
For more details on how the data is interpreted, please
|
|
605
605
|
refer to the documentation of the function corresponding
|
|
606
606
|
to the specified backend (see below).
|
|
@@ -621,7 +621,7 @@ def draw_image(
|
|
|
621
621
|
The resulting plot output.
|
|
622
622
|
|
|
623
623
|
Warning:
|
|
624
|
-
Matplotlib backend requires ``data`` to be either RGB or RGBA array.
|
|
624
|
+
Matplotlib backend requires ``data`` to be either an RGB or an RGBA array.
|
|
625
625
|
|
|
626
626
|
Examples:
|
|
627
627
|
The following example shows how to plot a 2-D image,
|
|
@@ -5,7 +5,7 @@ from typing import TypeVar
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
from jaxtyping import Array
|
|
7
7
|
|
|
8
|
-
# NOTE: we declare this
|
|
8
|
+
# NOTE: we declare this in another module to be able to patch it when building the docs
|
|
9
9
|
ArrayType = TypeVar(
|
|
10
10
|
"ArrayType",
|
|
11
11
|
bound=Array | np.ndarray, # type: ignore[reportMissingTypeArgument]
|
|
@@ -286,7 +286,7 @@ def export(
|
|
|
286
286
|
The current implementation assumes far-field propagation in free space, and isotropic antennas with vertical polarization.
|
|
287
287
|
|
|
288
288
|
While tests show a good match with Sionna's :class:`sionna.rt.PathSolver` for most attributes,
|
|
289
|
-
:attr:`DeepMIMO.power` and :attr:`DeepMIMO.phase` are not exactly
|
|
289
|
+
:attr:`DeepMIMO.power` and :attr:`DeepMIMO.phase` are not exactly equal, and we don't know yet if our implementation is 100% correct. If you know how to improve this, please open an issue or a pull-request on GitHub!
|
|
290
290
|
|
|
291
291
|
Args:
|
|
292
292
|
paths: The geometrical paths.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# ruff: noqa: ERA001
|
|
2
|
-
|
|
3
1
|
from functools import partial
|
|
4
2
|
from typing import overload
|
|
5
3
|
|
|
@@ -26,7 +24,7 @@ def image_of_vertices_with_respect_to_mirrors(
|
|
|
26
24
|
vertex on the infinite plane that describes the mirror is considered
|
|
27
25
|
to be a valid vertex.
|
|
28
26
|
mirror_normals: An array of mirror normals, where each normal has a unit
|
|
29
|
-
length and
|
|
27
|
+
length and is perpendicular to the corresponding mirror.
|
|
30
28
|
|
|
31
29
|
Returns:
|
|
32
30
|
An array of image vertices.
|
|
@@ -220,7 +218,7 @@ def image_method(
|
|
|
220
218
|
of specular reflections on a pre-defined list of mirrors.
|
|
221
219
|
|
|
222
220
|
The method assumes infinitely long mirrors, and will return invalid
|
|
223
|
-
paths in some degenerated cases such as consecutive
|
|
221
|
+
paths in some degenerated cases such as consecutive collinear mirrors,
|
|
224
222
|
or impossible configurations. It is the user's responsibility to make
|
|
225
223
|
sure that the returned path is correct.
|
|
226
224
|
|
|
@@ -243,7 +241,7 @@ def image_method(
|
|
|
243
241
|
vertex on the infinite plane that describes the mirror is considered
|
|
244
242
|
to be a valid vertex.
|
|
245
243
|
mirror_normals: An array of mirror normals, where each normal has a unit
|
|
246
|
-
length and
|
|
244
|
+
length and is perpendicular to the corresponding mirror.
|
|
247
245
|
|
|
248
246
|
Returns:
|
|
249
247
|
An array of ray paths obtained with the image method.
|
|
@@ -283,8 +281,8 @@ def image_method(
|
|
|
283
281
|
valid path that can be taken to join BS and UE with, in between, reflection with
|
|
284
282
|
two mirrors (the interaction order is important). First, the consecutive images
|
|
285
283
|
of the BS are determined through each mirror, using line symmetry. Second,
|
|
286
|
-
intersections with mirrors are computed backward,
|
|
287
|
-
first, by joining the UE, then the
|
|
284
|
+
intersections with mirrors are computed backward, i.e., from last mirror to
|
|
285
|
+
first, by joining the UE, then the intersection points, with the images of the
|
|
288
286
|
BS. Finally, the valid path can be obtained by joining BS, the intermediary
|
|
289
287
|
intersection points, and the UE :cite:`mpt-eucap2023{fig. 5, p. 3}`.
|
|
290
288
|
|
|
@@ -430,12 +428,21 @@ def consecutive_vertices_are_on_same_side_of_mirrors(
|
|
|
430
428
|
|
|
431
429
|
if mirror_vertices.shape[-2] == 0:
|
|
432
430
|
# If there are no mirrors, return empty array.
|
|
433
|
-
|
|
434
|
-
|
|
431
|
+
batch = jnp.broadcast_shapes(
|
|
432
|
+
vertices.shape[:-2],
|
|
433
|
+
mirror_vertices.shape[:-2],
|
|
434
|
+
mirror_normals.shape[:-2],
|
|
435
|
+
)
|
|
436
|
+
dtype = (
|
|
437
|
+
bool
|
|
438
|
+
if smoothing_factor is None
|
|
439
|
+
else jnp.result_type(vertices, mirror_vertices, mirror_normals)
|
|
440
|
+
)
|
|
441
|
+
return jnp.empty((*batch, 0), dtype=dtype)
|
|
435
442
|
|
|
436
443
|
# dot_{prev,next} = <(v_{prev,next} - mirror_v), mirror_n>
|
|
437
444
|
|
|
438
|
-
# [num_mirrors]
|
|
445
|
+
# [*batch num_mirrors 3]
|
|
439
446
|
d_prev = vertices[..., :-2, :] - mirror_vertices
|
|
440
447
|
d_next = vertices[..., +2:, :] - mirror_vertices
|
|
441
448
|
|
|
@@ -85,14 +85,14 @@ def generate_all_path_candidates(
|
|
|
85
85
|
another, by passing by exactly ``order`` primitives. Calling this function
|
|
86
86
|
is equivalent to calling :func:`itertools.product` with parameters
|
|
87
87
|
``[0, 1, ..., num_primitives - 1]`` and ``repeat=order``, and removing entries
|
|
88
|
-
|
|
88
|
+
containing loops, i.e., two or more consecutive indices that are equal.
|
|
89
89
|
|
|
90
90
|
Args:
|
|
91
91
|
num_primitives: The (positive) number of primitives.
|
|
92
92
|
order: The path order. An order less than one returns an empty array.
|
|
93
93
|
|
|
94
94
|
Returns:
|
|
95
|
-
An unsigned array with primitive indices on each
|
|
95
|
+
An unsigned array with primitive indices on each column. Its number of
|
|
96
96
|
columns is actually equal to
|
|
97
97
|
``num_primitives * ((num_primitives - 1) ** (order - 1))``.
|
|
98
98
|
"""
|
|
@@ -206,12 +206,12 @@ def rays_intersect_triangles(
|
|
|
206
206
|
|
|
207
207
|
Such a tolerance is especially useful when rays are hitting
|
|
208
208
|
triangle edges, a very common case if geometries are planes
|
|
209
|
-
split into multiple triangles.
|
|
209
|
+
split into multiple triangles.
|
|
210
210
|
|
|
211
211
|
If not specified, the default is ten times the epsilon value
|
|
212
212
|
of the currently used floating point dtype.
|
|
213
213
|
smoothing_factor: If set, hard conditions are replaced with smoothed ones,
|
|
214
|
-
as described in :cite:`fully-eucap2024`, and this argument
|
|
214
|
+
as described in :cite:`fully-eucap2024`, and this argument parameterizes the slope
|
|
215
215
|
of the smoothing function. The second output value is now a real value
|
|
216
216
|
between 0 (:data:`False`) and 1 (:data:`True`).
|
|
217
217
|
|
|
@@ -414,7 +414,7 @@ def rays_intersect_any_triangle(
|
|
|
414
414
|
If not specified, the default is ten times the epsilon value
|
|
415
415
|
of the currently used floating point dtype.
|
|
416
416
|
smoothing_factor: If set, hard conditions are replaced with smoothed ones,
|
|
417
|
-
as described in :cite:`fully-eucap2024`, and this argument
|
|
417
|
+
as described in :cite:`fully-eucap2024`, and this argument parameterizes the slope
|
|
418
418
|
of the smoothing function. The second output value is now a real value
|
|
419
419
|
between 0 (:data:`False`) and 1 (:data:`True`).
|
|
420
420
|
|
|
@@ -116,7 +116,7 @@ def download_sionna_scenes(
|
|
|
116
116
|
else: # pragma: no cover
|
|
117
117
|
msg = (
|
|
118
118
|
"You are using an old version of Python that doesn't include the 'filter' "
|
|
119
|
-
"parameter in 'tarfile.TarFile.extractall'. This
|
|
119
|
+
"parameter in 'tarfile.TarFile.extractall'. This can be a security issue, and we "
|
|
120
120
|
"recommend upgrading to a newer version of Python: 3.12, 3.11.4, or 3.10.12."
|
|
121
121
|
)
|
|
122
122
|
warnings.warn(msg, UserWarning, stacklevel=2)
|
|
@@ -212,7 +212,7 @@ def main() -> None: # pragma: no cover
|
|
|
212
212
|
"-f",
|
|
213
213
|
"--force",
|
|
214
214
|
action="store_true",
|
|
215
|
-
help="force to clean any existing folder
|
|
215
|
+
help="force to clean any existing folder when '--no-cached' is set.",
|
|
216
216
|
)
|
|
217
217
|
parser.add_argument(
|
|
218
218
|
"--cached",
|
|
@@ -224,7 +224,7 @@ def main() -> None: # pragma: no cover
|
|
|
224
224
|
"--chunk-size",
|
|
225
225
|
type=int,
|
|
226
226
|
default=1024,
|
|
227
|
-
help="the chunk size, in bytes, used
|
|
227
|
+
help="the chunk size, in bytes, used for displaying progress",
|
|
228
228
|
)
|
|
229
229
|
parser.add_argument(
|
|
230
230
|
"--progress",
|
|
@@ -8,8 +8,6 @@ import equinox as eqx
|
|
|
8
8
|
import jax
|
|
9
9
|
import jax.numpy as jnp
|
|
10
10
|
import numpy as np
|
|
11
|
-
from jax.experimental.shard_map import shard_map
|
|
12
|
-
from jax.sharding import PartitionSpec as P
|
|
13
11
|
from jaxtyping import Array, ArrayLike, Bool, Float, Int
|
|
14
12
|
|
|
15
13
|
import differt_core.scene
|
|
@@ -58,7 +56,6 @@ def _compute_paths(
|
|
|
58
56
|
rx_vertices: Float[Array, "num_rx_vertices 3"],
|
|
59
57
|
path_candidates: Int[Array, "num_path_candidates order"],
|
|
60
58
|
*,
|
|
61
|
-
parallel: bool,
|
|
62
59
|
epsilon: Float[ArrayLike, " "] | None,
|
|
63
60
|
hit_tol: Float[ArrayLike, " "] | None,
|
|
64
61
|
min_len: Float[ArrayLike, " "] | None,
|
|
@@ -113,200 +110,161 @@ def _compute_paths(
|
|
|
113
110
|
mesh.normals, path_candidates[..., :: (2 if mesh.assume_quads else 1)], axis=0
|
|
114
111
|
)
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
tx_vertices: Float[Array, "num_tx_vertices 3"],
|
|
118
|
-
rx_vertices: Float[Array, "num_rx_vertices 3"],
|
|
119
|
-
) -> tuple[
|
|
120
|
-
Float[
|
|
121
|
-
Array,
|
|
122
|
-
"num_tx_vertices num_rx_vertices num_path_candidates path_length 3",
|
|
123
|
-
],
|
|
124
|
-
Bool[Array, "num_tx_vertices num_rx_vertices num_path_candidates"]
|
|
125
|
-
| Float[Array, "num_tx_vertices num_rx_vertices num_path_candidates"],
|
|
126
|
-
]:
|
|
127
|
-
# 2 - Trace paths
|
|
128
|
-
|
|
129
|
-
# [num_tx_vertices num_rx_vertices num_path_candidates order 3]
|
|
130
|
-
paths = image_method(
|
|
131
|
-
tx_vertices[:, None, None, :],
|
|
132
|
-
rx_vertices[None, :, None, :],
|
|
133
|
-
mirror_vertices,
|
|
134
|
-
mirror_normals,
|
|
135
|
-
)
|
|
113
|
+
# 2 - Trace paths
|
|
136
114
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
115
|
+
# [num_tx_vertices num_rx_vertices num_path_candidates order 3]
|
|
116
|
+
paths = image_method(
|
|
117
|
+
tx_vertices[:, None, None, :],
|
|
118
|
+
rx_vertices[None, :, None, :],
|
|
119
|
+
mirror_vertices,
|
|
120
|
+
mirror_normals,
|
|
121
|
+
)
|
|
143
122
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
# 3.1 - Check if paths vertices are inside respective triangles
|
|
152
|
-
|
|
153
|
-
# [num_tx_vertices num_rx_vertices num_path_candidates]
|
|
154
|
-
if mesh.assume_quads:
|
|
155
|
-
if smoothing_factor is not None:
|
|
156
|
-
inside_triangles = (
|
|
157
|
-
rays_intersect_triangles(
|
|
158
|
-
jnp.repeat(ray_origins[..., :-1, :], 2, axis=-2),
|
|
159
|
-
jnp.repeat(ray_directions[..., :-1, :], 2, axis=-2),
|
|
160
|
-
triangle_vertices,
|
|
161
|
-
epsilon=epsilon,
|
|
162
|
-
smoothing_factor=smoothing_factor,
|
|
163
|
-
)[1]
|
|
164
|
-
.reshape(
|
|
165
|
-
num_tx_vertices, num_rx_vertices, num_path_candidates, order, 2
|
|
166
|
-
)
|
|
167
|
-
.max(axis=-1, initial=0.0)
|
|
168
|
-
.min(axis=-1, initial=1.0)
|
|
169
|
-
) # Reduce on 'order' axis and on the two triangles (per quad)
|
|
170
|
-
else:
|
|
171
|
-
inside_triangles = (
|
|
172
|
-
rays_intersect_triangles(
|
|
173
|
-
jnp.repeat(ray_origins[..., :-1, :], 2, axis=-2),
|
|
174
|
-
jnp.repeat(ray_directions[..., :-1, :], 2, axis=-2),
|
|
175
|
-
triangle_vertices,
|
|
176
|
-
epsilon=epsilon,
|
|
177
|
-
)[1]
|
|
178
|
-
.reshape(
|
|
179
|
-
num_tx_vertices, num_rx_vertices, num_path_candidates, order, 2
|
|
180
|
-
)
|
|
181
|
-
.any(axis=-1)
|
|
182
|
-
.all(axis=-1)
|
|
183
|
-
) # Reduce on 'order' axis and on the two triangles (per quad)
|
|
184
|
-
elif smoothing_factor is not None:
|
|
185
|
-
inside_triangles = rays_intersect_triangles(
|
|
186
|
-
ray_origins[..., :-1, :],
|
|
187
|
-
ray_directions[..., :-1, :],
|
|
188
|
-
triangle_vertices,
|
|
189
|
-
epsilon=epsilon,
|
|
190
|
-
smoothing_factor=smoothing_factor,
|
|
191
|
-
)[1].min(axis=-1, initial=1.0) # Reduce on 'order' axis
|
|
192
|
-
else:
|
|
193
|
-
inside_triangles = rays_intersect_triangles(
|
|
194
|
-
ray_origins[..., :-1, :],
|
|
195
|
-
ray_directions[..., :-1, :],
|
|
196
|
-
triangle_vertices,
|
|
197
|
-
epsilon=epsilon,
|
|
198
|
-
)[1].all(axis=-1) # Reduce on 'order' axis
|
|
123
|
+
# [num_tx_vertices num_rx_vertices num_path_candidates order+2 3]
|
|
124
|
+
full_paths = assemble_paths(
|
|
125
|
+
tx_vertices[:, None, None, :],
|
|
126
|
+
paths,
|
|
127
|
+
rx_vertices[None, :, None, :],
|
|
128
|
+
)
|
|
199
129
|
|
|
200
|
-
|
|
130
|
+
# 3 - Identify invalid paths
|
|
201
131
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
mirror_vertices,
|
|
207
|
-
mirror_normals,
|
|
208
|
-
smoothing_factor=smoothing_factor,
|
|
209
|
-
).min(axis=-1, initial=1.0) # Reduce on 'order'
|
|
210
|
-
else:
|
|
211
|
-
valid_reflections = consecutive_vertices_are_on_same_side_of_mirrors(
|
|
212
|
-
full_paths,
|
|
213
|
-
mirror_vertices,
|
|
214
|
-
mirror_normals,
|
|
215
|
-
).all(axis=-1) # Reduce on 'order'
|
|
132
|
+
# [num_tx_vertices num_rx_vertices num_path_candidates order+1 3]
|
|
133
|
+
ray_origins = full_paths[..., :-1, :]
|
|
134
|
+
# [num_tx_vertices num_rx_vertices num_path_candidates order+1 3]
|
|
135
|
+
ray_directions = jnp.diff(full_paths, axis=-2)
|
|
216
136
|
|
|
217
|
-
|
|
137
|
+
# 3.1 - Check if paths vertices are inside respective triangles
|
|
218
138
|
|
|
219
|
-
|
|
139
|
+
# [num_tx_vertices num_rx_vertices num_path_candidates]
|
|
140
|
+
if mesh.assume_quads:
|
|
220
141
|
if smoothing_factor is not None:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
142
|
+
inside_triangles = (
|
|
143
|
+
rays_intersect_triangles(
|
|
144
|
+
jnp.repeat(ray_origins[..., :-1, :], 2, axis=-2),
|
|
145
|
+
jnp.repeat(ray_directions[..., :-1, :], 2, axis=-2),
|
|
146
|
+
triangle_vertices,
|
|
147
|
+
epsilon=epsilon,
|
|
148
|
+
smoothing_factor=smoothing_factor,
|
|
149
|
+
)[1]
|
|
150
|
+
.reshape(
|
|
151
|
+
num_tx_vertices, num_rx_vertices, num_path_candidates, order, 2
|
|
152
|
+
)
|
|
153
|
+
.max(axis=-1, initial=0.0)
|
|
154
|
+
.min(axis=-1, initial=1.0)
|
|
155
|
+
) # Reduce on 'order' axis and on the two triangles (per quad)
|
|
231
156
|
else:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
157
|
+
inside_triangles = (
|
|
158
|
+
rays_intersect_triangles(
|
|
159
|
+
jnp.repeat(ray_origins[..., :-1, :], 2, axis=-2),
|
|
160
|
+
jnp.repeat(ray_directions[..., :-1, :], 2, axis=-2),
|
|
161
|
+
triangle_vertices,
|
|
162
|
+
epsilon=epsilon,
|
|
163
|
+
)[1]
|
|
164
|
+
.reshape(
|
|
165
|
+
num_tx_vertices, num_rx_vertices, num_path_candidates, order, 2
|
|
166
|
+
)
|
|
167
|
+
.any(axis=-1)
|
|
168
|
+
.all(axis=-1)
|
|
169
|
+
) # Reduce on 'order' axis and on the two triangles (per quad)
|
|
170
|
+
elif smoothing_factor is not None:
|
|
171
|
+
inside_triangles = rays_intersect_triangles(
|
|
172
|
+
ray_origins[..., :-1, :],
|
|
173
|
+
ray_directions[..., :-1, :],
|
|
174
|
+
triangle_vertices,
|
|
175
|
+
epsilon=epsilon,
|
|
176
|
+
smoothing_factor=smoothing_factor,
|
|
177
|
+
)[1].min(axis=-1, initial=1.0) # Reduce on 'order' axis
|
|
178
|
+
else:
|
|
179
|
+
inside_triangles = rays_intersect_triangles(
|
|
180
|
+
ray_origins[..., :-1, :],
|
|
181
|
+
ray_directions[..., :-1, :],
|
|
182
|
+
triangle_vertices,
|
|
183
|
+
epsilon=epsilon,
|
|
184
|
+
)[1].all(axis=-1) # Reduce on 'order' axis
|
|
241
185
|
|
|
242
|
-
|
|
186
|
+
# 3.2 - Check if consecutive path vertices are on the same side of mirrors
|
|
243
187
|
|
|
244
|
-
|
|
188
|
+
# [num_tx_vertices num_rx_vertices num_path_candidates]
|
|
189
|
+
if smoothing_factor is not None:
|
|
190
|
+
valid_reflections = consecutive_vertices_are_on_same_side_of_mirrors(
|
|
191
|
+
full_paths,
|
|
192
|
+
mirror_vertices,
|
|
193
|
+
mirror_normals,
|
|
194
|
+
smoothing_factor=smoothing_factor,
|
|
195
|
+
).min(axis=-1, initial=1.0) # Reduce on 'order'
|
|
196
|
+
else:
|
|
197
|
+
valid_reflections = consecutive_vertices_are_on_same_side_of_mirrors(
|
|
198
|
+
full_paths,
|
|
199
|
+
mirror_vertices,
|
|
200
|
+
mirror_normals,
|
|
201
|
+
).all(axis=-1) # Reduce on 'order'
|
|
245
202
|
|
|
246
|
-
|
|
247
|
-
too_small = smoothing_function(min_len - ray_lengths, smoothing_factor).max(
|
|
248
|
-
axis=-1, initial=0.0
|
|
249
|
-
) # Any path segment being too small
|
|
250
|
-
else:
|
|
251
|
-
too_small = (ray_lengths < min_len).any(
|
|
252
|
-
axis=-1
|
|
253
|
-
) # Any path segment being too small
|
|
254
|
-
|
|
255
|
-
# 3.5 - Identify paths that are not finite
|
|
256
|
-
is_finite = jnp.isfinite(full_paths).all(axis=(-1, -2))
|
|
257
|
-
full_paths = jnp.where(
|
|
258
|
-
is_finite[..., None, None], full_paths, jnp.zeros_like(full_paths)
|
|
259
|
-
)
|
|
203
|
+
# 3.3 - Identify paths that are blocked by other objects
|
|
260
204
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
205
|
+
# [num_tx_vertices num_rx_vertices num_path_candidates]
|
|
206
|
+
if smoothing_factor is not None:
|
|
207
|
+
blocked = rays_intersect_any_triangle(
|
|
208
|
+
ray_origins,
|
|
209
|
+
ray_directions,
|
|
210
|
+
mesh.triangle_vertices,
|
|
211
|
+
active_triangles=mesh.mask,
|
|
212
|
+
epsilon=epsilon,
|
|
213
|
+
hit_tol=hit_tol,
|
|
214
|
+
smoothing_factor=smoothing_factor,
|
|
215
|
+
batch_size=1024,
|
|
216
|
+
).max(axis=-1, initial=0.0) # Reduce on 'order'
|
|
217
|
+
else:
|
|
218
|
+
blocked = rays_intersect_any_triangle(
|
|
219
|
+
ray_origins,
|
|
220
|
+
ray_directions,
|
|
221
|
+
mesh.triangle_vertices,
|
|
222
|
+
active_triangles=mesh.mask,
|
|
223
|
+
epsilon=epsilon,
|
|
224
|
+
hit_tol=hit_tol,
|
|
225
|
+
batch_size=1024,
|
|
226
|
+
).any(axis=-1) # Reduce on 'order'
|
|
279
227
|
|
|
280
|
-
|
|
281
|
-
num_devices = jax.device_count()
|
|
228
|
+
# 3.4 - Identify path segments that are too small (e.g., double-reflection inside an edge)
|
|
282
229
|
|
|
283
|
-
|
|
284
|
-
tx_mesh = math.gcd(num_tx_vertices, num_devices)
|
|
285
|
-
rx_mesh = num_devices // tx_mesh
|
|
286
|
-
in_specs = (P("i", None), P("j", None))
|
|
287
|
-
out_specs = (P("i", "j", None, None, None), P("i", "j", None))
|
|
288
|
-
else:
|
|
289
|
-
msg = (
|
|
290
|
-
f"Found {num_devices} devices available, "
|
|
291
|
-
"but could not find any input with a size that is a multiple of that value. "
|
|
292
|
-
"Please user a number of transmitter and receiver points that is a "
|
|
293
|
-
f"multiple of {num_devices}."
|
|
294
|
-
)
|
|
295
|
-
raise ValueError(msg)
|
|
230
|
+
ray_lengths = dot(ray_directions) # Squared norm
|
|
296
231
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
)
|
|
232
|
+
if smoothing_factor is not None:
|
|
233
|
+
too_small = smoothing_function(min_len - ray_lengths, smoothing_factor).max(
|
|
234
|
+
axis=-1, initial=0.0
|
|
235
|
+
) # Any path segment being too small
|
|
236
|
+
else:
|
|
237
|
+
too_small = (ray_lengths < min_len).any(
|
|
238
|
+
axis=-1
|
|
239
|
+
) # Any path segment being too small
|
|
240
|
+
|
|
241
|
+
# 3.5 - Identify paths that are not finite
|
|
242
|
+
is_finite = jnp.isfinite(full_paths).all(axis=(-1, -2))
|
|
243
|
+
full_paths = jnp.where(
|
|
244
|
+
is_finite[..., None, None], full_paths, jnp.zeros_like(full_paths)
|
|
245
|
+
)
|
|
303
246
|
|
|
304
247
|
if smoothing_factor is not None:
|
|
305
|
-
vertices, confidence = fun(tx_vertices, rx_vertices)
|
|
306
248
|
mask = None
|
|
249
|
+
confidence = jnp.stack(
|
|
250
|
+
(
|
|
251
|
+
inside_triangles,
|
|
252
|
+
valid_reflections,
|
|
253
|
+
1.0 - blocked,
|
|
254
|
+
1.0 - too_small,
|
|
255
|
+
is_finite.astype(inside_triangles.dtype),
|
|
256
|
+
),
|
|
257
|
+
axis=-1,
|
|
258
|
+
).min(axis=-1, initial=1.0)
|
|
259
|
+
if active_rays is not None:
|
|
260
|
+
confidence *= active_rays
|
|
307
261
|
else:
|
|
308
|
-
vertices, mask = fun(tx_vertices, rx_vertices)
|
|
309
262
|
confidence = None
|
|
263
|
+
mask = inside_triangles & valid_reflections & ~blocked & ~too_small & is_finite
|
|
264
|
+
if active_rays is not None:
|
|
265
|
+
mask &= active_rays
|
|
266
|
+
|
|
267
|
+
vertices = full_paths
|
|
310
268
|
|
|
311
269
|
# 4 - Generate output paths and reshape
|
|
312
270
|
|
|
@@ -352,7 +310,6 @@ def _compute_paths_sbr(
|
|
|
352
310
|
*,
|
|
353
311
|
order: int,
|
|
354
312
|
num_rays: int,
|
|
355
|
-
parallel: bool,
|
|
356
313
|
epsilon: Float[ArrayLike, " "] | None,
|
|
357
314
|
max_dist: Float[ArrayLike, " "],
|
|
358
315
|
) -> SBRPaths:
|
|
@@ -465,51 +422,12 @@ def _compute_paths_sbr(
|
|
|
465
422
|
masks,
|
|
466
423
|
)
|
|
467
424
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
Bool[Array, "order_plus_1 num_tx_vertices num_rx_vertices num_rays"],
|
|
475
|
-
]:
|
|
476
|
-
valid_rays = jnp.ones(ray_origins.shape[:-1], dtype=bool)
|
|
477
|
-
_, (path_candidates, vertices, masks) = jax.lax.scan(
|
|
478
|
-
scan_fun,
|
|
479
|
-
(ray_origins, ray_directions, valid_rays),
|
|
480
|
-
length=order + 1,
|
|
481
|
-
)
|
|
482
|
-
return (path_candidates, vertices, masks)
|
|
483
|
-
|
|
484
|
-
if parallel:
|
|
485
|
-
num_devices = jax.device_count()
|
|
486
|
-
|
|
487
|
-
if (num_tx_vertices * num_rays) % num_devices == 0:
|
|
488
|
-
tx_mesh = math.gcd(num_tx_vertices, num_devices)
|
|
489
|
-
ray_mesh = num_devices // tx_mesh
|
|
490
|
-
in_specs = (P("i", "j", None), P("i", "j", None))
|
|
491
|
-
out_specs = (
|
|
492
|
-
P(None, "i", "j"),
|
|
493
|
-
P(None, "i", "j", None),
|
|
494
|
-
P(None, "i", None, "j"),
|
|
495
|
-
)
|
|
496
|
-
else:
|
|
497
|
-
msg = (
|
|
498
|
-
f"Found {num_devices} devices available, "
|
|
499
|
-
"but could not find any input with a size that is a multiple of that value. "
|
|
500
|
-
"Please user a number of transmitters and rays that is a "
|
|
501
|
-
f"multiple of {num_devices}."
|
|
502
|
-
)
|
|
503
|
-
raise ValueError(msg)
|
|
504
|
-
|
|
505
|
-
fun = shard_map(
|
|
506
|
-
fun,
|
|
507
|
-
jax.make_mesh((tx_mesh, ray_mesh), axis_names=("i", "j")),
|
|
508
|
-
in_specs=in_specs,
|
|
509
|
-
out_specs=out_specs,
|
|
510
|
-
)
|
|
511
|
-
|
|
512
|
-
path_candidates, vertices, masks = fun(ray_origins, ray_directions)
|
|
425
|
+
valid_rays = jnp.ones(ray_origins.shape[:-1], dtype=bool)
|
|
426
|
+
_, (path_candidates, vertices, masks) = jax.lax.scan(
|
|
427
|
+
scan_fun,
|
|
428
|
+
(ray_origins, ray_directions, valid_rays),
|
|
429
|
+
length=order + 1,
|
|
430
|
+
)
|
|
513
431
|
|
|
514
432
|
path_candidates = jnp.moveaxis(path_candidates[:-1, ...], 0, -1)
|
|
515
433
|
vertices = jnp.moveaxis(vertices[:-1, ...], 0, -2)
|
|
@@ -692,7 +610,7 @@ class TriangleScene(eqx.Module):
|
|
|
692
610
|
Return a new scene by applying a scale factor to all the objects in the scene.
|
|
693
611
|
|
|
694
612
|
Args:
|
|
695
|
-
scale_factor: The
|
|
613
|
+
scale_factor: The scale factor.
|
|
696
614
|
|
|
697
615
|
Returns:
|
|
698
616
|
The new scaled scene.
|
|
@@ -853,7 +771,6 @@ class TriangleScene(eqx.Module):
|
|
|
853
771
|
chunk_size: None = None,
|
|
854
772
|
num_rays: int = int(1e6),
|
|
855
773
|
path_candidates: Int[ArrayLike, "num_path_candidates order"] | None = None,
|
|
856
|
-
parallel: bool = False,
|
|
857
774
|
epsilon: Float[ArrayLike, " "] | None = None,
|
|
858
775
|
hit_tol: Float[ArrayLike, " "] | None = None,
|
|
859
776
|
min_len: Float[ArrayLike, " "] | None = None,
|
|
@@ -871,7 +788,6 @@ class TriangleScene(eqx.Module):
|
|
|
871
788
|
chunk_size: None = None,
|
|
872
789
|
num_rays: int = int(1e6),
|
|
873
790
|
path_candidates: None = None,
|
|
874
|
-
parallel: bool = False,
|
|
875
791
|
epsilon: Float[ArrayLike, " "] | None = None,
|
|
876
792
|
hit_tol: Float[ArrayLike, " "] | None = None,
|
|
877
793
|
min_len: Float[ArrayLike, " "] | None = None,
|
|
@@ -889,7 +805,6 @@ class TriangleScene(eqx.Module):
|
|
|
889
805
|
chunk_size: int,
|
|
890
806
|
num_rays: int = int(1e6),
|
|
891
807
|
path_candidates: None = None,
|
|
892
|
-
parallel: bool = False,
|
|
893
808
|
epsilon: Float[ArrayLike, " "] | None = None,
|
|
894
809
|
hit_tol: Float[ArrayLike, " "] | None = None,
|
|
895
810
|
min_len: Float[ArrayLike, " "] | None = None,
|
|
@@ -907,7 +822,6 @@ class TriangleScene(eqx.Module):
|
|
|
907
822
|
chunk_size: int,
|
|
908
823
|
num_rays: int = int(1e6),
|
|
909
824
|
path_candidates: None = None,
|
|
910
|
-
parallel: bool = False,
|
|
911
825
|
epsilon: Float[ArrayLike, " "] | None = None,
|
|
912
826
|
hit_tol: Float[ArrayLike, " "] | None = None,
|
|
913
827
|
min_len: Float[ArrayLike, " "] | None = None,
|
|
@@ -925,7 +839,6 @@ class TriangleScene(eqx.Module):
|
|
|
925
839
|
chunk_size: int,
|
|
926
840
|
num_rays: int = int(1e6),
|
|
927
841
|
path_candidates: Int[ArrayLike, "num_path_candidates order"],
|
|
928
|
-
parallel: bool = False,
|
|
929
842
|
epsilon: Float[ArrayLike, " "] | None = None,
|
|
930
843
|
hit_tol: Float[ArrayLike, " "] | None = None,
|
|
931
844
|
min_len: Float[ArrayLike, " "] | None = None,
|
|
@@ -943,7 +856,6 @@ class TriangleScene(eqx.Module):
|
|
|
943
856
|
chunk_size: None = None,
|
|
944
857
|
num_rays: int = int(1e6),
|
|
945
858
|
path_candidates: None = None,
|
|
946
|
-
parallel: bool = False,
|
|
947
859
|
epsilon: Float[ArrayLike, " "] | None = None,
|
|
948
860
|
hit_tol: None = None,
|
|
949
861
|
min_len: None = None,
|
|
@@ -960,7 +872,6 @@ class TriangleScene(eqx.Module):
|
|
|
960
872
|
chunk_size: int | None = None,
|
|
961
873
|
num_rays: int = int(1e6),
|
|
962
874
|
path_candidates: Int[ArrayLike, "num_path_candidates order"] | None = None,
|
|
963
|
-
parallel: bool = False,
|
|
964
875
|
epsilon: Float[ArrayLike, " "] | None = None,
|
|
965
876
|
hit_tol: Float[ArrayLike, " "] | None = None,
|
|
966
877
|
min_len: Float[ArrayLike, " "] | None = None,
|
|
@@ -1031,16 +942,7 @@ class TriangleScene(eqx.Module):
|
|
|
1031
942
|
to triangle indices, not quadrilateral indices).
|
|
1032
943
|
|
|
1033
944
|
**Not compatible with** ``method == 'sbr'`` and ``method == 'hybrid'``.
|
|
1034
|
-
|
|
1035
|
-
devices. The number of transmitters times the number of receivers
|
|
1036
|
-
**must** be a multiple of :func:`jax.device_count`, otherwise an error is raised.
|
|
1037
|
-
|
|
1038
|
-
When ``method == 'sbr'``, the number of transmitters times the number of rays
|
|
1039
|
-
**must** be a multiple of :func:`jax.device_count`, otherwise an error is raised.
|
|
1040
|
-
|
|
1041
|
-
.. warning::
|
|
1042
|
-
Parallel execution is automatically disabled if ``jax>=0.6`` is used, see `#280 <https://github.com/jeertmans/DiffeRT/issues/280>`_.
|
|
1043
|
-
epsilon: Tolelance for checking ray / objects intersection, see
|
|
945
|
+
epsilon: Tolerance for checking ray / objects intersection, see
|
|
1044
946
|
:func:`rays_intersect_triangles<differt.rt.rays_intersect_triangles>`.
|
|
1045
947
|
hit_tol: Tolerance for checking blockage (i.e., obstruction), see
|
|
1046
948
|
:func:`rays_intersect_any_triangle<differt.rt.rays_intersect_any_triangle>`.
|
|
@@ -1088,18 +990,8 @@ class TriangleScene(eqx.Module):
|
|
|
1088
990
|
|
|
1089
991
|
If ``method == 'sbr'`` or ``method == 'hybrid'`, and ``order`` is not provided.
|
|
1090
992
|
|
|
1091
|
-
If ``parallel`` is :data:`True`, and the number of devices is not a divisor of the number of transmitters times the number of receivers, or the number of transmitters times the number of rays.
|
|
1092
|
-
|
|
1093
993
|
.. [#f1] Passing the squared length/distance is useful to avoid computing square root values, which is expensive.
|
|
1094
|
-
"""
|
|
1095
|
-
if parallel and jax.__version_info__ >= (0, 6):
|
|
1096
|
-
msg = (
|
|
1097
|
-
"Parallel execution is automatically disabled when using jax>=0.6, "
|
|
1098
|
-
"as it is not (yet) compatible with the new JAX API. See "
|
|
1099
|
-
"https://github.com/jeertmans/DiffeRT/issues/280."
|
|
1100
|
-
)
|
|
1101
|
-
warnings.warn(msg, UserWarning, stacklevel=2)
|
|
1102
|
-
parallel = False
|
|
994
|
+
"""
|
|
1103
995
|
if (order is None) == (path_candidates is None):
|
|
1104
996
|
msg = "You must specify one of 'order' or `path_candidates`, not both."
|
|
1105
997
|
raise ValueError(msg)
|
|
@@ -1126,7 +1018,6 @@ class TriangleScene(eqx.Module):
|
|
|
1126
1018
|
self.receivers.reshape(-1, 3),
|
|
1127
1019
|
order=order,
|
|
1128
1020
|
num_rays=num_rays,
|
|
1129
|
-
parallel=parallel,
|
|
1130
1021
|
epsilon=epsilon,
|
|
1131
1022
|
max_dist=max_dist,
|
|
1132
1023
|
).reshape(*tx_batch, *rx_batch, -1)
|
|
@@ -1196,7 +1087,6 @@ class TriangleScene(eqx.Module):
|
|
|
1196
1087
|
2 * path_candidates if assume_quads else path_candidates,
|
|
1197
1088
|
dtype=int,
|
|
1198
1089
|
),
|
|
1199
|
-
parallel=parallel,
|
|
1200
1090
|
epsilon=epsilon,
|
|
1201
1091
|
hit_tol=hit_tol,
|
|
1202
1092
|
min_len=min_len,
|
|
@@ -1233,7 +1123,6 @@ class TriangleScene(eqx.Module):
|
|
|
1233
1123
|
tx_vertices,
|
|
1234
1124
|
rx_vertices,
|
|
1235
1125
|
path_candidates,
|
|
1236
|
-
parallel=parallel,
|
|
1237
1126
|
epsilon=epsilon,
|
|
1238
1127
|
hit_tol=hit_tol,
|
|
1239
1128
|
min_len=min_len,
|
|
@@ -170,7 +170,7 @@ def safe_divide(
|
|
|
170
170
|
den: The denominator.
|
|
171
171
|
|
|
172
172
|
Returns:
|
|
173
|
-
The result of ``num /
|
|
173
|
+
The result of ``num / den``, except that division by zero returns 0.
|
|
174
174
|
|
|
175
175
|
Examples:
|
|
176
176
|
The following examples shows how division by zero is handled.
|
|
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
|