Check adaptive CUDA growth against an independent depletion reference
Download Python script · Download script with helper and data files (.zip)
Check adaptive CUDA growth against an independent depletion reference
Section titled “Check adaptive CUDA growth against an independent depletion reference”This companion repeats the finite-reservoir growth calculation with native CUDA RK23 in addition to the CPU methods. Download the complete example ZIP to retain the shared physical setup and scalar reference. A real CUDA device is required; this example never substitutes a CPU backend.
Accepted state and trial arrays stay on the device. The controller reads scalar error/status reductions, and each requested observation explicitly downloads a snapshot. This one-representative-particle case establishes numerical accuracy, not useful acceleration or throughput. It cannot be captured as a fixed CUDA graph, and it does not qualify stiff wet-to-dry relaxation on the GPU.
Python · section 1
import matplotlib.pyplot as pltimport warp as wpfrom docs.examples.simulations.adaptive_reservoir_depletion import ( plot_results, simulate,)
def run_cuda(): """Require CUDA and qualify both tolerances against the scalar reference.""" wp.init() if not wp.is_cuda_available(): raise RuntimeError("This comparison requires a real CUDA device") device = wp.get_device("cuda:0") print("CUDA device:", device.name) report = simulate(device=device.alias) report["device"] = {"alias": device.alias, "name": device.name} return reportEvery adaptive profile must meet the same predeclared radius and vapor error bounds. Each backend also has to improve when its tolerance is tightened. Compare these errors with the independent reference rather than treating CPU/GPU agreement alone as validation. A heterogeneous chamber adds stiffness, shared-controller constraints and stochastic scheduling that this case excludes. In the retained RTX 5060 run, tightening CUDA RK23 tolerance from 10⁻⁴ to 10⁻⁷ reduces maximum relative radius error from 1.82×10⁻⁵ to 2.57×10⁻⁸. The corresponding initial-vapor-normalized errors are 6.74×10⁻⁵ and 9.15×10⁻⁸; relative mass residuals remain below 2×10⁻¹⁵. These checks support the stated accuracy for this case, without claiming GPU performance from a tiny population.
Python · section 2
if __name__ == "__main__": report = run_cuda() figure = plot_results(report) plt.show()Explicit cuda invocation
report = run_cuda()figure = plot_results(report)Fixed 0.5 s radius error: 0.013104491968154663 vapor error / initial vapor: 0.051724928104230926 mass residual: 1.3348093070485667e-16 work: {'fixed_steps': 20}
Fixed 0.005 s radius error: 0.00012153195858566335 vapor error / initial vapor: 0.00047126688190263693 mass residual: 5.339237228194267e-16 work: {'fixed_steps': 2000}
CPU RK23 1e-4 radius error: 1.820119292772482e-05 vapor error / initial vapor: 6.736678437977377e-05 mass residual: 4.0044279211457e-16 work: {'accepted': 62, 'rejected': 1, 'domain_rejected': 0, 'rate_calls': 252, 'jacobian_calls': 0, 'time_derivative_calls': 0, 'factorizations': 0, 'linear_solves': 0}
CPU RK23 1e-7 radius error: 2.573387414273043e-08 vapor error / initial vapor: 9.152069530558079e-08 mass residual: 8.0088558422914e-16 work: {'accepted': 430, 'rejected': 2, 'domain_rejected': 0, 'rate_calls': 1728, 'jacobian_calls': 0, 'time_derivative_calls': 0, 'factorizations': 0, 'linear_solves': 0}
CPU ROS2 1e-5 radius error: 7.743971802698368e-07 vapor error / initial vapor: 2.8580766376794065e-06 mass residual: 2.2691758219825635e-15 work: {'accepted': 2574, 'rejected': 1, 'domain_rejected': 0, 'rate_calls': 5150, 'jacobian_calls': 2575, 'time_derivative_calls': 2575, 'factorizations': 2575, 'linear_solves': 15450}
CUDA RK23 1e-4 radius error: 1.819961694282668e-05 vapor error / initial vapor: 6.736250729474167e-05 mass residual: 2.6696186140971333e-16 work: {'accepted': 62, 'rejected': 1, 'domain_rejected': 0, 'rate_calls': 252, 'jacobian_calls': 0, 'time_derivative_calls': 0, 'factorizations': 0, 'linear_solves': 0}
CUDA RK23 1e-7 radius error: 2.5733596586974272e-08 vapor error / initial vapor: 9.151970898865327e-08 mass residual: 1.4682902377534233e-15 work: {'accepted': 430, 'rejected': 2, 'domain_rejected': 0, 'rate_calls': 1728, 'jacobian_calls': 0, 'time_derivative_calls': 0, 'factorizations': 0, 'linear_solves': 0}

Explore this topic: Adaptive growth and relaxation · GPU workflows