pyrucast 0.11.0

Finite-element library in Rust, inspired by cast3m, exposed to Python
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
//! Python wrappers for [`crate::containers::evolution::SubEvolution`] and
//! [`crate::containers::evolution::Evolution`].

use crate::containers::element_field::ElementField;
use crate::containers::evolution::{Evolution, Interpolated, OutOfRange, SubEvolution, SubValue};
use crate::containers::node_field::NodeField;
use crate::py::element_field::{PyElementField, PySubElementField};
// Used by the viz-gated `plot` methods and — even without `viz` — by the
// `gen_stub_pymethods` macro, which reads those methods' signatures to emit
// the `.pyi` stub. Hence the import must also be present under `stub-gen`.
use crate::handle::Handle;
#[cfg(any(feature = "viz", feature = "stub-gen"))]
use crate::py::mesh::PyMesh;
use crate::py::node_field::{PyNodeField, PySubNodeField};
use pyo3::exceptions::{PyTypeError, PyValueError};
use pyo3::prelude::*;
use pyo3::types::{PyFloat, PyList, PyTuple};

// ─── Helpers ────────────────────────────────────────────────────────────────

/// Extract one tabulated value (`float` / `SubNodeField` / `SubElementField`)
/// from a Python object.
fn extract_sub_value(value: &Bound<'_, PyAny>) -> PyResult<SubValue> {
    if let Ok(f) = value.extract::<f64>() {
        return Ok(SubValue::Scalar(f));
    }
    if let Ok(s) = value.extract::<PyRef<PySubNodeField>>() {
        return Ok(SubValue::Node((*s.handle.read()).clone()));
    }
    if let Ok(s) = value.extract::<PyRef<PySubElementField>>() {
        return Ok(SubValue::Element((*s.handle.read()).clone()));
    }
    Err(PyTypeError::new_err(
        "evolution value must be a float, a SubNodeField or a SubElementField",
    ))
}

/// One abscissa: a float for a curve, a tuple (or list) of floats for a table.
fn extract_abscissa(x: &Bound<'_, PyAny>) -> PyResult<Vec<f64>> {
    if let Ok(v) = x.extract::<f64>() {
        return Ok(vec![v]);
    }
    x.extract::<Vec<f64>>().map_err(|_| {
        PyTypeError::new_err("an abscissa is a float, or a tuple of floats for a table")
    })
}

/// The abscissa types: a name for a curve, a sequence of names for a table,
/// `None` for none.
fn extract_abscissa_types(types: Option<&Bound<'_, PyAny>>) -> PyResult<Vec<String>> {
    match types {
        None => Ok(Vec::new()),
        Some(t) => match t.extract::<String>() {
            Ok(name) => Ok(vec![name]),
            Err(_) => t.extract::<Vec<String>>().map_err(|_| {
                PyTypeError::new_err("abscissa_type is a name, or a sequence of names for a table")
            }),
        },
    }
}

/// The abscissa types handed back: `None`, a name for a curve, a tuple of
/// names for a table.
fn abscissa_types_to_py(py: Python<'_>, types: &[String]) -> PyResult<Py<PyAny>> {
    Ok(match types {
        [] => py.None(),
        [one] => one.into_pyobject(py)?.into_any().unbind(),
        many => PyTuple::new(py, many)?.into_any().unbind(),
    })
}

/// Wrap an interpolated [`SubValue`] as the matching Python object.
fn sub_value_to_py(py: Python<'_>, value: SubValue) -> PyResult<Py<PyAny>> {
    match value {
        SubValue::Scalar(s) => Ok(PyFloat::new(py, s).into_any().unbind()),
        SubValue::Node(f) => Ok(Py::new(
            py,
            PySubNodeField {
                handle: Handle::new(f),
            },
        )?
        .into_any()),
        SubValue::Element(f) => Ok(Py::new(
            py,
            PySubElementField {
                handle: Handle::new(f),
            },
        )?
        .into_any()),
    }
}

// ─── SubEvolution (view + builder) ──────────────────────────────────────────

/// One tabulated curve: a sorted list of abscissas with the matching values
/// (a float, a `SubNodeField` or a `SubElementField`), interpolated linearly.
///
/// Build with `SubEvolution(samples, out_of_range="error")` where `samples`
/// is a list of `(abscissa, value)` pairs; compose several curves into an
/// `Evolution` with `|`.
#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pyclass)]
#[pyclass(name = "SubEvolution")]
pub struct PySubEvolution {
    pub(crate) handle: Handle<SubEvolution>,
}

#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pymethods)]
#[pymethods]
impl PySubEvolution {
    /// `SubEvolution(samples, out_of_range="error", abscissa_type=None,
    /// ordinate_type=None)` — one curve, or one table. `samples` is a list of
    /// `(abscissa, value)`; the abscissa is a float for a curve, a tuple of
    /// floats for a table of several variables (`((T, phi), value)`), read
    /// hierarchically — grouped by the first variable, then the second… — so
    /// the groups need not share their abscissas. The values must all be of
    /// the same kind (and, for fields, on the same support). `out_of_range`
    /// defaults to `"error"`. `abscissa_type` names the physical type of each
    /// variable — a name, or a tuple of names for a table — used to label plots
    /// and to select the field components a field is read from when it is
    /// interpolated; `ordinate_type` names the value's type (scalar curves
    /// only).
    #[new]
    #[pyo3(signature = (samples, out_of_range=None, abscissa_type=None, ordinate_type=None))]
    fn py_new(
        py: Python<'_>,
        samples: Vec<(Py<PyAny>, Py<PyAny>)>,
        out_of_range: Option<OutOfRange>,
        abscissa_type: Option<Py<PyAny>>,
        ordinate_type: Option<String>,
    ) -> PyResult<Self> {
        let oor = out_of_range.unwrap_or(OutOfRange::Error);
        let mut pairs = Vec::with_capacity(samples.len());
        for (x, v) in samples {
            pairs.push((
                extract_abscissa(x.bind(py))?,
                extract_sub_value(v.bind(py))?,
            ));
        }
        let mut sub = SubEvolution::new(pairs, oor)?;
        sub.set_abscissa_types(extract_abscissa_types(
            abscissa_type.as_ref().map(|t| t.bind(py)),
        )?)?;
        sub.set_ordinate_type(ordinate_type)?;
        Ok(Self {
            handle: Handle::new(sub),
        })
    }

    /// The abscissa's physical type: a name for a curve, a tuple of names for
    /// a table, or `None`.
    fn abscissa_type(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
        abscissa_types_to_py(py, self.handle.read().abscissa_types())
    }

    /// The ordinate's physical type (scalar curves), or `None`.
    fn ordinate_type(&self) -> Option<String> {
        self.handle.read().ordinate_type().map(str::to_string)
    }

    /// Number of samples.
    fn __len__(&self) -> usize {
        self.handle.read().len()
    }

    /// The sorted abscissas: floats for a curve, tuples of floats for a table
    /// (in lexicographic order).
    fn abscissas(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
        let sub = self.handle.read();
        if sub.dims() == 1 {
            return Ok(PyList::new(py, sub.abscissas())?.into_any().unbind());
        }
        let tuples: Vec<Bound<'_, PyTuple>> = sub
            .abscissas()
            .chunks(sub.dims())
            .map(|x| PyTuple::new(py, x))
            .collect::<PyResult<_>>()?;
        Ok(PyList::new(py, tuples)?.into_any().unbind())
    }

    /// The stored out-of-range policy name.
    fn out_of_range(&self) -> String {
        self.handle.read().out_of_range().name().to_string()
    }

    /// Interpolate at `x`.
    ///
    /// - `x` a **float** (a curve) or a **tuple of floats** (a table) → a
    ///   float / `SubNodeField` / `SubElementField`, the value at `x`;
    /// - `x` a **`SubNodeField`** or **`SubElementField`** → a field of the
    ///   same support whose every entry is this **scalar** curve or table
    ///   evaluated at the input's `abscissa_type` components (applied like
    ///   `cos` to a field). The output component is named after
    ///   `ordinate_type`.
    ///
    /// `out_of_range` (`"error"` / `"clamp"` / `"extrapolate"`) overrides the
    /// stored policy for this query.
    #[pyo3(signature = (x, out_of_range=None))]
    fn interpolate(
        &self,
        py: Python<'_>,
        x: Py<PyAny>,
        out_of_range: Option<OutOfRange>,
    ) -> PyResult<Py<PyAny>> {
        let policy = out_of_range;
        let x = x.bind(py);
        let sub = self.handle.read();
        if let Ok(v) = x.extract::<f64>() {
            return sub_value_to_py(py, sub.interpolate(v, policy)?);
        }
        if let Ok(v) = x.extract::<Vec<f64>>() {
            return sub_value_to_py(py, sub.interpolate_at(&v, policy)?);
        }
        if let Ok(f) = x.extract::<PyRef<PySubNodeField>>() {
            let field = (*f.handle.read()).clone();
            let out = sub.interpolate_field(&field, policy)?;
            return Ok(Py::new(
                py,
                PySubNodeField {
                    handle: Handle::new(out),
                },
            )?
            .into_any());
        }
        if let Ok(f) = x.extract::<PyRef<PySubElementField>>() {
            let field = (*f.handle.read()).clone();
            let out = sub.interpolate_field(&field, policy)?;
            return Ok(Py::new(
                py,
                PySubElementField {
                    handle: Handle::new(out),
                },
            )?
            .into_any());
        }
        Err(PyTypeError::new_err(
            "interpolate expects a float, a tuple of floats, a SubNodeField or a SubElementField",
        ))
    }

    /// Plot this single curve — see `Evolution.plot`. A scalar curve draws an
    /// X-Y line; a field curve renders with a frame slider.
    /// `revolve` / `revolve_angle` sweep an axisymmetric plot into its body
    /// of revolution — see `SubMesh.plot`.
    #[cfg(feature = "viz")]
    #[pyo3(signature = (view=None, save=None, show_axes=true, mesh=None, component=None, vmin=None, vmax=None, cmap=None, smooth=4, frame=None, revolve=false, revolve_angle=360.0, x_label=None, y_label=None, title=None))]
    #[allow(clippy::too_many_arguments)]
    fn plot(
        &self,
        view: Option<(f64, f64, f64)>,
        save: Option<std::path::PathBuf>,
        show_axes: bool,
        mesh: Option<PyRef<'_, PyMesh>>,
        component: Option<String>,
        vmin: Option<f64>,
        vmax: Option<f64>,
        cmap: Option<crate::viz::Colormap>,
        smooth: usize,
        frame: Option<usize>,
        revolve: bool,
        revolve_angle: f64,
        x_label: Option<String>,
        y_label: Option<String>,
        title: Option<String>,
    ) -> PyResult<()> {
        let view = crate::py::build_view(view, show_axes, revolve, revolve_angle)?;
        let scale = crate::viz::ColorScale {
            cmap: cmap.unwrap_or_default(),
            vmin,
            vmax,
        };
        // Clone out so no read lock is held during rendering.
        let sub = (*self.handle.read()).clone();
        sub.plot(
            view,
            save.as_deref(),
            mesh.as_ref().map(|m| &m.inner),
            component.as_deref(),
            scale,
            smooth,
            frame,
            x_label.as_deref(),
            y_label.as_deref(),
            title.as_deref(),
        )?;
        Ok(())
    }
}

crate::impl_dump_pymethod!(handle PySubEvolution, handle);

// ─── Evolution (aggregate) ──────────────────────────────────────────────────

/// An aggregate of tabulated curves (one `SubEvolution` per zone), interpolated
/// linearly against a variable (often time).
///
/// Build high-level with `Evolution(steps, out_of_range="error")` where each
/// step is `(abscissa, value)` and `value` is a whole `NodeField`,
/// `ElementField` or float (whole fields are transposed into one curve per
/// zone); or low-level by composing `SubEvolution`s with `|`. Index it
/// (`evolution[i]`) to reach a `SubEvolution`.
#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pyclass)]
#[pyclass(name = "Evolution")]
pub struct PyEvolution {
    pub(crate) inner: Evolution,
}

#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pymethods)]
#[pymethods]
impl PyEvolution {
    /// The abscissas every zone shares — the times of a series. Raises if
    /// the zones tabulate at different abscissas.
    fn shared_abscissas(&self) -> PyResult<Vec<f64>> {
        Ok(self.inner.shared_abscissas()?)
    }

    /// The tabulated values as whole fields, one per shared abscissa: a
    /// `list[NodeField]` or a `list[ElementField]`. Raises for scalars.
    fn frames(&self, py: Python<'_>) -> PyResult<Vec<Py<PyAny>>> {
        use crate::containers::evolution::ValueKind;
        let n = self.inner.frame_count()?;
        match self.inner.kind()? {
            ValueKind::Node => (0..n)
                .map(|k| {
                    Ok(Py::new(
                        py,
                        PyNodeField {
                            inner: self.inner.node_frame(k)?,
                        },
                    )?
                    .into_any())
                })
                .collect(),
            ValueKind::Element => (0..n)
                .map(|k| {
                    Ok(Py::new(
                        py,
                        PyElementField {
                            inner: self.inner.element_frame(k)?,
                        },
                    )?
                    .into_any())
                })
                .collect(),
            ValueKind::Scalar => Err(PyTypeError::new_err(
                "frames: this evolution tabulates scalars, not fields",
            )),
        }
    }

    /// `Evolution(steps, out_of_range="error")` — build from whole values
    /// (`out_of_range` defaults to `"error"`)
    /// tabulated at each abscissa. `steps` is a list of `(abscissa, value)`
    /// where `value` is a float, a `NodeField` or an `ElementField`; the kind
    /// is taken from the first step. Whole fields are transposed into one
    /// curve per zone. The abscissa is a float, or a tuple of floats for a
    /// table of several variables (`((T, phi), value)`), read hierarchically
    /// — see `SubEvolution`; `abscissa_type` is then a tuple of names.
    #[new]
    #[pyo3(signature = (steps, out_of_range=None, abscissa_type=None, ordinate_type=None))]
    fn py_new(
        py: Python<'_>,
        steps: Vec<(Py<PyAny>, Py<PyAny>)>,
        out_of_range: Option<OutOfRange>,
        abscissa_type: Option<Py<PyAny>>,
        ordinate_type: Option<String>,
    ) -> PyResult<Self> {
        let oor = out_of_range.unwrap_or(OutOfRange::Error);
        if steps.is_empty() {
            return Err(PyValueError::new_err(
                "Evolution: at least one step is required",
            ));
        }
        let first = steps[0].1.bind(py);
        let abscissas: Vec<Vec<f64>> = steps
            .iter()
            .map(|(x, _)| extract_abscissa(x.bind(py)))
            .collect::<PyResult<_>>()?;

        let mut inner = if first.extract::<f64>().is_ok() {
            let mut pairs = Vec::with_capacity(steps.len());
            for (x, (_, v)) in abscissas.iter().zip(&steps) {
                pairs.push((x.clone(), v.bind(py).extract::<f64>()?));
            }
            Evolution::from_scalars(pairs, oor)?
        } else if first.extract::<PyRef<PyNodeField>>().is_ok() {
            let mut fields: Vec<PyRef<PyNodeField>> = Vec::with_capacity(steps.len());
            for (_, v) in &steps {
                fields.push(v.bind(py).extract::<PyRef<PyNodeField>>()?);
            }
            let refs: Vec<(Vec<f64>, &NodeField)> = abscissas
                .iter()
                .cloned()
                .zip(fields.iter().map(|f| &f.inner))
                .collect();
            Evolution::from_node_fields(&refs, oor)?
        } else if first.extract::<PyRef<PyElementField>>().is_ok() {
            let mut fields: Vec<PyRef<PyElementField>> = Vec::with_capacity(steps.len());
            for (_, v) in &steps {
                fields.push(v.bind(py).extract::<PyRef<PyElementField>>()?);
            }
            let refs: Vec<(Vec<f64>, &ElementField)> = abscissas
                .iter()
                .cloned()
                .zip(fields.iter().map(|f| &f.inner))
                .collect();
            Evolution::from_element_fields(&refs, oor)?
        } else {
            return Err(PyTypeError::new_err(
                "Evolution step value must be a float, a NodeField or an ElementField",
            ));
        };
        inner.set_abscissa_types(extract_abscissa_types(
            abscissa_type.as_ref().map(|t| t.bind(py)),
        )?)?;
        inner.set_ordinate_type(ordinate_type)?;
        Ok(Self { inner })
    }

    /// The stored out-of-range policy name.
    fn out_of_range(&self) -> String {
        self.inner.out_of_range().name().to_string()
    }

    /// The abscissa types of the first curve: a name for a curve, a tuple of
    /// names for a table, or `None`. Each curve keeps its own — `E(T)` beside
    /// `sigma_y(T, phi)` — see `SubEvolution.abscissa_type`.
    fn abscissa_type(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
        abscissa_types_to_py(py, &self.inner.abscissa_types())
    }

    /// The ordinate's physical type (scalar evolutions), or `None`.
    fn ordinate_type(&self) -> PyResult<Option<String>> {
        Ok(self.inner.ordinate_type()?)
    }

    /// Interpolate at `x`.
    ///
    /// - `x` a **float** (curves) or a **tuple of floats** (tables) → every
    ///   curve interpolated and regrouped: a `list[float]` for scalars, a
    ///   `NodeField` / `ElementField` for fields;
    /// - `x` a **`NodeField`** or **`ElementField`** → that field mapped
    ///   through every **scalar** curve, like `cos` through a field: each curve
    ///   reads the input's components named like its `abscissa_type` and
    ///   writes one component, named after its `ordinate_type`, on the same
    ///   support — material laws `E(T)`, `sigma_y(T, phi)` evaluated at the
    ///   state in one call.
    ///
    /// `out_of_range` overrides the stored policy for this query.
    #[pyo3(signature = (x, out_of_range=None))]
    fn interpolate(
        &self,
        py: Python<'_>,
        x: Py<PyAny>,
        out_of_range: Option<OutOfRange>,
    ) -> PyResult<Py<PyAny>> {
        let policy = out_of_range;
        let x = x.bind(py);
        let at = if let Ok(v) = x.extract::<f64>() {
            Some(vec![v])
        } else {
            x.extract::<Vec<f64>>().ok()
        };
        if let Some(v) = at {
            return match self.inner.interpolate_at(&v, policy)? {
                Interpolated::Scalars(v) => Ok(PyList::new(py, v)?.into_any().unbind()),
                Interpolated::Node(f) => Ok(Py::new(py, PyNodeField { inner: f })?.into_any()),
                Interpolated::Element(f) => {
                    Ok(Py::new(py, PyElementField { inner: f })?.into_any())
                }
            };
        }
        if let Ok(f) = x.extract::<PyRef<PyNodeField>>() {
            let out = self.inner.interpolate_node_field(&f.inner, policy)?;
            return Ok(Py::new(py, PyNodeField { inner: out })?.into_any());
        }
        if let Ok(f) = x.extract::<PyRef<PyElementField>>() {
            let out = self.inner.interpolate_element_field(&f.inner, policy)?;
            return Ok(Py::new(py, PyElementField { inner: out })?.into_any());
        }
        Err(PyTypeError::new_err(
            "interpolate expects a float, a tuple of floats, a NodeField or an ElementField",
        ))
    }

    /// Plot the evolution. A **scalar** evolution draws an X-Y curve (one line
    /// per zone); a **field** evolution renders like `Mesh.plot(field=...)`
    /// with a frame slider (drag, or ← / →) picking the tabulated value.
    ///
    /// `save` writes a PNG/SVG (a single `frame`, default = last for fields);
    /// omit it for the interactive window. `mesh` supplies the surface for
    /// field evolutions (node frames default to a point cloud). `x_label` /
    /// `y_label` / `title` label the curve.
    /// `revolve` / `revolve_angle` sweep an axisymmetric plot into its body
    /// of revolution — see `SubMesh.plot`.
    #[cfg(feature = "viz")]
    #[pyo3(signature = (view=None, save=None, show_axes=true, mesh=None, component=None, vmin=None, vmax=None, cmap=None, smooth=4, frame=None, revolve=false, revolve_angle=360.0, x_label=None, y_label=None, title=None))]
    #[allow(clippy::too_many_arguments)]
    fn plot(
        &self,
        view: Option<(f64, f64, f64)>,
        save: Option<std::path::PathBuf>,
        show_axes: bool,
        mesh: Option<PyRef<'_, PyMesh>>,
        component: Option<String>,
        vmin: Option<f64>,
        vmax: Option<f64>,
        cmap: Option<crate::viz::Colormap>,
        smooth: usize,
        frame: Option<usize>,
        revolve: bool,
        revolve_angle: f64,
        x_label: Option<String>,
        y_label: Option<String>,
        title: Option<String>,
    ) -> PyResult<()> {
        let view = crate::py::build_view(view, show_axes, revolve, revolve_angle)?;
        let scale = crate::viz::ColorScale {
            cmap: cmap.unwrap_or_default(),
            vmin,
            vmax,
        };
        self.inner.plot(
            view,
            save.as_deref(),
            mesh.as_ref().map(|m| &m.inner),
            component.as_deref(),
            scale,
            smooth,
            frame,
            x_label.as_deref(),
            y_label.as_deref(),
            title.as_deref(),
        )?;
        Ok(())
    }
}

crate::impl_aggregate_pymethods!(
    PyEvolution,
    PySubEvolution,
    "Evolution",
    sub_evolution,
    Evolution,
    r#"
class PyEvolution:
    @overload
    def __getitem__(self, key: int) -> pyo3_stub_gen.RustType["PySubEvolution"]:
        """`evolution[i]` → the `SubEvolution` of zone i: one tabulated curve,
        interpolated linearly against the variable."""
    @overload
    def __getitem__(self, key: slice) -> pyo3_stub_gen.RustType["PyEvolution"]:
        """`evolution[i:j:k]` → a fresh `Evolution` holding the sliced curves,
        shared with this one (no deep copy)."""
    def __or__(self, other: pyo3_stub_gen.RustType["PyEvolution"] | pyo3_stub_gen.RustType["PySubEvolution"]) -> pyo3_stub_gen.RustType["PyEvolution"]:
        """`evolution | other` → a fresh `Evolution` holding the curves of both,
        in first-seen order and deduplicated by object identity."""
    def __ror__(self, other: pyo3_stub_gen.RustType["PySubEvolution"]) -> pyo3_stub_gen.RustType["PyEvolution"]:
        """`sub_evolution | evolution` — the mirror of
        `evolution | sub_evolution`, differing only in that the lone curve
        comes first."""
    "#,
    r#"
class PySubEvolution:
    def __or__(self, other: pyo3_stub_gen.RustType["PySubEvolution"]) -> pyo3_stub_gen.RustType["PyEvolution"]:
        """`sub_evolution | sub_evolution` → a fresh `Evolution` holding both
        curves — the low-level way to build a multi-zone evolution."""
    "#
);