Help us shape the future of Go! Take the 2026 Go Developer Survey

scipy

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

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

View Source
const (
	SciPyVersion  = "1.18.1"
	NumPyVersion  = "2.5.4"
	CvxoptVersion = "1.3.3"
)

Pinned oracle versions.

View Source
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

func DefaultCommand() *exec.Cmd

DefaultCommand returns the uv command that runs the oracle with single-threaded numerical libraries.

func FakeCommand

func FakeCommand(mode string) func() *exec.Cmd

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.

func MaybeServeFake

func MaybeServeFake(getenv func(string) string, in io.Reader, out io.Writer) bool

MaybeServeFake serves the fake oracle on in/out and returns true when getenv(FakeEnv) selects a mode; otherwise it returns false at once.

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

type LUResponse struct {
	NNZ   int   `json:"nnz"`
	PermC []int `json:"perm_c"`
}

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.

func FromCSR

func FromCSR(a *sparse.CSR[float64]) Matrix

FromCSR converts a real CSR matrix to its wire form (no copy).

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 Start

func Start(command func() *exec.Cmd) (*Session, error)

Start launches the process built by command (normally DefaultCommand).

func (*Session) AMD

func (s *Session) AMD(a Matrix) ([]int, error)

AMD returns SuiteSparse AMD's permutation (through cvxopt) of the pattern of the symmetric matrix a.

func (*Session) Call

func (s *Session) Call(req, resp any) error

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) Close

func (s *Session) Close() error

Close ends the session.

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

func (s *Session) LU(a Matrix, perm []int, spec string, symmetric bool) (LUResponse, error)

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) Load

func (s *Session) Load(name string, a Matrix, b []float64) error

Load stores a system in the oracle for Time.

func (*Session) RCM

func (s *Session) RCM(a Matrix) ([]int, error)

RCM returns scipy's reverse Cuthill-McKee permutation.

func (*Session) Solve

func (s *Session) Solve(r SolveRequest) (SolveResponse, error)

Solve runs one solve.

func (*Session) Time

func (s *Session) Time(name, what string, reps, restart int) (float64, error)

Time runs a timed loop in the oracle and returns the seconds it took: what is "spmv" (reps products), "cg" (reps iterations, no stopping) or "gmres" (reps restart cycles of length restart, no stopping).

func (*Session) Versions

func (s *Session) Versions() (scipy, numpy string, err error)

Versions reports the SciPy and NumPy versions in use.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL