|
| 1 | +```@meta |
| 2 | +CurrentModule = CTBase |
| 3 | +``` |
| 4 | + |
| 5 | +# Getting Started |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +CTBase.jl is typically installed as a dependency of another package in the ecosystem |
| 10 | +(e.g. [OptimalControl.jl](https://github.com/control-toolbox/OptimalControl.jl)). |
| 11 | +To install it directly: |
| 12 | + |
| 13 | +```julia |
| 14 | +import Pkg |
| 15 | +Pkg.add("CTBase") |
| 16 | +``` |
| 17 | + |
| 18 | +**Requires Julia ≥ 1.10.** |
| 19 | + |
| 20 | +## Mental Model |
| 21 | + |
| 22 | +CTBase is the **base layer** of the control-toolbox ecosystem. |
| 23 | +It provides infrastructure shared by every package above it. |
| 24 | + |
| 25 | +Three things to keep in mind: |
| 26 | + |
| 27 | +1. **No top-level exports.** `using CTBase` loads the package but brings no symbols |
| 28 | + into scope. Every symbol is accessed via its qualified path: |
| 29 | + ```julia |
| 30 | + CTBase.Descriptions.add # ✓ always works |
| 31 | + CTBase.Exceptions.NotImplemented |
| 32 | + ``` |
| 33 | +2. **Submodule-first API.** The public API lives in named submodules |
| 34 | + (`Descriptions`, `Exceptions`, `Extensions`, `Core`, `Unicode`). |
| 35 | + You can bring a submodule's exports into scope explicitly: |
| 36 | + ```julia |
| 37 | + using CTBase.Exceptions # brings IncorrectArgument, NotImplemented, … into scope |
| 38 | + ``` |
| 39 | +3. **Extension-backed features.** `run_tests`, `postprocess_coverage`, and |
| 40 | + `automatic_reference_documentation` require loading the matching weak dependency |
| 41 | + (`Test`, `Coverage`, `Documenter` respectively) before they become active. |
| 42 | + |
| 43 | +## 5-Minute Walkthrough |
| 44 | + |
| 45 | +### Working with Descriptions |
| 46 | + |
| 47 | +A *description* is a `Tuple` of `Symbol`s that declaratively identifies an algorithm |
| 48 | +or configuration. Catalogues collect known descriptions; `complete` resolves a partial |
| 49 | +description to an exact one. |
| 50 | + |
| 51 | +```@repl walkthrough |
| 52 | +using CTBase |
| 53 | +
|
| 54 | +# Build a catalogue |
| 55 | +descs = CTBase.Descriptions.add((), (:euler, :explicit)) |
| 56 | +descs = CTBase.Descriptions.add(descs, (:euler, :implicit)) |
| 57 | +descs = CTBase.Descriptions.add(descs, (:runge_kutta, :explicit)) |
| 58 | +
|
| 59 | +# Partial completion: find the unique entry containing :implicit |
| 60 | +CTBase.Descriptions.complete(:implicit; descriptions=descs) |
| 61 | +
|
| 62 | +# Ambiguous completion raises AmbiguousDescription |
| 63 | +try |
| 64 | + CTBase.Descriptions.complete(:euler; descriptions=descs) |
| 65 | +catch e |
| 66 | + println(typeof(e)) |
| 67 | +end |
| 68 | +``` |
| 69 | + |
| 70 | +For more, see the **[Descriptions guide](guide/descriptions.md)**. |
| 71 | + |
| 72 | +### Working with Exceptions |
| 73 | + |
| 74 | +CTBase defines a typed exception hierarchy rooted at |
| 75 | +[`CTBase.Exceptions.CTException`](@ref). |
| 76 | +Each type carries structured context fields for actionable error messages. |
| 77 | + |
| 78 | +```@repl walkthrough |
| 79 | +# IncorrectArgument — invalid input value |
| 80 | +try |
| 81 | + throw(CTBase.Exceptions.IncorrectArgument( |
| 82 | + "state dimension must be positive"; |
| 83 | + got="0", |
| 84 | + expected="n > 0", |
| 85 | + suggestion="Pass a positive integer for the state dimension", |
| 86 | + )) |
| 87 | +catch e |
| 88 | + println(e) |
| 89 | +end |
| 90 | +
|
| 91 | +# NotImplemented — interface stub |
| 92 | +try |
| 93 | + throw(CTBase.Exceptions.NotImplemented( |
| 94 | + "solve! is not implemented"; |
| 95 | + required_method="solve!(::MyStrategy, ocp)", |
| 96 | + suggestion="Import the package that provides this strategy", |
| 97 | + )) |
| 98 | +catch e |
| 99 | + println(typeof(e)) |
| 100 | +end |
| 101 | +``` |
| 102 | + |
| 103 | +For more, see the **[Exceptions guide](guide/exceptions.md)**. |
| 104 | + |
| 105 | +## Next Steps |
| 106 | + |
| 107 | +| Topic | Guide | |
| 108 | +|:---|:---| |
| 109 | +| Descriptions catalogue and completion | [Descriptions](guide/descriptions.md) | |
| 110 | +| Exception hierarchy and best practices | [Exceptions](guide/exceptions.md) | |
| 111 | +| Modular test runner setup | [Test Runner](guide/test-runner.md) | |
| 112 | +| Coverage report generation | [Coverage](guide/coverage.md) | |
| 113 | +| Auto-generated API reference | [API Documentation](guide/api-documentation.md) | |
| 114 | +| Full API reference | API Reference (left sidebar) | |
0 commit comments