Skip to content

liblaf.peach.optim.objective ¤

Classes:

Objective ¤

Bases: FunctionWrapper


              flowchart TD
              liblaf.peach.optim.objective.Objective[Objective]
              liblaf.peach.functools._wrapper.FunctionWrapper[FunctionWrapper]

                              liblaf.peach.functools._wrapper.FunctionWrapper --> liblaf.peach.optim.objective.Objective
                


              click liblaf.peach.optim.objective.Objective href "" "liblaf.peach.optim.objective.Objective"
              click liblaf.peach.functools._wrapper.FunctionWrapper href "" "liblaf.peach.functools._wrapper.FunctionWrapper"
            

Parameters:

  • structure ¤

    (Structure[PyTree] | None, default: None ) –

Methods:

Attributes:

fun class-attribute instance-attribute ¤

X -> Scalar

grad class-attribute instance-attribute ¤

X -> X

grad_and_hess_diag class-attribute instance-attribute ¤

grad_and_hess_diag = FunctionDescriptor(
    n_outputs=2,
    unflatten_inputs=(0,),
    flatten_outputs=(0, 1),
)

X -> X, X

hess class-attribute instance-attribute ¤

X -> H

hess_diag class-attribute instance-attribute ¤

X -> X

hess_prod class-attribute instance-attribute ¤

X, P -> X

hess_quad class-attribute instance-attribute ¤

X, P -> Scalar

structure class-attribute instance-attribute ¤

structure: Structure[PyTree] | None = field(
    default=None, kw_only=True
)

value_and_grad class-attribute instance-attribute ¤

X -> Scalar, X

flatten ¤

flatten(
    params: PyTree,
    *,
    constraints: Iterable[Constraint] = (),
) -> tuple[Self, Shaped[Array, " free"], list[Constraint]]
Source code in src/liblaf/peach/functools/_wrapper.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def flatten(
    self, params: PyTree, *, constraints: Iterable[Constraint] = ()
) -> tuple[Self, Shaped[Array, " free"], list[Constraint]]:
    fixed_constr: list[FixedConstraint] = []
    other_constr: list[Constraint] = []
    for c in constraints:
        if isinstance(c, FixedConstraint):
            fixed_constr.append(c)
        else:
            other_constr.append(c)
    if len(fixed_constr) > 1:
        raise NotImplementedError
    fixed_mask: PyTree | None = fixed_constr[0].mask if fixed_constr else None
    params_flat: Shaped[Array, " free"]
    structure: Structure[PyTree]
    params_flat, structure = tree.flatten(params, fixed_mask=fixed_mask)
    self_new: Self = attrs.evolve(self, flatten=True, structure=structure)
    constr_flat: list[Constraint] = [
        constr.flatten(structure) for constr in other_constr
    ]
    return self_new, params_flat, constr_flat

jit ¤

jit(enable: bool = True) -> Self
Source code in src/liblaf/peach/functools/_wrapper.py
45
46
def jit(self, enable: bool = True) -> Self:  # noqa: FBT001, FBT002
    return attrs.evolve(self, jit=enable)

partial ¤

partial(*args: Any, **kwargs: Any) -> Self
Source code in src/liblaf/peach/functools/_wrapper.py
51
52
53
54
def partial(self, *args: Any, **kwargs: Any) -> Self:
    return attrs.evolve(
        self, args=(*self._args, *args), kwargs={**self._kwargs, **kwargs}
    )

timer ¤

timer(enable: bool = True) -> Self
Source code in src/liblaf/peach/functools/_wrapper.py
58
59
def timer(self, enable: bool = True) -> Self:  # noqa: FBT001, FBT002
    return attrs.evolve(self, timer=enable)

timer_finish ¤

timer_finish() -> None
Source code in src/liblaf/peach/functools/_wrapper.py
61
62
63
64
65
66
67
68
def timer_finish(self) -> None:
    _logging_hide = True
    for name, member in inspect.getmembers(self):
        if name.startswith("_"):
            continue
        timer: grapes.BaseTimer | None = grapes.get_timer(member, None)
        if timer is not None and len(timer) > 0:
            timer.finish()

with_aux ¤

with_aux(enable: bool = True) -> Self
Source code in src/liblaf/peach/functools/_wrapper.py
72
73
def with_aux(self, enable: bool = True) -> Self:  # noqa: FBT001, FBT002
    return attrs.evolve(self, with_aux=enable)