Skip to content

Define LinearSolverBackend protocol and tighten operator contracts #19

@jc-macdonald

Description

@jc-macdonald

Summary

Introduce the core backend protocol that all solver backends must satisfy.

Scope

Create src/op_engine/backends/__init__.py defining:

  1. LinearSolverBackend(Protocol)@runtime_checkable, with methods:

    • solve(left_op, right_op, x) -> NDArray — equivalent to current implicit_solve()
    • clear_cache() -> None — equivalent to clear_implicit_solver_cache()
    • convert_operator(op: OperatorLike) -> Any — replaces CoreSolver._as_scipy_operator()
  2. Tighten OperatorLike — add dtype property (already checked in _SolverMeta but not in protocol)

  3. Export LinearSolverBackend from op_engine.__init__

Files to create/modify

  • src/op_engine/backends/__init__.py (new) — protocol definitions
  • src/op_engine/__init__.py — add to exports

Acceptance criteria

  • LinearSolverBackend is a typing.Protocol with @runtime_checkable
  • mypy --strict passes for the new module
  • No existing tests break (protocols are structural)

Dependencies

None — can start immediately.

Design context

Current anchor points in codebase:

  • OperatorLike / PredictorLike protocols: core_solver.py ~L99-125
  • ScipyOperator type alias: core_solver.py L149
  • Operator / DenseOperator / SparseOperator aliases: matrix_ops.py L18-20

Metadata

Metadata

Assignees

Labels

architectureStructural or design-level changesenhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions