Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): reduce line length in notebooks #139

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions docs/source/notebooks/advanced_path_tracing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
" consecutive_vertices_are_on_same_side_of_mirrors,\n",
" image_method,\n",
")\n",
"from differt.rt.utils import generate_all_path_candidates, rays_intersect_triangles"
"from differt.rt.utils import (\n",
" generate_all_path_candidates,\n",
" rays_intersect_triangles,\n",
")"
]
},
{
Expand Down Expand Up @@ -140,7 +143,9 @@
"tx = jnp.array([0.0, 4.9352, 22.0])\n",
"rx = jnp.array([0.0, 10.034, 1.50])\n",
"\n",
"dplt.draw_markers(np.array([tx, rx]), labels=[\"tx\", \"rx\"], figure=fig, name=\"nodes\")"
"dplt.draw_markers(\n",
" np.array([tx, rx]), labels=[\"tx\", \"rx\"], figure=fig, name=\"nodes\"\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LanguageTool] reported by reviewdog 🐶
Unpaired symbol: ‘"’ seems to be missing (EN_UNPAIRED_QUOTES)
URL: https://languagetool.org/insights/post/punctuation-guide/#what-are-parentheses
Rule: https://community.languagetool.org/rule/show/EN_UNPAIRED_QUOTES?lang=en-US
Category: PUNCTUATION

")"
]
},
{
Expand Down Expand Up @@ -228,7 +233,9 @@
"\n",
" # 2 - Trace paths\n",
"\n",
" path = image_method(from_vertices, to_vertices, mirror_vertices, mirror_normals)\n",
" path = image_method(\n",
" from_vertices, to_vertices, mirror_vertices, mirror_normals\n",
" )\n",
"\n",
" # 3 - ??\n",
"\n",
Expand Down Expand Up @@ -326,7 +333,9 @@
" # 2 - Trace paths\n",
"\n",
" # [num_path_candidates order 3]\n",
" paths = image_method(from_vertices, to_vertices, mirror_vertices, mirror_normals)\n",
" paths = image_method(\n",
" from_vertices, to_vertices, mirror_vertices, mirror_normals\n",
" )\n",
"\n",
" # 3 - Remove invalid paths\n",
"\n",
Expand Down Expand Up @@ -499,7 +508,9 @@
"mesh = mesh.set_face_colors(mesh.face_colors.at[indices].set(visible_color))\n",
"\n",
"with dplt.reuse(\"vispy\") as canvas:\n",
" dplt.draw_markers(np.array([tx]), [\"tx\"], size=7, text_kwargs={\"font_size\": 2000})\n",
" dplt.draw_markers(\n",
" np.array([tx]), [\"tx\"], size=7, text_kwargs={\"font_size\": 2000}\n",
" )\n",
" mesh.plot()\n",
"\n",
"canvas"
Expand Down
49 changes: 38 additions & 11 deletions docs/source/notebooks/multipath.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24402,7 +24402,9 @@
],
"source": [
"# Let's put one transmitter and many receivers in our scene\n",
"scene = eqx.tree_at(lambda s: s.transmitters, scene, jnp.array([-33.0, 0.0, 32.0]))\n",
"scene = eqx.tree_at(\n",
" lambda s: s.transmitters, scene, jnp.array([-33.0, 0.0, 32.0])\n",
")\n",
"# Our scene can be simplified to quadrilaterals,\n",
"# so informing the code of that matter will make it run faster\n",
"scene = scene.set_assume_quads()\n",
Expand All @@ -24422,7 +24424,9 @@
"unique_cluster_ids = jnp.empty(\n",
" (), dtype=jnp.int32\n",
") # Contains unique values of 'cluster_ids'\n",
"cluster_hashes = {0: b\"\"} # This is only use generate constant random color per cluster\n",
"cluster_hashes = {\n",
" 0: b\"\"\n",
"} # This is only use generate constant random color per cluster\n",
"has_multipath = jnp.zeros(\n",
" batch, dtype=bool\n",
") # Will be true if a receiver has at least one valid ray path\n",
Expand All @@ -24443,7 +24447,9 @@
" cluster_ids, cluster_hashes = merge_cluster_ids_and_hashes(\n",
" cluster_ids, new_cluster_ids, cluster_hashes, new_cluster_hashes\n",
" )\n",
" power += (paths.mask / path_lengths(paths.vertices) ** 2).sum(axis=-1)\n",
" power += (paths.mask / path_lengths(paths.vertices) ** 2).sum(\n",
" axis=-1\n",
" )\n",
"\n",
" draw_image( # TODO: change colorbar label\n",
" np.asarray(power),\n",
Expand Down Expand Up @@ -36075,7 +36081,9 @@
"# We renumber unique indices to be between 0 and num_unique_cluster_ids (excluded)\n",
"# Because `jax.numpy.unique` sorts entries, the first cluster id will always refer to\n",
"# the 'no multipath' cluster, if it exists.\n",
"unique_ids, renumbered_cluster_ids = jnp.unique(cluster_ids, return_inverse=True)\n",
"unique_ids, renumbered_cluster_ids = jnp.unique(\n",
" cluster_ids, return_inverse=True\n",
")\n",
"renumbered_cluster_ids = renumbered_cluster_ids.reshape(cluster_ids.shape)\n",
"renumbered_cluster_hashes = {\n",
" i: cluster_hashes[int(id_)] for i, id_ in enumerate(unique_ids)\n",
Expand Down Expand Up @@ -36109,7 +36117,11 @@
" fig.update_layout(\n",
" height=600,\n",
" xaxis={\"range\": [x.min(), x.max()]},\n",
" yaxis={\"range\": [y.min(), y.max()], \"scaleanchor\": \"x\", \"scaleratio\": 1},\n",
" yaxis={\n",
" \"range\": [y.min(), y.max()],\n",
" \"scaleanchor\": \"x\",\n",
" \"scaleratio\": 1,\n",
" },\n",
" )\n",
"\n",
"fig"
Expand Down Expand Up @@ -581667,12 +581679,19 @@
" has_multipath = jnp.zeros(batch, dtype=bool)\n",
"\n",
" for order in range(2):\n",
" for paths in scene_grid.compute_paths(order=order, chunk_size=1_000):\n",
" for paths in scene_grid.compute_paths(\n",
" order=order, chunk_size=1_000\n",
" ):\n",
" new_cluster_ids = paths.multipath_clusters()\n",
" new_cluster_hashes = get_cluster_hashes(new_cluster_ids, paths.mask)\n",
" new_cluster_hashes = get_cluster_hashes(\n",
" new_cluster_ids, paths.mask\n",
" )\n",
" has_multipath |= paths.mask.any(axis=-1)\n",
" cluster_ids, cluster_hashes = merge_cluster_ids_and_hashes(\n",
" cluster_ids, new_cluster_ids, cluster_hashes, new_cluster_hashes\n",
" cluster_ids,\n",
" new_cluster_ids,\n",
" cluster_hashes,\n",
" new_cluster_hashes,\n",
" )\n",
"\n",
" if not has_multipath.all():\n",
Expand All @@ -581683,7 +581702,9 @@
" unique_ids, renumbered_cluster_ids = jnp.unique(\n",
" cluster_ids, return_inverse=True\n",
" )\n",
" renumbered_cluster_ids = renumbered_cluster_ids.reshape(cluster_ids.shape)\n",
" renumbered_cluster_ids = renumbered_cluster_ids.reshape(\n",
" cluster_ids.shape\n",
" )\n",
" renumbered_cluster_hashes = {\n",
" i: cluster_hashes[int(id_)] for i, id_ in enumerate(unique_ids)\n",
" }\n",
Expand Down Expand Up @@ -581742,7 +581763,9 @@
" step[\"args\"][0][\"visible\"][offset + 3 * i + 0] = (\n",
" True # Show TX position on scene\n",
" )\n",
" step[\"args\"][0][\"visible\"][offset + 3 * i + 1] = True # Show TX position on MLM\n",
" step[\"args\"][0][\"visible\"][offset + 3 * i + 1] = (\n",
" True # Show TX position on MLM\n",
" )\n",
" step[\"args\"][0][\"visible\"][offset + 3 * i + 2] = True # Show MLM\n",
" steps.append(step)\n",
"\n",
Expand All @@ -581763,7 +581786,11 @@
" height=800,\n",
" sliders=sliders,\n",
" xaxis={\"range\": [x.min(), x.max()]},\n",
" yaxis={\"range\": [y.min(), y.max()], \"scaleanchor\": \"x\", \"scaleratio\": 1},\n",
" yaxis={\n",
" \"range\": [y.min(), y.max()],\n",
" \"scaleanchor\": \"x\",\n",
" \"scaleratio\": 1,\n",
" },\n",
" )\n",
"\n",
"fig"
Expand Down
4 changes: 3 additions & 1 deletion docs/source/notebooks/path_candidates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@
"source": [
"for depth in [2, 3, 4, 5, 6, 7]:\n",
" num_paths_di_graph = sum(1 for _ in di_graph.all_paths(0, 13, depth=depth))\n",
" num_paths_complete_graph = len(complete_graph.all_paths(12, 13, depth=depth))\n",
" num_paths_complete_graph = len(\n",
" complete_graph.all_paths(12, 13, depth=depth)\n",
" )\n",
"\n",
" print( # noqa: T201\n",
" f\"{depth = }: {num_paths_di_graph:6d} (DiGraph) \"\n",
Expand Down
4 changes: 3 additions & 1 deletion docs/source/notebooks/performance_tips.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@
"\n",
"\n",
"@jax.jit\n",
"def matmul_t_sum(x: Float[Array, \"m k\"], y: Float[Array, \"k n\"]) -> Float[Array, \" \"]:\n",
"def matmul_t_sum(\n",
" x: Float[Array, \"m k\"], y: Float[Array, \"k n\"]\n",
") -> Float[Array, \" \"]:\n",
" return (x @ y).sum()"
]
},
Expand Down
1 change: 1 addition & 0 deletions docs/source/notebooks/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
line-length = 80
Loading