RustedSciThe 0.4.16

Rust framework for symbolic and numerical computing:BVP ( Newton-Raphson frozen/damped/with collocations ), IVP( BDF, Radau, Backward Euler, LSODE, LSODA, RK45, DoPri), nonlinear equations ( Levenberg, Gavin) and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# Task Documents in RustedSciThe: Practical Guide for IVP/BVP Workflows

This guide explains how to write task documents for RustedSciThe so you can run IVP and BVP jobs from plain text files. The target reader is a Rust developer who wants a reproducible, human-readable input format for numerical experiments, CI scenarios, and solver benchmarking, without building a custom driver for every single model.

The parser stack lives in:

- `src/command_interpreter/task_parser_ivp.rs`
- `src/command_interpreter/task_parser_bvp.rs`
- `src/command_interpreter/task_runner.rs`

Ready-to-run examples are in:

- `examples/task_docs/`

---

## 1. Big Picture

RustedSciThe task docs are section-based text files. You describe:

- what kind of task you want (`solver: IVP` or `solver: BVP`),
- the equations,
- initial/boundary conditions,
- solver options (including backend/AOT knobs),
- optional output preferences.

The runner (`task_runner`) detects task kind automatically and dispatches to the corresponding parser and solver route.

From executable mode:

```bash
RustedSciThe.exe examples/task_docs/ivp_decay_task.txt
RustedSciThe.exe examples/task_docs/bvp_reference_task.txt
```

From Rust API:

```rust
use RustedSciThe::command_interpreter::task_runner::run_task_from_file;

let result = run_task_from_file("examples/task_docs/ivp_decay_task.txt")?;
println!("{:?}", result.kind());
# Ok::<(), Box<dyn std::error::Error>>(())
```

---

## 2. Document Layout and Grammar

Each section starts with a header line (for example `task`, `equations`, `solver_options`). Inside a section, fields are written as `key: value`.

Comments and empty lines are allowed and can be used to annotate task files.

### 2.1 Required sections by task kind

For IVP:

- `task`
- `equations`
- `initial_conditions`

For BVP:

- `task`
- `equations`
- `boundary_conditions`
- `mesh`
- `initial_guess`

Optional for both:

- `solver_options`
- `postprocessing`
- `where` (or `substitute`) for symbolic substitutions

### 2.2 Equation section forms

Both IVP and BVP parsers support two equation styles.

List style:

```text
equations
arg: t
unknowns: y, z
rhs: z, -y
```

Pair style:

```text
equations
arg: t
y: z
z: -y
```

List style is recommended for larger systems because the unknown order is explicit and easier to review.

### 2.3 Symbolic substitutions (`where` / `substitute`)

You can define reusable symbolic aliases and have them substituted before solver construction:

```text
where
k: A*exp(-E/(R*T))
source: k*c
```

Then use `source` in `rhs`. This is symbolic substitution, not numeric parameter assignment.

Numeric parameters remain:

```text
parameters: A, E, R
parameter_values: 1.0e7, 1.2e5, 8.314
```

---

## 3. IVP Task Docs

### 3.1 Minimal LSODE2 example

```text
task
solver: IVP
method: LSODE2

equations
arg: t
parameters: a
parameter_values: 1.0
y: -a*y

initial_conditions
t0: 0.0
t_end: 2.0
y0: 1.0

solver_options
rtol: 1e-6
atol: 1e-8
max_step: 0.05
lsode2_symbolic_assembly: AtomView
lsode2_symbolic_execution: LambdifyExpr
lsode2_linear_structure: sparse
lsode2_linear_solver_policy: faer_sparse_lu
lsode2_native_execution: faithful_bdf_solve
```

### 3.2 `task` section (IVP)

Core fields:

- `solver: IVP`
- `method: ...`

Supported method values:

- `RK45`, `RK4`, `Euler`, `AB4`
- `Radau3`, `Radau5`
- `BDF`
- `BackwardEuler`
- `LSODE2` (aliases `LSODE`, `LSODA` are accepted)

### 3.3 `initial_conditions` (IVP)

Required:

- `t0`
- `t_end`
- `y0` (vector, same length as unknowns)

### 3.4 General `solver_options` (IVP)

These are parsed for all IVP methods; each solver uses what is relevant:

- `step_size`
- `tolerance`
- `max_iterations`
- `rtol`
- `atol`
- `max_step`
- `first_step` (supports `Some(...)` or plain numeric value)
- `vectorized`
- `parallel`
- `neighborhood_check`

### 3.5 LSODE2-specific options (IVP)

Symbolic assembly backend:

- `lsode2_symbolic_assembly: ExprLegacy | AtomView`

Symbolic execution mode:

- `lsode2_symbolic_execution: LambdifyExpr`
- `lsode2_symbolic_execution: AOT`

If `AOT`, you can additionally set:

- `lsode2_aot_toolchain: c_tcc | c_gcc | zig | rust`
- `lsode2_aot_profile: debug | release`
- `lsode2_aot_output_dir: <path>`

Linear structure:

- `lsode2_linear_structure: dense`
- `lsode2_linear_structure: sparse`
- `lsode2_linear_structure: banded`
- for banded: `lsode2_banded_kl`, `lsode2_banded_ku`

Linear solver policy:

- `lsode2_linear_solver_policy: auto`
- `lsode2_linear_solver_policy: dense_lu`
- `lsode2_linear_solver_policy: faer_sparse_lu`
- `lsode2_linear_solver_policy: lapack_faithful_banded_lu`

Native execution mode:

- `lsode2_native_execution: faithful_bdf_solve`
- `lsode2_native_execution: probe_before_bridge`
- `lsode2_native_execution: bridge_solve`

Native limits:

- `lsode2_native_max_step_attempts`
- `lsode2_native_max_accepted_steps`

---

## 4. BVP Task Docs

### 4.1 Minimal BVP example

```text
task
solver: BVP
strategy: Damped
scheme: forward
method: Sparse

equations
arg: x
unknowns: z, y
rhs: y-z, -z^3

boundary_conditions
z_left: 1.0
y_right: 1.0

mesh
t0: 0.0
t_end: 1.0
n_steps: 20

initial_guess
z: 0.0
y: 0.0

solver_options
tolerance: 1e-5
max_iterations: 20
generated_backend: sparse_lambdify
```

### 4.2 `task` section (BVP)

Fields:

- `solver: BVP`
- `strategy: Damped | Frozen | Naive` (default `Damped`)
- `scheme` (currently usually `forward`)
- `method: Dense | Sparse | Banded` (default `Sparse`)

### 4.3 Boundary conditions and mesh

Boundary keys use suffixes:

- `<unknown>_left`
- `<unknown>_right`

Mesh:

- `t0`, `t_end`, `n_steps`

### 4.4 Generated backend controls (BVP)

In `solver_options`, parser supports:

- `generated_backend` presets (for example `banded_lambdify`, `banded_aot_tcc`, `sparse_aot_gcc`, etc.)
- `matrix_backend: dense | sparse | banded`
- `backend_policy: lambdify_only | aot_only | prefer_aot_then_lambdify`
- `symbolic_backend: ExprLegacy | AtomView`
- `aot_codegen_backend: rust | c | zig`
- `aot_c_compiler` (for C routes, e.g. `tcc`/`gcc`)
- `aot_build_policy: use_if_available | build_if_missing | require_prebuilt | rebuild_always`
- `aot_build_profile: debug | release`
- `aot_compile_preset: production | fast_build | dev_fastest`
- `aot_execution_policy: auto | sequential`
- `banded_linear_solver` (faithful/block-tridiagonal/faer-sparse variants)
- `refinement_steps`

Note: parser currently rejects `aot_execution_policy: parallel` for BVP task docs because exposing full parallel executor config in task docs is not yet finished.

Also note that BVP task documents are symbolic inputs. They contain equations as text, not Rust closures, so they intentionally do not support `backend_policy: numeric_only`, `backend_policy: prefer_aot_then_numeric`, or `backend_policy: prefer_lambdify_then_numeric`. The pure numerical BVP route exists in the Rust API of the damped Newton solver: call `NRBVP::set_numeric_rhs(...)` or `NRBVP::with_numeric_rhs(...)`, set `BackendSelectionPolicy::NumericOnly`, and the solver will discretize that closure and build the Newton Jacobian by finite differences. The frozen BVP solver remains a symbolic Lambdify/AOT route by design; there is no frozen pure-numeric closure path.

---

## 5. IVP Method Keyword Matrix

This table is intentionally practical: it shows what to put in task docs depending on the method family.

| IVP method | Required task fields | Strongly recommended solver options | LSODE2-only options |
|---|---|---|---|
| `RK45`, `RK4`, `Euler`, `AB4` | `solver: IVP`, `method`, `equations`, `initial_conditions` | `step_size` (where relevant), `rtol`, `atol`, `max_step` | not used |
| `Radau3`, `Radau5` | same | `rtol`, `atol`, `max_step`, optionally `first_step` | not used |
| `BDF` | same | `rtol`, `atol`, `max_step`, `first_step`, optionally `max_iterations` | not used |
| `BackwardEuler` | same | `step_size` and/or `max_step`, `tolerance` | not used |
| `LSODE2` / `LSODE` / `LSODA` | same | `rtol`, `atol`, `max_step`, `first_step` | `lsode2_symbolic_assembly`, `lsode2_symbolic_execution`, `lsode2_linear_structure`, `lsode2_linear_solver_policy`, `lsode2_native_execution`, optional AOT fields and native limits |

---

## 6. AOT, Lambdify, Numerical: How to choose in task docs

For LSODE2 from task docs, the practical choices are:

- Numerical callback route: use method/backends from Rust API directly when you already own residual/Jacobian closures in code. Task docs are mainly symbolic-driven.
- Lambdify route: fastest to set up, excellent baseline for correctness and many production runs.
- AOT route: adds build/prepare overhead but is useful when solve-loop throughput matters across repeated runs.

For AOT in IVP task docs:

```text
lsode2_symbolic_execution: AOT
lsode2_aot_toolchain: c_gcc
lsode2_aot_profile: release
```

Toolchain prerequisites: install the corresponding compiler/toolchain on the host machine (`tcc`, `gcc`, `zig`, Rust toolchain for Rust AOT mode).

---

## 7. Parallelism Notes

The task-doc layer currently exposes parallelism in two ways:

- generic IVP option `parallel: true/false`,
- backend policy/execution selections where available.

Low-level chunk-size and advanced executor tuning are still richer in direct Rust API than in task-doc format. This is intentional for now: task docs stay stable and human-readable, while advanced orchestration can evolve in typed APIs.

---

## 8. Postprocessing

Both IVP and BVP task docs support:

- `save_csv: true/false`
- `csv_path: ...`
- `save_txt: true/false`
- `txt_path: ...`
- `write_report: true/false`
- `report_path: ...`
- `plotters_png: true/false`
- `plotters_dir: ...`
- `gnuplot_png: true/false`
- `gnuplot_dir: ...`
- `terminal_plot: true/false`
- `plot: true/false`

CSV, TXT and markdown report export are routed through the unified
`PostprocessPlan` facade. `plotters_png`, `gnuplot_png` and `terminal_plot`
are explicit modern plotting actions; `plot` remains a legacy compatibility flag
and its behavior depends on the specific solver path and available plotting
setup.

---

## 9. Header/Field Aliases (Pseudonyms)

Parsers include tolerant aliases so older or alternative naming can still work. For example:

- section aliases like `problem` for `task`,
- `system` for `equations`,
- `solver_settings` or `options` for `solver_options`,
- `substitute` as alias for `where`.

Still, for new files prefer canonical names from templates to keep docs and CI consistent.

---

## 10. Common Failure Modes and Fast Checks

If parsing fails, check these first:

- `solver` value is exactly `IVP` or `BVP`,
- section names are correct and separated cleanly,
- equation unknown count equals RHS count,
- `parameter_values` count matches `parameters`,
- `y0` length matches number of unknowns,
- BVP boundary keys follow `<unknown>_left` / `<unknown>_right`,
- LSODE2 AOT options are coherent (`lsode2_symbolic_execution: AOT` plus toolchain/profile if needed).

If execution fails in AOT mode, verify compiler availability and output directory permissions first.

---

## 11. Recommended Workflow

Start from templates:

```bash
RustedSciThe.exe --template ivp
RustedSciThe.exe --template bvp
```

Then adapt step by step:

1. make equations/conditions run with baseline options,
2. lock correctness (compare against known solution or baseline route),
3. introduce backend-specific tuning (`Lambdify` -> `AOT`, sparse/banded policy, etc.),
4. only then run multi-run performance stories.

This sequence keeps debugging local and avoids mixing model errors with backend orchestration noise.