Documentation
¶
Overview ¶
Package scipy drives SciPy as a verification oracle: one Python process per Session, spoken to in JSON lines over a pipe. Only the minimal SciPy call per request is made on the Python side (see script.go); all test generation, comparison and reporting is Go.
The default command is
uv run --with scipy==1.18.1 --with numpy==2.5.4 --with cvxopt==1.3.3 python -u -c <script>
cvxopt is used only for its SuiteSparse AMD binary (BSD-3-Clause), as an oracle for the ordering quality; no SuiteSparse source is involved.
Index ¶
- Constants
- func DefaultCommand() *exec.Cmd
- func FakeCommand(mode string) func() *exec.Cmd
- func MaybeServeFake(getenv func(string) string, in io.Reader, out io.Writer) bool
- type LSMRResponse
- type LSQRRequest
- type LSQRResponse
- type LUResponse
- type Matrix
- type Precond
- type Session
- func (s *Session) AMD(a Matrix) ([]int, error)
- func (s *Session) Call(req, resp any) error
- func (s *Session) Close() error
- func (s *Session) LSMR(r LSQRRequest) (LSMRResponse, error)
- func (s *Session) LSQR(r LSQRRequest) (LSQRResponse, error)
- func (s *Session) LU(a Matrix, perm []int, spec string, symmetric bool) (LUResponse, error)
- func (s *Session) Load(name string, a Matrix, b []float64) error
- func (s *Session) RCM(a Matrix) ([]int, error)
- func (s *Session) Solve(r SolveRequest) (SolveResponse, error)
- func (s *Session) Time(name, what string, reps, restart int) (float64, error)
- func (s *Session) Versions() (scipy, numpy string, err error)
- type SolveRequest
- type SolveResponse
Constants ¶
const ( SciPyVersion = "1.18.1" NumPyVersion = "2.5.4" CvxoptVersion = "1.3.3" )
Pinned oracle versions.
const FakeEnv = "GO_SPARSE_FAKE_ORACLE"
FakeEnv selects the fake-oracle mode of a re-executed test binary: "ok" answers every request with plausible canned numbers, "fail" answers with an error, "garbage" answers with the wrong JSON shape and "eof" exits at once. The fake lets the harness code be tested at 100% coverage without Python; it is not used by the real tools.
Variables ¶
This section is empty.
Functions ¶
func DefaultCommand ¶
DefaultCommand returns the uv command that runs the oracle with single-threaded numerical libraries.
func FakeCommand ¶
FakeCommand returns a command that re-executes the running test binary as a fake oracle in the given mode; the binary's TestMain must call MaybeServeFake.
Types ¶
type LSMRResponse ¶
type LSMRResponse struct {
X []float64 `json:"x"`
Istop int `json:"istop"`
Itn int `json:"itn"`
NormR float64 `json:"normr"`
NormAR float64 `json:"normar"`
NormA float64 `json:"norma"`
CondA float64 `json:"conda"`
NormX float64 `json:"normx"`
}
LSMRResponse is the tuple scipy.sparse.linalg.lsmr returns.
type LSQRRequest ¶
type LSQRRequest struct {
Op string `json:"op"`
A Matrix `json:"A"`
B []float64 `json:"b"`
Damp float64 `json:"damp"`
ATol float64 `json:"atol"`
BTol float64 `json:"btol"`
ConLim float64 `json:"conlim"`
IterLim int `json:"iter_lim"`
}
LSQRRequest asks for scipy.sparse.linalg.lsqr.
type LSQRResponse ¶
type LSQRResponse struct {
X []float64 `json:"x"`
Istop int `json:"istop"`
Itn int `json:"itn"`
R1Norm float64 `json:"r1norm"`
R2Norm float64 `json:"r2norm"`
ANorm float64 `json:"anorm"`
ACond float64 `json:"acond"`
ARNorm float64 `json:"arnorm"`
XNorm float64 `json:"xnorm"`
}
LSQRResponse is the tuple lsqr returns.
type LUResponse ¶
LUResponse is the factor size of SuperLU.
type Matrix ¶
type Matrix struct {
M int `json:"m"`
N int `json:"n"`
Indptr []int `json:"indptr"`
Indices []int32 `json:"indices"`
Data []float64 `json:"data"`
}
Matrix is the wire form of a CSR matrix.
type Precond ¶
type Precond struct {
Kind string `json:"kind"`
Omega float64 `json:"omega,omitempty"`
L *Matrix `json:"L,omitempty"`
U *Matrix `json:"U,omitempty"`
}
Precond selects the preconditioner of a Solve request.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a running oracle process.
func (*Session) AMD ¶
AMD returns SuiteSparse AMD's permutation (through cvxopt) of the pattern of the symmetric matrix a.
func (*Session) Call ¶
Call sends one request (a struct or map with an "op" field) and decodes the response into resp. An {"error": ...} reply becomes a Go error.
func (*Session) LSMR ¶
func (s *Session) LSMR(r LSQRRequest) (LSMRResponse, error)
LSMR runs scipy lsmr; the request has the shape of an LSQR request (IterLim is lsmr's maxiter).
func (*Session) LSQR ¶
func (s *Session) LSQR(r LSQRRequest) (LSQRResponse, error)
LSQR runs scipy lsqr.
func (*Session) LU ¶
LU factorises with scipy splu and returns nnz(L)+nnz(U). With perm nil the column ordering is spec ("COLAMD", "NATURAL", "MMD_AT_PLUS_A", "MMD_ATA"); otherwise A[:, perm] is factorised with spec "NATURAL" (or A[perm][:, perm] in SuperLU's symmetric mode without row pivoting when symmetric is true).
func (*Session) Solve ¶
func (s *Session) Solve(r SolveRequest) (SolveResponse, error)
Solve runs one solve.
type SolveRequest ¶
type SolveRequest struct {
Op string `json:"op"`
Solver string `json:"solver"`
A Matrix `json:"A"`
B []float64 `json:"b"`
M *Precond `json:"M,omitempty"`
RTol float64 `json:"rtol"`
ATol float64 `json:"atol"`
MaxIter *int `json:"maxiter"`
Restart int `json:"restart,omitempty"`
}
SolveRequest asks for scipy.sparse.linalg.{cg,bicgstab,gmres,minres}.
type SolveResponse ¶
type SolveResponse struct {
Info int `json:"info"`
Iters int `json:"iters"`
Res float64 `json:"res"`
}
SolveResponse is what SciPy reported: info, callback count, and the true relative residual it computed itself.