Repository navigation
Conversation
|
Jenkins, test this please. |
|
QA tests have started for PR 1493. This patch merges cleanly. |
|
Jenkins, retest this please. |
|
QA tests have started for PR 1493. This patch merges cleanly. |
|
Jenkins, retest this please. |
|
QA tests have started for PR 1493. This patch merges cleanly. |
|
QA results for PR 1493: |
There was a problem hiding this comment.
Better would be
prob = exp(margin)/(1 + exp(margin))because for very small probabilities this computation is essentially doing 1 - 1. For example:
>>> from math import exp
>>> margin = -40
>>> 1 - 1 / (1 + exp(margin))
0.0
>>> exp(margin)/(1 + exp(margin))
4.248354255291589e-18
>>>There was a problem hiding this comment.
Yes, that is definitely better. Could you submit a PR? We don't need a JIRA for small changes. Btw, please cache exp(margin) instead of computing it twice.
There was a problem hiding this comment.
Sure, pull request here! #1652
Thanks a lot! :-)
to avoid overflow in `exp(x)` if `x` is large. Author: Xiangrui Meng <meng@databricks.com> Closes apache#1493 from mengxr/py-logistic and squashes the following commits: 259e863 [Xiangrui Meng] stabilize logistic function in pyspark
Master's apache#1443 added IEEE_EQ, IEEE_LT and IEEE_LE to CompareOp and apache#1493's VarkaSmtNodes switch over it did not cover them, so catalyst tests did not compile. The floating lanes are refused before the switch; the arm refuses too. Generated-by: Claude Code (Opus 5.5)
Master's apache#1443 added IEEE_EQ, IEEE_LT and IEEE_LE to CompareOp and apache#1493's VarkaSmtNodes switch over it did not cover them, so catalyst tests did not compile. The floating lanes are refused before the switch; the arm refuses too. Generated-by: Claude Code (Opus 5.5)
Each of apache#1443 and apache#1493 regenerated the digests on its own base; an option arm's digest is one hash over every coverage shape, so with both merged three entries went stale and VarkaEmittedBytesSuite failed. Generated-by: Claude Code (Opus 5.5)
…pache#1495) ### What changes were proposed in this pull request? Master's catalyst test sources do not compile, and its emitted-bytes digests are stale. Two pull requests merged one after the other, and each was green on its own base: - apache#1443 added three members to the IR's compare operator: `IEEE_EQ`, `IEEE_LT` and `IEEE_LE`, the one-instruction IEEE compares of a floating lane. - apache#1493 added the proof printer's `VarkaSmtNodes.compare`, whose `switch` expression over that operator lists the nine members it knew about. A Java `switch` expression over an enum must cover every member, so with both merged, javac rejects `VarkaSmtNodes.java` ("the switch expression does not cover all possible input values"). This PR adds the missing arm. It also fixes a second consumer that only fails at run time: `VarkaSmtSamples.hand()` built one sample compare per operator over two long columns, and `Compare`'s constructor rejects an IEEE compare on a non-floating lane, so `VarkaSmtNodesSuite` and `VarkaProofFilesSuite` would throw while building their samples. The loop now walks `CompareOp.integral()`, as `VarkaIrGrammar` already does. The PR also regenerates `sql/varka/emitted_bytes.json`. Each of the two merges regenerated it on its own base, and an option arm's digest is one hash over every coverage shape, so with both merged three digests went stale and `VarkaEmittedBytesSuite` failed. The regeneration moves those digests and no shape's bytes. The new `switch` arm refuses the three IEEE compares, the way the printer already refuses every other node it cannot state. The arm is never reached today: `sortOf` refuses a `FLOAT` or `DOUBLE` lane before the `switch` runs, and the IEEE compares only ever read floating lanes. The arm exists so the `switch` stays total. ### Why are the changes needed? Until master compiles its test sources again, every open pull request that merges master fails its Build, and so does every regeneration of the generated files. ### Does this PR introduce _any_ user-facing change? No. The change is two lines in test sources. ### How was this patch tested? - `build/sbt catalyst/Test/compile` on master plus this change. - `VarkaSmtNodesSuite`, `VarkaProofFilesSuite` and `VarkaEmittedBytesSuite` pass. - `dev/varka_regen_generated.sh --all`, whose only change is the three digests. - `dev/varka_push_check.py`. - One `/code-review high` pass. It found the samples loop, fixed here. Left as they are: the new arm throws the printer's ordinary refusal rather than an assertion, though no node reaches it today, and its reason is worded as a short fragment. Both keep the line byte-identical to the copy that two open pull requests carry while master is broken, so their merges stay clean. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 5.5)
…ache#1496) ### What changes were proposed in this pull request? Varka's 64-bit decimal kernels were proven in `sql/varka/proofs/refinement.smt2` by rows written by hand: each row typed the kernel as an SMT string, such as `(< (jlong.mul a 100) c)`, beside Spark's rule, such as `(< (* a 10000) (* c 100))`. Nothing tied either string to the code. This pull request renders those proofs instead: the kernel side from the IR the compiler actually builds, the specification side from Spark's own analyzed expression. 1. **`sql/varka/proofs/decimal_refinement.smt2`, rendered by the new test class `VarkaDecimalRefinementFile`.** It covers the 43 rows of the coverage table's families "DECIMAL columns" and "DECIMAL arithmetic". Each row is compiled as `VarkaCoverageSuite` compiles a predicate (`compilePredicate`, default options, no host refusal), once under an ANSI session and once under a LEGACY one. Each gets the five checks `refinement.smt2` uses: a satisfiable precondition; a decline wherever the specification raises; equal validity; equal values on valid lanes; and a decline only where the specification raises. - **The kernel side** is the proof printer's outcome (`VarkaSmtNodes`) for the kernel's one fused root, with the kernel's own literal tables, every long in the printer's word form. - **The specification side** is read from Spark's analyzed `Expression`, one rule per Catalyst node, into `decimal_spec.smt2`'s `spec.dec.*` definitions from apache#1493. A column raises on a valid slot past its precision wherever it is read, as Spark's reader does. A cast rescales up exactly or cuts `HALF_UP`. A sum, difference or product is exact, then fitted to its result type: past it, a raise under ANSI and a null otherwise. Comparisons compare the rationals. `<=>`, `IS NULL`, `greatest`, `coalesce`, `CASE`/`IF`, `IN` and `InSet` follow Spark's semantics, and a later `coalesce` operand or an untaken `CASE` arm raises only where Spark evaluates it. Any other node is refused, not guessed. - A row whose two sessions print the same text is checked once. 42 rows render, 320 checks in all. The file's header lists the one refused row, `d8 * d9 <= d9b`: its kernel multiplies two column values, which the printer does not yet render (a product of two unknowns needs the planned limb-product layer). 2. **The retired hand rows.** 31 hand rows go from `refinement.smt2` (226 checks left, from 381). Only `d8 * d9 <= d9b` stays hand-written, in both modes. `try_multiply(d8, d9) IS NULL` renders after all: the compiler reads only its operands' validity, so its kernel has no product. 3. **The coverage table names the rendered file.** The two families' rows now say `rendered: decimal_refinement.smt2`, a new verification kind with its own column in `docs/sql-varka.md`'s counts. `VarkaCoverageSuite` fails a row of either family that the file does not echo, so a row added later is rendered or the build says why not. The equal-scale comparisons, until now checked only differentially, are refined for the first time. 4. **The printed decline is the emitter's, read rather than restated.** The printer's templates used to state by hand which `IfElse` arms qualify a guard. The emitter (`Analysis.armChainsOf`) leaves a guard unqualified in more cases: a decimal slot check, `guardUnderArm` off, past `MAX_ARM_CHAINS` chains, on an arm cycle, and a stored-value guard with several chains. So a printed decline could be smaller than the emitted one, which would make check 5 unsound. The new `VarkaSmtNodes.kernel` takes the guards `VarkaLoopEmitter.guardsForTest` reports, each with its chains. It declines on each guarded node's own check on the lanes some chain selects, or on every lane where there is no chain. A node whose template declines but which the emitter never checks is refused. A stored-value guard (VARKA-379) also reads null rows, as the emitter's does. The samples' oracle reads the same guards, evaluated through `VarkaReference`, and the suite holds the two together on the sampled trees; the hand set gains the date contract guard. The per-node templates go back to their own rule. 5. **No more unshared slot-check walk.** The old arm rule re-walked each choice's subtree for slot checks, quadratic in CASE depth. It is removed, and `kernel` visits each node once. 6. **The printer's compare covers the IEEE compares.** The floating literal compares master gained (`IEEE_EQ`, `IEEE_LT`, `IEEE_LE`) are refused in `VarkaSmtNodes.compare`, as the floating lane they belong to already is, so the switch is exhaustive again and catalyst's tests compile; the arm is byte-identical to a separate fix on master, so the two merge cleanly. 7. **The plans.** `VARKA-506.md` gains section 10.3, `PLAN.md` row 506 is updated, and the proofs README lists the new file. ### Why are the changes needed? A hand-written kernel string proves the kernel someone typed, not the one the compiler builds. Row 506's own admission check found exactly that gap elsewhere: `year(d) * 2` is proven as a checked multiply while the compiler builds a wrapping one. Rendering the kernel from the compiled IR removes the transcription for the 64-bit decimals. A later change to the compiler's lowering, or to Spark's decimal rules, then moves the proof with it, and `VarkaProofFilesSuite` fails until the file is regenerated and the solvers agree. Before removing the hand rows, a scratch file paired each of the 31 with its rendered row, the columns mapped by name, and asked Z3 whether any claim differs: the specification's raise, the kernel's decline, the kernel's validity and data, and the specification's value and validity, each where it is read. All 155 queries were `unsat`, so the hand rows were right and nothing proven is lost. The only difference was outside the claims: under LEGACY, five arithmetic rows' hand-written validity ignored a cast's precision check, and that differs only on a slot past its precision, where both specifications raise. ### Does this PR introduce _any_ user-facing change? No. Test sources, proof files and documentation only. No emitted byte moves. ### How was this patch tested? - `VarkaProofFilesSuite`, `VarkaSmtNodesSuite`, `VarkaSmtTermSuite` and `VarkaCoverageSuite` (catalyst), after `VARKA_PROOFS_REGEN=true` and `dev/varka_regen_generated.sh --all`. - `dev/varka_prove.sh --solver both`: every proof holds under Z3 and cvc5. Laptop times: `decimal_refinement.smt2` 0.47 s (Z3) and 0.55 s (cvc5); `refinement.smt2` 2.94 s and 4.13 s, from 2.96 s and 4.22 s; `smt_nodes_check.smt2` 0.03 s and 0.07 s. `--lint` takes 45 s for all files, from 56 s. - Planted faults on the rendered text, each run and reverted, each failing its own check under both solvers: `d9 < d9s4`'s rescale factor as 10 instead of 100 (check 4); the slot check of `d9 + d9b < d18`'s first column dropped from the decline (check 2); the specification rescaling a column by one digit instead of two (check 4). - The scratch diff of the 31 retired rows described above. - `dev/varka_errorprone.sh`, checkstyle on the catalyst tests, `dev/varka_push_check.py`. ### Review `/code-review high` found ten points. Fixed: the rendered file regenerated after a wording change; `IN` raising only on the items Spark evaluates (none for a null value, none after a match); an `InSet` holding a null, or a literal past a long, refused and listed instead of aborting the render; `kernel` also refusing a node the emitter guards whose template states no check; the variables' sorts taken from the terms rather than their names; `docs/sql-varka.md`'s prose and row 506's stale clause updated. A second `/code-review high`, after apache#1493 merged, found ten more points. Fixed: a row that does not compile or fuse as one root, and a literal past a long, are refused and listed instead of aborting the render or hiding an unrelated `ArithmeticException` under a false reason; a one-item `IN` prints no one-argument `or`, and its raise term is linear in the list (one running no-earlier-match term); a decimal operator with no rule is no longer reported as a cut scale; `kernel`'s javadoc points at `Analysis.armChainsOf` instead of restating it; the plans record apache#1493's merge. Left, as trade-offs (both reviews): - The renderer's seven decimal columns and the `InSet`'s elements copy `VarkaCoverageSuite`'s fixtures. Only the rows' SQL ties the two, because that suite's fixtures are private Scala. A changed fixture type would refine a different kernel than the table runs, until someone updates both. - The last hand row's helper keeps a `try_` branch no row reaches now; removing it would push the change past the size cap. - `VarkaSmtNodesSuite` skips a sampled tree for which `guardsForTest` throws an `IllegalArgumentException` or `IllegalStateException`, rather than telling the expected rejection from a regression; the suite's floor of 300 trees held to the emitter's decline still catches a broad one. - A widening cast keeps its ANSI overflow raise, which can never fire, so 22 rows print differently per session and are checked twice: 110 extra checks, about half a second under both solvers. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 5.5)
to avoid overflow in
exp(x)ifxis large.