- Move existing OndselSolver, GNN ML layer, and tooling into GNN/ directory for integration in later phases - Add Create addon scaffold: package.xml, Init.py - Add expression DAG with eval, symbolic diff, simplification - Add parameter table with fixed/free variable tracking - Add quaternion rotation as polynomial Expr trees - Add RigidBody entity (7 DOF: position + unit quaternion) - Add constraint classes: Coincident, DistancePointPoint, Fixed - Add Newton-Raphson solver with symbolic Jacobian + numpy lstsq - Add pre-solve passes: substitution + single-equation - Add DOF counting via Jacobian SVD rank - Add KindredSolver IKCSolver bridge for kcsolve integration - Add 82 unit tests covering all modules Registers as 'kindred' solver via kcsolve.register_solver() when loaded by Create's addon_loader.
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
"""Tests for pre-solve passes."""
|
|
|
|
import pytest
|
|
from kindred_solver.expr import Const, Var
|
|
from kindred_solver.params import ParamTable
|
|
from kindred_solver.prepass import single_equation_pass, substitution_pass
|
|
|
|
|
|
class TestSubstitutionPass:
|
|
def test_fixed_replaced(self):
|
|
pt = ParamTable()
|
|
x = pt.add("x", 3.0, fixed=True)
|
|
y = pt.add("y", 0.0)
|
|
residuals = [x + y - Const(5.0)]
|
|
result = substitution_pass(residuals, pt)
|
|
# After substitution, x is replaced with 3.0
|
|
# So residual becomes 3.0 + y - 5.0 = y - 2.0
|
|
env = pt.get_env()
|
|
assert abs(result[0].eval({"y": 2.0}) - 0.0) < 1e-10
|
|
|
|
def test_no_fixed(self):
|
|
pt = ParamTable()
|
|
x = pt.add("x", 1.0)
|
|
residuals = [x - Const(1.0)]
|
|
result = substitution_pass(residuals, pt)
|
|
assert len(result) == 1
|
|
|
|
|
|
class TestSingleEquationPass:
|
|
def test_solve_linear(self):
|
|
"""x - 3 = 0 with only x free → solves x=3 and removes residual."""
|
|
pt = ParamTable()
|
|
x = pt.add("x", 0.0)
|
|
residuals = [x - Const(3.0)]
|
|
result = single_equation_pass(residuals, pt)
|
|
assert len(result) == 0
|
|
assert abs(pt.get_value("x") - 3.0) < 1e-10
|
|
assert pt.is_fixed("x")
|
|
|
|
def test_two_residuals_chain(self):
|
|
"""x - 3 = 0, y - x = 0 → solves x=3, then y=3."""
|
|
pt = ParamTable()
|
|
x = pt.add("x", 0.0)
|
|
y = pt.add("y", 0.0)
|
|
residuals = [x - Const(3.0), y - x]
|
|
result = single_equation_pass(residuals, pt)
|
|
assert len(result) == 0
|
|
assert abs(pt.get_value("x") - 3.0) < 1e-10
|
|
assert abs(pt.get_value("y") - 3.0) < 1e-10
|
|
|
|
def test_multi_var_not_solved(self):
|
|
"""x + y - 5 = 0 with both free → not solved."""
|
|
pt = ParamTable()
|
|
x = pt.add("x", 0.0)
|
|
y = pt.add("y", 0.0)
|
|
residuals = [x + y - Const(5.0)]
|
|
result = single_equation_pass(residuals, pt)
|
|
assert len(result) == 1 # still unsolved
|