TorchLean API

NN.Verification.Util.Json

Json #

Shared JSON helpers for TorchLean verification tools.

Many verification workflows consume small JSON “certificates” produced by Python tooling (often PyTorch-based). This module centralizes:

These helpers take a strict stance: malformed certificates fail fast with contextual error messages instead of silently defaulting.

Turn an Except String α parser result into IO, preserving the parser's error text.

Instances For

    Read and parse a JSON verification artifact from disk.

    Use this at checker boundaries instead of repeating IO.FS.readFile and Json.parse in every tool. The file path is included in parse errors.

    Instances For

      Ensure a JSON value is an object.

      Instances For

        Extract a required field from a JSON object.

        Instances For

          Read a JSON artifact and require the top-level value to be an object.

          Instances For

            Extract an optional field from a JSON object.

            Instances For

              Require a JSON string in an IO parser, preserving contextual error messages.

              Instances For

                Require a natural number, accepting either JSON numeric syntax or a decimal string.

                Instances For

                  Require a JSON array and return its entries.

                  Instances For

                    Parse a Nat from a JSON number or decimal string.

                    Instances For

                      Parse a Float from a JSON number or a string containing a JSON number.

                      Instances For

                        Parse a finite Float from a JSON number or a string containing a JSON number.

                        Instances For

                          Require a floating-point value in an Except parser.

                          Instances For

                            Require a finite floating-point value in an Except parser.

                            Instances For

                              Parse a JSON array of finite floats in an Except parser.

                              Instances For

                                A finite axis-aligned region parsed from a verification artifact.

                                • dim : Nat

                                  Declared dimension, or the inferred endpoint-array length when dim is absent.

                                • Lower coordinate bounds.

                                • Upper coordinate bounds.

                                Instances For

                                  Check the dimensional and ordering invariants of an axis-aligned region.

                                  Instances For

                                    Parse either {lo, hi} or {center, eps} notation for a finite axis-aligned region.

                                    When dim is absent, it is inferred from the endpoint or center array. When present, it must be a natural number equal to the resulting endpoint lengths. The parser also rejects negative radii, non-finite values, incomplete schemas, and intervals whose lower endpoint exceeds the upper one. Keeping these checks here gives certificate consumers one well-formed region type instead of several subtly different parsers.

                                    Instances For

                                      Parse the exact endpoint schema {lo, hi}, with an optional matching dim field.

                                      Instances For

                                        Extract a floating-point-valued field in an Except parser.

                                        Instances For

                                          Extract a finite floating-point-valued field in an Except parser.

                                          Instances For

                                            Extract a string-valued field in an Except parser.

                                            Instances For

                                              Decode a JSON boolean if the value is exactly true or false.

                                              Instances For

                                                Require a floating-point value, accepting JSON numbers and string-encoded numbers.

                                                Instances For

                                                  Require a finite floating-point value, accepting JSON numbers and string-encoded numbers.

                                                  Instances For

                                                    Require a JSON boolean and report ctx on mismatch.

                                                    Instances For

                                                      Parse a JSON array of floats.

                                                      Instances For

                                                        Parse a JSON matrix represented as an array of float arrays.

                                                        Instances For

                                                          Parse a JSON array of floats with contextual errors.

                                                          Instances For

                                                            Parse a JSON array of finite floats with contextual errors.

                                                            Instances For

                                                              Parse a JSON matrix of floats with contextual errors.

                                                              Instances For

                                                                Parse a JSON matrix whose entries are all finite floats.

                                                                Instances For

                                                                  Extract an object-valued field.

                                                                  Instances For

                                                                    Extract a string-valued field.

                                                                    Instances For

                                                                      Extract a natural-number-valued field.

                                                                      Instances For

                                                                        Extract an array-valued field.

                                                                        Instances For

                                                                          Extract an optional array-valued field in an Except parser, using #[] when absent/null.

                                                                          Instances For

                                                                            Extract a float-array-valued field.

                                                                            Instances For

                                                                              Extract a finite-float-array-valued field.

                                                                              Instances For

                                                                                Extract a float-matrix-valued field.

                                                                                Instances For

                                                                                  Extract a finite-float-matrix-valued field.

                                                                                  Instances For

                                                                                    Extract an optional string-valued field.

                                                                                    Instances For

                                                                                      Extract an optional natural-number-valued field.

                                                                                      Instances For

                                                                                        Extract an optional finite floating-point-valued field.

                                                                                        Instances For

                                                                                          Extract an optional boolean-valued field.

                                                                                          Instances For
                                                                                            def NN.Verification.Json.expectFormat (j : Lean.Json) (expected : String) (ctx : String := "top-level") :

                                                                                            Require a top-level format field to match an expected artifact schema string.

                                                                                            This makes schema checks uniform across verification tools and keeps examples from hand-rolling their own unsupported-format errors.

                                                                                            Instances For

                                                                                              Pointwise all on two float arrays of equal length.

                                                                                              Instances For

                                                                                                Pointwise any on two float arrays of equal length.

                                                                                                Instances For