Replies: 3 comments
-
|
@ocots priority on
|
Beta Was this translation helpful? Give feedback.
-
CTFlows.jl V3 Refactoring PlanningIssue: #143 - [Dev] Refactoring TL;DRRefactor CTFlows.jl to V3 architecture: remove type wrappers from differential geometry tools, simplify Flow API to OCP and ODEFunction only, implement SciMLBase extension with helpful stubs, and introduce multi-phase concatenation with solution merging. This will result in a simpler, more performant, and more maintainable codebase aligned with the V3 architecture report. 1. OverviewGoalImplement the V3 architecture for CTFlows.jl as documented in
Key Features
References
2. User Stories
3. Technical Decisions
4. TasksPhase 1: Differential Geometry Refactoring
Phase 2: Flow API Simplification
Phase 3: Extension and Stub Implementation
Phase 4: Multi-Phase Concatenation
Phase 5: Documentation and Migration
5. Testing GuidelinesTest file structure# test/test_<feature>.jl
function test_<feature>()
# ========================================================
# Unit tests – helper logic (no side effects)
# ========================================================
@testset "<feature> helpers" begin
# Test individual helper functions
end
# ========================================================
# Integration tests – actual functionality
# ========================================================
@testset "<feature> integration" begin
# Test full feature with real OCP/ODEFunction
end
endKey test files to update
6. Test Commands# Run all tests
julia --project=. -e 'using Pkg; Pkg.test("CTFlows");'
# Run specific test file
julia --project=. test/test_differential_geometry.jl
# Run with coverage
julia --project=. --code-coverage=user -e 'using Pkg; Pkg.test("CTFlows");'7. Coverage TestingCoverage commandjulia --project=. --code-coverage=user -e 'using Pkg; Pkg.test("CTFlows");'Target≥ 90% coverage for refactored code. Iteration process
8. GitHub WorkflowStructureChecklist for Issue #143
9. MVP (Minimum Viable Product)MVP = Phase 1 + Phase 2 + Phase 3 The MVP includes:
Not in MVP (deferred to later phases):
10. Breaking ChangesAPI Changes
Deprecation Strategy
11. Risk Assessment
12. Success Criteria
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
CTFlows.jl - Architecture and Use Cases (V3)
This document describes the architecture and use cases for
CTFlows.jlversion 3.1. Overview
CTFlows.jlprovides a unified interface for computing flows (time evolution) of dynamical systems arising from:SciMLBase.ODEFunctionThe package emphasizes:
2. Use Cases
2.1 Flow from an Optimal Control Problem (OCP)
The primary use case is computing flows from an OCP with different control specifications.
UC1.1: Dynamic Feedback (Default)
UC1.2: State Feedback
UC1.3: Open Loop
UC1.4: Regular Case with Constraints
UC1.5: Regular Case via Implicit Function Theorem
2.2 Flow from an ODEFunction
For general ODEs already defined using SciML's
ODEFunction. We support both out-of-place and in-place signatures.2.3 Options Management
Options are lightweight and can be defined at creation or overridden at call time.
2.4 Flow Concatenation
Type Constraint
Flows can only be concatenated if they are of the same strict type:
:state_feedback, both:dynamic_feedback, etc.)ODEFunctionThis constraint is enforced via type parameters that track the flow's origin.
Concatenation Syntax
Outputs
2.5 Autonomy and Variable Handling
Automatic Detection from OCP
The flow call signature is automatically determined from the OCP properties:
CTModels.is_autonomous(ocp)CTModels.variable_dimension(ocp) > 0The control function
umust respect the OCP's autonomy:u(x),u(x, p), oru(x, p, v)u(t, x),u(t, x, p), oru(t, x, p, v)Variable Argument
vThe variable
vin flow calls depends on the OCP configuration:Case 1: No variable (
variable_dimension(ocp) == 0)Case 2: Variable is
tf(has_free_final_time(ocp) && variable_dimension(ocp) == 1)Case 3: Variable is
t0(has_free_initial_time(ocp) && variable_dimension(ocp) == 1)Case 4: Variable is
[t0, tf](has_free_initial_time(ocp) && has_free_final_time(ocp) && variable_dimension(ocp) == 2)Case 5: External variable (other cases)
Overriding Autonomy
You can override the OCP's autonomy for the control function using named arguments:
Similarly, you can override the variable dependency:
2.6 Differential Geometry Tools
CTFlows.jlprovides a comprehensive library of differential geometry primitives for optimal control. These tools enable direct implementation of Pontryagin's Maximum Principle formulas without manual computation of partial derivatives.Design Philosophy: No Type Wrappers
All differential geometry tools work with pure
Functionobjects — there are no type wrappers likeHamiltonian,VectorField, orHamiltonianLift. This design choice provides:FunctionobjectsThe only "types" are mathematical conventions:
Functionthat mapsx → ℝⁿFunctionthat maps(x, p) → ℝFunctionthat mapsx → ℝAvailable Tools
Lift(f)Function → Functionf:(x, p) → p' * f(x)Lift(f; autonomous, variable)Function → Functionad(X, f; autonomous, variable)(Function, Function) → Functionfscalar, Lie bracket iffvector∂ₜ(f)Function → Function(t, args...) → ∂f/∂tPoisson(H, G; autonomous, variable)(Function, Function) → Function{H,G}(x,p) = ∇ₚH'·∇ₓG - ∇ₓH'·∇ₚG@Lie [X, Y]CTFlows.ad(X, Y))@Lie {H, G}CTFlows.Poisson(H, G))@Lie {H, G} autonomous=falseExample: Goddard Problem
The Goddard tutorial demonstrates practical usage of these tools for computing singular and boundary arc controls.
1. Hamiltonian Lift
2. Poisson Brackets for Singular Control
3. Lie Derivative for Boundary Control
4. Multiplier for State Constraint
Mathematical Formulas
Hamiltonian Lift
Lie Derivative
Lie Bracket
Poisson Bracket
where$J_Y$ is the Jacobian matrix of $Y$ .
Implementation Details
No Type Dispatch: All operators work directly on
Functionobjects:Prefix System: The
@Liemacro uses a configurable prefix (default:CTFlows):Automatic Differentiation: All derivatives are computed using
ForwardDiff.jlvia thectgradientandctjacobianutilities.Macro Magic: The
@Liemacro provides mathematical notation while dispatching to the appropriate function:3. Internal Machinery
This section describes the internal architecture using Option 1: Implicit Dispatch on Algorithm Type.
3.1 Core Design Principles
SciMLBase.jlextension only (triggered byusing SciMLBase)_ode_problemand_solveare stubs insrc/that error with helpful messagesSciMLBase(viaOrdinaryDiffEq,SimpleDiffEq, orDifferentialEquations) activates the extension3.2 Extension Loading Strategy
Stubs in
src/CTFlows.jlExtension Override in
ext/CTFlowsSciMLBaseExt.jl3.3 Multi-Phase Flow Concatenation
When flows are concatenated, a
MultiPhaseSystemis created that manages phase transitions.Internal Representation
Point Evaluation Logic
For point evaluation
xf, pf = f(t0, x0, p0, tf, v):Complete Solution Logic
For complete solution
sol = f((t0, tf), x0, p0, v):Solution Merging (Extension)
The merging logic is delegated to the SciMLBase extension, following the pattern from
DiffEqParamEstim.jl:3.4 Summary of Internal Types
Flow{S<:AbstractSystem}AbstractSystem{T}T(e.g.,:state_feedback)MultiPhaseSystem{S}_ode_problem(system, ...)src/, overridden in extension_solve(problem, alg, options)src/, overridden in extension_merge_solutions(solutions, mps)src/, overridden in extensionbuild_solution(raw_sol, system)3.5 Pseudo-code Call Graphs
1. Simple Flow Creation
2. Point Evaluation
3. Complete Solution
4. Concatenation (Point)
5. Concatenation (Solution)
4. Design Decisions (V3)
HamiltonianFeedback,StateFeedback, etc., are removed from the public API.:hamiltonianare not used for dispatch in the factory; the type of the first argument and positional control argument are sufficient.:state_feedback,:dynamic_feedback, etc.) is a positional argument, not a named argument. Named arguments are reserved for solver options.rhs!must be robust to the shape of the input state.NamedTuplemerging, noOCPTooloverhead.SciMLBaseextension providesODEProblem,solve, and solution merging. Stubs insrc/provide helpful error messages.AbstractSystem{T}).MultiPhaseSystemwith explicit phase transitions and jumps. Solution merging follows theDiffEqParamEstim.jlpattern.5. Advantages of V3 Architecture
SciMLBaseis loaded only when needed.Flowobjects.6. Migration from V2
Key changes from V2:
Flow(ocp, u, :state_feedback)instead ofcontrol=:state_feedback)MultiPhaseSysteminstead of nestedFlowobjectsSciMLBaseinstead ofOrdinaryDiffEqDiffEqParamEstim.jlpattern7. Future Considerations
MultiPhaseSystemcan be extended to support parallel phase integrationBeta Was this translation helpful? Give feedback.
All reactions