differt 0.1.0__tar.gz → 0.1.2__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.1.0 → differt-0.1.2}/PKG-INFO +14 -5
  2. {differt-0.1.0 → differt-0.1.2}/README.md +11 -2
  3. {differt-0.1.0 → differt-0.1.2}/pyproject.toml +2 -2
  4. {differt-0.1.0 → differt-0.1.2}/src/differt/em/_interaction_type.py +1 -1
  5. {differt-0.1.0 → differt-0.1.2}/src/differt/em/_material.py +3 -1
  6. {differt-0.1.0 → differt-0.1.2}/src/differt/geometry/_paths.py +79 -14
  7. {differt-0.1.0 → differt-0.1.2}/src/differt/geometry/_triangle_mesh.py +3 -2
  8. {differt-0.1.0 → differt-0.1.2}/src/differt/geometry/_utils.py +2 -2
  9. {differt-0.1.0 → differt-0.1.2}/src/differt/plotting/_core.py +1 -1
  10. differt-0.1.2/src/differt/plugins/__init__.py +4 -0
  11. differt-0.1.2/src/differt/plugins/_deepmimo_types.py +9 -0
  12. differt-0.1.2/src/differt/plugins/deepmimo.py +577 -0
  13. {differt-0.1.0 → differt-0.1.2}/src/differt/rt/_fermat.py +99 -39
  14. {differt-0.1.0 → differt-0.1.2}/src/differt/rt/_image_method.py +13 -0
  15. {differt-0.1.0 → differt-0.1.2}/src/differt/rt/_utils.py +2 -1
  16. {differt-0.1.0 → differt-0.1.2}/src/differt/scene/_triangle_scene.py +111 -16
  17. {differt-0.1.0 → differt-0.1.2}/src/differt/utils.py +20 -75
  18. {differt-0.1.0 → differt-0.1.2}/.gitignore +0 -0
  19. {differt-0.1.0 → differt-0.1.2}/LICENSE.md +0 -0
  20. {differt-0.1.0 → differt-0.1.2}/src/differt/__init__.py +0 -0
  21. {differt-0.1.0 → differt-0.1.2}/src/differt/_version.py +0 -0
  22. {differt-0.1.0 → differt-0.1.2}/src/differt/em/__init__.py +0 -0
  23. {differt-0.1.0 → differt-0.1.2}/src/differt/em/_antenna.py +0 -0
  24. {differt-0.1.0 → differt-0.1.2}/src/differt/em/_constants.py +0 -0
  25. {differt-0.1.0 → differt-0.1.2}/src/differt/em/_fresnel.py +0 -0
  26. {differt-0.1.0 → differt-0.1.2}/src/differt/em/_utd.py +0 -0
  27. {differt-0.1.0 → differt-0.1.2}/src/differt/em/_utils.py +0 -0
  28. {differt-0.1.0 → differt-0.1.2}/src/differt/geometry/__init__.py +0 -0
  29. {differt-0.1.0 → differt-0.1.2}/src/differt/plotting/__init__.py +0 -0
  30. {differt-0.1.0 → differt-0.1.2}/src/differt/plotting/_utils.py +0 -0
  31. {differt-0.1.0 → differt-0.1.2}/src/differt/py.typed +0 -0
  32. {differt-0.1.0 → differt-0.1.2}/src/differt/rt/__init__.py +0 -0
  33. {differt-0.1.0 → differt-0.1.2}/src/differt/scene/__init__.py +0 -0
  34. {differt-0.1.0 → differt-0.1.2}/src/differt/scene/_sionna.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DiffeRT
3
- Version: 0.1.0
3
+ Version: 0.1.2
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,10 +21,10 @@ 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.1.0
24
+ Requires-Dist: differt-core==0.1.2
25
25
  Requires-Dist: equinox>=0.12.2
26
26
  Requires-Dist: filelock>=3.15.4
27
- Requires-Dist: jax<0.6,>=0.4.32
27
+ Requires-Dist: jax>=0.4.32
28
28
  Requires-Dist: jaxtyping>=0.3.2
29
29
  Requires-Dist: numpy>=1.26.1
30
30
  Requires-Dist: optax>=0.1.7
@@ -132,8 +132,17 @@ for a detailed step-by-step procedure.
132
132
 
133
133
  ## Citing
134
134
 
135
- If you use this software, please cite it as
136
- [detailed here](https://differt.readthedocs.io/latest/citing.html).
135
+ If you use this software, please cite it as:
136
+
137
+ ```bibtex
138
+ @software{Eertmans_Differentiable_Ray_Tracing,
139
+ title = {{DiffeRT: A Differentiable Ray Tracing Toolbox for Radio Propagation Simulations}},
140
+ author = {Eertmans, Jérome},
141
+ url = {https://github.com/jeertmans/DiffeRT},
142
+ license = {MIT},
143
+ version = {v0.1.2}
144
+ }
145
+ ```
137
146
 
138
147
  [pypi-version-badge]: https://img.shields.io/pypi/v/DiffeRT?label=DiffeRT&color=blueviolet
139
148
  [pypi-version-url]: https://pypi.org/project/DiffeRT/
@@ -75,8 +75,17 @@ for a detailed step-by-step procedure.
75
75
 
76
76
  ## Citing
77
77
 
78
- If you use this software, please cite it as
79
- [detailed here](https://differt.readthedocs.io/latest/citing.html).
78
+ If you use this software, please cite it as:
79
+
80
+ ```bibtex
81
+ @software{Eertmans_Differentiable_Ray_Tracing,
82
+ title = {{DiffeRT: A Differentiable Ray Tracing Toolbox for Radio Propagation Simulations}},
83
+ author = {Eertmans, Jérome},
84
+ url = {https://github.com/jeertmans/DiffeRT},
85
+ license = {MIT},
86
+ version = {v0.1.2}
87
+ }
88
+ ```
80
89
 
81
90
  [pypi-version-badge]: https://img.shields.io/pypi/v/DiffeRT?label=DiffeRT&color=blueviolet
82
91
  [pypi-version-url]: https://pypi.org/project/DiffeRT/
@@ -16,10 +16,10 @@ classifiers = [
16
16
  ]
17
17
  dependencies = [
18
18
  "chex>=0.1.86",
19
- "differt-core==0.1.0",
19
+ "differt-core==0.1.2",
20
20
  "equinox>=0.12.2",
21
21
  "filelock>=3.15.4",
22
- "jax>=0.4.32,<0.6", # TODO: fixme, issue with pmap
22
+ "jax>=0.4.32", # TODO: fixme, issue with pmap
23
23
  "jaxtyping>=0.3.2",
24
24
  "numpy>=1.26.1",
25
25
  "optax>=0.1.7",
@@ -6,7 +6,7 @@ class InteractionType(IntEnum):
6
6
  """Enumeration of interaction types."""
7
7
 
8
8
  REFLECTION = 0
9
- """Specular reflection on an surface."""
9
+ """Specular reflection on a surface."""
10
10
  DIFFRACTION = 1
11
11
  """Diffraction on an edge."""
12
12
  SCATTERING = 2
@@ -1,5 +1,7 @@
1
1
  # ruff: noqa: FURB152
2
+
2
3
  import operator
4
+ import os
3
5
  from collections.abc import Callable
4
6
  from functools import partial
5
7
  from typing import TYPE_CHECKING, Any
@@ -9,7 +11,7 @@ import jax
9
11
  import jax.numpy as jnp
10
12
  from jaxtyping import Array, ArrayLike, Float
11
13
 
12
- if TYPE_CHECKING:
14
+ if TYPE_CHECKING or "READTHEDOCS" in os.environ:
13
15
  import sys
14
16
 
15
17
  if sys.version_info >= (3, 11):
@@ -1,3 +1,5 @@
1
+ import math
2
+ import os
1
3
  import warnings
2
4
  from collections.abc import Callable, Iterator, Sequence
3
5
  from dataclasses import KW_ONLY
@@ -10,7 +12,7 @@ from jaxtyping import Array, ArrayLike, Bool, Float, Int, Num, Shaped
10
12
 
11
13
  from differt.plotting import PlotOutput, draw_paths, reuse
12
14
 
13
- if TYPE_CHECKING:
15
+ if TYPE_CHECKING or "READTHEDOCS" in os.environ:
14
16
  import sys
15
17
 
16
18
  if sys.version_info >= (3, 11):
@@ -133,6 +135,16 @@ class Paths(eqx.Module):
133
135
  )
134
136
  warnings.warn(msg, UserWarning, stacklevel=2)
135
137
 
138
+ @property
139
+ def shape(self) -> tuple[int, ...]:
140
+ """
141
+ Return the batch shape of the paths.
142
+
143
+ Returns:
144
+ The shape of paths' batch dimensions.
145
+ """
146
+ return self.vertices.shape[:-2]
147
+
136
148
  def reshape(self, *batch: int) -> Self:
137
149
  """
138
150
  Return a copy with reshaped paths' batch dimensions to match a given shape.
@@ -270,16 +282,26 @@ class Paths(eqx.Module):
270
282
  for _ in range(max(ndim - 1, 0)):
271
283
  f = jax.vmap(f)
272
284
 
273
- # TODO: mask the 'confidence' attribute too
285
+ non_duplicates = f(objects)
286
+ non_duplicates = jnp.moveaxis(non_duplicates, -1, axis)
274
287
 
275
- mask = f(objects)
276
- mask = jnp.moveaxis(mask, -1, axis)
277
- mask = mask & self.mask if self.mask is not None else mask
288
+ if self.mask is not None:
289
+ return eqx.tree_at(
290
+ lambda p: p.mask,
291
+ self,
292
+ self.mask & non_duplicates,
293
+ )
294
+ if self.confidence is not None:
295
+ return eqx.tree_at(
296
+ lambda p: p.confidence,
297
+ self,
298
+ self.confidence * non_duplicates,
299
+ )
278
300
 
279
301
  return eqx.tree_at(
280
302
  lambda p: p.mask,
281
303
  self,
282
- mask,
304
+ non_duplicates,
283
305
  is_leaf=lambda x: x is None,
284
306
  )
285
307
 
@@ -291,7 +313,7 @@ class Paths(eqx.Module):
291
313
  @property
292
314
  def order(self) -> int:
293
315
  """The length (i.e., number of vertices) of each individual path, excluding start and end vertices."""
294
- return self.objects.shape[-1] - 2
316
+ return self.path_length - 2
295
317
 
296
318
  @property
297
319
  def num_valid_paths(self) -> int | Int[Array, " "]:
@@ -303,7 +325,7 @@ class Paths(eqx.Module):
303
325
  return self.mask.sum()
304
326
  if self.confidence is not None:
305
327
  return (self.confidence >= self.confidence_threshold).sum()
306
- return self.objects[..., 0].size
328
+ return math.prod(self.objects.shape[:-1])
307
329
 
308
330
  @property
309
331
  def masked_vertices(
@@ -340,6 +362,51 @@ class Paths(eqx.Module):
340
362
  return objects[mask, ...]
341
363
  return objects
342
364
 
365
+ def masked(self) -> Self:
366
+ """Return a flattened copy of this object that only keeps valid paths.
367
+
368
+ The returned object has all batch dimensions flattened into one,
369
+ keeping only the paths where :attr:`mask` is :data:`True` (or where :attr:`confidence` is greater than or equal to :attr:`confidence_threshold`), and :attr:`mask` and :attr:`confidence` attributes are set to :data:`None`.
370
+
371
+ Returns:
372
+ A new paths instance with flattened batch dimensions and only valid paths.
373
+ """
374
+ batch_len = len(self.vertices.shape) - 2
375
+ self = jax.tree.map( # noqa: PLW0642
376
+ lambda arr: arr.reshape(-1, *arr.shape[batch_len:])
377
+ if jnp.ndim(arr) >= batch_len
378
+ else arr,
379
+ self,
380
+ )
381
+
382
+ if self.mask is not None:
383
+ mask = self.mask.reshape(-1)
384
+ elif self.confidence is not None:
385
+ mask = self.confidence.reshape(-1) >= self.confidence_threshold
386
+ else:
387
+ mask = slice(None, None, None)
388
+
389
+ return eqx.tree_at(
390
+ lambda p: (
391
+ p.vertices,
392
+ p.objects,
393
+ p.mask,
394
+ p.interaction_types,
395
+ p.confidence,
396
+ ),
397
+ self,
398
+ (
399
+ self.vertices[mask, ...],
400
+ self.objects[mask, ...],
401
+ None,
402
+ self.interaction_types[mask, ...]
403
+ if self.interaction_types is not None
404
+ else None,
405
+ None,
406
+ ),
407
+ is_leaf=lambda x: x is None,
408
+ )
409
+
343
410
  @eqx.filter_jit
344
411
  def multipath_cells(
345
412
  self,
@@ -390,7 +457,8 @@ class Paths(eqx.Module):
390
457
  if self.mask is not None:
391
458
  mask = jnp.moveaxis(self.mask, axis, -1)
392
459
  else:
393
- mask = jnp.moveaxis(self.confidence >= self.confidence_threshold, axis, -1)
460
+ # Looks like Pyright is not able to infer this
461
+ mask = jnp.moveaxis(self.confidence >= self.confidence_threshold, axis, -1) # type: ignore[reportOperatorIssue]
394
462
  *partial_batch, last_axis = mask.shape
395
463
 
396
464
  return _cell_ids(mask.reshape(-1, last_axis)).reshape(partial_batch)
@@ -568,11 +636,8 @@ class SBRPaths(Paths):
568
636
  )
569
637
 
570
638
  def plot(self, **kwargs: Any) -> PlotOutput:
571
- backend = kwargs.pop(
572
- "backend", None
573
- ) # TODO: check if kwargs may not cause issues
574
- with reuse(backend=backend) as output:
639
+ with reuse(**kwargs, pass_all_kwargs=True) as output:
575
640
  for order in range(self.order + 1):
576
- self.get_paths(order).plot(**kwargs)
641
+ self.get_paths(order).plot()
577
642
 
578
643
  return output
@@ -1,5 +1,6 @@
1
1
  # ruff: noqa: ERA001
2
2
 
3
+ import os
3
4
  from collections.abc import Callable, Iterator, Mapping
4
5
  from dataclasses import replace
5
6
  from typing import TYPE_CHECKING, Any, Generic, TypeVar, overload
@@ -14,7 +15,7 @@ from differt.plotting import PlotOutput, draw_mesh, draw_paths, draw_rays, reuse
14
15
 
15
16
  from ._utils import normalize, orthogonal_basis, rotation_matrix_along_axis
16
17
 
17
- if TYPE_CHECKING:
18
+ if TYPE_CHECKING or "READTHEDOCS" in os.environ:
18
19
  import sys
19
20
 
20
21
  if sys.version_info >= (3, 11):
@@ -278,7 +279,7 @@ class TriangleMesh(eqx.Module):
278
279
 
279
280
  def iter_objects(self) -> Iterator[Self]:
280
281
  """
281
- Iterator over sub meshes (i.e., objects) defined by :attr:`object_bounds`.
282
+ Return an iterator over sub meshes (i.e., objects) defined by :attr:`object_bounds`.
282
283
 
283
284
  If :attr:`object_bounds` is :data:`None`, then yield ``self``.
284
285
 
@@ -802,8 +802,8 @@ def cartesian_to_spherical(
802
802
  xyz = jnp.asarray(xyz)
803
803
  r = jnp.linalg.norm(xyz, axis=-1)
804
804
  r: Array = jnp.where(r == 0.0, jnp.ones_like(r), r)
805
- p = jnp.arccos(xyz[..., -1] / r)
806
- a = jnp.arctan2(xyz[..., 1], xyz[..., 0])
805
+ p = jnp.acos(xyz[..., -1] / r)
806
+ a = jnp.atan2(xyz[..., 1], xyz[..., 0])
807
807
 
808
808
  return jnp.stack((r, p, a), axis=-1)
809
809
 
@@ -544,7 +544,7 @@ def _(
544
544
 
545
545
  xs, ys, zs = np.asarray(markers).reshape(-1, 3).T
546
546
 
547
- ax.scatter(xs, ys, zs=zs, **kwargs)
547
+ ax.scatter(xs, ys, zs=zs, **kwargs) # type: ignore[reportArgumentType]
548
548
 
549
549
  return fig
550
550
 
@@ -0,0 +1,4 @@
1
+ """DiffeRT plugins.
2
+
3
+ Plugins extend the functionality of DiffeRT by providing additional features or integrations with other libraries.
4
+ """
@@ -0,0 +1,9 @@
1
+ __all__ = ("ArrayType",)
2
+
3
+ from typing import TypeVar
4
+
5
+ import numpy as np
6
+ from jaxtyping import Array
7
+
8
+ # NOTE: we declare this is another module to be able to patch it when building the docs
9
+ ArrayType = TypeVar("ArrayType", bound=Array | np.ndarray)