differt 0.3.1__tar.gz → 0.4.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.3.1 → differt-0.4.0}/PKG-INFO +3 -3
  2. {differt-0.3.1 → differt-0.4.0}/README.md +1 -1
  3. {differt-0.3.1 → differt-0.4.0}/pyproject.toml +1 -1
  4. {differt-0.3.1 → differt-0.4.0}/src/differt/geometry/_triangle_mesh.py +61 -24
  5. {differt-0.3.1 → differt-0.4.0}/src/differt/scene/_triangle_scene.py +4 -4
  6. {differt-0.3.1 → differt-0.4.0}/.gitignore +0 -0
  7. {differt-0.3.1 → differt-0.4.0}/LICENSE.md +0 -0
  8. {differt-0.3.1 → differt-0.4.0}/src/differt/__init__.py +0 -0
  9. {differt-0.3.1 → differt-0.4.0}/src/differt/_version.py +0 -0
  10. {differt-0.3.1 → differt-0.4.0}/src/differt/em/__init__.py +0 -0
  11. {differt-0.3.1 → differt-0.4.0}/src/differt/em/_antenna.py +0 -0
  12. {differt-0.3.1 → differt-0.4.0}/src/differt/em/_constants.py +0 -0
  13. {differt-0.3.1 → differt-0.4.0}/src/differt/em/_fresnel.py +0 -0
  14. {differt-0.3.1 → differt-0.4.0}/src/differt/em/_interaction_type.py +0 -0
  15. {differt-0.3.1 → differt-0.4.0}/src/differt/em/_material.py +0 -0
  16. {differt-0.3.1 → differt-0.4.0}/src/differt/em/_utd.py +0 -0
  17. {differt-0.3.1 → differt-0.4.0}/src/differt/em/_utils.py +0 -0
  18. {differt-0.3.1 → differt-0.4.0}/src/differt/geometry/__init__.py +0 -0
  19. {differt-0.3.1 → differt-0.4.0}/src/differt/geometry/_paths.py +0 -0
  20. {differt-0.3.1 → differt-0.4.0}/src/differt/geometry/_utils.py +0 -0
  21. {differt-0.3.1 → differt-0.4.0}/src/differt/plotting/__init__.py +0 -0
  22. {differt-0.3.1 → differt-0.4.0}/src/differt/plotting/_core.py +0 -0
  23. {differt-0.3.1 → differt-0.4.0}/src/differt/plotting/_utils.py +0 -0
  24. {differt-0.3.1 → differt-0.4.0}/src/differt/plugins/__init__.py +0 -0
  25. {differt-0.3.1 → differt-0.4.0}/src/differt/plugins/_deepmimo_types.py +0 -0
  26. {differt-0.3.1 → differt-0.4.0}/src/differt/plugins/deepmimo.py +0 -0
  27. {differt-0.3.1 → differt-0.4.0}/src/differt/py.typed +0 -0
  28. {differt-0.3.1 → differt-0.4.0}/src/differt/rt/__init__.py +0 -0
  29. {differt-0.3.1 → differt-0.4.0}/src/differt/rt/_fermat.py +0 -0
  30. {differt-0.3.1 → differt-0.4.0}/src/differt/rt/_image_method.py +0 -0
  31. {differt-0.3.1 → differt-0.4.0}/src/differt/rt/_utils.py +0 -0
  32. {differt-0.3.1 → differt-0.4.0}/src/differt/scene/__init__.py +0 -0
  33. {differt-0.3.1 → differt-0.4.0}/src/differt/scene/_sionna.py +0 -0
  34. {differt-0.3.1 → differt-0.4.0}/src/differt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DiffeRT
3
- Version: 0.3.1
3
+ Version: 0.4.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.3.1
24
+ Requires-Dist: differt-core==0.4.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
@@ -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.1}
143
+ version = {v0.4.0}
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.1}
86
+ version = {v0.4.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.3.1",
19
+ "differt-core==0.4.0",
20
20
  "equinox>=0.12.2",
21
21
  "filelock>=3.15.4",
22
22
  "jax>=0.4.32", # TODO: fixme, issue with pmap
@@ -213,7 +213,7 @@ class TriangleMesh(eqx.Module):
213
213
  converter=tuple, default_factory=tuple, static=True
214
214
  )
215
215
  """The list of material names (must be unique)."""
216
- object_bounds: Int[Array, "num_objects 2"] | None = eqx.field(
216
+ object_bounds: Int[Array, "num_primitives 2"] | None = eqx.field(
217
217
  converter=lambda x: jnp.asarray(x) if x is not None else None, default=None
218
218
  )
219
219
  """The array of object indices.
@@ -350,10 +350,10 @@ class TriangleMesh(eqx.Module):
350
350
  return self.triangles.shape[0] // 2
351
351
 
352
352
  @property
353
- def num_objects(self) -> int:
354
- """The number of objects.
353
+ def num_primitives(self) -> int:
354
+ """The number of primitives.
355
355
 
356
- This is a convenient alias to :attr:`num_quads` :attr:`assume_quads` is :data:`True`
356
+ This is a convenient alias to :attr:`num_quads` if :attr:`assume_quads` is :data:`True`
357
357
  else :attr:`num_triangles`.
358
358
  """
359
359
  return self.num_quads if self.assume_quads else self.num_triangles
@@ -662,7 +662,7 @@ class TriangleMesh(eqx.Module):
662
662
  """
663
663
  return cls(vertices=jnp.empty((0, 3)), triangles=jnp.empty((0, 3), dtype=int))
664
664
 
665
- def append(self, other: "TriangleMesh") -> Self: # noqa: C901, PLR0912
665
+ def append(self, other: "TriangleMesh") -> Self:
666
666
  """
667
667
  Return a new mesh by appending another mesh to this one.
668
668
 
@@ -1061,7 +1061,7 @@ class TriangleMesh(eqx.Module):
1061
1061
  )
1062
1062
  elif self.assume_quads:
1063
1063
  quad_colors = jax.random.uniform(key, (self.num_quads, 3))
1064
- repeats = jnp.full(self.num_objects, 2)
1064
+ repeats = jnp.full(self.num_primitives, 2)
1065
1065
  colors = jnp.repeat(
1066
1066
  quad_colors, repeats, axis=0, total_repeat_length=self.num_triangles
1067
1067
  )
@@ -1095,11 +1095,11 @@ class TriangleMesh(eqx.Module):
1095
1095
  A new mesh with updated face materials.
1096
1096
 
1097
1097
  Raises:
1098
- ValueError: If the number of names is not 1, :attr:`num_triangles`, or :attr:`num_objects` (if :attr:`assume_quads` is set to :data:`True`).
1098
+ ValueError: If the number of names is not 1, :attr:`num_triangles`, or :attr:`num_primitives` (if :attr:`assume_quads` is set to :data:`True`).
1099
1099
  """
1100
- if len(names) not in {1, self.num_triangles, self.num_objects}:
1100
+ if len(names) not in {1, self.num_triangles, self.num_primitives}:
1101
1101
  if self.assume_quads:
1102
- msg = f"Expected either 1, {self.num_triangles}, or {self.num_objects} names, got {len(names)}."
1102
+ msg = f"Expected either 1, {self.num_triangles}, or {self.num_primitives} names, got {len(names)}."
1103
1103
  else:
1104
1104
  msg = f"Expected either 1, or {self.num_triangles} names, got {len(names)}."
1105
1105
  raise ValueError(msg)
@@ -1518,20 +1518,23 @@ class TriangleMesh(eqx.Module):
1518
1518
  preserve: bool = False,
1519
1519
  *,
1520
1520
  by_masking: bool = False,
1521
+ sample_objects: bool = False,
1521
1522
  key: PRNGKeyArray,
1522
1523
  ) -> Self:
1523
1524
  """
1524
- Generate a new mesh by randomly sampling triangles from this geometry.
1525
+ Generate a new mesh by randomly sampling primitives from this geometry.
1525
1526
 
1526
- Warning:
1527
- If :attr:`assume_quads` is :data:`True`, then quadrilaterals are
1528
- sampled.
1527
+ Important:
1528
+ If ``by_masking`` is set to :data:`True`, then this function is compatible
1529
+ with :func:`jax.jit`. Conversely, if ``by_masking`` is set to :data:`False`,
1530
+ then this function is **not** compatible with :func:`jax.jit`,
1531
+ as the size of the output mesh is not known at compile time.
1529
1532
 
1530
1533
  Args:
1531
- size: The size of the sample, i.e., the number of triangles.
1534
+ size: The size of the sample, i.e., the number of primitives (or objects, if ``sample_objects`` is :data:`True`).
1532
1535
 
1533
1536
  If a floating point number is provided, it is interpreted as a fill factor,
1534
- i.e., the fraction of triangles to sample from the mesh. This is only supported
1537
+ i.e., the fraction of primitives to sample from the mesh. This is only supported
1535
1538
  if ``by_masking`` is set to :data:`True`.
1536
1539
  replace: Whether to sample with or without replacement.
1537
1540
 
@@ -1546,8 +1549,11 @@ class TriangleMesh(eqx.Module):
1546
1549
  is :data:`None`.
1547
1550
 
1548
1551
  Cannot be used with ``by_masking`` set to :data:`True`.
1549
- by_masking: Whether to sample by masking the triangles.
1552
+ by_masking: Whether to sample by masking the primitives.
1550
1553
  If :data:`True`, then the :attr:`mask` attribute set (ignoring any existing mask).
1554
+ sample_objects: Whether to sample by objects, i.e., sampling whole objects at once.
1555
+ The value of ``size`` is interpreted as the number of objects to sample,
1556
+ or the fill factor of objects to sample.
1551
1557
  key: The :func:`jax.random.key` to be used.
1552
1558
 
1553
1559
  Returns:
@@ -1556,35 +1562,56 @@ class TriangleMesh(eqx.Module):
1556
1562
  Raises:
1557
1563
  TypeError: If ``by_masking`` is :data:`False` and ``size`` is not an integer.
1558
1564
  ValueError: If ``by_masking`` is :data:`True` and ``replace`` or ``preserve`` are set to :data:`True`.
1565
+ ValueError: If ``sample_objects`` is :data:`True` and :attr:`object_bounds` is :data:`None`.
1559
1566
  """
1567
+ if sample_objects:
1568
+ if self.object_bounds is None:
1569
+ msg = "Cannot sample by objects when 'object_bounds' is None."
1570
+ raise ValueError(msg)
1571
+ num = self.object_bounds.shape[0]
1572
+ else:
1573
+ num = self.num_primitives
1560
1574
  if by_masking:
1561
1575
  if replace:
1562
1576
  msg = "Cannot sample with replacement when 'by_masking' is True."
1563
1577
  raise ValueError(msg)
1564
- if preserve:
1565
- msg = "Cannot preserve 'object_bounds' when 'by_masking' is True."
1578
+ if preserve and not sample_objects:
1579
+ msg = "Cannot preserve 'object_bounds' when 'by_masking' is True and 'sample_objects' is False."
1566
1580
  raise ValueError(msg)
1567
1581
  if isinstance(size, int):
1568
- mask = jnp.zeros(self.num_objects, dtype=bool)
1582
+ mask = jnp.zeros(num, dtype=bool)
1569
1583
  mask = mask.at[:size].set(True)
1570
1584
  mask = jax.random.permutation(key, mask)
1571
1585
  else:
1572
- mask = jax.random.uniform(key, (self.num_objects,)) <= size
1573
-
1574
- if self.assume_quads:
1586
+ mask = jax.random.uniform(key, (num,)) <= size
1587
+
1588
+ if sample_objects:
1589
+ indices = jnp.arange(self.num_triangles)
1590
+ indices_inside_bounds = (
1591
+ self.object_bounds[:, 0] <= indices[:, None] # type: ignore[reportOptionalSubscript]
1592
+ ) & (indices[:, None] < self.object_bounds[:, 1]) # type: ignore[reportOptionalSubscript]
1593
+ triangle_indices = indices_inside_bounds.argmax(
1594
+ axis=1
1595
+ ) # Exactly one bound should be true for each triangle
1596
+ mask = jnp.take(
1597
+ mask,
1598
+ triangle_indices,
1599
+ indices_are_sorted=True, # Object bounds are sorted
1600
+ )
1601
+ elif self.assume_quads:
1575
1602
  mask = jnp.repeat(mask, 2)
1576
1603
 
1577
1604
  return eqx.tree_at(
1578
1605
  lambda m: (m.object_bounds, m.mask),
1579
1606
  self,
1580
- (None, mask),
1607
+ (self.object_bounds if preserve else None, mask),
1581
1608
  is_leaf=lambda x: x is None,
1582
1609
  )
1583
1610
 
1584
1611
  if isinstance(size, int):
1585
1612
  indices = jax.random.choice(
1586
1613
  key,
1587
- self.num_objects,
1614
+ num,
1588
1615
  shape=(size,),
1589
1616
  replace=replace,
1590
1617
  )
@@ -1592,6 +1619,11 @@ class TriangleMesh(eqx.Module):
1592
1619
  msg = "'size' must be an integer when 'by_masking' is False."
1593
1620
  raise TypeError(msg)
1594
1621
 
1622
+ if sample_objects:
1623
+ indices = jnp.concatenate([
1624
+ jnp.arange(self.object_bounds[i, 0], self.object_bounds[i, 1]) # type: ignore[reportOptionalSubscript]
1625
+ for i in indices
1626
+ ])
1595
1627
  if self.assume_quads:
1596
1628
  indices *= 2
1597
1629
 
@@ -1604,6 +1636,11 @@ class TriangleMesh(eqx.Module):
1604
1636
  ),
1605
1637
  axis=-1,
1606
1638
  )
1639
+ # Some object may not have any triangles left after sampling,
1640
+ # so we remove them.
1641
+ object_bounds = object_bounds.compress(
1642
+ object_bounds[:, 0] < object_bounds[:, 1], axis=0
1643
+ )
1607
1644
  else:
1608
1645
  object_bounds = None
1609
1646
 
@@ -52,7 +52,7 @@ else:
52
52
 
53
53
 
54
54
  @eqx.filter_jit
55
- def _compute_paths( # noqa: C901, PLR0915
55
+ def _compute_paths( # noqa: PLR0915
56
56
  mesh: TriangleMesh,
57
57
  tx_vertices: Float[Array, "num_tx_vertices 3"],
58
58
  rx_vertices: Float[Array, "num_rx_vertices 3"],
@@ -117,7 +117,7 @@ def _compute_paths( # noqa: C901, PLR0915
117
117
  # [num_path_candidates order 3]
118
118
  mirror_normals = jnp.take(mesh.normals, path_candidates, axis=0)
119
119
 
120
- def fun( # noqa: PLR0912
120
+ def fun(
121
121
  tx_vertices: Float[Array, "num_tx_vertices 3"],
122
122
  rx_vertices: Float[Array, "num_rx_vertices 3"],
123
123
  ) -> tuple[
@@ -948,7 +948,7 @@ class TriangleScene(eqx.Module):
948
948
  confidence_threshold: Float[ArrayLike, " "] = 0.5,
949
949
  ) -> SBRPaths: ...
950
950
 
951
- def compute_paths( # noqa: C901, PLR0912, PLR0915
951
+ def compute_paths( # noqa: PLR0915
952
952
  self,
953
953
  order: int | None = None,
954
954
  *,
@@ -1135,7 +1135,7 @@ class TriangleScene(eqx.Module):
1135
1135
  # [rx_batch_flattened 3]
1136
1136
  rx_vertices = self.receivers.reshape(-1, 3)
1137
1137
 
1138
- graph = CompleteGraph(self.mesh.num_objects)
1138
+ graph = CompleteGraph(self.mesh.num_primitives)
1139
1139
 
1140
1140
  if method == "hybrid":
1141
1141
  if order is None:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes