Simulation Benchmarking Suite (softpotato.analytical.benchmark)¶
The softpotato.analytical.benchmark module provides automated validation harnesses, exact analytical benchmarks, and convergence testing utilities.
benchmark
¶
Automated numerical solver validation suite and analytical benchmarking harness.
This submodule provides a comprehensive benchmarking suite that validates numerical
PDE solvers (softpotato.solver) against closed-form analytical ground truths
(softpotato.analytical).
Features
-
Standardized Error Metrics:
-
Pointwise absolute error (\(L_\infty\) norm,
compute_error_metrics). - Root-Mean-Square Error (RMSE).
- Discrete relative \(L_2\) error norm.
- Mean absolute error (MAE).
-
Mean and maximum relative errors with zero-division protection.
-
Order-of-Convergence Verification:
-
Spatial discretization convergence verification (\(\mathcal{O}(\Delta x^2)\)).
- Temporal discretization convergence verification (\(\mathcal{O}(\Delta t^2)\) for Crank–Nicolson, \(\mathcal{O}(\Delta t)\) for backward-Euler BTCS).
-
Empirical order estimation via log-log regression (
estimate_convergence_order). -
Canonical Electrochemical Benchmark Problems:
-
Fourier sine diffusion decay (
run_fourier_decay_benchmark). - Planar Cottrell potential step chronoamperometry (
run_cottrell_benchmark). -
Total mass conservation under zero-flux Neumann BCs (
run_mass_conservation_benchmark). -
Automated Suite Execution:
-
Unified single-case runner (
run_benchmark). - Multi-solver comparative benchmark suite (
run_benchmark_suite) with formatted tabular ASCII reporting.
BenchmarkMetrics
dataclass
¶
Standardized error metrics between numerical and analytical solutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rmse
|
float
|
Root-mean-square error: \[
\text{RMSE} = \sqrt{\frac{1}{N} \sum_{i=1}^N (u_i^{\text{num}} - u_i^{\text{exact}})^2}
\]
|
required |
max_abs_error
|
float
|
Maximum pointwise absolute deviation (\(L_\infty\) norm): \[
\|u^{\text{num}} - u^{\text{exact}}\|_\infty = \max_i |u_i^{\text{num}} - u_i^{\text{exact}}|
\]
|
required |
l2_error
|
float
|
Discrete relative \(L_2\) error norm: \[
L_2 = \frac{\|u^{\text{num}} - u^{\text{exact}}\|_2}{\|u^{\text{exact}}\|_2}
\]
(evaluates to absolute \(L_2\) norm if \(\|u^{\text{exact}}\|_2 = 0\)). |
required |
mean_abs_error
|
float
|
Mean absolute error (MAE): \[
\text{MAE} = \frac{1}{N} \sum_{i=1}^N |u_i^{\text{num}} - u_i^{\text{exact}}|
\]
|
required |
mean_rel_error
|
float
|
Mean relative error across all evaluated points: \[
\text{MRE} = \frac{1}{N} \sum_{i=1}^N \frac{|u_i^{\text{num}} - u_i^{\text{exact}}|}{|u_i^{\text{exact}}| + \epsilon}
\]
|
required |
max_rel_error
|
float
|
Maximum relative error: \[
\text{MaxRE} = \max_i \frac{|u_i^{\text{num}} - u_i^{\text{exact}}|}{|u_i^{\text{exact}}| + \epsilon}
\]
|
required |
Examples:
>>> import numpy as np
>>> from softpotato.analytical.benchmark import compute_error_metrics
>>> num = np.array([1.0, 2.01, 3.0])
>>> exact = np.array([1.0, 2.0, 3.0])
>>> metrics = compute_error_metrics(num, exact)
>>> round(metrics.max_abs_error, 4)
0.01
Source code in src/softpotato/analytical/benchmark.py
to_dict
¶
Convert metrics to a standard Python dictionary.
Source code in src/softpotato/analytical/benchmark.py
ConvergenceResult
dataclass
¶
Results from an order-of-convergence refinement study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spacings
|
ndarray
|
Discretization spacings tested (\(\Delta x\) for spatial, \(\Delta t\) for temporal). |
required |
errors
|
ndarray
|
Corresponding error norm evaluated for each spacing. |
required |
observed_order
|
float
|
Empirical convergence order \(p\) extracted from linear regression: \[
\ln(\text{error}) = p \cdot \ln(h) + C
\]
|
required |
expected_order
|
float
|
Theoretical convergence order (e.g., \(2.0\) for second-order schemes). |
required |
r_squared
|
float
|
Goodness-of-fit \(R^2\) of the log-log linear regression. |
required |
passed
|
bool
|
Whether |
required |
spacing_type
|
('spatial', 'temporal')
|
Discretization domain refined during the study. |
'spatial'
|
details
|
dict[str, Any]
|
Additional context such as solver name, test case, and tolerance thresholds. |
dict()
|
Examples:
>>> import numpy as np
>>> from softpotato.analytical.benchmark import estimate_convergence_order
>>> h = np.array([0.1, 0.05, 0.025])
>>> err = 0.5 * h**2 # pure 2nd-order error
>>> p, r2 = estimate_convergence_order(h, err)
>>> round(p, 2)
2.0
>>> round(r2, 4)
1.0
Source code in src/softpotato/analytical/benchmark.py
BenchmarkCaseResult
dataclass
¶
Execution and validation outcome for a single benchmark problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case_name
|
str
|
Name of the benchmark problem (e.g. |
required |
solver_name
|
str
|
Name of the numerical solver evaluated. |
required |
concentration_metrics
|
BenchmarkMetrics
|
Standardized error metrics for the spatial/temporal concentration field. |
required |
flux_metrics
|
BenchmarkMetrics or None
|
Standardized error metrics for interfacial boundary flux or current, or None if not applicable for the case. |
None
|
execution_time
|
float
|
Wall-clock simulation execution time in seconds. |
0.0
|
passed
|
bool
|
Whether all error metrics satisfied the predefined tolerance criteria. |
True
|
details
|
dict[str, Any]
|
Diagnostic metadata and parameters used for the benchmark run. |
dict()
|
Source code in src/softpotato/analytical/benchmark.py
BenchmarkSuiteResult
dataclass
¶
Aggregated outcome of running a benchmark suite across solvers and test cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cases
|
list[BenchmarkCaseResult]
|
Collection of all individual benchmark run results. |
required |
total_time
|
float
|
Total wall-clock execution time for the entire suite in seconds. |
required |
all_passed
|
bool
|
Flag indicating if all individual benchmark cases passed their tolerances. |
required |
Source code in src/softpotato/analytical/benchmark.py
summary
¶
Generate a formatted ASCII comparison table of all benchmark runs.
Source code in src/softpotato/analytical/benchmark.py
compute_error_metrics
¶
compute_error_metrics(numerical: ArrayLike, exact: ArrayLike, *, eps: float = 1e-12) -> BenchmarkMetrics
Compute standardized error norms between numerical results and exact ground truths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numerical
|
array - like
|
Simulated numerical values (scalar, 1D, or multidimensional array). |
required |
exact
|
array - like
|
Exact analytical reference values corresponding to |
required |
eps
|
float
|
Small positive constant added to denominators to prevent division by zero when evaluating relative errors against zero-valued ground truths. |
1e-12
|
Returns:
| Type | Description |
|---|---|
BenchmarkMetrics
|
Dataclass containing RMSE, \(L_\infty\) ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input arrays cannot be broadcast together or have different shapes. |
Examples:
>>> import numpy as np
>>> from softpotato.analytical.benchmark import compute_error_metrics
>>> y_num = np.array([1.0, 2.05, 3.0])
>>> y_exact = np.array([1.0, 2.0, 3.0])
>>> m = compute_error_metrics(y_num, y_exact)
>>> round(m.max_abs_error, 4)
0.05
>>> round(m.rmse, 4)
0.0289
Source code in src/softpotato/analytical/benchmark.py
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 | |
estimate_convergence_order
¶
Estimate empirical order of convergence \(p\) and \(R^2\) via log-log regression.
Fits the power law \(\text{error} = C \cdot h^p\) in logarithmic space:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spacings
|
array - like
|
Array of strictly positive discretization increments \(h\) (\(\Delta x\) or \(\Delta t\)). |
required |
errors
|
array - like
|
Array of strictly positive corresponding error norms. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
order |
float
|
Empirical convergence order \(p\) (slope of log-log regression). |
r_squared |
float
|
Coefficient of determination \(R^2 \in [0, 1]\) indicating the linearity and reliability of the power-law convergence regime. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If inputs have fewer than 2 data points or contain non-positive values. |
Examples:
>>> import numpy as np
>>> from softpotato.analytical.benchmark import estimate_convergence_order
>>> h = np.array([0.1, 0.05, 0.025, 0.0125])
>>> err = 2.5 * h**2
>>> p, r2 = estimate_convergence_order(h, err)
>>> round(p, 4)
2.0
>>> round(r2, 4)
1.0
Source code in src/softpotato/analytical/benchmark.py
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 | |
run_fourier_decay_benchmark
¶
run_fourier_decay_benchmark(solver: BaseSolver | str = 'crank_nicolson', *, n_points: int = 51, D: float = 0.05, L: float = 1.0, t_end: float = 0.2, n_times: int = 11, max_error_threshold: float = 0.005, **solver_kwargs: Any) -> BenchmarkCaseResult
Run 1D Fourier sine diffusion decay benchmark comparing against exact solution.
Governing PDE:
Initial and boundary conditions:
Exact analytical solution:
Exact surface flux at \(x = 0\):
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
BaseSolver or str
|
Numerical solver instance or registered string name. |
"crank_nicolson"
|
n_points
|
int
|
Number of spatial grid points \(N_x\). |
51
|
D
|
float
|
Diffusion coefficient \(D > 0\). |
0.05
|
L
|
float
|
Domain length \(L > 0\). |
1.0
|
t_end
|
float
|
Simulation end time \(t_{\text{end}} > 0\). |
0.2
|
n_times
|
int
|
Number of time evaluation points across \([0, t_{\text{end}}]\). |
11
|
max_error_threshold
|
float
|
Maximum allowable \(L_\infty\) concentration error to consider the run passed. |
5e-3
|
**solver_kwargs
|
Any
|
Additional keyword arguments forwarded to the solver (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
BenchmarkCaseResult
|
Outcome containing concentration metrics, interfacial flux metrics, wall-clock runtime, and pass/fail indicator. |
Examples:
>>> from softpotato.analytical.benchmark import run_fourier_decay_benchmark
>>> res = run_fourier_decay_benchmark("crank_nicolson", n_points=41, t_end=0.1)
>>> res.passed
True
>>> res.concentration_metrics.max_abs_error < 5e-3
True
Source code in src/softpotato/analytical/benchmark.py
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 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
run_cottrell_benchmark
¶
run_cottrell_benchmark(solver: BaseSolver | str = 'crank_nicolson', *, n_points: int = 101, D: float = 1e-05, c_bulk: float = 0.001, n_electrons: int = 1, area: float = 0.0001, t_span: tuple[float, float] = (0.01, 0.2), n_times: int = 20, domain_factor: float = 6.0, max_error_threshold: float = 0.05, **solver_kwargs: Any) -> BenchmarkCaseResult
Run Cottrell potential step benchmark comparing concentration profiles and flux.
Simulates chronoamperometric semi-infinite linear diffusion following a step to zero surface concentration (\(c(0, t) = 0\)). The domain length is automatically dimensioned as \(L = \text{domain\_factor} \times \sqrt{D \cdot t_{\text{end}}}\) to ensure the right boundary satisfies semi-infinite boundary conditions (\(c(L, t) \approx c^*\)).
Exact analytical spatial concentration profile:
Exact Cottrell current transient:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
BaseSolver or str
|
Numerical solver instance or registered string name. |
"crank_nicolson"
|
n_points
|
int
|
Number of spatial grid points \(N_x\). |
101
|
D
|
float
|
Diffusion coefficient \(D > 0\). |
1e-5
|
c_bulk
|
float
|
Bulk concentration \(c^* > 0\). |
1e-3
|
n_electrons
|
int
|
Number of electrons transferred per redox event \(n \ge 1\). |
1
|
area
|
float
|
Electrode area in \(\text{m}^2\) (or \(\text{cm}^2\)). |
1e-4
|
t_span
|
tuple[float, float]
|
Evaluation time interval \((t_{\min}, t_{\max})\) with \(t_{\min} > 0\) to evaluate beyond the initial Cottrell step discontinuity. |
(0.01, 0.2)
|
n_times
|
int
|
Number of evaluation time points across |
20
|
domain_factor
|
float
|
Diffusion layer multiplier setting domain length \(L = \text{domain\_factor} \sqrt{D t_{\max}}\). |
6.0
|
max_error_threshold
|
float
|
Maximum allowable \(L_\infty\) concentration error to consider the run passed. |
5e-2
|
**solver_kwargs
|
Any
|
Additional keyword arguments forwarded to the solver. |
{}
|
Returns:
| Type | Description |
|---|---|
BenchmarkCaseResult
|
Outcome containing concentration metrics, Cottrell current metrics, runtime, and pass/fail indicator. |
Examples:
>>> from softpotato.analytical.benchmark import run_cottrell_benchmark
>>> res = run_cottrell_benchmark("scipy_ivp", n_points=81, t_span=(0.02, 0.1))
>>> res.passed
True
>>> res.concentration_metrics.max_abs_error < 0.05
True
Source code in src/softpotato/analytical/benchmark.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 | |
run_mass_conservation_benchmark
¶
run_mass_conservation_benchmark(solver: BaseSolver | str = 'crank_nicolson', *, n_points: int = 61, D: float = 0.02, L: float = 1.0, t_span: tuple[float, float] = (0.0, 0.2), n_times: int = 11, max_drift_threshold: float = 0.001, **solver_kwargs: Any) -> BenchmarkCaseResult
Run mass conservation benchmark under zero-flux Neumann boundary conditions.
Solves 1D diffusion on a closed interval with zero-flux boundaries:
initialized with an internal Gaussian concentration pulse:
Analytical conservation invariant:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
BaseSolver or str
|
Numerical solver instance or registered string name. |
"crank_nicolson"
|
n_points
|
int
|
Number of spatial grid points \(N_x\). |
61
|
D
|
float
|
Diffusion coefficient \(D > 0\). |
0.02
|
L
|
float
|
Domain length \(L > 0\). |
1.0
|
t_span
|
tuple[float, float]
|
Simulation time span \((t_0, t_{\text{end}})\). |
(0.0, 0.2)
|
n_times
|
int
|
Number of evaluation time points. |
11
|
max_drift_threshold
|
float
|
Maximum relative mass drift \(|M(t) - M(0)| / M(0)\) allowed. |
1e-3
|
**solver_kwargs
|
Any
|
Additional keyword arguments forwarded to the solver. |
{}
|
Returns:
| Type | Description |
|---|---|
BenchmarkCaseResult
|
Outcome containing mass error metrics, execution time, and pass/fail indicator. |
Examples:
>>> from softpotato.analytical.benchmark import run_mass_conservation_benchmark
>>> res = run_mass_conservation_benchmark("crank_nicolson", n_points=51)
>>> res.passed
True
>>> res.details["max_relative_drift"] < 1e-3
True
Source code in src/softpotato/analytical/benchmark.py
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | |
verify_spatial_convergence
¶
verify_spatial_convergence(solver: BaseSolver | str = 'crank_nicolson', *, n_points_list: Sequence[int] = (21, 41, 81, 161), D: float = 0.05, L: float = 1.0, t_fixed: float = 0.1, dt_fine: float = 0.0001, expected_order: float = 2.0, order_tolerance: float = 0.25, metric: Literal['max_abs_error', 'rmse', 'l2_error'] = 'max_abs_error', **solver_kwargs: Any) -> ConvergenceResult
Verify spatial discretization order across grid refinement \(\Delta x\).
Executes a sequence of spatial grid refinements on the Fourier sine decay problem,
using a fine time step dt_fine so spatial error dominates. Computes the
empirical convergence order \(p\) via log-log regression:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
BaseSolver or str
|
Numerical solver instance or registered string name. |
"crank_nicolson"
|
n_points_list
|
sequence of int
|
List of spatial grid point counts to evaluate. |
(21, 41, 81, 161)
|
D
|
float
|
Diffusion coefficient \(D > 0\). |
0.05
|
L
|
float
|
Domain length \(L > 0\). |
1.0
|
t_fixed
|
float
|
Fixed time at which error is evaluated. |
0.1
|
dt_fine
|
float
|
Small time step size ensuring temporal error is negligible. |
1e-4
|
expected_order
|
float
|
Theoretical spatial order of convergence (default 2.0 for central differences). |
2.0
|
order_tolerance
|
float
|
Permissible deficit below |
0.25
|
metric
|
('max_abs_error', 'rmse', 'l2_error')
|
Error norm to regress against \(\Delta x\). |
'max_abs_error'
|
**solver_kwargs
|
Any
|
Additional keyword arguments forwarded to the solver. |
{}
|
Returns:
| Type | Description |
|---|---|
ConvergenceResult
|
Dataclass containing grid spacings \(\Delta x\), error array, empirical order \(p\), \(R^2\), and pass/fail indicator. |
Examples:
>>> from softpotato.analytical.benchmark import verify_spatial_convergence
>>> res = verify_spatial_convergence("crank_nicolson", n_points_list=(21, 41, 81))
>>> res.passed
True
>>> round(res.observed_order, 1)
2.0
Source code in src/softpotato/analytical/benchmark.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 | |
verify_temporal_convergence
¶
verify_temporal_convergence(solver: BaseSolver | str = 'crank_nicolson', *, dt_list: Sequence[float] = (0.04, 0.02, 0.01, 0.005), n_points: int = 51, D: float = 0.05, L: float = 1.0, t_end: float = 0.2, reference: Literal['fine_step', 'analytical'] = 'fine_step', dt_ref: float = 1e-05, expected_order: float = 2.0, order_tolerance: float = 0.3, metric: Literal['max_abs_error', 'rmse', 'l2_error'] = 'max_abs_error', **solver_kwargs: Any) -> ConvergenceResult
Verify temporal discretization order across time-step refinement \(\Delta t\).
Executes a sequence of temporal step refinements on the Fourier sine decay problem.
To prevent spatial discretization errors from masking temporal convergence, the
reference solution can be computed either analytically or via a high-resolution
self-consistent numerical baseline (reference='fine_step').
Linear regression in logarithmic coordinates determines the temporal order \(p\):
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
BaseSolver or str
|
Numerical solver instance or registered string name. |
"crank_nicolson"
|
dt_list
|
sequence of float
|
Sequence of time-step sizes \(\Delta t\) to evaluate. |
(0.04, 0.02, 0.01, 0.005)
|
n_points
|
int
|
Number of spatial grid points \(N_x\). |
51
|
D
|
float
|
Diffusion coefficient \(D > 0\). |
0.05
|
L
|
float
|
Domain length \(L > 0\). |
1.0
|
t_end
|
float
|
Simulation end time \(t_{\text{end}}\). |
0.2
|
reference
|
('fine_step', 'analytical')
|
Reference standard for error computation. |
'fine_step'
|
dt_ref
|
float
|
Reference time-step used when |
1e-5
|
expected_order
|
float
|
Expected theoretical temporal order (e.g. 2.0 for Crank–Nicolson, 1.0 for BTCS). |
2.0
|
order_tolerance
|
float
|
Permissible deficit below |
0.3
|
metric
|
('max_abs_error', 'rmse', 'l2_error')
|
Error norm to regress against \(\Delta t\). |
'max_abs_error'
|
**solver_kwargs
|
Any
|
Additional keyword arguments forwarded to the solver. |
{}
|
Returns:
| Type | Description |
|---|---|
ConvergenceResult
|
Dataclass containing time steps \(\Delta t\), error array, empirical temporal order \(p\), \(R^2\), and pass/fail indicator. |
Examples:
>>> from softpotato.analytical.benchmark import verify_temporal_convergence
>>> # Crank-Nicolson should exhibit 2nd-order temporal convergence (order ~ 2)
>>> res = verify_temporal_convergence("crank_nicolson", dt_list=(0.04, 0.02, 0.01), expected_order=2.0)
>>> res.passed
True
>>> round(res.observed_order, 1)
2.0
Source code in src/softpotato/analytical/benchmark.py
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 | |
list_benchmark_cases
¶
run_benchmark
¶
run_benchmark(case: Literal['fourier_decay', 'cottrell_step', 'cottrell', 'mass_conservation'], solver: BaseSolver | str = 'crank_nicolson', **kwargs: Any) -> BenchmarkCaseResult
Unified entry point to run a specific benchmark case with a solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case
|
('fourier_decay', 'cottrell_step', 'cottrell', 'mass_conservation')
|
Benchmark problem to execute. |
'fourier_decay'
|
solver
|
BaseSolver or str
|
Numerical solver instance or registered string name. |
"crank_nicolson"
|
**kwargs
|
Any
|
Parameters passed to the specific benchmark runner function. |
{}
|
Returns:
| Type | Description |
|---|---|
BenchmarkCaseResult
|
Outcome of the benchmark run. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unrecognized benchmark case name is provided. |
Examples:
>>> from softpotato.analytical.benchmark import run_benchmark
>>> res = run_benchmark("fourier_decay", "crank_nicolson")
>>> res.passed
True
Source code in src/softpotato/analytical/benchmark.py
run_benchmark_suite
¶
run_benchmark_suite(solvers: Sequence[BaseSolver | str] | None = None, cases: Sequence[Literal['fourier_decay', 'cottrell_step', 'cottrell', 'mass_conservation']] | None = None, **kwargs: Any) -> BenchmarkSuiteResult
Execute a comprehensive benchmark suite across multiple solvers and cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solvers
|
sequence of (BaseSolver or str)
|
List of solvers to evaluate. Defaults to unconditionally stable solvers:
|
None
|
cases
|
sequence of str
|
List of benchmark case names to run. Defaults to all standard cases:
|
None
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to benchmark runs. |
{}
|
Returns:
| Type | Description |
|---|---|
BenchmarkSuiteResult
|
Aggregated outcomes of all benchmark runs with summary reporting. |
Examples:
>>> from softpotato.analytical.benchmark import run_benchmark_suite
>>> suite = run_benchmark_suite(solvers=["crank_nicolson", "scipy_ivp"], cases=["fourier_decay"])
>>> suite.all_passed
True
>>> "crank_nicolson" in suite.summary()
True
Source code in src/softpotato/analytical/benchmark.py
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 | |