From badadfbfc2c43bb89329c7685c88fb651f213c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sofus=20Albert=20H=C3=B8gsbro=20Rose?= Date: Wed, 24 Apr 2024 19:06:15 +0200 Subject: [PATCH] fix: Extract fixes incl. draw, array-copy on export. --- pyproject.toml | 1 + .../nodes/analysis/extract_data.py | 27 ++++++++++++++----- src/blender_maxwell/utils/bl_cache.py | 2 -- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 11c54f2..852ba57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,6 +109,7 @@ ignore = [ "ERA001", # 'Commented-out code' seems to be just about anything to ruff "F722", # jaxtyping uses type annotations that ruff sees as "syntax error" "N806", # Sometimes we like using types w/uppercase in functions, sue me + "RUF001", # We use a lot of unicode, yes, on purpose! # Line Length - Controversy Incoming ## Hot Take: Let the Formatter Worry about Line Length diff --git a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/analysis/extract_data.py b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/analysis/extract_data.py index e8e083f..cac504a 100644 --- a/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/analysis/extract_data.py +++ b/src/blender_maxwell/node_trees/maxwell_sim_nodes/nodes/analysis/extract_data.py @@ -1,9 +1,11 @@ +"""Declares `ExtractDataNode`.""" + import enum import typing as typ import bpy import jax -import jax.numpy as jnp +import numpy as np import sympy.physics.units as spu import tidy3d as td @@ -246,9 +248,17 @@ class ExtractDataNode(base.MaxwellSimNode): row = col.row() box = row.box() grid = box.grid_flow(row_major=True, columns=2, even_columns=True) - for monitor_name, monitor_type in self.sim_data_monitor_nametype.items(): - grid.label(text=monitor_name) - grid.label(text=monitor_type) + if has_sim_data: + for ( + monitor_name, + monitor_type, + ) in self.sim_data_monitor_nametype.items(): + grid.label(text=monitor_name) + grid.label(text=monitor_type.replace('Data', '')) + elif has_monitor_data: + for component_name in self.monitor_data_components: + grid.label(text=component_name) + grid.label(text=self.monitor_data_type) #################### # - Events @@ -319,6 +329,7 @@ class ExtractDataNode(base.MaxwellSimNode): """Compute `Data:Array` by querying an array-like attribute of `Monitor Data`, then constructing an `ct.ArrayFlow`. Uses the internal `xarray` data returned by Tidy3D. + By using `np.array` on the `.data` attribute of the `xarray`, instead of the usual JAX array constructor, we should save a (possibly very big) copy. Notes: The attribute to query is read directly from `self.extract_filter`. @@ -335,8 +346,7 @@ class ExtractDataNode(base.MaxwellSimNode): xarray_data = getattr( input_sockets['Monitor Data'], props['extract_filter'] ) - return ct.ArrayFlow(values=jnp.array(xarray_data.data), unit=None) - ## TODO: Try np.array instead, as it removes a copy, while still (I believe) being JIT-compatible. + return ct.ArrayFlow(values=np.array(xarray_data.data), unit=None) return ct.FlowSignal.FlowPending @@ -373,6 +383,11 @@ class ExtractDataNode(base.MaxwellSimNode): kind=ct.FlowKind.Params, ) def compute_data_params(self) -> ct.ParamsFlow: + """Declare an empty `Data:Params`, to indicate the start of a function-composition pipeline. + + Returns: + A completely empty `ParamsFlow`, ready to be composed. + """ return ct.ParamsFlow() @events.computes_output_socket( diff --git a/src/blender_maxwell/utils/bl_cache.py b/src/blender_maxwell/utils/bl_cache.py index 68bec7a..b541360 100644 --- a/src/blender_maxwell/utils/bl_cache.py +++ b/src/blender_maxwell/utils/bl_cache.py @@ -375,7 +375,6 @@ class CachedBLProperty: return if value == Signal.InvalidateCache: - log.critical('![%s] Invalidating %s', str(bl_instance), str(self)) self._invalidate_cache(bl_instance) return @@ -577,7 +576,6 @@ class BLField: Thus, whenever the user wants the items in the enum to update, they must manually set the descriptor attribute to the value `Signal.ResetEnumItems`. """ if self._enum_cb_cache.get(_self.instance_id) is None: - log.critical('REGEN ENUM') # Retrieve Dynamic Enum Items enum_items = self._enum_cb(_self, context)