differt 0.3.0__tar.gz → 0.3.1__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.3.0 → differt-0.3.1}/PKG-INFO +3 -3
  2. {differt-0.3.0 → differt-0.3.1}/README.md +1 -1
  3. {differt-0.3.0 → differt-0.3.1}/pyproject.toml +1 -1
  4. {differt-0.3.0 → differt-0.3.1}/src/differt/plugins/deepmimo.py +1 -1
  5. {differt-0.3.0 → differt-0.3.1}/src/differt/scene/_triangle_scene.py +110 -33
  6. {differt-0.3.0 → differt-0.3.1}/.gitignore +0 -0
  7. {differt-0.3.0 → differt-0.3.1}/LICENSE.md +0 -0
  8. {differt-0.3.0 → differt-0.3.1}/src/differt/__init__.py +0 -0
  9. {differt-0.3.0 → differt-0.3.1}/src/differt/_version.py +0 -0
  10. {differt-0.3.0 → differt-0.3.1}/src/differt/em/__init__.py +0 -0
  11. {differt-0.3.0 → differt-0.3.1}/src/differt/em/_antenna.py +0 -0
  12. {differt-0.3.0 → differt-0.3.1}/src/differt/em/_constants.py +0 -0
  13. {differt-0.3.0 → differt-0.3.1}/src/differt/em/_fresnel.py +0 -0
  14. {differt-0.3.0 → differt-0.3.1}/src/differt/em/_interaction_type.py +0 -0
  15. {differt-0.3.0 → differt-0.3.1}/src/differt/em/_material.py +0 -0
  16. {differt-0.3.0 → differt-0.3.1}/src/differt/em/_utd.py +0 -0
  17. {differt-0.3.0 → differt-0.3.1}/src/differt/em/_utils.py +0 -0
  18. {differt-0.3.0 → differt-0.3.1}/src/differt/geometry/__init__.py +0 -0
  19. {differt-0.3.0 → differt-0.3.1}/src/differt/geometry/_paths.py +0 -0
  20. {differt-0.3.0 → differt-0.3.1}/src/differt/geometry/_triangle_mesh.py +0 -0
  21. {differt-0.3.0 → differt-0.3.1}/src/differt/geometry/_utils.py +0 -0
  22. {differt-0.3.0 → differt-0.3.1}/src/differt/plotting/__init__.py +0 -0
  23. {differt-0.3.0 → differt-0.3.1}/src/differt/plotting/_core.py +0 -0
  24. {differt-0.3.0 → differt-0.3.1}/src/differt/plotting/_utils.py +0 -0
  25. {differt-0.3.0 → differt-0.3.1}/src/differt/plugins/__init__.py +0 -0
  26. {differt-0.3.0 → differt-0.3.1}/src/differt/plugins/_deepmimo_types.py +0 -0
  27. {differt-0.3.0 → differt-0.3.1}/src/differt/py.typed +0 -0
  28. {differt-0.3.0 → differt-0.3.1}/src/differt/rt/__init__.py +0 -0
  29. {differt-0.3.0 → differt-0.3.1}/src/differt/rt/_fermat.py +0 -0
  30. {differt-0.3.0 → differt-0.3.1}/src/differt/rt/_image_method.py +0 -0
  31. {differt-0.3.0 → differt-0.3.1}/src/differt/rt/_utils.py +0 -0
  32. {differt-0.3.0 → differt-0.3.1}/src/differt/scene/__init__.py +0 -0
  33. {differt-0.3.0 → differt-0.3.1}/src/differt/scene/_sionna.py +0 -0
  34. {differt-0.3.0 → differt-0.3.1}/src/differt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DiffeRT
3
- Version: 0.3.0
3
+ Version: 0.3.1
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.3.0
24
+ Requires-Dist: differt-core==0.3.1
25
25
  Requires-Dist: equinox>=0.12.2
26
26
  Requires-Dist: filelock>=3.15.4
27
27
  Requires-Dist: jax>=0.4.32
@@ -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.3.0}
143
+ version = {v0.3.1}
144
144
  }
145
145
  ```
146
146
 
@@ -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.3.0}
86
+ version = {v0.3.1}
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.3.0",
19
+ "differt-core==0.3.1",
20
20
  "equinox>=0.12.2",
21
21
  "filelock>=3.15.4",
22
22
  "jax>=0.4.32", # TODO: fixme, issue with pmap
@@ -120,7 +120,7 @@ class DeepMIMO(eqx.Module, Generic[ArrayType]):
120
120
  )
121
121
 
122
122
  if vertices.shape != self.inter_pos.shape: # pragma: no cover
123
- msg = "Cannot sort based on provided paths: shape mismatch, got {vertices.shape!r} but expected {self.inter_pos.shape!r}."
123
+ msg = f"Cannot sort based on provided paths: shape mismatch, got {vertices.shape!r} but expected {self.inter_pos.shape!r}."
124
124
  raise ValueError(msg)
125
125
 
126
126
  max_num_interactions = self.inter.shape[-1]
@@ -1,12 +1,13 @@
1
1
  import math
2
2
  import os
3
3
  import warnings
4
- from collections.abc import Mapping
4
+ from collections.abc import Iterator, Mapping
5
5
  from typing import TYPE_CHECKING, Any, Literal, overload
6
6
 
7
7
  import equinox as eqx
8
8
  import jax
9
9
  import jax.numpy as jnp
10
+ import numpy as np
10
11
  from jax.experimental.shard_map import shard_map
11
12
  from jax.sharding import PartitionSpec as P
12
13
  from jaxtyping import Array, ArrayLike, Bool, Float, Int
@@ -25,14 +26,13 @@ from differt.rt import (
25
26
  SizedIterator,
26
27
  consecutive_vertices_are_on_same_side_of_mirrors,
27
28
  first_triangles_hit_by_rays,
28
- generate_all_path_candidates,
29
- generate_all_path_candidates_chunks_iter,
30
29
  image_method,
31
30
  rays_intersect_any_triangle,
32
31
  rays_intersect_triangles,
33
32
  triangles_visible_from_vertices,
34
33
  )
35
34
  from differt.utils import dot, smoothing_function
35
+ from differt_core.rt import CompleteGraph, DiGraph
36
36
 
37
37
  if TYPE_CHECKING or "READTHEDOCS" in os.environ:
38
38
  import sys
@@ -845,7 +845,7 @@ class TriangleScene(eqx.Module):
845
845
  self,
846
846
  order: int | None = None,
847
847
  *,
848
- method: Literal["exhaustive", "hybrid"] = "exhaustive",
848
+ method: Literal["exhaustive"] = "exhaustive",
849
849
  chunk_size: None = None,
850
850
  num_rays: int = int(1e6),
851
851
  path_candidates: Int[ArrayLike, "num_path_candidates order"] | None = None,
@@ -858,12 +858,30 @@ class TriangleScene(eqx.Module):
858
858
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
859
859
  ) -> Paths: ...
860
860
 
861
+ @overload
862
+ def compute_paths(
863
+ self,
864
+ order: int,
865
+ *,
866
+ method: Literal["hybrid"],
867
+ chunk_size: None = None,
868
+ num_rays: int = int(1e6),
869
+ path_candidates: None = None,
870
+ parallel: bool = False,
871
+ epsilon: Float[ArrayLike, " "] | None = None,
872
+ hit_tol: Float[ArrayLike, " "] | None = None,
873
+ min_len: Float[ArrayLike, " "] | None = None,
874
+ max_dist: Float[ArrayLike, " "] = 1e-3,
875
+ smoothing_factor: Float[ArrayLike, " "] | None = None,
876
+ confidence_threshold: Float[ArrayLike, " "] = 0.5,
877
+ ) -> Paths: ...
878
+
861
879
  @overload
862
880
  def compute_paths(
863
881
  self,
864
882
  order: int | None = None,
865
883
  *,
866
- method: Literal["exhaustive", "hybrid"] = "exhaustive",
884
+ method: Literal["exhaustive"] = "exhaustive",
867
885
  chunk_size: int,
868
886
  num_rays: int = int(1e6),
869
887
  path_candidates: None = None,
@@ -876,6 +894,24 @@ class TriangleScene(eqx.Module):
876
894
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
877
895
  ) -> SizedIterator[Paths]: ...
878
896
 
897
+ @overload
898
+ def compute_paths(
899
+ self,
900
+ order: int,
901
+ *,
902
+ method: Literal["hybrid"],
903
+ chunk_size: int,
904
+ num_rays: int = int(1e6),
905
+ path_candidates: None = None,
906
+ parallel: bool = False,
907
+ epsilon: Float[ArrayLike, " "] | None = None,
908
+ hit_tol: Float[ArrayLike, " "] | None = None,
909
+ min_len: Float[ArrayLike, " "] | None = None,
910
+ max_dist: Float[ArrayLike, " "] = 1e-3,
911
+ smoothing_factor: Float[ArrayLike, " "] | None = None,
912
+ confidence_threshold: Float[ArrayLike, " "] = 0.5,
913
+ ) -> Iterator[Paths]: ...
914
+
879
915
  @overload
880
916
  def compute_paths(
881
917
  self,
@@ -912,7 +948,7 @@ class TriangleScene(eqx.Module):
912
948
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
913
949
  ) -> SBRPaths: ...
914
950
 
915
- def compute_paths( # noqa: C901, PLR0912
951
+ def compute_paths( # noqa: C901, PLR0912, PLR0915
916
952
  self,
917
953
  order: int | None = None,
918
954
  *,
@@ -927,7 +963,7 @@ class TriangleScene(eqx.Module):
927
963
  max_dist: Float[ArrayLike, " "] = 1e-3,
928
964
  smoothing_factor: Float[ArrayLike, " "] | None = None,
929
965
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
930
- ) -> Paths | SizedIterator[Paths] | SBRPaths:
966
+ ) -> Paths | SizedIterator[Paths] | Iterator[Paths] | SBRPaths:
931
967
  """
932
968
  Compute paths between all pairs of transmitters and receivers in the scene, that undergo a fixed number of interaction with objects.
933
969
 
@@ -959,7 +995,7 @@ class TriangleScene(eqx.Module):
959
995
  it is likely to changed in future releases. Use with caution.
960
996
  * If ``'hybrid'``, a hybrid method is used, which estimates the objects
961
997
  visible from all transmitters, to reduce the number of path candidates,
962
- by launching a fixed number of rays, and then performs an extausive
998
+ by launching a fixed number of rays, and then performs an exhaustive
963
999
  search on those path candidates. This is a faster alternative to
964
1000
  ``'exhaustive'``, but still grows exponentially with the number of
965
1001
  bounces or the size of the scene. In the future, we plan on allowing
@@ -967,8 +1003,9 @@ class TriangleScene(eqx.Module):
967
1003
  number of path candidates.
968
1004
 
969
1005
  .. warning::
970
-
971
- The ``'hybrid'`` method is not yet implemented.
1006
+ This method is best used for a single transmitter and a single receiver,
1007
+ as the estimated visibility is merged across all transmitters and receivers,
1008
+ respectively.
972
1009
 
973
1010
  chunk_size: If specified, it will iterate through chunks of path
974
1011
  candidates, and yield the result as an iterator over paths chunks.
@@ -989,7 +1026,7 @@ class TriangleScene(eqx.Module):
989
1026
  rounded down toward the nearest even value (but object indices still refer
990
1027
  to triangle indices, not quadrilateral indices).
991
1028
 
992
- **Not compatible with** ``method == 'sbr'``.
1029
+ **Not compatible with** ``method == 'sbr'`` and ``method == 'hybrid'``.
993
1030
  parallel: If :data:`True`, ray tracing is performed in parallel across all available
994
1031
  devices. The number of transmitters times the number of receivers
995
1032
  **must** be a multiple of :func:`jax.device_count`, otherwise an error is raised.
@@ -1045,7 +1082,7 @@ class TriangleScene(eqx.Module):
1045
1082
  ValueError: If neither ``order`` nor ``path_candidates`` has been provided,
1046
1083
  or if both have been provided simultaneously.
1047
1084
 
1048
- If ``method == 'sbr'``, ``order`` is required.
1085
+ If ``method == 'sbr'`` or ``method == 'hybrid'`, and ``order`` is not provided.
1049
1086
 
1050
1087
  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.
1051
1088
 
@@ -1089,39 +1126,72 @@ class TriangleScene(eqx.Module):
1089
1126
  epsilon=epsilon,
1090
1127
  max_dist=max_dist,
1091
1128
  ).reshape(*tx_batch, *rx_batch, -1)
1092
- if method == "hybrid":
1093
- msg = "Hybrid method not implemented yet."
1094
- raise NotImplementedError(msg) # TODO: implement
1095
- visibility = triangles_visible_from_vertices(
1096
- self.transmitters, self.mesh.triangle_vertices
1097
- )
1098
-
1099
- if self.mesh.assume_quads:
1100
- visibility = visibility.reshape(-1, 2).any(axis=-1)
1101
1129
 
1102
1130
  # 0 - Constants arrays of chunks
1103
- num_objects = (
1104
- self.mesh.num_quads if self.mesh.assume_quads else self.mesh.num_triangles
1105
- )
1131
+ assume_quads = self.mesh.assume_quads
1106
1132
 
1107
1133
  # [tx_batch_flattened 3]
1108
1134
  tx_vertices = self.transmitters.reshape(-1, 3)
1109
1135
  # [rx_batch_flattened 3]
1110
1136
  rx_vertices = self.receivers.reshape(-1, 3)
1111
1137
 
1138
+ graph = CompleteGraph(self.mesh.num_objects)
1139
+
1140
+ if method == "hybrid":
1141
+ if order is None:
1142
+ msg = "Argument 'order' is required when 'method == \"hybrid\"'."
1143
+ raise ValueError(msg)
1144
+
1145
+ triangles_visible_from_tx = triangles_visible_from_vertices(
1146
+ tx_vertices,
1147
+ self.mesh.triangle_vertices,
1148
+ active_triangles=self.mesh.mask,
1149
+ num_rays=num_rays,
1150
+ epsilon=epsilon,
1151
+ ).any(axis=0) # reduce on all transmitters
1152
+
1153
+ triangles_visible_from_rx = triangles_visible_from_vertices(
1154
+ rx_vertices,
1155
+ self.mesh.triangle_vertices,
1156
+ active_triangles=self.mesh.mask,
1157
+ num_rays=num_rays,
1158
+ epsilon=epsilon,
1159
+ ).any(axis=0) # reduce on all receivers
1160
+
1161
+ if assume_quads:
1162
+ triangles_visible_from_tx = triangles_visible_from_tx.reshape(
1163
+ -1, 2
1164
+ ).any(axis=-1) # seeing any triangle of a quad is enough
1165
+ triangles_visible_from_rx = triangles_visible_from_rx.reshape(
1166
+ -1, 2
1167
+ ).any(axis=-1) # seeing any triangle of a quad is enough
1168
+
1169
+ graph = DiGraph.from_complete_graph(graph)
1170
+ from_, to = graph.insert_from_and_to_nodes(
1171
+ from_adjacency=np.asarray(triangles_visible_from_tx),
1172
+ to_adjacency=np.asarray(triangles_visible_from_rx),
1173
+ )
1174
+ else:
1175
+ from_ = graph.num_nodes
1176
+ to = from_ + 1
1177
+
1112
1178
  if chunk_size:
1113
- path_candidates_iter = generate_all_path_candidates_chunks_iter(
1114
- num_objects,
1115
- order, # type: ignore[reportArgumentType]
1179
+ path_candidates_iter = graph.all_paths_array_chunks(
1180
+ from_=from_,
1181
+ to=to,
1182
+ depth=order + 2, # type: ignore[reportOptionalOperand]
1183
+ include_from_and_to=False,
1116
1184
  chunk_size=chunk_size,
1117
1185
  )
1118
- size = path_candidates_iter.__len__
1119
1186
  it = (
1120
1187
  _compute_paths(
1121
1188
  self.mesh,
1122
1189
  tx_vertices,
1123
1190
  rx_vertices,
1124
- 2 * path_candidates if self.mesh.assume_quads else path_candidates,
1191
+ jnp.asarray(
1192
+ 2 * path_candidates if assume_quads else path_candidates,
1193
+ dtype=int,
1194
+ ),
1125
1195
  parallel=parallel,
1126
1196
  epsilon=epsilon,
1127
1197
  hit_tol=hit_tol,
@@ -1132,12 +1202,19 @@ class TriangleScene(eqx.Module):
1132
1202
  for path_candidates in path_candidates_iter
1133
1203
  )
1134
1204
 
1135
- return SizedIterator(it, size=size)
1205
+ if hasattr(path_candidates_iter, "__len__"):
1206
+ return SizedIterator(it, size=path_candidates_iter.__len__)
1207
+ return it
1136
1208
 
1137
1209
  if path_candidates is None:
1138
- path_candidates = generate_all_path_candidates(
1139
- num_objects,
1140
- order,
1210
+ path_candidates = jnp.asarray(
1211
+ graph.all_paths_array(
1212
+ from_=from_,
1213
+ to=to,
1214
+ depth=order + 2, # type: ignore[reportOptionalOperand]
1215
+ include_from_and_to=False,
1216
+ ),
1217
+ dtype=int,
1141
1218
  )
1142
1219
 
1143
1220
  if self.mesh.assume_quads:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes