Skip to content

Add comprehensive slice notation tests#251

Open
ocots wants to merge 1 commit intomainfrom
slices
Open

Add comprehensive slice notation tests#251
ocots wants to merge 1 commit intomainfrom
slices

Conversation

@ocots
Copy link
Copy Markdown
Member

@ocots ocots commented Apr 10, 2026

  • Test slices in constraints: x[1:3](0), x[1:end](0), x[1:n](0)
  • Test slices in dynamics: ∂(x[1:3])(t), ∂(x[1:end])(t), ∂(x[1:n])(t)
  • Test slices in Mayer cost: x[1:3](tf), x[1:end](tf), x[1:n](tf)
  • Mark broken tests for unsupported features (end keyword, variable n)
  • Literal integer ranges work for parsing, some broken for discretisation

- Test slices in constraints: x[1:3](0), x[1:end](0), x[1:n](0)
- Test slices in dynamics: ∂(x[1:3])(t), ∂(x[1:end])(t), ∂(x[1:n])(t)
- Test slices in Mayer cost: x[1:3](tf), x[1:end](tf), x[1:n](tf)
- Mark broken tests for unsupported features (end keyword, variable n)
- Literal integer ranges work for parsing, some broken for discretisation
@ocots
Copy link
Copy Markdown
Member Author

ocots commented Apr 10, 2026

@jbcaillau

Comprehensive Slice Notation Tests

This PR adds extensive tests for slice notation (x[...]) in different contexts of optimal control problem definitions.

Test Coverage

The test suite covers 3 main contexts where slices can appear:

  1. Constraints (initial conditions): x[...](0) == x0
  2. Dynamics: ∂(x[...])(t) == ...
  3. Mayer cost (terminal cost): x[...](tf)

For each context, we test 3 slice variants:

  • Literal integer range: x[1:3] ✅ Most reliable
  • end keyword: x[1:end] ❌ Parsing fails
  • Variable: x[1:n] where n=3 ⚠️ Context-dependent

Current Status

✅ What Works (End-to-End)

Context Slice Type Status
Constraints x[1:3](0) ✅ Parsing + Discretisation + Solve

⚠️ What Partially Works (Parsing OK, Discretisation Fails)

Context Slice Type Parsing Discretisation
Dynamics ∂(x[1:3])(t)
Dynamics ∂(x[1:n])(t)
Mayer cost x[1:3](tf)
Mayer cost x[1:end](tf)
Mayer cost x[1:n](tf)

❌ What's Broken (Parsing Fails)

Context Slice Type Error
Constraints x[1:end](0) MethodError: no method matching (::Colon)(::Int64, ::Symbol)
Constraints x[1:n](0) MethodError: no method matching (::Colon)(::Int64, ::Symbol)
Dynamics ∂(x[1:end])(t) MethodError: no method matching (::Colon)(::Int64, ::Symbol)

Key Findings

  1. Literal integer ranges (x[1:3]) work everywhere for parsing
  2. end keyword fails during parsing in constraints and dynamics contexts
  3. Variable slices (x[1:n]) work for parsing in dynamics and Mayer cost, but fail in constraints
  4. Discretisation currently only works for constraints with literal ranges

Test Structure

Each context has:

  • Model builders: Helper functions to create test problems
  • Unit tests: Verify parsing and model construction
  • Integration tests: Test discretisation and solver execution

All broken tests are marked with @test_broken to document known limitations without failing the test suite.

Next Steps

  1. High Priority: Fix end keyword support in slice parsing (affects all contexts)
  2. High Priority: Fix variable slice support (x[1:n]) in constraints
  3. Medium Priority: Fix discretisation for sliced dynamics (∂(x[1:3])(t))
  4. Medium Priority: Fix discretisation for sliced Mayer costs (x[...](tf))

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

Breakage test results
Date: 2026-04-10 14:13:39

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

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