Commit Graph

51 Commits (a3551c68b75ec90f977b14f23c8902195830ac8f)

Author SHA1 Message Date
Sofus Albert Høgsbro Rose a3551c68b7
refactor: symbolic flow support
Massive boost.
Hard to quantify everything.

We're almost batch/inverse design!
- All units are now correct at realization (they weren't before), and
  several operations were simply wrong.
- Near-optimal "flow narrowing", which globally minimizes `DataChanged`
  even in the face of complex internal property dependencies.
- Sockets now cache `FlowKind` output themselves, with invalidation
  provided for and flow narrowing happening before it even enters the
  node flow.
- New FlowKind (`PreviewsFlow`) w/plotting, 3D, efficient caching, with
  all previewed nodes already adapted.
- Drastically prettified plot output, due to seaborn theme integration,
  dict-like data transport w/better labelling, etc. .
- Deep, reliable unit/unit dimension deduction and arithmetic for
  `PhysicalType` deduction using dimensional analysis on arbitrary
  expression operations.
- Fourier transform w/Nyquist limits as boundary conditions (preserving original shift).
- Vastly improved math node operation checks.
- Symbol constant node, integrating domain presumptions.
- Flow integration for ExprSocket, including for flow-dynamic capabilities and color.
- Viewer node got a big update, incl. live-display of sympy types (even
  matrix) and a few Tidy3D types, as well as seperating deeper options
  into a "Debug" mode
- Deeply streamlined symbolic flow, including
- **Differentiable Box structure**, w/generic lazy parameter support - only the start!
2024-05-27 16:48:27 +02:00
Sofus Albert Høgsbro Rose bcba444a8b
refactor: revamped symbolic flow (inaccurate unit conversions) 2024-05-24 16:01:23 +02:00
Sofus Albert Høgsbro Rose 353a2c997e
refactor: end-of-day commit (sim symbol flow for data import/export & inverse design) 2024-05-21 22:57:56 +02:00
Sofus Albert Høgsbro Rose 0f2f494868
feat: implemented data loading w/new math ops
We implemented a node to load various kinds of data, notably `.npy`,
`.txt`, `.txt.gz`, and `.csv`. The `DataFileImporterNode` really should
expose some settings for setting name/mathtype/physical type/unit of
each unit, and/or treating a column from 2D data as index coordinates.
But the nuances of doing this in a manner general enough to deal with
!=2D data was a lot, and we needed similar abilities in the general math
system anyway.

So, we delved back into the `FilterMathNode` and a little into the
`TransformMathNode`. Fundamentally, a few difficult operations came out
of this:

- Filter:SliceIdx: Slice an array using the usual syntax, as baked into the
  function.
- Filter:PinIdx: Pin an axis by its actual index.
- Filter:SetDim: Set the `InfoFlow` index coordinates of an axis to a specific,
  loose-socket provided 1D array, and use a common symbol to set the
  name+physical type (and allow specifying an appropriate unit).
- Transform:IntDimToComplex: Fold a last length-2 integer-indexed axis
  into a real output type, which removes the dimension and produces a
  complex output type. Essentially, this is equivalent to folding it as
  a vector and treating the `R^2` numbers as real/imaginary, except this
  is more explicit.

By combining all of these, we managed to process and constrain the medium data to
be a well-suited, unit-aware (**though not on the output (yet)**) `wl->C` tensor.
In particular, the slicing is nice for avoiding discontinuities.

Workflow-wise, we'll see how important these are / what else we might
want. Also, it turns out Blender's text editor is really quite nice for
light data-text viewing.
2024-05-19 18:04:58 +02:00
Sofus Albert Høgsbro Rose a66a28da27
feat: transform node w/sane `DataChanged`-chaining
We also implemented a JIT-based `rescale` for `ArrayFlow`, where the
same function as for `LazyArrayRangeFlow` passes through and can do an
arbitrary symbolic shift/rescale/order-preserving whatever.
To make this fast for `ArrayFlow`, we utilize a "test" variable `a`,
put it through the function and rescale/strip its units, then `lambdify`
it and broadcast the function onto `ArrayFlow.values`.

It's an immensely clean way of working.
The `lambdify` seems fast, interestingly, but ideally we would of course
also cache that somehow.

Some details remain:

- Fourier Transform index bounds / length are currently not presumed
  known before actually computing them; it's unclear what's best here,
  as the design cross-section of physical expectation, mathematical
  correctness, and ease of implementation (especially trying to keep
  actual data out of the `InfoFlow` hot-path). For now, the `0..\infty`
  bounds **will probably break** the `Viz` node.
- We've reverted the notion that particular `sim_symbol`s must have a
  unit pre-defined, which causes a little more complexity for nodes like
  `TemporalShape`. This question is going to need resolving
- The whole `InfoFlow` object really seems to be at the heart of certain
  lagginess when it comes to the math system. It, together with the
  index representations, would benefit greatly from a principled
  refactor.
- The `Viewer` node is broken for 3D preview; see #70.

Closes #59. Progress on #54.
2024-05-19 09:06:33 +02:00
Sofus Albert Høgsbro Rose 532f0246b5
fix: operate node and "remembered" math ops
We reimplemented the OperateMathNode entirely, and it should now be
relatively to entirely robust. It works based on an enum, just like
`MapMathNode`, which enormously simplifies the node itself. Note that
we're not quite done with sympy+jax implementations of everything, nor
validating that all operations have an implementation valid for all the
`InfoFlow`s that prompted it, but, nonetheless, such fixes should be
easy to work out as we go.

We also finally managed to implement "remembering". In essence,
"remembering" causes `FlowPending` to not reset the dynamic enums in
math / extract nodes. The implementation is generally per-node, and a
bit of boilerplate, but it seems quite robust on the whole - allowing
one to "keep a node tree around" even after removing simulation data.

Extract of sim data is of course more leniant, as it also "remembers"
when there is `NoFlow`. Only new `Sim Data` will reset the extraction
filter enum.

Caches are kept (not memory efficient, but convenient for me), but
only `FlowPending` is actually passed along the `InfoFlow`. This is the
semantics we want - having to deal with this all is a tradeoff of
having data-driven enums, but all in all, it still feels like the right
approach.
2024-05-18 18:02:15 +02:00
Sofus Albert Høgsbro Rose 035d8971f3
fix: local invalidation chains w/extract fixes 2024-05-18 12:09:37 +02:00
Sofus Albert Høgsbro Rose 785c6f764c
fix: GN update for custom geonodes
We also implement `BLField` support for Blender `IDStruct` types.

There's a crash haunting us specifically with the cylinder array. Other
primitives (esp. ring) work just fine, as does previews of nested-linked
node groups. The crash triggers specifically when the file is saved and
reloaded, whereafter all the `load_post` handlers run fine (like -
extremely fine, we can perfectly access and dereference all of the node
groups, seemingly all the objects, etc.). Then, crash.

We're also discovering that `id_properties_ui` is completely useless for
after-the-fact updating of custom properties within sockets. Which is a
great surprise, and I have trouble thinking it's on purpose - the data
is stored somewhere, after all. All the forced updates/redraws/etc. in
the world don't seem to change this.

We may have to go back to the drawing board with dynamically-updated
min/max. The entire infrastructure with `SocketDef` altering sockets
after creation is entirely, _violently_ unsuited to do a static
modification. But the bare fact is, the dynamic modification methods are
falling short. It's kind of important stuff, this stuff.
2024-05-17 12:39:11 +02:00
Sofus Albert Høgsbro Rose 2d26ea6ce8
feat: merged temporal shapes w/symbolic envelope
We now have a single node for all temporal shapes, which is extremely
usable. Note that we found a bug where input socket caching seems to
survive changes to loose inputs / socket set-driven alterations, which
prevents output from being able to switch with the socket set. We'll
make an issue for it whenever convenient.

Work also continued very briskly with the `SimSymbol` abstraction, which
is really, really working out.

Closes #67.
2024-05-16 18:02:01 +02:00
Sofus Albert Høgsbro Rose 060f54bd94
feat: expr constant w/viz fixes
Driven solely by the Expr socket, we've completely replaced the
dedicated NumberConstant and PhysicalConstant nodes. We also
demonstrated symbolic variable operations w/visualization and
end-node realization, validating that this approach to Expr sockets is
key.

We prepared for a new `BLPropType`, namely dynamic lists of dataclasses,
which will represent dynamic user-adjustable lists. This is the only
proper UI design for declaring symbols directly in an Expr node.
For now, we'll do without symbols, but will be a core feature for design
space exploration (aka. batch-run a bunch of sims), and for inverse
design.

Else, a few fixes: Naming of `ManagedBLImage` was updated, the expr
socket info display was fixed to display even when only output
information is available,

A few TODOs remain in the Expr Constant, but they are less important
before dynamic symbol declarations are in place.
2024-05-16 13:01:37 +02:00
Sofus Albert Høgsbro Rose 92be84ec8a
feat: perm monitor, enh. monitors, sim node naming
We greatly enhanced the field, flux monitors, and added the permittivity
monitor.

mobj naming is still a bit borked; we need a node-tree bound namespace
to go further with it.
For now, don't duplicate nodes, and don't use multiple node trees.
2024-05-16 11:06:18 +02:00
Sofus Albert Høgsbro Rose af358a4d32
fix: reordered init to suppress warnings and unit-conversion fix 2024-05-15 14:08:00 +02:00
Sofus Albert Høgsbro Rose c9936b8942
feat: big refactor to fight fundamental crashes
Some rather foundational things were fundamentally broken, especially related to the initialization procedures of fields / cached properties.

- We completely revamped `bl_cache`, fixing many to-be-discovered bugs.
- We completely streamlined `BLField` property logic into reusable
  `bl_cache.BLProp` and `bl_cache.BLPropType`.
- We implemented `BLInstance` superclass to handle ex. deterministic
  persistance of dynamic enum items, and other nuanced common
  functionality that was being duplicated raw.
- We implemented inter `cached_bl_property` / `BLField` dependency
  logic, including the ability to invalidate dynamic enums without
  @on_value_changed logic. This **greatly** simplifies a vast quantity
  of nodes that were traditionally very difficult to get working due to
  the sharp edges imposed by needing manual invalidation logic.
- We gave `ExprSocket` a significant usability upgrade, including
  thorough parsing logic in the `SocketDef`.

It's not that existing nodes are as such broken, but their existing bugs
are now going to cause problems a lot faster.
Which is a good thing.

BREAKING CHANGE: Closes #13. Closes #16. Big work on #64. Work on #37.
2024-05-15 12:37:38 +02:00
Sofus Albert Høgsbro Rose 9f8ff33e4f
feat: implement plane wave node w/viz
the visualization of Tidy3D's spherical coordinates was exceptionally harsh. See #63 for more information.

Closes #63.
2024-05-06 22:11:05 +02:00
Sofus Albert Høgsbro Rose b0db0ca072
fix: fix import and remove some TODOs
We're slowly migrating all the random sprinkled TODOs into actual, trackable issues, so we actually have a change of keeping an overview.
2024-05-05 09:51:17 +02:00
Sofus Albert Høgsbro Rose c5f438bb87
docs: added license headers to all files
It's recommended to add license headers to all files in an AGPL project, in case a file is viewed outside the context of its main repository. We're using a `pre-commit` tool to manage this, to make sure it's consistently applied to all our Python files.
2024-05-04 22:29:40 +02:00
Sofus Albert Høgsbro Rose a7e3c17c86
refactor: applied tooling for predictable lint/fmt/commits
Applied `rye lint --fix`, `rye fmt`, and commitizen checking to better control the project development.
2024-05-04 20:08:33 +02:00
Sofus Albert Høgsbro Rose 9df0d20c68
feat: Finished Gaussian Pulse node.
Also fixed several bugs along the way.
Full speed aheaad on the sources!
2024-05-02 20:59:30 +02:00
Sofus Albert Høgsbro Rose 7263d585e5
fix: Inching closer.
I'm of the belief that the correct abstractions are now actually
available, and that most-to-all of the required functionality actually
already exists within the code base.
The art is bringing it together!
2024-05-01 13:54:16 +02:00
Sofus Albert Høgsbro Rose e330b9a451
refactor: Huge simplifications from ExprSocket 2024-04-30 18:42:46 +02:00
Sofus Albert Høgsbro Rose 80d7b21c34
refactor: Big breakthrough on Expr socket (non working) 2024-04-28 18:02:54 +02:00
Sofus Albert Høgsbro Rose 4e1eb19a88
feat: Use `canvas.draw()` for plotting.
The performance difference isn't as clear cut as hoped.
However, the plotting procedure is enormously more straightforward, and
performance is more predictable.
So it's worth it.

We're managing to perfectly reuse figure/canvas/axis, but still hovering at around 70-80ms.
Mind you, the tested machine is an older laptop.
Still, things feel interactive enough, especially together with the
other modifications.

To really amp it up, we can look into blitting. It requires alterations
to the plotting methodology, but it offers a cached approach to drawing
only altered pixels (the bottleneck with `canvas.draw()` is that it
needs to render all the pixels, every time).

We can also try to lower the resolution if it's too slow.
2024-04-27 03:09:47 +02:00
Sofus Albert Høgsbro Rose b2a7eefb45
feat: Implemented operate math node. 2024-04-26 17:22:55 +02:00
Sofus Albert Høgsbro Rose 7d944a704e
ui: Data socket UI is now spiffy. 2024-04-25 09:56:21 +02:00
Sofus Albert Høgsbro Rose badadfbfc2
fix: Extract fixes incl. draw, array-copy on export. 2024-04-24 19:06:15 +02:00
Sofus Albert Høgsbro Rose c82862dde9
fix: Implement explicit no-flow w/FlowSignal 2024-04-24 18:36:29 +02:00
Sofus Albert Høgsbro Rose a3defd3c1c
feat: Complete matplotlib plotting system.
The Viz node now detects the shape of the data, and presents compatible
plot options.
Not all are implemented, but a few quite important ones are.

Additionally, a number of dataflow-related bugs were investigated and
fixed. A few were truly damaging, but many simply resulted in gross
inefficiencies - we must be careful declaring BLFields that are updated
in hot loops!

Moreover, it is exceptionally easy to add more as needed, as we analyze
more and more sims.
The only limit is `matplotlib`, which is... well, yeah.

Due to the BLField work, the dynamicness of the Viz node is quite
under control, so there will not be any critical issues there.

The plotting lags (70ms total in the hot loop), but that's actually
entirely fixeable.
It's also entirely the `managed_bl_image`'s fault.
Fixing these inefficiencies will also make Tidy3D's builtin plots
near-realtime, incidentally.

We profiled the following currently:
- 25ms: Creating `fig = plt.subplots`. We can reuse fig per-managed
  image.
- 43ms: The BytesIO roundtrip, including `savefig`. We can instead use
  the Agg backend, `fig.canvas.draw()`, and a `np.frombuffer` to both
  plot directly to the memory location,
- ~3ms: Actual plotting functions in `image_ops`. They are seriously fast.
- ~0ms: Blitting pixels to the Blender image - this was optimized in
  4.1, and it shows; the time to copy the data over is essentially nothing.
2024-04-23 19:27:45 +02:00
Sofus Albert Høgsbro Rose e7d3ecf48e
fix: Crashes on enum changes 2024-04-23 11:51:24 +02:00
Sofus Albert Høgsbro Rose f09b58e0e7
fix: BLFields in FilterMath, bug fixes. 2024-04-23 09:30:26 +02:00
Sofus Albert Høgsbro Rose 44d61b5639
feat: Safe, practical BLField.
BLField has gotten a huge facelift, to make it practical to wrangle
properties without the sharp edges.
- All the "special" UI-exposed property types can now be directly
  constructed in a BLField marked with 'prop_ui'.
- The most appropriate internal representation will be chosen to
  represent the attribute based on its type annotation, including sized
  vector-like `bool`, `int`, `float` for `tuple[...]`.
- Static EnumProperties can now be derived from a special `StrEnum`, to
  which a `to_name` and `to_icon` method is attached.
- Dynamic `EnumProperty` can now be used safely, with builtin
  workarounds to the real-world reference-loss-crash (realized
  in the Tidy3D Cloud Task node) and jankiness like empty enum.
- The update method is now fully managed, negating all bugs related to
  improper update callback naming.
- Python-side getter caching is preserved for ui-exposed
  properties, with the help of node/socket base class support for
  passing a `Signal.InvalidateCache` to BLFields that are altered in the
  UI.

The cost to all this niceness is rather low, and arguably, positive:
- Dynamic Enum/String searchers no longer "magically" invoke all the
  time, since the values seen by Blender are cached by the BLField.
- To regenerate the searcher output, an `@on_value_changed` should be
  made by the user to pass `Signal.ResetEnumItems` or
  `Signal.ResetStrSearch` to the `BLField`.
- Since searching is no longer eager, there is no danger of
  out-of-reference strings (which crash Blender from EnumProperty), but
  also a greatly reduced performance problems associated with
  the hot-loop regeneration of EnumProperty strings.
- The base classes are now involved with BLField invalidation, to ensure
  that the getter caches are cleared up when the UI changes. For the
  price of that small indirection (done cheaply with set lookup),
  all attribute lookups are generally done in a single lookup, completely
  avoiding Blender until needed.
- This does represent another increase in confidence wrt. the event
  system's integrity, but so far, that has been a very productive
  direction.

**NOTE**: The entire feature set of BLField is not well tested, and will
likely need adjustments as the codebase is converted to use them.
2024-04-23 07:55:54 +02:00
Sofus Albert Høgsbro Rose b4d6eae036
feat: High-performance math system and depsflow.
Enormously important changes to the data flow semantics and invalidation
rules. Especially significant is the way in which the node graph
produces a deeply composed function, compiles it to optimized machine
code with `jax`, and uses a seperately cached data flow to insert values
into the function from anywhere along the node graph without recompiling
the function.

A critical portion of the math system, namely the unit-aware dimensional
representation, is also finished. The `Data` node socket type now
dynamically reports the dimensional properties of the object flowing
through it, courtesy the use of a seperate data flow for information.
This allows for very high-peformance unit-aware nearest-value indexing built on binary
search.

Also, dependency management is completely ironed out. The `pip install`
process now runs concurrently, and the installation log is parsed in the
background to update a progress bar. This is the foundational work for a
similar concurrent process wrt. Tidy3D progress reporting.
2024-04-22 15:26:15 +02:00
Sofus Albert Høgsbro Rose 9960cd3480
refactor: Big changes to data flow and deps loading 2024-04-19 16:53:24 +02:00
Sofus Albert Høgsbro Rose ff5d71aeff
refactor: More changes to docs/layout 2024-04-18 08:42:53 +02:00
Sofus Albert Høgsbro Rose 8dece384ad
refactor: Moved contracts + fixes 2024-04-17 18:36:11 +02:00
Sofus Albert Høgsbro Rose c6e00dcd7b
refactor: Fixes and movement. 2024-04-17 18:14:14 +02:00
Sofus Albert Høgsbro Rose dfeb65feec
feat: Math nodes (non-working) 2024-04-17 16:03:15 +02:00
Sofus Albert Høgsbro Rose 568fc449e8
fix: Caching now (seems to) work robustly.
The serialization routines are fast and effective.
Overall, the node graph feels snappy, and everything updates smoothly.
Logging on the action chain suggests that there aren't extraneous calls,
and that existing calls (ex. no-op previews) are fast.

There will likely be edge cases, and we'll see how it scales - but
for now, let's go with it!
2024-04-15 19:15:20 +02:00
Sofus Albert Høgsbro Rose 269af4ba32
refactor: Ran lint fix 2024-04-15 17:49:53 +02:00
Sofus Albert Høgsbro Rose 4f6bd8e990
refactor: Revamped serialization (non-working) 2024-04-15 17:46:31 +02:00
Sofus Albert Høgsbro Rose 3def85e24f
refactor: Non-working first-move of serialization logic 2024-04-15 15:21:13 +02:00
Sofus Albert Høgsbro Rose 56abb3fb46
feat: Scientific constant node. 2024-04-09 10:37:50 +02:00
Sofus Albert Høgsbro Rose 02c63e3b8f
fix: The rabid __mp_main__ segfault. 2024-04-07 18:39:27 +02:00
Sofus Albert Høgsbro Rose c2db40ca6d
fix: Broken GN unit evaluation 2024-04-03 10:13:10 +02:00
Sofus Albert Høgsbro Rose a282d1e7ef
fix: @base event callbacks now use @events 2024-04-02 20:49:57 +02:00
Sofus Albert Høgsbro Rose 01cfc61094
feat: Fixes for cloud tasks, lint run 2024-04-02 20:39:55 +02:00
Sofus Albert Høgsbro Rose 505a12fa25
fix: Bugs related to geonodes, end-of-chain unit conversion 2024-04-02 16:40:02 +02:00
Sofus Albert Høgsbro Rose 221d5378e4
feat: ManagedObj Semantics 2024-04-01 16:48:56 +02:00
Sofus Albert Høgsbro Rose 6f665b891d
feat: Working logging, before- and after-deps.
We have a far more sane approach to nodeps now, which
allows us to essentially have two loggers - one that is
very useful, pretty, and clear, but requires a 'rich'
dependency, and one that is simple.
In this spirit, we factored out services/ too.

We can also set the initial console log level now when
packing the .zip.

There's still work to do with the actual flow for deps
installing / uninstalling.
But it should be far more robust now.

Finally, we have a barebones working `quartodoc`-based docs site.
It's super clever; see <https://github.com/machow/quartodoc>.
As it's "just" a quarto project with some python autodiscovery,
fleshing it out with ex. math, images, diagrams, and so forth
should be exceptionally easy.

As we develop, various linter-guided fixes are being realized.
This will be a long process, best done as we spiff everything up
in preparation for general release.
2024-03-21 18:45:38 +01:00
Sofus Albert Høgsbro Rose 0fbf201d08
chore: Ran code formatter over all files 2024-03-20 12:56:50 +01:00
Sofus Albert Høgsbro Rose be4eec2242
feat: Completely revamped dependency system. 2024-03-20 12:55:40 +01:00