differt 0.6.0__tar.gz → 0.6.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.6.0 → differt-0.6.2}/PKG-INFO +8 -7
  2. {differt-0.6.0 → differt-0.6.2}/README.md +1 -1
  3. {differt-0.6.0 → differt-0.6.2}/pyproject.toml +6 -5
  4. {differt-0.6.0 → differt-0.6.2}/src/differt/em/_antenna.py +1 -1
  5. {differt-0.6.0 → differt-0.6.2}/src/differt/em/_utd.py +1 -0
  6. {differt-0.6.0 → differt-0.6.2}/src/differt/em/_utils.py +2 -13
  7. {differt-0.6.0 → differt-0.6.2}/src/differt/geometry/_utils.py +2 -6
  8. {differt-0.6.0 → differt-0.6.2}/src/differt/plotting/_core.py +6 -1
  9. {differt-0.6.0 → differt-0.6.2}/src/differt/plotting/_utils.py +1 -1
  10. {differt-0.6.0 → differt-0.6.2}/src/differt/plugins/_deepmimo_types.py +1 -1
  11. {differt-0.6.0 → differt-0.6.2}/src/differt/plugins/deepmimo.py +1 -1
  12. {differt-0.6.0 → differt-0.6.2}/src/differt/rt/_fermat.py +33 -93
  13. {differt-0.6.0 → differt-0.6.2}/src/differt/rt/_utils.py +3 -1
  14. {differt-0.6.0 → differt-0.6.2}/src/differt/scene/_triangle_scene.py +2 -0
  15. {differt-0.6.0 → differt-0.6.2}/.gitignore +0 -0
  16. {differt-0.6.0 → differt-0.6.2}/LICENSE.md +0 -0
  17. {differt-0.6.0 → differt-0.6.2}/src/differt/__init__.py +0 -0
  18. {differt-0.6.0 → differt-0.6.2}/src/differt/_version.py +0 -0
  19. {differt-0.6.0 → differt-0.6.2}/src/differt/em/__init__.py +0 -0
  20. {differt-0.6.0 → differt-0.6.2}/src/differt/em/_constants.py +0 -0
  21. {differt-0.6.0 → differt-0.6.2}/src/differt/em/_fresnel.py +0 -0
  22. {differt-0.6.0 → differt-0.6.2}/src/differt/em/_interaction_type.py +0 -0
  23. {differt-0.6.0 → differt-0.6.2}/src/differt/em/_material.py +0 -0
  24. {differt-0.6.0 → differt-0.6.2}/src/differt/geometry/__init__.py +0 -0
  25. {differt-0.6.0 → differt-0.6.2}/src/differt/geometry/_paths.py +0 -0
  26. {differt-0.6.0 → differt-0.6.2}/src/differt/geometry/_triangle_mesh.py +0 -0
  27. {differt-0.6.0 → differt-0.6.2}/src/differt/plotting/__init__.py +0 -0
  28. {differt-0.6.0 → differt-0.6.2}/src/differt/plugins/__init__.py +0 -0
  29. {differt-0.6.0 → differt-0.6.2}/src/differt/py.typed +0 -0
  30. {differt-0.6.0 → differt-0.6.2}/src/differt/rt/__init__.py +0 -0
  31. {differt-0.6.0 → differt-0.6.2}/src/differt/rt/_image_method.py +0 -0
  32. {differt-0.6.0 → differt-0.6.2}/src/differt/scene/__init__.py +0 -0
  33. {differt-0.6.0 → differt-0.6.2}/src/differt/scene/_sionna.py +0 -0
  34. {differt-0.6.0 → differt-0.6.2}/src/differt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DiffeRT
3
- Version: 0.6.0
3
+ Version: 0.6.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
@@ -11,22 +11,23 @@ Author-email: Jérome Eertmans <jeertmans@icloud.com>
11
11
  License-Expression: MIT
12
12
  License-File: LICENSE.md
13
13
  Keywords: differentiable,jax,propagation,radio,ray tracing
14
- Classifier: License :: OSI Approved :: MIT License
15
14
  Classifier: Operating System :: OS Independent
16
15
  Classifier: Programming Language :: Python :: 3
17
16
  Classifier: Programming Language :: Python :: 3.11
18
17
  Classifier: Programming Language :: Python :: 3.12
19
18
  Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: Free Threading
20
21
  Classifier: Topic :: Scientific/Engineering
21
22
  Requires-Python: >=3.11
22
23
  Requires-Dist: chex>=0.1.86
23
- Requires-Dist: differt-core==0.6.0
24
- Requires-Dist: equinox>=0.12.2
24
+ Requires-Dist: differt-core==0.6.2
25
+ Requires-Dist: equinox>=0.13.1
25
26
  Requires-Dist: filelock>=3.15.4
26
- Requires-Dist: jax>=0.7.0
27
+ Requires-Dist: fpt-jax==0.1.0
28
+ Requires-Dist: jax>=0.7.2
27
29
  Requires-Dist: jaxtyping>=0.3.2
28
30
  Requires-Dist: numpy>=1.26.1
29
- Requires-Dist: optax>=0.1.7
30
31
  Requires-Dist: requests>=2.32.0
31
32
  Requires-Dist: tqdm>=4.66.2
32
33
  Provides-Extra: all
@@ -140,7 +141,7 @@ If you use this software, please cite it as:
140
141
  author = {Eertmans, Jérome},
141
142
  url = {https://github.com/jeertmans/DiffeRT},
142
143
  license = {MIT},
143
- version = {v0.6.0}
144
+ version = {v0.6.2}
144
145
  }
145
146
  ```
146
147
 
@@ -85,7 +85,7 @@ If you use this software, please cite it as:
85
85
  author = {Eertmans, Jérome},
86
86
  url = {https://github.com/jeertmans/DiffeRT},
87
87
  license = {MIT},
88
- version = {v0.6.0}
88
+ version = {v0.6.2}
89
89
  }
90
90
  ```
91
91
 
@@ -9,19 +9,20 @@ classifiers = [
9
9
  "Programming Language :: Python :: 3.11",
10
10
  "Programming Language :: Python :: 3.12",
11
11
  "Programming Language :: Python :: 3.13",
12
- "License :: OSI Approved :: MIT License",
12
+ "Programming Language :: Python :: 3.14",
13
+ "Programming Language :: Python :: Free Threading",
13
14
  "Operating System :: OS Independent",
14
15
  "Topic :: Scientific/Engineering",
15
16
  ]
16
17
  dependencies = [
17
18
  "chex>=0.1.86",
18
- "differt-core==0.6.0",
19
- "equinox>=0.12.2",
19
+ "differt-core==0.6.2",
20
+ "equinox>=0.13.1",
20
21
  "filelock>=3.15.4",
21
- "jax>=0.7.0",
22
+ "fpt-jax==0.1.0",
23
+ "jax>=0.7.2",
22
24
  "jaxtyping>=0.3.2",
23
25
  "numpy>=1.26.1",
24
- "optax>=0.1.7",
25
26
  "requests>=2.32.0",
26
27
  "tqdm>=4.66.2",
27
28
  ]
@@ -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)
648
+ s = self.poynting_vector(r) # type: ignore[reportAttributeAccessIssue]
649
649
 
650
650
  p = jnp.linalg.norm(s, axis=-1, keepdims=True)
651
651
 
@@ -1,4 +1,5 @@
1
1
  # ruff: noqa: N802, N806
2
+ # type: ignore # noqa: PGH003
2
3
  from functools import partial
3
4
  from typing import Any, Literal, overload
4
5
 
@@ -311,23 +311,12 @@ def transition_matrices(
311
311
  interaction_types: Int[ArrayLike, "*batch path_length-2"],
312
312
  object_normals: Float[ArrayLike, "*batch path_length 3"],
313
313
  ) -> Float[Array, "*batch 2 2"]:
314
- # ruff: noqa: D417, DOC202
315
314
  """
316
315
  Compute the transition matrix, ...
317
316
 
318
- Args:
319
- k_i: The array of propagation direction of incident fields.
320
-
321
- Each vector must have a unit length.
322
- k_r: The array of propagation direction of reflected fields.
323
-
324
- Each vector must have a unit length.
325
- normals: The array of local normals.
326
-
327
- Each vector must have a unit length.
317
+ .. warning::
328
318
 
329
- Returns:
330
- The array of s and p directions, before and after reflection.
319
+ Do not use this function yet, it is not implemented!
331
320
  """
332
321
  vertices = jnp.asarray(vertices)
333
322
  objects = jnp.asarray(objects)
@@ -72,8 +72,9 @@ def normalize(
72
72
  """
73
73
  vectors = jnp.asarray(vectors)
74
74
  lengths = jnp.linalg.norm(vectors, axis=-1, keepdims=True)
75
+ lengths_no_zero: Array = jnp.where(lengths == 0.0, jnp.ones_like(lengths), lengths) # type: ignore[reportAssignmentType]
75
76
 
76
- return vectors / jnp.where(lengths == 0.0, jnp.ones_like(lengths), lengths), (
77
+ return vectors / lengths_no_zero, (
77
78
  lengths if keepdims else jnp.squeeze(lengths, axis=-1)
78
79
  )
79
80
 
@@ -390,11 +391,6 @@ def fibonacci_lattice(
390
391
  Args:
391
392
  n: The size of the lattice.
392
393
  dtype: The float dtype of the vertices.
393
- grid: Whether to return a grid of shape ``{n} {n} 3``
394
- instead. This is mainly useful if you need to plot
395
- a surface that is generated from a lattice.
396
-
397
- Unused if ``frustum`` is passed.
398
394
  frustum: The spatial region where to sample points.
399
395
 
400
396
  The frustum in an array of min. and max. values for
@@ -555,7 +555,12 @@ def _(
555
555
 
556
556
  xs, ys, zs = np.asarray(markers).reshape(-1, 3).T
557
557
 
558
- ax.scatter(xs, ys, zs=zs, **kwargs)
558
+ ax.scatter(
559
+ xs,
560
+ ys,
561
+ zs=zs, # type: ignore[reportArgumentType]
562
+ **kwargs,
563
+ )
559
564
 
560
565
  return fig
561
566
 
@@ -573,7 +573,7 @@ def process_matplotlib_kwargs(
573
573
  return None
574
574
 
575
575
  def new_ax3d() -> Axes3D:
576
- return figure.add_subplot(projection="3d") # type: ignore[reportReturnType]
576
+ return figure.add_subplot(projection="3d")
577
577
 
578
578
  ax = maybe_ax or current_ax3d() or new_ax3d()
579
579
 
@@ -8,5 +8,5 @@ from jaxtyping import Array
8
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
- bound=Array | np.ndarray, # type: ignore[reportMissingTypeArgument]
11
+ bound=Array | np.ndarray,
12
12
  )
@@ -171,7 +171,7 @@ class DeepMIMO(eqx.Module, Generic[ArrayType]):
171
171
  """
172
172
  return jax.tree.map(jnp.asarray, self)
173
173
 
174
- def numpy(self) -> "DeepMIMO[np.ndarray]": # type: ignore[reportMissingTypeArgument]
174
+ def numpy(self) -> "DeepMIMO[np.ndarray]":
175
175
  """
176
176
  Return a new instance of this class with arrays converted to NumPy arrays.
177
177
 
@@ -1,88 +1,13 @@
1
- from typing import Any, no_type_check
1
+ from typing import Any
2
2
 
3
- import chex
4
3
  import equinox as eqx
5
- import jax
4
+ import fpt_jax
6
5
  import jax.numpy as jnp
7
- import optax
8
6
  from jaxtyping import Array, ArrayLike, Float
9
7
 
10
8
  from differt.geometry import orthogonal_basis
11
9
 
12
10
 
13
- def _param_to_xyz(
14
- p: Float[Array, "*batch num_object_x_num_dims"],
15
- o: Float[Array, "*#batch num_objects 3"],
16
- v: Float[Array, "*#batch num_objects num_dims 3"],
17
- ) -> Float[Array, "*batch num_objects 3"]:
18
- *_, num_objects, num_dims, _ = v.shape
19
- p = jnp.reshape(p, (*p.shape[:-1], num_objects, num_dims, 1))
20
- return o + jnp.sum(p * v, axis=-2)
21
-
22
-
23
- def _loss(
24
- p: Float[Array, "*batch num_object_x_num_dims"],
25
- from_: Float[Array, "*#batch 3"],
26
- to: Float[Array, "*#batch 3"],
27
- o: Float[Array, "*#batch num_objects 3"],
28
- v: Float[Array, "*#batch num_objects num_dims 3"],
29
- ) -> Float[Array, " *batch"]:
30
- chex.assert_axis_dimension_gt(p, -1, 0, exception_type=TypeError)
31
- chex.assert_axis_dimension(
32
- p, -1, v.shape[-2] * v.shape[-3], exception_type=TypeError
33
- )
34
- xyz = _param_to_xyz(p, o, v)
35
- first_segment = xyz[..., 0, :] - from_
36
- last_segment = to - xyz[..., -1, :]
37
- other_segments = jnp.diff(xyz, axis=-2)
38
- return (
39
- jnp.linalg.norm(first_segment, axis=-1)
40
- + jnp.linalg.norm(last_segment, axis=-1)
41
- + jnp.sum(jnp.linalg.norm(other_segments, axis=-1), axis=-1)
42
- )
43
-
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
-
86
11
  @eqx.filter_jit
87
12
  def fermat_path_on_linear_objects(
88
13
  from_vertices: Float[ArrayLike, "*#batch 3"],
@@ -91,7 +16,10 @@ def fermat_path_on_linear_objects(
91
16
  object_vectors: Float[ArrayLike, "*#batch num_objects num_dims 3"],
92
17
  *,
93
18
  steps: int = 10,
94
- optimizer: optax.GradientTransformationExtraArgs | None = None,
19
+ unroll: int | bool = 1,
20
+ linesearch_steps: int = 1,
21
+ unroll_linesearch: int | bool = 1,
22
+ implicit_diff: bool = True,
95
23
  ) -> Float[Array, "*batch num_objects 3"]:
96
24
  """
97
25
  Return the ray paths between pairs of vertices, that reflect or diffract on a given list of objects in between.
@@ -112,6 +40,14 @@ def fermat_path_on_linear_objects(
112
40
  :func:`image method<differt.rt.image_method>`, choosing an appropriate origin can be important
113
41
  as it will be used as the initial point of the minimization procedure.
114
42
 
43
+ .. important::
44
+
45
+ The current implementation uses the ``fpt-jax`` library
46
+ :cite:`fpt-eucap2026`, which defines :class:`jax.custom_vjp` functions for more
47
+ efficient gradient computations, see the paper for more details. The implementation
48
+ is not guaranteed to converge for all configurations of vertices and objects,
49
+ and the user may need to tune the number of steps to achieve convergence.
50
+
115
51
  Args:
116
52
  from_vertices: An array of ``from`` vertices, i.e., vertices from which the
117
53
  ray paths start. In a radio communications context, this is usually
@@ -124,14 +60,14 @@ def fermat_path_on_linear_objects(
124
60
  It is used as the initial guess of the minimization procedure.
125
61
  object_vectors: An array of base vectors describing the objects.
126
62
  steps: The number of optimization steps to perform.
127
- optimizer: The optimizer to use. If not provided,
128
- uses :func:`optax.lbfgs`.
129
-
130
- .. important::
131
-
132
- The optimizer should store the gradient in the state. In the future,
133
- we hope to support optimizers that do not store the gradient in the state,
134
- such as :func:`optax.adam` or :func:`optax.sgd`.
63
+ unroll: Whether to unroll the optimization loop. Can be a boolean or an integer
64
+ specifying the number of iterations to unroll, see :func:`jax.lax.scan`.
65
+ linesearch_steps: The number of line search steps to perform at each iteration.
66
+ unroll_linesearch: Whether to unroll the line search loop. Can be a boolean or an integer
67
+ specifying the number of iterations to unroll, see :func:`jax.lax.scan`.
68
+ implicit_diff: Whether to use implicit differentiation for computing the gradient.
69
+ See :cite:`fpt-eucap2026` and its
70
+ `GitHub page <https://github.com/jeertmans/fpt-jax/tree/v0.1.0>`_ for more details.
135
71
 
136
72
  Returns:
137
73
  An array of ray paths obtained based on Fermat's principle.
@@ -232,13 +168,17 @@ def fermat_path_on_linear_objects(
232
168
  return jnp.empty((*batch, 0, 3), dtype=dtype)
233
169
  return jnp.broadcast_to(object_origins, (*batch, num_objects, 3)).astype(dtype)
234
170
 
235
- optimizer = optimizer if optimizer is not None else optax.lbfgs()
236
-
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)
171
+ return fpt_jax.trace_rays(
172
+ from_vertices,
173
+ to_vertices,
174
+ object_origins,
175
+ object_vectors,
176
+ num_iters=steps,
177
+ unroll=unroll,
178
+ num_iters_linesearch=linesearch_steps,
179
+ unroll_linesearch=unroll_linesearch,
180
+ implicit_diff=implicit_diff,
181
+ )
242
182
 
243
183
 
244
184
  @eqx.filter_jit
@@ -278,6 +278,8 @@ def rays_intersect_triangles(
278
278
  dtype = jnp.result_type(ray_origins, ray_directions, triangle_vertices)
279
279
  epsilon = 10 * jnp.finfo(dtype).eps
280
280
 
281
+ epsilon = jnp.asarray(epsilon)
282
+
281
283
  # [*batch 3]
282
284
  vertex_0 = triangle_vertices[..., 0, :]
283
285
  vertex_1 = triangle_vertices[..., 1, :]
@@ -292,7 +294,7 @@ def rays_intersect_triangles(
292
294
 
293
295
  # [*batch]
294
296
  a = jnp.sum(h * edge_1, axis=-1)
295
- a = jnp.where(a == 0.0, jnp.inf, a) # Avoid division by zero
297
+ a: Array = jnp.where(a == 0.0, jnp.inf, a) # Avoid division by zero
296
298
 
297
299
  if smoothing_factor is not None:
298
300
  hit = smoothing_function(jnp.abs(a) - epsilon, smoothing_factor)
@@ -62,6 +62,8 @@ def _compute_paths(
62
62
  dtype = jnp.result_type(mesh.vertices, tx_vertices, tx_vertices)
63
63
  min_len = 10 * jnp.finfo(dtype).eps
64
64
 
65
+ min_len = jnp.asarray(min_len)
66
+
65
67
  # 1 - Broadcast arrays
66
68
 
67
69
  num_tx_vertices = tx_vertices.shape[0]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes