differt 0.0.26__tar.gz → 0.0.28__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.
- {differt-0.0.26 → differt-0.0.28}/PKG-INFO +3 -2
- {differt-0.0.26 → differt-0.0.28}/pyproject.toml +2 -1
- {differt-0.0.26 → differt-0.0.28}/src/differt/geometry/_paths.py +2 -2
- {differt-0.0.26 → differt-0.0.28}/src/differt/geometry/_utils.py +11 -15
- {differt-0.0.26 → differt-0.0.28}/src/differt/plotting/_core.py +128 -13
- {differt-0.0.26 → differt-0.0.28}/src/differt/rt/_fermat.py +37 -31
- {differt-0.0.26 → differt-0.0.28}/src/differt/rt/_image_method.py +7 -3
- {differt-0.0.26 → differt-0.0.28}/src/differt/rt/_utils.py +5 -3
- {differt-0.0.26 → differt-0.0.28}/src/differt/scene/_sionna.py +23 -1
- {differt-0.0.26 → differt-0.0.28}/src/differt/scene/_triangle_scene.py +2 -2
- {differt-0.0.26 → differt-0.0.28}/src/differt/utils.py +6 -3
- {differt-0.0.26 → differt-0.0.28}/.gitignore +0 -0
- {differt-0.0.26 → differt-0.0.28}/LICENSE.md +0 -0
- {differt-0.0.26 → differt-0.0.28}/README.md +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/__init__.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/_version.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/em/__init__.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/em/_constants.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/em/_special.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/em/_utd.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/em/_utils.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/geometry/__init__.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/geometry/_triangle_mesh.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/plotting/__init__.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/plotting/_utils.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/rt/__init__.py +0 -0
- {differt-0.0.26 → differt-0.0.28}/src/differt/scene/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.28
|
|
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
|
|
@@ -16,11 +16,12 @@ Classifier: Programming Language :: Python :: 3
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
20
|
Classifier: Topic :: Scientific/Engineering
|
|
20
21
|
Requires-Python: >=3.10
|
|
21
22
|
Requires-Dist: beartype>=0.19.0
|
|
22
23
|
Requires-Dist: chex>=0.1.86
|
|
23
|
-
Requires-Dist: differt-core==0.0.
|
|
24
|
+
Requires-Dist: differt-core==0.0.28
|
|
24
25
|
Requires-Dist: equinox>=0.11.5
|
|
25
26
|
Requires-Dist: filelock>=3.15.4
|
|
26
27
|
Requires-Dist: jax>=0.4.32
|
|
@@ -9,6 +9,7 @@ classifiers = [
|
|
|
9
9
|
"Programming Language :: Python :: 3.10",
|
|
10
10
|
"Programming Language :: Python :: 3.11",
|
|
11
11
|
"Programming Language :: Python :: 3.12",
|
|
12
|
+
"Programming Language :: Python :: 3.13",
|
|
12
13
|
"License :: OSI Approved :: MIT License",
|
|
13
14
|
"Operating System :: OS Independent",
|
|
14
15
|
"Topic :: Scientific/Engineering",
|
|
@@ -16,7 +17,7 @@ classifiers = [
|
|
|
16
17
|
dependencies = [
|
|
17
18
|
"beartype>=0.19.0",
|
|
18
19
|
"chex>=0.1.86",
|
|
19
|
-
"differt-core==0.0.
|
|
20
|
+
"differt-core==0.0.28",
|
|
20
21
|
"equinox>=0.11.5",
|
|
21
22
|
"filelock>=3.15.4",
|
|
22
23
|
"jax>=0.4.32",
|
|
@@ -12,7 +12,7 @@ from jaxtyping import Array, ArrayLike, Bool, Float, Int, Num, Shaped, jaxtyped
|
|
|
12
12
|
|
|
13
13
|
from differt.plotting import PlotOutput, draw_paths, reuse
|
|
14
14
|
|
|
15
|
-
if sys.version_info >= (3, 11):
|
|
15
|
+
if sys.version_info >= (3, 11):
|
|
16
16
|
from typing import Self
|
|
17
17
|
else:
|
|
18
18
|
from typing_extensions import Self
|
|
@@ -22,7 +22,7 @@ else:
|
|
|
22
22
|
@jaxtyped(typechecker=typechecker)
|
|
23
23
|
def _cell_ids(
|
|
24
24
|
array: Shaped[Array, "batch n"],
|
|
25
|
-
) -> Int[Array, " batch"]:
|
|
25
|
+
) -> Int[Array, " batch"]:
|
|
26
26
|
@jaxtyped(typechecker=typechecker)
|
|
27
27
|
def scan_fun(
|
|
28
28
|
indices: Int[Array, " batch"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
from functools import partial
|
|
1
2
|
from typing import Literal, overload
|
|
2
3
|
|
|
3
|
-
import equinox as eqx
|
|
4
4
|
import jax
|
|
5
5
|
import jax.numpy as jnp
|
|
6
6
|
from beartype import beartype as typechecker
|
|
@@ -52,7 +52,7 @@ def normalize(
|
|
|
52
52
|
): ...
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
@
|
|
55
|
+
@partial(jax.jit, static_argnames=("keepdims",), inline=True)
|
|
56
56
|
@jaxtyped(typechecker=typechecker)
|
|
57
57
|
def normalize(
|
|
58
58
|
vector: Float[Array, "*batch 3"],
|
|
@@ -97,7 +97,7 @@ def normalize(
|
|
|
97
97
|
return vector / length, (length if keepdims else jnp.squeeze(length, axis=-1))
|
|
98
98
|
|
|
99
99
|
|
|
100
|
-
@
|
|
100
|
+
@partial(jax.jit, static_argnames=("normalize",), inline=True)
|
|
101
101
|
@jaxtyped(typechecker=typechecker)
|
|
102
102
|
def orthogonal_basis(
|
|
103
103
|
u: Float[Array, "*batch 3"],
|
|
@@ -146,7 +146,7 @@ def orthogonal_basis(
|
|
|
146
146
|
return v, w
|
|
147
147
|
|
|
148
148
|
|
|
149
|
-
@jax.jit
|
|
149
|
+
@partial(jax.jit, inline=True)
|
|
150
150
|
@jaxtyped(typechecker=typechecker)
|
|
151
151
|
def path_lengths(
|
|
152
152
|
paths: Float[Array, "*batch path_length 3"],
|
|
@@ -440,7 +440,6 @@ def fibonacci_lattice(
|
|
|
440
440
|
return spherical_to_cartesian(pa).astype(dtype)
|
|
441
441
|
|
|
442
442
|
|
|
443
|
-
@jax.jit
|
|
444
443
|
@jaxtyped(typechecker=typechecker)
|
|
445
444
|
def assemble_paths(
|
|
446
445
|
*path_segments: Float[Array, "*#batch _num_vertices 3"],
|
|
@@ -547,7 +546,7 @@ def viewing_frustum(
|
|
|
547
546
|
) -> Float[Array, "*batch 2 3"] | Float[Array, "2 3"]: ...
|
|
548
547
|
|
|
549
548
|
|
|
550
|
-
@
|
|
549
|
+
@partial(jax.jit, static_argnames=("reduce",))
|
|
551
550
|
@jaxtyped(typechecker=typechecker)
|
|
552
551
|
def viewing_frustum(
|
|
553
552
|
viewing_vertex: Float[Array, "*#batch 3"],
|
|
@@ -602,7 +601,7 @@ def viewing_frustum(
|
|
|
602
601
|
... color = r, g, b = jax.random.randint(key_color, (3,), 0, 256)
|
|
603
602
|
... center = mesh.bounding_box.mean(axis=0)
|
|
604
603
|
... mesh = mesh.translate(5 * (center - tx)).set_face_colors(color)
|
|
605
|
-
... mesh.plot()
|
|
604
|
+
... mesh.plot(opacity=0.5)
|
|
606
605
|
...
|
|
607
606
|
... frustum = viewing_frustum(
|
|
608
607
|
... tx, mesh.triangle_vertices.reshape(-1, 3)
|
|
@@ -615,8 +614,7 @@ def viewing_frustum(
|
|
|
615
614
|
... draw_rays(
|
|
616
615
|
... ray_origins,
|
|
617
616
|
... ray_directions,
|
|
618
|
-
...
|
|
619
|
-
... mode="lines",
|
|
617
|
+
... color=f"rgb({r:f},{g:f},{b:f})",
|
|
620
618
|
... showlegend=False,
|
|
621
619
|
... ) # doctest: +SKIP
|
|
622
620
|
>>> fig # doctest: +SKIP
|
|
@@ -639,7 +637,7 @@ def viewing_frustum(
|
|
|
639
637
|
... ):
|
|
640
638
|
... center = mesh.bounding_box.mean(axis=0)
|
|
641
639
|
... mesh = mesh.translate(5 * (center - tx))
|
|
642
|
-
... mesh.plot()
|
|
640
|
+
... mesh.plot(opacity=0.5)
|
|
643
641
|
...
|
|
644
642
|
... world_vertices = jnp.concatenate(
|
|
645
643
|
... (world_vertices, mesh.triangle_vertices.reshape(-1, 3)),
|
|
@@ -655,8 +653,7 @@ def viewing_frustum(
|
|
|
655
653
|
... draw_rays(
|
|
656
654
|
... ray_origins,
|
|
657
655
|
... ray_directions,
|
|
658
|
-
...
|
|
659
|
-
... mode="lines",
|
|
656
|
+
... color="red",
|
|
660
657
|
... showlegend=False,
|
|
661
658
|
... ) # doctest: +SKIP
|
|
662
659
|
>>> fig # doctest: +SKIP
|
|
@@ -676,7 +673,7 @@ def viewing_frustum(
|
|
|
676
673
|
... mesh = TriangleMesh.box(
|
|
677
674
|
... width=10.0, length=20.0, height=3.0, with_top=True
|
|
678
675
|
... ).set_face_colors(jnp.array([1.0, 0.0, 0.0]))
|
|
679
|
-
... mesh.plot()
|
|
676
|
+
... mesh.plot(opacity=0.5)
|
|
680
677
|
...
|
|
681
678
|
... frustum = viewing_frustum(tx, mesh.triangle_vertices.reshape(-1, 3))
|
|
682
679
|
... ray_origins, ray_directions = jnp.broadcast_arrays(
|
|
@@ -687,8 +684,7 @@ def viewing_frustum(
|
|
|
687
684
|
... draw_rays(
|
|
688
685
|
... ray_origins,
|
|
689
686
|
... ray_directions,
|
|
690
|
-
...
|
|
691
|
-
... mode="lines",
|
|
687
|
+
... color="red",
|
|
692
688
|
... showlegend=False,
|
|
693
689
|
... ) # doctest: +SKIP
|
|
694
690
|
>>> fig # doctest: +SKIP
|
|
@@ -4,7 +4,7 @@ from collections.abc import Mapping, Sequence
|
|
|
4
4
|
from typing import TYPE_CHECKING, Any
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
|
-
from jaxtyping import ArrayLike, Int, Real
|
|
7
|
+
from jaxtyping import ArrayLike, Float, Int, Real
|
|
8
8
|
|
|
9
9
|
from ._utils import (
|
|
10
10
|
dispatch,
|
|
@@ -251,6 +251,8 @@ def _(
|
|
|
251
251
|
def draw_rays(
|
|
252
252
|
ray_origins: Real[ArrayLike, "*batch 3"],
|
|
253
253
|
ray_directions: Real[ArrayLike, "*batch 3"],
|
|
254
|
+
*,
|
|
255
|
+
ratio: Float[ArrayLike, " "] = 0.1,
|
|
254
256
|
**kwargs: Any,
|
|
255
257
|
) -> Canvas | MplFigure | Figure: # type: ignore[reportInvalidTypeForm]
|
|
256
258
|
"""
|
|
@@ -260,15 +262,60 @@ def draw_rays(
|
|
|
260
262
|
ray_origins: An array of origin vertices.
|
|
261
263
|
ray_directions: An array of ray directions. The ray ends
|
|
262
264
|
should be equal to ``ray_origins + ray_directions``.
|
|
265
|
+
ratio: The ratio of the arrow head size with respect to the
|
|
266
|
+
corresponding ray length.
|
|
263
267
|
kwargs: Keyword arguments passed to
|
|
264
|
-
:class:`
|
|
265
|
-
:meth:`
|
|
266
|
-
or
|
|
268
|
+
:class:`Arrow<vispy.scene.visuals.Arrow>`,
|
|
269
|
+
:meth:`quiver<mpl_toolkits.mplot3d.axes3d.Axes3D.quiver>`,
|
|
270
|
+
or a mix of :class:`Scatter3d<plotly.graph_objects.Scatter3d>`
|
|
271
|
+
and :class:`Cone<plotly.graph_objects.Cone>` [#f1]_ ,
|
|
267
272
|
depending on the backend.
|
|
268
273
|
|
|
269
274
|
Returns:
|
|
270
275
|
The resulting plot output.
|
|
271
276
|
|
|
277
|
+
.. [#f1] Plotly's 3D quiver plot is just a cone, which does not look like an
|
|
278
|
+
arrow. To improve it, a line is prepended the cone.
|
|
279
|
+
|
|
280
|
+
.. raw:: html
|
|
281
|
+
|
|
282
|
+
<details>
|
|
283
|
+
<summary><a>Specific keyword rules for Plotly's backend</a></summary>
|
|
284
|
+
|
|
285
|
+
The following keyword arguments have a special meaning:
|
|
286
|
+
|
|
287
|
+
- ``color``: the color of the rays;
|
|
288
|
+
- ``name``: the name of the rays;
|
|
289
|
+
|
|
290
|
+
The following keyword arguments are passed to the line plot:
|
|
291
|
+
|
|
292
|
+
- ``legendgroup=name``;
|
|
293
|
+
- ``line_color=color``;
|
|
294
|
+
- ``mode="lines"``;
|
|
295
|
+
- ``showlegend=False``.
|
|
296
|
+
|
|
297
|
+
The following keyword arguments are passed to the cone plot (i.e., arrow head):
|
|
298
|
+
|
|
299
|
+
- ``colorscale=[color, color]``;
|
|
300
|
+
- ``hoverinfo="name"``;
|
|
301
|
+
- ``legendgroup=name``;
|
|
302
|
+
- ``name=name``;
|
|
303
|
+
- ``showscale=False``;
|
|
304
|
+
- ``showlegend=True``;
|
|
305
|
+
- ``sizemode="raw"``.
|
|
306
|
+
|
|
307
|
+
If you wish to override any of the above arguments, or add any additional,
|
|
308
|
+
you can use the following keyword arguments:
|
|
309
|
+
|
|
310
|
+
- ``cone_kwargs``: a mapping of keyword arguments passed to :class:`Cone<plotly.graph_objects.Cone>`;
|
|
311
|
+
- ``line_kwargs``: a mapping of keyword arguments passed to :class:`Scatter3d<plotly.graph_objects.Scatter3d>`;
|
|
312
|
+
|
|
313
|
+
Other keyword arguments are passed to both constructors.
|
|
314
|
+
|
|
315
|
+
.. raw:: html
|
|
316
|
+
|
|
317
|
+
</details>
|
|
318
|
+
|
|
272
319
|
Examples:
|
|
273
320
|
The following example shows how to plot rays.
|
|
274
321
|
|
|
@@ -295,24 +342,49 @@ def draw_rays(
|
|
|
295
342
|
def _(
|
|
296
343
|
ray_origins: Real[ArrayLike, "*batch 3"],
|
|
297
344
|
ray_directions: Real[ArrayLike, "*batch 3"],
|
|
345
|
+
*,
|
|
346
|
+
ratio: Float[ArrayLike, " "] = 0.1,
|
|
298
347
|
**kwargs: Any,
|
|
299
348
|
) -> Canvas:
|
|
300
|
-
|
|
301
|
-
ray_directions = np.asarray(ray_directions)
|
|
302
|
-
ray_ends = ray_origins + ray_directions
|
|
303
|
-
paths = np.concatenate((ray_origins[..., None, :], ray_ends[..., None, :]), axis=-2)
|
|
349
|
+
from vispy.scene.visuals import Arrow # noqa: PLC0415
|
|
304
350
|
|
|
305
|
-
|
|
351
|
+
canvas, view = process_vispy_kwargs(kwargs)
|
|
352
|
+
|
|
353
|
+
kwargs.setdefault("width", 3.0)
|
|
354
|
+
kwargs.setdefault("arrow_size", 6.0)
|
|
355
|
+
|
|
356
|
+
ray_origins = np.asarray(ray_origins).reshape(-1, 3)
|
|
357
|
+
ray_directions = np.asarray(ray_directions).reshape(-1, 3)
|
|
358
|
+
ratio = np.asarray(ratio)
|
|
359
|
+
body_ends = ray_origins + (1 - ratio) * ray_directions
|
|
360
|
+
|
|
361
|
+
pos = np.concatenate((ray_origins, body_ends), axis=-1).reshape(-1, 3)
|
|
362
|
+
connect = np.ones(pos.shape[0], dtype=bool)
|
|
363
|
+
connect[1::2] = False
|
|
364
|
+
|
|
365
|
+
arrows_dir = ratio * ray_directions
|
|
366
|
+
arrows_center = body_ends + 0.5 * arrows_dir
|
|
367
|
+
arrows = np.concatenate((body_ends, arrows_center), axis=-1)
|
|
368
|
+
|
|
369
|
+
view.add(Arrow(pos=pos, connect=connect, arrows=arrows, **kwargs)) # type: ignore[reportArgumentType]
|
|
370
|
+
|
|
371
|
+
view.camera.set_range()
|
|
372
|
+
|
|
373
|
+
return canvas
|
|
306
374
|
|
|
307
375
|
|
|
308
376
|
@draw_rays.register("matplotlib")
|
|
309
377
|
def _(
|
|
310
378
|
ray_origins: Real[ArrayLike, "*batch 3"],
|
|
311
379
|
ray_directions: Real[ArrayLike, "*batch 3"],
|
|
380
|
+
*,
|
|
381
|
+
ratio: Float[ArrayLike, " "] = 0.1,
|
|
312
382
|
**kwargs: Any,
|
|
313
383
|
) -> MplFigure:
|
|
314
384
|
fig, ax = process_matplotlib_kwargs(kwargs)
|
|
315
385
|
|
|
386
|
+
kwargs.setdefault("arrow_length_ratio", float(ratio)) # type: ignore[reportCallIssue]
|
|
387
|
+
|
|
316
388
|
ray_origins = np.asarray(ray_origins).reshape(-1, 3)
|
|
317
389
|
ray_directions = np.asarray(ray_directions).reshape(-1, 3)
|
|
318
390
|
|
|
@@ -324,15 +396,58 @@ def _(
|
|
|
324
396
|
@draw_rays.register("plotly")
|
|
325
397
|
def _(
|
|
326
398
|
ray_origins: Real[ArrayLike, "*batch 3"],
|
|
327
|
-
ray_directions:
|
|
399
|
+
ray_directions: Float[ArrayLike, "*batch 3"],
|
|
400
|
+
*,
|
|
401
|
+
ratio: Float[ArrayLike, " "] = 0.1,
|
|
328
402
|
**kwargs: Any,
|
|
329
403
|
) -> Figure:
|
|
330
404
|
ray_origins = np.asarray(ray_origins)
|
|
331
405
|
ray_directions = np.asarray(ray_directions)
|
|
332
|
-
|
|
333
|
-
|
|
406
|
+
ratio = np.asarray(ratio)
|
|
407
|
+
|
|
408
|
+
color = kwargs.pop("color", None)
|
|
409
|
+
name = kwargs.pop("name", None)
|
|
410
|
+
line_kwargs = kwargs.pop("line_kwargs", {})
|
|
411
|
+
cone_kwargs = kwargs.pop("cone_kwargs", {})
|
|
412
|
+
line_kwargs = {**kwargs, **line_kwargs}
|
|
413
|
+
cone_kwargs = {**kwargs, **cone_kwargs}
|
|
414
|
+
|
|
415
|
+
line_kwargs.setdefault("legendgroup", name)
|
|
416
|
+
if color: # pragma: no cover
|
|
417
|
+
line_kwargs.setdefault("line_color", color)
|
|
418
|
+
line_kwargs.setdefault("mode", "lines")
|
|
419
|
+
line_kwargs.setdefault("showlegend", False)
|
|
420
|
+
|
|
421
|
+
line_ends = ray_origins + (1 - ratio) * ray_directions
|
|
422
|
+
line_paths = np.concatenate(
|
|
423
|
+
(ray_origins[..., None, :], line_ends[..., None, :]), axis=-2
|
|
424
|
+
)
|
|
334
425
|
|
|
335
|
-
|
|
426
|
+
fig = draw_paths(line_paths, backend="plotly", **line_kwargs)
|
|
427
|
+
|
|
428
|
+
if color is None: # pragma: no cover
|
|
429
|
+
color = fig.layout.template.layout.colorway[0]
|
|
430
|
+
fig.data[-1].line.color = color
|
|
431
|
+
cone_kwargs.setdefault("colorscale", [color, color])
|
|
432
|
+
cone_kwargs.setdefault("hoverinfo", "name")
|
|
433
|
+
cone_kwargs.setdefault("legendgroup", name)
|
|
434
|
+
cone_kwargs.setdefault("name", name)
|
|
435
|
+
cone_kwargs.setdefault("showscale", False)
|
|
436
|
+
cone_kwargs.setdefault("showlegend", True)
|
|
437
|
+
cone_kwargs.setdefault("sizemode", "raw")
|
|
438
|
+
|
|
439
|
+
cone_origins = line_ends.reshape(-1, 3)
|
|
440
|
+
cone_directions = (ratio * ray_directions).reshape(-1, 3)
|
|
441
|
+
|
|
442
|
+
return fig.add_cone(
|
|
443
|
+
x=cone_origins[:, 0],
|
|
444
|
+
y=cone_origins[:, 1],
|
|
445
|
+
z=cone_origins[:, 2],
|
|
446
|
+
u=cone_directions[:, 0],
|
|
447
|
+
v=cone_directions[:, 1],
|
|
448
|
+
w=cone_directions[:, 2],
|
|
449
|
+
**cone_kwargs,
|
|
450
|
+
)
|
|
336
451
|
|
|
337
452
|
|
|
338
453
|
@dispatch
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
from functools import partial
|
|
1
2
|
from typing import Any
|
|
2
3
|
|
|
3
4
|
import equinox as eqx
|
|
5
|
+
import jax
|
|
4
6
|
import jax.numpy as jnp
|
|
5
7
|
from beartype import beartype as typechecker
|
|
6
8
|
from jaxtyping import Array, Float, jaxtyped
|
|
@@ -9,6 +11,39 @@ from differt.geometry import orthogonal_basis
|
|
|
9
11
|
from differt.utils import minimize
|
|
10
12
|
|
|
11
13
|
|
|
14
|
+
@partial(jax.jit, inline=True)
|
|
15
|
+
@jaxtyped(typechecker=typechecker)
|
|
16
|
+
def _st_to_xyz(
|
|
17
|
+
st: Float[Array, "*batch num_unknowns"],
|
|
18
|
+
o: Float[Array, "*batch num_mirrors 3"],
|
|
19
|
+
d1: Float[Array, "*batch num_mirrors 3"],
|
|
20
|
+
d2: Float[Array, "*batch num_mirrors 3"],
|
|
21
|
+
) -> Float[Array, "*batch num_mirrors 3"]:
|
|
22
|
+
s = st[..., 0::2, None]
|
|
23
|
+
t = st[..., 1::2, None]
|
|
24
|
+
return o + d1 * s + d2 * t
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@partial(jax.jit, inline=True)
|
|
28
|
+
@jaxtyped(typechecker=typechecker)
|
|
29
|
+
def _loss( # noqa: PLR0917
|
|
30
|
+
st: Float[Array, "*batch num_unknowns"],
|
|
31
|
+
from_: Float[Array, "*batch 3"],
|
|
32
|
+
to: Float[Array, "*batch 3"],
|
|
33
|
+
o: Float[Array, "*batch num_mirrors 3"],
|
|
34
|
+
d1: Float[Array, "*batch num_mirrors 3"],
|
|
35
|
+
d2: Float[Array, "*batch num_mirrors 3"],
|
|
36
|
+
) -> Float[Array, " *batch"]:
|
|
37
|
+
xyz = _st_to_xyz(st, o, d1, d2)
|
|
38
|
+
paths = jnp.concatenate(
|
|
39
|
+
(from_[..., None, :], xyz, to[..., None, :]),
|
|
40
|
+
axis=-2,
|
|
41
|
+
)
|
|
42
|
+
vectors = jnp.diff(paths, axis=-2)
|
|
43
|
+
lengths = jnp.linalg.norm(vectors, axis=-1)
|
|
44
|
+
return jnp.sum(lengths, axis=-1)
|
|
45
|
+
|
|
46
|
+
|
|
12
47
|
@eqx.filter_jit
|
|
13
48
|
@jaxtyped(typechecker=typechecker)
|
|
14
49
|
def fermat_path_on_planar_mirrors(
|
|
@@ -84,38 +119,9 @@ def fermat_path_on_planar_mirrors(
|
|
|
84
119
|
|
|
85
120
|
mirror_directions_1, mirror_directions_2 = orthogonal_basis(mirror_normals)
|
|
86
121
|
|
|
87
|
-
@jaxtyped(typechecker=typechecker)
|
|
88
|
-
def st_to_xyz(
|
|
89
|
-
st: Float[Array, "*batch num_unknowns"],
|
|
90
|
-
o: Float[Array, "*batch num_mirrors 3"],
|
|
91
|
-
d1: Float[Array, "*batch num_mirrors 3"],
|
|
92
|
-
d2: Float[Array, "*batch num_mirrors 3"],
|
|
93
|
-
) -> Float[Array, "*batch num_mirrors 3"]:
|
|
94
|
-
s = st[..., 0::2, None]
|
|
95
|
-
t = st[..., 1::2, None]
|
|
96
|
-
return o + d1 * s + d2 * t
|
|
97
|
-
|
|
98
|
-
@jaxtyped(typechecker=typechecker)
|
|
99
|
-
def loss( # noqa: PLR0917
|
|
100
|
-
st: Float[Array, "*batch num_unknowns"],
|
|
101
|
-
from_: Float[Array, "*batch 3"],
|
|
102
|
-
to: Float[Array, "*batch 3"],
|
|
103
|
-
o: Float[Array, "*batch num_mirrors 3"],
|
|
104
|
-
d1: Float[Array, "*batch num_mirrors 3"],
|
|
105
|
-
d2: Float[Array, "*batch num_mirrors 3"],
|
|
106
|
-
) -> Float[Array, " *batch"]:
|
|
107
|
-
xyz = st_to_xyz(st, o, d1, d2)
|
|
108
|
-
paths = jnp.concatenate(
|
|
109
|
-
(from_[..., None, :], xyz, to[..., None, :]),
|
|
110
|
-
axis=-2,
|
|
111
|
-
)
|
|
112
|
-
vectors = jnp.diff(paths, axis=-2)
|
|
113
|
-
lengths = jnp.linalg.norm(vectors, axis=-1)
|
|
114
|
-
return jnp.sum(lengths, axis=-1)
|
|
115
|
-
|
|
116
122
|
st0 = jnp.zeros((*batch, num_unknowns))
|
|
117
123
|
st, _ = minimize(
|
|
118
|
-
|
|
124
|
+
_loss,
|
|
119
125
|
st0,
|
|
120
126
|
args=(
|
|
121
127
|
from_vertices,
|
|
@@ -127,4 +133,4 @@ def fermat_path_on_planar_mirrors(
|
|
|
127
133
|
**kwargs,
|
|
128
134
|
)
|
|
129
135
|
|
|
130
|
-
return
|
|
136
|
+
return _st_to_xyz(st, mirror_vertices, mirror_directions_1, mirror_directions_2)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# ruff: noqa: ERA001
|
|
2
2
|
|
|
3
|
+
from functools import partial
|
|
4
|
+
|
|
3
5
|
import chex
|
|
4
6
|
import jax
|
|
5
7
|
import jax.numpy as jnp
|
|
@@ -9,7 +11,7 @@ from jaxtyping import Array, Bool, Float, jaxtyped
|
|
|
9
11
|
from differt.utils import dot
|
|
10
12
|
|
|
11
13
|
|
|
12
|
-
@jax.jit
|
|
14
|
+
@partial(jax.jit, inline=True)
|
|
13
15
|
@jaxtyped(typechecker=typechecker)
|
|
14
16
|
def image_of_vertices_with_respect_to_mirrors(
|
|
15
17
|
vertices: Float[Array, "*#batch 3"],
|
|
@@ -74,7 +76,7 @@ def image_of_vertices_with_respect_to_mirrors(
|
|
|
74
76
|
)
|
|
75
77
|
|
|
76
78
|
|
|
77
|
-
@jax.jit
|
|
79
|
+
@partial(jax.jit, inline=True)
|
|
78
80
|
@jaxtyped(typechecker=typechecker)
|
|
79
81
|
def intersection_of_rays_with_planes(
|
|
80
82
|
ray_origins: Float[Array, "*#batch 3"],
|
|
@@ -346,7 +348,9 @@ def consecutive_vertices_are_on_same_side_of_mirrors(
|
|
|
346
348
|
A boolean array indicating whether pairs of consecutive vertices
|
|
347
349
|
are on the same side of the corresponding mirror.
|
|
348
350
|
"""
|
|
349
|
-
chex.assert_axis_dimension(
|
|
351
|
+
chex.assert_axis_dimension(
|
|
352
|
+
vertices, -2, mirror_vertices.shape[-2] + 2, exception_type=TypeError
|
|
353
|
+
)
|
|
350
354
|
|
|
351
355
|
# dot_{prev,next} = <(v_{prev,next} - mirror_v), mirror_n>
|
|
352
356
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
4
|
from collections.abc import Callable, Iterator, Sized
|
|
5
|
+
from functools import cache
|
|
5
6
|
from typing import Any, Generic, TypeVar
|
|
6
7
|
|
|
7
8
|
import equinox as eqx
|
|
@@ -14,7 +15,7 @@ from differt.geometry import fibonacci_lattice, viewing_frustum
|
|
|
14
15
|
from differt.utils import dot
|
|
15
16
|
from differt_core.rt import CompleteGraph
|
|
16
17
|
|
|
17
|
-
if sys.version_info >= (3, 11):
|
|
18
|
+
if sys.version_info >= (3, 11):
|
|
18
19
|
from typing import Self
|
|
19
20
|
else:
|
|
20
21
|
from typing_extensions import Self
|
|
@@ -24,7 +25,7 @@ _T = TypeVar("_T")
|
|
|
24
25
|
|
|
25
26
|
@typechecker
|
|
26
27
|
class SizedIterator(Iterator, Sized, Generic[_T]):
|
|
27
|
-
"""A custom
|
|
28
|
+
"""A custom generic class that is both :class:`Iterator<collections.abc.Iterator>` and :class:`Sized<collections.abc.Sized>`.
|
|
28
29
|
|
|
29
30
|
The main purpose of this class is to be able to use
|
|
30
31
|
`tqdm <https://github.com/tqdm/tqdm>`_ utilities
|
|
@@ -67,6 +68,7 @@ class SizedIterator(Iterator, Sized, Generic[_T]):
|
|
|
67
68
|
|
|
68
69
|
|
|
69
70
|
@jaxtyped(typechecker=typechecker)
|
|
71
|
+
@cache
|
|
70
72
|
def generate_all_path_candidates(
|
|
71
73
|
num_primitives: int,
|
|
72
74
|
order: int,
|
|
@@ -234,7 +236,7 @@ def rays_intersect_triangles(
|
|
|
234
236
|
... jnp.asarray(ray_origins[rays_hit, :]),
|
|
235
237
|
... jnp.asarray(ray_directions[rays_hit, :]),
|
|
236
238
|
... backend="plotly",
|
|
237
|
-
...
|
|
239
|
+
... color="red",
|
|
238
240
|
... showlegend=False,
|
|
239
241
|
... )
|
|
240
242
|
>>> visible_color = jnp.array([0.2, 0.2, 0.2])
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import sys
|
|
1
2
|
import tarfile
|
|
2
3
|
import tempfile
|
|
4
|
+
import warnings
|
|
3
5
|
from collections.abc import Iterator
|
|
4
6
|
from pathlib import Path
|
|
5
7
|
|
|
@@ -26,6 +28,12 @@ def download_sionna_scenes(
|
|
|
26
28
|
If cached is :data:`False` and folder exists, then it will
|
|
27
29
|
raise an error if not empty: please clear it first!
|
|
28
30
|
|
|
31
|
+
Warning:
|
|
32
|
+
Older Python versions (i.e., <3.12, <3.11.4, and <3.10.12) do not
|
|
33
|
+
provide the ``filter`` parameter in :meth:`tarfile.TarFile.extractall`,
|
|
34
|
+
which can be considered a security risk. This function will raise a
|
|
35
|
+
warning if the current Python version is one of these versions.
|
|
36
|
+
|
|
29
37
|
Args:
|
|
30
38
|
branch_or_tag: The branch or tag version of the Sionna repository.
|
|
31
39
|
folder: Where to extract the scene files, i.e., the content
|
|
@@ -83,7 +91,21 @@ def download_sionna_scenes(
|
|
|
83
91
|
f.flush()
|
|
84
92
|
|
|
85
93
|
with tarfile.open(f.name) as tar:
|
|
86
|
-
|
|
94
|
+
# tarfile added 'filter' parameter for security reasons.
|
|
95
|
+
if (
|
|
96
|
+
sys.version_info >= (3, 12)
|
|
97
|
+
or (sys.version_info.minor == 11 and sys.version_info.micro >= 4) # noqa: PLR2004
|
|
98
|
+
or (sys.version_info.minor == 10 and sys.version_info.micro >= 12) # noqa: PLR2004
|
|
99
|
+
):
|
|
100
|
+
tar.extractall(path=folder, members=members(tar), filter="data")
|
|
101
|
+
else: # pragma: no cover
|
|
102
|
+
msg = (
|
|
103
|
+
"You are using an old version of Python that doesn't include the 'filter' "
|
|
104
|
+
"parameter in 'tarfile.TarFile.extractall'. This is can be security issue, and we "
|
|
105
|
+
"recommend upgrading to a newer version of Python: 3.12, 3.11.4, or 3.10.12."
|
|
106
|
+
)
|
|
107
|
+
warnings.warn(msg, UserWarning, stacklevel=2)
|
|
108
|
+
tar.extractall(path=folder, members=members(tar)) # noqa: S202
|
|
87
109
|
|
|
88
110
|
|
|
89
111
|
def list_sionna_scenes(*, folder: str | Path = SIONNA_SCENES_FOLDER) -> list[str]:
|
|
@@ -13,7 +13,7 @@ from beartype import beartype as typechecker
|
|
|
13
13
|
from jax.experimental import mesh_utils
|
|
14
14
|
from jax.experimental.shard_map import shard_map
|
|
15
15
|
from jax.sharding import Mesh
|
|
16
|
-
from jax.sharding import PartitionSpec as P
|
|
16
|
+
from jax.sharding import PartitionSpec as P
|
|
17
17
|
from jaxtyping import Array, ArrayLike, Bool, Float, Int, jaxtyped
|
|
18
18
|
|
|
19
19
|
import differt_core.scene
|
|
@@ -39,7 +39,7 @@ from differt.rt import (
|
|
|
39
39
|
)
|
|
40
40
|
from differt.utils import dot
|
|
41
41
|
|
|
42
|
-
if sys.version_info >= (3, 11):
|
|
42
|
+
if sys.version_info >= (3, 11):
|
|
43
43
|
from typing import Self
|
|
44
44
|
else:
|
|
45
45
|
from typing_extensions import Self
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""General purpose utilities."""
|
|
2
2
|
|
|
3
3
|
from collections.abc import Callable, Iterable, Mapping
|
|
4
|
-
from
|
|
4
|
+
from functools import partial
|
|
5
|
+
from typing import Any, Concatenate, ParamSpec, overload
|
|
5
6
|
|
|
6
7
|
import chex
|
|
7
8
|
import equinox as eqx
|
|
@@ -132,12 +133,14 @@ def sorted_array2(array: Shaped[Array, "m n"]) -> Shaped[Array, "m n"]:
|
|
|
132
133
|
# Redefined here, because chex uses deprecated type hints
|
|
133
134
|
# TODO: fixme when google/chex#361 is resolved.
|
|
134
135
|
_OptState = chex.Array | Iterable["_OptState"] | Mapping[Any, "_OptState"]
|
|
136
|
+
# TODO: fixme when Python >= 3.11
|
|
137
|
+
_P = ParamSpec("_P")
|
|
135
138
|
|
|
136
139
|
|
|
137
140
|
@eqx.filter_jit
|
|
138
141
|
@jaxtyped(typechecker=typechecker)
|
|
139
142
|
def minimize(
|
|
140
|
-
fun: Callable[Concatenate[Num[Array, " n"],
|
|
143
|
+
fun: Callable[Concatenate[Num[Array, " n"], _P], Num[Array, " "]],
|
|
141
144
|
x0: Num[Array, "*batch n"],
|
|
142
145
|
args: tuple[Any, ...] = (),
|
|
143
146
|
steps: int = 1000,
|
|
@@ -305,7 +308,7 @@ def sample_points_in_bounding_box(
|
|
|
305
308
|
) -> Float[Array, "3"]: ...
|
|
306
309
|
|
|
307
310
|
|
|
308
|
-
@
|
|
311
|
+
@partial(jax.jit, static_argnames=("shape",))
|
|
309
312
|
@jaxtyped(typechecker=typechecker)
|
|
310
313
|
def sample_points_in_bounding_box(
|
|
311
314
|
bounding_box: Float[Array, "2 3"],
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|