-
-
Notifications
You must be signed in to change notification settings - Fork 114
Add documentation for undocumented SciMLBase API components #1107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChrisRackauckas
merged 7 commits into
SciML:master
from
ChrisRackauckas-Claude:docs/api-documentation-additions
Aug 15, 2025
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
184851c
Add documentation for undocumented SciMLBase API components
ChrisRackauckas de8e171
Enhance documentation with additional API coverage and examples
ChrisRackauckas 46f3f2a
Refactor documentation approach: use docstrings instead of separate docs
ChrisRackauckas a876813
Remove remaining standalone documentation pages per review feedback
ChrisRackauckas 44ed8d4
Delete docs/src/assets/Project.toml
ChrisRackauckas 4a99e3e
Delete docs/src/interfaces/ClockSystem.md
ChrisRackauckas 01b77f9
Update docs/pages.jl
ChrisRackauckas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,262 @@ | ||
| # Clock and Timing System | ||
|
|
||
| SciMLBase provides a sophisticated clock and timing system for discrete-time models, hybrid systems, and event-driven simulations. This system enables precise control over when events occur and how different time domains interact within complex models. | ||
|
|
||
| ## Overview | ||
|
|
||
| The clock system is designed to handle: | ||
| - Discrete-time models with regular sampling | ||
| - Event-driven systems with irregular timing | ||
| - Hybrid continuous-discrete systems | ||
| - Multi-rate systems with different time scales | ||
| - Scheduled events and periodic triggers | ||
|
|
||
| ## Abstract Clock Types | ||
|
|
||
| ### Core Abstractions | ||
|
|
||
| ```julia | ||
| abstract type TimeDomain end | ||
| abstract type Clocks end | ||
| ``` | ||
|
|
||
| These form the foundation of the clock system: | ||
| - `TimeDomain`: Represents different types of time domains (continuous, discrete, etc.) | ||
| - `Clocks`: Base type for all clock implementations | ||
|
|
||
| ## Concrete Clock Types | ||
|
|
||
| ### ContinuousClock | ||
|
|
||
| ```julia | ||
| ContinuousClock() | ||
| ``` | ||
|
|
||
| Represents continuous time domains where events can occur at any real-valued time instant. This is the default for continuous differential equations. | ||
|
|
||
| ### PeriodicClock | ||
|
|
||
| ```julia | ||
| PeriodicClock(period) | ||
| ``` | ||
|
|
||
| Creates a clock that triggers at regular intervals. | ||
|
|
||
| **Arguments:** | ||
| - `period`: The time interval between clock ticks | ||
|
|
||
| **Use Cases:** | ||
| - Discrete-time control systems | ||
| - Regular sampling of continuous signals | ||
| - Periodic boundary conditions | ||
|
|
||
| ### SolverStepClock | ||
|
|
||
| ```julia | ||
| SolverStepClock() | ||
| ``` | ||
|
|
||
| A clock that triggers at every solver step. This is useful for monitoring solver progress or implementing step-dependent logic. | ||
|
|
||
| ### EventClock | ||
|
|
||
| ```julia | ||
| EventClock(condition, affect!) | ||
| ``` | ||
|
|
||
| A clock that triggers when a specified condition is met. | ||
|
|
||
| **Arguments:** | ||
| - `condition`: Function that returns true when the event should trigger | ||
| - `affect!`: Function to execute when the event occurs | ||
|
|
||
| **Use Cases:** | ||
| - State-dependent events | ||
| - Threshold crossing detection | ||
| - Condition-based state changes | ||
|
|
||
| ## Clock Properties and Traits | ||
|
|
||
| ### Time Domain Classification | ||
|
|
||
| ```julia | ||
| is_discrete_time_domain(clock) | ||
| iscontinuous(clock) | ||
| ``` | ||
|
|
||
| - `is_discrete_time_domain`: Returns `true` if the clock operates in discrete time | ||
| - `iscontinuous`: Returns `true` if the clock operates in continuous time | ||
|
|
||
| ### Clock Type Checking | ||
|
|
||
| ```julia | ||
| isclock(obj) | ||
| issolverstepclock(clock) | ||
| ``` | ||
|
|
||
| - `isclock`: Returns `true` if the object is a valid clock | ||
| - `issolverstepclock`: Returns `true` if the clock triggers on solver steps | ||
|
|
||
| ## Indexed Clock System | ||
|
|
||
| ### IndexedClock | ||
|
|
||
| ```julia | ||
| IndexedClock(base_clock, index) | ||
| ``` | ||
|
|
||
| Wraps a base clock with an index for use in multi-clock systems. | ||
|
|
||
| **Arguments:** | ||
| - `base_clock`: The underlying clock | ||
| - `index`: Unique identifier for this clock instance | ||
|
|
||
| ### Clock Canonicalization | ||
|
|
||
| ```julia | ||
| canonicalize_indexed_clock(clock) | ||
| ``` | ||
|
|
||
| Converts clocks to their canonical indexed form for consistent internal representation. | ||
|
|
||
| ## Usage Patterns | ||
|
|
||
| ### Simple Periodic Sampling | ||
|
|
||
| ```julia | ||
| using SciMLBase | ||
|
|
||
| # Create a periodic clock with 0.1 time unit intervals | ||
| clock = PeriodicClock(0.1) | ||
|
|
||
| # Use in a discrete problem | ||
| function discrete_update!(u, p, t, clock) | ||
| if isclock(clock) && is_discrete_time_domain(clock) | ||
| u[1] = u[1] * 0.9 # Decay | ||
| u[2] = u[2] + sin(t) # Periodic forcing | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| ### Event-Driven Systems | ||
|
|
||
| ```julia | ||
| # Create an event clock that triggers when x > 1.0 | ||
| event_condition(u, t, integrator) = u[1] - 1.0 | ||
| event_affect!(integrator) = integrator.u[1] = 0.0 | ||
|
|
||
| event_clock = EventClock(event_condition, event_affect!) | ||
|
|
||
| # Use with hybrid systems | ||
| ``` | ||
|
|
||
| ### Multi-Rate Systems | ||
|
|
||
| ```julia | ||
| # Different clocks for different subsystems | ||
| fast_clock = PeriodicClock(0.01) # Fast dynamics | ||
| slow_clock = PeriodicClock(0.1) # Slow dynamics | ||
| event_clock = EventClock(condition, affect!) # Event-driven | ||
|
|
||
| # Indexed for system identification | ||
| clocks = [ | ||
| IndexedClock(fast_clock, 1), | ||
| IndexedClock(slow_clock, 2), | ||
| IndexedClock(event_clock, 3) | ||
| ] | ||
| ``` | ||
|
|
||
| ### Solver Step Monitoring | ||
|
|
||
| ```julia | ||
| # Monitor every solver step | ||
| step_clock = SolverStepClock() | ||
|
|
||
| function monitor_steps(integrator) | ||
| if issolverstepclock(step_clock) | ||
| println("Step: $(integrator.step), Time: $(integrator.t)") | ||
| # Log solution values, check convergence, etc. | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| ## Integration with Problem Types | ||
|
|
||
| ### Discrete Problems | ||
|
|
||
| ```julia | ||
| using SciMLBase | ||
|
|
||
| function discrete_dynamics!(u_next, u, p, t, clock) | ||
| # Clock-dependent discrete update | ||
| if is_discrete_time_domain(clock) | ||
| u_next[1] = p[1] * u[1] + p[2] * u[2] | ||
| u_next[2] = p[3] * u[1] + p[4] * u[2] | ||
| end | ||
| end | ||
|
|
||
| # Problem with explicit clock | ||
| prob = DiscreteProblem(discrete_dynamics!, u0, tspan, p, | ||
| clock = PeriodicClock(0.1)) | ||
| ``` | ||
|
|
||
| ### Hybrid Systems | ||
|
|
||
| ```julia | ||
| # Continuous dynamics with discrete events | ||
| function hybrid_dynamics!(du, u, p, t) | ||
| du[1] = -u[1] + u[2] # Continuous part | ||
| du[2] = -2*u[2] + u[1] | ||
| end | ||
|
|
||
| # Event clock for state jumps | ||
| jump_condition(u, t, integrator) = u[1] - 2.0 | ||
| jump_affect!(integrator) = integrator.u[2] += 1.0 | ||
|
|
||
| hybrid_clock = EventClock(jump_condition, jump_affect!) | ||
| ``` | ||
|
|
||
| ## Advanced Features | ||
|
|
||
| ### Clock Synchronization | ||
|
|
||
| ```julia | ||
| # Synchronize multiple clocks | ||
| function synchronize_clocks(clocks) | ||
| canonical_clocks = [canonicalize_indexed_clock(c) for c in clocks] | ||
| # Implementation depends on specific synchronization requirements | ||
| return canonical_clocks | ||
| end | ||
| ``` | ||
|
|
||
| ### Dynamic Clock Modification | ||
|
|
||
| ```julia | ||
| # Dynamically change clock periods | ||
| mutable struct AdaptiveClock <: Clocks | ||
| base_period::Float64 | ||
| current_period::Float64 | ||
| adaptation_rule::Function | ||
| end | ||
|
|
||
| function update_clock!(clock::AdaptiveClock, system_state) | ||
| clock.current_period = clock.adaptation_rule(system_state) | ||
| end | ||
| ``` | ||
|
|
||
| ## Performance Considerations | ||
|
|
||
| - **Clock Overhead**: Frequent clock checks can impact performance; use appropriate clock types for your application | ||
| - **Event Detection**: Event clocks require root-finding which can be computationally expensive | ||
| - **Memory Usage**: Multiple clocks in large systems should be managed efficiently | ||
| - **Synchronization**: Multi-clock systems may require careful synchronization for deterministic behavior | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Choose Appropriate Clock Types**: Use `PeriodicClock` for regular sampling, `EventClock` for condition-based events | ||
| 2. **Minimize Clock Frequency**: Higher frequency clocks increase computational overhead | ||
| 3. **Index Clocks**: Use `IndexedClock` for systems with multiple clock domains | ||
| 4. **Test Clock Logic**: Verify clock behavior with simple test cases before complex integration | ||
| 5. **Monitor Performance**: Profile clock-dependent systems to ensure acceptable performance | ||
|
|
||
| The clock system provides powerful tools for modeling complex temporal behavior in scientific simulations while maintaining the performance and reliability expected from the SciML ecosystem. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.