SciML/ComponentArrays.jl

Arrays with arbitrarily nested named components.

What it solves

Many scientific computing solvers (like those for differential equations or optimization) require parameters and states to be passed as flat vectors. However, managing these flat vectors manually is error-prone and difficult to maintain, especially when composing multiple smaller models into a larger one, as it requires constant "index juggling" to track where each variable is located in the array.

How it works

ComponentArrays.jl introduces the ComponentArray type, which acts as a hybrid between a flat array and a NamedTuple. It stores data in a contiguous flat vector but allows users to access, modify, and slice that data using named indices. This allows developers to treat their data as structured, nested objects while the underlying solver receives the flat vector it expects.

Who it’s for

It is primarily designed for researchers and engineers using the SciML ecosystem (specifically DifferentialEquations.jl and Optim.jl) or any project that requires flat vectors for numerical solvers but wants to maintain a structured modeling approach.

Highlights

  • Named Access: Access array blocks via names rather than integer indices.
  • Seamless Composition: Compose standalone models by passing ComponentArray views into smaller functions.
  • Flat Vector Compatibility: Fully compatible with solvers that require standard flat vectors.
  • Automatic Dimension Expansion: Supports the creation of higher-dimensional ComponentMatrix objects through broadcasted operations.

Related

  • Project
  • Project
  • Project
  • Project
  • Project