Skip to content

Independent MATLAB reference validation

Fixtures in tests/reference/matlab/warp_factory.npz were exported by MATLAB R2026a Update 5 from WarpFactory commit 03b10cb02e73998af28db87201a43f2fa0e30319. They were not generated by Python's implementation. metadata.json records runtime, grid parameters, constants and the raw JSON SHA-256. There are 130 arrays for ten cases: Minkowski, static, dynamic and comoving Alcubierre, dynamic and comoving Lentz, dynamic Van Den Broeck, Schwarzschild, and two comoving warp shells (smoothFactor 1 and 502). Modified Time has no reference because upstream's implementation is defective (see below).

The first three cases were first exported with R2025b Update 1. Re-exporting them with R2026a changed no array by more than 8e-16 relative, so the references do not depend on the MATLAB release.

For each case the tests compare metric components, second/fourth Ricci tensors, second/fourth stress-energy, Eulerian frame transfer, dominant maps and vorticity. Eight cases agree with rtol=1e-10, with atol=max(1e-30, max(abs(reference))*1e-12) to accommodate cross-platform roundoff, including near-zero components; the observed agreement is about 1e-15 for the Alcubierre, Lentz and Van Den Broeck cases. Schwarzschild uses 1e-7 and the warp shells have their own comparisons, both explained below. Boundaries are included. These cases validate representative paths, not every possible metric/parameter combination.

CPU compatibility required by the installed MATLAB

Parallel Computing Toolbox is absent on the validation machine. Upstream calls isgpuarray on its CPU path, and its vector generator hard-codes a GPU sphere helper even with tryGPU=0. The exporter always prepends two explicit helpers, whether or not the toolbox is installed, so the export does not depend on the machine's GPU setup:

  • isgpuarray.m checks isa(value, 'gpuArray'), which is false for these arrays.
  • getEvenPointsOnSphere.m is the upstream helper with useGPU=false, selecting the identical CPU formulas instead of attempting a GPU allocation.

The downloaded upstream tree is unchanged. The copied helper retains the upstream MIT license through the repository LICENSE. No mathematical formulas are modified for the reference export.

Intentional differences (not asserted as direct parity)

The fixture also retains null/weak/strong conditions and scalar outputs that expose known convention differences. They are not silently discarded:

Output Upstream behavior Python behavior
Null/weak conditions Lowers Eulerian components using the original curved metric. Uses the local Minkowski metric for orthonormal-frame components.
Weak/strong conditions Samples speed 1 down to 0, including exactly null vectors. Samples strictly timelike speeds from 0 up to below 1.
Dominant condition Checks causal flux norm. Also requires future-directed flux. Identical on the Alcubierre, Lentz and Van Den Broeck references; on the warp shell it enlarges violations by up to about 13% and never changes the sign.
Expansion/shear Uses hard-coded unit spacing in getScalars; no ct conversion in covDiv. Uses supplied spacing and converts time derivatives to the ct basis.
Comoving Modified Time/Van Den Broeck g00 uses the original shift term. Uses the comoving shift, restoring the Alcubierre limiting case.
Warp-shell radial sampling Uses Legendre radial interpolation. Uses linear interpolation; analytic exterior and zero-mass limits are tested.

On the exported curved cases, null/weak/strong map differences were roughly 6-14% of the largest map magnitude. Dynamic expansion/shear differ by factors associated with the 0.5 m grid spacing. Analytic tests in tests/analyser/ and tests/numerical/ check Python's intended behavior independently; passing parity tests does not claim these corrected outputs are identical upstream.

Further differences found by the additional references

Output Upstream behavior Python behavior
Schwarzschild metric Adds epsilon = 1e-10 to r ("to mitigate divide by zero errors") while using the unperturbed x, y, z. A grid point on the origin gives huge finite values instead of an error. Uses the exact r and raises ValueError when the grid touches the origin or the coordinate horizon. Differs from upstream by about 1e-9 relative on the reference case.
No Eulerian observers (t = const not spacelike, or singular metric) getEulerianTransformationMatrix takes a complex square root, then only warns "Eulerian Transformation is imaginary" and returns the complex matrix. The real square root gives NaN, so the function raises ValueError ("not finite"). An invalid frame is an error, not a result to be used.
Axes too short for the stencil takeFiniteDifference1/2 return zeros along any axis shorter than five samples, so a moving bubble on three time slices silently loses its time derivative and gives the same stress-energy as the metric frozen in time. get_energy_tensor, get_scalars and eval_metric raise ValueError for an axis of 2 to 4 samples (2 for second order). One sample stays valid: nothing varies along it. The reference grids use 1 or 5 samples, so they never exercise this.
Non-Cartesian coords verifyTensor warns but still returns 1, and getEnergyConditions only warns that results are unverified, so the Cartesian formulas run on a metric they do not describe. Verification fails, and the solver and analysis functions raise "not verified" (with a warning naming the cause). Only Cartesian coordinates are implemented.
Single x sample in covDiv Sets phiphiFlag = 1 for the g22 component when the grid has one x sample. takeFiniteDifference1 then replaces the first and last two boundary values of that component's y-derivative with hard-coded constants (2*4, 2*3, 2*(s-5-1), 2*(s-5)), which affects expansion, shear and vorticity. No special case: the ordinary stencil and boundary copy are used. The reference grids have five x samples, so they do not exercise this.
Warp shell at r = 0 A grid radius that falls exactly on a radial sample makes the Legendre interpolation divide by zero (x1 == x2); r = 0 is sample 1, so a grid point on the shell centre gives NaN in 12 metric components, and the NaNs spread through the derivative stencils. Interpolates linearly, which has no such singularity; the metric and stress-energy stay finite.
Warp-shell radial range Samples radii only up to 1.2 times the distance from the centre to the far grid corner, and the interpolation needs two further samples. A centre far enough from the grid middle leaves the near corner outside the array and raises "Index exceeds the number of array elements". Samples up to 1.2 times the largest grid radius (at least R_2), so any centre works.
Second-order stress-energy constants einE2 hard-codes the rounded values G = 6.6740e-11 and c = 2.99792e8 (scaled by the unit factors), while the fourth-order path uses G = 6.6743e-11 and c = 299792458, so the two orders disagree by about 4e-5 for the same metric. Both orders use warpica.units. Second-order stress-energy is about 3.9e-5 smaller in relative terms than MATLAB's; the parity tests rescale the MATLAB fixture by the exact constant ratio and still compare to 1e-10.

The Schwarzschild difference is exactly the offset: upstream's formula evaluated with r + 1e-10 reproduces the MATLAB reference to roundoff (test_schwarzschild_difference_is_the_upstream_epsilon), so the parity comparison for that case uses a relative tolerance of 1e-7 instead of 1e-10. The reference cases keep the grid away from r = 0 for both families.

Warp-shell comparison

The shell involves three choices that upstream and Python make differently, so it is compared in two ways (tests/reference/test_matlab_parity_shell.py).

Tight comparison, 1e-7. Python's sampled radial range is replaced by upstream's. Everything else is then compared as-is: the mass integral, the pressure and alpha solvers, smooth() and the interpolation. Python interpolates linearly where upstream uses a cubic Lagrange formula. Measured agreement is about 2e-10 for the metric and 3e-9 for the stress-energy, for both smoothing factors. The smoothFactor 502 case also confirms that Python's reimplementation of MATLAB's smooth() applies the same window rules as the real function: the floor-versus-round choice for the non-integer span of 898.58 alone would change the result by about 3e-6.

Python's own range, 5e-4 and 3e-3. Python samples radii up to 1.2 times the largest grid radius (at least R_2); upstream uses 1.2 times the distance to the far grid corner. These agree when the grid is symmetric about the centre, but the reference grids are deliberately off-centre to avoid r = 0 (see above), so the 100,000 samples fall differently relative to the density edges. That quadrature difference is about 1e-4. smooth() windows are counted in samples, so with smoothFactor 502 the physical window also differs, by the ratio of the two ranges (6% here), which raises the difference to about 1e-3. Rescaling Python's window to the same physical width brings the error back to the unsmoothed level. Because the window is measured in samples, the same smooth_factor means a different physical width for different grids in both implementations.

Dominant condition. Upstream's formula, applied to Python's stress-energy, matches the reference; Python's own map differs only by its future-direction rule. The tests check that Python's value is never less severe than the upstream formula's and that the signs agree everywhere.

Toolbox requirement for the warp-shell reference

Upstream metricGet_WarpShellComoving calls smooth(), which requires the MATLAB Curve Fitting Toolbox (or another toolbox that provides it). The exporter needs it for the two warp-shell cases. It is deliberately not replaced by a stand-in: Python's _smooth is itself a reimplementation of smooth(), so a second reimplementation written from the same reading of the documentation would only confirm the assumption it is meant to test. One shell case uses smoothFactor=1, where smooth() reduces to the identity, and the other uses smoothFactor=5, where the window rules (non-integer and even spans) change the result.

Known upstream defects

Exporting references for the remaining metric families exposed defects in upstream metricGet_ModifiedTime and metricGet_ModifiedTimeComoving at the pinned commit. They are why Modified Time has no MATLAB reference case.

Defect Variant Effect
gridScale is used but the parameter is named gridScaling (line 62) non-comoving The function raises "Unrecognized function or variable" on every call that reaches the loop.
x, y, z use spacing indices 1, 2, 3 instead of 2, 3, 4 (lines 55-57, 60-62) both The x position is scaled by the time spacing, the y position by the x spacing, and so on; results are wrong whenever the spacings differ.
The symmetric shift copy reads tensor{1,2}(t,i,k,k) instead of (t,i,j,k) (line 72) both The {2,1} component is taken from the wrong cell, so the metric is not symmetric when j != k.

The Alcubierre, Lentz and Van Den Broeck generators use the correct indices and a symmetric copy, and have reference cases. Python's Modified Time uses the correct indices; it is checked by its reduction to the Alcubierre metric (test_modified_metrics_reduce_to_alcubierre) and by the generator tests instead of by MATLAB parity.

Stability contract for 1.0

The behaviour in the right-hand column above is the supported contract: a later 1.x release will not change these results. Each difference is pinned by a test that checks the analytically correct answer, not a recording of current output.

Difference Why Python's behaviour is correct Pinned by
Minkowski lowering of Eulerian components The Eulerian frame is orthonormal, so its metric is already Minkowski; lowering with the curved metric would apply the curvature twice. Dust at rest must report the same density in any coordinates. test_conditions_are_frame_independent_in_a_curved_metric
Strictly timelike speeds A speed of exactly 1 is the null limit, which the Null condition already covers. Speeds are linspace(0, 1, n, endpoint=False). test_timelike_speeds_include_rest_and_exclude_the_null_limit, test_timelike_samples_are_strictly_timelike
Future-directed dominant flux The dominant condition requires a future-directed causal flux, so a causal but past-directed flux is a violation. test_dust_sign_and_sample_return (negative density), test_shell_dominant_differs_only_by_the_future_direction_rule
Expansion and shear scaling The result for a physical flow must not depend on how finely it is sampled. test_expansion_uses_the_supplied_spatial_spacing, test_flrw_expansion_shear_and_vorticity
Comoving Modified Time and Van Den Broeck g00 Both must reduce to Alcubierre when their extra parameters are neutral. test_modified_metrics_reduce_to_alcubierre
Linear warp-shell interpolation The radial profiles are smooth enough that 100,000 linear samples are accurate to about 1e-10 or better; the choice of interpolant is not visible in results. test_linear_interpolation_error_is_negligible, test_shell_agrees_closely_when_sampling_like_upstream

Because these are conventions of the output, not of the interface, a switch selecting the upstream behaviour could be added in a 1.x release without breaking anything. None is provided in 1.0.

Reproduce

Download and extract the exact commit archive from GitHub into .reference-source/, then run from the repository root:

matlab -batch "addpath('tools'); export_matlab_reference('.reference-source/WarpFactory-03b10cb02e73998af28db87201a43f2fa0e30319','tests/reference/matlab/raw.json');"
python tools/convert_matlab_reference.py
python -m pytest tests/reference -q

The raw JSON is ignored by Git; compressed arrays and metadata are committed. The converter only reshapes MATLAB column-major data and compresses it. It never imports the Python solver. The CI run uses frozen fixtures and needs no MATLAB license. Review numerical differences before replacing fixtures.