Repository navigation
Conversation
On development evaluate(1e-19*T) and global_evaluate of the same are wrong by the 1e-18*x*y term the evaluators add, and a matrix mixing a small field entry with a constant one is wrong in that entry. Underworld development team with AI support from Claude Code
… instead evaluate and global_evaluate added zero_matrix(shape), 1e-18*x*y in every entry, so that lambdify returned a uniform array for a matrix mixing constant and coordinate-dependent entries. _lambdify_and_evaluate now lambdifies the entries as a flat list and fills the result entry by entry, numpy broadcasting a constant entry over the points. Underworld development team with AI support from Claude Code
|
Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)) #1295 at 4257f04: evaluate and global_evaluate no longer add 1e-18·x·yVerdict at 4257f04: changes requested. The defect is gone. Small values now come back exact through both evaluators, serial and in parallel, including on a rank with no cells. Every value that ran on both builds differs from development by at most the removed 1e-18·x·y. Shapes, dtypes and cost are unchanged. But the change removes more than the added term. The deleted lines also ran a second Method
ResultsThe defect (T holds x + 2y, degree 1; Ts holds 1e-20·(x + 2y), degree 2; six points; tolerance rel 1e-12)
Nothing else changed. I ran a battery through
Expressions that hold a
Cost (hex box 12³, P2 scalar and vector fields; median of 3 after a warm-up; at np 4 each rank asks for a quarter of the points, max over ranks)
At 1e6 points the differences are within 2.4%, in both directions. That is within run-to-run noise with other jobs on the machine. At 1e4 points and np 4, head was 6–29% faster, on times under 0.15 s. Tests
Findings
What was run and not run
Underworld development team with AI support from Claude Code |
What changed and why
UNFILED 42, from the parallel review desk's review of #1284. This is the core evaluation path; the change is confined to how
evaluateandglobal_evaluateshape a result.Both evaluators added
mesh.CoordinateSystem.zero_matrix(expr.shape)to every expression before lambdify (introduced in ff65767, "Evaluation updates"). Each entry of that matrix isuw.maths.functions.vanishing * x * y(* zin 3-D), that is 1e-18·x·y. Its purpose was shape: a matrix that mixes constant entries with coordinate-dependent ones does not lambdify to a uniform numpy array, and the added term made every entry depend on the coordinates. But it is added to the value, so wherever the value itself is of order 1e-18 it is most of the answer:evaluate(1e-19*T)came out 3.08 times too large at (0.5, 0.5);evaluate(R*T)gave 27801 against 9976.8.integraland the solvers do not add it and were exact.Now nothing is added to the expression.
_lambdify_and_evaluate, the final step shared by both evaluators, lambdifies the entries as a flat list and fills the(n_points, entries)result entry by entry; an entry that depends on no coordinate and no variable comes back as a number, which numpy broadcasts over the points. The result is then reshaped to(n_points, *shape)exactly as before. This cannot change a value: each entry is the lambdified entry itself, and the only operation applied to it is assignment into the result array (broadcasting a number repeats it). The result dtype is numpy's result type of the entries (at least float64), as lambdify's array was before.What a user's run sees: values of
evaluateandglobal_evaluatethat differ from before by the removed 1e-18·x·y (relative to the domain scale), which is visible only where the evaluated values are themselves that small. Shapes are unchanged.Left as is
The coordinate systems use the same term as an exact-looking zero inside their rotation matrices (
coordinates.py:independent_of_Nin the third row of the sphericalrRotNand in the 3-D cylindrical east unit vector). Those forms are also compiled by the solvers, so they are not changed here; evaluating those unit vectors still carries 1e-18·x·y·z where the entry is zero.Tests
tests/test_1295_evaluate_adds_nothing_to_small_values.py(serial;evaluateis rank-local):1e-19*Tand1e-30*xagainst their exact values (Tholds x + 2y on a degree-1 variable) through both evaluators; a matrix mixing a small field entry and a constant, and a 2x2 matrix mixing coordinates, constants and a small term; constants (an integer, a rational, 2.5e-20) and a constant matrix broadcast to the right shape; an expression in a parameter only. On development 4 of the 10 fail (the small-field and small-coordinate cases and the mixed matrix); the shape cases passed already and pin the shapes.tests/parallel/test_1295_global_evaluate_adds_nothing_to_small_values_parallel.py: the same throughglobal_evaluate, each rank asking for its own points. Fails on development at np 2; passes at np 2 and np 3.Cost
evaluateof a P2 field expression on a 2-D box (cell 1/64), median of five calls, same base before and after:exp(-T)*xWithin run-to-run noise (a first run against an older build moved the other way by a similar amount).
What was run
On a 96-thread Linux workstation (single system image, Intel Xeon Gold 6240R, MPICH):
test_0720 ... test_mesh_coordinates_complex, which also xpasses on development)check_test_coverage.py,check_deprecated_patterns.pyNot run
np 4 or more, 3-D evaluation at scale, macOS, the full suite.
Underworld development team with AI support from Claude Code