Skip to content

Support state and input arrays of different types in linearize - #1072

Merged
baggepinnen merged 1 commit into
masterfrom
linearize-input-jacobian-conversion
Oct 1, 2026
Merged

baggepinnen merged 1 commit into
masterfrom
linearize-input-jacobian-conversion

Conversation

@baggepinnen

Copy link
Copy Markdown
Member

Summary

linearize(f, x, u, args...) computed the Jacobian with respect to the input as

B = ForwardDiff.jacobian(u -> f(convert(typeof(u), xi), u, args...), ui)

convert(typeof(u), xi) converts the state to the array type of the input. This causes two failures:

  • If the state and the input are static arrays of different lengths, it throws a DimensionMismatch, e.g., x::SVector{4} and u::SVector{2}. This occurs, for example, in ControlSystemsBase.observability(filter, x, u, p, t) for nonlinear filters of LowLevelParticleFilters.jl with static arrays.
  • It discards the array type of the state. With a ComponentArray state and a Vector input, the components are lost, and x.v in f throws a FieldError.

The state is now converted element-wise, convert.(eltype(u), xi), which keeps the container type of the state and gives its elements the dual-number type of the input.

Tests

  • Two cases were added to lib/ControlSystemsBase/test/test_hammerstein_wiener.jl: an SVector{3} state with an SVector{2} input, and a ComponentArray state with a Vector input. Both fail with the previous implementation (DimensionMismatch and FieldError) and pass with the new one.
  • The rest of test_hammerstein_wiener.jl passes. The full test suite was not run.

The ControlSystemsBase version is bumped to 1.22.1.


Host: demeter2, Claude Code session session_01Seo8ETEV7wrEk54KBJb7sy

🤖 Generated with Claude Code

https://claude.ai/code/session_01Seo8ETEV7wrEk54KBJb7sy

The Jacobian with respect to the input converted the state to the type
of the input with `convert(typeof(u), x)`. This fails when the state and
the input are static arrays of different lengths, and discards the
array type of the state, e.g., the components of a ComponentArray. The
state is now converted element-wise to the element type of the input,
which preserves the array type of the state.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Seo8ETEV7wrEk54KBJb7sy
baggepinnen added a commit to baggepinnen/LowLevelParticleFilters.jl that referenced this pull request Oct 1, 2026
…ension

The failure of linearization for static arrays of different lengths is
fixed in ControlSystemsBase.linearize instead, see
JuliaControl/ControlSystems.jl#1072.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Seo8ETEV7wrEk54KBJb7sy
@JuliaControlBot

Copy link
Copy Markdown

This is an automated message.
Plots were compared to references. 4/11 images have changed, see differences below.
After pulling this PR, please update the reference images by creating a PR to ControlExamplePlots.jl here.

Difference Reference Image New Image
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New

@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.64%. Comparing base (7e1ac64) to head (aebbfb9).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1072   +/-   ##
=======================================
  Coverage   91.64%   91.64%           
=======================================
  Files          42       42           
  Lines        5795     5795           
=======================================
  Hits         5311     5311           
  Misses        484      484           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@baggepinnen
baggepinnen merged commit 2e023d9 into master Oct 1, 2026
6 checks passed
@baggepinnen
baggepinnen deleted the linearize-input-jacobian-conversion branch October 1, 2026 13:19
baggepinnen referenced this pull request Oct 1, 2026
ControlSystemsBase requires MatrixPencils 1.8.3 or later, which requires
julia 1.8 or later, so the package could not be installed on julia 1.6.
The registration of ControlSystemsBase 1.22.1 was not merged
automatically for this reason.


Claude-Session: https://claude.ai/code/session_01Seo8ETEV7wrEk54KBJb7sy

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
baggepinnen referenced this pull request Oct 1, 2026
The julia compat lower bound was raised to 1.10 in #1073, which the
General registry does not accept in a patch release.


Claude-Session: https://claude.ai/code/session_01Seo8ETEV7wrEk54KBJb7sy

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants