Skip to content

Conversation

@jbcaillau
Copy link
Member

@jbcaillau jbcaillau commented Jan 6, 2026

From #182

start with going to x[i1, i2 in 1:1, k in 1:1, j] for M(n, 1, R)

  • 0:grid_size to 1:grid_size+1 to avoid discrepancy between x and x_m
  • [ ] implement operations on x_m instead of x
  • at this step, add idoneus subs to replace x(t) or x[rg](g) by x[rg, j] (should work)
  • same update can be made for u to allow u(t) -> u[:, j], etc., still with (real) vectors
  • vectorise dynamics for exa
  • vectorise constraints for exa
  •  at this step, re-write some qc tests (with tweaks / macros for matrix / complex values)
  • go for tensors (matrix + complex valued)
  • for that, use the fact that Julia vectors are indeed n x 1 matrices (v[i] == v[i, 1] for a Vector), consistently with R^n = M(n, 1, R)

jbcaillau and others added 3 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 <[email protected]>
@jbcaillau jbcaillau mentioned this pull request Jan 6, 2026
7 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

Breakage test results
Date: 2026-01-09 16:41:33

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

@jbcaillau
Copy link
Member Author

close #181 (that has been largely rethought)

jbcaillau and others added 8 commits January 7, 2026 00:32
… (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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
- 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 <[email protected]>
@jbcaillau jbcaillau marked this pull request as ready for review January 9, 2026 17:52
@jbcaillau
Copy link
Member Author

@ocots please have a look (still draft)

@jbcaillau jbcaillau mentioned this pull request Jan 9, 2026
2 tasks
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