Skip to content

Conversation

@jbcaillau
Copy link
Member

@jbcaillau jbcaillau commented Jan 9, 2026

subtask from #204

  • check that rhs has size n
  • add dynamics given by ranges, as for fun (+ some checks, probably redundant with those in CTModel for :fun)

jbcaillau and others added 12 commits January 6, 2026 11:11
…lgebra support

Refactored test/exa_linalg.jl into a proper Julia module providing trait-based linear algebra extensions for Array{ExaModels.AbstractNode}. Extended operations to include trace, norms, determinant, array addition/subtraction, and diagonal operations. Added comprehensive unit tests in test/test_exa_linalg.jl covering all operation combinations with 164 passing tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
… (wrapper based) extensions, all inside test (no pollution of CTParser / external add-on)
Eliminated all 23 method ambiguities by restricting type parameters to
Number or AbstractNode types, preventing conflicts with LinearAlgebra,
SparseArrays, and other standard library methods.

Changes:
- Narrowed Scalar × Vector/Matrix operations to use Number instead of Any
- Narrowed Vector/Matrix × Scalar operations to use Number instead of Any
- Added explicit methods for AbstractNode × AbstractNode cases
- Applied same pattern to dot, matrix-vector, matrix-matrix products
- Applied same pattern to vector/matrix addition and subtraction
- Applied same pattern to adjoint vector × matrix operations

All 164 tests pass, zero ambiguities detected.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added 43 new tests verifying all ambiguity fixes work correctly.

New testset "Method ambiguity fixes" includes:
- Scalar × Vector (both AbstractNode)
- Vector × Scalar (both AbstractNode)
- Scalar × Matrix (both AbstractNode)
- Matrix × Scalar (both AbstractNode)
- dot product (both AbstractNode)
- Matrix × Vector (both AbstractNode) - the originally reported issue!
- Matrix × Matrix (both AbstractNode)
- Adjoint Vector × Matrix (both AbstractNode)
- Vector + Vector (both AbstractNode)
- Vector - Vector (both AbstractNode)
- Matrix + Matrix (both AbstractNode)
- Matrix - Matrix (both AbstractNode)
- Mixed operations (no standard library conflicts)

All 207 tests pass (increased from 164).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implement optimization rules for operations involving zero values:
- Multiplication: 0 * x and x * 0 return Null(0)
- Addition: 0 + x and x + 0 return x (identity)
- Subtraction: x - 0 returns x (identity)

Added helper functions:
- is_zero_value(x): detects zeros in Number, Null, and AbstractNode
- zero_node(): returns canonical Null(0)

Optimized 24 methods:
- 12 scalar-vector/matrix multiplication methods
- 6 vector/matrix addition methods
- 6 vector/matrix subtraction methods

Benefits:
- Simpler expression trees (fewer Node2 allocations)
- Type stability maintained (all return AbstractNode types)
- Proper mathematical identities respected

All 287 tests passing (added 43 new optimization tests).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace scattered zero checks with unified optimized scalar operations:
- Add is_zero/is_one detection using iszero/isone for all numeric types
- Use Null(nothing) as canonical zero (per ExaModels graph.jl line 313)
- Add Null(1) as canonical one for multiplicative identity
- Implement opt_add, opt_sub, opt_mul, opt_sum core operations
- Refactor all vector/matrix ops to use these primitives

Key optimization: dot([1,0,1,0], [x,y,z,t]) now produces x+z instead
of bloated expression tree with unnecessary zero terms.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add sum(::AbstractArray{<:AbstractNode}) wrapper around opt_sum
- Update convert to return zero_node() for zero values (canonical)
- Keep opt_* functions internal (not exported) following Julia best practices
- Import opt_* explicitly in tests for testing internal functions
- Update module documentation to clarify public vs internal API
- Remove exa_linalg_w files (obsolete)

sum([zero_node(), x, zero_node(), y]) now returns x + y directly,
skipping zeros during summation for optimal expression trees.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jbcaillau jbcaillau requested a review from ocots January 9, 2026 17:53
@jbcaillau jbcaillau self-assigned this Jan 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Breakage test results
Date: 2026-01-14 23:10:10

Name Latest Stable
OptimalControl compat: v0.7.2 compat: v0.7.2

jbcaillau and others added 8 commits January 9, 2026 19:19
- Fixed p_dynamics_exa! to populate dyn_coords when using vector-form dynamics ∂(x)(t) == [e1, e2, ...]
- Added comprehensive test suite (400 tests) in test/test_dynamics_exa.jl covering:
  * All numerical schemes (euler, euler_implicit, midpoint, trapeze)
  * Both CPU and GPU backends
  * Basic dynamics, sums, user functions, nonlinear systems
  * Classic control problems (double integrator, 9D drone)
- Registered dynamics_exa test suite in runtests.jl

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- add 9 unit tests for p_dynamics_exa! covering code generation, various
  expressions, time-dependent dynamics, and vector operations
- add 14 tests for ParsingInfo fields (is_global_dyn, is_coord_dyn, dyn_coords)
  including mutual exclusion and duplicate detection
- fix test_onepass_fun objectives to properly test dynamics parsing
- all 176 tests pass successfully

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jbcaillau
Copy link
Member Author

@ocots not having CTBase 0.17 is now breaking to make the documentation
https://github.com/control-toolbox/CTParser.jl/actions/runs/21012454996/job/60410418917?pr=205

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