kkthn.builder

class kkthn.builder.Constraint(residual: "'Expression'", kind: 'str', text: 'str')[source]

Bases: object

residual: Expression
kind: str
text: str
class kkthn.builder.DatasetSpec(parameters_path: 'str', variables_path: 'str | None' = None)[source]

Bases: object

parameters_path: str
variables_path: str | None = None
class kkthn.builder.Expression(fn: Callable, text: str)[source]

Bases: object

eval(ctx)[source]
class kkthn.builder.VectorExpression(fn: Callable, text: str, *, size: int, components: list[Expression] | None = None)[source]

Bases: object

eval(ctx)[source]
class kkthn.builder.Constant(name: str, value: Any)[source]

Bases: object

class kkthn.builder.ConstraintList[source]

Bases: object

items: list[Constraint]
add(*constraints: Constraint) ConstraintList[source]
equality(expr, *, name: str | None = None) ConstraintList[source]
inequality(expr, *, name: str | None = None) ConstraintList[source]
class kkthn.builder.KKTHardNet(name: str = 'kkthardnet', *, train: dict[str, Any] | KKTTrainConfig | None = None, projection: dict[str, Any] | ProjectionSettings | None = None)[source]

Bases: object

parameter_names: list[str]
variable_names: list[str]
inverse_parameter_names: list[str]
objective: Expression | None
dataset_spec: DatasetSpec | None
add_parameter(names: str | Iterable[str])[source]
add_variable(names: str | Iterable[str])[source]
add_inverse_parameter(names: str | Iterable[str], *, init_value: float | Iterable[float] | None = None)[source]
matrix(values) Constant[source]

Register a constant matrix and return its wrapper.

vector(values) Constant[source]

Register a constant vector and return its wrapper.

tensor(values) Constant[source]

Register a constant tensor and return its wrapper.

extract(path: str | Path) dict[str, Constant][source]

Load arrays from a .npz file and expose them as model attributes.

dataset(*, parameters: str | Path, variables: str | Path | None = None) KKTHardNet[source]
set_dataset(*, parameters: str | Path, variables: str | Path | None = None) KKTHardNet[source]
use_dataset(*, parameters: str | Path, variables: str | Path | None = None) KKTHardNet[source]
set_train_config(config: dict[str, Any] | KKTTrainConfig) KKTHardNet[source]
set_projection_config(config: dict[str, Any] | ProjectionSettings) KKTHardNet[source]
model(*, train: dict[str, Any] | KKTTrainConfig | None = None, projection: dict[str, Any] | ProjectionSettings | None = None) dict[str, Any][source]
optimize(*, train: dict[str, Any] | KKTTrainConfig | None = None, projection: dict[str, Any] | ProjectionSettings | None = None) dict[str, Any][source]
estimate(*, train: dict[str, Any] | KKTTrainConfig | None = None, projection: dict[str, Any] | ProjectionSettings | None = None) dict[str, Any][source]
load(metadata_path: str | Path, *, verbose: bool | None = None) KKTHardNet[source]
predict(values, *, projection_backend: str = 'jax') ndarray[source]
summary() dict[str, Any][source]

Print a compact summary of the current completed or loaded run.

plot_history(*, show: bool = True, save_dir: str | Path | None = None, bg: str = 'grey')[source]

Plot and save MSE/loss and constraint violation histories.

lin(matrix, expr)[source]

Form A @ expr from an extracted or registered matrix/vector.

batch_lin(matrix, expr)[source]

Form a vector expression from a 2D matrix and vector expression.

quad(matrix, expr) Expression[source]

Form expr.T @ Q @ expr.

batch_quad(tensor, expr) VectorExpression[source]

Form batched quadratic expressions from a rank-3 tensor.

batch_exp(expr) VectorExpression[source]
sin(expr)[source]
cos(expr)[source]
exp(expr)[source]
log(expr)[source]
sqrt(expr)[source]
abs(expr)[source]
kkthn.builder.ProblemBuilder

alias of KKTHardNet