differt 0.4.0__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.
Files changed (34) hide show
  1. {differt-0.4.0 → differt-0.5.0}/PKG-INFO +5 -5
  2. {differt-0.4.0 → differt-0.5.0}/README.md +3 -3
  3. {differt-0.4.0 → differt-0.5.0}/pyproject.toml +1 -1
  4. {differt-0.4.0 → differt-0.5.0}/src/differt/em/_antenna.py +22 -22
  5. {differt-0.4.0 → differt-0.5.0}/src/differt/em/_utd.py +4 -4
  6. {differt-0.4.0 → differt-0.5.0}/src/differt/geometry/_paths.py +3 -3
  7. {differt-0.4.0 → differt-0.5.0}/src/differt/geometry/_triangle_mesh.py +8 -3
  8. {differt-0.4.0 → differt-0.5.0}/src/differt/geometry/_utils.py +3 -3
  9. {differt-0.4.0 → differt-0.5.0}/src/differt/plotting/_core.py +21 -9
  10. {differt-0.4.0 → differt-0.5.0}/src/differt/plugins/_deepmimo_types.py +1 -1
  11. {differt-0.4.0 → differt-0.5.0}/src/differt/plugins/deepmimo.py +2 -2
  12. {differt-0.4.0 → differt-0.5.0}/src/differt/rt/_fermat.py +57 -78
  13. {differt-0.4.0 → differt-0.5.0}/src/differt/rt/_image_method.py +97 -90
  14. {differt-0.4.0 → differt-0.5.0}/src/differt/rt/_utils.py +294 -115
  15. {differt-0.4.0 → differt-0.5.0}/src/differt/scene/_sionna.py +3 -3
  16. {differt-0.4.0 → differt-0.5.0}/src/differt/scene/_triangle_scene.py +163 -270
  17. {differt-0.4.0 → differt-0.5.0}/src/differt/utils.py +1 -1
  18. {differt-0.4.0 → differt-0.5.0}/.gitignore +0 -0
  19. {differt-0.4.0 → differt-0.5.0}/LICENSE.md +0 -0
  20. {differt-0.4.0 → differt-0.5.0}/src/differt/__init__.py +0 -0
  21. {differt-0.4.0 → differt-0.5.0}/src/differt/_version.py +0 -0
  22. {differt-0.4.0 → differt-0.5.0}/src/differt/em/__init__.py +0 -0
  23. {differt-0.4.0 → differt-0.5.0}/src/differt/em/_constants.py +0 -0
  24. {differt-0.4.0 → differt-0.5.0}/src/differt/em/_fresnel.py +0 -0
  25. {differt-0.4.0 → differt-0.5.0}/src/differt/em/_interaction_type.py +0 -0
  26. {differt-0.4.0 → differt-0.5.0}/src/differt/em/_material.py +0 -0
  27. {differt-0.4.0 → differt-0.5.0}/src/differt/em/_utils.py +0 -0
  28. {differt-0.4.0 → differt-0.5.0}/src/differt/geometry/__init__.py +0 -0
  29. {differt-0.4.0 → differt-0.5.0}/src/differt/plotting/__init__.py +0 -0
  30. {differt-0.4.0 → differt-0.5.0}/src/differt/plotting/_utils.py +0 -0
  31. {differt-0.4.0 → differt-0.5.0}/src/differt/plugins/__init__.py +0 -0
  32. {differt-0.4.0 → differt-0.5.0}/src/differt/py.typed +0 -0
  33. {differt-0.4.0 → differt-0.5.0}/src/differt/rt/__init__.py +0 -0
  34. {differt-0.4.0 → 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.4.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.4.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/README.md)
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.4.0}
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/README.md)
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.4.0}
86
+ version = {v0.5.0}
87
87
  }
88
88
  ```
89
89
 
@@ -16,7 +16,7 @@ classifiers = [
16
16
  ]
17
17
  dependencies = [
18
18
  "chex>=0.1.86",
19
- "differt-core==0.4.0",
19
+ "differt-core==0.5.0",
20
20
  "equinox>=0.12.2",
21
21
  "filelock>=3.15.4",
22
22
  "jax>=0.4.32", # TODO: fixme, issue with pmap
@@ -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 Pointing vector in vacuum at from electric :math:`\vec{E}` and magnetic :math:`\vec{B}` fields.
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 magnetical field.
31
+ b: The magnetic field.
32
32
 
33
33
  Returns:
34
- The pointing vector :math:`\vec{S}`.
34
+ The Poynting vector :math:`\vec{S}`.
35
35
 
36
- It can be either real of complex-valued.
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 pointing vector at a distance
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 magnetical :math:`\vec{B}` fields.
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 pointing vector :math:`\vec{S}`.
134
+ The Poynting vector :math:`\vec{S}`.
135
135
 
136
- It can be either real of complex-valued.
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 azimutal and elevation angles.
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 aximutal axis.
160
+ Twice this number of points are sampled on the azimuthal axis.
161
161
 
162
162
  Returns:
163
- Azimutal and elevation angles, as well as corresponding directivity values.
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 an sphere around the antenna.
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 aximutal axis.
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, the only the direction of the moment
283
- vector is used, and its insensity is set to match the dipole moment with
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 magnetical :math:`\vec{B}` fields.
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 azimutal and elevation angles.
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 aximutal axis.
560
+ Twice this number of points are sampled on the azimuthal axis.
561
561
 
562
562
  Returns:
563
- Azimutal and elevation angles, as well as corresponding directivity values.
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 an sphere around the antenna.
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 aximutal axis.
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
@@ -645,7 +645,7 @@ class RadiationPattern(BaseAntenna):
645
645
 
646
646
  r = self.center + distance * jnp.stack((x, y, z), axis=-1)
647
647
 
648
- s = self.poynting_vector(r) # type: ignore[reportAttributeAccessIssue]
648
+ s = self.poynting_vector(r)
649
649
 
650
650
  p = jnp.linalg.norm(s, axis=-1, keepdims=True)
651
651
 
@@ -75,7 +75,7 @@ def L_i(
75
75
 
76
76
 
77
77
  @eqx.filter_jit
78
- def L_i( # noqa: PLR0917
78
+ def L_i(
79
79
  s_d: Float[Array, " *#batch"],
80
80
  sin_2_beta_0: Float[Array, " *#batch"],
81
81
  rho_1_i: Float[Array, " *#batch"] | None = None,
@@ -100,10 +100,10 @@ def L_i( # noqa: PLR0917
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 wavewront at :math:`Q_d`
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 wavewront at :math:`Q_d`
106
- in the place transverse to the plane of incidence,
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 multiplath cells from non-existing mask (or confidence matrix)!"
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
- by overwritten with the last array in :attr:`masks`.
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
- The obtain the name of the material, see :attr:`material_names`.
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(
@@ -248,6 +248,11 @@ class TriangleMesh(eqx.Module):
248
248
 
249
249
  Unless specified, the transformation or selection operations, like :meth:`rotate`,
250
250
  will not take the mask into account, and will apply to all triangles.
251
+
252
+ .. important::
253
+
254
+ When :attr:`assume_quads` is :data:`True`, a quad is considered active if both triangles
255
+ that form the quad are active.
251
256
  """
252
257
 
253
258
  def __check_init__(self) -> None: # noqa: PLW3201
@@ -263,7 +268,7 @@ class TriangleMesh(eqx.Module):
263
268
 
264
269
  Warning:
265
270
  As it is not possible to guarantee that indexing would not break existing
266
- object bounds, the :attr:`object_bounds` attributed is simply dropped.
271
+ object bounds, the :attr:`object_bounds` attribute is simply dropped.
267
272
 
268
273
  Args:
269
274
  key: The key used to index :attr:`triangles`
@@ -625,7 +630,7 @@ class TriangleMesh(eqx.Module):
625
630
  Return a new mesh by applying a scale factor to all triangle coordinates.
626
631
 
627
632
  Args:
628
- scale_factor: The scate factor.
633
+ scale_factor: The scale factor.
629
634
 
630
635
  Returns:
631
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
- azimutal and elevation angles, see :func:`viewing_frustum` for example.
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 azimutal angles near -pi;pi can create
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 azimutal angles from [-pi;pi[ to [0;2pi[.
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
@@ -99,10 +99,14 @@ def _(
99
99
 
100
100
  canvas, view = process_vispy_kwargs(kwargs)
101
101
 
102
+ if vertices.size == 0 or triangles.size == 0: # type: ignore[reportAttributeAccessIssue] # pragma: no cover
103
+ return canvas
104
+
102
105
  kwargs.setdefault("shading", "flat")
103
106
 
104
107
  vertices = np.asarray(vertices)
105
108
  triangles = np.asarray(triangles)
109
+
106
110
  view.add(Mesh(vertices=vertices, faces=triangles, **kwargs))
107
111
  view.camera.set_range()
108
112
 
@@ -202,6 +206,9 @@ def _(
202
206
 
203
207
  canvas, view = process_vispy_kwargs(kwargs)
204
208
 
209
+ if paths.size == 0: # type: ignore[reportAttributeAccessIssue] # pragma: no cover
210
+ return canvas
211
+
205
212
  kwargs.setdefault("width", 3.0)
206
213
  kwargs.setdefault("marker_size", 0.0)
207
214
  paths = np.asarray(paths)
@@ -211,7 +218,6 @@ def _(
211
218
  connect[path_length - 1 :: path_length] = False
212
219
 
213
220
  view.add(LinePlot(data=paths, connect=connect, **kwargs)) # type: ignore[reportArgumentType]
214
-
215
221
  view.camera.set_range()
216
222
 
217
223
  return canvas
@@ -278,7 +284,7 @@ def draw_rays(
278
284
  The resulting plot output.
279
285
 
280
286
  .. [#f1] Plotly's 3D quiver plot is just a cone, which does not look like an
281
- arrow. To improve it, a line is prepended the cone.
287
+ arrow. To improve it, a line is prepended to the cone.
282
288
 
283
289
  .. raw:: html
284
290
 
@@ -353,6 +359,9 @@ def _(
353
359
 
354
360
  canvas, view = process_vispy_kwargs(kwargs)
355
361
 
362
+ if ray_origins.size == 0 or ray_directions.size == 0: # type: ignore[reportAttributeAccessIssue] # pragma: no cover
363
+ return canvas
364
+
356
365
  kwargs.setdefault("width", 3.0)
357
366
  kwargs.setdefault("arrow_size", 6.0)
358
367
 
@@ -370,7 +379,6 @@ def _(
370
379
  arrows = np.concatenate((body_ends, arrows_center), axis=-1)
371
380
 
372
381
  view.add(Arrow(pos=pos, connect=connect, arrows=arrows, **kwargs)) # type: ignore[reportArgumentType]
373
-
374
382
  view.camera.set_range()
375
383
 
376
384
  return canvas
@@ -512,6 +520,10 @@ def _(
512
520
  from vispy.scene.visuals import Markers, Text # noqa: PLC0415
513
521
 
514
522
  canvas, view = process_vispy_kwargs(kwargs)
523
+
524
+ if markers.size == 0: # type: ignore[reportAttributeAccessIssue] # pragma: no cover
525
+ return canvas
526
+
515
527
  kwargs.setdefault("size", 1)
516
528
  kwargs.setdefault("edge_width_rel", 0.05)
517
529
  kwargs.setdefault("scaling", "scene")
@@ -588,7 +600,7 @@ def draw_image(
588
600
  Plot a 2D image on a 3D canvas, at a fixed z-coordinate.
589
601
 
590
602
  Args:
591
- data: The image data array. Can be grayscale, RGB or RGBA.
603
+ data: The image data array. Can be grayscale, RGB, or RGBA.
592
604
  For more details on how the data is interpreted, please
593
605
  refer to the documentation of the function corresponding
594
606
  to the specified backend (see below).
@@ -609,7 +621,7 @@ def draw_image(
609
621
  The resulting plot output.
610
622
 
611
623
  Warning:
612
- 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.
613
625
 
614
626
  Examples:
615
627
  The following example shows how to plot a 2-D image,
@@ -734,7 +746,7 @@ def _(
734
746
 
735
747
 
736
748
  @dispatch
737
- def draw_contour( # noqa: PLR0917
749
+ def draw_contour(
738
750
  data: Real[ArrayLike, "rows cols"],
739
751
  x: Real[ArrayLike, " cols"] | Real[ArrayLike, "rows cols 3"] | None = None,
740
752
  y: Real[ArrayLike, " rows"] | Real[ArrayLike, "rows cols 3"] | None = None,
@@ -796,7 +808,7 @@ def draw_contour( # noqa: PLR0917
796
808
 
797
809
 
798
810
  @draw_contour.register("vispy")
799
- def _( # noqa: PLR0917
811
+ def _(
800
812
  data: Real[ArrayLike, "rows cols"],
801
813
  x: Real[ArrayLike, " cols"] | Real[ArrayLike, "rows cols"] | None = None,
802
814
  y: Real[ArrayLike, " rows"] | Real[ArrayLike, "rows cols"] | None = None,
@@ -861,7 +873,7 @@ def _( # noqa: PLR0917
861
873
 
862
874
 
863
875
  @draw_contour.register("matplotlib")
864
- def _( # noqa: PLR0917
876
+ def _(
865
877
  data: Real[ArrayLike, "rows cols"],
866
878
  x: Real[ArrayLike, " cols"] | Real[ArrayLike, "rows cols"] | None = None,
867
879
  y: Real[ArrayLike, " rows"] | Real[ArrayLike, "rows cols"] | None = None,
@@ -891,7 +903,7 @@ def _( # noqa: PLR0917
891
903
 
892
904
 
893
905
  @draw_contour.register("plotly")
894
- def _( # noqa: PLR0917
906
+ def _(
895
907
  data: Real[ArrayLike, "rows cols"],
896
908
  x: Real[ArrayLike, " cols"] | Real[ArrayLike, "rows cols"] | None = None,
897
909
  y: Real[ArrayLike, " rows"] | Real[ArrayLike, "rows cols"] | None = None,
@@ -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 is another module to be able to patch it when building the docs
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]
@@ -271,7 +271,7 @@ class DeepMIMO(eqx.Module, Generic[ArrayType]):
271
271
  return output
272
272
 
273
273
 
274
- def export( # noqa: PLR0915
274
+ def export(
275
275
  *,
276
276
  paths: Paths | Iterable[Paths],
277
277
  scene: TriangleScene,
@@ -286,7 +286,7 @@ def export( # noqa: PLR0915
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 equals, 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!
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,4 +1,3 @@
1
- from functools import partial
2
1
  from typing import Any, no_type_check
3
2
 
4
3
  import chex
@@ -11,7 +10,6 @@ from jaxtyping import Array, ArrayLike, Float
11
10
  from differt.geometry import orthogonal_basis
12
11
 
13
12
 
14
- @partial(jax.jit, inline=True)
15
13
  def _param_to_xyz(
16
14
  p: Float[Array, "*batch num_object_x_num_dims"],
17
15
  o: Float[Array, "*#batch num_objects 3"],
@@ -22,7 +20,6 @@ def _param_to_xyz(
22
20
  return o + jnp.sum(p * v, axis=-2)
23
21
 
24
22
 
25
- @partial(jax.jit, inline=True)
26
23
  def _loss(
27
24
  p: Float[Array, "*batch num_object_x_num_dims"],
28
25
  from_: Float[Array, "*#batch 3"],
@@ -45,6 +42,47 @@ def _loss(
45
42
  )
46
43
 
47
44
 
45
+ def _fermat_path_on_linear_objects(
46
+ from_vertex: Float[Array, "3"],
47
+ to_vertex: Float[Array, "3"],
48
+ object_origins: Float[Array, "num_objects 3"],
49
+ object_vectors: Float[Array, "num_objects num_dims 3"],
50
+ steps: int,
51
+ optimizer: optax.GradientTransformationExtraArgs,
52
+ ) -> Float[Array, "num_objects 3"]:
53
+ dtype = jnp.result_type(from_vertex, to_vertex, object_origins, object_vectors)
54
+ x_0 = jnp.zeros(object_vectors.shape[0] * object_vectors.shape[1], dtype=dtype)
55
+ opt_state = optimizer.init(x_0)
56
+ value_and_grad = optax.value_and_grad_from_state(_loss)
57
+
58
+ @no_type_check
59
+ def update(
60
+ state: tuple[Float[Array, " num_unknowns"], Any],
61
+ _: None,
62
+ ) -> tuple[tuple[Float[Array, " num_unknowns"], Any], float | Float[Array, " "]]:
63
+ x, opt_state = state
64
+ loss_value, grad = value_and_grad(
65
+ x, from_vertex, to_vertex, object_origins, object_vectors, state=opt_state
66
+ )
67
+ updates, opt_state = optimizer.update(
68
+ grad,
69
+ opt_state,
70
+ x,
71
+ value=loss_value,
72
+ grad=grad,
73
+ value_fn=_loss,
74
+ from_=from_vertex,
75
+ to=to_vertex,
76
+ o=object_origins,
77
+ v=object_vectors,
78
+ )
79
+ x = optax.apply_updates(x, updates)
80
+ return (x, opt_state), loss_value
81
+
82
+ (x, _), _ = jax.lax.scan(update, (x_0, opt_state), length=steps)
83
+ return _param_to_xyz(x, object_origins, object_vectors)
84
+
85
+
48
86
  @eqx.filter_jit
49
87
  def fermat_path_on_linear_objects(
50
88
  from_vertices: Float[ArrayLike, "*#batch 3"],
@@ -176,90 +214,31 @@ def fermat_path_on_linear_objects(
176
214
  object_origins = jnp.asarray(object_origins)
177
215
  object_vectors = jnp.asarray(object_vectors)
178
216
 
179
- batch = jnp.broadcast_shapes(
180
- from_vertices.shape[:-1],
181
- to_vertices.shape[:-1],
182
- object_origins.shape[:-2],
183
- object_vectors.shape[:-3],
184
- )
185
-
186
- num_objects = object_origins.shape[-2]
187
-
188
- if num_objects == 0:
217
+ if (num_objects := object_origins.shape[-2]) == 0 or (
218
+ object_vectors.shape[-2] == 0
219
+ ):
189
220
  # If there are no objects, return empty paths.
190
- dtype = jnp.result_type(
191
- from_vertices, to_vertices, object_origins, object_vectors
221
+ # If there are no dimensions, return origins.
222
+ batch = jnp.broadcast_shapes(
223
+ from_vertices.shape[:-1],
224
+ to_vertices.shape[:-1],
225
+ object_origins.shape[:-2],
226
+ object_vectors.shape[:-3],
192
227
  )
193
- return jnp.empty((*batch, 0, 3), dtype=dtype)
194
-
195
- num_dims = object_vectors.shape[-2]
196
-
197
- if num_dims == 0:
198
- # If there are no dimension, return origins.
199
228
  dtype = jnp.result_type(
200
229
  from_vertices, to_vertices, object_origins, object_vectors
201
230
  )
231
+ if num_objects == 0:
232
+ return jnp.empty((*batch, 0, 3), dtype=dtype)
202
233
  return jnp.broadcast_to(object_origins, (*batch, num_objects, 3)).astype(dtype)
203
234
 
204
- num_unknowns = num_objects * num_dims
205
-
206
- objective = _loss
207
-
208
235
  optimizer = optimizer if optimizer is not None else optax.lbfgs()
209
236
 
210
- def minimize(
211
- x_0: Float[Array, " num_unknowns"],
212
- from_: Float[Array, "3"],
213
- to: Float[Array, "3"],
214
- o: Float[Array, "num_objects 3"],
215
- v: Float[Array, "num_objects num_dims 3"],
216
- ) -> Float[Array, "num_objects 3"]:
217
- opt_state = optimizer.init(x_0)
218
-
219
- value_and_grad = optax.value_and_grad_from_state(objective)
220
-
221
- @no_type_check
222
- def update(
223
- state: tuple[Float[Array, "*batch num_unknowns"], Any],
224
- _: None,
225
- ) -> tuple[
226
- tuple[Float[Array, "*batch num_unknowns"], Any], float | Float[Array, " "]
227
- ]:
228
- x, opt_state = state
229
- loss_value, grad = value_and_grad(x, from_, to, o, v, state=opt_state)
230
- updates, opt_state = optimizer.update(
231
- grad,
232
- opt_state,
233
- x,
234
- value=loss_value,
235
- grad=grad,
236
- value_fn=objective,
237
- from_=from_,
238
- to=to,
239
- o=o,
240
- v=v,
241
- )
242
- x = optax.apply_updates(x, updates)
243
- return (x, opt_state), loss_value
244
-
245
- (x, _), _ = jax.lax.scan(update, (x_0, opt_state), length=steps)
246
- return _param_to_xyz(x, o, v)
247
-
248
- x_0 = jnp.zeros((*batch, num_unknowns))
249
-
250
- for i in reversed(range(len(batch))):
251
- minimize = jax.vmap(
252
- minimize,
253
- in_axes=(
254
- 0,
255
- 0 if from_vertices.ndim > i + 1 else None,
256
- 0 if to_vertices.ndim > i + 1 else None,
257
- 0 if object_origins.ndim > i + 2 else None,
258
- 0 if object_vectors.ndim > i + 3 else None,
259
- ),
260
- )
261
-
262
- return minimize(x_0, from_vertices, to_vertices, object_origins, object_vectors)
237
+ return jnp.vectorize(
238
+ _fermat_path_on_linear_objects,
239
+ excluded={4, 5},
240
+ signature="(3),(3),(n,3),(n,d,3)->(n,3)",
241
+ )(from_vertices, to_vertices, object_origins, object_vectors, steps, optimizer)
263
242
 
264
243
 
265
244
  @eqx.filter_jit